From 721e03d7e6926055111d4edbbdf5f700a11ed58a Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Sun, 30 Dec 2018 15:23:34 +0200 Subject: Working on new Machine Designer. --- .../ViewModels/ConfigurationsViewVM.cs | 1 - .../Tango.MachineStudio.MachineDesigner.csproj | 9 +- .../ViewModels/MainViewVM.cs | 598 +++++++++------------ .../Views/ConfigurationView.xaml | 55 +- .../Views/MachineDetailsView.xaml | 43 +- .../Views/MachineSettingsView.xaml | 99 ++++ .../Views/MachineSettingsView.xaml.cs | 28 + .../Views/MachineView.xaml | 19 - .../Views/MachinesView.xaml | 7 +- .../Views/MainView.xaml | 3 +- .../Tango.MachineStudio.Common/DeploymentSlots.cs | 2 + 11 files changed, 453 insertions(+), 411 deletions(-) create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/MachineSettingsView.xaml create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/MachineSettingsView.xaml.cs (limited to 'Software/Visual_Studio/MachineStudio') diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DB/ViewModels/ConfigurationsViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DB/ViewModels/ConfigurationsViewVM.cs index 18c8c3daa..d5022c761 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DB/ViewModels/ConfigurationsViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DB/ViewModels/ConfigurationsViewVM.cs @@ -18,7 +18,6 @@ namespace Tango.MachineStudio.DB.ViewModels protected override void InitializeEntity(Configuration entity) { base.InitializeEntity(entity); - entity.CreationDate = DateTime.UtcNow; } } } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Tango.MachineStudio.MachineDesigner.csproj b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Tango.MachineStudio.MachineDesigner.csproj index 8ced2e510..a55d7e696 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Tango.MachineStudio.MachineDesigner.csproj +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Tango.MachineStudio.MachineDesigner.csproj @@ -83,6 +83,9 @@ MachineDetailsView.xaml + + MachineSettingsView.xaml + MachinesView.xaml @@ -103,6 +106,10 @@ Designer MSBuild:Compile + + Designer + MSBuild:Compile + Designer MSBuild:Compile @@ -254,7 +261,7 @@ - + \ No newline at end of file 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 e2924a185..b0b97d7d4 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 @@ -26,30 +26,21 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels public class MainViewVM : StudioViewModel { private INotificationProvider _notification; - private ObservablesContext _dbContext; - private ObservablesContext _machineContext; - private ObservablesContext _configContext; #region Properties - private ObservableCollection _machines; - /// - /// Gets or sets the machines. - /// - public ObservableCollection Machines + private ObservablesStaticCollections _machinesAdapter; + public ObservablesStaticCollections MachinesAdapter { - get { return _machines; } - set { _machines = value; RaisePropertyChangedAuto(); } + get { return _machinesAdapter; } + set { _machinesAdapter = value; RaisePropertyChangedAuto(); } } - private ObservableCollection _dispensers; - /// - /// Gets or sets the dispensers. - /// - public ObservableCollection Dispensers + private ObservablesStaticCollections _activeMachineAdapter; + public ObservablesStaticCollections ActiveMachineAdapter { - get { return _dispensers; } - set { _dispensers = value; RaisePropertyChangedAuto(); } + get { return _activeMachineAdapter; } + set { _activeMachineAdapter = value; RaisePropertyChangedAuto(); } } private Machine _selectedMachine; @@ -80,17 +71,6 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels set { _activeMachine = value; RaisePropertyChangedAuto(); } } - - private Configuration _configuration; - /// - /// Gets or sets the editable machine configuration. - /// - public Configuration Configuration - { - get { return _configuration; } - set { _configuration = value; RaisePropertyChangedAuto(); } - } - private IdsPack _selectedIds; /// /// Gets or sets the selected ids pack. @@ -155,6 +135,11 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels /// public RelayCommand EditMachineCommand { get; set; } + /// + /// Gets or sets the back to machines command. + /// + public RelayCommand BackToMachinesCommand { get; set; } + #endregion #region Constructors @@ -169,32 +154,17 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels /// public MainViewVM(INotificationProvider notification) { - _dbContext = ObservablesContext.CreateDefault(); + MachinesAdapter = new ObservablesStaticCollections(ObservablesContext.CreateDefault()); _notification = notification; //SaveCommand = new RelayCommand(Save); - AddIdsCommand = new RelayCommand(AddIds, (x) => Configuration != null && Configuration.IdsPacks.Count < 8); + AddIdsCommand = new RelayCommand(AddIds, (x) => ActiveMachine != null && ActiveMachine.Configuration != null && ActiveMachine.Configuration.IdsPacks.Count < 8); RemoveIdsCommand = new RelayCommand(RemoveIds, (x) => SelectedIds != null); - EditMachineCommand = new RelayCommand(EditSelectedMachine, () => SelectedMachine != null); - } - - private async void EditSelectedMachine() - { - using (_notification.PushTaskItem("Loading machine details...")) - { - IsFree = false; - - if (_machineContext != null) - { - _machineContext.Dispose(); - } - - _machineContext = ObservablesContext.CreateDefault(); - ActiveMachine = (await new MachineBuilder(_machineContext).Set(SelectedMachine).WithOrganization().WithConfiguration().BuildAsync()); - View.NavigateTo(MachineDesignerNavigationView.MachineDetailsView); - - IsFree = true; - } + EditMachineCommand = new RelayCommand(() => LoadSelectedMachine(), () => SelectedMachine != null); + BackToMachinesCommand = new RelayCommand(() => View.NavigateTo(MachineDesignerNavigationView.MachinesView)); + SaveCommand = new RelayCommand(SaveMachine); + AddMachineCommand = new RelayCommand(AddNewMachine); + RemoveMachineCommand = new RelayCommand(RemoveSelectedMachine,() => SelectedMachine != null); } #endregion @@ -208,59 +178,16 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels #endregion - //private Task InitCollections() - //{ - // return Task.Factory.StartNew(() => - // { - // CanWork = false; - - // _dbContext = ObservablesContext.CreateDefault(); - - // Adapter = new ObservablesStaticCollections(); - // Adapter.ApplicationDisplayPanelVersions = _dbContext.ApplicationDisplayPanelVersions.ToObservableCollection(); - // Adapter.ApplicationFirmwareVersions = _dbContext.ApplicationFirmwareVersions.ToObservableCollection(); - // Adapter.ApplicationOsVersions = _dbContext.ApplicationOsVersions.ToObservableCollection(); - // Adapter.EmbeddedFirmwareVersions = _dbContext.EmbeddedFirmwareVersions.ToObservableCollection(); - // Adapter.DispenserTypes = _dbContext.DispenserTypes.ToObservableCollection(); - // Adapter.LiquidTypes = _dbContext.LiquidTypes.ToObservableCollection(); - // Adapter.MidTankTypes = _dbContext.MidTankTypes.ToObservableCollection(); - // Adapter.CartridgeTypes = _dbContext.CartridgeTypes.ToObservableCollection(); - // Adapter.IdsPackFormulas = _dbContext.IdsPackFormulas.ToObservableCollection(); - // Adapter.HardwareVersions = _dbContext.HardwareVersions.ToObservableCollection(); - // Adapter.MachineVersions = _dbContext.MachineVersions.ToObservableCollection(); - // Adapter.Organizations = _dbContext.Organizations.ToObservableCollection(); - - // Adapter.InitCollectionSources(); - - // CanWork = true; - // }); - //} - - private void Reset() - { - //using (_notification.PushTaskItem("Resetting designer...")) - //{ - // SelectedMachine = null; - // Machine = new Machine(); - // Configuration = new Configuration(); - // InitCollections(); - //} - } - private async void OnDispensersFilterChanged() { if (!String.IsNullOrWhiteSpace(DispensersFilter)) { IsFree = false; - Dispensers = (await _configContext.Dispensers.Where(x => x.SerialNumber.ToLower().StartsWith(DispensersFilter.ToLower())).ToListAsync()).ToObservableCollection(); + ActiveMachineAdapter.Dispensers = (await ActiveMachineAdapter.Context.Dispensers.Where(x => x.SerialNumber.ToLower().StartsWith(DispensersFilter.ToLower())).ToListAsync()).ToObservableCollection(); IsFree = true; } } - #region Virtual Methods - - #endregion - #region Drag Drop Handlers /// @@ -270,7 +197,7 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels /// The ids pack2. public void DropIdsPack(IdsPack idsPack1, IdsPack idsPack2) { - Configuration.IdsPacks.Swap(idsPack1, idsPack2); + ActiveMachine.Configuration.IdsPacks.Swap(idsPack1, idsPack2); } /// @@ -279,8 +206,8 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels /// The application display panel version. public void DropTouchPanel(ApplicationDisplayPanelVersion applicationDisplayPanelVersion) { - Configuration.ApplicationDisplayPanelVersion = applicationDisplayPanelVersion; - Configuration.ApplicationDisplayPanelVersionGuid = applicationDisplayPanelVersion.Guid; + ActiveMachine.Configuration.ApplicationDisplayPanelVersion = applicationDisplayPanelVersion; + ActiveMachine.Configuration.ApplicationDisplayPanelVersionGuid = applicationDisplayPanelVersion.Guid; } /// @@ -289,8 +216,8 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels /// The application firmware version. public void DropApplicationFirmwareVersion(ApplicationFirmwareVersion applicationFirmwareVersion) { - Configuration.ApplicationFirmwareVersion = applicationFirmwareVersion; - Configuration.ApplicationFirmwareVersionGuid = applicationFirmwareVersion.Guid; + ActiveMachine.Configuration.ApplicationFirmwareVersion = applicationFirmwareVersion; + ActiveMachine.Configuration.ApplicationFirmwareVersionGuid = applicationFirmwareVersion.Guid; } /// @@ -299,8 +226,8 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels /// The hardware version. public void DropHardwareVersion(HardwareVersion hardwareVersion) { - Configuration.HardwareVersion = hardwareVersion; - Configuration.HardwareVersionGuid = hardwareVersion.Guid; + ActiveMachine.Configuration.HardwareVersion = hardwareVersion; + ActiveMachine.Configuration.HardwareVersionGuid = hardwareVersion.Guid; } /// @@ -309,8 +236,8 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels /// The embedded firmware version. public void DropEmbeddedFirmware(EmbeddedFirmwareVersion embeddedFirmwareVersion) { - Configuration.EmbeddedFirmwareVersion = embeddedFirmwareVersion; - Configuration.EmbeddedFirmwareVersionGuid = embeddedFirmwareVersion.Guid; + ActiveMachine.Configuration.EmbeddedFirmwareVersion = embeddedFirmwareVersion; + ActiveMachine.Configuration.EmbeddedFirmwareVersionGuid = embeddedFirmwareVersion.Guid; } /// @@ -319,8 +246,8 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels /// The application os version. public void DropApplicationOsVersion(ApplicationOsVersion applicationOsVersion) { - Configuration.ApplicationOsVersion = applicationOsVersion; - Configuration.ApplicationOsVersionGuid = applicationOsVersion.Guid; + ActiveMachine.Configuration.ApplicationOsVersion = applicationOsVersion; + ActiveMachine.Configuration.ApplicationOsVersionGuid = applicationOsVersion.Guid; } /// @@ -388,7 +315,7 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels /// private void RemoveIds() { - _dbContext.IdsPacks.Remove(SelectedIds); + ActiveMachineAdapter.Context.IdsPacks.Remove(SelectedIds); SelectedIds = null; } @@ -397,249 +324,242 @@ namespace Tango.MachineStudio.MachineDesigner.ViewModels /// private void AddIds() { - _dbContext.IdsPacks.Add(new IdsPack() { Configuration = Configuration }); + ActiveMachineAdapter.Context.IdsPacks.Add(new IdsPack() { Configuration = ActiveMachine.Configuration }); InvalidateRelayCommands(); } - ///// - ///// Saves the current machine configuration. - ///// - //private async void Save() - //{ - // foreach (var ids in Configuration.IdsPacks) - // { - // ids.PackIndex = Configuration.IdsPacks.IndexOf(ids); - // ids.Configuration = Configuration; - // ids.ConfigurationGuid = Configuration.Guid; - // } - - // //Validate - - // List errors = new List(); - - // if (Machine.MachineVersion == null) - // { - // errors.Add("Machine version is required."); - // } - - // if (Machine.Name.IsNullOrWhiteSpace()) - // { - // errors.Add("Machine name is required."); - // } - - // if (Machine.Organization == null) - // { - // errors.Add("Machine organization is required."); - // } - - // if (Machine.SerialNumber.IsNullOrWhiteSpace()) - // { - // errors.Add("Machine serial number is required."); - // } - - // if (Configuration.Name.IsNullOrWhiteSpace()) - // { - // errors.Add("Configuration name is required."); - // } - - // if (Configuration.ApplicationDisplayPanelVersion == null) - // { - // errors.Add("Touch Panel is required."); - // } - - // if (Configuration.ApplicationFirmwareVersion == null) - // { - // errors.Add("Application firmware is required."); - // } - - // if (Configuration.ApplicationOsVersion == null) - // { - // errors.Add("Application operation system is required."); - // } - - // if (Configuration.EmbeddedFirmwareVersion == null) - // { - // errors.Add("Embedded firmware is required."); - // } - - // if (Configuration.HardwareVersion == null) - // { - // errors.Add("Hardware version is required."); - // } - - // foreach (var pack in Configuration.IdsPacks) - // { - // if (pack.LiquidType != null || pack.CartridgeType != null || pack.Dispenser != null || pack.IdsPackFormula != null || pack.MidTankType != null) - // { - // if (pack.CartridgeType == null) - // { - // errors.Add(String.Format("Cartridge type is required on IDS pack '{0}'.", pack.PackIndex)); - // } - // if (pack.Dispenser == null) - // { - // errors.Add(String.Format("Dispenser is required on IDS pack '{0}'.", pack.PackIndex)); - // } - // if (pack.LiquidType == null) - // { - // errors.Add(String.Format("Liquid type is required on IDS pack '{0}'.", pack.PackIndex)); - // } - // if (pack.MidTankType == null) - // { - // errors.Add(String.Format("Mid Tank type is required on IDS pack '{0}'.", pack.PackIndex)); - // } - // if (pack.IdsPackFormula == null) - // { - // errors.Add(String.Format("Formula type is required on IDS pack '{0}'.", pack.PackIndex)); - // } - - // pack.IsEmpty = false; - // } - // else - // { - // pack.IsEmpty = true; - // } - // } - - // if (errors.Count > 0) - // { - // String errorsString = "Please fix the following validation errors before trying to save." + Environment.NewLine + Environment.NewLine; - // errorsString += String.Join(Environment.NewLine, errors); - // _notification.ShowError(errorsString); - // return; - // } - - // //Validate - - // try - // { - // CanWork = false; - - // using (_notification.PushTaskItem("Saving Machine Configuration...")) - // { - // if (!_dbContext.Machines.Any(x => x.SerialNumber.ToLower() == Machine.SerialNumber.ToLower())) - // { - // if (!_notification.ShowQuestion("The specified machine serial number does not exist. Do you wish to create a new machine?")) - // { - // CanWork = true; - // return; - // } - // else - // { - // Machine.Configuration = Configuration; - // Configuration.CreationDate = DateTime.UtcNow; - // Machine.ProductionDate = DateTime.UtcNow; - - // _dbContext.Machines.Add(Machine); - // } - // } - - // await _dbContext.SaveChangesAsync(); - // OnSelectedMachineChanged(); - - // } - // } - // catch (Exception ex) - // { - // _notification.ShowError("An error occurred while trying to save the configuration" + Environment.NewLine + ex.Message); - // } - // finally - // { - // CanWork = true; - // InvalidateRelayCommands(); - // } - //} - - ///// - ///// Sets the current configuration to the selected machine version default configuration. - ///// - //private async void SetVersionConfiguration() - //{ - // if (Machine.MachineVersion != null) - // { - // using (_notification.PushTaskItem("Applying default configuration...")) - // { - // CanWork = false; - - // await Task.Factory.StartNew(() => - // { - // var version = _dbContext.MachineVersions.Where(x => x.Guid == Machine.MachineVersion.Guid).Include(x => x.DefaultConfiguration).FirstOrDefault(); - // var version_config = _dbContext.Adapter.GetConfiguration(x => x.Guid == version.DefaultConfiguration.Guid); - // Configuration = version_config.Clone(); - // Machine.Configuration = Configuration; - // }); - - // CanWork = true; - // } - // } - // else - // { - // _notification.ShowError("No machine version selected."); - // } - //} - - ///// - ///// Sets the current configuration as a default machine version configuration. - ///// - //private void SetAsDefaultConfiguration() - //{ - // _notification.ShowModalDialog(async (vm) => - // { - // CanWork = false; - - // try - // { - // using (_notification.PushTaskItem("Saving Default Configuration...")) - // { - // if (vm.SelectedVersion != null) - // { - // var version = _dbContext.MachineVersions.Where(x => x.Guid == vm.SelectedVersion.Guid).Include(x => x.DefaultConfiguration).SingleOrDefault(x => x.Guid == vm.SelectedVersion.Guid); - - // _dbContext.Configurations.Remove(version.DefaultConfiguration); - - // var cloned = Configuration.Clone(); - // _dbContext.Configurations.Add(cloned); - // version.DefaultConfiguration = cloned; - - // await _dbContext.SaveChangesAsync(); - // } - // else - // { - // MachineVersion newVersion = new MachineVersion(); - // newVersion.Version = vm.Version; - // newVersion.Name = vm.VersionName; - - // var cloned = Configuration.Clone(); - - // _dbContext.Configurations.Add(cloned); - // newVersion.DefaultConfiguration = cloned; - // _dbContext.MachineVersions.Add(newVersion); - // await _dbContext.SaveChangesAsync(); - // } - // } - // } - // catch (Exception ex) - // { - // _notification.ShowError(ex.Message); - // } - // finally - // { - // CanWork = true; - // } - - // }, () => - // { - - // }); - //} + private async void LoadSelectedMachine(bool newMachine = false) + { + using (_notification.PushTaskItem("Loading machine details...")) + { + try + { + IsFree = false; + + if (ActiveMachineAdapter != null) + { + ActiveMachineAdapter.Context.Dispose(); + } + + ActiveMachineAdapter = new ObservablesStaticCollections(ObservablesContext.CreateDefault()); + ActiveMachineAdapter.Organizations = (await ActiveMachineAdapter.Context.Organizations.ToListAsync()).ToObservableCollection(); + ActiveMachineAdapter.MachineVersions = (await ActiveMachineAdapter.Context.MachineVersions.ToListAsync()).ToObservableCollection(); + ActiveMachineAdapter.Rmls = (await ActiveMachineAdapter.Context.Rmls.ToListAsync()).ToObservableCollection(); + ActiveMachineAdapter.ColorSpaces = (await ActiveMachineAdapter.Context.ColorSpaces.ToListAsync()).ToObservableCollection(); + ActiveMachineAdapter.SpoolTypes = (await ActiveMachineAdapter.Context.SpoolTypes.ToListAsync()).ToObservableCollection(); + + ActiveMachineAdapter.ApplicationDisplayPanelVersions = (await ActiveMachineAdapter.Context.ApplicationDisplayPanelVersions.ToListAsync()).ToObservableCollection(); + ActiveMachineAdapter.ApplicationFirmwareVersions = (await ActiveMachineAdapter.Context.ApplicationFirmwareVersions.ToListAsync()).ToObservableCollection(); + ActiveMachineAdapter.ApplicationOsVersions = (await ActiveMachineAdapter.Context.ApplicationOsVersions.ToListAsync()).ToObservableCollection(); + ActiveMachineAdapter.EmbeddedFirmwareVersions = (await ActiveMachineAdapter.Context.EmbeddedFirmwareVersions.ToListAsync()).ToObservableCollection(); + ActiveMachineAdapter.DispenserTypes = (await ActiveMachineAdapter.Context.DispenserTypes.ToListAsync()).ToObservableCollection(); + ActiveMachineAdapter.LiquidTypes = (await ActiveMachineAdapter.Context.LiquidTypes.ToListAsync()).ToObservableCollection(); + ActiveMachineAdapter.MidTankTypes = (await ActiveMachineAdapter.Context.MidTankTypes.ToListAsync()).ToObservableCollection(); + ActiveMachineAdapter.CartridgeTypes = (await ActiveMachineAdapter.Context.CartridgeTypes.ToListAsync()).ToObservableCollection(); + ActiveMachineAdapter.IdsPackFormulas = (await ActiveMachineAdapter.Context.IdsPackFormulas.ToListAsync()).ToObservableCollection(); + ActiveMachineAdapter.HardwareVersions = (await ActiveMachineAdapter.Context.HardwareVersions.ToListAsync()).ToObservableCollection(); + ActiveMachineAdapter.MachineVersions = (await ActiveMachineAdapter.Context.MachineVersions.ToListAsync()).ToObservableCollection(); + ActiveMachineAdapter.Organizations = (await ActiveMachineAdapter.Context.Organizations.ToListAsync()).ToObservableCollection(); + + if (!newMachine) + { + ActiveMachine = (await new MachineBuilder(ActiveMachineAdapter.Context).Set(SelectedMachine.Guid).WithOrganization().WithConfiguration().WithSpools().BuildAsync()); + } + else + { + ActiveMachine = new Machine(); + ActiveMachine.Configuration = new Configuration(); + ActiveMachineAdapter.Context.Machines.Add(ActiveMachine); + } + + View.NavigateTo(MachineDesignerNavigationView.MachineDetailsView); + } + catch (Exception ex) + { + LogManager.Log(ex, $"Error loading machine details for serial number {SelectedMachine.SerialNumber}"); + _notification.ShowError($"An error occurred while trying to load the selected machine details.\n{ex.Message}"); + } + finally + { + IsFree = true; + InvalidateRelayCommands(); + } + } + } + + private async void SaveMachine() + { + foreach (var ids in ActiveMachine.Configuration.IdsPacks) + { + ids.PackIndex = ActiveMachine.Configuration.IdsPacks.IndexOf(ids); + ids.Configuration = ActiveMachine.Configuration; + ids.ConfigurationGuid = ActiveMachine.Configuration.Guid; + } + + List errors = new List(); + + if (ActiveMachine.MachineVersion == null) + { + errors.Add("Machine version is required."); + } + + if (ActiveMachine.Name.IsNullOrWhiteSpace()) + { + errors.Add("Machine name is required."); + } + + if (ActiveMachine.Organization == null) + { + errors.Add("Machine organization is required."); + } + + if (ActiveMachine.SerialNumber.IsNullOrWhiteSpace()) + { + errors.Add("Machine serial number is required."); + } + + if (ActiveMachine.Configuration.ApplicationDisplayPanelVersion == null) + { + errors.Add("Touch Panel is required."); + } + + if (ActiveMachine.Configuration.ApplicationFirmwareVersion == null) + { + errors.Add("Application firmware is required."); + } + + if (ActiveMachine.Configuration.ApplicationOsVersion == null) + { + errors.Add("Application operation system is required."); + } + + if (ActiveMachine.Configuration.EmbeddedFirmwareVersion == null) + { + errors.Add("Embedded firmware is required."); + } + + if (ActiveMachine.Configuration.HardwareVersion == null) + { + errors.Add("Hardware version is required."); + } + + foreach (var pack in ActiveMachine.Configuration.IdsPacks) + { + if (pack.LiquidType != null || pack.CartridgeType != null || pack.Dispenser != null || pack.IdsPackFormula != null || pack.MidTankType != null) + { + if (pack.CartridgeType == null) + { + errors.Add(String.Format("Cartridge type is required on IDS pack '{0}'.", pack.PackIndex)); + } + if (pack.Dispenser == null) + { + errors.Add(String.Format("Dispenser is required on IDS pack '{0}'.", pack.PackIndex)); + } + if (pack.LiquidType == null) + { + errors.Add(String.Format("Liquid type is required on IDS pack '{0}'.", pack.PackIndex)); + } + if (pack.MidTankType == null) + { + errors.Add(String.Format("Mid Tank type is required on IDS pack '{0}'.", pack.PackIndex)); + } + if (pack.IdsPackFormula == null) + { + errors.Add(String.Format("Formula type is required on IDS pack '{0}'.", pack.PackIndex)); + } + + pack.IsEmpty = false; + } + else + { + pack.IsEmpty = true; + } + } + + foreach (var pack in ActiveMachine.Configuration.IdsPacks.Where(x => x.Dispenser != null)) + { + if (ActiveMachine.Configuration.IdsPacks.Where(x => x.Dispenser == pack.Dispenser).Count() > 1) + { + errors.Add($"Dispenser '{pack.Dispenser.SerialNumber}' is installed on multiple IDS packs."); + } + + if (ActiveMachineAdapter.Context.IdsPacks.Count(x => x.ConfigurationGuid != pack.ConfigurationGuid && x.DispenserGuid == pack.DispenserGuid) > 0) + { + errors.Add($"Dispenser '{pack.Dispenser.SerialNumber}' is already installed on a different machine."); + } + } + + if (errors.Count > 0) + { + String errorsString = "Please fix the following validation errors before trying to save." + Environment.NewLine + Environment.NewLine; + errorsString += String.Join(Environment.NewLine, errors.Distinct()); + _notification.ShowError(errorsString); + return; + } + + try + { + IsFree = false; + + using (_notification.PushTaskItem("Saving Machine Details...")) + { + + ActiveMachine.ConfigurationGuid = ActiveMachine.Configuration.Guid; + ActiveMachine.LastUpdated = DateTime.UtcNow; + ActiveMachine.ProductionDate = DateTime.UtcNow; + await ActiveMachineAdapter.Context.SaveChangesAsync(); + } + } + catch (Exception ex) + { + LogManager.Log(ex, "Error saving machine details."); + _notification.ShowError("An error occurred while trying to save the machine details" + Environment.NewLine + ex.Message); + } + finally + { + IsFree = true; + InvalidateRelayCommands(); + } + } + + private void AddNewMachine() + { + LoadSelectedMachine(true); + } + + private async void RemoveSelectedMachine() + { + if (_notification.ShowQuestion("Are you sure you want to delete the selected machine?")) + { + using (_notification.PushTaskItem("Removing machine...")) + { + try + { + IsFree = false; + await SelectedMachine.DeleteCascadeAsync(MachinesAdapter.Context); + MachinesAdapter.Context.Machines.Remove(SelectedMachine); + } + catch (Exception ex) + { + LogManager.Log(ex, $"Error removing machine {SelectedMachine.SerialNumber}."); + _notification.ShowError($"An error occurred while trying to delete the selected machine.\n{ex.Message}"); + } + finally + { + IsFree = true; + } + } + } + } #endregion private async void OnFilterChanged() { - if (!String.IsNullOrWhiteSpace(Filter)) + if (Filter != null) { IsFree = false; - Machines = (await _dbContext.Machines.Where(x => x.SerialNumber.StartsWith(Filter)).ToListAsync()).ToObservableCollection(); + MachinesAdapter.Machines = (await MachinesAdapter.Context.Machines.Where(x => x.SerialNumber.StartsWith(Filter)).Include(x => x.Organization).Include(x => x.MachineVersion).ToListAsync()).ToObservableCollection(); IsFree = true; } } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/ConfigurationView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/ConfigurationView.xaml index a96cd4685..97eceaa7d 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/ConfigurationView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/ConfigurationView.xaml @@ -102,8 +102,8 @@ - - + + @@ -145,7 +145,7 @@ 8 - + + + + + + + + + + + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/MachineSettingsView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/MachineSettingsView.xaml new file mode 100644 index 000000000..63d1d2305 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/MachineSettingsView.xaml @@ -0,0 +1,99 @@ + + + + + + + + + + + + + + + + + + + + + + + + Serial Number + + + Name + + + Machine Version + + + Organization + + + Default RML + + + Loaded RML + + + Default Color Space + + + Default Segment Length + + + Default Spool Type + + + OS Key + + + + + Auto Login + + + Auto Check For Updates + + + Setup Activation + + + Setup Remote Assistance + + + Setup UWF + + + Setup Firmware + + + Setup FPGA + + + Is Demo Machine + + + + + + + + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/MachineSettingsView.xaml.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/MachineSettingsView.xaml.cs new file mode 100644 index 000000000..29367c3c4 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/MachineSettingsView.xaml.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace Tango.MachineStudio.MachineDesigner.Views +{ + /// + /// Interaction logic for MachineDetailsView.xaml + /// + public partial class MachineSettingsView : UserControl + { + public MachineSettingsView() + { + InitializeComponent(); + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/MachineView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/MachineView.xaml index ded14930a..d6afd41bf 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/MachineView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/MachineView.xaml @@ -69,25 +69,6 @@ - Add IDS - - - - - - Remove IDS - - - - - - - - 1 2 diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/MachinesView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/MachinesView.xaml index 48ce34688..91eda3491 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/MachinesView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.MachineDesigner/Views/MachinesView.xaml @@ -53,7 +53,7 @@ - +