Example #1
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            //prompts a validation message to ensure selection
            DialogResult dialogResult = MessageBox.Show("Are you sure you want to delete this taught course?",
                                                        "Delete Notice", MessageBoxButtons.YesNo);

            //if yes, the taught course object is created and passed to be deleted
            if (dialogResult == DialogResult.Yes)
            {
                TaughtCourse tCourse = (TaughtCourse)this.cmbTaughtID.SelectedItem;
                //Delete All Related Records First
                //From Schedule Table
                scheduleList.Delete("Section", "Section.SectionID", "Schedule.SectionID", "Section.TaughtCourseID", cmbTaughtID.SelectedItem.ToString());
                //From SectionStudent Table
                sectionStudentList.Delete("Section", "Section.SectionID", "SectionStudent.SectionID", "Section.TaughtCourseID", cmbTaughtID.SelectedItem.ToString());
                //From Section Table
                sectionList.Delete("TaughtCourseID", cmbTaughtID.SelectedItem.ToString());
                //Delete Taught Course From Taught Courses Table Second
                taughtCourses.Delete(tCourse);
                //checks if the execution was a seccuess or not
                if (tCourse.getValid() == true)
                {
                    MessageBox.Show("Taught Course has been deleted successfully.");
                }
                else
                {
                    MessageBox.Show("An error has occured. Record was not deleted.");
                }
                loadTCourses();
            }
        }