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_Add : System.Web.UI.Page { SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["CMSConnectionString"].ToString()); SqlConnection CONADD = new SqlConnection(ConfigurationManager.ConnectionStrings["CMSConnectionString"].ToString()); protected void Page_Load(object sender, EventArgs e) { if (! IsPostBack) { Grddata.Visible = false; } } protected void btnAdd2_Click(object sender, EventArgs e) { AddRecord(); } private void AddRecord() { String MainLink = "حدث خطأ في التحميل"; string xadmin = Session["AddNew"].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; //Zip File Save On ServerSide. if (File.Exists(fullpath)) { lblerror0.Text = "يوجد ملف بنفس الاسم من فضلك غير اسم المادة"; return; } FUlUpload.SaveAs(fullpath); MainLink = fullpath.ToString(); } } if (CBLWay.SelectedValue == "2") { MainLink = txtUrl.Text; } // = , == " + SqlCommand cmdInsert = new SqlCommand("insert into Materials(Name,Type,URL,Detail,UserInfo)" + " Values(N'" + txtName.Text + "',N'" + RBLTYPE.SelectedValue + "',N'" + MainLink + "',N'" + txtDesc.Text + "'" + "," + Session["User"].ToString() + ")", con); if (con.State == ConnectionState.Closed) con.Open(); cmdInsert.ExecuteNonQuery(); con.Close(); lblerror2.Text = "تم إضافة البيان الجديد"; grdtbl0.DataBind(); txtUrl.Text = ""; txtDesc.Text = ""; RBLTYPE.ClearSelection(); } catch (Exception ex) { lblerror2.Text = "حدث خطأ كالتالي " + ex.ToString(); return; } } else lblerror2.Text="ليس لك الصلاحية في هذا الاجراء"; } protected void btnreturn_Click(object sender, EventArgs e) { Response.Redirect("Materials.aspx"); } 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 grdtbl0_SelectedIndexChanged(object sender, EventArgs e) { Session["MatConfirm"] = grdtbl0.SelectedRow.Cells[0].Text.ToString(); try { SqlCommand cmdInsert = new SqlCommand("insert into Material_Trust(UserTrust,Material,UpdateDate,Staus)" + " Values(6," + Session["MatConfirm"].ToString() + ",N'" + DateTime.Now.ToString("d") + "' , 0 )", con); if (con.State == ConnectionState.Closed) con.Open(); cmdInsert.ExecuteNonQuery(); con.Close(); SqlCommand cmdInsert2 = new SqlCommand("insert into Material_Trust(UserTrust,Material,UpdateDate,Staus)" + " Values(49," + Session["MatConfirm"].ToString() + ",N'" + DateTime.Now.ToString("d") + "' , 0 )", con); if (con.State == ConnectionState.Closed) con.Open(); cmdInsert2.ExecuteNonQuery(); con.Close(); SqlCommand cmdInsert3 = new SqlCommand("insert into Material_Trust(UserTrust,Material,UpdateDate,Staus)" + " Values(45," + Session["MatConfirm"].ToString() + ",N'" + DateTime.Now.ToString("d") + "' , 0 )", con); if (con.State == ConnectionState.Closed) con.Open(); cmdInsert3.ExecuteNonQuery(); con.Close(); SqlCommand cmdInsert4 = new SqlCommand("insert into Material_Trust(UserTrust,Material,UpdateDate,Staus)" + " Values(21," + Session["MatConfirm"].ToString() + ",N'" + DateTime.Now.ToString("d") + "' , 0 )", con); if (con.State == ConnectionState.Closed) con.Open(); cmdInsert4.ExecuteNonQuery(); con.Close(); } catch (Exception ex) { Response.Write(ex.ToString()); } lblfrom.Visible = true; Grddata.DataBind(); Grddata.Visible = true; } }