/// <summary> /// Deletes selected criteria /// </summary> private void DeleteCommand() { // Show message box to ask the user if he wants to delete criteria var vm = new DecisionDialogViewModel { Title = LocalizationResource.CriteriaDeletion, Message = LocalizationResource.ChoosenCriteriaWillBeDeleted + "\n" + LocalizationResource.ContinueQuestion, AcceptText = LocalizationResource.Yes, CancelText = LocalizationResource.No }; DI.UI.ShowMessage(vm); // If user has declined, don't do anything if (!vm.UserResponse) { return; } try { // Try to delete this criteria by old name because the user may have changed it meanwhile CriteriaFileWriter.DeleteXmlFileByName(EditingCriteriaOldName); } catch (Exception ex) { // If an error occured, show info to the user DI.UI.ShowMessage(new MessageBoxDialogViewModel { Title = LocalizationResource.Yes, Message = LocalizationResource.UnableToDeleteCriteria + "\n" + LocalizationResource.ErrorContentSemicolon + ex.Message, OkText = LocalizationResource.Ok }); DI.Logger.Log("Unable to delete criteria file, error message: " + ex.Message); // Don't do anything after the error is shown return; } // Reload items CriteriaListViewModel.Instance.LoadItems(); // Load brand new criteria LoadCriteria(new GradingPercentage()); // Hide all errors and flags EditingCriteriaMode = false; InvalidDataError = false; CriteriaChanged = false; // Mark all criteria unchecked CriteriaListViewModel.Instance.UncheckAll(); }
/// <summary> /// Submits the criteria or saves changes /// </summary> private void SubmitCriteria() { // Check if input data is correct if (!ValidateInputData()) { InvalidDataError = true; return; } // Hide any errors InvalidDataError = false; // Update values in grading object if (Criteria.IsMarkAIncluded) { Criteria.UpdateMark(Marks.A, int.Parse(TopValueMarkA), int.Parse(BottomValueMarkA)); } Criteria.UpdateMark(Marks.B, int.Parse(TopValueMarkB), int.Parse(BottomValueMarkB)); Criteria.UpdateMark(Marks.C, int.Parse(TopValueMarkC), int.Parse(BottomValueMarkC)); Criteria.UpdateMark(Marks.D, int.Parse(TopValueMarkD), int.Parse(BottomValueMarkD)); Criteria.UpdateMark(Marks.E, int.Parse(TopValueMarkE), int.Parse(BottomValueMarkE)); Criteria.UpdateMark(Marks.F, int.Parse(TopValueMarkF), int.Parse(BottomValueMarkF)); try { // Try to save the grading CriteriaFileWriter.WriteToFile(Name, Criteria); // Check if we were editing existing one or not if (EditingCriteriaMode) { // If user has changed the name of the criteria, try to delete old one if (Name != EditingCriteriaOldName) { CriteriaFileWriter.DeleteXmlFileByName(EditingCriteriaOldName); } } } catch (Exception ex) { // If an error occured, show info to the user DI.UI.ShowMessage(new MessageBoxDialogViewModel { Title = LocalizationResource.SaveError, Message = LocalizationResource.UnableToSaveCurrentCriteria + "\n" + LocalizationResource.ErrorContentSemicolon + ex.Message, OkText = LocalizationResource.Ok }); DI.Logger.Log("Unable to save/delete criteria file, error message: " + ex.Message); // Don't do anything after the error is shown return; } // Get out of editing mode EditingCriteriaMode = false; // Mark all criteria unchecked CriteriaListViewModel.Instance.UncheckAll(); // Reload the criteria list to include newly created criteria CriteriaListViewModel.Instance.LoadItems(); // Reload the viewmodel with the sample data LoadCriteria(new GradingPercentage()); Name = ""; }