using System; using System.Collections; using System.Configuration; using System.Data; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Data.SqlClient; public partial class Companies_Edit : System.Web.UI.Page { SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["CMSConnectionString"].ToString()); int Companies; protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { Companies = Convert.ToInt16(Request.QueryString["id"].ToString()); LoadData(Companies); } } protected void btnShowDis_Click(object sender, EventArgs e) { DrpSaudiDis.Enabled = true; DrpSaudiDis.DataBind(); } private void LoadData(int Code) { try { SqlCommand cmd = new SqlCommand("Select * From Companies where Code=" + Code, con); if (con.State == ConnectionState.Closed) con.Open(); SqlDataReader dr = cmd.ExecuteReader(); dr.Read(); if (dr.HasRows) { if (!dr.IsDBNull(1)) { txtName.Text = dr["Com_Name"].ToString(); LBLSHOW.Text = "بيانات المتعاون " + dr["Com_Name"].ToString(); Page.Title = "بيانات المتعاون " + dr["Com_Name"].ToString(); } if (!dr.IsDBNull(2)) { txtWork.Text = dr["Com_Work"].ToString(); } if (!dr.IsDBNull(3)) { DrpCity.SelectedValue = dr["Com_City"].ToString(); DrpSaudiDis.DataBind(); } if (!dr.IsDBNull(4)) { DrpSaudiDis.SelectedValue = dr["Com_Dis"].ToString(); } if (!dr.IsDBNull(5)) { txtaddress.Text = dr["Com_Address"].ToString(); } if (!dr.IsDBNull(6)) { txtMobile.Text = dr["Com_Mobile"].ToString(); } if (!dr.IsDBNull(7)) txtphone.Text = dr["Com_Phone"].ToString(); if (!dr.IsDBNull(8)) txtfax.Text = dr["Com_Fax"].ToString(); if (!dr.IsDBNull(9)) txtEmail.Text = dr["Com_Email"].ToString(); if (!dr.IsDBNull(10)) txtEmpNo.Text = dr["Com_EmpNo"].ToString(); } dr.Close(); con.Close(); } catch { throw; } } private void UpdateData(int Code) { try { SqlCommand cmdInsert = new SqlCommand("Update Companies set Com_Name=N'" + txtName.Text + "' ,Com_Work=N'" + txtWork.Text + "'" + ",Com_City=" + DrpCity.SelectedValue + ",Com_Dis=" + DrpSaudiDis.SelectedValue + ",Com_Address=N'" + txtaddress.Text + "' " + ",Com_Mobile=N'" + txtMobile.Text + "',Com_Phone=N'" + txtphone.Text + "'," + "Com_Fax=N'" + txtfax.Text + "',Com_Email=N'" + txtEmail.Text + "',Com_EmpNo=N'" + txtEmpNo.Text + "' " + ",Com_User=" + Session["User"].ToString() + "" + " where Code=" + Code, con); if (con.State == ConnectionState.Closed) con.Open(); //Response.Write(cmdInsert.CommandText.ToString()); cmdInsert.ExecuteNonQuery(); con.Close(); lblerror2.Text = "تم تحديث الشركة أو المؤسسة"; } catch (Exception ex) { Response.Write(ex.ToString()); return; } } protected void btnAdd2_Click(object sender, EventArgs e) { try { string xadmin = Session["admin"].ToString(); if (xadmin == "True") { Companies = Convert.ToInt16(Request.QueryString["id"].ToString()); UpdateData(Companies); LoadData(Companies); } } catch { throw; } } protected void btnreturn_Click(object sender, EventArgs e) { Response.Redirect("Companies.aspx"); } protected void btnDelete_Click(object sender, EventArgs e) { try { Companies = Convert.ToInt16(Request.QueryString["id"].ToString()); SqlCommand cmdInsert = new SqlCommand("Delete From Companies " + " where Code=" + Companies, con); if (con.State == ConnectionState.Closed) con.Open(); //Response.Write(cmdInsert.CommandText.ToString()); cmdInsert.ExecuteNonQuery(); con.Close(); lblerror2.Text = "تم حذف بيانات الشركة أو المؤسسة"; txtName.Text = ""; txtMobile.Text = ""; txtaddress.Text = ""; txtEmail.Text = ""; txtphone.Text = ""; txtfax.Text = ""; txtEmpNo.Text = ""; txtWork.Text = ""; DrpCity.ClearSelection();//الجنسية DrpSaudiDis.ClearSelection(); } catch (Exception ex) { //Response.Write(ex.ToString()); return; } } }