public GeneralDataEditorPageViewModel(Timetable timetable) { this.timetable = timetable; this.Subjects = new ReadOnlyCollection<SubjectViewModel>(timetable.Subjects.Select(p => new SubjectViewModel(p)).ToList()); this.LessonTimes = new ReadOnlyCollection<LessonTimeViewModel>(timetable.LessonTimes.Select(p => new LessonTimeViewModel(p)).ToList()); timetable.Subjects.CollectionChanged += Subjects_CollectionChanged; timetable.LessonTimes.CollectionChanged += LessonTimes_CollectionChanged; }
public ProgressViewModel(Timetable timetable, string notEnoughDataString, string freeTimeString, string progressStringFormat) { this.timetable = timetable; this.notEnoughData = new LessonViewModel(new Lesson(null, new SubjectRoom(new Subject(notEnoughDataString), ""))); this.empty = new LessonViewModel(new Lesson(null, new SubjectRoom(new Subject(""), ""))); this.freeTimeString = freeTimeString; this.progressStringFormat = progressStringFormat; this.UpdateData(); }
public DateOverviewPageViewModel(Timetable timetable, string statePast, string stateToday, string stateThisWeek, string stateThisMonth, string stateFuture) { this.timetable = timetable; this.timetable.Dates.CollectionChanged += (sender, e) => { UpdateDatesGrouped(); }; this.statePast = statePast; this.stateToday = stateToday; this.stateThisWeek = stateThisWeek; this.stateThisMonth = stateThisMonth; this.stateFuture = stateFuture; this.UpdateDatesGrouped(); }
public HomeworkOverviewPageViewModel(Timetable timetable, string noFilterSubjectName) { this.timetable = timetable; this.timetable.Homeworks.CollectionChanged += (sender, e) => { this.ResortHomework(); }; this.timetable.Subjects.CollectionChanged += (sender, e) => { this.ReloadSubjects(); }; this.NoFilterSubject = new SubjectViewModel(new Subject(noFilterSubjectName)); ReloadSubjects(); this.HomeworkOrders = new ReadOnlyCollection<OrderBy>(new List<OrderBy>(Enum.GetValues(typeof(OrderBy)).Cast<OrderBy>())); this.ResortHomework(); }
public MainPageViewModel(Timetable timetable) { this.timetable = timetable; timetable.PropertyChanged += (sender, e) => { if (e.PropertyName == "Name") NotifyPropertyChanged("TimetableName"); }; this.Days = new ReadOnlyCollection<object>(this.timetable.Days.Select(p => (object)new DayViewModel(this.timetable, p)).ToList()); this.LessonTimes = new ReadOnlyCollection<LessonTimeViewModel>(this.timetable.LessonTimes.Select(p => new LessonTimeViewModel(p)).ToList()); this.timetable.Days.CollectionChanged += Days_CollectionChanged; LessonViewModel.IsOddWeekChanged += (s, e) => NotifyPropertyChanged("WeekNumber"); }
public TimetableSettingsPageViewModel(Timetable timetable) { this.timetable = timetable; this.Name = timetable.Name; this.DaysOfWeek = new ReadOnlyCollection<DayOfWeekSettingsViewModel>(new DayOfWeek[] { DayOfWeek.Monday, DayOfWeek.Tuesday, DayOfWeek.Wednesday, DayOfWeek.Thursday, DayOfWeek.Friday, DayOfWeek.Saturday, DayOfWeek.Sunday }.Select(p => new DayOfWeekSettingsViewModel(p, timetable.Days.Any(q => q.DayOfWeek == p))).ToList()); }
internal Lesson(LessonTime lessonTime, Timetable timetable, XElement element) { this.officalLessonTime = lessonTime; if (element.Attribute("Start") != null && element.Attribute("End") != null) { this.isCustomLessonTime = true; this.LessonTime = new LessonTime(officalLessonTime.Number, DateTime.Parse(element.Attribute("Start").Value), DateTime.Parse(element.Attribute("End").Value)); } else this.IsCustomLessonTime = false; if (element.Attribute("Subject") != null) { //Ins neue Format konvertieren this.DataEvenWeek = new SubjectRoom(timetable.GetSubject(element.Attribute("Subject").Value), element.Attribute("Room").Value); this.DataOddWeek = new SubjectRoom(this.DataEvenWeek.Subject, this.DataEvenWeek.Room); } else { this.DataEvenWeek = new SubjectRoom( timetable.GetSubject(element.Attribute("SubjectEvenWeek").Value), element.Attribute("RoomEvenWeek").Value); bool value; if (element.Attribute("IsChangingLesson") != null && bool.TryParse(element.Attribute("IsChangingLesson").Value, out value) && !value) { this.DataOddWeek = new SubjectRoom(DataEvenWeek.Subject, DataEvenWeek.Room); } else { this.DataOddWeek = new SubjectRoom( timetable.GetSubject(element.Attribute("SubjectOddWeek").Value), element.Attribute("RoomOddWeek").Value); } } }
public ColorViewModel(string color, Subject subject, Timetable timetable) { this.Color = color; var subjects = timetable.Subjects.Where(p => p.Color == color && p != subject).Select(p => p.Name).OrderBy(p => p); int maxAmount = 3; if (!subjects.Any()) OtherSubjects = ""; else { OtherSubjects = string.Join("," + Environment.NewLine, subjects.Take(maxAmount)); if (subjects.Count() > 3) OtherSubjects += "," + Environment.NewLine + "..."; } this.subject = subject; subject.PropertyChanged += subject_PropertyChanged; }
public EditHomeworkPageViewModel(Homework homework, Timetable timetable) : base(homework) { this.Subjects = new ReadOnlyCollection<SubjectViewModel>(timetable.Subjects.Select(p => new SubjectViewModel(p)).ToList()); }
/// <summary> /// Invoked when the application is launched normally by the end user. Other entry points /// will be used when the application is launched to open a specific file, to display /// search results, and so forth. /// </summary> /// <param name="e">Details about the launch request and process.</param> protected override void OnLaunched(LaunchActivatedEventArgs e) { #if DEBUG if (System.Diagnostics.Debugger.IsAttached) { this.DebugSettings.EnableFrameRateCounter = true; } #endif Frame rootFrame = Window.Current.Content as Frame; // Do not repeat app initialization when the Window already has content, // just ensure that the window is active if (rootFrame == null || (e.Arguments != null && e.Arguments != "")) { // Create a Frame to act as the navigation context and navigate to the first page rootFrame = new Frame(); rootFrame.CacheSize = 3; if (e.PreviousExecutionState == ApplicationExecutionState.Terminated) { } // Place the frame in the current Window Window.Current.Content = rootFrame; } TimetableIO.ErrorMessageDispatcher = rootFrame.Dispatcher; // Load timetable synchronous here to avoid having to rewrite the entire Codebase to understand async. if (e.Arguments != null && e.Arguments != "" && (Timetable == null || Timetable.FileName != e.Arguments)) { Timetable = Task.Run(async () => { if (Timetable != null) await TimetableIO.SaveTimetable(Timetable); return await TimetableIO.LoadTimetable(e.Arguments); }).Result; } if(Timetable == null) { Timetable = Task.Run(async () => { var timetable = await TimetableIO.LoadCurrentTimetable(); if (timetable == null) timetable = Timetable.CreateNew(Strings.TimetableNewName, await TimetableIO.ReserveNewTimetableFilename()); return timetable; }).Result; } if (rootFrame.Content == null) { // Removes the turnstile navigation for startup. if (rootFrame.ContentTransitions != null) { this.transitions = new TransitionCollection(); foreach (var c in rootFrame.ContentTransitions) { this.transitions.Add(c); } } rootFrame.ContentTransitions = null; rootFrame.Navigated += this.RootFrame_FirstNavigated; rootFrame.Navigating += this.RootFrame_Navigating; // When the navigation stack isn't restored navigate to the first page, // configuring the new page by passing required information as a navigation // parameter if (!rootFrame.Navigate(typeof(MainPage), e.Arguments)) { throw new Exception("Failed to create initial page"); } } ShowOpenSourceMessage(); // Ensure the current window is active Window.Current.Activate(); }
public EditSubjectPageViewModel(Subject subject, Timetable timetable) : base(subject) { this.oldName = subject.Name; this.Teachers = new ReadOnlyCollection<string>(timetable.Subjects.Select(p => p.Teacher).Distinct().ToList()); this.AvailableColors = new ReadOnlyCollection<ColorViewModel>(new String[] { "A4C400", "60A917", "008A00", "00ABA9", "1BA1E2", "3E65FF", "6A00FF", "AA00FF", "F472D0", "D80073", "A20025", "E51400", "FA6800", "F0A30A", "E3C800", "825A2C", "6D8764", "647687", "76608A", "87794E" }.Select(p => new ColorViewModel(p, subject, timetable)).ToList()); }
public bool IsSameTimetable(Timetable timetable) { return timetable == this.timetable; }
public static async Task SaveTimetable(Timetable timetable) { try { var timetableDirectory = await GetTimetableDirectory(); var timetableFile = await timetableDirectory.CreateFileAsync(timetable.FileName, CreationCollisionOption.OpenIfExists); try { var backupFile = await timetableDirectory.CreateFileAsync(timetable.FileName + backupExtension, CreationCollisionOption.OpenIfExists); await timetableFile.CopyAndReplaceAsync(backupFile); timetableFile = await timetableDirectory.CreateFileAsync(timetable.FileName, CreationCollisionOption.ReplaceExisting); } catch (Exception e) { if (System.Diagnostics.Debugger.IsAttached) System.Diagnostics.Debugger.Break(); throw new Exception(Strings.TimetableSaveToFileBackupException, e); } //XML-Generieren string xml; try { var appVersion = Package.Current.Id.Version.Major + "." + Package.Current.Id.Version.Minor; xml = timetable.WriteXml(appVersion); } catch (Exception e) { if (System.Diagnostics.Debugger.IsAttached) System.Diagnostics.Debugger.Break(); throw new Exception(Strings.TimetableSaveFileInnerXmlException, e); } //Alles in die Datei schreiben try { using (var stream = await timetableFile.OpenStreamForWriteAsync()) using (StreamWriter streamWriter = new StreamWriter(stream)) { streamWriter.Write(xml); } } catch (Exception e) { if (System.Diagnostics.Debugger.IsAttached) System.Diagnostics.Debugger.Break(); throw new Exception(Strings.TimetableSaveFileInnerSaveException, e); } using (var stream = await (await (await GetTimetableDirectory()).CreateFileAsync(currentTimetableFileName, CreationCollisionOption.ReplaceExisting)) .OpenStreamForWriteAsync()) using (var writer = new StreamWriter(stream)) { writer.Write(timetable.FileName); } } catch (Exception error) { //Worst Case Situation ComposeErrorReport(String.Format(Strings.LoadSaveSaveErrorFormat, error.Message), error, error.InnerException); } }
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; }
/// <summary> /// Erstellt einen neuen, Leeren Stundenplan. /// Einziger Inhalt sind 5 Wochentage und 6 Zeiten für Unterrichtsstunden /// </summary> /// <param name="name">Name des Stundenplans</param> /// <returns>Ein neuer Stundenplan.</returns> public static Timetable CreateNew(string name, string fileName) { Timetable timetable = new Timetable(name, fileName); timetable.Days.Add(new Day(DayOfWeek.Monday)); timetable.Days.Add(new Day(DayOfWeek.Tuesday)); timetable.Days.Add(new Day(DayOfWeek.Wednesday)); timetable.Days.Add(new Day(DayOfWeek.Thursday)); timetable.Days.Add(new Day(DayOfWeek.Friday)); // for (int i = 0; i < 6; i++) // timetable.AddLessonTime(); return timetable; }