private void btnDelete_Click(object sender, EventArgs e) { if (lblSelected.Text == "") { MessageBox.Show("Please select a class to delete"); } else { Classes newClasses = new Classes(); int classNum = Convert.ToInt32(lblSelected.Text); newClasses.ClassID = classNum; ClassesDB.ClassDelete(newClasses); List <Teacher> teacherList = TeacherDB.TeacherLoad(); foreach (Teacher teacher in teacherList) { foreach (int classid in teacher.ClassID) { if (classid == newClasses.ClassID) { teacher.ClassID.Remove(classid); TeacherDB.TeacherDelete(teacher); TeacherDB.TeacherSave(teacher); } } } RefreshTable(); } }
private void btnDelete_Click(object sender, EventArgs e) { Student deleteStudent = new Student(); deleteStudent.StudentID = Convert.ToInt32(dataGridView1.CurrentRow.Cells[0].Value.ToString()); deleteStudent.FirstName = dataGridView1.CurrentRow.Cells[1].Value.ToString(); deleteStudent.LastName = dataGridView1.CurrentRow.Cells[2].Value.ToString(); //Need to check all classes and see if teacher has that class and delete them. List <Classes> ListClasses = ClassesDB.ClassLoad(); foreach (Classes classes in ListClasses) { if (classes.StudentID != null) { foreach (int studentid in classes.StudentID) { if (deleteStudent.StudentID == studentid) { classes.StudentID.Remove(studentid); ClassesDB.ClassDelete(classes); ClassesDB.ClassSave(classes); } } } } StudentDB.StudentDelete(deleteStudent); RefreshTable(); }
private void btnDelete_Click(object sender, EventArgs e) { Teacher deleteTeacher = new Teacher(); deleteTeacher.TeacherID = Convert.ToInt32(dataGridView1.CurrentRow.Cells[0].Value.ToString()); deleteTeacher.FirstName = dataGridView1.CurrentRow.Cells[1].Value.ToString(); deleteTeacher.LastName = dataGridView1.CurrentRow.Cells[2].Value.ToString(); //Need to check all classes and see if teacher has that class and delete them. List <Classes> ListClasses = ClassesDB.ClassLoad(); foreach (Classes classes in ListClasses) { foreach (int teacherid in classes.TeacherID) { if (deleteTeacher.TeacherID == teacherid) { classes.TeacherID.Remove(teacherid); ClassesDB.ClassDelete(classes); ClassesDB.ClassSave(classes); } } } TeacherDB.TeacherDelete(deleteTeacher); RefreshTable(); }
private void btnSave_Click(object sender, EventArgs e) //Needs validation { if (true) //Validate everything { List <int> ClassList = new List <int>(); List <Classes> ClassListSave = new List <Classes>(); //Retrieves class data and populates list foreach (object classData in checkedListBox1.CheckedItems) { string[] classInfo = classData.ToString().Split(' '); Classes newClass = ClassesDB.ClassFind(Convert.ToInt32(classInfo[0])); ClassListSave.Add(newClass); ClassList.Add(newClass.ClassID); } //Find teacher and add data into teacher string[] teacherID = comboBox1.Text.Split(' '); Teacher newTeacher = TeacherDB.TeacherFind(Convert.ToInt32(teacherID[0])); newTeacher.ClassID = ClassList; foreach (Classes classes in ClassListSave) { classes.TeacherID.Add(newTeacher.TeacherID); ClassesDB.ClassDelete(classes); ClassesDB.ClassSave(classes); } TeacherDB.TeacherDelete(newTeacher); TeacherDB.TeacherSave(newTeacher); } else { MessageBox.Show("Please select the correct number of classes or select a different teacher"); } this.Close(); }
//Save all classes to student private void button1_Click(object sender, EventArgs e) { Student student = StudentDB.StudentFind(Convert.ToInt32(label2.Text)); List <int> ClassId = new List <int>(); foreach (object classid in checkedListBox1.CheckedItems) { string[] id = classid.ToString().Split(' '); ClassId.Add(Convert.ToInt32(id[0])); Classes classes = ClassesDB.ClassFind(Convert.ToInt32(id[0])); List <int> studentID = new List <int>(); studentID.Add(classes.ClassID); ClassesDB.ClassDelete(classes); ClassesDB.ClassSave(classes); } student.ClassID = ClassId; StudentDB.StudentDelete(student); StudentDB.StudentSave(student); }