private void BtnGetTimetable_Click(object sender, RoutedEventArgs args)
        {
            TimeTableViewModel vm = DataContext as TimeTableViewModel;

            try
            {
                vm.GetTimeTable();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }
Exemplo n.º 2
0
        static private List <USINGCLASS> AutoMakeSchedule(USINGCLASS usingClass, CLASS class_, ROOM selectedRoom, int selectedStartPeriod)
        {
            if (CalcEndPeriod(selectedStartPeriod, usingClass.Duration) > 5 && selectedStartPeriod <= 5 ||
                CalcEndPeriod(selectedStartPeriod, usingClass.Duration) == -1)
            {
                return(null);
            }

            List <USINGCLASS> result = null;

            var beginningRoomID      = usingClass.RoomID;
            var beginningStartPeriod = usingClass.StartPeriod;

            List <ROOM> listRoomFiltered;

            if (selectedRoom == null)
            {
                listRoomFiltered = (from room in DataProvider.Ins.DB.ROOMs
                                    where room.Capacity >= class_.Population_
                                    select room).ToList();
            }
            else if (selectedRoom.Capacity >= class_.Population_)
            {
                listRoomFiltered = new List <ROOM>();
                listRoomFiltered.Add(selectedRoom);
            }
            else
            {
                listRoomFiltered = new List <ROOM>();
            }

            var targetDate = ((DateTime)usingClass.StartDate).AddDays(usingClass.Day_ - 1);

            TimeTableViewModel timeTableViewModel = new TimeTableViewModel();

            timeTableViewModel.selectedDay = targetDate.Day;
            timeTableViewModel.selectedMonth.monthValue = targetDate.Month;
            timeTableViewModel.selectedYear             = targetDate.Year;

            timeTableViewModel.GetTimeTable();

            var listUsingClass = timeTableViewModel.tb; // get all using class for that day

            // only get using on the room that satisfy the capacity
            var listUsingClassFiltered = listUsingClass.Where(x => { return(DataProvider.Ins.DB.ROOMs.Find(x.roomID).Capacity >= class_.Population_); }).ToList();
            var ListUsedRoom           = (from usg in listUsingClassFiltered
                                          select usg.roomID).ToList();

            List <ROOM> listUnusedRoom = listRoomFiltered.Where(x => { return(!ListUsedRoom.Contains(x.RoomID)); }).ToList();

            foreach (var room in listRoomFiltered)
            {
                usingClass.RoomID      = room.RoomID;
                usingClass.StartPeriod = selectedStartPeriod;

                USINGCLASS        overlappedUsingClass         = CheckOverlapUsingClass(usingClass, class_);
                USINGCLASS        overlappedLecturerUsingClass = CheckOverlapLecturerTimeUsingClass(usingClass, class_);
                List <USINGEVENT> listOverlappedEvent          = new List <USINGEVENT>();

                if (overlappedUsingClass == null && overlappedLecturerUsingClass == null)
                {
                    // we found an empty room and time, finish here
                    result = HandleOverlapEvent(usingClass, class_, out listOverlappedEvent);

                    if (result != null)
                    {
                        return(result);
                    }
                }
            }

            return(null);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Auto choose the Room and Start period for the usingclass
        ///
        /// </summary>
        /// <param name="usingClass"></param>
        /// <param name="class_"></param>
        /// <param name="selectedRoom">If selected room is null, function auto choose the room for you</param>
        /// <returns>
        ///     If success, return list of new UsingClass that auto scheduled
        ///     Otherwise, return null
        /// </returns>
        static private List <USINGCLASS> AutoMakeSchedule(USINGCLASS usingClass, CLASS class_, ROOM selectedRoom)
        {
            List <USINGCLASS> result = null;

            var beginningRoomID      = usingClass.RoomID;
            var beginningStartPeriod = usingClass.StartPeriod;

            List <ROOM> listRoomFiltered;

            if (selectedRoom == null)
            {
                listRoomFiltered = (from room in DataProvider.Ins.DB.ROOMs
                                    where room.Capacity >= class_.Population_
                                    select room).ToList();
            }
            else if (selectedRoom.Capacity >= class_.Population_)
            {
                listRoomFiltered = new List <ROOM>();
                listRoomFiltered.Add(selectedRoom);
            }
            else
            {
                listRoomFiltered = new List <ROOM>();
            }

            var targetDate = ((DateTime)usingClass.StartDate).AddDays(usingClass.Day_ - 1);

            TimeTableViewModel timeTableViewModel = new TimeTableViewModel();

            timeTableViewModel.selectedDay = targetDate.Day;
            timeTableViewModel.selectedMonth.monthValue = targetDate.Month;
            timeTableViewModel.selectedYear             = targetDate.Year;

            timeTableViewModel.GetTimeTable();

            var listUsingClass = timeTableViewModel.tb; // get all using class for that day

            // only get using on the room that satisfy the capacity
            var listUsingClassFiltered = listUsingClass.Where(x => { return(DataProvider.Ins.DB.ROOMs.Find(x.roomID).Capacity >= class_.Population_); }).ToList();
            var ListUsedRoom           = (from usg in listUsingClassFiltered
                                          select usg.roomID).ToList();

            List <ROOM> listUnusedRoom = listRoomFiltered.Where(x => { return(!ListUsedRoom.Contains(x.RoomID)); }).ToList();

            foreach (var room in listRoomFiltered)
            {
                usingClass.RoomID      = room.RoomID;
                usingClass.StartPeriod = 1;

                USINGCLASS        overlappedUsingClass         = CheckOverlapUsingClass(usingClass, class_);
                USINGCLASS        overlappedLecturerUsingClass = CheckOverlapLecturerTimeUsingClass(usingClass, class_);
                List <USINGEVENT> listOverlappedEvent          = new List <USINGEVENT>();

                if (overlappedUsingClass == null && overlappedLecturerUsingClass == null)
                {                        // we found an empty room and time, finish here
                    result = HandleOverlapEvent(usingClass, class_, out listOverlappedEvent);

                    if (result != null)
                    {
                        return(result);
                    }
                }

                if (result == null)
                {
                    int newStartPeriod = 0;
                    int endPeriod      = 0;

                    // loop through period to find the next fit in room on target date
                    while (endPeriod != -1)
                    {
                        if (overlappedUsingClass == null && overlappedLecturerUsingClass == null)
                        // if both are null, then the problem is with the event
                        {
                            listOverlappedEvent.Sort((x, y) =>
                            {
                                return(Convert.ToInt32(CalcEndPeriod(x.StartPeriod, x.Duration) < CalcEndPeriod(y.StartPeriod, y.Duration)));
                            });

                            newStartPeriod = CalcEndPeriod(listOverlappedEvent[0].StartPeriod, listOverlappedEvent[0].Duration) + 1;
                        }
                        else if (overlappedUsingClass == null)
                        {
                            newStartPeriod = CalcEndPeriod(overlappedLecturerUsingClass.StartPeriod, overlappedLecturerUsingClass.Duration) + 1;
                        }
                        else if (overlappedLecturerUsingClass == null || overlappedUsingClass.StartPeriod > overlappedLecturerUsingClass.StartPeriod)
                        {
                            newStartPeriod = CalcEndPeriod(overlappedUsingClass.StartPeriod, overlappedUsingClass.Duration) + 1;
                        }
                        else
                        {
                            newStartPeriod = CalcEndPeriod(overlappedLecturerUsingClass.StartPeriod, overlappedLecturerUsingClass.Duration) + 1;
                        }

                        endPeriod = CalcEndPeriod(newStartPeriod, usingClass.Duration);

                        if (endPeriod == -1)
                        {
                            break;
                        }

                        if (newStartPeriod <= 5 && endPeriod > 5)
                        {
                            newStartPeriod = 6;
                            endPeriod      = CalcEndPeriod(newStartPeriod, usingClass.Duration);
                        }

                        if (endPeriod == -1)
                        {
                            break;
                        }

                        usingClass.StartPeriod = newStartPeriod;

                        overlappedUsingClass         = CheckOverlapUsingClass(usingClass, class_);
                        overlappedLecturerUsingClass = CheckOverlapLecturerTimeUsingClass(usingClass, class_);

                        if (overlappedUsingClass == null && overlappedLecturerUsingClass == null)
                        {
                            result = HandleOverlapEvent(usingClass, class_, out listOverlappedEvent);

                            if (result != null)
                            {
                                return(result);
                            }
                        }
                    }
                }
            }

            usingClass.RoomID      = beginningRoomID;
            usingClass.StartPeriod = beginningStartPeriod;

            return(result);
        }