From c23d740d6a80db62b7b43ea17639ba4c2ef4e336 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Wed, 3 Oct 2018 14:19:04 +0300 Subject: Working on RML Module.. --- .../ViewModels/AddLiquidFactorViewVM.cs | 50 +++++++++++++++ .../ViewModels/MainViewVM.cs | 71 ++++++++++++++++++++++ 2 files changed, 121 insertions(+) create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/AddLiquidFactorViewVM.cs (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels') diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/AddLiquidFactorViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/AddLiquidFactorViewVM.cs new file mode 100644 index 000000000..f6fca0ac2 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/AddLiquidFactorViewVM.cs @@ -0,0 +1,50 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.BL; +using Tango.BL.Entities; +using Tango.SharedUI; +using System.Data.Entity; + +namespace Tango.MachineStudio.RML.ViewModels +{ + public class AddLiquidFactorViewVM : DialogViewVM + { + private ObservablesContext _context; + + private ObservableCollection _liquidTypes; + public ObservableCollection LiquidTypes + { + get + { + return _liquidTypes; + } + set + { + _liquidTypes = value; RaisePropertyChangedAuto(); + } + } + + private LiquidType _selectedLiquidType; + public LiquidType SelectedLiquidType + { + get { return _selectedLiquidType; } + set { _selectedLiquidType = value; RaisePropertyChangedAuto(); } + } + + public AddLiquidFactorViewVM(ObservablesContext context) + { + _context = context; + } + + public async override void OnShow() + { + base.OnShow(); + LiquidTypes = (await _context.LiquidTypes.ToListAsync()).ToObservableCollection(); + SelectedLiquidType = LiquidTypes.FirstOrDefault(); + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/MainViewVM.cs index b7e7859ac..be46e2148 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/ViewModels/MainViewVM.cs @@ -14,6 +14,7 @@ using Tango.MachineStudio.ColorLab.ViewModels; using Tango.MachineStudio.Common; using Tango.MachineStudio.Common.Notifications; using Tango.MachineStudio.RML.Contracts; +using Tango.MachineStudio.RML.Views; namespace Tango.MachineStudio.RML.ViewModels { @@ -140,6 +141,14 @@ namespace Tango.MachineStudio.RML.ViewModels public RelayCommand AddProcessParametersTableCommand { get; set; } + public RelayCommand RemoveProcessParametersTableCommand { get; set; } + + public RelayCommand AddLiquidFactorCommand { get; set; } + + public RelayCommand RemoveLiquidFactorCommand { get; set; } + + public RelayCommand CreateCalibrationDataExcelTemplateCommand { get; set; } + /// /// Gets or sets the back to RMLS command. /// @@ -153,6 +162,10 @@ namespace Tango.MachineStudio.RML.ViewModels AddRmlCommand = new RelayCommand(AddNewRml); BackToRmlsCommand = new RelayCommand(BackToRmls); AddProcessParametersTableCommand = new RelayCommand(AddProcessParametersTable); + RemoveProcessParametersTableCommand = new RelayCommand(RemoveProcessParametersTable); + AddLiquidFactorCommand = new RelayCommand(AddLiquidFactor); + RemoveLiquidFactorCommand = new RelayCommand(RemoveLiquidFactor); + CreateCalibrationDataExcelTemplateCommand = new RelayCommand(CreateCalibrationDataExcelTemplate); } public override void OnApplicationReady() @@ -205,6 +218,7 @@ namespace Tango.MachineStudio.RML.ViewModels CalibrationDataVM catVM = new CalibrationDataVM(); catVM.Name = liquidTypeRml.LiquidType.Name; catVM.Color = liquidTypeRml.LiquidType.Color; + catVM.LiquidType = liquidTypeRml.LiquidType; if (liquidTypeRml.DefaultCatData != null) { @@ -316,6 +330,63 @@ namespace Tango.MachineStudio.RML.ViewModels ActiveProcessParametersTableView.Refresh(); } + private void RemoveLiquidFactor(LiquidTypesRml liquidFactor) + { + if (_notification.ShowQuestion("Removing this liquid factor will remove the liquid type association with the RML and will drop the calibration data. Are you sure?")) + { + var catVM = CalibrationDataViewVM.LiquidsCalibrationData.SingleOrDefault(x => x.LiquidType == liquidFactor.LiquidType); + CalibrationDataViewVM.LiquidsCalibrationData.Remove(catVM); + _active_context.LiquidTypesRmls.Remove(liquidFactor); + } + } + + private void AddLiquidFactor() + { + AddLiquidFactorViewVM vm = new AddLiquidFactorViewVM(_active_context); + _notification.ShowModalDialog(vm, (_) => + { + if (LiquidTypesRmls.ToList().Exists(x => x.LiquidType == vm.SelectedLiquidType)) + { + _notification.ShowError("The selected liquid type is already associated with this RML."); + return; + } + + LiquidTypesRml liquidFactor = new LiquidTypesRml() + { + LiquidType = vm.SelectedLiquidType, + Rml = ActiveRML, + }; + + _active_context.LiquidTypesRmls.Add(liquidFactor); + + CalibrationDataVM catVM = new CalibrationDataVM(); + catVM.Name = liquidFactor.LiquidType.Name; + catVM.Color = liquidFactor.LiquidType.Color; + + CalibrationDataViewVM.LiquidsCalibrationData.Add(catVM); + + }, () => { }); + } + + private void RemoveProcessParametersTable(ProcessParametersTable processParametersTable) + { + if (ActiveProcessParametersGroup.ProcessParametersTables.Count == 1) + { + _notification.ShowError("The process group must contain at least one table."); + return; + } + + if (_notification.ShowQuestion("Are you sure you want to remove this process parameters table?")) + { + _active_context.ProcessParametersTables.Remove(processParametersTable); + } + } + + private void CreateCalibrationDataExcelTemplate() + { + + } + private void BackToRmls() { View.NavigateTo(RmlNavigationView.RmlsView); -- cgit v1.3.1