示例#1
0
        /// <summary>
        /// Generates schedules, first from program database, then from example data in Scheduler class
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Button_Click_Generate_Schedules(object sender, RoutedEventArgs e)
        {
            int               score;
            List <Room>       rooms       = GetRooms();
            List <Instructor> instructors = GetInstructors();
            List <Course>     courses     = GetCourses();

            Scheduler scheduler = new Scheduler();
            //Schedule scheduleFromDataBase = s.generateScheduleLvl1(courses, s.instructorList, rooms);
            //s.printSchedule(scheduleFromDataBase);

            Schedule scheduleFromExampleData = scheduler.generateScheduleLvl1(scheduler.courseList, scheduler.instructorList, scheduler.roomList);

            //Console.WriteLine("First schedule: \n\n");
            //scheduler.printSchedule(scheduleFromExampleData);

            score = ScoreSchedule(scheduleFromExampleData);

            CourseSchedulerDBDataSet.InstructorsDataTable instructorTbl = new CourseSchedulerDBDataSet.InstructorsDataTable();
            CourseSchedulerDBDataSet.CoursesDataTable     courseTbl     = new CourseSchedulerDBDataSet.CoursesDataTable();
            CourseSchedulerDBDataSet.RoomsDataTable       roomTbl       = new CourseSchedulerDBDataSet.RoomsDataTable();
            dataBaseHandler.RoomsTableAdapter.Fill(roomTbl);
            dataBaseHandler.CoursesTableAdapter.Fill(courseTbl);
            dataBaseHandler.InstructorsTableAdapter.Fill(instructorTbl);
            dataBaseHandler.InsertNewSchedule(scheduleFromExampleData.scheduleID, scheduleFromExampleData.score);
            dataBaseHandler.InsertNewPossibleCourse((CourseSchedulerDBDataSet.CoursesRow)courseTbl.Rows[0], (CourseSchedulerDBDataSet.InstructorsRow)instructorTbl.Rows[0], 8, 10, "MW", (CourseSchedulerDBDataSet.RoomsRow)roomTbl.Rows[0]);
            dataBaseHandler.InsertNewPossibleCourse((CourseSchedulerDBDataSet.CoursesRow)courseTbl.Rows[1], (CourseSchedulerDBDataSet.InstructorsRow)instructorTbl.Rows[0], 12, 14, "TH", (CourseSchedulerDBDataSet.RoomsRow)roomTbl.Rows[1]);
            dataBaseHandler.InsertNewPossibleCourse((CourseSchedulerDBDataSet.CoursesRow)courseTbl.Rows[2], (CourseSchedulerDBDataSet.InstructorsRow)instructorTbl.Rows[0], 16, 17, "MWF", (CourseSchedulerDBDataSet.RoomsRow)roomTbl.Rows[2]);
            dataBaseHandler.InsertNewPossibleCourse((CourseSchedulerDBDataSet.CoursesRow)courseTbl.Rows[3], (CourseSchedulerDBDataSet.InstructorsRow)instructorTbl.Rows[1], 8, 10, "TF", (CourseSchedulerDBDataSet.RoomsRow)roomTbl.Rows[3]);
            dataBaseHandler.InsertNewPossibleCourse((CourseSchedulerDBDataSet.CoursesRow)courseTbl.Rows[4], (CourseSchedulerDBDataSet.InstructorsRow)instructorTbl.Rows[1], 12, 14, "MTW", (CourseSchedulerDBDataSet.RoomsRow)roomTbl.Rows[4]);
            dataBaseHandler.InsertNewPossibleCourse((CourseSchedulerDBDataSet.CoursesRow)courseTbl.Rows[5], (CourseSchedulerDBDataSet.InstructorsRow)instructorTbl.Rows[1], 16, 17, "HF", (CourseSchedulerDBDataSet.RoomsRow)roomTbl.Rows[5]);
            CourseSchedulerDBDataSet.PossibleCoursesDataTable tbl = new CourseSchedulerDBDataSet.PossibleCoursesDataTable();
            dataBaseHandler.PossibleCoursesTableAdapter.Fill(tbl);
            CourseSchedulerDBDataSet.SchedulesDataTable scheduleTbl = new CourseSchedulerDBDataSet.SchedulesDataTable();
            dataBaseHandler.SchedulesTableAdapter.Fill(scheduleTbl);
            dataBaseHandler.InsertNewJoin_Schedules_PossibleCourses((CourseSchedulerDBDataSet.SchedulesRow)scheduleTbl.Rows[0], (CourseSchedulerDBDataSet.PossibleCoursesRow)tbl.Rows[0]);
            dataBaseHandler.InsertNewJoin_Schedules_PossibleCourses((CourseSchedulerDBDataSet.SchedulesRow)scheduleTbl.Rows[0], (CourseSchedulerDBDataSet.PossibleCoursesRow)tbl.Rows[1]);
            dataBaseHandler.InsertNewJoin_Schedules_PossibleCourses((CourseSchedulerDBDataSet.SchedulesRow)scheduleTbl.Rows[0], (CourseSchedulerDBDataSet.PossibleCoursesRow)tbl.Rows[2]);

            GrdReport.ItemsSource = dataBaseHandler.SchedulesTableAdapter.GetData();

            foreach (var possibleCourse in scheduleFromExampleData.possibleCourses)
            {
                scheduleOutput.Text += "Course Name: " + possibleCourse.course.Name + "\n";
                scheduleOutput.Text += "Instructor Name: " + possibleCourse.instructor.name + "\n";
                scheduleOutput.Text += "Start Time: " + possibleCourse.startTime.ToString() + "\n";
                scheduleOutput.Text += "End Time: " + possibleCourse.endTime.ToString() + "\n";
                scheduleOutput.Text += "Room: " + possibleCourse.room.roomID + "\n";
                scheduleOutput.Text += "Days Offered: " + possibleCourse.datesOffered + "\n";
                scheduleOutput.Text += "\n";
            }
            scheduleOutput.Text += "score: " + score + "\n";

            //Console.WriteLine("\n Twenty other schedules: ");

            //var manySchedules = scheduler.getTwentySchedules(courses, scheduler.instructorList, scheduler.roomList);
            //manySchedules.ForEach(delegate (Schedule s)
            //{
            //    scheduler.printSchedule(s);
            //});
        }