| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Linq.Expressions;
- using System.Net.Http;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Input;
- using System.Windows.Media.Imaging;
- using Comal.Classes;
- using InABox.Clients;
- using InABox.Configuration;
- using InABox.Core;
- using InABox.Integration;
- using InABox.Integration.Awg;
- using InABox.WPF;
- using Inflector;
- using Microsoft.CodeAnalysis.CSharp.Syntax;
- using Microsoft.Xaml.Behaviors.Core;
- using PRSDimensionUtils;
- using sun.text.resources.ro;
- namespace PRSDesktop.Integrations.Common;
- public class AWGMappingWindowViewModel : DependencyObject
- {
- private readonly LogikalSettings _settings;
- public LogikalSettings Settings => _settings;
-
- public AWGMappingWindowViewModel() : base()
- {
- _settings = new GlobalConfiguration<LogikalSettings>().Load();
- StylesChecked = _settings.UpdateStyles != LogikalUpdateType.None;
- GroupsChecked = _settings.UpdateGroups != LogikalUpdateType.None;
- SuppliersChecked = _settings.UpdateSuppliers != LogikalUpdateType.None;
- DiscountsChecked = _settings.UpdateDiscounts != LogikalUpdateType.None;
- ProfilesChecked = _settings.UpdateProfiles != LogikalUpdateType.None;
- GasketsChecked = _settings.UpdateGaskets != LogikalUpdateType.None;
- ComponentsChecked = _settings.UpdateComponents != LogikalUpdateType.None;
- GlassChecked = _settings.UpdateGlass != LogikalUpdateType.None;
- LabourChecked = _settings.UpdateLabour != LogikalUpdateType.None;
- }
-
- private static readonly DependencyProperty SourceTypeProperty = DependencyProperty.Register(
- nameof(SourceType),
- typeof(IntegrationSourceType),
- typeof(AWGMappingWindowViewModel)
- );
- public IntegrationSourceType SourceType
- {
- get => (IntegrationSourceType)GetValue(SourceTypeProperty);
- set => SetValue(SourceTypeProperty, value);
- }
-
- private static readonly DependencyProperty StylesProperty = DependencyProperty.Register(
- nameof(Styles),
- typeof(IEnumerable<IAwgStyle>),
- typeof(AWGMappingWindowViewModel),
- new FrameworkPropertyMetadata(StylesChanged)
- );
- private static void StylesChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- if (d is not AWGMappingWindowViewModel model || e.NewValue is not IEnumerable<IAwgStyle> styles)
- return;
- var mappings =
- model.ExtractMappings<ProductStyleIntegrationSource, IAwgStyle, ProductStyle, ProductStyleLink>(
- styles,
- (logikal, mapping) =>
- {
- mapping.Cost = logikal.Cost;
- mapping.StyleType = logikal.StyleType;
- },
- x => x.Code
- );
- mappings.Wait();
- model.StyleMappings = mappings.Result;
- model.CheckChanged();
- }
- public IEnumerable<IAwgStyle>? Styles
- {
- get => GetValue(StylesProperty) as IEnumerable<IAwgStyle>;
- set => SetValue(StylesProperty, value);
- }
- private static readonly DependencyProperty GroupsProperty = DependencyProperty.Register(
- nameof(Groups),
- typeof(IEnumerable<IAwgGroup>),
- typeof(AWGMappingWindowViewModel),
- new FrameworkPropertyMetadata(GroupsChanged)
- );
- private static void GroupsChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- if (d is not AWGMappingWindowViewModel model || e.NewValue is not IEnumerable<IAwgGroup> groups)
- return;
- var mappings =
- model.ExtractMappings<ProductGroupIntegrationSource, IAwgGroup, ProductGroup, ProductGroupLink>(
- groups,
- (logikal, mapping) =>
- {
- mapping.Parent = logikal.Parent;
- },
- x => x.Code
- );
- mappings.Wait();
- model.GroupMappings = mappings.Result;
- model.CheckChanged();
- }
- public IEnumerable<IAwgGroup>? Groups
- {
- get => GetValue(GroupsProperty) as IEnumerable<IAwgGroup>;
- set => SetValue(GroupsProperty, value);
- }
- private static readonly DependencyProperty SuppliersProperty = DependencyProperty.Register(
- nameof(Suppliers),
- typeof(IEnumerable<IAwgSupplier>),
- typeof(AWGMappingWindowViewModel),
- new FrameworkPropertyMetadata(SuppliersChanged)
- );
- private static void SuppliersChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- if (d is not AWGMappingWindowViewModel model || e.NewValue is not IEnumerable<IAwgSupplier> suppliers)
- return;
- var mappings =
- model.ExtractMappings<SupplierIntegrationSource, IAwgSupplier, Supplier, SupplierLink>(
- suppliers,
- null,
- x => x.Code
- );
- mappings.Wait();
- model.SupplierMappings = mappings.Result;
- model.CheckChanged();
- }
- public IEnumerable<IAwgSupplier>? Suppliers
- {
- get => GetValue(SuppliersProperty) as IEnumerable<IAwgSupplier>;
- set => SetValue(SuppliersProperty, value);
- }
-
- private static readonly DependencyProperty DiscountsProperty = DependencyProperty.Register(
- nameof(Discounts),
- typeof(IEnumerable<IAwgDiscount>),
- typeof(AWGMappingWindowViewModel),
- new FrameworkPropertyMetadata(DiscountsChanged)
- );
- private static void DiscountsChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- if (d is not AWGMappingWindowViewModel model || e.NewValue is not IEnumerable<IAwgDiscount> discounts)
- return;
- var mappings =
- model.ExtractMappings<SupplierDiscountGroupIntegrationSource, IAwgDiscount, SupplierDiscountGroup, SupplierDiscountGroupLink>(
- discounts,
- (logikal, mapping) =>
- {
- mapping.Supplier = logikal.SupplierCode;
- mapping.Discount = logikal.Discount;
- },
- x => x.Code
- );
- mappings.Wait();
- model.DiscountMappings = mappings.Result;
- model.CheckChanged();
- }
- public IEnumerable<IAwgDiscount>? Discounts
- {
- get => GetValue(DiscountsProperty) as IEnumerable<IAwgDiscount>;
- set => SetValue(DiscountsProperty, value);
- }
- private static readonly DependencyProperty ProfilesProperty = DependencyProperty.Register(
- nameof(Profiles),
- typeof(IEnumerable<IAwgProfile>),
- typeof(AWGMappingWindowViewModel),
- new FrameworkPropertyMetadata(ProfilesChanged)
- );
- private static void ProfilesChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- if (d is not AWGMappingWindowViewModel model || e.NewValue is not IEnumerable<IAwgProfile> profiles)
- return;
- var mappings = model.ExtractMappings<ProductIntegrationSource, IAwgProfile, Product, ProductLink>(
- profiles,
- (logikal, mapping) =>
- {
- mapping.Style = logikal.Finish;
- mapping.Dimensions.Unit.CopyFrom(model.Settings.ProfileUom);
- mapping.Dimensions.Length = logikal.Length;
- mapping.Group = logikal.Group;
- mapping.Supplier = logikal.Supplier;
- mapping.Cost = logikal.Cost;
- mapping.MillCost = logikal.MillCost;
- mapping.Quantity = logikal.Quantity;
- mapping.TreatmentParameters[AwgStyleType.Powdercoated] = logikal.PaintPerimeter;
- mapping.TreatmentParameters[AwgStyleType.Anodised] = logikal.AnodizePerimeter;
- },
- x => x.Code
- );
- mappings.Wait();
- model.ProfileMappings = mappings.Result;
- model.CheckChanged();
- }
- public IEnumerable<IAwgProfile>? Profiles
- {
- get => GetValue(ProfilesProperty) as IEnumerable<IAwgProfile>;
- set => SetValue(ProfilesProperty, value);
- }
- private static readonly DependencyProperty GasketsProperty = DependencyProperty.Register(
- nameof(Gaskets),
- typeof(IEnumerable<IAwgGasket>),
- typeof(AWGMappingWindowViewModel),
- new FrameworkPropertyMetadata(GasketsChanged)
- );
- private static void GasketsChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- if (d is not AWGMappingWindowViewModel model || e.NewValue is not IEnumerable<IAwgGasket> gaskets)
- return;
- var mappings = model.ExtractMappings<ProductIntegrationSource, IAwgGasket, Product, ProductLink>(
- gaskets,
- (logikal, mapping) =>
- {
- mapping.Group = logikal.Group;
- mapping.Supplier = logikal.Supplier;
- mapping.Style = logikal.Finish;
- mapping.Dimensions.Unit.CopyFrom(model.Settings.GasketUom);
- mapping.Dimensions.Length = logikal.Length;
- mapping.Cost = logikal.Cost;
- mapping.Quantity = logikal.Quantity;
- },
- x => x.Code
- );
- mappings.Wait();
- model.GasketMappings = mappings.Result;
- model.CheckChanged();
- }
- public IEnumerable<IAwgGasket>? Gaskets
- {
- get => GetValue(GasketsProperty) as IEnumerable<IAwgGasket>;
- set => SetValue(GasketsProperty, value);
- }
- private static readonly DependencyProperty ComponentsProperty = DependencyProperty.Register(
- nameof(Components),
- typeof(IEnumerable<IAwgComponent>),
- typeof(AWGMappingWindowViewModel),
- new FrameworkPropertyMetadata(ComponentsChanged)
- );
- private static void ComponentsChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- if (d is not AWGMappingWindowViewModel model || e.NewValue is not IEnumerable<IAwgComponent> components)
- return;
- var mappings = model.ExtractMappings<ProductIntegrationSource, IAwgComponent, Product, ProductLink>(
- components,
- (logikal, mapping) =>
- {
- mapping.Dimensions.Unit.CopyFrom(model.Settings.ComponentUom);
- mapping.Dimensions.Quantity = logikal.PackSize;
- mapping.Quantity = logikal.Quantity;
- mapping.Cost = logikal.Cost;
- mapping.Group = logikal.Group;
- mapping.Supplier = logikal.Supplier;
- mapping.Style = logikal.Finish;
- },
- x => x.Code
- );
- mappings.Wait();
- model.ComponentMappings = mappings.Result;
- model.CheckChanged();
- }
- public IEnumerable<IAwgComponent>? Components
- {
- get => GetValue(ComponentsProperty) as IEnumerable<IAwgComponent>;
- set => SetValue(ComponentsProperty, value);
- }
- private static readonly DependencyProperty GlassProperty = DependencyProperty.Register(
- nameof(Glass),
- typeof(IEnumerable<IAwgGlass>),
- typeof(AWGMappingWindowViewModel),
- new FrameworkPropertyMetadata(GlassChanged)
- );
- private static void GlassChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- if (d is not AWGMappingWindowViewModel model || e.NewValue is not IEnumerable<IAwgGlass> glass)
- return;
- var mappings = model.ExtractMappings<ProductIntegrationSource, IAwgGlass, Product, ProductLink>(
- glass,
- (logikal, mapping) =>
- {
- mapping.Group = logikal.Group;
- mapping.Supplier = logikal.Supplier;
- mapping.Dimensions.Unit.CopyFrom(model.Settings.GlassUom);
- mapping.Dimensions.Height = logikal.Height;
- mapping.Dimensions.Width = logikal.Width;
- mapping.Style = logikal.Treatment;
- mapping.Quantity = logikal.Quantity;
- mapping.Cost = logikal.Cost;
- },
- x => x.Code
- );
- mappings.Wait();
- model.GlassMappings = mappings.Result;
- model.CheckChanged();
- }
- public IEnumerable<IAwgGlass>? Glass
- {
- get => GetValue(GlassProperty) as IEnumerable<IAwgGlass>;
- set => SetValue(GlassProperty, value);
- }
- private static readonly DependencyProperty LabourProperty = DependencyProperty.Register(
- nameof(Labour),
- typeof(IEnumerable<IAwgLabour>),
- typeof(AWGMappingWindowViewModel),
- new FrameworkPropertyMetadata(LabourChanged)
- );
- private static void LabourChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- if (d is not AWGMappingWindowViewModel model || e.NewValue is not IEnumerable<IAwgLabour> labour)
- return;
- var mappings = model.ExtractMappings<ActivityIntegrationSource, IAwgLabour, Activity, ActivityLink>(
- labour,
- (logikal, mapping) =>
- {
- mapping.Quantity = logikal.Quantity;
- },
- x => x.Code
- );
- mappings.Wait();
- model.LabourMappings = mappings.Result;
- model.CheckChanged();
- }
- public IEnumerable<IAwgLabour>? Labour
- {
- get => GetValue(LabourProperty) as IEnumerable<IAwgLabour>;
- set => SetValue(LabourProperty, value);
- }
- private static void SectionCheckedChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- if (d is AWGMappingWindowViewModel model)
- model.CheckChanged();
- }
- private static readonly DependencyProperty StyleMappingsProperty = DependencyProperty.Register(
- nameof(StyleMappings),
- typeof(List<ProductStyleIntegrationSource>),
- typeof(AWGMappingWindowViewModel)
- );
- public List<ProductStyleIntegrationSource>? StyleMappings
- {
- get => GetValue(StyleMappingsProperty) as List<ProductStyleIntegrationSource>;
- set => SetValue(StyleMappingsProperty, value);
- }
- private static readonly DependencyProperty StylesCheckedProperty = DependencyProperty.Register(
- nameof(StylesChecked),
- typeof(bool),
- typeof(AWGMappingWindowViewModel),
- new FrameworkPropertyMetadata(defaultValue: true, propertyChangedCallback: SectionCheckedChanged)
- );
- public bool StylesChecked
- {
- get => (bool)GetValue(StylesCheckedProperty);
- set => SetValue(StylesCheckedProperty, value);
- }
- private static readonly DependencyProperty GroupMappingsProperty = DependencyProperty.Register(
- nameof(GroupMappings),
- typeof(List<ProductGroupIntegrationSource>),
- typeof(AWGMappingWindowViewModel)
- );
- public List<ProductGroupIntegrationSource>? GroupMappings
- {
- get => GetValue(GroupMappingsProperty) as List<ProductGroupIntegrationSource>;
- set => SetValue(GroupMappingsProperty, value);
- }
- private static readonly DependencyProperty GroupsCheckedProperty = DependencyProperty.Register(
- nameof(GroupsChecked),
- typeof(bool),
- typeof(AWGMappingWindowViewModel),
- new FrameworkPropertyMetadata(defaultValue: true, propertyChangedCallback: SectionCheckedChanged)
- );
- public bool GroupsChecked
- {
- get => (bool)GetValue(GroupsCheckedProperty);
- set => SetValue(GroupsCheckedProperty, value);
- }
- private static readonly DependencyProperty SupplierMappingsProperty = DependencyProperty.Register(
- nameof(SupplierMappings),
- typeof(List<SupplierIntegrationSource>),
- typeof(AWGMappingWindowViewModel)
- );
- public List<SupplierIntegrationSource>? SupplierMappings
- {
- get => GetValue(SupplierMappingsProperty) as List<SupplierIntegrationSource>;
- set => SetValue(SupplierMappingsProperty, value);
- }
-
- private static readonly DependencyProperty DiscountMappingsProperty = DependencyProperty.Register(
- nameof(DiscountMappings),
- typeof(List<SupplierDiscountGroupIntegrationSource>),
- typeof(AWGMappingWindowViewModel)
- );
- public List<SupplierDiscountGroupIntegrationSource>? DiscountMappings
- {
- get => GetValue(DiscountMappingsProperty) as List<SupplierDiscountGroupIntegrationSource>;
- set => SetValue(DiscountMappingsProperty, value);
- }
- private static readonly DependencyProperty SuppliersCheckedProperty = DependencyProperty.Register(
- nameof(SuppliersChecked),
- typeof(bool),
- typeof(AWGMappingWindowViewModel),
- new FrameworkPropertyMetadata(defaultValue: true, propertyChangedCallback: SectionCheckedChanged)
- );
- public bool SuppliersChecked
- {
- get => (bool)GetValue(SuppliersCheckedProperty);
- set => SetValue(SuppliersCheckedProperty, value);
- }
-
- private static readonly DependencyProperty DiscountsCheckedProperty = DependencyProperty.Register(
- nameof(DiscountsChecked),
- typeof(bool),
- typeof(AWGMappingWindowViewModel),
- new FrameworkPropertyMetadata(defaultValue: true, propertyChangedCallback: SectionCheckedChanged)
- );
- public bool DiscountsChecked
- {
- get => (bool)GetValue(DiscountsCheckedProperty);
- set => SetValue(DiscountsCheckedProperty, value);
- }
- private static readonly DependencyProperty ProfileMappingsProperty = DependencyProperty.Register(
- nameof(ProfileMappings),
- typeof(List<ProductIntegrationSource>),
- typeof(AWGMappingWindowViewModel)
- );
- public List<ProductIntegrationSource>? ProfileMappings
- {
- get => GetValue(ProfileMappingsProperty) as List<ProductIntegrationSource>;
- set => SetValue(ProfileMappingsProperty, value);
- }
- private static readonly DependencyProperty ProfilesCheckedProperty = DependencyProperty.Register(
- nameof(ProfilesChecked),
- typeof(bool),
- typeof(AWGMappingWindowViewModel),
- new FrameworkPropertyMetadata(defaultValue: true, propertyChangedCallback: SectionCheckedChanged)
- );
- public bool ProfilesChecked
- {
- get => (bool)GetValue(ProfilesCheckedProperty);
- set => SetValue(ProfilesCheckedProperty, value);
- }
- private static readonly DependencyProperty GasketMappingsProperty = DependencyProperty.Register(
- nameof(GasketMappings),
- typeof(List<ProductIntegrationSource>),
- typeof(AWGMappingWindowViewModel)
- );
- public List<ProductIntegrationSource>? GasketMappings
- {
- get => GetValue(GasketMappingsProperty) as List<ProductIntegrationSource>;
- set => SetValue(GasketMappingsProperty, value);
- }
- private static readonly DependencyProperty GasketsCheckedProperty = DependencyProperty.Register(
- nameof(GasketsChecked),
- typeof(bool),
- typeof(AWGMappingWindowViewModel),
- new FrameworkPropertyMetadata(defaultValue: true, propertyChangedCallback: SectionCheckedChanged)
- );
- public bool GasketsChecked
- {
- get => (bool)GetValue(GasketsCheckedProperty);
- set => SetValue(GasketsCheckedProperty, value);
- }
- private static readonly DependencyProperty ComponentMappingsProperty = DependencyProperty.Register(
- nameof(ComponentMappings),
- typeof(List<ProductIntegrationSource>),
- typeof(AWGMappingWindowViewModel)
- );
- public List<ProductIntegrationSource>? ComponentMappings
- {
- get => GetValue(ComponentMappingsProperty) as List<ProductIntegrationSource>;
- set => SetValue(ComponentMappingsProperty, value);
- }
- private static readonly DependencyProperty ComponentsCheckedProperty = DependencyProperty.Register(
- nameof(ComponentsChecked),
- typeof(bool),
- typeof(AWGMappingWindowViewModel),
- new FrameworkPropertyMetadata(defaultValue: true, propertyChangedCallback: SectionCheckedChanged)
- );
- public bool ComponentsChecked
- {
- get => (bool)GetValue(ComponentsCheckedProperty);
- set => SetValue(ComponentsCheckedProperty, value);
- }
- private static readonly DependencyProperty GlassMappingsProperty = DependencyProperty.Register(
- nameof(GlassMappings),
- typeof(List<ProductIntegrationSource>),
- typeof(AWGMappingWindowViewModel)
- );
- public List<ProductIntegrationSource>? GlassMappings
- {
- get => GetValue(GlassMappingsProperty) as List<ProductIntegrationSource>;
- set => SetValue(GlassMappingsProperty, value);
- }
- private static readonly DependencyProperty GlassCheckedProperty = DependencyProperty.Register(
- nameof(GlassChecked),
- typeof(bool),
- typeof(AWGMappingWindowViewModel),
- new FrameworkPropertyMetadata(defaultValue: true, propertyChangedCallback: SectionCheckedChanged)
- );
- public bool GlassChecked
- {
- get => (bool)GetValue(GlassCheckedProperty);
- set => SetValue(GlassCheckedProperty, value);
- }
- private static readonly DependencyProperty LabourMappingsProperty = DependencyProperty.Register(
- nameof(LabourMappings),
- typeof(List<ActivityIntegrationSource>),
- typeof(AWGMappingWindowViewModel)
- );
- public List<ActivityIntegrationSource>? LabourMappings
- {
- get => GetValue(LabourMappingsProperty) as List<ActivityIntegrationSource>;
- set => SetValue(LabourMappingsProperty, value);
- }
- private static readonly DependencyProperty LabourCheckedProperty = DependencyProperty.Register(
- nameof(LabourChecked),
- typeof(bool),
- typeof(AWGMappingWindowViewModel),
- new FrameworkPropertyMetadata(defaultValue: true, propertyChangedCallback: SectionCheckedChanged)
- );
- public bool LabourChecked
- {
- get => (bool)GetValue(LabourCheckedProperty);
- set => SetValue(LabourCheckedProperty, value);
- }
- private static readonly DependencyProperty SectionsProperty = DependencyProperty.Register(
- nameof(Sections),
- typeof(CoreObservableCollection<KeyValuePair<string, BitmapImage>>),
- typeof(AWGMappingWindowViewModel),
- new PropertyMetadata(new CoreObservableCollection<KeyValuePair<string, BitmapImage>>())
- );
- public CoreObservableCollection<KeyValuePair<string, BitmapImage>> Sections
- {
- get => (CoreObservableCollection<KeyValuePair<string, BitmapImage>>)GetValue(SectionsProperty);
- set => SetValue(SectionsProperty, value);
- }
- private static readonly DependencyProperty SelectedSectionProperty = DependencyProperty.Register(
- nameof(SelectedSection),
- typeof(KeyValuePair<string, BitmapImage>?),
- typeof(AWGMappingWindowViewModel)
- );
- public KeyValuePair<string, BitmapImage>? SelectedSection
- {
- get => (KeyValuePair<string, BitmapImage>?)GetValue(SelectedSectionProperty);
- set => SetValue(SelectedSectionProperty, value);
- }
- private static readonly DependencyProperty MappingsCompleteProperty = DependencyProperty.Register(
- nameof(MappingsComplete),
- typeof(bool),
- typeof(AWGMappingWindowViewModel)
- );
- public bool MappingsComplete
- {
- get => (bool)GetValue(MappingsCompleteProperty);
- set => SetValue(MappingsCompleteProperty, value);
- }
- private Task<List<TCode>> ExtractMappings<TCode, TType, TEntity, TLink>(
- IEnumerable<TType>? items,
- Action<TType, TCode>? populate,
- Expression<Func<TEntity, object?>> entitycode
- )
- where TType : IAwgItem
- where TCode : BaseIntegrationSource<TEntity, TLink>, IRemotable, IPersistent, new()
- where TEntity : Entity, IRemotable, IPersistent, new()
- where TLink : EntityLink<TEntity>
- {
- return Task.Run(() =>
- {
- var results = new List<TCode>();
- if (items == null)
- return results;
- //var sourceitems = new Dictionary<string, string>();
- //foreach (var item in items)
- // sourceitems[item.Code] = item.Description;
- var keys = items.Select(x => x.Code).Distinct().ToArray();
- MultiQuery query = new();
- query.Add(
- new Filter<TEntity>(entitycode).InList(keys),
- Columns.Required<TEntity>().Add(x => x.ID).Add(entitycode)
- );
- var entitycodecol = $"Entity.{CoreUtils.GetFullPropertyName(entitycode, ".")}";
- query.Add(
- new Filter<TCode>(x => x.Code).InList(keys),
- Columns.Required<TCode>()
- .Add(x => x.ID)
- .Add(x => x.Code)
- .Add(x => x.Entity.ID)
- .Add(entitycodecol)
- );
- query.Query();
- var mappings = query.Get<TCode>().ToObjects<TCode>().ToArray();
- var entities = query.Get<TEntity>();
- foreach (var item in items)
- {
- var result = new TCode()
- {
- Code = item.Code,
- Description = item.Description
- };
- populate?.Invoke(item, result);
- var mapping = mappings.FirstOrDefault(x => string.Equals(x.Code, item.Code));
- if (mapping != null)
- result.Entity.CopyFrom(mapping.Entity);
- else
- {
- var entity = entities.Rows.FirstOrDefault(r => Equals(item.Code, r.Get(entitycode)));
- if (entity != null)
- {
- result.Entity.CopyFrom(entity.ToObject<TEntity>());
- result.DirectMatch = true;
- }
- }
- results.Add(result);
- // result.PropertyChanged += (_, _) =>
- // {
- // // TMapping mapping = mappingtable.Rows.FirstOrDefault(r =>
- // // string.Equals(r.Get<TMapping, String>(c => c.Code), result.Code))?.ToObject<TMapping>();
- // // if (mapping == null)
- // // mapping = new TMapping() { Code = result.Code };
- // // mapping.Entity.ID = result.Entity.ID;
- // // new Client<TMapping>().Save(mapping, "Created from BOM Integration Window");
- //
- // CheckChanged();
- // };
- }
- return results;
- });
- }
- public void CheckChanged()
- {
- Dispatcher.BeginInvoke(() =>
- {
- var curSel = SelectedSection?.Key ?? "";
- SelectedSection = null;
- Sections.Clear();
- if (StylesChecked && StyleMappings?.Any() == true)
- Sections.Add(new KeyValuePair<string, BitmapImage>("Styles", Resources.palette.AsBitmapImage(64, 64)));
- if (GroupsChecked && GroupMappings?.Any() == true)
- Sections.Add(
- new KeyValuePair<string, BitmapImage>("Groups", Resources.productgroup.AsBitmapImage(64, 64)));
- if (SuppliersChecked && SupplierMappings?.Any() == true)
- Sections.Add(
- new KeyValuePair<string, BitmapImage>("Suppliers", Resources.supplier.AsBitmapImage(64, 64)));
-
- if (DiscountsChecked && DiscountMappings?.Any() == true)
- Sections.Add(
- new KeyValuePair<string, BitmapImage>("Discounts", Resources.receipt.AsBitmapImage(64, 64)));
- if (ProfilesChecked && ProfileMappings?.Any() == true)
- Sections.Add(
- new KeyValuePair<string, BitmapImage>("Profiles", Resources.profile.AsBitmapImage(64, 64)));
- if (GasketsChecked && GasketMappings?.Any() == true)
- Sections.Add(new KeyValuePair<string, BitmapImage>("Gaskets", Resources.gasket.AsBitmapImage(64, 64)));
- if (ComponentsChecked && ComponentMappings?.Any() == true)
- Sections.Add(
- new KeyValuePair<string, BitmapImage>("Components", Resources.fixings.AsBitmapImage(64, 64)));
- if (GlassChecked && GlassMappings?.Any() == true)
- Sections.Add(new KeyValuePair<string, BitmapImage>("Glass", Resources.glass.AsBitmapImage(64, 64)));
- if (LabourChecked && LabourMappings?.Any() == true)
- Sections.Add(new KeyValuePair<string, BitmapImage>("Labour", Resources.quality.AsBitmapImage(64, 64)));
- SelectedSection = Sections.Any(x => string.Equals(x.Key, curSel))
- ? Sections.First(x => string.Equals(x.Key, curSel))
- : Sections.FirstOrDefault();
- var styles = !StylesChecked || (StyleMappings?.Any() != true) || (StyleMappings?.All(x => x.Entity.ID != Guid.Empty) ?? false);
- var groups = !GroupsChecked || (GroupMappings?.Any() != true) || (GroupMappings?.All(x => x.Entity.ID != Guid.Empty) ?? false);
- var suppliers = !SuppliersChecked || (SupplierMappings?.Any() != true) || (SupplierMappings?.All(x => x.Entity.ID != Guid.Empty) ?? false);
- var discounts = !DiscountsChecked || (DiscountMappings?.Any() != true) || (DiscountMappings?.All(x => x.Entity.ID != Guid.Empty) ?? false);
- var profiles = !ProfilesChecked || (ProfileMappings?.Any() != true) || (ProfileMappings?.All(x => x.Entity.ID != Guid.Empty) ?? false);
- var gaskets = !GasketsChecked || (GasketMappings?.Any() != true) || (GasketMappings?.All(x => x.Entity.ID != Guid.Empty) ?? false);
- var components = !ComponentsChecked || (ComponentMappings?.Any() != true) || (ComponentMappings?.All(x => x.Entity.ID != Guid.Empty) ?? false);
- var glass = !GlassChecked || (GlassMappings?.Any() != true) || (GlassMappings?.All(x => x.Entity.ID != Guid.Empty) ?? false);
- var labour = !LabourChecked || (LabourMappings?.Any() != true) || (LabourMappings?.All(x => x.Entity.ID != Guid.Empty) ?? false);
- MappingsComplete = styles && groups && suppliers && discounts && profiles && gaskets && components && glass && labour;
- });
- }
- public ICommand CreateStyle => new ActionCommand(
- o =>
- {
- if (o is IntegrationGridCreateEntityArgs<ProductStyle, ProductStyleIntegrationSource> args)
- {
- PopulateStyle(args.Entity, args.Mapping);
- args.Entity.Problem.Notes = ["Created from BOM Integration Window"];
- }
- }
- );
- private void PopulateStyle(ProductStyle entity, ProductStyleIntegrationSource mapping)
- {
- entity.Code = mapping.Code ?? "";
- entity.Description = mapping.Description ?? "";
-
- TreatmentTypeLink? type = mapping.StyleType == AwgStyleType.Powdercoated
- ? _settings.PowdercoatedType
- : mapping.StyleType == AwgStyleType.Anodised
- ? _settings.AnodisedType
- : mapping.StyleType == AwgStyleType.Varnished
- ? _settings.VarnishedType
- : mapping.StyleType == AwgStyleType.Taped
- ? _settings.TapedType
- : new TreatmentTypeLink();
- entity.TreatmentType.ID = type.ID;
- if (entity.TreatmentType.ID != Guid.Empty)
- {
- var product = new Client<Product>().Query(
- new Filter<Product>(x => x.Code).IsEqualTo(entity.Code),
- Columns.Local<Product>()
- ).ToArray<Product>().FirstOrDefault();
-
- if (product == null)
- {
- product = new Product();
- product.Problem.Notes = ["Created from BOM Integration Window"];
- }
- product.Code = entity.Code;
- product.Name = entity.Description;
- product.TreatmentType.ID = entity.TreatmentType.ID;
- if (product.IsChanged())
- Client.Save(product, "Created from AWG Mapping Window");
-
- entity.StockTreatmentProduct.ID = product.ID;
- entity.ManufacturingTreatmentProduct.ID = product.ID;
- }
- }
-
- public ICommand CreateGroup => new ActionCommand(
- o =>
- {
- if (o is IntegrationGridCreateEntityArgs<ProductGroup, ProductGroupIntegrationSource> args)
- {
- PopulateGroup(args.Entity, args.Mapping);
- args.Entity.Problem.Notes = ["Created from BOM Integration Window"];
- }
- }
- );
-
- public void PopulateGroup(ProductGroup entity, ProductGroupIntegrationSource mapping)
- {
- Guid parentid = Guid.Empty;
- var parentcodes = mapping.Parent
- .Split('/')
- .Select(x => x.Trim().ToUpper())
- .Where(x=>!string.IsNullOrWhiteSpace(x))
- .ToArray();
- var parents = Client.Query(
- new Filter<ProductGroup>(x => x.Code).InList(parentcodes),
- Columns.None<ProductGroup>().Add(x => x.ID).Add(x => x.Code)
- ).ToArray<ProductGroup>();
- foreach (var parentcode in parentcodes)
- {
- var parent = parents.FirstOrDefault(x => Equals(x.Code,parentcode));
- if (parent == null)
- {
- parent = new ProductGroup();
- parent.Code = parentcode;
- parent.Description = !string.IsNullOrWhiteSpace(parentcode) ? parentcode.Titleize() : "";
- parent.Parent.ID = parentid;
- parent.Problem.Notes = ["Created from BOM Integration Window"];
- Client.Save(parent, "Created from AWG Mapping Window");
- }
- parentid = parent.ID;
- }
-
- entity.Parent.ID = parentid;
- entity.Code = mapping.Code ?? "";
- entity.Description = mapping.Description ?? "";
- }
- public ICommand CreateSupplier => new ActionCommand(
- o =>
- {
- if (o is IntegrationGridCreateEntityArgs<Supplier, SupplierIntegrationSource> args)
- {
- PopulateSupplier(args.Entity, args.Mapping);
- args.Entity.Problem.Notes = ["Created from BOM Integration Window"];
- }
- }
- );
- private void PopulateSupplier(Supplier entity, SupplierIntegrationSource mapping)
- {
- entity.Code = mapping.Code ?? "";
- entity.Name = mapping.Description ?? "";
- }
- public ICommand CreateDiscount => new ActionCommand(
- o =>
- {
- if (o is IntegrationGridCreateEntityArgs<SupplierDiscountGroup, SupplierDiscountGroupIntegrationSource> args)
- {
- PopulateDiscountGroup(args.Entity, args.Mapping);
- args.Entity.Problem.Notes = ["Created from BOM Integration Window"];
- }
- }
- );
- private void PopulateDiscountGroup(SupplierDiscountGroup entity, SupplierDiscountGroupIntegrationSource mapping)
- {
- entity.Code = mapping.Code ?? "";
- entity.Description = mapping.Description ?? "";
- entity.Type = SupplierDiscountGroupType.Discount;
- var _supplier = SupplierMappings?.FirstOrDefault(x => string.Equals(x.Code, mapping.Supplier))?.Entity.ID;
- if (_supplier == null)
- _supplier = new Client<Supplier>()
- .Query(new Filter<Supplier>(x => x.Code).IsEqualTo(entity.Code),
- Columns.None<Supplier>().Add(x => x.ID))
- .ToArray<Supplier>()
- .FirstOrDefault()?.ID ?? Guid.Empty;
- entity.Supplier.ID = _supplier.Value;
- }
- public ICommand AfterCreateDiscountGroup => new ActionCommand(
- o =>
- {
- if (o is IntegrationGridCreateEntityArgs<SupplierDiscountGroup, SupplierDiscountGroupIntegrationSource> args)
- {
- PopulateDiscount(args.Entity,args.Mapping);
- }
- }
- );
- private void PopulateDiscount(SupplierDiscountGroup entity, SupplierDiscountGroupIntegrationSource mapping)
- {
- var _discount = new Client<SupplierDiscount>().Query(
- new Filter<SupplierDiscount>(x => x.Group.ID).IsEqualTo(entity.ID),
- Columns.Local<SupplierDiscount>()
- ).ToObjects<SupplierDiscount>().FirstOrDefault();
- if (_discount == null)
- {
- _discount = new();
- _discount.Group.ID = entity.ID;
- }
- _discount.Value = mapping.Discount;
-
- if (_discount.IsChanged())
- Client.Save(_discount, "Updated from AWG Mapping Window");
- }
- public ICommand CreateProfile => new ActionCommand(
- o =>
- {
- if (o is IntegrationGridCreateEntityArgs<Product, ProductIntegrationSource> args)
- {
- PopulateProfile(args.Entity,args.Mapping);
- args.Entity.Problem.Notes = ["Created from BOM Integration Window"];
- //CreateImage(args);
- }
- }
- );
- private void PopulateProfile(Product entity, ProductIntegrationSource mapping)
- {
- entity.Code = mapping.Code ?? "";
- entity.Name = mapping.Description ?? "";
- entity.UnitOfMeasure.ID = _settings.ProfileUom.ID;
- var _group = GroupMappings?.FirstOrDefault(x => Equals(x.Code, mapping.Group));
- if (_group != null)
- entity.Group.ID = _group.Entity.ID;
- }
- public ICommand AfterCreateProduct => new ActionCommand(
- o =>
- {
- if (o is IntegrationGridCreateEntityArgs<Product, ProductIntegrationSource> args)
- {
- PopulateProduct(args.Entity,args.Mapping);
- }
- }
- );
- private void PopulateProduct(Product entity, ProductIntegrationSource mapping)
- {
- CreateTreatmentParams(entity, mapping, AwgStyleType.Powdercoated, Settings.PowdercoatedType);
- CreateTreatmentParams(entity, mapping, AwgStyleType.Anodised, Settings.AnodisedType);
- CreateTreatmentParams(entity, mapping, AwgStyleType.Taped, Settings.TapedType);
- CreateTreatmentParams(entity, mapping, AwgStyleType.Varnished, Settings.VarnishedType);
- CreateSupplierProducts(entity, mapping);
- }
- // private void CreateImage(IntegrationGridCreateEntityArgs<Product, ProductIntegrationSource> args)
- // {
- // if (!string.IsNullOrWhiteSpace(_settings.ImageUrl))
- // {
- // var model = new LogikalCodeModel() { Code = args.Mapping.Code };
- // var _expression = new CoreExpression<LogikalCodeModel, string>(_settings.ImageUrl);
- // if (_expression.Evaluate(model).Get(out var eval, out var e))
- // {
- // var tcs = new TaskCompletionSource<byte[]>();
- // new HttpClient().GetByteArrayAsync(eval)
- // .ContinueWith(
- // t =>
- // {
- // if (t.IsFaulted)
- // tcs.SetException(t.Exception);
- // else
- // tcs.SetResult(t.Result);
- // });
- // try
- // {
- // var data = tcs.Task.Result;
- // var document = new Document()
- // {
- // Data = tcs.Task.Result,
- // CRC = CoreUtils.CalculateCRC(data),
- // FileName = args.Mapping.Code
- // };
- // Client.Save(document,"Created from AWG Mapping Window");
- // args.Entity.Image.ID = document.ID;
- // }
- // catch (Exception exception)
- // {
- // Logger.Send(LogType.Error,"",$"Exception in CreateImage(): {exception.Message}");
- // }
- // }
- // }
- // }
- private void CreateTreatmentParams(Product entity, ProductIntegrationSource mapping, AwgStyleType type, TreatmentTypeLink link)
- {
- if (mapping.TreatmentParameters.ContainsKey(type) && !Equals(link.ID,Guid.Empty))
- {
- var _treatment = new Client<ProductTreatment>().Query(
- new Filter<ProductTreatment>(x=>x.Product.ID).IsEqualTo(entity.ID)
- .And(x=>x.TreatmentType.ID).IsEqualTo(link.ID),
- Columns.Local<ProductTreatment>()
- ).ToObjects<ProductTreatment>().FirstOrDefault();
- if (_treatment == null)
- {
- _treatment = new();
- _treatment.Product.ID = entity.ID;
- _treatment.TreatmentType.ID = link.ID;
- }
-
- _treatment.Parameter = mapping.TreatmentParameters[type];
- if (_treatment.IsChanged())
- Client.Save(_treatment,"Updated from AWG Mapping Window");
- }
- }
- private void CreateSupplierProducts(Product entity, ProductIntegrationSource mapping)
- {
- var supplier = SupplierMappings?.FirstOrDefault(x => Equals(x.Code, mapping.Supplier));
- if (supplier != null)
- {
- List<SupplierProduct> products = new();
-
- if (!mapping.MillCost.IsEffectivelyEqual(mapping.Cost))
- {
- var _mill = CreateSupplierProduct(entity, mapping, supplier, "", mapping.MillCost, false);
- products.Add(_mill);
- }
-
- var _treated = CreateSupplierProduct(entity, mapping, supplier, mapping.Style, mapping.Cost, false);
- products.Add(_treated);
- var _updates = products.Where(x => x.IsChanged()).ToArray();
- if (_updates.Any())
- Client.Save(_updates,"Updated from AWG Mapping Window");
- }
- }
- private SupplierProduct CreateSupplierProduct(Product entity, ProductIntegrationSource mapping, SupplierIntegrationSource supplier,
- string stylecode, double cost, bool save)
- {
- var _sp = new Client<SupplierProduct>().Query(
- new Filter<SupplierProduct>(x => x.Product.ID).IsEqualTo(entity.ID).And(x=>x.SupplierLink.ID).IsEqualTo(supplier.Entity.ID),
- Columns.Local<SupplierProduct>()
- ).ToObjects<SupplierProduct>().FirstOrDefault();
- if (_sp == null)
- {
- _sp = new();
- _sp.Product.ID = entity.ID;
- _sp.SupplierLink.ID = supplier.Entity.ID;
- }
- _sp.SupplierCode = mapping.Code ?? "";
- _sp.SupplierDescription = mapping.Description ?? "";
- _sp.Dimensions.Unit.ID = mapping.Dimensions.Unit.ID;
- _sp.Dimensions.Height = mapping.Dimensions.Height;
- _sp.Dimensions.Width = mapping.Dimensions.Width;
- _sp.Dimensions.Length = mapping.Dimensions.Length;
- _sp.Dimensions.Quantity = mapping.Dimensions.Quantity;
- _sp.Dimensions.Weight = mapping.Dimensions.Weight;
- _sp.Dimensions.Value = mapping.Dimensions.Value;
- _sp.Dimensions.UnitSize = mapping.Dimensions.UnitSize;
- var _style = StyleMappings?.FirstOrDefault(x => Equals(x.Code, stylecode));
- _sp.Style.ID = _style?.Entity.ID ?? Guid.Empty;
- _sp.TradePrice = cost;
- if (save && _sp.IsChanged())
- new Client<SupplierProduct>().Save(_sp, "Updated by Awg Mapping Window");
- return _sp;
- }
- public ICommand CreateGasket => new ActionCommand(
- o =>
- {
- if (o is IntegrationGridCreateEntityArgs<Product, ProductIntegrationSource> args)
- {
- PopulateGasket(args.Entity, args.Mapping);
- args.Entity.Problem.Notes = ["Created from BOM Integration Window"];
- }
- }
- );
- private void PopulateGasket(Product argsEntity, ProductIntegrationSource argsMapping)
- {
- argsEntity.Code = argsMapping.Entity.Code ?? "";
- argsEntity.Name = argsMapping.Description ?? "";
- argsEntity.UnitOfMeasure.ID = _settings.GasketUom.ID;
- var _group = GroupMappings?.FirstOrDefault(x => Equals(x.Code, argsMapping.Group));
- if (_group != null)
- argsEntity.Group.ID = _group.Entity.ID;
- }
- public ICommand CreateComponent => new ActionCommand(
- o =>
- {
- if (o is IntegrationGridCreateEntityArgs<Product, ProductIntegrationSource> args)
- {
- PopulateComponent(args.Entity, args.Mapping);
- args.Entity.Problem.Notes = ["Created from BOM Integration Window"];
- }
- }
- );
- private void PopulateComponent(Product entity, ProductIntegrationSource mapping)
- {
- entity.Code = mapping.Entity.Code ?? "";
- entity.Name = mapping.Description ?? "";
- entity.UnitOfMeasure.ID = _settings.ComponentUom.ID;
- var _group = GroupMappings?.FirstOrDefault(x => Equals(x.Code, mapping.Group));
- if (_group != null)
- entity.Group.ID = _group.Entity.ID;
- }
- public ICommand CreateGlass => new ActionCommand(
- o =>
- {
- if (o is IntegrationGridCreateEntityArgs<Product, ProductIntegrationSource> args)
- {
- PopulateGlass(args.Entity, args.Mapping);
- args.Entity.Problem.Notes = ["Created from BOM Integration Window"];
- }
- }
- );
- private void PopulateGlass(Product entity, ProductIntegrationSource mapping)
- {
- entity.Code = mapping.Entity.Code ?? "";
- entity.Name = mapping.Description ?? "";
- entity.UnitOfMeasure.ID = _settings.GlassUom.ID;
- var _group = GroupMappings?.FirstOrDefault(x => Equals(x.Code, mapping.Group));
- if (_group != null)
- entity.Group.ID = _group.Entity.ID;
- }
- public ICommand CreateActivity => new ActionCommand(
- o =>
- {
- if (o is IntegrationGridCreateEntityArgs<Activity, ActivityIntegrationSource> args)
- {
- PopulateActivity(args.Entity, args.Mapping);
-
- args.Entity.Problem.Notes = ["Created from BOM Integration Window"];
- }
- }
- );
- private void PopulateActivity(Activity entity, ActivityIntegrationSource mapping)
- {
- entity.Code = mapping.Entity.Code ?? "";
- entity.Description = mapping.Description ?? "";
- }
- private class RawDimensions : IBaseDimensions
- {
- public double Quantity { get; set; }
- public double Length { get; set; }
- public double Width { get; set; }
- public double Height { get; set; }
- public double Weight { get; set; }
- }
- public void GetDiscounts(Action<SupplierDiscountGroupLink, double>? discountCallback)
- {
- if (DiscountsChecked && Discounts != null)
- {
- foreach (var discount in Discounts)
- {
- var discountmapping = DiscountMappings?.FirstOrDefault(x => x.Code == discount.Code);
- if (discountmapping != null && discountCallback != null)
- discountCallback?.Invoke(discountmapping.Entity,discountmapping.Discount);
- }
- }
- }
- public void GetParts(
- Action<ProductLink, ProductStyleLink?, IBaseDimensions, double, double>? productCallback,
- Action<ActivityLink, TimeSpan, double>? labourCallback)
- {
- GetParts(Profiles,Gaskets,Components,Glass,Labour,productCallback,labourCallback);
- }
-
- public void GetParts<TProfile, TGasket, TComponent, TGlass, TLabour>(
- IEnumerable<TProfile>? profiles,
- IEnumerable<TGasket>? gaskets,
- IEnumerable<TComponent>? components,
- IEnumerable<TGlass>? glasses,
- IEnumerable<TLabour>? labour,
- Action<ProductLink, ProductStyleLink?, IBaseDimensions, double, double>? productCallback,
- Action<ActivityLink, TimeSpan, double>? labourCallback)
- where TProfile : IAwgProfile
- where TGasket : IAwgGasket
- where TComponent : IAwgComponent
- where TGlass : IAwgGlass
- where TLabour : IAwgLabour
- {
- if (ProfilesChecked && profiles != null)
- {
- foreach (var profile in profiles)
- {
- var profilemapping = ProfileMappings?.FirstOrDefault(x => x.Code == profile.Code);
- var stylemapping = StyleMappings?.FirstOrDefault(x => string.Equals(x.Code, profile.Finish));
- if (profilemapping != null && productCallback is not null)
- {
- productCallback(
- profilemapping.Entity,
- stylemapping?.Entity,
- new RawDimensions() { Length = profile.Length },
- profile.Quantity,
- profile.Cost * profile.Quantity);
- }
- }
- }
- if (GasketsChecked && gaskets != null)
- {
- foreach (var gasket in gaskets)
- {
- var _mapping = GasketMappings?.FirstOrDefault(x => x.Code == gasket.Code);
- var stylemapping = StyleMappings?.FirstOrDefault(x => string.Equals(x.Code, gasket.Finish));
- if (_mapping != null && productCallback is not null)
- {
- _mapping.ConvertDimensions(
- x => x.Dimensions,
- x => x.Quantity,
- x => x.Cost,
- Client<ProductDimensionUnit>.Provider
- );
-
- productCallback(
- _mapping.Entity,
- stylemapping?.Entity,
- new RawDimensions() { Length = _mapping.Dimensions.Length },
- _mapping.Quantity,
- _mapping.Quantity * _mapping.Cost);
- }
- }
- }
- if (ComponentsChecked && components != null)
- {
- foreach (var component in components)
- {
- var _mapping = ComponentMappings?.FirstOrDefault(x => string.Equals(x.Code, component.Code));
- var stylemapping = StyleMappings?.FirstOrDefault(x => string.Equals(x.Code, component.Finish));
- if (_mapping != null && productCallback is not null)
- {
- _mapping.ConvertDimensions(
- x => x.Dimensions,
- x => x.Quantity,
- x => x.Cost,
- Client<ProductDimensionUnit>.Provider
- );
-
- productCallback(
- _mapping.Entity,
- stylemapping?.Entity,
- new RawDimensions() { Quantity = _mapping.Dimensions.Quantity },
- _mapping.Quantity,
- _mapping.Quantity * _mapping.Cost);
- }
- }
- }
- if (GlassChecked && glasses != null)
- {
- foreach (var glass in glasses)
- {
- var _mapping = GlassMappings?.FirstOrDefault(x => string.Equals(x.Code, glass.Code));
- if (_mapping != null && productCallback is not null)
- {
- productCallback(
- _mapping.Entity,
- null,
- new RawDimensions() { Height = glass.Height, Width = glass.Width },
- glass.Quantity,
- glass.Quantity * glass.Cost);
- }
- }
- }
- if (LabourChecked && labour != null)
- {
- foreach (var activity in labour)
- {
- var _mapping = LabourMappings?.FirstOrDefault(x => string.Equals(x.Code, activity.Code));
- if (_mapping != null && labourCallback is not null)
- {
- labourCallback(
- _mapping.Entity,
- TimeSpan.FromHours(activity.Quantity),
- activity.Quantity * activity.Cost);
- }
- }
- }
- }
- private void CheckUpdate<TEntity,TItem,TMapping>(bool isChecked, LogikalUpdateType updateType, IEnumerable<TItem>? items,
- IEnumerable<TMapping>? mappings,
- Action<TEntity,TMapping> callback)
- where TEntity : Entity, IRemotable, IPersistent, new()
- where TItem : IIntegrationItem
- where TMapping : class, IBaseIntegrationSource
- {
- var _items = items as TItem[] ?? items?.ToArray();
- var _mappings = mappings as TMapping[] ?? mappings?.ToArray();
- if (isChecked && updateType.Equals(LogikalUpdateType.AlwaysUpdate) && _items?.Any()==true && _mappings?.Any() == true)
- {
- var _ids = _mappings?.Select(x => x.Entity.ID).Distinct().ToArray() ?? [];
- var _entities = new Client<TEntity>().Query(
- new Filter<TEntity>(x=>x.ID).InList(_ids),
- Columns.Local<TEntity>().Add(Columns.Required<TEntity>())
- ).ToArray<TEntity>();
-
- foreach (var _item in _items)
- {
- var _mapping = _mappings?.FirstOrDefault(x => string.Equals(x.Code, _item.Code));
- if (_mapping != null)
- {
- var _entity = _entities.FirstOrDefault(x => x.ID == _mapping.Entity.ID);
- if (_entity != null)
- callback(_entity, _mapping);
- }
- }
- var _updates = _entities.Where(x => x.IsChanged()).ToArray();
- if (_updates.Any())
- new Client<TEntity>().Save(_updates,"Updated by AWG Mapping Window");
- }
- }
- public void CheckUpdates()
- {
- CheckUpdate<ProductStyle,IAwgStyle,ProductStyleIntegrationSource>(StylesChecked, Settings.UpdateStyles, Styles,
- StyleMappings, PopulateStyle);
-
- CheckUpdate<ProductGroup,IAwgGroup,ProductGroupIntegrationSource>(GroupsChecked, Settings.UpdateGroups, Groups,
- GroupMappings, PopulateGroup);
-
- CheckUpdate<Supplier, IAwgSupplier, SupplierIntegrationSource>(SuppliersChecked, Settings.UpdateSuppliers,
- Suppliers, SupplierMappings, PopulateSupplier);
-
- CheckUpdate<SupplierDiscountGroup, IAwgDiscount,SupplierDiscountGroupIntegrationSource>(DiscountsChecked,
- Settings.UpdateDiscounts, Discounts, DiscountMappings, (entity,mapping) =>
- {
- PopulateDiscountGroup(entity,mapping);
- PopulateDiscount(entity,mapping);
- });
- CheckUpdate<Product, IAwgProfile, ProductIntegrationSource>(ProfilesChecked, Settings.UpdateProfiles,
- Profiles, ProfileMappings, (entity, mapping) =>
- {
- PopulateProfile(entity,mapping);
- PopulateProduct(entity,mapping);
- });
-
- CheckUpdate<Product, IAwgGasket, ProductIntegrationSource>(GasketsChecked, Settings.UpdateGaskets,
- Gaskets, GasketMappings, (entity, mapping) =>
- {
- PopulateGasket(entity,mapping);
- PopulateProduct(entity,mapping);
- });
-
- CheckUpdate<Product, IAwgComponent, ProductIntegrationSource>(ComponentsChecked, Settings.UpdateComponents,
- Components, ComponentMappings, (entity, mapping) =>
- {
- PopulateComponent(entity,mapping);
- PopulateProduct(entity,mapping);
- });
-
- CheckUpdate<Product, IAwgGlass, ProductIntegrationSource>(GlassChecked, Settings.UpdateGlass,
- Glass, GlassMappings, (entity, mapping) =>
- {
- PopulateGlass(entity,mapping);
- PopulateProduct(entity,mapping);
- });
-
- CheckUpdate<Activity, IAwgLabour, ActivityIntegrationSource>(LabourChecked, Settings.UpdateLabour,
- Labour, LabourMappings, PopulateActivity);
- }
-
- }
|