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 State_Add : System.Web.UI.Page { SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["CMSConnectionString"].ToString()); Int32 ReturnValue = 0; protected void Page_Load(object sender, EventArgs e) { } protected void btnAdd2_Click(object sender, EventArgs e) { AddRecord(); Cleartxt(); } private void AddRecord() { string xadmin = Session["admin"].ToString(); if (xadmin == "True") { try { if (txtCoordinator_Phone.Text=="") { txtCoordinator_Phone.Text = "-"; } if (txtCoordinator_Name.Text == "") { txtCoordinator_Name.Text = "-"; } if (txtPlace_Name.Text == "") { txtPlace_Name.Text = "-"; } if (txtYear.Text == "") { txtYear.Text = "1434"; } if (txtName.Text == "") { return; } string Manual_Date = DrpDate.SelectedValue + "/" + DrpMonth.SelectedValue + "/" + txtYear.Text; SqlCommand cmdInsert = new SqlCommand("insert into TBL_Static (Manual_Date,beneficiary,Country,City,DisName,PlaceIslam,Muslim_No,Type_Muslim," + "Coordinator_Name,Coordinator_Phone,WhatInISlam,User_Input,insert_month,insert_year,Place_Name)" + " Values(N'" + Manual_Date + "' , N'" + txtName.Text + "'," + DrpCountry.SelectedValue + "," + DrpWorkPlace.SelectedValue + "," + " " + DrpSaudiDis.SelectedValue + ",N'" + DrpIslamPlace.SelectedValue + "'," + txtEmail.Text + " ," + " N'" + DrpType_Muslim.SelectedValue + "',N'" + txtCoordinator_Name.Text + "',N'" + txtCoordinator_Phone.Text + "',N'" + DrpWhatinIslam.SelectedValue + "'," + " " + Session["User"].ToString() + "," + DrpMonth.SelectedValue + "," + txtYear.Text + ", " + " N'" + txtPlace_Name.Text + "') SELECT CAST(scope_identity() AS int) AS [SCOPE_IDENTITY]", con); if (con.State == ConnectionState.Closed) con.Open(); //Response.Write(cmdInsert.CommandText.ToString()); ReturnValue = (Int32)cmdInsert.ExecuteScalar(); //cmdInsert.ExecuteNonQuery(); con.Close(); //return (int)ReturnValue; Session["team"] = ReturnValue; String Static_User; if (tblteam.Visible == true) Static_User = DrpTeam.SelectedValue; else Static_User = DrpwhoName.SelectedValue; AddTeam(Session["team"].ToString(),Static_User.ToString() , txtEmail.Text); } catch (Exception ex) { Response.Write(ex.ToString()); return; } } else Response.Redirect("Home.aspx"); } private void Cleartxt() { lblerror2.Text = "تم إضافة الإحصائية"; txtName.Text = ""; txtYear.Text = ""; DrpType_Muslim.ClearSelection(); DrpSaudiDis.ClearSelection(); DrpwhoName.ClearSelection(); DrpMonth.ClearSelection(); DrpDate.ClearSelection(); DrpWorkPlace.ClearSelection(); DrpCountry.ClearSelection(); txtCoordinator_Name.Text = ""; txtCoordinator_Phone.Text = ""; txtPlace_Name.Text = ""; DrpIslamPlace.ClearSelection(); txtEmail.Text = ""; DrpWhatinIslam.ClearSelection(); } protected void btnShowCity_Click(object sender, EventArgs e) { DrpWorkPlace.DataBind(); } protected void btnShowDis_Click(object sender, EventArgs e) { DrpSaudiDis.Enabled = true; DrpSaudiDis.DataBind(); } protected void btnreturn_Click(object sender, EventArgs e) { Response.Redirect("State.aspx"); } protected void IBAddTeam_Click(object sender, ImageClickEventArgs e) { btnAdd2.Visible = false; lblnameuser.Visible = false; DrpwhoName.Visible = false; btnAddFinish.Visible = true; if (Page.IsValid) { AddRecord(); } tblteam.Visible = true; } private void AddTeam(String Static_ID, String Static_User, String Static_Muslim) { string xadmin = Session["admin"].ToString(); if (xadmin == "True") { try { SqlCommand cmdInsert = new SqlCommand("insert into Static_Team(Static_ID,Static_User,Static_Muslim)" + " Values(" + Static_ID + "," + Static_User + "," + Static_Muslim + ")", con); if (con.State == ConnectionState.Closed) con.Open(); //Response.Write(cmdInsert.CommandText.ToString()); cmdInsert.ExecuteNonQuery(); con.Close(); } catch (Exception ex) { Response.Write(ex.ToString()); return; } } else Response.Redirect("Home.aspx"); } protected void BtnTeam_Click(object sender, EventArgs e) { if (Page.IsValid) { try { AddTeam(Session["team"].ToString(), DrpTeam.SelectedValue, txtEmail.Text); GRDTEAM.DataBind(); } catch { throw; } } } protected void btnAddFinish_Click(object sender, EventArgs e) { tblteam.Visible = false; btnAdd2.Visible = true; lblnameuser.Visible = true; DrpwhoName.Visible = true; btnAddFinish.Visible = false; Cleartxt(); } protected void GRDTEAM_SelectedIndexChanged(object sender, EventArgs e) { string xadmin = Session["admin"].ToString(); if (xadmin == "True") { try { SqlCommand cmdDelete = new SqlCommand("Delete Static_Team where Code=" + GRDTEAM.SelectedRow.Cells[1].Text.ToString() + " ", con); if (con.State == ConnectionState.Closed) con.Open(); //Response.Write(cmdInsert.CommandText.ToString()); cmdDelete.ExecuteNonQuery(); con.Close(); GRDTEAM.DataBind(); } catch (Exception ex) { //Response.Write(ex.ToString()); return; } } else Response.Redirect("Home.aspx"); } }