private void btnAddClick(object sender, RoutedEventArgs e)
        {
            if (comboProfessors.SelectedIndex == -1)
            {
                MessageBox.Show("Please select a professor!");
                return;
            }

            Professor prof = comboProfessors.SelectedItem as Professor;

            if (comboDays.SelectedIndex == -1)
            {
                MessageBox.Show("Please select a day!");
                return;
            }

            int day = comboDays.SelectedIndex;
            int startHours;
            int startMinutes;
            int endHours;
            int endMinutes;
            int seconds = 0;

            if (int.TryParse(txtStartHour.Text, out startHours))
            {
                if (startHours < 8 || startHours >20 )
                {
                    MessageBox.Show("Ooops. The start hour must be between 8 and 20!");
                    return;
                }
            }
            else
            {
                MessageBox.Show("Ooops. Please enter a start hour[8,20] !");
                return;
            }

            if (int.TryParse(txtStartMin.Text, out startMinutes))
            {
                if (startMinutes < 0 || startMinutes >59 )
                {
                    MessageBox.Show("Ooops. The start minutes must be between 0 and 59!");
                    return;
                }
            }
            else
            {
                MessageBox.Show("Ooops. Please enter start minutes[0,59] !");
                return;
            }

            if (int.TryParse(txtEndHour.Text, out endHours))
            {
                if (endHours < 8 || endHours >20 )
                {
                    MessageBox.Show("Ooops. The end hour must be between 8 and 20!");
                    return;
                }
            }
            else
            {
                MessageBox.Show("Ooops. Please enter an end hour[8,20] !");
                return;
            }

            if (int.TryParse(txtEndMin.Text, out endMinutes))
            {
                if (endMinutes < 0 || endMinutes > 59)
                {
                    MessageBox.Show("Ooops. The end minutes must be between 0 and 59!");
                    return;
                }
            }
            else
            {
                MessageBox.Show("Ooops. Please enter end minutes[0,59] !");
                return;
            }

            TimeSpan start = new TimeSpan( startHours, startMinutes, seconds );
            TimeSpan end = new TimeSpan( endHours, endMinutes, seconds);

            if (start < end)
            {
                TimeDayRequirement req = new TimeDayRequirement(prof, day, start, end);
                if (Requirements.Contains(req))
                {
                    MessageBox.Show("Ooops. This requirement already exists!");
                    return;
                }
                else
                {
                    Requirements.Add(req);
                }
            }
            else
            {
                MessageBox.Show("Ooops. Start time must be earlier than the end time!");
                return;
            }
        }
Exemple #2
0
        private void TestProfessorDayAndTimeOff()
        {
            config.Clear();

            Stopwatch s = new Stopwatch();

            var mitov = new Professor("Kiril Mitov");
            var abrama = new Professor("Janet Abramowitch");

            var r12 = new Room("12", CourseType.NormalCourse);
            var r24 = new Room("24", CourseType.NormalCourse);
            var r32 = new Room("32", CourseType.ComputerCourse);

            var g11a = new StudentGroup("11A");
            var g11g = new StudentGroup("11G");

            var tp = new Course("TP", mitov, CourseType.ComputerCourse);
            var maths = new Course("Maths", abrama, CourseType.NormalCourse);

            var tp11a = new Class(g11a, tp, new TimeSpan(1, 20, 0), r32);
            var tp11g = new Class(g11g, tp, new TimeSpan(1, 20, 0), r24);

            config.Rooms.Add(r12);
            config.Rooms.Add(r24);
            config.Rooms.Add(r32);

            config.Groups.Add(g11a);
            config.Groups.Add(g11g);

            config.Professors.Add(mitov);
            config.Professors.Add(abrama);

            config.Courses.Add(tp);
            config.Courses.Add(maths);

            Schedule sched = new Schedule();
            for (int i = 0; i < 7; i++)
            {
                sched.SetStartTime(i, g11a, new TimeSpan(8, 0, 0));
                sched.SetStartTime(i, g11g, new TimeSpan(9, 35, 0));
            }
            sched[0][g11a] = new ObservableCollection<Class>();
            sched[0][g11g] = new ObservableCollection<Class>();

            sched[0][g11a].Add(tp11a);//11A class has TP from 8AM to 9:20AM in room 32 on monday
            sched[0][g11g].Add(tp11g);//11G class has TP from 9:35AM to 10:55AM in room 24 on monday
            //result should be false as professor day conflict
            TimeSpan start = new TimeSpan(9, 30, 0);
            TimeSpan end = new TimeSpan(16, 20, 0);
            List<TimeDayRequirement> prevents = new List<TimeDayRequirement>();
            TimeDayRequirement aPrevent = new TimeDayRequirement(mitov, 0, start, end);
            prevents.Add(aPrevent);
            s.Start();
            IConstraint c = new ProfessorDayAndTimeConstraint(prevents);
            var result = c.Check(sched);
            s.Stop();

            string pass = result.ConstraintFulfilled == false ? "succeeded" : "failed";
            Console.WriteLine("TestProfessorDayAndTimeConstraint() " + pass);
            Console.WriteLine(result.ErrorMessage);
            Console.WriteLine("{0} ms.", s.ElapsedMilliseconds);
        }