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 AddCD : 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 btnAdd_Click(object sender, EventArgs e) { if (Page.IsValid) { string xadmin = Session["admin"].ToString(); if (xadmin == "True") { SqlCommand cmd = new SqlCommand("Select Code From DisTaha where Name=N'" + txtName.Text + "' and City=" + DrpCity.SelectedValue + "", con); if (con.State == ConnectionState.Closed) con.Open(); SqlDataReader dr = cmd.ExecuteReader(); dr.Read(); if (dr.HasRows) { lblerror.Text = "هذه المقاطعة مضافة من قبل"; ; dr.Close(); con.Close(); return; } dr.Close(); con.Close(); SqlCommand cmdInsert2 = new SqlCommand("Insert into DisTaha(Name ,City,Vline,Hline ) Values (N'" + txtName.Text + "' ," + DrpCity.SelectedValue + ""+ " ,N'" + txtNameV.Text + "',N'" + txtNameH.Text + "')", con); if (con.State == ConnectionState.Closed) con.Open(); cmdInsert2.ExecuteNonQuery(); lblerror.Text = "تم إضــافة المقاطعة"; txtName.Text = ""; DataBind(); con.Close(); } con.Close(); } } }