//Save the pre course
        private void save_Click(object sender, EventArgs e)
        {
            //Check if any courses was chosen
            if (comboBox1.SelectedItem == null || comboBox2.SelectedItem == null)
            {
                MessageBox.Show("Please choose pre course and course", "Error"
                                , MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            //Get two strings from combobox
            DataRowView oDataRowView = comboBox1.SelectedItem as DataRowView;
            string      preCourse    = oDataRowView.Row["CourseName"] as string;

            oDataRowView = comboBox2.SelectedItem as DataRowView;
            string course = oDataRowView.Row["CourseName"] as string;

            //Check if the courses isn't the same
            if (preCourse == course)
            {
                MessageBox.Show("Course can't have himself as pre course", "Error"
                                , MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            int success = SqlWorker.addPreCourse(preCourse, course);

            //Show message according to add pre course function
            if (success == 2)
            {
                MessageBox.Show("Action successfully completed.", "Success!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }
            else if (success == 0)
            {
                MessageBox.Show("The course " + course + " already has " + preCourse + " as pre course!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                MessageBox.Show("The course " + preCourse + " has " + course + " as pre course!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Beispiel #2
0
        public void Test_add_pre_course()
        {
            //Add pre course
            //0 - already exists
            //1 - opposite exists
            //2 - operation successfull

            //Add brand new courses
            SqlWorker.addCourse(course1, lecturerID, practitionerID, LectureDuration, PracticeDuration, LabDuration, true);
            SqlWorker.addCourse(course2, lecturerID, practitionerID, LectureDuration, PracticeDuration, LabDuration, true);
            //Set course1 as pre course of course2
            Assert.IsTrue(SqlWorker.addPreCourse(course1, course2) == 2);

            //Try again
            Assert.IsTrue(SqlWorker.addPreCourse(course1, course2) == 0);

            //Try to set the opposite
            Assert.IsTrue(SqlWorker.addPreCourse(course2, course1) == 1);

            SqlWorker.ExecuteQueries("Delete from Courses where CourseName='" + course1 + "' or CourseName='" + course2 + "'");
            SqlWorker.ExecuteQueries("Delete from PreCourses where PreCourse='" + course1 + "' and course='" + course2 + "'");
        }