diff options
| author | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2021-02-15 04:26:39 +0200 |
|---|---|---|
| committer | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2021-02-15 04:26:39 +0200 |
| commit | 29ffa937475d82d2c32cbccfb97c2f5f7c8f24cd (patch) | |
| tree | 2c19e49dc72270036e27cdc23b0ee0d8a3429664 /Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MainViewVM.cs | |
| parent | f1af9d5e2c3c7b3fa48a113f41b03aea9deab188 (diff) | |
| download | Tango-29ffa937475d82d2c32cbccfb97c2f5f7c8f24cd.tar.gz Tango-29ffa937475d82d2c32cbccfb97c2f5f7c8f24cd.zip | |
Implemented MS machine prototypes.
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MainViewVM.cs')
| -rw-r--r-- | Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/ViewModels/MainViewVM.cs | 155 |
1 files changed, 26 insertions, 129 deletions
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 dc29515c8..6ddf86ddb 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 @@ -287,7 +287,7 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels public override async void OnApplicationReady() { MachinesAdapter.MachineVersions = (await MachinesAdapter.Context.MachineVersions.ToListAsync()).ToObservableCollection(); - + MachinesAdapter.MachinePrototypes = (await MachinesAdapter.Context.MachinePrototypes.ToListAsync()).ToObservableCollection(); } #endregion @@ -513,7 +513,7 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels { IsNewMachine = true; - if (machineCreationDialogVM.SelectedMachineVersion == null) + if (machineCreationDialogVM.SelectedPrototype == null) { ActiveMachine = new Machine(); ActiveMachine.Configuration = new Configuration(); @@ -526,9 +526,8 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels try { initHwConfig = false; - ActiveMachine = await machineCreationDialogVM.SelectedMachineVersion.CreatePrototypeMachine(ActiveMachineAdapter.Context); - ActiveMachine.SerialNumber = machineCreationDialogVM.SerialNumber; - ActiveMachine.Name = machineCreationDialogVM.Name; + ActiveMachine = machineCreationDialogVM.SelectedPrototype.CreateMachine(machineCreationDialogVM.SerialNumber, machineCreationDialogVM.Name); + ActiveMachine.MachineVersion = ActiveMachineAdapter.MachineVersions.FirstOrDefault(x => x.Guid == ActiveMachine.MachineVersionGuid); ActiveMachineAdapter.Context.Machines.Add(ActiveMachine); HardwareConfigurationViewVM = new HardwareConfigurationViewVM(_notification); @@ -537,105 +536,13 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels } catch (Exception ex) { - _notification.ShowError($"Invalid machine version prototype.\n{ex.FlattenMessage()}"); + _notification.ShowError($"Invalid machine prototype.\n{ex.FlattenMessage()}"); View.NavigateTo(MachineDesignerNavigationView.MachinesView); return; } } } - if ((newMachine || clone) && machineCreationDialogVM.GenerateDispensers) - { - for (int i = 0; i < 10; i++) - { - var serial = machineCreationDialogVM.SerialNumber + "-" + (i + 1); - - var existingDispenser = await ActiveMachineAdapter.Context.Dispensers.Include(x => x.IdsPacks).SingleOrDefaultAsync(x => x.SerialNumber == serial); - - if (existingDispenser != null) - { - if (existingDispenser.IsInstalled) - { - _notification.ShowError($"Dispenser '{serial}' already exists. Cannot create machine."); - return; - } - else - { - if (!_notification.ShowErrorQuestion($"Dispenser '{serial}' already exists and is not installed. Do you wish to assign the existing dispenser to this machine?")) - { - return; - } - } - } - - Dispenser dispenser = new Dispenser(); - - if (existingDispenser == null) - { - dispenser.SerialNumber = serial; - - if (newMachine) - { - dispenser.NlPerPulse = machineCreationDialogVM.DispenserFactor; - - if (i == 8) - { - dispenser.DispenserTypeGuid = ActiveMachineAdapter.DispenserTypes.FirstOrDefault(x => x.Code == BL.Enumerations.DispenserTypes.LubricantDispenser.ToInt32()).Guid; - } - else if (i == 9) - { - dispenser.DispenserTypeGuid = ActiveMachineAdapter.DispenserTypes.FirstOrDefault(x => x.Code == BL.Enumerations.DispenserTypes.CleanerDispenser.ToInt32()).Guid; - } - else - { - dispenser.DispenserTypeGuid = ActiveMachineAdapter.DispenserTypes.FirstOrDefault(x => x.Code == BL.Enumerations.DispenserTypes.StandardDispenser.ToInt32()).Guid; - } - } - else - { - var packBefore = machineConfigBeforeClone.NoneEmptyIdsPacks.SingleOrDefault(x => x.PackIndex == i); - - if (packBefore != null) - { - dispenser.NlPerPulse = packBefore.Dispenser.NlPerPulse; - - if (i == 8) - { - dispenser.DispenserTypeGuid = ActiveMachineAdapter.DispenserTypes.FirstOrDefault(x => x.Code == BL.Enumerations.DispenserTypes.LubricantDispenser.ToInt32()).Guid; - } - else if (i == 9) - { - dispenser.DispenserTypeGuid = ActiveMachineAdapter.DispenserTypes.FirstOrDefault(x => x.Code == BL.Enumerations.DispenserTypes.CleanerDispenser.ToInt32()).Guid; - } - else - { - dispenser.DispenserTypeGuid = ActiveMachineAdapter.DispenserTypes.FirstOrDefault(x => x.Code == BL.Enumerations.DispenserTypes.StandardDispenser.ToInt32()).Guid; - } - } - else - { - continue; - } - } - - dispenser.ProductionDate = DateTime.UtcNow; - - ActiveMachineAdapter.Context.Dispensers.Add(dispenser); - } - else - { - dispenser = existingDispenser; - } - - var idsPack = ActiveMachine.Configuration.NoneEmptyIdsPacks.SingleOrDefault(x => x.PackIndex == i); - - if (idsPack != null) - { - idsPack.Dispenser = dispenser; - idsPack.DispenserGuid = dispenser.Guid; - } - } - } ActiveMachine.OrganizationChanged -= ActiveMachine_OrganizationChanged; ActiveMachine.OrganizationChanged += ActiveMachine_OrganizationChanged; @@ -888,7 +795,7 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels { MachineCreationDialogVM vm = new MachineCreationDialogVM(); vm.IsNewMachine = true; - vm.MachineVersions = MachinesAdapter.MachineVersions.ToList(); + vm.Prototypes = MachinesAdapter.MachinePrototypes.ToList(); _notification.ShowModalDialog<MachineCreationDialogVM, Views.MachineCreationDialog>(vm, (x) => { if (MachinesAdapter.Context.Machines.Any(y => y.SerialNumber == vm.SerialNumber || y.Name.ToLower() == vm.Name.ToLower())) @@ -897,12 +804,6 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels return; } - if (vm.SelectedMachineVersion != null && String.IsNullOrWhiteSpace(vm.SelectedMachineVersion.PrototypeMachineData)) - { - _notification.ShowError("The selected version does not contain any prototype machine data."); - return; - } - LoadSelectedMachine(true, false, vm); }, () => { }); } @@ -946,36 +847,32 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels private async void MakePrototype() { - if (ActiveMachine.MachineVersion == null) - { - _notification.ShowError("Machine version must be selected in order to make a prototype."); - return; - } + String protoName = _notification.ShowTextInput("Enter prototype name", "name"); + + if (!protoName.IsNotNullOrWhiteSpace()) return; - if (_notification.ShowQuestion($"Are you sure you wish to make this machine configuration as a prototype for version '{ActiveMachine.MachineVersion.Name}' ?")) + using (_notification.PushTaskItem($"Saving machine prototype '{protoName}'...")) { - using (_notification.PushTaskItem($"Making prototype machine for '{ActiveMachine.MachineVersion.Name}'...")) + try { - try - { - IsFree = false; + IsFree = false; - using (var db = ObservablesContext.CreateDefault()) - { - var machineVersion = await db.MachineVersions.SingleOrDefaultAsync(x => x.Guid == ActiveMachine.MachineVersionGuid); - await machineVersion.ApplyPrototypeMachine(ActiveMachine, db); - await db.SaveChangesAsync(); - } - } - catch (Exception ex) + using (var db = ObservablesContext.CreateDefault()) { - _notification.ShowError($"Error making machine version prototype\n{ex.FlattenMessage()}"); - } - finally - { - IsFree = true; + MachinePrototype prototype = MachinePrototype.CreateNew(ActiveMachine, protoName, protoName); + db.MachinePrototypes.Add(prototype); + await db.SaveChangesAsync(); + MachinesAdapter.MachinePrototypes = (await MachinesAdapter.Context.MachinePrototypes.ToListAsync()).ToObservableCollection(); } } + catch (Exception ex) + { + _notification.ShowError($"Error creating machine prototype\n{ex.FlattenMessage()}"); + } + finally + { + IsFree = true; + } } } @@ -985,7 +882,7 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels { MachineCreationDialogVM vm = new MachineCreationDialogVM(); vm.IsNewMachine = false; - vm.MachineVersions = MachinesAdapter.MachineVersions.ToList(); + vm.Prototypes = MachinesAdapter.MachinePrototypes.ToList(); _notification.ShowModalDialog<MachineCreationDialogVM, Views.MachineCreationDialog>(vm, (x) => { if (MachinesAdapter.Context.Machines.Any(y => y.SerialNumber == vm.SerialNumber || y.Name.ToLower() == vm.Name.ToLower())) |
