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 NewView_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 Le_Name,Le_Month,Le_Year,Le_User,Le_UserAdd,Le_hourse,Le_mi,Le_type From tbl_NewView where Code=" + Code, con); if (con.State == ConnectionState.Closed) con.Open(); SqlDataReader dr = cmd.ExecuteReader(); dr.Read(); if (dr.HasRows) { if (!dr.IsDBNull(0)) { txtNo.Text = dr["Le_Name"].ToString(); } if (!dr.IsDBNull(1)) DrpMonth.SelectedValue = dr["Le_Month"].ToString(); if (!dr.IsDBNull(2)) txtYear.Text = dr["Le_Year"].ToString(); if (!dr.IsDBNull(3)) DrpwhoName.SelectedValue = dr["Le_User"].ToString(); if (!dr.IsDBNull(4)) DrpwhoAdd.SelectedValue = dr["Le_UserAdd"].ToString(); if (!dr.IsDBNull(5)) txthours.Text = dr["Le_hourse"].ToString(); if (!dr.IsDBNull(6)) txtmi.Text = dr["Le_mi"].ToString(); if (!dr.IsDBNull(7)) DrpType.SelectedValue = dr["Le_type"].ToString(); } dr.Close(); con.Close(); } catch (Exception ex) { lblerror2.Text = "حدث خطأ كالتالي " + ex.ToString(); //throw; } } private void UpdateData(int Code) { try { if (txtYear.Text == "") { txtYear.Text = "1435"; } if (txtNo.Text == "") { return; } string codeTest = ""; SqlCommand cmdSelect = new SqlCommand("select * from tbl_NewView where Le_Name =N'" + txtNo.Text + "' and Le_type =N'" + DrpType.SelectedValue + "'" + " ", con); if (con.State == ConnectionState.Closed) con.Open(); SqlDataReader dr = cmdSelect.ExecuteReader(); dr.Read(); if (dr.HasRows) { codeTest = dr[0].ToString(); dr.Close(); con.Close(); } else { dr.Close(); con.Close(); SqlCommand cmdInsert2 = new SqlCommand("Update tbl_NewView set Le_Name=N'" + txtNo.Text + "'," + "Le_Month=N'" + DrpMonth.SelectedValue + "',Le_Year=N'" + txtYear.Text + "'" + ",Le_User=" + Session["User"].ToString() + ",Le_UserAdd=" + DrpwhoAdd.SelectedValue + ",Le_hourse =" + txthours.Text + " " + " ,Le_mi =" + txtmi.Text + ",Le_type=N'" + DrpType.SelectedValue + "' " + " where Code=" + Code, con); if (con.State == ConnectionState.Closed) con.Open(); cmdInsert2.ExecuteNonQuery(); con.Close(); lblerror2.Text = "تم تحديث البيانات"; return; } if (codeTest== Code.ToString()) { SqlCommand cmdInsert = new SqlCommand("Update tbl_NewView set Le_Name=N'" + txtNo.Text + "'," + "Le_Month=N'" + DrpMonth.SelectedValue + "',Le_Year=N'" + txtYear.Text + "'" + ",Le_User=" + Session["User"].ToString() + ",Le_UserAdd=" + DrpwhoAdd.SelectedValue + ",Le_hourse =" + txthours.Text + " " + " ,Le_mi =" + txtmi.Text + ",Le_type=N'" + DrpType.SelectedValue + "' " + " where Code=" + Code, con); if (con.State == ConnectionState.Closed) con.Open(); cmdInsert.ExecuteNonQuery(); con.Close(); lblerror2.Text = "تم تحديث البيانات"; } else lblerror2.Text = "اسم المادة موجود من قبل"; } catch (Exception ex) { lblerror2.Text = "حدث خطأ كالتالي " + ex.ToString(); return; } } protected void btnAdd2_Click(object sender, EventArgs e) { string xadmin = Session["admin"].ToString(); if (xadmin == "True") { muslim = Convert.ToInt16(Request.QueryString["id"].ToString()); UpdateData(muslim); LoadData(muslim); } } protected void btnreturn_Click(object sender, EventArgs e) { Response.Redirect("NewView.aspx"); } protected void btnDelete_Click(object sender, EventArgs e) { try { muslim = Convert.ToInt16(Request.QueryString["id"].ToString()); SqlCommand cmdInsert = new SqlCommand("Delete From tbl_NewView " + " where Code=" + muslim, con); if (con.State == ConnectionState.Closed) con.Open(); cmdInsert.ExecuteNonQuery(); con.Close(); lblerror2.Text = "تم حذف البيانات"; txtNo.Text = ""; txtYear.Text = ""; DrpMonth.ClearSelection(); } catch (Exception ex) { lblerror2.Text = "حدث خطأ كالتالي " + ex.ToString(); return; } } }