// Button to give the selected student its CourseMark private void Btn_CourseMark_Click(object sender, RoutedEventArgs e) { // Created and initialized -empty- string to store errors string errorMsg = ""; // Once we have selected an existing student, we mark the course of the student and update its label try { selectedStudent.CourseMark = int.Parse(txtCourseMark.Text); studentMark = selectedStudent.getMark(); lbl_TotalMark.Content = studentMark + "%"; } catch (Exception except) { errorMsg += except.Message + "\n"; } // Give feedback to user when validation hasn't been achieved if (!String.IsNullOrEmpty(errorMsg)) { MessageBox.Show(errorMsg); return; } // Clear the textbox for the courseMark txtCourseMark.Clear(); // Get total after adding course mark selectedStudent.totall = selectedStudent.getMark(); }
//This method searches the student by matric number and displays its info private void btnFind_Click(object sender, RoutedEventArgs e) { //if the Find student textbox is not empty... if (txtBoxFind.Text != "") { //check if the student exists if (store.find(Convert.ToInt16(txtBoxFind.Text)) != null) { //create a new student with the matric no. that was input Student findStudent = store.find(Convert.ToInt16(txtBoxFind.Text)); //display values lblName3.Content = findStudent.FirstName; lblSurname3.Content = findStudent.Surname; lblCW3.Content = findStudent.CWMark; lblExam3.Content = findStudent.ExamMark; lblTotal3.Content = findStudent.getMark() + "%"; //clear the "Find" textbox txtBoxFind.Clear(); } else //display error message if matric is not found { MessageBox.Show("The matric number does not exist."); } } else //display error message if the textbox is empty { MessageBox.Show("Please enter a matric number to find."); } }
// Button to Find a student from a given matriculation number and show part of its information private void Btn_Find_Click(object sender, RoutedEventArgs e) { // Looking for student and adding its name to a Name label try { // Take input number and parse it. The result into the find method, which return its student if matriculation number is found selectedStudent = store.find(int.Parse(txtStudentNo.Text)); lbl_Name.Content = selectedStudent.FirstName + " " + selectedStudent.Surname; } catch { MessageBox.Show("Ops, something went wrong, try different student matriculation number"); } // Get mark of student using the 'getMark' method. Show the result in a label try { studentMark = selectedStudent.getMark(); lbl_TotalMark.Content = studentMark + "%"; } catch { MessageBox.Show("Ops, seems like the student didn't the coursework or the exam"); } // Clear the text box to look for another student txtStudentNo.Clear(); }
//This method displays the details of the student selected from the listbox. private void listBoxAll_MouseDoubleClick(object sender, MouseButtonEventArgs e) { //if the listbox is not empty... if (listBoxAll.SelectedItem != null) { //copy the matric number selected into the textbox txtBoxFind.Text = Convert.ToString(listBoxAll.SelectedItem); //create a new student with the matric no. that was input Student findStudent2 = store.find(Convert.ToInt16(listBoxAll.SelectedItem)); //Display student's info lblName3.Content = findStudent2.FirstName; lblSurname3.Content = findStudent2.Surname; lblCW3.Content = findStudent2.CWMark; lblExam3.Content = findStudent2.ExamMark; lblTotal3.Content = findStudent2.getMark() + "%"; } else //display error message if user tries to select an item and the listbox is empty { MessageBox.Show("Don't be cheeky."); } }