public static Timetable ParseXml(string xml, string timetableFilename, string legacyTimetableNewName) { XDocument document = XDocument.Parse(xml); Timetable timetable; if (document.Root.Attribute("Name") == null) timetable = new Timetable(legacyTimetableNewName, timetableFilename); else timetable = new Timetable(document.Root.Attribute("Name").Value, timetableFilename); XElement lessonTimesElement = document.Root.Element("LessonTimes"); int n = 0; foreach (XElement e in lessonTimesElement.Elements()) timetable.LessonTimes.Add(new LessonTime(n++, DateTime.Parse(e.Attribute("Start").Value), DateTime.Parse(e.Attribute("End").Value))); XElement subjectsElement = document.Root.Element("Subjects"); foreach (XElement e in subjectsElement.Elements()) { var color = ""; if (e.Attribute("Color") != null) color = e.Attribute("Color").Value; timetable.Subjects.Add(new Subject(e.Attribute("Name").Value, e.Attribute("Teacher").Value, color)); } XElement homeworksElement = document.Root.Element("Homeworks"); foreach (XElement e in homeworksElement.Elements()) timetable.Homeworks.Add(new Homework(timetable.GetSubject(e.Attribute("Subject").Value)) { FromDate = ConvertHelpers.ParseDate(e.Attribute("From").Value), ToDate = ConvertHelpers.ParseDate(e.Attribute("To").Value), Text = e.Attribute("Description").Value.Replace("\\n", "\n"), IsDone = bool.Parse(e.Attribute("IsDone").Value) }); XElement lessonsElement = document.Root.Element("Lessons"); foreach (XElement dayLessonElement in lessonsElement.Elements()) { Day day = new Day((DayOfWeek)Enum.Parse(typeof(DayOfWeek), dayLessonElement.Name.LocalName, true)); int i = 0; foreach (XElement e in dayLessonElement.Elements()) { LessonTime lessonTime = timetable.LessonTimes[i]; day.Lessons.Add(new Lesson(lessonTime, timetable, e)); i++; } timetable.Days.Add(day); } XElement datesElement = document.Root.Element("Dates"); if (datesElement != null) { foreach (XElement e in datesElement.Elements()) timetable.Dates.Add(new Date(e.Attribute("Name").Value, ConvertHelpers.ParseDate(e.Attribute("Due").Value), (RepeatBehaviour)Enum.Parse(typeof(RepeatBehaviour), e.Attribute("Repeat").Value, true))); } return timetable; }
private async void DoneAppBarButton_Click(object sender, RoutedEventArgs e) { var viewModel = (TimetableSettingsPageViewModel)this.DataContext; App.Timetable.Name = this.NameTextBox.Text; if (viewModel.DaysOfWeek.Any(p => p.IsEnabled)) { List<Day> oldDays = new List<Day>(); foreach (Day day in App.Timetable.Days) oldDays.Add(day); App.Timetable.Days.Clear(); foreach (DayOfWeekSettingsViewModel helperDay in viewModel.DaysOfWeek.Where(p => p.IsEnabled)) { Day oldDay = oldDays.FirstOrDefault(p => p.DayOfWeek == helperDay.DayOfWeek); if (oldDay == null) oldDay = new Day(helperDay.DayOfWeek); App.Timetable.Days.Add(oldDay); } } else await new MessageDialog(Strings.PageTimetableSettingsWeekDaysWarning, Strings.MessageBoxWarningCaption).ShowAsync(); this.Frame.GoBack(); }
public Lesson AddLesson(Day day) { Lesson lesson = new Lesson(CheckLessonTime(day.Lessons.Count)); day.Lessons.Add(lesson); return lesson; }