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 re_Edit : System.Web.UI.Page { SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["CMSConnectionString"].ToString()); int muslim; protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { muslim = Convert.ToInt16(Request.QueryString["id"].ToString()); LoadData(muslim); } } private void LoadData(int Code) { LBLSHOW.Text = "تحرير تقرير الحوار الدعوي"; Page.Title = "تحرير تقرير الحوار الدعوي"; try { SqlCommand cmd = new SqlCommand("Select Tit_No1,Tit_No2,Tit_No3,Tit_No4,Tit_No5,Tit_No6,Tit_No7" + ",Le_Day,Le_Month,Le_Year,Le_User From tbl_re where Code=" + Code, con); if (con.State == ConnectionState.Closed) con.Open(); SqlDataReader dr = cmd.ExecuteReader(); dr.Read(); if (dr.HasRows) { if (!dr.IsDBNull(0)) { txtTit_No1.Text = dr["Tit_No1"].ToString(); } if (!dr.IsDBNull(1)) { txtTit_No2.Text = dr["Tit_No2"].ToString(); } if (!dr.IsDBNull(2)) { txtTit_No3.Text = dr["Tit_No3"].ToString(); } if (!dr.IsDBNull(3)) { txtTit_No4.Text = dr["Tit_No4"].ToString(); } if (!dr.IsDBNull(4)) { txtTit_No5.Text = dr["Tit_No5"].ToString(); } if (!dr.IsDBNull(5)) { txtTit_No6.Text = dr["Tit_No6"].ToString(); } if (!dr.IsDBNull(6)) { txtTit_No7.Text = dr["Tit_No7"].ToString(); } if (!dr.IsDBNull(7)) { DrpDay.SelectedValue = dr["Le_Day"].ToString(); } if (!dr.IsDBNull(8)) { DrpMonth.SelectedValue = dr["Le_Month"].ToString(); } if (!dr.IsDBNull(9)) { txtYear.Text = dr["Le_Year"].ToString(); } if (!dr.IsDBNull(10)) { DrpwhoName.SelectedValue = dr["Le_User"].ToString(); } } dr.Close(); con.Close(); } catch (Exception ex) { lblerror2.Text = "حدث خطأ كالتالي " + ex.ToString(); throw; } } private void UpdateData(int Code) { string xadmin = Session["Edit"].ToString(); if (xadmin == "True") { try { if (txtYear.Text == "") { txtYear.Text = "1435"; } SqlCommand cmdInsert = new SqlCommand("Update tbl_re set Tit_No1=" + txtTit_No1.Text + "," + "Tit_No2=" + txtTit_No2.Text + ",Tit_No3=" + txtTit_No3.Text + ",Tit_No4=" + txtTit_No4.Text + "" + ",Tit_No5=" + txtTit_No5.Text + ",Tit_No6=" + txtTit_No6.Text + ",Tit_No7=" + txtTit_No7.Text + "," + "Le_Day=N'" + DrpDay.SelectedValue + "'" + ",Le_Month=N'" + DrpMonth.SelectedValue + "',Le_Year=N'" + txtYear.Text + "' " + " where Code=" + Code, con); if (con.State == ConnectionState.Closed) con.Open(); cmdInsert.ExecuteNonQuery(); con.Close(); lblerror2.Text = "تم تحديث البيانات"; } catch (Exception ex) { lblerror2.Text = "حدث خطأ كالتالي " + ex.ToString(); return; } } else lblerror2.Text = "ليس لك الصلاحية في هذا الاجراء"; } protected void btnAdd2_Click(object sender, EventArgs e) { string xadmin = Session["Edit"].ToString(); if (xadmin == "True") { muslim = Convert.ToInt16(Request.QueryString["id"].ToString()); UpdateData(muslim); LoadData(muslim); } else lblerror2.Text = "ليس لك الصلاحية في هذا الاجراء"; } protected void btnreturn_Click(object sender, EventArgs e) { Response.Redirect("re.aspx"); } protected void btnDelete_Click(object sender, EventArgs e) { string xadmin = Session["P_Delete"].ToString(); if (xadmin == "True") { try { muslim = Convert.ToInt16(Request.QueryString["id"].ToString()); SqlCommand cmdInsert = new SqlCommand("Delete From tbl_re " + " where Code=" + muslim, con); if (con.State == ConnectionState.Closed) con.Open(); cmdInsert.ExecuteNonQuery(); con.Close(); lblerror2.Text = "تم حذف البيانات"; txtYear.Text = ""; DrpMonth.ClearSelection(); DrpDay.ClearSelection(); txtTit_No1.Text = "0"; txtTit_No2.Text = "0"; txtTit_No3.Text = "0"; txtTit_No4.Text = "0"; txtTit_No5.Text = "0"; txtTit_No6.Text = "0"; txtTit_No7.Text = "0"; } catch (Exception ex) { lblerror2.Text = "حدث خطأ كالتالي " + ex.ToString(); return; } } else lblerror2.Text = "ليس لك الصلاحية في هذا الاجراء"; } }