From 4760444d7276aec024dac5fbbc202becc41105dd Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Sun, 30 Dec 2018 18:33:30 +0200 Subject: Machine designer working with spools ! PMR of dispenser & spools changed. --- .../ViewModels/MainViewVM.cs | 44 ++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MainViewVM.cs') diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MainViewVM.cs index b0b97d7d4..a5b54fed2 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MainViewVM.cs @@ -101,6 +101,14 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels set { _filter = value; RaisePropertyChangedAuto(); OnFilterChanged(); } } + private Spool _selectedSpool; + public Spool SelectedSpool + { + get { return _selectedSpool; } + set { _selectedSpool = value; RaisePropertyChangedAuto(); InvalidateRelayCommands(); } + } + + #endregion #region Commands @@ -140,6 +148,16 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels /// public RelayCommand BackToMachinesCommand { get; set; } + /// + /// Gets or sets the add spool command. + /// + public RelayCommand AddSpoolCommand { get; set; } + + /// + /// Gets or sets the remove spool command. + /// + public RelayCommand RemoveSpoolCommand { get; set; } + #endregion #region Constructors @@ -165,8 +183,11 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels SaveCommand = new RelayCommand(SaveMachine); AddMachineCommand = new RelayCommand(AddNewMachine); RemoveMachineCommand = new RelayCommand(RemoveSelectedMachine,() => SelectedMachine != null); + AddSpoolCommand = new RelayCommand(AddNewSpool); + RemoveSpoolCommand = new RelayCommand(RemoveSpool,() => SelectedSpool != null); } + #endregion #region Application Ready @@ -489,6 +510,11 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels } } + if (ActiveMachine.Spools.GroupBy(x => x.SpoolType).Any(x => x.Count() > 1)) + { + errors.Add($"Same spool type is registered multiple times."); + } + if (errors.Count > 0) { String errorsString = "Please fix the following validation errors before trying to save." + Environment.NewLine + Environment.NewLine; @@ -508,6 +534,7 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels ActiveMachine.LastUpdated = DateTime.UtcNow; ActiveMachine.ProductionDate = DateTime.UtcNow; await ActiveMachineAdapter.Context.SaveChangesAsync(); + await SelectedMachine.Reload(MachinesAdapter.Context); } } catch (Exception ex) @@ -554,6 +581,23 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels #endregion + private void AddNewSpool() + { + _activeMachineAdapter.Context.Spools.Add(new Spool() + { + Machine = ActiveMachine, + }); + } + + private void RemoveSpool() + { + if (SelectedSpool != null) + { + _activeMachineAdapter.Context.Spools.Remove(SelectedSpool); + ActiveMachine.Spools.Remove(SelectedSpool); + } + } + private async void OnFilterChanged() { if (Filter != null) -- cgit v1.3.1