Beispiel #1
0
 private List<TimetableItem> ParseTable(HtmlDocument document, TimetableType type, StudyYear studyYear = StudyYear.None, HalfYear halfYear = HalfYear.None, string groupNumber = "")
 {
     List<TimetableItem> timetable = new List<TimetableItem>();
     if (document.DocumentNode.Descendants("table").Count() > 0)
     {
         foreach (HtmlNode table in document.DocumentNode.Descendants("table"))
         {
             DayOfWeek day = DayOfWeek.Monday;
             foreach (HtmlNode tableRow in table.Descendants("tr"))
             {
                 bool isDirty = false;
                 if (tableRow.Attributes.Count == 0)
                 {
                     TimetableItem item = null;
                     int index = 0;
                     foreach (HtmlNode tableCell in tableRow.Descendants("td"))
                     {
                         string innerText = tableCell.InnerText.Trim();
                         if (tableCell.Attributes.Count > 0 && tableCell.Attributes[0].Value == "10")
                         {
                             day = new DayOfWeek();
                             day = GetDayFromCell(innerText);
                         }
                         else
                         {
                             switch (index)
                             {
                                 case 0:
                                     item = new TimetableItem();
                                     item.Day = day;
                                     int startHours;
                                     int startMinutes;
                                     if (Int32.TryParse(innerText.Substring(0, 2), out startHours) &&
                                         Int32.TryParse(innerText.Substring(3, 2), out startMinutes))
                                     {
                                         item.StartTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, startHours, startMinutes, 0);
                                     }
                                     break;
                                 case 1:
                                     int endHours;
                                     int endMinutes;
                                     if (Int32.TryParse(innerText.Substring(0, 2), out endHours) &&
                                         Int32.TryParse(innerText.Substring(3, 2), out endMinutes))
                                     {
                                         item.EndTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, endHours, endMinutes, 0);
                                     }
                                     break;
                                 case 2:
                                     if (type == TimetableType.Year)
                                     {
                                         item.StudyGroup = GetGroupFromCell(innerText);
                                         index--;
                                         type = TimetableType.Group;
                                         isDirty = true;
                                     }
                                     else
                                     {
                                         item.ClassName = innerText;
                                         if (item.StudyGroup == null)
                                         {
                                             item.StudyGroup = new Group
                                             {
                                                 YearOfStudy = studyYear,
                                                 HalfYearOfStudy = halfYear,
                                                 Number = groupNumber
                                             };
                                         }
                                         if (isDirty)
                                             type = TimetableType.Year;
                                     }
                                     break;
                                 case 3:
                                     item.TypeOfClass = GetClassTypeFromCell(innerText);
                                     break;
                                 case 4:
                                     item.TeacherName = innerText;
                                     break;
                                 case 5:
                                     item.RoomNumber = innerText;
                                     break;
                                 case 6:
                                     item.Frequency = GetFrequencyFromCell(innerText);
                                     break;
                                 case 7:
                                     item.OptionalPackage = GetOptionalPackageFromCell(innerText);
                                     break;
                             }
                             index++;
                         }
                     }
                     if (item != null)
                         timetable.Add(item);
                 }
             }
         }
     }
     return timetable;
 }
Beispiel #2
0
        private List<TimetableItem> ConvertToRegularTimetable(List<FiiTimetableItem> timetableForGroup)
        {
            var list = new List<TimetableItem>();

            foreach (var fiiTimetableItem in timetableForGroup)
            {
                var item = new TimetableItem();
                item.ClassName = fiiTimetableItem.ClassName;
                item.Day = fiiTimetableItem.Day;
                item.EndTime = fiiTimetableItem.EndTime;
                item.OptionalPackage = fiiTimetableItem.OptionalPackage;
                item.RoomNumber = fiiTimetableItem.RoomNumber;
                item.StartTime = fiiTimetableItem.StartTime;
                item.Frequency = fiiTimetableItem.Frequency;
                var studyGroupIds = new List<string>();
                foreach (var group in fiiTimetableItem.StudyGroups)
                {
                    string year = string.Empty;
                    if (group.YearOfStudy != StudyYear.None)
                        year = Enum.GetName(typeof (StudyYear), group.YearOfStudy);

                    string halfYear = String.Empty;
                    if (group.HalfYearOfStudy != HalfYear.None)
                        halfYear = Enum.GetName(typeof (HalfYear), group.HalfYearOfStudy);

                    studyGroupIds.Add(GetGroupIdByName(year + halfYear + group.Number));
                }
                item.StudyGroups = studyGroupIds;
                item.Teacher = fiiTimetableItem.TeacherName;
                item.TypeOfClass = fiiTimetableItem.TypeOfClass;
                list.Add(item);
            }
            return list;
        }