// Button delete student
        private void BtnDelete_Click(object sender, EventArgs e)
        {
            // Trying to find a student
            ClsStudent lcStudent = (ClsStudent)LstStudents.SelectedItem;

            // If list is empty
            if (lcStudent == null)
            {
                // Display Message box
                DialogResult CantDelete = MessageBox.Show("No students exist to delete", "Delete Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                // User clicks ok
                if (CantDelete == DialogResult.OK)
                {
                    // And messagebox closes
                    return;
                }
            }
            // Display message box asking user if they want to delete
            DialogResult DeleteStudent = MessageBox.Show("You are about to delete a student, are you sure?", "Delete student", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

            // If user clicks yes
            if (DeleteStudent == DialogResult.Yes)
            {
                // Delete the student
                RemoveStudent();
            }
        }
        private void StudentEdit()
        {
            // Locating the student that the user has highlighted
            ClsStudent lcStudent = (ClsStudent)LstStudents.SelectedItem;

            // If student exists and is selected
            if (lcStudent != null)
            {
                // We will edit them
                EditStudent();
            }
            else
            {
                // Else we will display a message box saying no students exists amd ask if they would like to create one instead
                DialogResult NoStudent = MessageBox.Show("No students exist would you like to create one now?", "Error", MessageBoxButtons.YesNo, MessageBoxIcon.Error);
                // If user clicked on yes
                if (NoStudent == DialogResult.Yes)
                {
                    // We will create the student
                    CreateStudent();
                }
                else
                {
                    // Else we will cancel
                    return;
                }
            }
        }
Example #3
0
 // Display FrmStudent
 // V3, Show dialog now returns a boolinstead of dialog result, as ClsMOEStudent and ClsInternationalStudent are calling show dialog we don't want classes to concern themselves with windows specific items, change is good style
 public bool ShowDialog(ClsStudent prStudent)
 {
     // Creating and storing the parameter value in our member variable
     _Student = prStudent;
     // Calling the update display method so it will populate the form
     UpdateDisplay();
     // Returnung the values to the form and display them
     // V3, now just returns a bool
     return(ShowDialog() == DialogResult.OK);
 }
        // Delete student method
        private void RemoveStudent()
        {
            // Find selected student
            ClsStudent lcStudent = (ClsStudent)LstStudents.SelectedItem;

            // Remove them
            // V5 edit, as this is a dictionary we need to find the ID
            ClsInstitute.StudentList.Remove(lcStudent.ID);
            // Then update the listbox
            UpdateDisplay();
        }
        // Edit student method
        private void EditStudent()
        {
            // Locating the student that the user has highlighted
            ClsStudent lcStudent = (ClsStudent)LstStudents.SelectedItem;

            // If student details is not null and editing was successful
            if (lcStudent != null && lcStudent.ViewEdit())
            {
                // Then update display
                UpdateDisplay();
            }
        }
        // Create student method
        private void CreateStudent()
        {
            // We create a new student by calling the factory method NewStudent() in ClsStudent and storing it in the local variable lcStudent
            ClsStudent lcStudent = ClsStudent.NewStudent(CboStudentType.SelectedIndex);

            // If it was successful
            if (lcStudent != null && lcStudent.ViewEdit())
            {
                // We add the student to the student list
                // V5 edit, as we are using a dictionary this changes a little compared to the list one
                ClsInstitute.StudentList.Add(lcStudent.ID, lcStudent);
                // Then update the display to show the student in the list box
                UpdateDisplay();
            }
        }