From c5713f263db2aa8eda95e13c14ed31d1335b6bc0 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Mon, 8 Jul 2019 17:50:11 +0300 Subject: Refactoring of all color catalogs objects !!! --- .../Modules/Tango.PPC.Jobs/ViewModels/JobViewVM.cs | 119 +++++++++------------ 1 file changed, 50 insertions(+), 69 deletions(-) (limited to 'Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobViewVM.cs') diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobViewVM.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobViewVM.cs index fb1f240c5..08a5e1168 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobViewVM.cs +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobViewVM.cs @@ -17,7 +17,6 @@ using System.ComponentModel; using System.Windows.Data; using Tango.PPC.Jobs.Dialogs; using Tango.PPC.Jobs.Views; -using Tango.BL.Catalogs; using System.Runtime.InteropServices; using System.Threading; using Tango.SharedUI.Helpers; @@ -186,34 +185,39 @@ namespace Tango.PPC.Jobs.ViewModels set { _isJobDetailsExpanded = value; RaisePropertyChangedAuto(); } } - private List _twineCatalogItems; + private List _catalogItems; /// /// Gets or sets the twine catalog items. /// - public List TwineCatalogItems + public List CatalogItems { - get { return _twineCatalogItems; } - set { _twineCatalogItems = value; RaisePropertyChangedAuto(); } + get { return _catalogItems; } + set { _catalogItems = value; RaisePropertyChangedAuto(); } } + private ColorCatalogsItem _selectedCatalogItem; /// - /// Gets or sets the twine catalog automatic complete provider. + /// Gets or sets the selected catalog item. /// - public IAutoCompleteProvider TwineCatalogAutoCompleteProvider { get; set; } + public ColorCatalogsItem SelectedCatalogItem + { + get { return _selectedCatalogItem; } + set { _selectedCatalogItem = value; RaisePropertyChangedAuto(); } + } /// - /// Gets or sets the coats catalog automatic complete provider. + /// Gets or sets the twine catalog automatic complete provider. /// - public IAutoCompleteProvider CoatsCatalogAutoCompleteProvider { get; set; } + public IAutoCompleteProvider CatalogAutoCompleteProvider { get; set; } - private List _coatsCatalogItems; + private ColorCatalog _selectedCatalog; /// - /// Gets or sets the coats catalog items. + /// Gets or sets the selected catalog. /// - public List CoatsCatalogItems + public ColorCatalog SelectedCatalog { - get { return _coatsCatalogItems; } - set { _coatsCatalogItems = value; RaisePropertyChangedAuto(); } + get { return _selectedCatalog; } + set { _selectedCatalog = value; RaisePropertyChangedAuto(); } } #endregion @@ -268,12 +272,7 @@ namespace Tango.PPC.Jobs.ViewModels /// /// Gets or sets the twine catalog field tap command. /// - public RelayCommand OpenTwineCatalogCommand { get; set; } - - /// - /// Gets or sets the open coats catalog command. - /// - public RelayCommand OpenCoatsCatalogCommand { get; set; } + public RelayCommand OpenCatalogCommand { get; set; } /// /// Gets or sets the increase decrease samples to dye command. @@ -360,8 +359,7 @@ namespace Tango.PPC.Jobs.ViewModels FineTuneItems = new ObservableCollection(); ApprovalFineTuneItems = new ObservableCollection(); - TwineCatalogItems = new List(); - CoatsCatalogItems = new List(); + CatalogItems = new List(); CustomersAutoCompleteProvider = new AutoCompleteProvider((customer, filter) => { @@ -369,14 +367,9 @@ namespace Tango.PPC.Jobs.ViewModels }); - TwineCatalogAutoCompleteProvider = new AutoCompleteProvider((color, filter) => + CatalogAutoCompleteProvider = new AutoCompleteProvider((item, filter) => { - return !String.IsNullOrWhiteSpace(filter) && color.RmlGuid == Job.Rml.Guid && color.Name.ToLower().StartsWith(filter.ToLower()); - }); - - CoatsCatalogAutoCompleteProvider = new AutoCompleteProvider((color, filter) => - { - return !String.IsNullOrWhiteSpace(filter) && color.RmlGuid == Job.Rml.Guid && color.Name.ToLower().StartsWith(filter.ToLower()); + return !String.IsNullOrWhiteSpace(filter) && item.Name.ToLower().StartsWith(filter.ToLower()); }); //Initialize Commands @@ -421,8 +414,7 @@ namespace Tango.PPC.Jobs.ViewModels StartFineTuningCommand = new RelayCommand(StartFineTuning, () => FineTuneItems.Any(x => x.IsSelected) && CanStartJob()); RepeatFineTuningCommand = new RelayCommand(RepeatFineTuning); ApproveFineTuningCommand = new RelayCommand(ApproveFineTuning); - OpenTwineCatalogCommand = new RelayCommand(OpenTwineCatalog); - OpenCoatsCatalogCommand = new RelayCommand(OpenCoatsCatalog); + OpenCatalogCommand = new RelayCommand(OpenCatalog); ExportEmbroideryCommand = new RelayCommand(ExportEmbroidery); } @@ -479,8 +471,12 @@ namespace Tango.PPC.Jobs.ViewModels SpoolTypes = await _db.SpoolTypes.ToListAsync(); LogManager.Log("Loading Customers..."); Customers = await _db.Customers.Where(x => x.OrganizationGuid == MachineProvider.Machine.OrganizationGuid).ToListAsync(); - TwineCatalogItems = await _db.ColorCatalogs.Where(x => x.RmlGuid == Job.Rml.Guid && x.ColorSpace.Code == (int)BL.Enumerations.ColorSpaces.Twine).OrderBy(x => x.Name).ToListAsync(); - CoatsCatalogItems = await _db.ColorCatalogs.Where(x => x.RmlGuid == Job.Rml.Guid && x.ColorSpace.Code == (int)BL.Enumerations.ColorSpaces.Coats).OrderBy(x => x.Name).ToListAsync(); + + if (Job.ColorSpace.Space == BL.Enumerations.ColorSpaces.Catalog) + { + SelectedCatalog = await new ColorCatalogBuilder(_db).SetFirst().WithGroups().WithItems().BuildAsync(); + CatalogItems = SelectedCatalog.ColorCatalogsGroups.SelectMany(x => x.ColorCatalogsItems).ToList(); + } foreach (var segment in Job.Segments) { @@ -655,24 +651,23 @@ namespace Tango.PPC.Jobs.ViewModels #region RML Changed - protected virtual async void OnRmlChanged(object sender, Rml rml) + protected virtual void OnRmlChanged(object sender, Rml rml) { - TwineCatalogItems = await _db.ColorCatalogs.Where(x => x.RmlGuid == rml.Guid && x.ColorSpace.Code == (int)BL.Enumerations.ColorSpaces.Twine).OrderBy(x => x.Name).ToListAsync(); - CoatsCatalogItems = await _db.ColorCatalogs.Where(x => x.RmlGuid == rml.Guid && x.ColorSpace.Code == (int)BL.Enumerations.ColorSpaces.Coats).OrderBy(x => x.Name).ToListAsync(); - - //Replace all brush stops twine color catalogs. - foreach (var stop in Job.Segments.SelectMany(x => x.BrushStops).Where(x => x.ColorCatalog != null && x.BrushColorSpace == BL.Enumerations.ColorSpaces.Twine).ToList()) - { - var replacement = TwineCatalogItems.SingleOrDefault(x => x.Name == stop.ColorCatalog.Name); - stop.ColorCatalog = replacement; - } - - //Replace all brush stops coats color catalogs. - foreach (var stop in Job.Segments.SelectMany(x => x.BrushStops).Where(x => x.ColorCatalog != null && x.BrushColorSpace == BL.Enumerations.ColorSpaces.Coats).ToList()) - { - var replacement = CoatsCatalogItems.SingleOrDefault(x => x.Name == stop.ColorCatalog.Name); - stop.ColorCatalog = replacement; - } + //There is no need for that. + + ////Replace all brush stops twine color catalogs. + //foreach (var stop in Job.Segments.SelectMany(x => x.BrushStops).Where(x => x.ColorCatalog != null && x.BrushColorSpace == BL.Enumerations.ColorSpaces.Twine).ToList()) + //{ + // var replacement = CatalogItems.SingleOrDefault(x => x.Name == stop.ColorCatalog.Name); + // stop.ColorCatalog = replacement; + //} + + ////Replace all brush stops coats color catalogs. + //foreach (var stop in Job.Segments.SelectMany(x => x.BrushStops).Where(x => x.ColorCatalog != null && x.BrushColorSpace == BL.Enumerations.ColorSpaces.Coats).ToList()) + //{ + // var replacement = CoatsCatalogItems.SingleOrDefault(x => x.Name == stop.ColorCatalog.Name); + // stop.ColorCatalog = replacement; + //} ResetFineTuning(); } @@ -935,31 +930,17 @@ namespace Tango.PPC.Jobs.ViewModels /// Opens the twine catalog for the specified brush stop. /// /// The stop. - private async void OpenTwineCatalog(BrushStop stop) - { - var catalogItem = await NavigationManager.NavigateForResult(new TwineCatalogNavigationObject() - { - BrushStop = stop, - RML = Job.Rml, - }, true); - - if (catalogItem != null) - { - stop.ColorCatalog = TwineCatalogItems.SingleOrDefault(x => x.Name == catalogItem.Entity.Name); - } - } - - private async void OpenCoatsCatalog(BrushStop stop) + private async void OpenCatalog(BrushStop stop) { - var catalogItem = await NavigationManager.NavigateForResult(new TwineCatalogNavigationObject() + var catalogItem = await NavigationManager.NavigateForResult(new TwineCatalogNavigationObject() { - BrushStop = stop, - RML = Job.Rml, + SelectedItem = stop.ColorCatalogsItem, + Catalog = SelectedCatalog }, true); if (catalogItem != null) { - stop.ColorCatalog = CoatsCatalogItems.SingleOrDefault(x => x.Name == catalogItem.Entity.Name); + stop.ColorCatalogsItem = catalogItem; } } -- cgit v1.3.1