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; using System.IO; public partial class Materials_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 Name,Type,URL,Detail,UserInfo" + " From Materials where Code=" + Code, con); if (con.State == ConnectionState.Closed) con.Open(); SqlDataReader dr = cmd.ExecuteReader(); dr.Read(); if (dr.HasRows) { txtDesc.Text = dr["Detail"].ToString(); txtName.Text = dr["Name"].ToString(); DrpwhoName.SelectedValue = dr["UserInfo"].ToString(); lblurlshow.Text = " " + dr["URL"].ToString() + ""; RBLTYPE.SelectedValue = dr["Type"].ToString(); } dr.Close(); con.Close(); } catch (Exception ex) { lblerror2.Text = "حدث خطأ كالتالي " + ex.ToString(); throw; } } private void UpdateData(int Code) { String MainLink = "حدث خطأ في التحميل"; string xadmin = Session["Edit"].ToString(); if (xadmin == "True") { try { if (txtName.Text == "") { return; } if (txtDesc.Text == "") { txtDesc.Text = "لم يتم اضافة وصف"; } if (CBLWay.SelectedValue == "1") { if (FUlUpload.HasFile) { //SqlDataSource1.Insert(); string filename = Path.GetFileName(FUlUpload.FileName); string fullpath = Server.MapPath("~/FileUpload/") + txtName.Text +"_Edit"; //Zip File Save On ServerSide. if (File.Exists(fullpath)) { lblerror0.Text = "يوجد ملف بنفس الاسم من فضلك غير اسم المادة"; return; } FUlUpload.SaveAs(fullpath); MainLink = fullpath.ToString(); } } else if (CBLWay.SelectedValue == "2") { MainLink = txtUrl.Text; } else MainLink = lblurlshow.Text; // = , == " + SqlCommand cmdInsert = new SqlCommand("Update Materials set Name=N'" + txtName.Text + "',Type=N'" + txtDesc.Text + "' ," + " Type=N'" + RBLTYPE.SelectedValue + "',URL=N'" + txtName.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("Materials.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 Materials " + " where Code=" + muslim, con); if (con.State == ConnectionState.Closed) con.Open(); cmdInsert.ExecuteNonQuery(); con.Close(); lblerror2.Text = "تم حذف البيانات"; txtName.Text = ""; txtDesc.Text = ""; RBLTYPE.ClearSelection(); CBLWay.ClearSelection(); } catch (Exception ex) { lblerror2.Text = "حدث خطأ كالتالي " + ex.ToString(); return; } } else lblerror2.Text = "ليس لك الصلاحية في هذا الاجراء"; } protected void CBLWay_SelectedIndexChanged(object sender, EventArgs e) { if (CBLWay.SelectedValue == "1") { lblUpload.Visible = true; FUlUpload.Visible = true; lblUrl.Visible = false; txtUrl.Visible = false; } if (CBLWay.SelectedValue == "2") { lblUpload.Visible = false; FUlUpload.Visible = false; lblUrl.Visible = true; txtUrl.Visible = true; } } protected void grdDocs_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { //------------------ Have Document or Not --------------------- String Act_Design; Act_Design = (String)e.Row.Cells[3].Text; if (Act_Design == "0") e.Row.Cells[3].Text = "في الانتظار"; if (Act_Design == "1") e.Row.Cells[3].Text = "معتمدة"; if (Act_Design == "2") e.Row.Cells[3].Text = "مرفوضة"; } } }