Example #1
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.");
            }
        }