private void AddBtn_Click(object sender, EventArgs e) { ErrorList err = new ErrorList(); err = CreateAssignment(); if (err.hasErrors) { MessageBox.Show(err.CompileErrors(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand); } else { MessageBox.Show("Assignment Created", "Notify", MessageBoxButtons.OK, MessageBoxIcon.Information); AssignmentNameTxtBox.Text = ""; PointsPossibleTxtBox.Text = ""; ReturnBtn.Focus(); } }
private void SaveStudentBtn_Click(object sender, EventArgs e) { //creates the new object and adds it to either the editted list or the new student list ErrorList err = new ErrorList(); List <Grade> holdGrades = new List <Grade>(); Student holdNewStu = null; DormStudent holdNewDormStu = null; bool newStudent = false; if (StudentsListBox.SelectedItem.ToString() == "New Student") { newStudent = true; } else { var hold = Dependency.CurrentStudents.Where(a => a.StudentID == StudentIDTextBox.Text); if (hold.Count() > 1) { err.Errors.Add("Multiple Students found with the same ID."); } else if (hold.Count() < 1) { err.Errors.Add("Error finding student with that ID."); StudentsListBox.Items.Remove(StudentIDTextBox.Text); } else if (hold.Count() == 1) { holdGrades = hold.First().Grades; } } if (err.hasErrors) { MessageBox.Show(err.CompileErrors(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand); return; } //Change to validation command CheckStudentDataGood(err, holdGrades); if (err.hasErrors) { MessageBox.Show(err.CompileErrors(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand); return; } try { if (NonDormRadio.Checked) { holdNewStu = new Student(StudentIDTextBox.Text, NameTextBox.Text); holdNewStu.Grades = holdGrades; } else { string mealPlan = ""; switch (MealPlanCombo.SelectedItem) { case ("B - Basic"): mealPlan = "B"; break; case ("M - Medium"): mealPlan = "M"; break; case ("H - High"): mealPlan = "H"; break; default: break; } holdNewDormStu = new DormStudent(StudentIDTextBox.Text, NameTextBox.Text, DormDropDown.SelectedItem.ToString(), mealPlan); holdNewDormStu.Grades = holdGrades; } } catch (Exception ex) { err.Errors.Add(ex.Message); } if (err.hasErrors) { MessageBox.Show(err.CompileErrors(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand); return; } Student holdStu = null; if (DormRadio.Checked) { holdStu = holdNewDormStu; } else { holdStu = holdNewStu; } if (!newStudent) { Dependency.CurrentStudents.RemoveAll(a => a.StudentID == holdStu.StudentID); Dependency.CurrentStudents.Add(holdStu); if (Dependency.EditStudents.Any(a => a.StudentID == holdStu.StudentID)) { Dependency.EditStudents.RemoveAll(a => a.StudentID == holdStu.StudentID); Dependency.EditStudents.Add(holdStu); } else { Dependency.EditStudents.Add(holdStu); } Dependency.CurrentStudents.Sort(); Dependency.EditStudents.Sort(); } else { Dependency.CurrentStudents.Add(holdStu); Dependency.NewStudents.Add(holdStu); Dependency.CurrentStudents.Sort(); Dependency.NewStudents.Sort(); } ResetForm(); ReturnBtn.Focus(); }