/// <summary> /// Perform operations to close the application. /// - Save any changes required to the selected WorkItem. /// - If SAVE_WINDOW_COORDS_ON_EXIT == 1, save window position /// - If DATA_EXPORT_AUTOMATICALLY == 1 and either not done or today, create backup. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) { // Check to see if a Save is required based on the current selection if (_model.SelectedWorkItem != null) { UpdateWorkItemDBAsRequired(); } if (_model.WorkItemCheckListDBNeedsUpdating) { _controller.UpdateDBCheckListItem(_model.SelectedCheckListItem, 0); } // If set as a preference, save the window location. if (_model.GetAppPreferenceValue(PreferenceName.SAVE_WINDOW_COORDS_ON_EXIT).Equals("1", StringComparison.CurrentCultureIgnoreCase)) { string coords = $"{this.Left},{this.Top},{this.Width},{this.Height}"; _model.FireUpdateAppPreference(PreferenceName.APPLICATION_WINDOW_COORDS, coords); } if (_model.GetAppPreferenceAsBooleanValue(PreferenceName.DATA_EXPORT_AUTOMATICALLY)) { int backupEveryDays = Int32.Parse(_model.GetAppPreferenceValue(PreferenceName.DATA_EXPORT_PERIOD_DAYS)); // Get how often backups should be done. DateTime backupLastDone = DateTime.Parse(_model.GetAppPreferenceValue(PreferenceName.DATA_EXPORT_LAST_DONE)); // Get when it was last done. double daysSinceLastBackup = (DateTime.Now.Date - backupLastDone.Date).TotalDays; // Get days since the backup was done. string exportLastDoneStr = _model.GetAppPreferenceValue(PreferenceName.DATA_EXPORT_LAST_DONE); if ((daysSinceLastBackup >= backupEveryDays) || ((_model.GetAppPreferenceAsBooleanValue(PreferenceName.DATA_EXPORT_SAME_DAY_OVERWRITE) && (daysSinceLastBackup == 0)))) { _controller.CreateBackupFile(); } } }