/// <summary> /// Default constructor. /// </summary> public MainWindowViewModel() { // The commands must be initialised before the fields, because commands are updated // as soon as a property changes in our view model. SelectRootPathFolderCommand = new CommandHandler(SelectRootPathFolder, () => true); // The Load button can not be clicked if the path is empty. LoadFileCommand = new CommandHandler(LoadAfterCheck, () => !String.IsNullOrWhiteSpace(RootPath)); AddPenaltyCommand = new CommandHandler <Line>(AddPenalty, () => true); RemovePenaltyCommand = new CommandHandler(RemovePenalty, CanRemovePenalty); ActivateCroissantCommand = new CommandHandler(ActivateCroissant, CanActivateCroissant); SelectLineCommand = new CommandHandler <Line>((line) => SelectedLine = line, () => true); RemoveLineCommand = new CommandHandler <Line>(RemoveLine, () => true); UpdateLineCommand = new CommandHandler <Line>(UpdateLine, () => true); AddLineCommand = new CommandHandler(AddLine, () => true); EmailCommand = new CommandHandler(EmailSituation, () => (Lines.Count > 0 && !IsSendingEmail)); // The Save button can not be clicked if the path is empty. SaveCommand = new CommandHandler(Save, () => !String.IsNullOrWhiteSpace(RootPath)); IsSendingEmail = false; // By default, the proccesed date is the current day. ProcessedDate = DateTime.Now; // Load the configuration. PetitsPainsStore.ReadConfig(); // Set the original root path. this._RootPathOriginal = PetitsPainsStore.RootPath; // Retrieve the root path for the files of the application. RootPath = PetitsPainsStore.RootPath; // Load the lines. Load(); }
/// <summary> /// Saves the lines and the configuration to the corresponding files. /// </summary> private void Save() { // Reset the error state. ErrorPathInvalid = string.Empty; // Perform checks. CheckChosenFolder(); // Continue only if there is no error. if (String.IsNullOrWhiteSpace(ErrorPathInvalid)) { UpdatePath(); // Update the config file. PetitsPainsStore.WriteConfig(); // Save the lines. PetitsPainsStore.WriteCroissantsLines(this.Lines.ToList()); } }
/// <summary> /// Load the lines from the file. /// </summary> private void Load() { Lines = new ItemsChangeObservableCollection <Line>(PetitsPainsStore.ReadCroissantsLines()); }