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 Service_Agencies_Edit : System.Web.UI.Page { SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["CMSConnectionString"].ToString()); int Services; protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { Services = Convert.ToInt16(Request.QueryString["id"].ToString()); LoadData(Services); } } private void LoadData(int Code) { try { SqlCommand cmd = new SqlCommand("Select * From Service_Agencies 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["Name"].ToString(); LBLSHOW.Text = "بيانات الجهة الخيرية والخدمية " + dr["Name"].ToString(); Page.Title = "بيانات الجهة الخيرية والخدمية " + dr["Name"].ToString(); } if (!dr.IsDBNull(2)) { RBLWay.SelectedValue = dr["Service_Way"].ToString(); } if (!dr.IsDBNull(3)) { DrpCountry.SelectedValue = dr["Service_Country"].ToString(); DrpCity.DataBind(); } if (!dr.IsDBNull(4)) { DrpCity.SelectedValue = dr["Service_City"].ToString(); } if (!dr.IsDBNull(6)) txtaddress.Text = dr["Service_Address"].ToString(); if (!dr.IsDBNull(7)) txtMobile.Text = dr["Service_Mobile"].ToString(); if (!dr.IsDBNull(8)) txtPhone.Text = dr["Service_Phone"].ToString(); if (!dr.IsDBNull(9)) txtEmail.Text = dr["Service_Email"].ToString(); if (!dr.IsDBNull(11)) txtNote.Text = dr["Service_Note"].ToString(); } dr.Close(); con.Close(); } catch { throw; } } private void UpdateData(int Code) { try { SqlCommand cmdInsert = new SqlCommand("Update Service_Agencies set Name=N'" + txtName.Text + "' ,Service_Way=N'" + RBLWay.SelectedValue + "'" + ",Service_Country=" + DrpCountry.SelectedValue + ",Service_City=" + DrpCity.SelectedValue + " " + ",Service_Address=N'" + txtaddress.Text + "',Service_Mobile=N'" + txtMobile.Text + "'," + "Service_Phone=N'" + txtPhone.Text + "',Service_Email=N'" + txtEmail.Text + "' " + ",Service_Note=N'" + txtNote.Text + "',Service_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") { Services = Convert.ToInt16(Request.QueryString["id"].ToString()); UpdateData(Services); LoadData(Services); } } catch { throw; } } protected void btnShowCity_Click(object sender, EventArgs e) { DrpCity.DataBind(); } protected void btnreturn_Click(object sender, EventArgs e) { Response.Redirect("Service_Agencies.aspx"); } protected void btnDelete_Click(object sender, EventArgs e) { try { Services = Convert.ToInt16(Request.QueryString["id"].ToString()); SqlCommand cmdInsert = new SqlCommand("Delete From Service_Agencies " + " where Code=" + Services, con); if (con.State == ConnectionState.Closed) con.Open(); //Response.Write(cmdInsert.CommandText.ToString()); cmdInsert.ExecuteNonQuery(); con.Close(); lblerror2.Text = "تم حذف بيانات الجهة الخيرية أو الخدمية"; txtName.Text = ""; txtPhone.Text = ""; txtNote.Text = ""; txtMobile.Text = ""; txtaddress.Text = ""; txtEmail.Text = ""; DrpCity.ClearSelection(); DrpCountry.ClearSelection(); RBLWay.ClearSelection(); } catch (Exception ex) { //Response.Write(ex.ToString()); return; } } }