//Save a new class private void button3_Click(object sender, EventArgs e) { Classes newClass = new Classes(); List <int> teacherID = new List <int>() { 0, 0, 0, 0 }; newClass.ClassID = Convert.ToInt32(classIDLabel1.Text); newClass.ClassTitle = txtTitle.Text; newClass.Sections = 1; newClass.TeacherID = teacherID; if (comboBox1.Text == "") { newClass.ClassTrack = "A"; } else { newClass.ClassTrack = comboBox1.Text; } ClassesDB.ClassSave(newClass); 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); }