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 Activity_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 { string Act_Design, Act_Montag, Act_Prepair, Act_Cat, Act_Review, Act_Search, Act_Edit, Act_Write, Act_Select, Act_other, Act_Meeting, Act_Visitor; SqlCommand cmd = new SqlCommand("Select Act_Design,Act_Montag,Act_Prepair,Act_Cat,Act_Review,Act_Search,Act_Edit," + "Act_Write,Act_Select,Act_other,Act_Desc,Le_Month,Le_Year,Le_User,Act_Meeting,Act_Visitor From tbl_Activity where Code=" + Code, con); if (con.State == ConnectionState.Closed) con.Open(); SqlDataReader dr = cmd.ExecuteReader(); dr.Read(); if (dr.HasRows) { Act_Design = dr["Act_Design"].ToString(); if (Act_Design=="1") { RBAct_Design.Checked = true; } else RBAct_Design.Checked = false; Act_Montag = dr["Act_Montag"].ToString(); if (Act_Montag == "1") { RBAct_Montag.Checked = true; } else RBAct_Montag.Checked = false; Act_Prepair = dr["Act_Prepair"].ToString(); if (Act_Prepair == "1") { RBAct_Prepair.Checked = true; } else RBAct_Prepair.Checked = false; Act_Cat = dr["Act_Cat"].ToString(); if (Act_Cat == "1") { RBAct_Cat.Checked = true; } else RBAct_Cat.Checked = false; Act_Review = dr["Act_Review"].ToString(); if (Act_Review == "1") { RBAct_Review.Checked = true; } else RBAct_Review.Checked = false; Act_Search = dr["Act_Search"].ToString(); if (Act_Search == "1") { RBAct_Search.Checked = true; } else RBAct_Search.Checked = false; Act_Edit = dr["Act_Edit"].ToString(); if (Act_Edit == "1") { RBAct_Edit.Checked = true; } else RBAct_Edit.Checked = false; Act_Write = dr["Act_Write"].ToString(); if (Act_Write == "1") { RBAct_Write.Checked = true; } else RBAct_Write.Checked = false; Act_Select = dr["Act_Select"].ToString(); if (Act_Select == "1") { RBAct_Select.Checked = true; } else RBAct_Select.Checked = false; Act_other = dr["Act_other"].ToString(); if (Act_other == "1") { RBAct_other.Checked = true; } else RBAct_other.Checked = false; DrpMonth.SelectedValue = dr["Le_Month"].ToString(); txtDesc.Text = dr["Act_Desc"].ToString(); txtYear.Text = dr["Le_Year"].ToString(); DrpwhoName.SelectedValue = dr["Le_User"].ToString(); Act_Meeting = dr["Act_Meeting"].ToString(); if (Act_Meeting == "1") { RBAct_Meeting.Checked = true; } else RBAct_Meeting.Checked = false; Act_Visitor = dr["Act_Visitor"].ToString(); if (Act_Visitor == "1") { RBAct_Visitor.Checked = true; } else RBAct_Visitor.Checked = false; } 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 { int Act_Design = 0, Act_Montag = 0, Act_Prepair = 0, Act_Cat = 0, Act_Review = 0, Act_Search = 0, Act_Edit = 0, Act_Write = 0, Act_Select = 0, Act_other = 0, Act_Meeting = 0, Act_Visitor = 0; if (txtYear.Text == "") { txtYear.Text = "1435"; } if (txtDesc.Text == "") { txtDesc.Text = "لم يتم اضافة وصف"; } if (RBAct_Design.Checked == true) { Act_Design = 1; } if (RBAct_Montag.Checked == true) { Act_Montag = 1; } if (RBAct_Prepair.Checked == true) { Act_Prepair = 1; } if (RBAct_Cat.Checked == true) { Act_Cat = 1; } if (RBAct_Review.Checked == true) { Act_Review = 1; } if (RBAct_Search.Checked == true) { Act_Search = 1; } //Act_Edit = 0, Act_Write = 0, Act_Select = 0, Act_other = 0; if (RBAct_Edit.Checked == true) { Act_Edit = 1; } if (RBAct_Write.Checked == true) { Act_Write = 1; } if (RBAct_Select.Checked == true) { Act_Select = 1; } if (RBAct_other.Checked == true) { Act_other = 1; } if (RBAct_Meeting.Checked == true) { Act_Meeting = 1; } if (RBAct_Visitor.Checked == true) { Act_Visitor = 1; } // = , == " + SqlCommand cmdInsert = new SqlCommand("Update tbl_Activity set Act_Design=" + Act_Design + ",Act_Montag=" + Act_Montag + " ," + " Act_Prepair=" + Act_Prepair + ",Act_Cat=" + Act_Cat + ",Act_Review=" + Act_Review + ",Act_Search=" + Act_Search + ",Act_Edit=" + Act_Edit + "," + "Act_Write=" + Act_Write + ",Act_Select=" + Act_Select + ",Act_other=" + Act_other + ",Act_Desc=N'" + txtDesc.Text + "'," + "Le_Month=N'" + DrpMonth.SelectedValue + "',Le_Year=N'" + txtYear.Text + "',Le_User=" + Session["User"].ToString() + " " + " ,Act_Meeting=" + Act_Meeting + ",Act_Visitor=" + Act_Visitor + " 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("Activity.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_Activity " + " where Code=" + muslim, con); if (con.State == ConnectionState.Closed) con.Open(); cmdInsert.ExecuteNonQuery(); con.Close(); lblerror2.Text = "تم حذف البيانات"; txtYear.Text = ""; DrpMonth.ClearSelection(); } catch (Exception ex) { lblerror2.Text = "حدث خطأ كالتالي " + ex.ToString(); return; } } else lblerror2.Text = "ليس لك الصلاحية في هذا الاجراء"; } }