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();
            }
        }
Example #2
0
        private void btnSubmit_Click(object sender, EventArgs e)
        {
            //foreach loop that checks all controls and whether if they are empty or not.
            bool isEmpty = false;

            foreach (Control ctl in this.Controls.OfType <ComboBox>())
            {
                if (ctl.Text == "" || ctl.Text == null)
                {
                    isEmpty = true;
                }
            }
            if (isEmpty == false)
            {
                //create an object and set properties
                TaughtCourse tCourse = (TaughtCourse)this.cmbTaughtCourse.SelectedItem;
                tCourse.Semester = this.cmbSemester.SelectedItem.ToString();
                tCourse.CourseID = this.cmbCourse.SelectedItem.ToString();
                //checks if the capacity entered is a number by checking each character in the number
                bool isValid = false;
                foreach (char c in this.txtYear.Text.ToString())
                {
                    if (c < '0' || c > '9')
                    {
                        isValid = false;
                    }
                    else
                    {
                        isValid = true;
                    }
                }
                //if valid, set the year. if not, set the default value
                if (isValid)
                {
                    tCourse.Year = this.txtYear.Text.ToString();
                }
                else
                {
                    tCourse.Year = "0000";
                    MessageBox.Show("Year entered is invalid.");
                }
                //updates the created taught course object
                taughtCourses.Update(tCourse);
                if (tCourse.getValid() == true)
                {
                    MessageBox.Show("Taught Course have been updated successfully.");
                }
                else
                {
                    MessageBox.Show("An error has occured. Record was not updated.");
                }
            }
        }
Example #3
0
        private void btnSubmit_Click(object sender, EventArgs e)
        {
            //create a TaughtCourse object to be used to store information
            TaughtCourse tCourse = new TaughtCourse();

            //setting the properties of the object
            tCourse.setID(this.txtTaughtID.Text.ToString());
            tCourse.CourseID = this.cmbCourseID.SelectedItem.ToString();
            tCourse.Semester = this.cmbSemester.SelectedItem.ToString();
            //checks if the capacity entered is a number
            Boolean isValid = true;

            foreach (char c in this.txtYear.Text.ToString())
            {
                //checks the cahracter is between 0 or 9  and set the boolean to false if not
                if (c < '0' || c > '9')
                {
                    isValid = false;
                }
            }
            //if the string contains only numbers then set the proeprty
            if (isValid)
            {
                tCourse.Year = this.txtYear.Text.ToString();
            }
            else
            {
                //if invalid input, set the default value 0000 and show a message
                tCourse.Year = "0000";
                MessageBox.Show("Year entered is invalid.");
            }
            //call the add method and pass the TaughtCourse object as a parameter
            taughtCourses.Add(tCourse);
            //checks if the execution was a success or not
            if (tCourse.getValid() == true)
            {
                MessageBox.Show("Taught course have been added successfully.");
                //This calls two methods to get the new id and clears old information
                clear();
                nextID();
            }
            else
            {
                //prompt an error message for user indicating error
                MessageBox.Show("An error has occured. record was not added.");
            }
        }