diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2019-07-08 17:50:11 +0300 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2019-07-08 17:50:11 +0300 |
| commit | c5713f263db2aa8eda95e13c14ed31d1335b6bc0 (patch) | |
| tree | efb2685fd1f3296021e74e5b97bf87e83a533451 /Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels | |
| parent | 45a4da6b34d2aedea27e2826931f0705eb05130f (diff) | |
| download | Tango-c5713f263db2aa8eda95e13c14ed31d1335b6bc0.tar.gz Tango-c5713f263db2aa8eda95e13c14ed31d1335b6bc0.zip | |
Refactoring of all color catalogs objects !!!
Diffstat (limited to 'Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels')
4 files changed, 66 insertions, 244 deletions
diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/CoatsCatalogViewVM.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/CoatsCatalogViewVM.cs deleted file mode 100644 index ebeb5b704..000000000 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/CoatsCatalogViewVM.cs +++ /dev/null @@ -1,153 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Tango.BL; -using Tango.BL.Catalogs; -using Tango.BL.Entities; -using Tango.Core.Commands; -using Tango.PPC.Common; -using Tango.PPC.Common.Navigation; -using Tango.PPC.Jobs.NavigationObjects; -using Tango.Settings; - -namespace Tango.PPC.Jobs.ViewModels -{ - /// <summary> - /// Represents the coats catalog view model. - /// </summary> - /// <seealso cref="PPCViewModel" /> - /// <seealso cref="INavigationResultProvider{CatalogItem, TwineCatalogNavigationObject}" /> - public class CoatsCatalogViewVM : PPCViewModel, INavigationResultProvider<CatalogItem, TwineCatalogNavigationObject> - { - private bool _confirmed; - private ObservablesContext _db; - - private Catalog _catalog; - /// <summary> - /// Gets or sets the catalog. - /// </summary> - public Catalog Catalog - { - get { return _catalog; } - set { _catalog = value; RaisePropertyChangedAuto(); } - } - - private Catalog _recent; - /// <summary> - /// Gets or sets the recent catalog items as a complete catalog. - /// </summary> - public Catalog Recent - { - get { return _recent; } - set { _recent = value; RaisePropertyChangedAuto(); } - } - - private String _filter; - /// <summary> - /// Gets or sets the filter. - /// </summary> - /// <value> - /// The filter. - /// </value> - public String Filter - { - get { return _filter; } - set { _filter = value; RaisePropertyChangedAuto(); } - } - - private CatalogItem _selectedItem; - /// <summary> - /// Gets or sets the selected item. - /// </summary> - public CatalogItem SelectedItem - { - get { return _selectedItem; } - set - { - _selectedItem = value; RaisePropertyChangedAuto(); - } - } - - /// <summary> - /// Gets or sets the OK command. - /// </summary> - public RelayCommand OKCommand { get; set; } - - /// <summary> - /// Initializes a new instance of the <see cref="TwineCatalogViewVM"/> class. - /// </summary> - public CoatsCatalogViewVM() - { - OKCommand = new RelayCommand(Confirm); - } - - /// <summary> - /// Called when the application has been started. - /// </summary> - public override void OnApplicationStarted() - { - _db = ObservablesContext.CreateDefault(); - } - - /// <summary> - /// Called when the navigation system has navigated to this VM view. - /// </summary> - public override void OnNavigatedTo() - { - base.OnNavigatedTo(); - _confirmed = false; - Filter = "CATALOG"; - } - - /// <summary> - /// Confirms this instance. - /// </summary> - private void Confirm() - { - SettingsManager.Default.GetOrCreate<JobsModuleSettings>().RecentCoatsCatalogColors.Add(SelectedItem.Entity.Name); - SettingsManager.Default.Save(); - - _confirmed = true; - NavigationManager.NavigateBack(); - } - - /// <summary> - /// Called when the navigation system requests a result when it is navigating away from this instance. - /// </summary> - /// <returns></returns> - public CatalogItem GetNavigationResult() - { - if (_confirmed) - { - return SelectedItem; - } - else - { - return null; - } - } - - /// <summary> - /// Called when the navigation object has been received - /// </summary> - /// <param name="brushStop">The brush stop.</param> - public async virtual void OnNavigationObjectReceived(TwineCatalogNavigationObject obj) - { - IsFree = false; - Catalog = await CatalogLoader.LoadCatalog(BL.Enumerations.ColorSpaces.Coats, obj.RML, _db); - Recent = CatalogLoader.GetRecent(Catalog, SettingsManager.Default.GetOrCreate<JobsModuleSettings>().RecentCoatsCatalogColors); - IsFree = true; - - if (obj.BrushStop.ColorCatalog != null) - { - SelectedItem = Catalog.Groups.SelectMany(x => x.Items).SingleOrDefault(x => x.Entity.Guid == obj.BrushStop.ColorCatalog.Guid); - } - else - { - SelectedItem = null; - } - } - } -} 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<ColorCatalog> _twineCatalogItems; + private List<ColorCatalogsItem> _catalogItems; /// <summary> /// Gets or sets the twine catalog items. /// </summary> - public List<ColorCatalog> TwineCatalogItems + public List<ColorCatalogsItem> CatalogItems { - get { return _twineCatalogItems; } - set { _twineCatalogItems = value; RaisePropertyChangedAuto(); } + get { return _catalogItems; } + set { _catalogItems = value; RaisePropertyChangedAuto(); } } + private ColorCatalogsItem _selectedCatalogItem; /// <summary> - /// Gets or sets the twine catalog automatic complete provider. + /// Gets or sets the selected catalog item. /// </summary> - public IAutoCompleteProvider TwineCatalogAutoCompleteProvider { get; set; } + public ColorCatalogsItem SelectedCatalogItem + { + get { return _selectedCatalogItem; } + set { _selectedCatalogItem = value; RaisePropertyChangedAuto(); } + } /// <summary> - /// Gets or sets the coats catalog automatic complete provider. + /// Gets or sets the twine catalog automatic complete provider. /// </summary> - public IAutoCompleteProvider CoatsCatalogAutoCompleteProvider { get; set; } + public IAutoCompleteProvider CatalogAutoCompleteProvider { get; set; } - private List<ColorCatalog> _coatsCatalogItems; + private ColorCatalog _selectedCatalog; /// <summary> - /// Gets or sets the coats catalog items. + /// Gets or sets the selected catalog. /// </summary> - public List<ColorCatalog> 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 /// <summary> /// Gets or sets the twine catalog field tap command. /// </summary> - public RelayCommand<BrushStop> OpenTwineCatalogCommand { get; set; } - - /// <summary> - /// Gets or sets the open coats catalog command. - /// </summary> - public RelayCommand<BrushStop> OpenCoatsCatalogCommand { get; set; } + public RelayCommand<BrushStop> OpenCatalogCommand { get; set; } /// <summary> /// Gets or sets the increase decrease samples to dye command. @@ -360,8 +359,7 @@ namespace Tango.PPC.Jobs.ViewModels FineTuneItems = new ObservableCollection<FineTuneItem>(); ApprovalFineTuneItems = new ObservableCollection<FineTuneItem>(); - TwineCatalogItems = new List<ColorCatalog>(); - CoatsCatalogItems = new List<ColorCatalog>(); + CatalogItems = new List<ColorCatalogsItem>(); CustomersAutoCompleteProvider = new AutoCompleteProvider<Customer>((customer, filter) => { @@ -369,14 +367,9 @@ namespace Tango.PPC.Jobs.ViewModels }); - TwineCatalogAutoCompleteProvider = new AutoCompleteProvider<ColorCatalog>((color, filter) => + CatalogAutoCompleteProvider = new AutoCompleteProvider<ColorCatalogsItem>((item, filter) => { - return !String.IsNullOrWhiteSpace(filter) && color.RmlGuid == Job.Rml.Guid && color.Name.ToLower().StartsWith(filter.ToLower()); - }); - - CoatsCatalogAutoCompleteProvider = new AutoCompleteProvider<ColorCatalog>((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<BrushStop>(OpenTwineCatalog); - OpenCoatsCatalogCommand = new RelayCommand<BrushStop>(OpenCoatsCatalog); + OpenCatalogCommand = new RelayCommand<BrushStop>(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(); + //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 = TwineCatalogItems.SingleOrDefault(x => x.Name == stop.ColorCatalog.Name); - stop.ColorCatalog = replacement; - } + ////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; - } + ////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. /// </summary> /// <param name="stop">The stop.</param> - private async void OpenTwineCatalog(BrushStop stop) - { - var catalogItem = await NavigationManager.NavigateForResult<JobsModule, TwineCatalogView, CatalogItem, TwineCatalogNavigationObject>(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<JobsModule, CoatsCatalogView, CatalogItem, TwineCatalogNavigationObject>(new TwineCatalogNavigationObject() + var catalogItem = await NavigationManager.NavigateForResult<JobsModule, TwineCatalogView, ColorCatalogsItem, TwineCatalogNavigationObject>(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; } } diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobsViewVM.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobsViewVM.cs index 248003b30..b7a6ad94a 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobsViewVM.cs +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/JobsViewVM.cs @@ -421,12 +421,12 @@ namespace Tango.PPC.Jobs.ViewModels if (settings.LastJobColorSpace != null) { - vm.SelectedColorSpace = settings.LastJobColorSpace.Value.IsUserSpace() ? settings.LastJobColorSpace.Value : ColorSpaces.Twine; + vm.SelectedColorSpace = settings.LastJobColorSpace.Value.IsUserSpace() ? settings.LastJobColorSpace.Value : ColorSpaces.Catalog; } else { var space = machine.SupportedColorSpaces.FirstOrDefault(); - vm.SelectedColorSpace = space.IsUserSpace() ? space : ColorSpaces.Twine; + vm.SelectedColorSpace = space.IsUserSpace() ? space : ColorSpaces.Catalog; } if (colorProfile != null || twnFile != null) diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/TwineCatalogViewVM.cs b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/TwineCatalogViewVM.cs index a72013d26..d7d720434 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/TwineCatalogViewVM.cs +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.Jobs/ViewModels/TwineCatalogViewVM.cs @@ -4,7 +4,6 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using Tango.BL; -using Tango.BL.Catalogs; using Tango.BL.Entities; using Tango.Core.Commands; using Tango.PPC.Common; @@ -19,26 +18,26 @@ namespace Tango.PPC.Jobs.ViewModels /// </summary> /// <seealso cref="PPCViewModel" /> /// <seealso cref="INavigationResultProvider{CatalogItem, TwineCatalogNavigationObject}" /> - public class TwineCatalogViewVM : PPCViewModel, INavigationResultProvider<CatalogItem, TwineCatalogNavigationObject> + public class TwineCatalogViewVM : PPCViewModel, INavigationResultProvider<ColorCatalogsItem, TwineCatalogNavigationObject> { private bool _confirmed; private ObservablesContext _db; - private Catalog _catalog; + private ColorCatalog _catalog; /// <summary> /// Gets or sets the catalog. /// </summary> - public Catalog Catalog + public ColorCatalog Catalog { get { return _catalog; } set { _catalog = value; RaisePropertyChangedAuto(); } } - private Catalog _recent; + private ColorCatalog _recent; /// <summary> /// Gets or sets the recent catalog items as a complete catalog. /// </summary> - public Catalog Recent + public ColorCatalog Recent { get { return _recent; } set { _recent = value; RaisePropertyChangedAuto(); } @@ -57,11 +56,11 @@ namespace Tango.PPC.Jobs.ViewModels set { _filter = value; RaisePropertyChangedAuto(); } } - private CatalogItem _selectedItem; + private ColorCatalogsItem _selectedItem; /// <summary> /// Gets or sets the selected item. /// </summary> - public CatalogItem SelectedItem + public ColorCatalogsItem SelectedItem { get { return _selectedItem; } set @@ -106,7 +105,7 @@ namespace Tango.PPC.Jobs.ViewModels /// </summary> private void Confirm() { - SettingsManager.Default.GetOrCreate<JobsModuleSettings>().RecentTwineCatalogColors.Add(SelectedItem.Entity.Name); + SettingsManager.Default.GetOrCreate<JobsModuleSettings>().RecentTwineCatalogColors.Add(SelectedItem.Guid); SettingsManager.Default.Save(); _confirmed = true; @@ -117,7 +116,7 @@ namespace Tango.PPC.Jobs.ViewModels /// Called when the navigation system requests a result when it is navigating away from this instance. /// </summary> /// <returns></returns> - public CatalogItem GetNavigationResult() + public ColorCatalogsItem GetNavigationResult() { if (_confirmed) { @@ -133,21 +132,16 @@ namespace Tango.PPC.Jobs.ViewModels /// Called when the navigation object has been received /// </summary> /// <param name="brushStop">The brush stop.</param> - public async virtual void OnNavigationObjectReceived(TwineCatalogNavigationObject obj) + public virtual void OnNavigationObjectReceived(TwineCatalogNavigationObject obj) { IsFree = false; - Catalog = await CatalogLoader.LoadCatalog(BL.Enumerations.ColorSpaces.Twine, obj.RML, _db); - Recent = CatalogLoader.GetRecent(Catalog, SettingsManager.Default.GetOrCreate<JobsModuleSettings>().RecentTwineCatalogColors); - IsFree = true; - if (obj.BrushStop.ColorCatalog != null) - { - SelectedItem = Catalog.Groups.SelectMany(x => x.Items).SingleOrDefault(x => x.Entity.Guid == obj.BrushStop.ColorCatalog.Guid); - } - else - { - SelectedItem = null; - } + Catalog = obj.Catalog; + //Recent = CatalogLoader.GetRecent(Catalog, SettingsManager.Default.GetOrCreate<JobsModuleSettings>().RecentTwineCatalogColors); + + SelectedItem = obj.SelectedItem; + + IsFree = true; } } } |
