Monday, November 16, 2009

ViewPaymentSent !!

public partial class viewpaymentsent : System.Web.UI.Page
{
private const string ASCENDING = " ASC";
private const string DESCENDING = " DESC";
string _Strfill;
IDLDPLMain objIDLDPLMain = new IDLDPLMain();
string strPayOperation = String.Empty;
string strPayApprove = String.Empty;
DynMenu objDynMenu = new DynMenu();

protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
objIDLDPLMain.AddlogDetails("View Payment Sent", Request.Url.ToString());
fillviewPayment();
}

}
//*Code for Fill The GridView*//
private void fillviewPayment()
{
using (SqlConnection ViewPayconn = new SqlConnection(ConfigurationManager.AppSettings["conIDLDPL"]))
{
try
{
ViewPayconn.Open();
string viewpaymentstr;
if (Session["logLevelName"].ToString().Trim().ToLower() == "admin")
{
viewpaymentstr = "select * from viewPaymentMadeNew where pm_delete='No' order by pm_id desc";
}
else
{
viewpaymentstr = "select * from viewPaymentMade where pm_delete='No' AND (loc_id = " + Session["loglocid"] + ") order by pm_id desc";
}
SqlDataAdapter viewPayDA = new SqlDataAdapter(viewpaymentstr, ViewPayconn);
DataSet ds = new DataSet();
viewPayDA.Fill(ds,"tmptable");


if (ds.Tables["tmptable"].Rows.Count == 0)
{
gviewPaymentSent.Visible = false;
hidetr.Visible = true;
EmptyMsg.Visible = true;
}
else
{
gviewPaymentSent.Visible = true;
EmptyMsg.Visible = false;
hidetr.Visible = false;
gviewPaymentSent.DataSource = ds;
gviewPaymentSent.DataBind();
}
}
catch (Exception ex)
{
Response.Write(ex.Message.ToString());
}
finally
{
ViewPayconn.Close();
}
}
}

//*Below 4 function ( code ) are used for Sorting*//
private void SortGridView(string sortExpression, string direction)
{
// You can cache the DataTable for improving performance
DataTable dt = GetData().Tables[0];
DataView dv = new DataView(dt);

dv.Sort = sortExpression + direction;

gviewPaymentSent.DataSource = dv;
gviewPaymentSent.DataBind();

}
private DataSet GetData()
{

SqlConnection StWConn = new SqlConnection(ConfigurationManager.AppSettings["conIDLDPL"]);

//SqlDataAdapter ad = new SqlDataAdapter("SELECT * from emplistview where emp_delete='No' order by emp_id desc", StWConn);
SqlDataAdapter ad;

if (Session["logLevelName"].ToString().Trim().ToLower() == "admin")
{
ad = new SqlDataAdapter("select * from viewPaymentMadeNew where pm_delete='No' order by pm_id desc", StWConn);
}
else
{
ad = new SqlDataAdapter("select * from viewPaymentMade where pm_delete='No' AND (loc_id = " + Session["loglocid"] + ") order by pm_id desc", StWConn);
}
DataSet ds = new DataSet();

ad.Fill(ds);

return ds;

}
public SortDirection GridViewSortDirection
{
get
{
if (ViewState["sortDirection"] == null)
ViewState["sortDirection"] = SortDirection.Ascending;
else
ViewState["sortDirection"] = SortDirection.Descending;
return (SortDirection)ViewState["sortDirection"];
}
set { ViewState["sortDirection"] = value; }
}
protected void gviewPaymentSent_Sorting(object sender, GridViewSortEventArgs e)
{
{
string sortExpression = e.SortExpression;

if (GridViewSortDirection == SortDirection.Ascending)
{
GridViewSortDirection = SortDirection.Descending;
SortGridView(sortExpression, DESCENDING);
}
else
{
GridViewSortDirection = SortDirection.Ascending;
SortGridView(sortExpression, ASCENDING);
ViewState["sortDirection"] = null;
}
}
}
protected void gviewPaymentSent_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
gviewPaymentSent.PageIndex = e.NewPageIndex;
fillviewPayment();
}
protected void gviewPaymentSent_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow || e.Row.RowType == DataControlRowType.Separator)
{
Label lblstatus = (Label)e.Row.Cells[9].FindControl("lblActive");
Label lblid = (Label)e.Row.Cells[9].FindControl("lblID");
Label lblDel = (Label)e.Row.Cells[9].FindControl("lblDel");


string status = lblstatus.Text.ToString();
string id = lblid.Text.ToString();

// \"Click Realised
// \"Click UnRealised

strPayOperation = objDynMenu.GetPermission("Accounts", "Payment Sent");


//////////////////////////Begin Approval Permission//////////////////////////////
if (strPayOperation.Length.ToString() != "0")
{
strPayOperation = strPayOperation.ToString().Substring(0, strPayOperation.Length - 1);
ArrayList myList = new ArrayList();
char[] sep ={ ',' };

string[] values = strPayOperation.Split(sep);

int i;
for (i = 0; i < values.Length; i++)
{
myList.Add(values[i]);
if (values[i].ToString().ToLower() == "approve")
{
strPayApprove = "approve";
break;
}
}
}


if (Session["logLevelName"].ToString().Trim().ToLower() == "admin")
{
if (status.ToString() == "Realised")
{
e.Row.Cells[7].Text = "\"Click";
}
else
{
e.Row.Cells[7].Text = "\"Click";
}
}
else if (strPayApprove.ToString() == "approve")
{
if (status.ToString() == "Realised")
{
e.Row.Cells[7].Text = "\"Click";
}
else
{
e.Row.Cells[7].Text = "\"Click";
}
}
else
{
if (status.ToString() == "Realised")
{
e.Row.Cells[7].Text = "\"Click";
}
else
{
e.Row.Cells[7].Text = "\"Click";
}
}
//////////////////////////End Approval Permission//////////////////////////////


////////////////Begin Delete Permissions////////////////////////
if (strPayOperation.Length.ToString() != "0")
{
strPayOperation = strPayOperation.ToString().Substring(0, strPayOperation.Length - 1);
ArrayList myList = new ArrayList();
char[] sep ={ ',' };
string[] values = strPayOperation.Split(sep);
int i;
for (i = 0; i < values.Length; i++)
{
myList.Add(values[i]);
if (values[i].ToString().ToLower() == "Delete")
{
lblDel.Text="";
break;
}
else if (Session["logLevelName"].ToString().Trim().ToLower() == "admin")
{
lblDel.Text = "";
}
else
{
lblDel.Text = "";
}
}
}
else if (Session["logLevelName"].ToString().Trim().ToLower() == "admin")
{
lblDel.Text = "";
}
else
{
lblDel.Text = "";
}
/////////////////End Delete Permissions///////////////////////
}
}
protected void BtnSubmit_click(object sender, EventArgs e)
{
Search();
}

//* Code for Search*//
private void Search()
{
using (SqlConnection ViewPayconn = new SqlConnection(ConfigurationManager.AppSettings["conIDLDPL"]))
{
try
{
ViewPayconn.Open();
if (Session["logLevelName"].ToString().Trim().ToLower() == "admin")
{
_Strfill = "select * from viewPaymentMadeNew ";
}
else
{
_Strfill = "select * from viewPaymentMade ";
}
string serkey;
serkey = txtSearch.Text;
if (txtSearch.Text != "")
{
if (DDLSearch.SelectedValue != "Select")
{
if (DDLSearch.SelectedValue == "Supplier Name")
{
// _Strfill = _Strfill + " where supl_name like '%" + serkey.ToString() + "%'";
if (Session["logLevelName"].ToString().Trim().ToLower() == "admin")
{
_Strfill = _Strfill + " where supl_name = '" + serkey.ToString() + "'";
}
else
{
_Strfill = _Strfill + " where supl_name = '" + serkey.ToString() + "' AND (loc_id = " + Session["loglocid"] + ")";
}
}
else if (DDLSearch.SelectedValue == "Date")
{
if (Session["logLevelName"].ToString().Trim().ToLower() == "admin")
{
_Strfill = _Strfill + " where progDate='" + serkey.ToString() + "'";
}
else
{
_Strfill = _Strfill + " where progDate='" + serkey.ToString() + "' AND (loc_id = " + Session["loglocid"] + ")";
}
}
else if (DDLSearch.SelectedValue == "Mode")
{
if (Session["logLevelName"].ToString().Trim().ToLower() == "admin")
{
_Strfill = _Strfill + " where pmode_name='" + serkey.ToString() + "'";
}
else
{
_Strfill = _Strfill + " where pmode_name='" + serkey.ToString() + "' AND (loc_id = " + Session["loglocid"] + ")";
}
}
else if (DDLSearch.SelectedValue == "Currency")
{
if (Session["logLevelName"].ToString().Trim().ToLower() == "admin")
{
_Strfill = _Strfill + " where pm_Currency='" + serkey.ToString() + "'";
}
else
{
_Strfill = _Strfill + " where pm_Currency='" + serkey.ToString() + "' AND (loc_id = " + Session["loglocid"] + ")";
}
}

}
}
// _Strfill = _Strfill + " order by pm_id desc";
PopulateSearchGrid(_Strfill);

}
catch (Exception ex)
{
Response.Write(ex.Message.ToString());
}
finally
{
ViewPayconn.Close();
}
}
}

public void PopulateSearchGrid(string StrKey)
{
try
{
using (SqlConnection IDLDPLConn = new SqlConnection(ConfigurationManager.AppSettings["conIDLDPL"]))
{
IDLDPLConn.Open();
SqlDataAdapter IDLDPLda = new SqlDataAdapter(StrKey.ToString(), IDLDPLConn);
DataSet IDLDPLds = new DataSet();
IDLDPLda.Fill(IDLDPLds,"Temp");
if (IDLDPLds.Tables["Temp"].Rows.Count == 0)
{
gviewPaymentSent.Visible = false;
hidetr.Visible = true;
EmptyMsg.Visible = true;
}
else
{
gviewPaymentSent.Visible = true;
EmptyMsg.Visible = false;
hidetr.Visible = false;
gviewPaymentSent.DataSource = IDLDPLds;
gviewPaymentSent.DataBind();
}
}
}
catch (Exception ex)
{
Response.Write(ex.Message.ToString());
}
}

}

AddLocation !!

protected void Page_Load(object sender, EventArgs e)
{
if (Request.QueryString.HasKeys())
{
if (Request.QueryString["action"].ToString() == "edit")
{
if (!Page.IsPostBack)
{
lblLocation.Text = "Edit Location";
btnSubmit.Text = "Save";
addLocType();
addCompName();
addCountry();
FillLocationDetail();

}
}
else if (Request.QueryString["action"].ToString() == "copy")
{
if (!Page.IsPostBack)
{
lblLocation.Text = "Copy Location";
btnSubmit.Text = "Save";
addLocType();
addCompName();
addCountry();
FillLocationDetail();
//addCountry();
}


}
}
else
{
if (!Page.IsPostBack)
{
addLocType();
addCompName();
addCountry();
}
}
}

######################################

// Add Company Location Type

private void addLocType()
{
using (SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["conIDLDPL"]))
{
try
{
DDCountry.Items.Clear();
conn.Open();
string str = "select loc_type_name,loc_type_id from tblLocationType where loc_type_active='Yes' and loc_type_delete='No'";
ListItem Locat;
SqlCommand insertCom = new SqlCommand(str, conn);
SqlDataReader userReader = insertCom.ExecuteReader();
if (userReader.HasRows)
{
while (userReader.Read())
{
ListItem insert;
insert = new ListItem(userReader["loc_type_name"].ToString(), userReader["loc_type_id"].ToString());
DDLocation.Items.Add(insert);

}
}

Locat = new ListItem("Select--------------------->");
DDLocation.Items.Insert(0, Locat);
userReader.Close();

}
catch (Exception ex)
{
Response.Write(ex.Message.ToString());
}
finally
{
conn.Close();
}

}

}

##########################################

// Add Company Name

private void addCompName()
{
using (SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["conIDLDPL"]))
{
try
{
DDCountry.Items.Clear();
conn.Open();
string str = "select comp_name,comp_id from tblCompanyMaster where comp_active='Yes' and comp_delete='No'";
ListItem Locat;
SqlCommand insertCom = new SqlCommand(str, conn);
SqlDataReader userReader = insertCom.ExecuteReader();
if (userReader.HasRows)
{
while (userReader.Read())
{
ListItem insert;
insert = new ListItem(userReader["comp_name"].ToString(), userReader["comp_id"].ToString());
DDCompName.Items.Add(insert);

}
}

Locat = new ListItem("Select--------------------->");
DDCompName.Items.Insert(0, Locat);
userReader.Close();

}
catch (Exception ex)
{
Response.Write(ex.Message.ToString());
}
finally
{
conn.Close();
}

}

}

#######################################

// Add Country
private void addCountry()
{
using (SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["conIDLDPL"]))
{
try
{
DDCountry.Items.Clear();
conn.Open();
string str = "select country_name,country_id from tblCountryMaster where country_active='Yes'and country_delete='No'";
ListItem Locat;
SqlCommand insertCom = new SqlCommand(str, conn);
SqlDataReader userReader = insertCom.ExecuteReader();
if (userReader.HasRows)
{
while (userReader.Read())
{
ListItem insert;
insert = new ListItem(userReader["country_name"].ToString(), userReader["country_id"].ToString());
DDCountry.Items.Add(insert);

}
}

Locat = new ListItem("Select--------------------->");
DDCountry.Items.Insert(0, Locat);
userReader.Close();

}
catch (Exception ex)
{
Response.Write(ex.Message.ToString());
}
finally
{
conn.Close();
}

}

}

###################################################

// Add Company Location
private void LocationAdd()
{
using (SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["conIDLDPL"]))
{
try
{
conn.Open();
SqlCommand comLocation = new SqlCommand("insert_tblLocationMaster", conn);
comLocation.CommandType = CommandType.StoredProcedure;
comLocation.Parameters.Add(new SqlParameter("@comp_id", DDCompName.SelectedValue.ToString()));
comLocation.Parameters.Add(new SqlParameter("@loc_type_id", DDLocation.SelectedValue.ToString()));
comLocation.Parameters.Add(new SqlParameter("@loc_name", txtLocName.Text));
comLocation.Parameters.Add(new SqlParameter("@loc_contect_person", txtContPerson.Text));
comLocation.Parameters.Add(new SqlParameter("@loc_addr1", txtaddr1.Text));
comLocation.Parameters.Add(new SqlParameter("@loc_addr2", txtaddr2.Text));
comLocation.Parameters.Add(new SqlParameter("@loc_city", txtcity.Text));


if (DDState.SelectedItem.Text == "Others")
{
comLocation.Parameters.Add(new SqlParameter("@loc_state", txtother.Text));
}
else
{
comLocation.Parameters.Add(new SqlParameter("@loc_state", DDState.SelectedItem.Text));
}

// comLocation.Parameters.Add(new SqlParameter("@loc_state", DDState.SelectedItem.Text));
comLocation.Parameters.Add(new SqlParameter("@loc_country", DDCountry.SelectedValue.ToString()));
comLocation.Parameters.Add(new SqlParameter("@loc_pin", txtpin.Text));
comLocation.Parameters.Add(new SqlParameter("@loc_phone", txtphone.Text));
comLocation.Parameters.Add(new SqlParameter("@loc_mobile", txtmobile.Text));
comLocation.Parameters.Add(new SqlParameter("@loc_fax", txtfax.Text));
comLocation.Parameters.Add(new SqlParameter("@loc_email", txtemail.Text));
comLocation.Parameters.Add(new SqlParameter("@loc_active", "Yes"));
comLocation.Parameters.Add(new SqlParameter("@loc_delete", "No"));
comLocation.Parameters.Add(new SqlParameter("@loc_add_by", int.Parse(Session["EmpID"].ToString())));
//comLocation.Parameters.Add(new SqlParameter("@loc_add_date", "No"));

comLocation.ExecuteNonQuery();


}
catch (Exception ex)
{
Response.Write(ex.Message.ToString());
}
finally
{

}


}


}
private void FillLocationDetail()
{
using (SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["conIDLDPL"]))
{
try
{
conn.Open();

string id = Request.QueryString["id"].ToString();
// string str = "select * from tblLocationMaster ";
string str = "select * from viewLocationDetail where loc_id=@Locid";


SqlCommand com = new SqlCommand(str, conn);
SqlParameter LOCID = new SqlParameter("@Locid", SqlDbType.Int, 4);
LOCID.Value = Request.QueryString["id"];
com.Parameters.Add(LOCID);
SqlDataReader dr = com.ExecuteReader();
if (dr.HasRows)
{
dr.Read();
DDCompName.SelectedIndex = DDCompName.Items.IndexOf(DDCompName.Items.FindByValue(dr["comp_id"].ToString()));
DDLocation.SelectedIndex = DDLocation.Items.IndexOf(DDLocation.Items.FindByValue(dr["loc_type_id"].ToString()));
txtLocName.Text = dr["loc_name"].ToString();
ViewState["locName"] = dr["loc_name"].ToString();

txtContPerson.Text = dr["loc_contect_person"].ToString();
txtaddr1.Text = dr["loc_addr1"].ToString();
txtaddr2.Text = dr["loc_addr2"].ToString();
txtcity.Text = dr["loc_city"].ToString();
// DDState.SelectedItem.Text = dr["loc_state"].ToString();
DDCountry.SelectedIndex = DDCountry.Items.IndexOf(DDCountry.Items.FindByValue(dr["loc_country"].ToString()));
if (DDCountry.SelectedIndex > 0)
{
DDState.SelectedIndex = DDState.Items.IndexOf(DDState.Items.FindByText(dr["loc_state"].ToString()));
if (DDState.SelectedIndex <= 0)
{

txtother.Visible = true;
txtother.Text = dr["loc_state"].ToString();
DDState.SelectedIndex = DDState.Items.Count - 1;

}
}
else
{
txtother.Visible = false;

}
txtpin.Text = dr["loc_pin"].ToString();
txtphone.Text = dr["loc_phone"].ToString();
txtmobile.Text = dr["loc_mobile"].ToString();
txtfax.Text = dr["loc_fax"].ToString();
txtemail.Text = dr["loc_email"].ToString();

}

}
catch (Exception ex)
{
Response.Write(ex.Message.ToString());
}
finally
{
conn.Close();
}

}

}
/*This code is used for update the LocationDetail*/
private void UpdateLocationDetail()
{
using (SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["conIDLDPL"]))
{
try
{
conn.Open();
SqlCommand comLocation = new SqlCommand("update_tblLocationMaster1", conn);
comLocation.CommandType = CommandType.StoredProcedure;
string id = Request.QueryString["id"].ToString();
comLocation.Parameters.Add(new SqlParameter("@loc_id", id));
comLocation.Parameters.Add(new SqlParameter("@comp_id", DDCompName.SelectedValue.ToString()));
comLocation.Parameters.Add(new SqlParameter("@loc_type_id", DDLocation.SelectedValue.ToString()));
comLocation.Parameters.Add(new SqlParameter("@loc_name", txtLocName.Text));
comLocation.Parameters.Add(new SqlParameter("@loc_contect_person", txtContPerson.Text));
comLocation.Parameters.Add(new SqlParameter("@loc_addr1", txtaddr1.Text));
comLocation.Parameters.Add(new SqlParameter("@loc_addr2", txtaddr2.Text));
comLocation.Parameters.Add(new SqlParameter("@loc_city", txtcity.Text));


if (DDState.SelectedItem.Text == "Others")
{
comLocation.Parameters.Add(new SqlParameter("@loc_state", txtother.Text));
}
else
{
comLocation.Parameters.Add(new SqlParameter("@loc_state", DDState.SelectedItem.Text));
}

// comLocation.Parameters.Add(new SqlParameter("@loc_state", DDState.SelectedItem.Text));
comLocation.Parameters.Add(new SqlParameter("@loc_country", DDCountry.SelectedValue.ToString()));
comLocation.Parameters.Add(new SqlParameter("@loc_pin", txtpin.Text));
comLocation.Parameters.Add(new SqlParameter("@loc_phone", txtphone.Text));
comLocation.Parameters.Add(new SqlParameter("@loc_mobile", txtmobile.Text));
comLocation.Parameters.Add(new SqlParameter("@loc_fax", txtfax.Text));
comLocation.Parameters.Add(new SqlParameter("@loc_email", txtemail.Text));

comLocation.Parameters.Add(new SqlParameter("@loc_edit_by", int.Parse(Session["EmpID"].ToString())));

comLocation.ExecuteNonQuery();

}
catch (Exception ex)
{
Response.Write(ex.Message.ToString());
}
finally
{

}


}


}

protected void btnSubmit_Click(object sender, EventArgs e)
{
if (Request.QueryString.HasKeys())
{
if (Request.QueryString["action"].ToString() == "edit")
{
UpdateLocationDetail();
Response.Redirect("viewlocation.aspx");
}
else if (Request.QueryString["action"].ToString() == "copy")
{
checkLocationStauts();

}
}
else
{
checkLocationStauts();
//LocationAdd();
//Response.Redirect("viewlocation.aspx");

}
}
public void checkLocationStauts()
{
using (SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["conIDLDPL"]))
{

try
{
lblmsg.Text = "";
conn.Open();
// string str = "select * from tblLocationMaster where loc_name='" + ViewState["locName"] + "'";
string str = "select * from tblLocationMaster where loc_name='" + txtLocName.Text + "'";
SqlCommand chkCom = new SqlCommand(str,conn);
SqlDataReader dr = chkCom.ExecuteReader();
if (dr.HasRows)
{

dr.Read();
lblmsg.Text="Location name already exists!";
}
else
{
LocationAdd();
Response.Redirect("viewlocation.aspx",false);
//checkLocationStauts();
}
}
catch (Exception ex)
{
Response.Redirect(ex.Message.ToString());
}
finally
{
conn.Close();
}
}


}
protected void btCancle_Click(object sender, EventArgs e)
{
if (Request.QueryString.HasKeys())
{
Response.Redirect("viewlocation.aspx");
}
else
{
Response.Redirect("adminhome.aspx");
}
}
protected void DDState_SelectedIndexChanged(object sender, EventArgs e)
{
if (DDState.SelectedItem.Text == "Others")
{

txtother.Visible = true;
}
else
{
txtother.Visible = false;
}

}
protected void DDCountry_SelectedIndexChanged(object sender, EventArgs e)
{
if (DDCountry.SelectedItem.Text != "India")
{
DDState.SelectedValue = "Others";
txtother.Visible = true;
// lblStar.Visible = true;
this.txtother.Focus();
}
else
{
txtother.Visible = false;
DDState.SelectedValue = DDState.SelectedValue.ToString();
// DDState.SelectedIndex = 0;
// lblStar.Visible = false;

}
}

Reapeter Fill !!

private void fillGridView()
{

string FileDirectory = Server.MapPath("Database/admin.mdb");
OleDbConnection ocon = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + FileDirectory.ToString() + "");

try
{
ocon.Open();
string str = "SELECT Project_master.Project_name,Project_master.Project_id, Project_master.Project_total_hours, Project_master.Project_start_date, Project_master.Project_end_date, User_master.User_name" + " " +
"FROM Project_master INNER JOIN User_master ON Project_master.User_id = User_master.User_id";

//string str = "SELECT Project_assignment.ProjAssig_opening_hours, Project_assignment.ProiAssig_Allolet_hours, Project_assignment.ProjAssig_status, Project_master.Project_name, Project_master.Project_total_hours, Project_master.Project_start_date, Project_master.Project_end_date, User_master.User_name" + " " +
//"FROM Project_assignment INNER JOIN (Project_master INNER JOIN User_master ON Project_master.User_id = User_master.User_id) ON Project_assignment.Project_id = Project_master.Project_id";
//String str = "select *,User_name from Project_master inner join User_Master on Project_master.User_id=User_Master.User_id order by Project_master.Project_end_date desc";
OleDbDataAdapter osap = new OleDbDataAdapter(str, ocon);

DataSet ds = new DataSet();
osap.Fill(ds, "temp");
GVProjectReports.DataSource = ds;
GVProjectReports.DataBind();


}
catch (Exception ex)
{
Response.Write(ex.Message.ToString());
}

}


private DataSet FillRepeater(string pid)
{

string FileDirectory = Server.MapPath("Database/admin.mdb");
DataSet ds = new DataSet();
OleDbConnection ocon = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + FileDirectory.ToString() + "");

try
{
ocon.Open();
string str = "SELECT User_master.User_name,ProjAssig_opening_hours,ProiAssig_Allolet_hours " + " " +
"FROM Project_assignment INNER JOIN User_master ON User_master.User_id = Project_assignment.User_id where Project_assignment.Project_id="+ pid +" ";

OleDbDataAdapter osap = new OleDbDataAdapter(str, ocon);


osap.Fill(ds, "temp");

}
catch (Exception ex)
{
Response.Write(ex.Message.ToString());
}

return ds;

}


protected void GVProjectReports_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow || e.Row.RowType == DataControlRowType.Separator)
{

Repeater rep = (Repeater)e.Row.FindControl("ProReport");
Label pid=(Label)e.Row.FindControl("projectID");
Label lblTotHr = (Label)e.Row.FindControl("lblTotHr");
Label _lblRemaingHr = (Label)e.Row.FindControl("lblRemaingHr");



rep.DataSource = FillRepeater(pid.Text);
rep.DataBind();
int totalHr = 0;
foreach (RepeaterItem repe in rep.Items)
{
Label lblopenAllocated = (Label)repe.FindControl("lblopenHr");
totalHr = totalHr + Convert.ToInt32(lblopenAllocated.Text);
}

_lblRemaingHr.Text =Convert.ToString((Convert.ToInt32(lblTotHr.Text) - totalHr));

}
}

Update !!

private void updatecom()
{
//using (SqlConnection scon = new SqlConnection(ConfigurationManager.AppSettings["MyCartConnKEy"]))
//{
string FileDirectory = Server.MapPath("Database/admin.mdb");
OleDbConnection ocon = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + FileDirectory.ToString() + "");
//OleDbConnection ocon = new OleDbConnection();
try
{
string status = Request.QueryString["setStatus"].ToString();
string id = Request.QueryString["um_id"].ToString();
ocon.Open();
string str = "update Project_master set Project_status='" + status + "' where Project_id=" + id + "";
// SqlCommand updatecom = new SqlCommand(str, scon);
OleDbCommand ocom = new OleDbCommand(str, ocon);
ocom.ExecuteNonQuery();
Response.Redirect("ViewProject.aspx");

}
catch (OleDbException ex)
{
Response.Write(ex.Message.ToString());

}
finally
{
ocon.Close();

}


//}

}

RowDataBound_ FillGrid !!

protected void GridDisplayCat_RowDataBound(object sender, GridViewRowEventArgs e)
{
{
if (e.Row.RowType == DataControlRowType.DataRow || e.Row.RowType == DataControlRowType.Separator)
{

//Label lbldate = (Label)e.Row.Cells[1].FindControl("lbldate");
// DateTime dt = Convert.ToDateTime(lbldate.Text);
// lbldate.Text = dt.ToString("dd/MM/yyyy");

// Label lblEdate = (Label)e.Row.Cells[1].FindControl("lblEdate");
// DateTime dt1 = Convert.ToDateTime(lblEdate.Text);
// lblEdate.Text = dt1.ToString("dd/MM/yyyy");

Label lblstatus = (Label)e.Row.Cells[1].FindControl("lblstatus");
Label lblid = (Label)e.Row.Cells[2].FindControl("lblid");
string status = lblstatus.Text.ToString();
string id = lblid.Text.ToString();
if (status.ToString() == "Yes")
{
e.Row.Cells[1].Text = "\"Click";
}
else
{
e.Row.Cells[1].Text = "\"Click";
}

}
}

}

Fill Grid !!

private void fillGrid()
{
string FileDirectory = Server.MapPath("Database/admin.mdb");
OleDbConnection ocon = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + FileDirectory.ToString() + "");
//OleDbConnection ocon = new OleDbConnection();
try
{
ocon.Open();
string str = "select *,User_name from (Project_master inner join User_Master on Project_master.User_id=User_Master.User_id ) "+" " +
" inner join Client_master on Project_master.Client_id=Client_master.Client_id order by Project_id desc";
// String str = "select *,User_name from Project_master inner join User_Master on Project_master.User_id=User_Master.User_id order by Project_id desc";
OleDbDataAdapter osap = new OleDbDataAdapter(str, ocon);

DataSet ds = new DataSet();
osap.Fill(ds, "temp");
GridDisplayCat.DataSource = ds;
GridDisplayCat.DataBind();


}
catch (Exception ex)
{
Response.Write(ex.Message.ToString());
}

}

Edit Procedure !!

CREATE Procedure EditCat
(
@catname Varchar(100),
@catid int
)
AS
update tblMainCat set
Cat_Name=@catname
where cat_id=@catid


GO

UpdateProcedure !!

CREATE Procedure UpdateProcedure
(
@firstname varchar(50),
@lastname varchar(50),
@address Varchar(100),
@city Varchar(50),
@state Varchar(50),
@pincode Varchar(20),
@EmailId Varchar(80),
@customerid int
)
AS
Update Registration set
customesr_firstname=@firstname,
customers_lastname= @lastname,
customers_address=@address,
customers_city= @city,
customers_state=@state,
customers_zipcode= @pincode ,
customers_email_address= @EmailId
where customers_id=@customerid


GO

UpdateProductProcedure !!

CREATE Procedure UpdateProductProcedure
(
@ProductName varchar(50),
@ProductPrice varchar(50),
@ProductDescription Varchar(100),
@Productid int

)
AS
update tblProduct_Master set

Product_Name=@ProductName,
Product_Price=@ProductPrice,
Product_desc=@ProductDescription
where Product_id=@Productid
GO

Insert Procedure !!

/*
Procedure Name :invoiceInsert
Description : This Procedure is Inserting the Invoice details
Created By: Chandrashekhar Dhingra
Creation Date :25/03/2008
*/

CREATE PROCEDURE invoiceInsert
(
@comdName varchar(50),
@vatD3 varchar(50),
@buyName varchar(50),
@bAddress varchar(500),
@bCity varchar(50),
@bState varchar(50),
@bPincode varchar(20),
@bCountry varchar(50),
@bEcc varchar(50),
@bTin varchar(50),
@conName varchar(50),
@cAddress varchar(500),
@cCity varchar(50),
@cState varchar(50),
@cPincode varchar(50),
@cCountry varchar(50),
@cEcc varchar(50),
@cTin varchar(50),
@ordNo varchar(50),
@ordDate datetime,
@confNo varchar(50),
@conDate datetime,
@rlNo varchar(50),
@rlDate datetime,
@destination varchar(50),
@transport varchar(50),
@transMode varchar(50),
@transTerms varchar(50),
@eCess float,
@tolPac varchar (50),
@she float,
@vat float,
@freight float,
@id int output
)
AS
insert into tblInvoiceDisplay
(
invoice_exComdName,
invoice_vatD3,
invoice_buyName,
invoice_bAddress,
invoice_bCity,
invoice_bState,
invoice_bPincode,
invoice_bCountry,
invoice_bEcc,
invoice_bTin,
invoice_conName,
invoice_cAddress,
invoice_cCity,
invoice_cState,
invoice_cPincode,
invoice_cCountry,
invoice_cEcc,
invoice_cTin,
invoice_ordNo,
invoice_ordDate,
invoice_confNo,
invoice_conDate,
invoice_rlNo,
invoice_rlDate,
invoice_dest,
invoice_transport,
invoice_transMode,
invoice_transTerms,
invoice_eCess,
invoice_tolpacl,
invoice_she,
invoiceAddVar,
invoice_freight
)
Values
(

@comdName,
@vatD3,
@buyName,
@bAddress,
@bCity,
@bState,
@bPincode,
@bCountry,
@bEcc,
@bTin,
@conName,
@cAddress,
@cCity,
@cState,
@cPincode,
@cCountry,
@cEcc,
@cTin,
@ordNo,
@ordDate,
@confNo,
@conDate,
@rlNo,
@rlDate,
@destination,
@transport,
@transMode,
@transTerms,
@eCess,
@tolPac,
@she,
@vat,
@freight
)
Select @id=Max(invoice_id) from tblInvoiceDisplay
GO

Insert Procedure !!

/*
Procedure Name :customerInsert
Description : This Procedure is Inserting the Customer details
Created By: Chandrashekhar Dhingra
Creation Date :24/03/2008
*/

CREATE PROCEDURE customerInsert
(
@custName varchar(100),
@custAdd varchar(500),
@custCity varchar(100),
@custState varchar(100),
@custPin varchar(20),
@custCountry varchar(100),
@custEcc varchar(50),
@custTin varchar(50),
@custID varchar(50),
@regDate datetime,
@active varchar(3),
@delete varchar(3)
)
AS
insert into tblCustomerMaster
(

cust_name,
cust_address,
cust_city,
cust_state,
cust_pin,
cust_country,
cust_eccNo,
cust_tinNo,
custom_id,
cust_regDate,
cust_active,
cust_delete
)
values
(
@custName,
@custAdd,
@custCity,
@custState,
@custPin,
@custCountry,
@custEcc,
@custTin,
@custID,
getdate(),
'Yes',
'No'
)
GO

Wednesday, November 11, 2009

GridView's RowCommand !!

Protected void GVMyProdct_RowCommand (object sender, GridViewCommandEventArgs e )
{

GridViewRow Row = (GridViewRow)(Button)e.CommandSource).NamingContainer;
Label lblPrice=(Label)row.FindControl("lblPrice");
if (e.CommandName=="AddCart")
{

}
}

# Command Name is the property of which is inside the

Inside the 's has the properties :

Text = "Add to cart";
Command Name = "AddCart";
Command Argument = '<%#DataBinder.Eval(Containe.DataItem,"Product_id")%>'

How to use for looping in Asp.Net !!

for(int i=0;i{
bool chK((CheckBox)GVMyCart.Row[i]
fndControl("ChkPro")).Checked;


string temid=((Lable)GVMyCart.Row[i];
findControl("lblid").Text;
if (Chk==true)
{
Delete(temid);
BindView();
}
}

How to use Delete Function in Asp.Net !!

Protected void MyCart()
{
string temid=lblid.Text;
Delete(temid);
}


Private void Delete(txtI)
{
scon.open();
string str="Delete from TblMycart where MyCart_id="+txtI+"";

}

How to Use Functions in Asp.net !!

Protected void MyCart()
{
string txtqty=txtCartQty.Text;
string temid=lblid.text;
decimal t;


t=Convert.ToDecimal(tprice.Tostring()* Convert.Tostring.ToDecimal(txtqty.Tostring());


update(txtqty, t.ToString(),temid )

/* update function is called in MyCart Function , and txtqty are actual parameters*/

}

/* update function are Defined here */

private void update(string txtQ, string txtP, string textT)// thies ar formal parametes

{

ccon.open();
string str= "update tblMyCart set
MyCart_Qty='"+txtQ+"', MyCart_Price='"+txtP+"'where MyCart_id="+id+";
";

}

Count the row In DataGrid or GridView !!

this.GVMyCount.Rows.Count;

this is used to count the No. of Items (Rows) in the GridView.

Validation is not working in the Page !!

When validation is not working or not being fire , then where we use (Page.IsValid)? Use it at the Button for which you are using.

Use this when validation is not working on the page -

if (Page.IsValid)
{


}

On the Button_Submit.


When we have used validation on the page and validation is not working on Button click. Then use use Page.Isvalid on the Buttion Click.. Like that..

Protected void btnSubmit_Click(Object sender, EventArgs e)

{

if(Page.IsValid)
{

}

}

Date Time

# Date should always present in the user part in the dd/mm/yyyy formate.

# Date should always saved or inserted in the Database MM/dd/yyyy formate.

# Date is always present in the presentation form as - dd/mm/yyyy. So we have to convert it accordingly.

Different Date Time Formate !!

lblDate.Text=DateTime.Today.TolongDateString();

This will show the Formate of Date time like that : Sunday, August 02, 2008

Inset Date Through Query !!

string str = "insert into Registration (cust_id, cust_name, cust_date)

vaues ('"+txtname.Text+"','"+DateTime.Today.Date.Tostring()+"')"

AddNews.aspx !!

Relation Between Insert Procedura and Page ;

Sql cmd =new SqlCommand ("insNews", Sqlcon)
Sqlcmd.CommandType=CommandType.StoreProcedure;
Sqlcmd.Parameters.AddWithVales("@headline",txtHeadline.Text);

string strtxtdate=txtDate.Text.Substring(3,2)+ "/" + txtDate.Text.Substring(0,2)+ "/" + txtDate.Text.Substring(6,4);

Sqlcmd.Parameters.Addwithvalue("@date",strtxtdate.ToString());

Sqlcmd.Parameters.Addwithvale("@active","");
Sqlcmd.Parameters.Addwithvalue("@delete","");

strImage=System.IO.Path.GetFileName(uploadImage.Post.PostedFile.fileName);

string savelocation= server.Mathpath("upload")+ "\" strImage;

uploadImage.Postfile.SaveAs(Savelocation);

Sqlcmd.Paremeters.Addwithvales("@image", stringImage.Tostring());

Insert Procedure !!

CREATE PROCEDURE insNews
(
@headline varchar (50),
@date datetime,
@active varchar(3),
@delete varchar (3),
@image varchar (50),

)

as

inseart into tblNewsMaster

(
nm_headline,
nm_date,
nm_activce,
nm_delete,
image
)

values

(
@headline,
@date,
'Yes'
'No'
@Image

)

Go

Update Procedure !!

CREATE PROCEDURE adminprojectupdate
(
@code varchar (50),
@startdate datetime,
@enddate datetime,
@amount varchar(50),
@title varchar (50),
@client varchar (200),
@des varchar (200),
pid int

)
as
update tblprojectmaster

pr_code=@code,
pr_startDate=@startDate,
pr_endDate=@amont,
pr_title=@title,
pr_client=@client,
pr_desc=@desc;

where pr_id=@pid

Go

Converting int to Floating !!

float Total = float.Parse(session["total.Tostring()"])

Tuesday, August 25, 2009

What is the difference between int.parse() and convert.int32()

If we want to convert a string value (Lets say we have a string “23”) to integer we have 2 options. One is to use the Int.Parse method and other is to use the Convert.ToInt32.

The real query with every one was what is the difference between the two. The answer is null handling. The difference between the 2 is the manner in which null is handled. If you pass a null value to convert.ToInt32 method it will return back 0. But the same is not true with Int.Parse. If we pass null to Int.Parse method it will throw an ArgumentNullException exception.

Although Convert.ToInt32 method does not throw an exception but it can have a big drawbacks. If you use it on a query string value(where u are also expecting the value 0) then the Convert.ToInt32 might cause programmatic error.

######################################################################################


The difference lies in the way both handles NULL value.

When encountered a NULL Value, Convert.ToInt32 returns a value 0. On other hand,Parse is more sensitive and expects a valid value. So it would throw an exception when you pass in a NULL.

string stringInt = "01234";

int iParse = int.Parse(stringInt);

int iConvert = Convert.ToInt32(stringInt);


##################################################################################3

string MyString = "12345";
int MyInt = int.Parse(MyString);
MyInt++;
Console.WriteLine(MyInt);
// The result is "12346".

#################################################################################
int.Parse for Integer Conversion in C#
--------------------------------------

1. Using int.Parse

First, here we see the int.Parse method. int.Parse is the simplest method, and is also the author's favorite for many situations. It throws exceptions on invalid input, which can be slow if they are common. It is does not contain any internal null checks.

=== Example program that uses int.Parse (C#) ===

using System;

class Program
{
static void Main()
{
// Convert string to number.
string text = "500";
int num = int.Parse(text);
Console.WriteLine(num);
}
}

=== Output of the program ===

500


2. Using Convert.ToInt32

Third, we look at the Convert.ToInt32 method. Convert.ToInt32, along with its siblings Convert.ToInt16 and Convert.ToInt64, is actually a static wrapper method for the int.Parse method. It can be slower than int.Parse if the surrounding code is equivalent.

=== Example program that uses Convert.ToInt32 (C#) ===

using System;

class Program
{
static void Main()
{
// Convert 'text' string to an integer with Convert.ToInt32.
string text = "500";
int num = Convert.ToInt32(text);
Console.WriteLine(num);
}
}

=== Output of the program ===

500


3. Which method should I use?

The it's recommendation is to use int.Parse when your input will be valid, as it makes for simpler calling code. It isn't always perfect, but it is a winner. On the other hand, use int.TryParse when you will be dealing with corrupt data.


Good Website : http://dotnetperls.com/datetime-1

Friday, August 14, 2009

What is ItemCommand ?

Dev Palmistry

DataGrid.ItemCommand Event


System.Web.UI.WebControls Namespace DataGrid Class

Occurs when a button within a DataGrid control is clicked.

[ VB ]
Public Event ItemCommand As DataGridCommandEventHandler

[ C# ]
public event DataGridCommandEventHandler ItemCommand;

[ C++ ]
public: __event DataGridCommandEventHandler* ItemCommand;

In [ JScript ], you can handle the events defined by a class, but you cannot define your own.
Remarks

The ItemCommand event is raised whenever any button associated with an item in the DataGrid is clicked. This provides for programmatically determining which specific command button is clicked and take appropriate action. This event is commonly used to handle button controls with a given CommandName value in the DataGrid control.
Event Data

Information related to the ItemCommand event is passed via a DataGridCommandEventArgs object to the method assigned to handle the event. The following DataGridCommandEventArgs properties provide information specific to this event.
Property Description
CommandSource Gets the source of the command.
Item Gets the DataGridItem associated with the event.

What is the namespace of StringBuilder ?

The System.Text is the namespace are used in StringBuilder

The System.Text.StringBuilder class can be used when you want to modify a string without creating a new object. For example, using the StringBuilder class can boost performance when concatenating many strings together in a loop.

You can create a new instance of the StringBuilder object by initializing your variable with one of the overloaded constructor methods, as illustrated in the following code example.


[ C# ]
StringBuilder myStringBuilder = new StringBuilder ( "Hello World!" );