Monday, November 16, 2009

EditCompany !!

public partial class EditCompany : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
selectCompDetails();
insertContPerDetail();
//addCountry();
}
private void selectCompDetails()
{
using (SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["conIDLDPL"]))
{
try
{
conn.Open();
string id=Request.QueryString["id"].ToString();
string str = "select * from tblCompanyMaster where comp_id="+id+"";
SqlCommand com = new SqlCommand(str,conn);
SqlDataReader dr = com.ExecuteReader();
if (dr.HasRows)
{
dr.Read();
txtCompName.Text = dr["comp_name"].ToString();
txtaddr1.Text = dr["comp_addr1"].ToString();
txtaddr2.Text = dr["comp_addr2"].ToString();
txtPin.Text = dr["comp_city"].ToString();
DDState.SelectedItem.Text =dr["comp_state"].ToString();
DDCountry.SelectedIndex = DDCountry.Items.IndexOf(DDCountry.Items.FindByValue(dr["comp_country"].ToString()));
txtPin.Text = dr["comp_pin"].ToString();
txtCompPhone.Text = dr["comp_phone"].ToString();
txtCompMobile.Text = dr["comp_mobile"].ToString();
txtCompFax.Text = dr["comp_fax"].ToString();
txtCompEmail.Text = dr["comp_email"].ToString();
txtWebsit.Text = dr["comp_website"].ToString();
txtVatNo.Text = dr["comp_vat_no"].ToString();
txtTin_CstNo.Text = dr["comp_tin_cst_no"].ToString();
}


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

}

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

string str = "select * from tblEmployeeMaster where emp_id=" + DDName.SelectedValue.ToString() + "";
SqlCommand insertCom = new SqlCommand(str, conn);
SqlDataReader dr = insertCom.ExecuteReader();
if (dr.HasRows)
{
dr.Read();
txtContPersName.Text = dr["emp_name"].ToString();
txtDesi.Text = dr["emp_designation"].ToString();
txtCPPhone.Text = dr["emp_phone"].ToString(); ;
txtCPMobile.Text = dr["emp_mobile"].ToString(); ;
txtCPFax.Text = dr["emp_fax"].ToString(); ;
txtCPEmail.Text = dr["emp_email"].ToString(); ;

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

}
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";
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();
}

}

}
protected void tbSubmit_Click(object sender, EventArgs e)
{

}
}

No comments: