Пример #1
0
        private async void SetupTimetable(string newRoom)
        {
            // clear timetable
            timetableUtils.clearTimetable(timetableThisWeek);

            /*request list of timetableObjects*/
            List <TimetableObject> items = await roomTimetableModel.GetRoomTimetable(newRoom);

            /*find out if current week is even or odd*/
            int evenOdd = timetableUtils.isCurrentWeekEvenOrOdd();

            /*display objects in grid*/
            foreach (TimetableObject item in items)
            {
                int[] row = timetableUtils.getRowForTable(item);
                if (row[0] != -1 && row[1] != -1)
                {
                    for (int currentRow = row[0]; currentRow <= row[1]; currentRow++)
                    {
                        // prepare the button for this lesson
                        TimetableItem timetableItem = new TimetableItem();
                        timetableItem.TextBlock.Text = item.LessonTag + "\n"
                                                       + item.Type + "\n"
                                                       + item.Professor;
                        Grid.SetColumn(timetableItem, item.Day);
                        Grid.SetRow(timetableItem, currentRow);

                        // switch for the week number
                        switch (item.Week)
                        {
                        /*lesson takes place every week*/
                        case 0: {
                            timetableUtils.addLessonToWeek(timetableThisWeek, currentRow, timetableItem);
                            break;
                        }

                        /*only at odd weeks*/
                        case 1: {
                            if (evenOdd == 1)
                            {
                                timetableUtils.addLessonToWeek(timetableThisWeek, currentRow, timetableItem);
                            }
                            break;
                        }

                        /*only at even weeks*/
                        case 2: {
                            if (evenOdd == 0)         /*current week is even -> show it first*/
                            {
                                timetableUtils.addLessonToWeek(timetableThisWeek, currentRow, timetableItem);
                            }
                            break;
                        }

                        default: {
                            break;
                        }
                        }
                    }
                }
            }
        }
Пример #2
0
        async Task LoadTimetables()
        {
            timetableModel = TimetableModel.GetInstance();
            timetableUtils = new TimetableUtils();
            settingsModel  = SettingsModel.GetInstance();
            TimetableObjectsList timetableObjects = await timetableModel.GetTimetable(settingsModel.StgJhr, settingsModel.Stg, settingsModel.StgGrp);

            if (timetableObjects != null)
            {
                // clear the timetables
                timetableUtils.clearTimetable(timetableThisWeek);
                timetableUtils.clearTimetable(timetableNextWeek);

                Lessons = timetableObjects.timetableObjects;

                UpdateLiveTile();

                /*find out if current week is even or odd*/
                int evenOdd = timetableUtils.isCurrentWeekEvenOrOdd();

                foreach (TimetableObject timetableObject in Lessons)
                {
                    int[] row = timetableUtils.getRowForTable(timetableObject);
                    if (row[0] != -1 && row[1] != -1)
                    {
                        for (int currentRow = row[0]; currentRow <= row[1]; currentRow++)
                        {
                            // prepare the button for this lesson
                            TimetableItem timetableItem = new TimetableItem();
                            string        room          = "";
                            if (timetableObject.Rooms.Count > 1)
                            {
                                room = timetableObject.Rooms[0] + " ...";
                            }
                            else
                            {
                                room = timetableObject.Rooms[0];
                            }
                            timetableItem.TextBlock.Text = timetableObject.LessonTag + "\n"
                                                           + timetableObject.Type + "\n"
                                                           + room;
                            Grid.SetColumn(timetableItem, timetableObject.Day);
                            Grid.SetRow(timetableItem, currentRow);
                            // switch for the week number
                            switch (timetableObject.Week)
                            {
                            /*lesson takes place every week*/
                            case 0: {
                                timetableUtils.addLessonToWeek(timetableThisWeek, currentRow, timetableItem);
                                // clone the button
                                TimetableItem clone = new TimetableItem();
                                Grid.SetColumn(clone, timetableObject.Day);
                                Grid.SetRow(clone, currentRow);
                                clone.TextBlock.Text = timetableItem.TextBlock.Text;
                                timetableUtils.addLessonToWeek(timetableNextWeek, currentRow, clone);
                                break;
                            }

                            /*only at odd weeks*/
                            case 1: {
                                /*if current week is even add it to next week*/
                                if (evenOdd == 0)
                                {
                                    timetableUtils.addLessonToWeek(timetableNextWeek, currentRow, timetableItem);
                                }
                                else
                                {
                                    timetableUtils.addLessonToWeek(timetableThisWeek, currentRow, timetableItem);
                                }
                                break;
                            }

                            /*only at even weeks*/
                            case 2: {
                                /*if current week is even add it to this week*/
                                if (evenOdd == 0)
                                {
                                    timetableUtils.addLessonToWeek(timetableThisWeek, currentRow, timetableItem);
                                }
                                else
                                {
                                    timetableUtils.addLessonToWeek(timetableNextWeek, currentRow, timetableItem);
                                }
                                break;
                            }

                            default: {
                                break;
                            }
                            }
                        }
                    }
                }
                // update timestamp
                timestampThisWeek.Text = timestampNextWeek.Text = "Stand: " + timetableObjects.timestamp.ToLocalTime().ToString();
            }
        }