/// <summary> /// Validates the data that was entered and adds an updated Student/DormStudent object to the list /// </summary> void UpdateStu() { int errctr = 0; bool clickedSearch = false; // used to show that the "Search" button was not clicked // Array of this form's radio buttons RadioButton[] radBtns = { basic, medium, high }; errctr += StuId(clickedSearch); errctr += StuName(); if (liveOnCamp.Checked) { errctr += Dorm(); errctr += MealPlan(radBtns); } else if (!liveOffCamp.Checked && !liveOnCamp.Checked) { errctr++; MessageBox.Show("No checkboxes were selected", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } if (errctr == 0) { char mealPlan = ' '; foreach (var radBtn in radBtns) { if (radBtn.Checked) { // Gets only the first letter in the text of the selected radio button mealPlan = char.Parse(radBtn.Text.Substring(0, 1)); break; } } if (liveOnCamp.Checked) { // Attempts to create a new list without the student ID that was entered and stores the result in "stuList" StudentSystem.stuList = StudentSystem.stuList.Where(s => s.Id != int.Parse(stuId.Text)).ToList(); // Creates the object that was submitted and adds it to the list DormStudent dormStu = new DormStudent(int.Parse(stuId.Text.Trim()), name.Text.Trim(), dorms.Text.Trim(), mealPlan); StudentSystem.stuList.Add(dormStu); } else { // Attempts to create a new list without the student ID that was entered and stores the result in "stuList" StudentSystem.stuList = StudentSystem.stuList.Where(s => s.Id != int.Parse(stuId.Text)).ToList(); // Creates the object that was submitted and adds it to the list Student stu = new Student(int.Parse(stuId.Text.Trim()), name.Text.Trim()); StudentSystem.stuList.Add(stu); } MessageBox.Show("This student has been updated!!", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information); DisableAndClear(); } }
/// <summary> /// Validates input fields and adds valid students that were entered to the list of students when the "Submit /// Student" button was clicked /// </summary> /// <param name="sender">Represents the form</param> /// <param name="e">Represents the event that occurred</param> void Submit_Click(object sender, EventArgs e) { int errctr = 0; // keeps track of all the errors that have been found // Array of this form's radio buttons RadioButton[] radBtns = { basic, medium, high }; errctr += StuId(); errctr += StuName(); if (liveOnCamp.Checked) { errctr += Dorm(); errctr += MealPlan(radBtns); } else if (!liveOffCamp.Checked && !liveOnCamp.Checked) { errctr++; MessageBox.Show("No checkboxes were selected", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } if (errctr == 0) { char mealPlan = ' '; foreach (var radBtn in radBtns) { if (radBtn.Checked) { // Gets only the first letter in the text of the selected radio button mealPlan = char.Parse(radBtn.Text.Substring(0, 1)); break; } } if (liveOnCamp.Checked) { DormStudent dormStu = new DormStudent(int.Parse(stuId.Text.Trim()), name.Text.Trim(), dorms.Text.Trim(), mealPlan); stuList.Add(dormStu); } else { Student stu = new Student(int.Parse(stuId.Text.Trim()), name.Text.Trim()); stuList.Add(stu); } MessageBox.Show("Student was saved", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
/// <summary> /// Searches the list for the student ID that was entered when the "Search" button is clicked /// </summary> /// <param name="sender">Represents the form</param> /// <param name="e">Represents the event that occurred</param> void Search_Click(object sender, EventArgs e) { int errctr = 0; // keeps track of all the errors that have been found bool found = false; errctr += StuId(); // Check if either the "Yes" or "No" checkbox was selected if (!liveOffCamp.Checked && !liveOnCamp.Checked) { errctr++; MessageBox.Show("No checkboxes were selected", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } if (errctr == 0) { foreach (var stu in StudentSystem.stuList) { if (liveOffCamp.Checked) { if (stu.GetType() == typeof(Student) && stu.Id == int.Parse(stuId.Text)) { MessageBox.Show("The student was found!!", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information); // Sets the matching input field to the value of the object name.Text = stu.Name; found = true; break; } } else if (liveOnCamp.Checked) { if (stu.GetType() == typeof(DormStudent) && stu.Id == int.Parse(stuId.Text)) { DormStudent dormStu = (DormStudent)stu; { MessageBox.Show("Student was found!!", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information); // Sets the matching input fields to the the values of the object name.Text = dormStu.Name; dorm.Text = dormStu.DormLoc; if (dormStu.MealPlan == 'B') { mealPlan.Text = "Basic"; } else if (dormStu.MealPlan == 'M') { mealPlan.Text = "Medium"; } else { mealPlan.Text = "High"; } found = true; break; } } } } if (!found) { MessageBox.Show("Student was not found", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { delete.Enabled = true; nameSection.Enabled = true; if (liveOnCamp.Checked) { dormSection.Enabled = true; mealPlanSection.Enabled = true; } } } }
/// <summary> /// Searches the list for the student ID that was entered and will enable certain fields based on which checkbox /// was selected and displays the student that was found when the "Search" button is clicked /// </summary> /// <param name="sender">Represents the form</param> /// <param name="e">Represents the event that occurred</param> void Search_Click(object sender, EventArgs e) { int errctr = 0; // keeps track of all the errors that have been found bool clicked = true; // used to show that the "Search" button was clicked bool found = false; // determines if a dorm student was found errctr += StuId(clicked); // Check if either the "Yes" or "No" checkbox was selected if (!liveOffCamp.Checked && !liveOnCamp.Checked) { errctr++; MessageBox.Show("No checkboxes were selected", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } if (errctr == 0) { foreach (var stu in StudentSystem.stuList) { if (liveOffCamp.Checked) { if (stu.GetType() == typeof(Student) && stu.Id == int.Parse(stuId.Text)) { // Sets the matching input field to the value of the object name.Text = stu.Name; // Clears any leftover values in the dorm student fields (dorm location and meal plan) dorms.Text = ""; RadioButton[] radBtns = { basic, medium, high }; foreach (var radbtn in radBtns) { if (radbtn.Checked) { radbtn.Checked = false; } } MessageBox.Show("The student was found!!", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information); found = true; break; } } else if (liveOnCamp.Checked) { if (stu.GetType() == typeof(DormStudent) && stu.Id == int.Parse(stuId.Text)) { DormStudent dormStu = (DormStudent)stu; { // Sets the matching input fields to the the values of the object name.Text = dormStu.Name; dorms.Text = dormStu.DormLoc; if (dormStu.MealPlan == 'B') { basic.Checked = true; } else if (dormStu.MealPlan == 'M') { medium.Checked = true; } else { high.Checked = true; } MessageBox.Show("The student was found!!", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information); found = true; break; } } } } if (!found) { MessageBox.Show("Student was not found", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { update.Enabled = true; nameSection.Enabled = true; if (liveOnCamp.Checked) { dormSection.Enabled = true; mealPlanSection.Enabled = true; } } } }