/// <summary> /// Find a student using their matric number as identification /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnFind_Click(object sender, RoutedEventArgs e) { int matric; // Convert the matric text input string to an integer Int32.TryParse(txtEnterMatric.Text, out matric); // Using the matric number, get the student from the list of students with the matching matric number Student found = store.find(matric); try { // If there is a student with a matching matric number if (found != null) { string output = found.ToString(); // Set the first name text box to the first name of the chosen student txtFirstName.Text = found.FirstName; // Set the surname text box to the surname of the chosen student txtSurname.Text = found.Surname; // Set the coursework mark text box to the coursework mark of the chosen student txtCoursework.Text = found.CourseworkMark.ToString(); // Set the exam mark text box to the exam mark of the chosen student txtExam.Text = found.ExamMark.ToString(); // Set the date picker to the date of birth of the chosen student dPicker.SelectedDate = found.DateOfBirth; // Reset the selected student on the list box of matric numbers lstEnrolled.SelectedIndex = -1; } else { // Tell the user that there isn't a student with the chosen matric number throw new ArgumentException("There is not a student with that matric number"); } } // Catch any exceptions catch (Exception excep) { // Display the exception in a message box MessageBox.Show(excep.Message); } }
/// <summary> /// Open a new window with the list of student strings /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnListAll_Click(object sender, RoutedEventArgs e) { // Declare a temporary student Student current = new Student(); // Create a list of matrics using the matrics from the store List <int> matrics = store.matrics; // Create a list of strings for the string representations of each student List <string> studentStrings = new List <string>(); // Loop through the number of matric numbers in the matric list for (int i = 0; i < matrics.Count; i++) { // Set the current student to the current student current = store.find(matrics[i]); // Add the current student string to the list of student strings studentStrings.Add(current.ToString()); } // Create a new window and pass in the list of student strings ListAllStudents listAllWindow = new ListAllStudents(studentStrings); // Show the new window for listing all of the student details listAllWindow.Show(); }