public void Test_add_new_course()
        {
            //Add course with lecture, practice and lab
            //Limit lecture, practice and lab duration
            SqlWorker.addCourse(courseName, lecturerID, practitionerID, LectureDuration, PracticeDuration, LabDuration, true);
            Assert.IsTrue(SqlWorker.GetDataSet("select * from Courses where CourseName='" + courseName +
                                               "' and Lecturer=" + lecID + " and practitioner=" + PracID + " and MaxStudent=20 and " +
                                               "LectureDuration=" + LecDuration + " and PracticeDuration=" + PracDuration + " and LabDuration=" + LabDur +
                                               " and Must=" + must).Tables[0].Rows.Count == 1);
            SqlWorker.ExecuteQueries("Delete from Courses where CourseName='" + courseName + "'");

            //Add course with lecture and practice without lab
            //Limit lecture and practice duration
            SqlWorker.addCourse(courseName, lecturerID, practitionerID, LectureDuration, PracticeDuration, null, true);
            Assert.IsTrue(SqlWorker.GetDataSet("select * from Courses where CourseName='" + courseName +
                                               "' and Lecturer=" + lecID + " and practitioner=" + PracID + " and MaxStudent=20 and " +
                                               "LectureDuration=" + LecDuration + " and PracticeDuration=" + PracDuration +
                                               " and Must=" + must + " and LabDuration is null").Tables[0].Rows.Count == 1);
            SqlWorker.ExecuteQueries("Delete from Courses where CourseName='" + courseName + "'");

            //Add course with lecture and lab
            //Limit lecture and lab duration
            SqlWorker.addCourse(courseName, lecturerID, practitionerID, LectureDuration, null, LabDuration, true);
            Assert.IsTrue(SqlWorker.GetDataSet("select * from Courses where CourseName='" + courseName +
                                               "' and Lecturer=" + lecID + " and practitioner=" + PracID + " and MaxStudent=20 and " +
                                               "LectureDuration=" + LecDuration + " and LabDuration=" + LabDur +
                                               " and Must=" + must + " and PracticeDuration is null").Tables[0].Rows.Count == 1);
            SqlWorker.ExecuteQueries("Delete from Courses where CourseName='" + courseName + "'");
        }
 public void Test_check_course_existence()
 {
     //Add new course
     SqlWorker.addCourse(courseName, lecturerID, practitionerID, LectureDuration, PracticeDuration, LabDuration, true);
     Assert.IsTrue(SqlWorker.GetDataSet("select * from Courses where CourseName='" + courseName +
                                        "' and Lecturer=" + lecID + " and practitioner=" + PracID + " and MaxStudent=20 and " +
                                        "LectureDuration=" + LecDuration + " and PracticeDuration=" + PracDuration + " and LabDuration=" + LabDur +
                                        " and Must=" + must).Tables[0].Rows.Count == 1 && SqlWorker.checkCourseExistence(courseName));
     SqlWorker.ExecuteQueries("Delete from Courses where CourseName='" + courseName + "'");
 }
Exemple #3
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 + "'");
        }
Exemple #4
0
        public void class_req_Test()
        {
            //insert one request for class in temp course.
            SqlWorker.addCourse(courseName, lecturerID, practitionerID, LectureDuration, PracticeDuration, LabDuration, true);
            SqlWorker.setClassRequest(lecID.ToString(), courseName, p, l);

            Assert.IsTrue(SqlWorker.GetDataSet("select * from ClassRequest where TeacherID LIKE '" + lecID +
                                               "' AND CourseName LIKE '" + courseName + "' AND Projector = '" + p + "' AND Lab = '" + l + "'").Tables[0].Rows.Count == 1);

            //try to update the request
            p = 0;
            SqlWorker.addCourse(courseName, lecturerID, practitionerID, LectureDuration, PracticeDuration, LabDuration, true);
            SqlWorker.setClassRequest(lecID.ToString(), courseName, p, l);

            Assert.IsTrue(SqlWorker.GetDataSet("select * from ClassRequest where TeacherID LIKE '" + lecID +
                                               "' AND CourseName LIKE '" + courseName + "' AND Projector = '" + p + "' AND Lab = '" + l + "'").Tables[0].Rows.Count == 1);

            //delete the temp course.
            SqlWorker.ExecuteQueries("Delete from Courses where CourseName='" + courseName + "'");

            //delete the request
            SqlWorker.ExecuteQueries("Delete from ClassRequest where CourseName='" + courseName + "'");
        }
        //When the save button is pressed
        private void save_button_Click(object sender, EventArgs e)
        {
            Regex checkName = new Regex("^[A-Za-z0-9 ]+$");

            //check if the course name is invaild or empty
            if (!checkName.IsMatch(course_textbox.Text) || course_textbox.ForeColor == Color.Gray)
            {
                MessageBox.Show("Course name invaild!\nMake sure that the name contains only letters and numbers", "Error"
                                , MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            //Check if lecturer was chosen
            if (LecturerID_combo.SelectedItem == null)
            {
                MessageBox.Show("You must chose lecturer", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            //Check if practitioner was chosen
            if (practitionerID_combo.SelectedItem == null)
            {
                MessageBox.Show("You must chose practitioner", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            //Check if lecture duration was chosen
            if (Lectur_duration_combobox.SelectedItem == null)
            {
                MessageBox.Show("You must choose lecture duration for a course!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            //Check if some item was selected in the practice/lab duration list
            if (Practice_checkbox.Checked && Practice_duration_combobox.SelectedItem == null)
            {
                MessageBox.Show("Please chose practice duration", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (Lab_Checkbox.Checked && lab_duration_combobox.SelectedItem == null)
            {
                MessageBox.Show("Please chose lab duration", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            //Check if at least 1 check box is checked
            if (!Lab_Checkbox.Checked && !Practice_checkbox.Checked)
            {
                MessageBox.Show("For a course there must be at least lab and/or practice", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            //Create new connection to write to database

            DataRowView oDataRowView = LecturerID_combo.SelectedItem as DataRowView;
            int         lecturerID   = (int)oDataRowView.Row["ID"];

            oDataRowView = practitionerID_combo.SelectedItem as DataRowView;
            int practitionerID = (int)oDataRowView.Row["ID"];

            //Check if the course exists
            if (SqlWorker.checkCourseExistence(course_textbox.Text))
            {
                MessageBox.Show("The course " + course_textbox.Text + " already exists!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            string practiceDur = null, labDur = null;
            //Show confirm message
            string messageString = "Are you sure you want to add the following course to the department?"
                                   + "\nName: " + course_textbox.Text
                                   + "\nLecturer ID: " + lecturerID.ToString()
                                   + "\nPractitioner ID: " + practitionerID.ToString()
                                   + "\nLecutre duration: " + Lectur_duration_combobox.SelectedItem;

            if (Practice_checkbox.Checked)
            {
                messageString += "\nPractice duration: " + Practice_duration_combobox.SelectedItem;
                practiceDur    = Practice_duration_combobox.SelectedItem.ToString();
            }
            if (Lab_Checkbox.Checked)
            {
                messageString += "\nLab duration: " + lab_duration_combobox.SelectedItem;
                labDur         = lab_duration_combobox.SelectedItem.ToString();
            }
            DialogResult resault = MessageBox.Show(messageString, "Before you continue", MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk);

            //If the user click ok, add the course to database
            if (resault == DialogResult.OK)
            {
                SqlWorker.addCourse(course_textbox.Text, lecturerID.ToString(), practitionerID.ToString(),
                                    Lectur_duration_combobox.SelectedItem.ToString(), practiceDur, labDur, checkBox1.Checked);
                MessageBox.Show("Course successfully added!", "Success!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                this.Close();
            }
        }