protected void BTNADDED_Click1(object sender, EventArgs e) { int num = 0; string sql = "select * from [DepartmentCourses] where Department='" + Session["Department"] + "' and Year='" + Session["Year"] + "' and Semster='" + Session["Semester"] + "'"; DataTable dt = DBFunctions.SelectFromTable(sql); GridViewRegistering.DataSource = (dt); // DataTable dt1=null; if (((CheckBox)GridViewRegistering.Rows[0].FindControl("CheckBox1")).Checked == true) { string s = dt.Rows[0]["IdCourse"].ToString(); string sql2 = "select * from [DepartmentCourses] where IdCourse= '" + s + "'"; DataTable dt2 = DBFunctions.SelectFromTable(sql2); string muchStudents = dt.Rows[0]["RegisteredStudents"].ToString(); string maxStudent = dt.Rows[0]["MaxStudent"].ToString(); StudentAtCourse c = new StudentAtCourse(s, Session["ID"].ToString()); if (Convert.ToInt32(muchStudents) < Convert.ToInt32(maxStudent)) { if (c.insertCourseForStudent()) { num = Convert.ToInt32(muchStudents) + 1; DepartmentCourses d = new DepartmentCourses(num.ToString(), maxStudent, s); d.UpdateRegisteringStudent(); lblMsn.Visible = true; lblMsn.Text = "Has Been Added"; } else { lblMsn.Visible = true; lblMsn.Text = "Already Exsist!"; } dt1 = DBFunctions.SelectFromTable(sql2); } } for (int i = 1; i < dt.Rows.Count; i++) { if (((CheckBox)GridViewRegistering.Rows[i].FindControl("CheckBox1")).Checked == true) { string s = dt.Rows[i]["IdCourse"].ToString(); string muchStudents = dt.Rows[i]["RegisteredStudents"].ToString(); string maxStudent = dt.Rows[i]["MaxStudent"].ToString(); StudentAtCourse c = new StudentAtCourse(s, Session["ID"].ToString()); if (Convert.ToInt32(muchStudents) < Convert.ToInt32(maxStudent)) { if (c.insertCourseForStudent()) { num = Convert.ToInt32(muchStudents) + 1; DepartmentCourses d = new DepartmentCourses(num.ToString(), maxStudent, s); d.UpdateRegisteringStudent(); lblMsn.Visible = true; lblMsn.Text = "Has Been Added"; } else { lblMsn.Visible = true; lblMsn.Text = "Already Exsist!"; } } else { lblMsn.Visible = true; lblMsn.Text = "There is no place in this course!"; } string sql2 = "select * from [DepartmentCourses] where IdCourse= '" + s + "'"; DataTable dt2 = DBFunctions.SelectFromTable(sql2); if (dt1 == null) { dt1 = dt2; } else { dt1.Merge(dt2); } } } GridViewAdded.DataSource = (dt1); newDt = DBFunctions.CopyDataTable(dt1, dt1.Rows.Count); DataBind(); }
protected void btnCancel_Click1(object sender, EventArgs e) { /* DataTable data=null; * string sql = "select [Id_Course] from [StudentAtCourse] where Id_Student='" + Session["ID"] + "'"; * DataTable dt = DBFunctions.SelectFromTable(sql); * int h = dt.Rows.Count; * if (h>0) * { * string s = dt.Rows[0]["Id_Course"].ToString(); * string year = "select Year from [DepartmentCourses] where IdCourse= '" + s + "'"; * string sem = "select semester from [DeaprtmentCourses] where IdCourse='" + s + "'"; * if(Session["Year"].ToString()==year && Session["Semester"].ToString()==sem) * { * string sql1 = "select * from [DepartmentCourses] where IdCourse='" + s + "'"; * data = DBFunctions.SelectFromTable(sql1); * } * * for(int d = 1; d < h; d++) * { * s = dt.Rows[0]["Id_Course"].ToString(); * year = "select Year from [DepartmentCourses] where IdCourse= '" + s + "'"; * sem = "select semester from [DeaprtmentCourses] where IdCourse='" + s + "'"; * if (Session["Year"].ToString() == year && Session["Semester"].ToString() == sem) * { * string sql2 = "select * from [DepartmentCourses] where IdCourse='" + s + "'"; * DataTable data2 = DBFunctions.SelectFromTable(sql2); * data.Merge(data2); * } * else * { * h = h - 1; * } * * * } * GridViewAdded.DataSource = data; * DataBind(); * * }*/ string sql = "select * from [DepartmentCourses] where Department='" + Session["Department"] + "' and Year='" + Session["Year"] + "' and Semster='" + Session["Semester"] + "'"; DataTable dt = DBFunctions.SelectFromTable(sql); GridViewRegistering.DataSource = (dt); for (int j = 0; j < GridViewAdded.Rows.Count; j++) { if (((CheckBox)GridViewAdded.Rows[j].FindControl("CheckBox1")).Checked == true) { string s = GridViewAdded.Rows[j].ToString(); StudentAtCourse ss = new StudentAtCourse(s, Session["ID"].ToString()); if (ss.DeleteCourseForStudent()) { string muchStudents = dt.Rows[j]["RegisteredStudents"].ToString(); string maxStudent = dt.Rows[j]["MaxStudent"].ToString(); int num = Convert.ToInt32(muchStudents) - 1; DepartmentCourses d = new DepartmentCourses(num.ToString(), maxStudent, s); d.UpdateRegisteringStudent(); lblMsn.Text = "Has Been Deleted"; GridViewAdded.Rows[j].Visible = false; } else { lblMsn.Text = "Is Already not exsist"; } } else { string s = dt.Rows[j]["IdCourse"].ToString(); string sql2 = "select * from [DepartmentCourses] where IdCourse= '" + s + "'"; DataTable dt2 = DBFunctions.SelectFromTable(sql2); if (dt1 == null) { dt1 = dt2; } else { dt1.Merge(dt2); } } } GridViewAdded.DataSource = (dt1); DataBind(); }
protected void btnDelete_Click(object sender, EventArgs e) { StudentAtCourse nd = new StudentAtCourse(txtIdCourse.Text, Session["ID"].ToString()); if (nd.DeleteCourseForStudent()) { string re = "select * from StudentAtCourse where Id_Course='" + txtIdCourse.Text + "'"; DataTable dr = DBFunctions.SelectFromTable(re); DepartmentCourses ds = new DepartmentCourses(txtIdCourse.Text); // int muchStudent=Convert.ToInt32( ds.sessionMuchStudent()); DataTable dtmaxStudent = ds.sessionMaxStudents(); string maxStudent = dtmaxStudent.Rows[0]["maxStudent"].ToString(); //int num11 = (muchStudent) - 1; int r = dr.Rows.Count; if (r == 0) { // r--; DepartmentCourses d1 = new DepartmentCourses("0", maxStudent, txtIdCourse.Text); d1.UpdateRegisteringStud(); } else { r--; DepartmentCourses d1 = new DepartmentCourses(r.ToString(), maxStudent, txtIdCourse.Text); d1.UpdateRegisteringStud(); } lblMsn.Visible = true; lblMsn.Text = "Has Been Delete it!"; } else { lblMsn.Visible = true; lblMsn.Text = "Not Exsist!"; } int sum = 0, num; string sql = "Select [Id_Course] From [StudentAtCourse] where Id_Student='" + Session["ID"] + "'"; DataTable dt = DBFunctions.SelectFromTable(sql); Session["data"] = dt.Rows[0]; if (dt.Rows.Count > 0) { string s = dt.Rows[0]["Id_Course"].ToString(); string sql2 = "select * from [DepartmentCourses] where IdCourse= '" + s + "'"; // string totsql = "select Credits from [Courses] where ID='" + s + "'"; string tot = "select Credits from [DepartmentCourses] where IdCourse='" + s + "'"; DataTable tott = DBFunctions.SelectFromTable(tot); DataTable dt2 = DBFunctions.SelectFromTable(sql2); for (int i = 1; i < dt.Rows.Count; i++) { s = dt.Rows[i]["Id_Course"].ToString(); sql2 = "select * from [DepartmentCourses] where IdCourse= '" + s + "'"; tot = "select Credits from [DepartmentCourses] where IdCourse='" + s + "'"; DataTable tt = DBFunctions.SelectFromTable(tot); DataTable dt3 = DBFunctions.SelectFromTable(sql2); dt2.Merge(dt3); tott.Merge(tt); } string ss = tott.Rows[0]["Credits"].ToString(); num = Convert.ToInt32(ss); sum = num; // txttot.Text = tott.Rows.Count.ToString(); // string totsql = "select Credits from [Courses] where ID='" + s + "'"; // DataTable newdt = DBFunctions.SelectFromTable(totsql); for (int i = 1; i < tott.Rows.Count; i++) { ss = tott.Rows[i]["Credits"].ToString(); sum += Convert.ToInt32(ss); } lblFinalTot.Text = sum.ToString(); GridViewDelete.DataSource = dt2; DataBind();//להופעת טבלה } }