private void ShowAllStudents(object sender, EventArgs e) { Reset(); displayRichTextBox.Text = ""; try { if (studentList.Count > 0) { string output = "Student Details \n\n"; foreach (StudentInformation student in studentList) { output += StudentInformation.ShowStudent(student); } output += StudentInformation.DisplayMaxMinAvgTotal(studentList); DisplayOutput(output); } else { ShowErrorMessage("Please add students first!"); return; } } catch (Exception exception) { ShowErrorMessage(exception.Message); } }
private void AddStudent(object sender, EventArgs e) { try { displayRichTextBox.Text = ""; id = idTextBox.Text; name = nameTextBox.Text; mobile = mobileTextBox.Text; age = (ageTextBox.Text == "") ? 0 : int.Parse(ageTextBox.Text); gpa = (gpaTextBox.Text == "") ? 0 : double.Parse(gpaTextBox.Text); if (ValidateInputs(studentList, id, name, mobile, age, gpa)) { StudentInformation newStudent = new StudentInformation(id, name, mobile, age, gpa); studentList.Add(newStudent); string output = "Student Added \n\n"; output += StudentInformation.ShowStudent(newStudent); DisplayOutput(output); Reset(); } else { return; } } catch (Exception exception) { ShowErrorMessage(exception.Message); } }
private void SearchStudent(object sender, EventArgs e) { List <StudentInformation> students = new List <StudentInformation>(); string searchText = searchTextBox.Text.ToLower(); if (searchText == "") { ShowErrorMessage("Please enter id, name or mobile to search."); } if (idRadioButton.Checked == true) { students = studentList.FindAll(r => r.id.ToLower() == searchText); } else if (nameRadioButton.Checked == true) { students = studentList.FindAll(r => r.name.ToLower() == searchText); } else if (mobileRadioButton.Checked == true) { students = studentList.FindAll(r => r.mobile.ToLower() == searchText); } else { ShowErrorMessage("Please select id, name or mobile to search."); } if (students.Count == 0) { ShowErrorMessage("No student found that matches the description"); } else { string output = "Search Result \n\n"; foreach (StudentInformation student in students) { output += StudentInformation.ShowStudent(student); } DisplayOutput(output); } }