diff --git a/VECTO3GUI/ViewModel/Impl/AbstractViewModel.cs b/VECTO3GUI/ViewModel/Impl/AbstractViewModel.cs index 802679acddd5664691078d1c828dd1f23770c26a..95782eb5be93cd17a20d313baf6aea9ec391a7c8 100644 --- a/VECTO3GUI/ViewModel/Impl/AbstractViewModel.cs +++ b/VECTO3GUI/ViewModel/Impl/AbstractViewModel.cs @@ -77,10 +77,15 @@ namespace VECTO3GUI.ViewModel.Impl return null; } - public virtual void ShowValidationError(Dictionary<string, string> errors) + public virtual void ShowValidationErrors(Dictionary<string, string> errors) { } + public virtual void RemoveValidationErrors(Dictionary<string, string> errors) + { + } + + #region Submodule Handling protected IEnumerable<Component> GetSubmodels() { diff --git a/VECTO3GUI/ViewModel/Impl/AuxiliariesViewModel.cs b/VECTO3GUI/ViewModel/Impl/AuxiliariesViewModel.cs index bc444973a3bc7fce1eee8ffc215f5526794f9e81..9107544e13a4b2ab8e030fdc6fb26f27cb77c22a 100644 --- a/VECTO3GUI/ViewModel/Impl/AuxiliariesViewModel.cs +++ b/VECTO3GUI/ViewModel/Impl/AuxiliariesViewModel.cs @@ -424,7 +424,7 @@ namespace VECTO3GUI.ViewModel.Impl ClearChangedProperties(); return _componentData; } - public override void ShowValidationError(Dictionary<string, string> errors) + public override void ShowValidationErrors(Dictionary<string, string> errors) { if (errors.IsNullOrEmpty()) return; @@ -433,13 +433,22 @@ namespace VECTO3GUI.ViewModel.Impl { string propertyName; if (XmlNamesToPropertyMapping.TryGetValue(error.Key, out propertyName)) - { AddPropertyError(propertyName, error.Value); - } } } + public override void RemoveValidationErrors(Dictionary<string, string> errors) + { + if (errors.IsNullOrEmpty()) + return; - + foreach (var error in errors) + { + string propertyName; + if (XmlNamesToPropertyMapping.TryGetValue(error.Key, out propertyName)) + RemovePropertyError(propertyName); + } + } + #region Commands diff --git a/VECTO3GUI/ViewModel/Impl/CompleteVehicleBusJobViewModel.cs b/VECTO3GUI/ViewModel/Impl/CompleteVehicleBusJobViewModel.cs index 1309953ef789924cbefd831282f1ef1fe5295391..10ef4b11db7e46a9abe1b39431ae91f50831d4b8 100644 --- a/VECTO3GUI/ViewModel/Impl/CompleteVehicleBusJobViewModel.cs +++ b/VECTO3GUI/ViewModel/Impl/CompleteVehicleBusJobViewModel.cs @@ -7,6 +7,7 @@ using System.Windows; using System.Windows.Input; using System.Xml; using System.Xml.Schema; +using Castle.Core.Internal; using MahApps.Metro.Controls.Dialogs; using Ninject; using TUGraz.VectoCommon.InputData; @@ -37,6 +38,9 @@ namespace VECTO3GUI.ViewModel.Impl private Dictionary<string, string> _errors; private ICommand _validateInputCommand; private ICommand _validationErrorsCommand; + private ICommand _removeValidationErrorsCommand; + + private bool _validationErrorsDisplayed; #endregion @@ -83,7 +87,7 @@ namespace VECTO3GUI.ViewModel.Impl SaveAsButtonVisible = IsNewJob; SaveButtonVisibility = !IsNewJob; } - + #region Commands protected override bool CanSaveJob(Window window) @@ -92,19 +96,20 @@ namespace VECTO3GUI.ViewModel.Impl } protected override void DoSaveJob(Window window) { - var dialogSettings = new MetroDialogSettings() + var dialogSettings = new MetroDialogSettings { AffirmativeButtonText = "Yes", NegativeButtonText = "Cancel", AnimateShow = true, AnimateHide = true }; - + var dialogResult = MetroDialogHelper.GetModalDialogBox(this, "Save", - "The existing file will be overwritten, do you want to continue?", + "The existing file will be overwritten, do you want to continue?", MessageDialogStyle.AffirmativeAndNegative, dialogSettings); - - if (dialogResult == MessageDialogResult.Affirmative) { + + if (dialogResult == MessageDialogResult.Affirmative) + { SetCurrentDataToSave(); var xDoc = _xmlCompletedBus.GenerateCompletedBusDocument(CompleteVehicleBusData); @@ -112,17 +117,15 @@ namespace VECTO3GUI.ViewModel.Impl _xmlCompletedBusWriter.WriteCompletedBusXml(XmlFilePath, xDoc); CloseWindow(window); } - + ValidationResultDialogWindow(false); } } - - - protected override void DoCloseJob(Window window) { - if (CloseWindowDialog()) { + if (CloseWindowDialog()) + { CloseWindow(window); } } @@ -130,16 +133,18 @@ namespace VECTO3GUI.ViewModel.Impl protected override void DoSaveAsJob(Window window) { var filePath = FileDialogHelper.SaveXmlFileToDialog(SettingsModel.XmlFilePathFolder); - if(filePath == null) + if (filePath == null) return; SetCurrentDataToSave(); var xDocument = _xmlCompletedBus.GenerateCompletedBusDocument(CompleteVehicleBusData); - if (XmlHelper.ValidateXDocument(xDocument, null, ValidationErrorAction)) { + if (XmlHelper.ValidateXDocument(xDocument, null, ValidationErrorAction)) + { _xmlCompletedBusWriter.WriteCompletedBusXml(filePath, xDocument); CloseWindow(window); } + ValidationResultDialogWindow(false); } public ICommand CommitComponent @@ -174,13 +179,17 @@ namespace VECTO3GUI.ViewModel.Impl public ICommand ResetComponent { - get { return _resetComponentCommand ?? - (_resetComponentCommand = new RelayCommand<Component>(DoResetComponent, CanResetComponent)); } + get + { + return _resetComponentCommand ?? + (_resetComponentCommand = new RelayCommand<Component>(DoResetComponent, CanResetComponent)); + } } private bool CanResetComponent(Component component) { return ComponentsChanged(component); - }private void DoResetComponent(Component component) + } + private void DoResetComponent(Component component) { switch (component) { @@ -196,6 +205,23 @@ namespace VECTO3GUI.ViewModel.Impl } } + public ICommand RemoveValidationErrors + { + get + { + return _removeValidationErrorsCommand ?? + (_removeValidationErrorsCommand = new RelayCommand(DoRemoveValidationErrors, CanRemoveValidationErrors)); + } + } + private bool CanRemoveValidationErrors() + { + return _validationErrorsDisplayed && !_errors.IsNullOrEmpty(); + } + private void DoRemoveValidationErrors() + { + ClearValidationErrors(); + } + #endregion private void SetCurrentDataToSave() @@ -206,13 +232,14 @@ namespace VECTO3GUI.ViewModel.Impl { Component.Auxiliaries, _subModels[Component.Auxiliaries].CommitComponentData()} }; } - + private bool ComponentsChanged(Component component) { - switch (component) { - case Component.CompleteBusVehicle : + switch (component) + { + case Component.CompleteBusVehicle: return _subModels[Component.CompleteBusVehicle].IsComponentDataChanged(); - case Component.Airdrag : + case Component.Airdrag: return _subModels[Component.Airdrag].IsComponentDataChanged(); case Component.Auxiliaries: return _subModels[Component.Auxiliaries].IsComponentDataChanged(); @@ -234,32 +261,42 @@ namespace VECTO3GUI.ViewModel.Impl private void DoValidateInput() { + ClearValidationErrors(); + _errors = new Dictionary<string, string>(); SetCurrentDataToSave(); var xDoc = _xmlCompletedBus.GenerateCompletedBusDocument(CompleteVehicleBusData); - if (XmlHelper.ValidateXDocument(xDoc, null, ValidationErrorAction)) - { - _xmlCompletedBusWriter.WriteCompletedBusXml(XmlFilePath, xDoc); + if (XmlHelper.ValidateXDocument(xDoc, null, ValidationErrorAction)) { + ValidationResultDialogWindow(true); + } else { + ValidationResultDialogWindow(false); } } - public ICommand ValidationErrors + public ICommand ShowValidationErrors { get { - return _validationErrorsCommand ?? (_validationErrorsCommand = new RelayCommand(DoValidationErrors)); + return _validationErrorsCommand ?? (_validationErrorsCommand = new RelayCommand(DoShowValidationErrors, CanShowValidationErrors)); } } - - private void DoValidationErrors() + private bool CanShowValidationErrors() + { + return !_validationErrorsDisplayed && !_errors.IsNullOrEmpty(); + } + private void DoShowValidationErrors() { + ClearValidationErrors(); + var completedBusViewModel = _subModels[Component.CompleteBusVehicle] as CompleteVehicleBusViewModel; var auxiliaryViewModel = _subModels[Component.Auxiliaries] as AuxiliariesViewModel; - - completedBusViewModel?.ShowValidationError(_errors); - auxiliaryViewModel?.ShowValidationError(_errors); + + completedBusViewModel?.ShowValidationErrors(_errors); + auxiliaryViewModel?.ShowValidationErrors(_errors); + + _validationErrorsDisplayed = true; } @@ -276,7 +313,34 @@ namespace VECTO3GUI.ViewModel.Impl _errors.Add(localName, message?.Message); } } - + + private void ClearValidationErrors() + { + if (_errors.IsNullOrEmpty()) + return; + + + var completedBusViewModel = _subModels[Component.CompleteBusVehicle] as CompleteVehicleBusViewModel; + var auxiliaryViewModel = _subModels[Component.Auxiliaries] as AuxiliariesViewModel; + + completedBusViewModel?.RemoveValidationErrors(_errors); + auxiliaryViewModel?.RemoveValidationErrors(_errors); + + _validationErrorsDisplayed = false; + } + + private void ValidationResultDialogWindow(bool validationResult) + { + if (validationResult) { + MetroDialogHelper.GetModalDialogBox(this, "Input Validation", + "No validation errors were found, the entered data is valid!", MessageDialogStyle.Affirmative); + } else { + MetroDialogHelper.GetModalDialogBox(this, "Input Validation", + "There are some input validation errors, the data must be valid for saving!", MessageDialogStyle.Affirmative); + } + } + + public string JobFile { get; } public IInputDataProvider InputDataProvider { get; set; } diff --git a/VECTO3GUI/ViewModel/Impl/CompleteVehicleBusViewModel.cs b/VECTO3GUI/ViewModel/Impl/CompleteVehicleBusViewModel.cs index 96d4602afd79795070c1ca05f62ed9840945b603..e8868d78bab5f6faf2b09ae75277dd2d4550dbe3 100644 --- a/VECTO3GUI/ViewModel/Impl/CompleteVehicleBusViewModel.cs +++ b/VECTO3GUI/ViewModel/Impl/CompleteVehicleBusViewModel.cs @@ -181,7 +181,7 @@ namespace VECTO3GUI.ViewModel.Impl get { return _lowEntry; } set { - if (!SetProperty(ref _lowEntry, value)) + if (!SetProperty(ref _lowEntry, value)) return; IsDataChanged(_lowEntry, _componentData); } @@ -283,7 +283,7 @@ namespace VECTO3GUI.ViewModel.Impl NgTankSystem = vehicle.TankSystem; NumberOfPassengersLowerDeck = vehicle.NumberOfPassengersLowerDeck; NumberOfPassengersUpperDeck = vehicle.NumberOfPassengersUpperDeck; - LowEntry = vehicle.FloorType == FloorType.LowFloor; + LowEntry = vehicle.FloorType == FloorType.LowFloor; HeightIntegratedBody = vehicle.Height; VehicleLength = vehicle.Length; VehicleWidth = vehicle.Width; @@ -297,18 +297,18 @@ namespace VECTO3GUI.ViewModel.Impl private void SetAllowedEntries() { - AllowedLegislativeClasses = new [] {LegislativeClass.M3} + AllowedLegislativeClasses = new[] { LegislativeClass.M3 } .Select(lc => AllowedEntry.Create(lc, lc.GetLabel())).ToArray(); AllowedVehicleCodes = EnumHelper.GetValues<VehicleCode>().Where(x => x != VehicleCode.NOT_APPLICABLE) .Select(vc => AllowedEntry.Create(vc, vc.GetLabel())).ToArray(); - AllowedDoorDriveTechnologies = new [] {ConsumerTechnology.Pneumatically, ConsumerTechnology.Electrically} + AllowedDoorDriveTechnologies = new[] { ConsumerTechnology.Pneumatically, ConsumerTechnology.Electrically } .Select(sc => AllowedEntry.Create(sc, sc.GetLabel())).ToArray(); AllowedRegisteredClasses = EnumHelper.GetValues<RegistrationClass>().Where(x => x != RegistrationClass.unknown) .Select(vc => AllowedEntry.Create(vc, vc.GetLabel())).ToArray(); - + AllowedTankSystems = new[] { AllowedEntry.Create((TankSystem?)null, "Not applicable") } .Concat(EnumHelper.GetValues<TankSystem>().Select(x => AllowedEntry.Create((TankSystem?)x, x.ToString()))).ToArray(); } @@ -327,19 +327,32 @@ namespace VECTO3GUI.ViewModel.Impl return _componentData; } - public override void ShowValidationError(Dictionary<string, string> errors) + public override void ShowValidationErrors(Dictionary<string, string> errors) { if (errors.IsNullOrEmpty()) return; - foreach (var error in errors) { - + foreach (var error in errors) + { string propertyName; - if (XmlNamesToPropertyMapping.TryGetValue(error.Key, out propertyName)) { + if (XmlNamesToPropertyMapping.TryGetValue(error.Key, out propertyName)) AddPropertyError(propertyName, error.Value); - } } } + + public override void RemoveValidationErrors(Dictionary<string, string> errors) + { + if (errors.IsNullOrEmpty()) + return; + + foreach (var error in errors) + { + string propertyName; + if (XmlNamesToPropertyMapping.TryGetValue(error.Key, out propertyName)) + RemovePropertyError(propertyName); + } + } + } } diff --git a/VECTO3GUI/ViewModel/Impl/DeclarationJobViewModel.cs b/VECTO3GUI/ViewModel/Impl/DeclarationJobViewModel.cs index ab77ed10754c003d210a6c0d605c7e18cddaf8b7..5cf5480c5664e75d5c9f50e45411e8ae6775959f 100644 --- a/VECTO3GUI/ViewModel/Impl/DeclarationJobViewModel.cs +++ b/VECTO3GUI/ViewModel/Impl/DeclarationJobViewModel.cs @@ -91,6 +91,7 @@ namespace VECTO3GUI.ViewModel.Impl } public ICommand ValidateInput { get; } - public ICommand ValidationErrors { get; } + public ICommand ShowValidationErrors { get; } + public ICommand RemoveValidationErrors { get; } } } diff --git a/VECTO3GUI/ViewModel/Impl/EngineOnlyJobViewModel.cs b/VECTO3GUI/ViewModel/Impl/EngineOnlyJobViewModel.cs index 7e25fbb903c817798bd1e86ac78715da7d247c42..0349c271282da92d7b1e3f3c5b86c2522a7fd811 100644 --- a/VECTO3GUI/ViewModel/Impl/EngineOnlyJobViewModel.cs +++ b/VECTO3GUI/ViewModel/Impl/EngineOnlyJobViewModel.cs @@ -47,7 +47,8 @@ namespace VECTO3GUI.ViewModel.Impl } public ICommand ValidateInput { get; } - public ICommand ValidationErrors { get; } + public ICommand ShowValidationErrors { get; } + public ICommand RemoveValidationErrors { get; } #endregion diff --git a/VECTO3GUI/ViewModel/Impl/PrimaryVehicleBusJobViewModel.cs b/VECTO3GUI/ViewModel/Impl/PrimaryVehicleBusJobViewModel.cs index 8ae295352d01ae2c434f0a9394a183ae60990c1c..2046232651d9b40d9cddc725ff27f507c99f801d 100644 --- a/VECTO3GUI/ViewModel/Impl/PrimaryVehicleBusJobViewModel.cs +++ b/VECTO3GUI/ViewModel/Impl/PrimaryVehicleBusJobViewModel.cs @@ -47,6 +47,7 @@ namespace VECTO3GUI.ViewModel.Impl } public IInputDataProvider InputDataProvider { get; set; } public ICommand ValidateInput { get; } - public ICommand ValidationErrors { get; } + public ICommand ShowValidationErrors { get; } + public ICommand RemoveValidationErrors { get; } } } diff --git a/VECTO3GUI/ViewModel/Interfaces/IComponentViewModel.cs b/VECTO3GUI/ViewModel/Interfaces/IComponentViewModel.cs index 1db0e7cdfec436236a2dfadab1c452f5089ab157..f8163babd631cd1b0dbeb707a32708fd3d6f8ee9 100644 --- a/VECTO3GUI/ViewModel/Interfaces/IComponentViewModel.cs +++ b/VECTO3GUI/ViewModel/Interfaces/IComponentViewModel.cs @@ -21,7 +21,8 @@ namespace VECTO3GUI.ViewModel.Interfaces { void ResetComponentData(); object CommitComponentData(); - void ShowValidationError(Dictionary<string, string> errors); + void ShowValidationErrors(Dictionary<string, string> errors); + void RemoveValidationErrors(Dictionary<string, string> errors); } diff --git a/VECTO3GUI/ViewModel/Interfaces/IJobEditViewModel.cs b/VECTO3GUI/ViewModel/Interfaces/IJobEditViewModel.cs index 2d7a7c67a812f107cd2e7a075f52f2795ea3f67f..e4d4e1af06b5fbb05af8618f9e0d985f9427a6f5 100644 --- a/VECTO3GUI/ViewModel/Interfaces/IJobEditViewModel.cs +++ b/VECTO3GUI/ViewModel/Interfaces/IJobEditViewModel.cs @@ -21,7 +21,8 @@ namespace VECTO3GUI.ViewModel.Interfaces ICommand SaveAsJob { get; } ICommand CloseJob { get; } ICommand ValidateInput { get; } - ICommand ValidationErrors { get; } + ICommand ShowValidationErrors { get; } + ICommand RemoveValidationErrors { get; } } } diff --git a/VECTO3GUI/Views/JoblistTabView.xaml b/VECTO3GUI/Views/JoblistTabView.xaml index 08e2463c8a1471a63c747a7c918ecc0e2167cf8a..bfccdb6c4c4c816f8412b14aa149a192f03d3955 100644 --- a/VECTO3GUI/Views/JoblistTabView.xaml +++ b/VECTO3GUI/Views/JoblistTabView.xaml @@ -42,8 +42,10 @@ <MenuItem Header="Input Validation"> <MenuItem Header="Validate" Command="{Binding ValidateInput}"/> - <MenuItem Header="Validation Errors" - Command="{Binding ValidationErrors}"/> + <MenuItem Header="Show Validation Errors" + Command="{Binding ShowValidationErrors}"/> + <MenuItem Header="Remove Validation Errors" + Command="{Binding RemoveValidationErrors}"/> </MenuItem> </Menu> <Separator HorizontalAlignment="Stretch" Background="Gray"/>