From 8ae0f3da19c537eff30e19a1fe99cce51b3116f1 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Tue, 23 Jan 2018 17:58:59 +0200 Subject: A lot of work on Developer Module and Jobs related DB tables. --- .../ViewModels/MainViewVM.cs | 120 +++++++++++++++++++-- .../Views/MainView.xaml | 100 ++++++++++------- 2 files changed, 172 insertions(+), 48 deletions(-) (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer') diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs index 621ce550b..34a4ff470 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/ViewModels/MainViewVM.cs @@ -7,6 +7,7 @@ using System.Text; using System.Threading.Tasks; using Tango.Core.Commands; using Tango.DAL.Observables; +using Tango.MachineStudio.Common.Notifications; using Tango.MachineStudio.Common.StudioApplication; using Tango.SharedUI; @@ -14,6 +15,8 @@ namespace Tango.MachineStudio.Developer.ViewModels { public class MainViewVM : ViewModel { + private INotificationProvider _notification; + public IStudioApplicationManager ApplicationManager { get; set; } public ObservablesEntitiesAdapter Adapter { get; set; } @@ -34,18 +37,43 @@ namespace Tango.MachineStudio.Developer.ViewModels set { _liquidTypesRmls = value; RaisePropertyChangedAuto(); } } - private ObservableCollection _rmlProcessParametersTables; + private ProcessParametersTablesGroup _rmlProcessParametersTablesGroup; + + public ProcessParametersTablesGroup RmlProcessParametersTableGroup + { + get { return _rmlProcessParametersTablesGroup; } + set { _rmlProcessParametersTablesGroup = value; RaisePropertyChangedAuto(); } + } + + private ProcessParametersTablesGroup _selectedGroupHistory; - public ObservableCollection RmlProcessParametersTables + public ProcessParametersTablesGroup SelectedGroupHistory { - get { return _rmlProcessParametersTables; } - set { _rmlProcessParametersTables = value; RaisePropertyChangedAuto(); } + get { return _selectedGroupHistory; } + set { _selectedGroupHistory = value; RaisePropertyChangedAuto(); OnSelectedGroupHistoryChanged(); } } + private void OnSelectedGroupHistoryChanged() + { + if (SelectedGroupHistory != null) + { + RmlProcessParametersTableGroup = SelectedGroupHistory.CloneGroup(); + } + } - private DBViewContextWrapper _selectedRML; + private ObservableCollection _groupsHistory; - public DBViewContextWrapper SelectedRML + public ObservableCollection GroupsHistory + { + get { return _groupsHistory; } + set { _groupsHistory = value; RaisePropertyChangedAuto(); } + } + + + + private Rml _selectedRML; + + public Rml SelectedRML { get { return _selectedRML; } set { _selectedRML = value; RaisePropertyChangedAuto(); InvalidateLiquidFactorsAndProcessTables(); InvalidateRelayCommands(); } @@ -66,24 +94,48 @@ namespace Tango.MachineStudio.Developer.ViewModels public RelayCommand ToggleSideBarCommand { get; set; } + public RelayCommand SaveProcessParametersCommand { get; set; } + + public RelayCommand SaveLiquidFactorsCommand { get; set; } + public MainViewVM() { IsSideBarOpened = true; } [PreferredConstructor] - public MainViewVM(IStudioApplicationManager applicationManager) + public MainViewVM(IStudioApplicationManager applicationManager, INotificationProvider notificationProvider) { + _notification = notificationProvider; Adapter = ObservablesEntitiesAdapter.Instance; EditMachineCommand = new RelayCommand(EditMachine, (x) => SelectedMachine != null); ApplicationManager = applicationManager; EditRMLCommand = new RelayCommand(EditRML, (x) => SelectedRML != null); ToggleSideBarCommand = new RelayCommand(() => IsSideBarOpened = !IsSideBarOpened); + SaveProcessParametersCommand = new RelayCommand(SaveProcessParameters); + SaveLiquidFactorsCommand = new RelayCommand(SaveLiquidFactors); + } + + private async void SaveLiquidFactors() + { + if (SelectedRML != null) + { + using (_notification.PushTaskItem("Saving Liquid Factors...")) + { + String machineGuid = SelectedMachine.Guid; + String rmlGuid = SelectedRML.Guid; + + await SelectedRML.SaveAsync(); + + SelectedMachine = Adapter.Machines.SingleOrDefault(x => x.Guid == machineGuid); + SelectedRML = Adapter.Rmls.SingleOrDefault(x => x.Guid == rmlGuid); + } + } } private void EditRML() { - ApplicationManager.RequestModule("Data Base", SelectedRML.EditEntity); + ApplicationManager.RequestModule("Data Base", SelectedRML); } private void EditMachine() @@ -96,12 +148,60 @@ namespace Tango.MachineStudio.Developer.ViewModels InvalidateLiquidFactorsAndProcessTables(); } + private async void SaveProcessParameters() + { + var response = _notification.ShowTextInput("Enter Group Name", "Group Name"); + + if (response == null) return; + + using (_notification.PushTaskItem("Saving Parameters Group...")) + { + ProcessParametersTablesGroup group = new ProcessParametersTablesGroup(); + + List tables = new List(); + foreach (var table in RmlProcessParametersTableGroup.ProcessParametersTables) + { + var newTable = table.CloneEntity(); + newTable.ProcessParametersTablesGroups = group; + tables.Add(newTable); + } + + group.Active = true; + group.ProcessParametersTables = tables.ToObservableCollection(); + group.Rml = SelectedRML; + group.Name = response; + group.SaveDate = DateTime.UtcNow; + + foreach (var g in SelectedRML.ProcessParametersTablesGroups) + { + g.Active = false; + } + + String machineGuid = SelectedMachine.Guid; + String rmlGuid = SelectedRML.Guid; + + SelectedRML.ProcessParametersTablesGroups.Add(group); + await SelectedRML.SaveAsync(); + + SelectedMachine = Adapter.Machines.SingleOrDefault(x => x.Guid == machineGuid); + SelectedRML = Adapter.Rmls.SingleOrDefault(x => x.Guid == rmlGuid); + } + } + private void InvalidateLiquidFactorsAndProcessTables() { if (SelectedRML != null && SelectedMachine != null) { - LiquidTypesRmls = SelectedMachine.Configuration.IdsPacks.OrderBy(x => x.PackIndex).Select(x => x.LiquidTypes).SelectMany(x => x.LiquidTypesRmls).Where(x => x.Rml.Guid == SelectedRML.EditEntity.Guid).ToList(); - RmlProcessParametersTables = SelectedRML.EditEntity.RmlsProcessParametersTables.ToObservableCollection(); + LiquidTypesRmls = SelectedMachine.Configuration.IdsPacks.OrderBy(x => x.PackIndex).Select(x => x.LiquidTypes).SelectMany(x => x.LiquidTypesRmls).Where(x => x.Rml.Guid == SelectedRML.Guid).ToList(); + RmlProcessParametersTableGroup = SelectedRML.ProcessParametersTablesGroups.SingleOrDefault(x => x.Active); + + if (RmlProcessParametersTableGroup != null) + { + RmlProcessParametersTableGroup = RmlProcessParametersTableGroup.CloneGroup(); + RmlProcessParametersTableGroup.ProcessParametersTables = RmlProcessParametersTableGroup.ProcessParametersTables.OrderBy(x => x.TableIndex).ToObservableCollection(); + } + + GroupsHistory = SelectedRML.ProcessParametersTablesGroups.OrderByDescending(x => x.SaveDate).OrderBy(x => !x.Active).ToObservableCollection(); } } } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MainView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MainView.xaml index d6cba4914..fa6cbbd76 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MainView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Developer/Views/MainView.xaml @@ -77,18 +77,45 @@ - - + + + + + HISTORY + + + + + + + + + + + + + + + + + - + - + - - + + Dyeing Speed: - + Min Ink Uptake: - + Mixer Temp: - + Head Zone1 Temp: - + Head Zone2 Temp: - + Head Zone3 Temp: - + Head Air Flow: - + Feeder Tension: - + Puller Tension: - + Dryer Buffer Length: - + Dryer Zone1 Temp: - + Dryer Zone2 Temp: - + Dryer Zone3 Temp: - + @@ -204,28 +231,14 @@ Dryer Air Flow: - + Winder Tension: - - - - - - - Lubrication NL/CM: - - - - - - - Lubrication: - + @@ -234,10 +247,14 @@ + + + + - +