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 Companies_Add : System.Web.UI.Page { SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["CMSConnectionString"].ToString()); protected void Page_Load(object sender, EventArgs e) { string xadmin = "False"; if (Session["admin"] != null) xadmin = Session["admin"].ToString(); if (!IsPostBack) { if ((xadmin == "False") || (Session["admin"] == null)) Response.Redirect("Home.aspx"); } } protected void btnShowDis_Click(object sender, EventArgs e) { DrpSaudiDis.Enabled = true; DrpSaudiDis.DataBind(); } protected void btnAdd_Click(object sender, EventArgs e) { try { if (Page.IsValid) { string xadmin = Session["admin"].ToString(); if (xadmin == "True") { SqlCommand cmd = new SqlCommand("Select Code From Companies where Com_Name=N'" + txtName.Text + "' ", con); if (con.State == ConnectionState.Closed) con.Open(); SqlDataReader dr = cmd.ExecuteReader(); dr.Read(); if (dr.HasRows) { lblerror2.Text = "هذه الشركة أو المؤسسة مضافة من قبل"; ; dr.Close(); con.Close(); return; } dr.Close(); con.Close(); SqlCommand cmdInsert = new SqlCommand("insert into Companies(Com_Name,Com_Work,Com_City,Com_Dis,Com_Address,Com_Mobile,Com_Phone,Com_Fax," + "Com_Email,Com_EmpNo,Com_User) " + " Values(N'" + txtName.Text + "' , N'" + txtWork.Text + "'," + DrpCity.SelectedValue + "," + DrpSaudiDis.SelectedValue + "," + " N'" + txtaddress.Text + "',N'" + txtMobile.Text + "',N'" + txtphone.Text + "' ,N'" + txtfax.Text + "' ," + " N'" + txtEmail.Text + "',N'" + txtEmpNo.Text + "'," + " " + Session["User"].ToString() + ")", con); if (con.State == ConnectionState.Closed) con.Open(); //Response.Write(cmdInsert.CommandText.ToString()); cmdInsert.ExecuteNonQuery(); con.Close(); lblerror2.Text = "تم إضافة بيانات الشركة أو المؤسسة"; txtName.Text = ""; txtMobile.Text = ""; txtaddress.Text = ""; txtEmail.Text = ""; txtphone.Text = ""; txtfax.Text = ""; txtEmpNo.Text = ""; txtWork.Text = ""; DrpCity.ClearSelection();//الجنسية DrpSaudiDis.ClearSelection(); } con.Close(); } } catch { lblerror2.Text = "حدث خطأ حاول مرة أخري"; return; } } protected void btnreturn_Click(object sender, EventArgs e) { Response.Redirect("Companies.aspx"); } }