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.Text; public partial class stu_reg_edit : System.Web.UI.Page { SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["CMSConnectionString"].ToString()); protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { LoadData(); tblData.Visible = false; TblEdit.Visible = false; } } private void LoadData() { try { SqlCommand cmd = new SqlCommand("Select Name From tbl_ProgramShow where Code=" + Request.QueryString["code"].ToString(), con); if (con.State == ConnectionState.Closed) con.Open(); SqlDataReader dr = cmd.ExecuteReader(); dr.Read(); if (dr.HasRows) { if (!dr.IsDBNull(0)) { lblName.Text = "التسجيل بالبرنامج 活动申请 " ;//+ dr["Name"].ToString(); Page.Title = "التسجيل بالبرنامج 活动申请 " ;//+ dr["Name"].ToString(); } } dr.Close(); con.Close(); } catch (Exception ex) { lblerror2.Text = "حدث خطأ كالتالي " + ex.ToString(); } } private void LoadDataStudent(String studentID) { try { SqlCommand cmd = new SqlCommand("Select Name,Stu_Email,Stu_No,Stu_Uni,Stu_Fac,Stu_Level,Stu_Mobil,Stu_Wechat,stu_Ename From tbl_StuShow where Stu_No=N'" + studentID.ToString() +"'", con); if (con.State == ConnectionState.Closed) con.Open(); //lblerror2.Text = cmd.CommandText.ToString(); SqlDataReader dr = cmd.ExecuteReader(); dr.Read(); if (dr.HasRows) { if (!dr.IsDBNull(0)) { TextBox1.Text = dr["Name"].ToString(); } if (!dr.IsDBNull(1)) { TextBox3.Text = dr["Stu_Email"].ToString(); } if (!dr.IsDBNull(3)) { DropDownList1.SelectedValue = dr["Stu_Uni"].ToString(); } if (!dr.IsDBNull(4)) { DropDownList2.SelectedValue = dr["Stu_Fac"].ToString(); } if (!dr.IsDBNull(5)) { DropDownList3.SelectedValue = dr["Stu_Level"].ToString(); } if (!dr.IsDBNull(6)) { TextBox4.Text = dr["Stu_Mobil"].ToString(); } if (!dr.IsDBNull(7)) { TextBox5.Text = dr["Stu_Wechat"].ToString(); } if (!dr.IsDBNull(8)) { TextBox2.Text = dr["stu_Ename"].ToString(); } } dr.Close(); con.Close(); } catch (Exception ex) { lblerror2.Text = "حدث خطأ كالتالي " + ex.ToString(); } } //Add new Data to Sysytem protected void btnNew_Click(object sender, EventArgs e) { lblerror2.Text = ""; if (Page.IsValid) { if (txtEmail.Text == "") { txtEmail.Text = "غير متوفر"; } if (txtwechat.Text == "") { txtwechat.Text = "غير متوفر"; } if (txtMobil.Text=="") { txtMobil.Text = "0"; } try { SqlCommand cmdcc = new SqlCommand("Select Code From tbl_StuShow where Stu_No=N'" + txtNO.Text + "'", con); if (con.State == ConnectionState.Closed) con.Open(); SqlDataReader drcc = cmdcc.ExecuteReader(); drcc.Read(); if (drcc.HasRows) { drcc.Close(); lblerror2.Text = "نفس الرقم الجامعي مسجل من قبل"; return; } con.Close(); drcc.Close(); SqlCommand cmdmain = new SqlCommand("insert into tbl_StuShow(Name,Stu_Email,Stu_No,Stu_Uni,Stu_Fac,Stu_Level,Stu_Mobil,Stu_Wechat,stu_Ename)" + " values(N'" + txtname.Text + "',N'" + txtEmail.Text + "',N'" + txtNO.Text + "'," + DrpUniV.SelectedValue + ","+ " " + DrpCollege.SelectedValue + "," + drpLevel.SelectedValue + ",N'" + txtMobil.Text + "',N'" + txtwechat.Text + "',N'" + txtename.Text + "')", con); if (con.State == ConnectionState.Closed) con.Open(); cmdmain.ExecuteNonQuery(); con.Close(); SqlCommand cmd = new SqlCommand("Select Code From tbl_StuShow where Stu_No=N'" + txtNO.Text + "'", con); if (con.State == ConnectionState.Closed) con.Open(); SqlDataReader dr = cmd.ExecuteReader(); dr.Read(); if (dr.HasRows) { String mainstu = dr["Code"].ToString(); dr.Close(); con.Close(); SqlCommand cmdinsert = new SqlCommand("insert into Pro_StuShow(Stu_No,Pro_No) values(" + mainstu + "," + Session["maincode"].ToString() + ")", con); if (con.State == ConnectionState.Closed) con.Open(); cmdinsert.ExecuteNonQuery(); con.Close(); lblerror2.Text = "تم الاشتراك في البرنامج"; Response.Redirect("finish.aspx"); } } catch (Exception ex) { lblerror2.Text = "حدث الخطأ التالي: " + ex.ToString(); } } else lblerror2.Text = "من فضلك تاكد من ادخال جميع البيانات"; } //هل موجود ام تسجيل جديد للبيانات protected void btnReg_Click(object sender, EventArgs e) { lblerror2.Text = ""; if (txtNO.Text == "") { lblerror2.Text = "من فضلك ادخل الرقم الجامعي"; return; } if (Session["CAPTCHA"].ToString().Equals(txtCaptcha.Text)) { String mainstu; try { SqlCommand cmd = new SqlCommand("Select Code From tbl_StuShow where Stu_No=N'" + txtNO.Text + "'", con); if (con.State == ConnectionState.Closed) con.Open(); SqlDataReader dr = cmd.ExecuteReader(); dr.Read(); if (dr.HasRows) { mainstu = dr["Code"].ToString(); dr.Close(); con.Close(); SqlCommand cmdd = new SqlCommand("Select Code From Pro_StuShow where Stu_No=" + mainstu + " and Pro_No=" + Session["maincode"].ToString() + "", con); if (con.State == ConnectionState.Closed) con.Open(); SqlDataReader drd = cmdd.ExecuteReader(); drd.Read(); if (drd.HasRows) { lblerror.Text = "انت مشترك في هذا البرنامج 你已申请完毕"; drd.Close(); con.Close(); TblEdit.Visible = true; LoadDataStudent(txtNO.Text); tblData.Visible = false; return; } else { drd.Close(); con.Close(); } SqlCommand cmdinsert = new SqlCommand("insert into Pro_StuShow(Stu_No,Pro_No) values(" + mainstu + "," + Session["maincode"].ToString() + ")", con); if (con.State == ConnectionState.Closed) con.Open(); cmdinsert.ExecuteNonQuery(); con.Close(); lblerror.Text = "تم الاشتراك في البرنامج"; TblEdit.Visible = true; LoadDataStudent(txtNO.Text); tblData.Visible = false; } else { dr.Close(); con.Close(); tblData.Visible = true; } } catch (Exception ex) { lblerror2.Text = "حدث الخطأ التالي: " + ex.ToString(); } } else { lblerror2.Text = ""; lblerror2.Text = "من فضلك أدخل بيانات الصورة بشكل صحيح"; } } //Edit Student Data protected void btnEdit_Click(object sender, EventArgs e) { lblerror2.Text = ""; if (Page.IsValid) { if (txtEmail.Text == "") { txtEmail.Text = "غير متوفر"; } if (txtwechat.Text == "") { txtwechat.Text = "غير متوفر"; } if (txtMobil.Text == "") { txtMobil.Text = "0"; } try { SqlCommand cmdmain = new SqlCommand("update tbl_StuShow set Name=N'" + txtname.Text + "',Stu_Email=N'" + txtEmail.Text + "',"+ "Stu_Uni=" + DrpUniV.SelectedValue + ",Stu_Fac=" + DrpCollege.SelectedValue + ",Stu_Level=" + drpLevel.SelectedValue + ","+ "Stu_Mobil=N'" + txtMobil.Text + "',Stu_Wechat=N'" + txtwechat.Text + "',stu_Ename=N'" + txtename.Text + "' where Stu_No=N'" + txtNO.Text + "'" + " ", con); if (con.State == ConnectionState.Closed) con.Open(); cmdmain.ExecuteNonQuery(); con.Close(); lblerror2.Text = "تم تعديل بياناتك بنجاح"; Response.Redirect("finish.aspx"); } catch (Exception ex) { lblerror2.Text = "حدث الخطأ التالي: " + ex.ToString(); } } else lblerror2.Text = "من فضلك تاكد من ادخال جميع البيانات"; } }