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_Add : System.Web.UI.Page { SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["CMSConnectionString"].ToString()); protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { DrpwhoAdd.SelectedValue = Session["User"].ToString(); } } protected void btnAdd2_Click(object sender, EventArgs e) { AddRecord(); Cleartxt(); } private void AddRecord() { string xadmin = Session["admin"].ToString(); if (xadmin == "True") { try { if (txtYear.Text == "") { txtYear.Text = "1435"; } if (txtNo.Text == "") { return; } 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) { lblerror2.Text = "هذه المادة مدخلة من قبل"; dr.Close(); con.Close(); return; } else { dr.Close(); con.Close(); SqlCommand cmdInsert = new SqlCommand("insert into tbl_NewView(Le_Name,Le_Month,Le_Year,Le_User,Le_UserAdd,Le_hourse,Le_mi,Le_type)" + " Values(N'" + txtNo.Text + "',N'" + DrpMonth.SelectedValue + "',N'" + txtYear.Text + "'," + " " + Session["User"].ToString() + "," + DrpwhoAdd.SelectedValue + "," + txthours.Text + "," + txtmi.Text + ",N'" + DrpType.SelectedValue + "')", 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; } } else Response.Redirect("Home.aspx"); } private void Cleartxt() { } protected void btnreturn_Click(object sender, EventArgs e) { Response.Redirect("NewView.aspx"); } }