/// <summary> /// Update a specific lesson by his id /// </summary> /// <param name="les_id">les_id of the lesson you want to update</param> /// <param name="newLes">the new lesson to update</param> public static void UpdateLesson(int les_id, ch_lessons newLes) { string strSql1 = "UPDATE ch_lessons SET pro_id=" + newLes.pro_Id + ", les_name='" + newLes.les_Name + "' WHERE les_id=" + les_id; Connect.DoAction(strSql1, "ch_lessons"); }
protected void btnAddLesson_Click(object sender, EventArgs e) { if (ValidatePage()) { //if teacher is checked bool selected = false; foreach (ListItem li in ckliTeachers.Items) { if (li.Selected) { selected = true; } } if (selected) { int selected_prof = Convert.ToInt32(ddlProf.SelectedValue); string selected_layer = ddlLayers.SelectedItem.Text; string les_name = txtLes_name.Text.Trim(); ch_lessons newLes = new ch_lessons(); newLes.pro_Id = selected_prof; newLes.les_Name = les_name + " - " + selected_layer; ch_lessonsSvc.AddLesson(newLes); int lastLesson_id = ch_lessonsSvc.GetLastInsertId(); //add teachers foreach (ListItem li in ckliTeachers.Items) { if (li.Selected) { ch_teachers_lessons newTchLes = new ch_teachers_lessons(); newTchLes.les_Id = lastLesson_id; newTchLes.usr_Id = Convert.ToInt32(li.Value); ch_teachers_lessonsSvc.AddTeachersLesson(newTchLes); } } //add students foreach (Hashtable htItem in htAllSelectedStudents.Values) { foreach (string usr_id in htItem.Keys) { ch_students_lessons newStuLes = new ch_students_lessons(); newStuLes.les_Id = lastLesson_id; newStuLes.usr_Id = Convert.ToInt32(usr_id); ch_students_lessonsSvc.AddStudentLesson(newStuLes); } } Response.Redirect("LessonsData.aspx"); } else { lblError.Text = "לא נבחרו מורים"; } } foreach (ListItem li in ckliTeachers.Items) { if (li.Selected) { Panel pnlName = new Panel(); pnlName.ID = "pnlName_" + li.Value; pnlName.CssClass = "pnlName"; pnlTeachers.Controls.Add(pnlName); Label lblName = new Label(); lblName.Text = li.Text; pnlName.Controls.Add(lblName); } } //show foreach (Hashtable htItem in htAllSelectedStudents.Values) { foreach (string student in htItem.Values) { Panel pnlName = new Panel(); pnlName.CssClass = "pnlName"; pnlStudents.Controls.Add(pnlName); Label lblName = new Label(); lblName.Text = student; pnlName.Controls.Add(lblName); } } update_pnlStudents.Update(); }
/// <summary> /// Add a new lesson /// </summary> /// <param name="newLes">The lesson you want to add</param> public static void AddLesson(ch_lessons newLes) { string strSql1 = "INSERT INTO ch_lessons(pro_id, les_name) VALUES(" + newLes.pro_Id + ",'" + newLes.les_Name + "')"; Connect.DoAction(strSql1, "ch_lessons"); }
protected void btnUpdateLesson_Click(object sender, EventArgs e) { if (ValidatePage()) { //if teacher is checked bool selected = false; foreach (ListItem li in ckliTeachers.Items) { if (li.Selected) { selected = true; } } if (selected) { int selected_prof = Convert.ToInt32(ddlProf.SelectedValue); string selected_layer = ddlLayers.SelectedItem.Text; string les_name = txtLes_name.Text.Trim(); ch_lessons newLes = new ch_lessons(); newLes.pro_Id = selected_prof; newLes.les_Name = les_name + " - " + selected_layer; ch_lessonsSvc.UpdateLesson(Convert.ToInt32(Request.QueryString["les_id"].ToString()), newLes); //update teachers ch_teachers_lessonsSvc.DeleteAllTeachersLesson(Convert.ToInt32(Request.QueryString["les_id"].ToString())); foreach (ListItem li in ckliTeachers.Items) { if (li.Selected) { ch_teachers_lessons newTchLes = new ch_teachers_lessons(); newTchLes.les_Id = Convert.ToInt32(Request.QueryString["les_id"].ToString()); newTchLes.usr_Id = Convert.ToInt32(li.Value); ch_teachers_lessonsSvc.AddTeachersLesson(newTchLes); } } //update students ch_students_lessonsSvc.DeleteAllStudentsLesson(Convert.ToInt32(Request.QueryString["les_id"].ToString())); foreach (Hashtable htItem in htAllSelectedStudents.Values) { foreach (string usr_id in htItem.Keys) { ch_students_lessons newStuLes = new ch_students_lessons(); newStuLes.les_Id = Convert.ToInt32(Request.QueryString["les_id"].ToString()); newStuLes.usr_Id = Convert.ToInt32(usr_id); ch_students_lessonsSvc.AddStudentLesson(newStuLes); } } Response.Redirect("LessonsData.aspx"); } } //----reenter Choices---- int les_id = Convert.ToInt32(Request.QueryString["les_id"].ToString()); DataRow drLesson = ch_lessonsSvc.GetLesson(les_id); ddlProf.SelectedValue = drLesson["pro_id"].ToString(); //מתמטיקה ddlLayers.SelectedItem.Text = drLesson["les_name"].ToString().Substring(drLesson["les_name"].ToString().LastIndexOf('-') + 2, drLesson["les_name"].ToString().Length - drLesson["les_name"].ToString().LastIndexOf('-') - 2); // יב txtLes_name.Text = drLesson["les_name"].ToString().Substring(0, drLesson["les_name"].ToString().LastIndexOf('-') - 1); // שם השיעור DataSet teachers = ch_teachers_lessonsSvc.GetTeachersLesson(les_id); lblEmpty_tch.Visible = (teachers.Tables[0].Rows.Count > 0) ? false : true; //show foreach (DataRow dr in teachers.Tables[0].Rows) { Panel pnlName = new Panel(); pnlName.ID = "pnlName_" + dr["usr_id"].ToString(); pnlName.CssClass = "pnlName"; pnlTeachers.Controls.Add(pnlName); Label lblName = new Label(); lblName.Text = dr["usr_fullname"].ToString(); pnlName.Controls.Add(lblName); } //checkboxes ckliTeachers.Items.Clear(); DataSet dsTeachersProfessions = ch_teachers_professionsSvc.GetTeachersByPro(Convert.ToInt32(ddlProf.SelectedValue)); for (int i = 0; i < dsTeachersProfessions.Tables[0].Rows.Count; i++) { int usr_id = Convert.ToInt32(dsTeachersProfessions.Tables[0].Rows[i]["tch_pro.usr_id"].ToString()); ListItem li = new ListItem(); li.Value = usr_id.ToString(); li.Text = ch_usersSvc.GetUserFullname(usr_id); foreach (DataRow dr in teachers.Tables[0].Rows) { if (usr_id == Convert.ToInt32(dr["usr_id"].ToString())) { li.Selected = true; } } ckliTeachers.Items.Add(li); } foreach (Hashtable htItem in htAllSelectedStudents.Values) { ((Hashtable)htItem).Clear(); } DataSet students = ch_students_lessonsSvc.GetStudentsLesson(les_id); foreach (DataRow dr in students.Tables[0].Rows) { ((Hashtable)htAllSelectedStudents[dr["rm_id"].ToString()]).Add(dr["usr_id"].ToString(), dr["usr_fullname"].ToString()); } //show foreach (Hashtable htItem in htAllSelectedStudents.Values) { foreach (string student in htItem.Values) { Panel pnlName = new Panel(); pnlName.CssClass = "pnlName"; pnlStudents.Controls.Add(pnlName); Label lblName = new Label(); lblName.Text = student; pnlName.Controls.Add(lblName); } } update_ckliStudentsByClass.Update(); update_ckliTeachers.Update(); update_pnlStudents.Update(); update_pnlTeachers.Update(); }