AWGMappingWindowViewModel.cs 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Linq.Expressions;
  5. using System.Net.Http;
  6. using System.Threading.Tasks;
  7. using System.Windows;
  8. using System.Windows.Input;
  9. using System.Windows.Media.Imaging;
  10. using Comal.Classes;
  11. using InABox.Clients;
  12. using InABox.Configuration;
  13. using InABox.Core;
  14. using InABox.Integration.Awg;
  15. using InABox.WPF;
  16. using Inflector;
  17. using Microsoft.Xaml.Behaviors.Core;
  18. using PRSDimensionUtils;
  19. using sun.text.resources.ro;
  20. namespace PRSDesktop.Integrations.Common;
  21. public class AWGMappingWindowViewModel : DependencyObject
  22. {
  23. private readonly LogikalSettings _settings;
  24. public LogikalSettings Settings => _settings;
  25. public AWGMappingWindowViewModel() : base()
  26. {
  27. _settings = new GlobalConfiguration<LogikalSettings>().Load();
  28. }
  29. private static readonly DependencyProperty SourceTypeProperty = DependencyProperty.Register(
  30. nameof(SourceType),
  31. typeof(IntegrationSourceType),
  32. typeof(AWGMappingWindowViewModel)
  33. );
  34. public IntegrationSourceType SourceType
  35. {
  36. get => (IntegrationSourceType)GetValue(SourceTypeProperty);
  37. set => SetValue(SourceTypeProperty, value);
  38. }
  39. private static readonly DependencyProperty StylesProperty = DependencyProperty.Register(
  40. nameof(Styles),
  41. typeof(IEnumerable<IAwgStyle>),
  42. typeof(AWGMappingWindowViewModel),
  43. new FrameworkPropertyMetadata(StylesChanged)
  44. );
  45. private static void StylesChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  46. {
  47. if (d is not AWGMappingWindowViewModel model || e.NewValue is not IEnumerable<IAwgStyle> styles)
  48. return;
  49. var mappings =
  50. model.ExtractMappings<ProductStyleIntegrationSource, IAwgStyle, ProductStyle, ProductStyleLink>(
  51. styles,
  52. (logikal, mapping) =>
  53. {
  54. mapping.Cost = logikal.Cost;
  55. mapping.StyleType = logikal.StyleType;
  56. },
  57. x => x.Code
  58. );
  59. mappings.Wait();
  60. model.StyleMappings = mappings.Result;
  61. model.CheckChanged();
  62. }
  63. public IEnumerable<IAwgStyle>? Styles
  64. {
  65. get => GetValue(StylesProperty) as IEnumerable<IAwgStyle>;
  66. set => SetValue(StylesProperty, value);
  67. }
  68. private static readonly DependencyProperty GroupsProperty = DependencyProperty.Register(
  69. nameof(Groups),
  70. typeof(IEnumerable<IAwgGroup>),
  71. typeof(AWGMappingWindowViewModel),
  72. new FrameworkPropertyMetadata(GroupsChanged)
  73. );
  74. private static void GroupsChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  75. {
  76. if (d is not AWGMappingWindowViewModel model || e.NewValue is not IEnumerable<IAwgGroup> groups)
  77. return;
  78. var mappings =
  79. model.ExtractMappings<ProductGroupIntegrationSource, IAwgGroup, ProductGroup, ProductGroupLink>(
  80. groups,
  81. (logikal, mapping) =>
  82. {
  83. mapping.Parent = logikal.Parent;
  84. },
  85. x => x.Code
  86. );
  87. mappings.Wait();
  88. model.GroupMappings = mappings.Result;
  89. model.CheckChanged();
  90. }
  91. public IEnumerable<IAwgGroup>? Groups
  92. {
  93. get => GetValue(GroupsProperty) as IEnumerable<IAwgGroup>;
  94. set => SetValue(GroupsProperty, value);
  95. }
  96. private static readonly DependencyProperty SuppliersProperty = DependencyProperty.Register(
  97. nameof(Suppliers),
  98. typeof(IEnumerable<IAwgSupplier>),
  99. typeof(AWGMappingWindowViewModel),
  100. new FrameworkPropertyMetadata(SuppliersChanged)
  101. );
  102. private static void SuppliersChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  103. {
  104. if (d is not AWGMappingWindowViewModel model || e.NewValue is not IEnumerable<IAwgSupplier> suppliers)
  105. return;
  106. var mappings =
  107. model.ExtractMappings<SupplierIntegrationSource, IAwgSupplier, Supplier, SupplierLink>(
  108. suppliers,
  109. null,
  110. x => x.Code
  111. );
  112. mappings.Wait();
  113. model.SupplierMappings = mappings.Result;
  114. model.CheckChanged();
  115. }
  116. public IEnumerable<IAwgSupplier>? Suppliers
  117. {
  118. get => GetValue(SuppliersProperty) as IEnumerable<IAwgSupplier>;
  119. set => SetValue(SuppliersProperty, value);
  120. }
  121. private static readonly DependencyProperty DiscountsProperty = DependencyProperty.Register(
  122. nameof(Discounts),
  123. typeof(IEnumerable<IAwgDiscount>),
  124. typeof(AWGMappingWindowViewModel),
  125. new FrameworkPropertyMetadata(DiscountsChanged)
  126. );
  127. private static void DiscountsChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  128. {
  129. if (d is not AWGMappingWindowViewModel model || e.NewValue is not IEnumerable<IAwgDiscount> discounts)
  130. return;
  131. var mappings =
  132. model.ExtractMappings<SupplierDiscountGroupIntegrationSource, IAwgDiscount, SupplierDiscountGroup, SupplierDiscountGroupLink>(
  133. discounts,
  134. (logikal, mapping) =>
  135. {
  136. mapping.Supplier = logikal.SupplierCode;
  137. mapping.Discount = logikal.Discount;
  138. },
  139. x => x.Code
  140. );
  141. mappings.Wait();
  142. model.DiscountMappings = mappings.Result;
  143. model.CheckChanged();
  144. }
  145. public IEnumerable<IAwgDiscount>? Discounts
  146. {
  147. get => GetValue(DiscountsProperty) as IEnumerable<IAwgDiscount>;
  148. set => SetValue(DiscountsProperty, value);
  149. }
  150. private static readonly DependencyProperty ProfilesProperty = DependencyProperty.Register(
  151. nameof(Profiles),
  152. typeof(IEnumerable<IAwgProfile>),
  153. typeof(AWGMappingWindowViewModel),
  154. new FrameworkPropertyMetadata(ProfilesChanged)
  155. );
  156. private static void ProfilesChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  157. {
  158. if (d is not AWGMappingWindowViewModel model || e.NewValue is not IEnumerable<IAwgProfile> profiles)
  159. return;
  160. var mappings = model.ExtractMappings<ProductIntegrationSource, IAwgProfile, Product, ProductLink>(
  161. profiles,
  162. (logikal, mapping) =>
  163. {
  164. mapping.Style = logikal.Finish;
  165. mapping.Dimensions.Unit.CopyFrom(model.Settings.ProfileUom);
  166. mapping.Dimensions.Length = logikal.Length;
  167. mapping.Group = logikal.Group;
  168. mapping.Supplier = logikal.Supplier;
  169. mapping.Cost = logikal.Cost;
  170. mapping.Quantity = logikal.Quantity;
  171. mapping.TreatmentParameters[AwgStyleType.Powdercoated] = logikal.PaintPerimeter;
  172. mapping.TreatmentParameters[AwgStyleType.Anodised] = logikal.AnodizePerimeter;
  173. },
  174. x => x.Code
  175. );
  176. mappings.Wait();
  177. model.ProfileMappings = mappings.Result;
  178. model.CheckChanged();
  179. }
  180. public IEnumerable<IAwgProfile>? Profiles
  181. {
  182. get => GetValue(ProfilesProperty) as IEnumerable<IAwgProfile>;
  183. set => SetValue(ProfilesProperty, value);
  184. }
  185. private static readonly DependencyProperty GasketsProperty = DependencyProperty.Register(
  186. nameof(Gaskets),
  187. typeof(IEnumerable<IAwgGasket>),
  188. typeof(AWGMappingWindowViewModel),
  189. new FrameworkPropertyMetadata(GasketsChanged)
  190. );
  191. private static void GasketsChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  192. {
  193. if (d is not AWGMappingWindowViewModel model || e.NewValue is not IEnumerable<IAwgGasket> gaskets)
  194. return;
  195. var mappings = model.ExtractMappings<ProductIntegrationSource, IAwgGasket, Product, ProductLink>(
  196. gaskets,
  197. (logikal, mapping) =>
  198. {
  199. mapping.Group = logikal.Group;
  200. mapping.Supplier = logikal.Supplier;
  201. mapping.Dimensions.Unit.CopyFrom(model.Settings.GasketUom);
  202. mapping.Dimensions.Length = logikal.Length;
  203. mapping.Cost = logikal.Cost;
  204. mapping.Quantity = logikal.Quantity;
  205. },
  206. x => x.Code
  207. );
  208. mappings.Wait();
  209. model.GasketMappings = mappings.Result;
  210. model.CheckChanged();
  211. }
  212. public IEnumerable<IAwgGasket>? Gaskets
  213. {
  214. get => GetValue(GasketsProperty) as IEnumerable<IAwgGasket>;
  215. set => SetValue(GasketsProperty, value);
  216. }
  217. private static readonly DependencyProperty ComponentsProperty = DependencyProperty.Register(
  218. nameof(Components),
  219. typeof(IEnumerable<IAwgComponent>),
  220. typeof(AWGMappingWindowViewModel),
  221. new FrameworkPropertyMetadata(ComponentsChanged)
  222. );
  223. private static void ComponentsChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  224. {
  225. if (d is not AWGMappingWindowViewModel model || e.NewValue is not IEnumerable<IAwgComponent> components)
  226. return;
  227. var mappings = model.ExtractMappings<ProductIntegrationSource, IAwgComponent, Product, ProductLink>(
  228. components,
  229. (logikal, mapping) =>
  230. {
  231. mapping.Dimensions.Unit.CopyFrom(model.Settings.ComponentUom);
  232. mapping.Dimensions.Quantity = logikal.PackSize;
  233. mapping.Quantity = logikal.Quantity;
  234. mapping.Cost = logikal.Cost;
  235. mapping.Group = logikal.Group;
  236. mapping.Supplier = logikal.Supplier;
  237. },
  238. x => x.Code
  239. );
  240. mappings.Wait();
  241. model.ComponentMappings = mappings.Result;
  242. model.CheckChanged();
  243. }
  244. public IEnumerable<IAwgComponent>? Components
  245. {
  246. get => GetValue(ComponentsProperty) as IEnumerable<IAwgComponent>;
  247. set => SetValue(ComponentsProperty, value);
  248. }
  249. private static readonly DependencyProperty GlassProperty = DependencyProperty.Register(
  250. nameof(Glass),
  251. typeof(IEnumerable<IAwgGlass>),
  252. typeof(AWGMappingWindowViewModel),
  253. new FrameworkPropertyMetadata(GlassChanged)
  254. );
  255. private static void GlassChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  256. {
  257. if (d is not AWGMappingWindowViewModel model || e.NewValue is not IEnumerable<IAwgGlass> glass)
  258. return;
  259. var mappings = model.ExtractMappings<ProductIntegrationSource, IAwgGlass, Product, ProductLink>(
  260. glass,
  261. (logikal, mapping) =>
  262. {
  263. mapping.Group = logikal.Group;
  264. mapping.Supplier = logikal.Supplier;
  265. mapping.Dimensions.Unit.CopyFrom(model.Settings.GlassUom);
  266. mapping.Dimensions.Height = logikal.Height;
  267. mapping.Dimensions.Width = logikal.Width;
  268. mapping.Style = logikal.Treatment;
  269. mapping.Quantity = logikal.Quantity;
  270. mapping.Cost = logikal.Cost;
  271. },
  272. x => x.Code
  273. );
  274. mappings.Wait();
  275. model.GlassMappings = mappings.Result;
  276. model.CheckChanged();
  277. }
  278. public IEnumerable<IAwgGlass>? Glass
  279. {
  280. get => GetValue(GlassProperty) as IEnumerable<IAwgGlass>;
  281. set => SetValue(GlassProperty, value);
  282. }
  283. private static readonly DependencyProperty LabourProperty = DependencyProperty.Register(
  284. nameof(Labour),
  285. typeof(IEnumerable<IAwgLabour>),
  286. typeof(AWGMappingWindowViewModel),
  287. new FrameworkPropertyMetadata(LabourChanged)
  288. );
  289. private static void LabourChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  290. {
  291. if (d is not AWGMappingWindowViewModel model || e.NewValue is not IEnumerable<IAwgLabour> labour)
  292. return;
  293. var mappings = model.ExtractMappings<ActivityIntegrationSource, IAwgLabour, Activity, ActivityLink>(
  294. labour,
  295. (logikal, mapping) =>
  296. {
  297. mapping.Quantity = logikal.Quantity;
  298. },
  299. x => x.Code
  300. );
  301. mappings.Wait();
  302. model.LabourMappings = mappings.Result;
  303. model.CheckChanged();
  304. }
  305. public IEnumerable<IAwgLabour>? Labour
  306. {
  307. get => GetValue(LabourProperty) as IEnumerable<IAwgLabour>;
  308. set => SetValue(LabourProperty, value);
  309. }
  310. private static void SectionCheckedChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  311. {
  312. if (d is AWGMappingWindowViewModel model)
  313. model.CheckChanged();
  314. }
  315. private static readonly DependencyProperty StyleMappingsProperty = DependencyProperty.Register(
  316. nameof(StyleMappings),
  317. typeof(List<ProductStyleIntegrationSource>),
  318. typeof(AWGMappingWindowViewModel)
  319. );
  320. public List<ProductStyleIntegrationSource>? StyleMappings
  321. {
  322. get => GetValue(StyleMappingsProperty) as List<ProductStyleIntegrationSource>;
  323. set => SetValue(StyleMappingsProperty, value);
  324. }
  325. private static readonly DependencyProperty StylesCheckedProperty = DependencyProperty.Register(
  326. nameof(StylesChecked),
  327. typeof(bool),
  328. typeof(AWGMappingWindowViewModel),
  329. new FrameworkPropertyMetadata(defaultValue: true, propertyChangedCallback: SectionCheckedChanged)
  330. );
  331. public bool StylesChecked
  332. {
  333. get => (bool)GetValue(StylesCheckedProperty);
  334. set => SetValue(StylesCheckedProperty, value);
  335. }
  336. private static readonly DependencyProperty GroupMappingsProperty = DependencyProperty.Register(
  337. nameof(GroupMappings),
  338. typeof(List<ProductGroupIntegrationSource>),
  339. typeof(AWGMappingWindowViewModel)
  340. );
  341. public List<ProductGroupIntegrationSource>? GroupMappings
  342. {
  343. get => GetValue(GroupMappingsProperty) as List<ProductGroupIntegrationSource>;
  344. set => SetValue(GroupMappingsProperty, value);
  345. }
  346. private static readonly DependencyProperty GroupsCheckedProperty = DependencyProperty.Register(
  347. nameof(GroupsChecked),
  348. typeof(bool),
  349. typeof(AWGMappingWindowViewModel),
  350. new FrameworkPropertyMetadata(defaultValue: true, propertyChangedCallback: SectionCheckedChanged)
  351. );
  352. public bool GroupsChecked
  353. {
  354. get => (bool)GetValue(GroupsCheckedProperty);
  355. set => SetValue(GroupsCheckedProperty, value);
  356. }
  357. private static readonly DependencyProperty SupplierMappingsProperty = DependencyProperty.Register(
  358. nameof(SupplierMappings),
  359. typeof(List<SupplierIntegrationSource>),
  360. typeof(AWGMappingWindowViewModel)
  361. );
  362. public List<SupplierIntegrationSource>? SupplierMappings
  363. {
  364. get => GetValue(SupplierMappingsProperty) as List<SupplierIntegrationSource>;
  365. set => SetValue(SupplierMappingsProperty, value);
  366. }
  367. private static readonly DependencyProperty DiscountMappingsProperty = DependencyProperty.Register(
  368. nameof(DiscountMappings),
  369. typeof(List<SupplierDiscountGroupIntegrationSource>),
  370. typeof(AWGMappingWindowViewModel)
  371. );
  372. public List<SupplierDiscountGroupIntegrationSource>? DiscountMappings
  373. {
  374. get => GetValue(DiscountMappingsProperty) as List<SupplierDiscountGroupIntegrationSource>;
  375. set => SetValue(DiscountMappingsProperty, value);
  376. }
  377. private static readonly DependencyProperty SuppliersCheckedProperty = DependencyProperty.Register(
  378. nameof(SuppliersChecked),
  379. typeof(bool),
  380. typeof(AWGMappingWindowViewModel),
  381. new FrameworkPropertyMetadata(defaultValue: true, propertyChangedCallback: SectionCheckedChanged)
  382. );
  383. public bool SuppliersChecked
  384. {
  385. get => (bool)GetValue(SuppliersCheckedProperty);
  386. set => SetValue(SuppliersCheckedProperty, value);
  387. }
  388. private static readonly DependencyProperty DiscountsCheckedProperty = DependencyProperty.Register(
  389. nameof(DiscountsChecked),
  390. typeof(bool),
  391. typeof(AWGMappingWindowViewModel),
  392. new FrameworkPropertyMetadata(defaultValue: true, propertyChangedCallback: SectionCheckedChanged)
  393. );
  394. public bool DiscountsChecked
  395. {
  396. get => (bool)GetValue(DiscountsCheckedProperty);
  397. set => SetValue(DiscountsCheckedProperty, value);
  398. }
  399. private static readonly DependencyProperty ProfileMappingsProperty = DependencyProperty.Register(
  400. nameof(ProfileMappings),
  401. typeof(List<ProductIntegrationSource>),
  402. typeof(AWGMappingWindowViewModel)
  403. );
  404. public List<ProductIntegrationSource>? ProfileMappings
  405. {
  406. get => GetValue(ProfileMappingsProperty) as List<ProductIntegrationSource>;
  407. set => SetValue(ProfileMappingsProperty, value);
  408. }
  409. private static readonly DependencyProperty ProfilesCheckedProperty = DependencyProperty.Register(
  410. nameof(ProfilesChecked),
  411. typeof(bool),
  412. typeof(AWGMappingWindowViewModel),
  413. new FrameworkPropertyMetadata(defaultValue: true, propertyChangedCallback: SectionCheckedChanged)
  414. );
  415. public bool ProfilesChecked
  416. {
  417. get => (bool)GetValue(ProfilesCheckedProperty);
  418. set => SetValue(ProfilesCheckedProperty, value);
  419. }
  420. private static readonly DependencyProperty GasketMappingsProperty = DependencyProperty.Register(
  421. nameof(GasketMappings),
  422. typeof(List<ProductIntegrationSource>),
  423. typeof(AWGMappingWindowViewModel)
  424. );
  425. public List<ProductIntegrationSource>? GasketMappings
  426. {
  427. get => GetValue(GasketMappingsProperty) as List<ProductIntegrationSource>;
  428. set => SetValue(GasketMappingsProperty, value);
  429. }
  430. private static readonly DependencyProperty GasketsCheckedProperty = DependencyProperty.Register(
  431. nameof(GasketsChecked),
  432. typeof(bool),
  433. typeof(AWGMappingWindowViewModel),
  434. new FrameworkPropertyMetadata(defaultValue: true, propertyChangedCallback: SectionCheckedChanged)
  435. );
  436. public bool GasketsChecked
  437. {
  438. get => (bool)GetValue(GasketsCheckedProperty);
  439. set => SetValue(GasketsCheckedProperty, value);
  440. }
  441. private static readonly DependencyProperty ComponentMappingsProperty = DependencyProperty.Register(
  442. nameof(ComponentMappings),
  443. typeof(List<ProductIntegrationSource>),
  444. typeof(AWGMappingWindowViewModel)
  445. );
  446. public List<ProductIntegrationSource>? ComponentMappings
  447. {
  448. get => GetValue(ComponentMappingsProperty) as List<ProductIntegrationSource>;
  449. set => SetValue(ComponentMappingsProperty, value);
  450. }
  451. private static readonly DependencyProperty ComponentsCheckedProperty = DependencyProperty.Register(
  452. nameof(ComponentsChecked),
  453. typeof(bool),
  454. typeof(AWGMappingWindowViewModel),
  455. new FrameworkPropertyMetadata(defaultValue: true, propertyChangedCallback: SectionCheckedChanged)
  456. );
  457. public bool ComponentsChecked
  458. {
  459. get => (bool)GetValue(ComponentsCheckedProperty);
  460. set => SetValue(ComponentsCheckedProperty, value);
  461. }
  462. private static readonly DependencyProperty GlassMappingsProperty = DependencyProperty.Register(
  463. nameof(GlassMappings),
  464. typeof(List<ProductIntegrationSource>),
  465. typeof(AWGMappingWindowViewModel)
  466. );
  467. public List<ProductIntegrationSource>? GlassMappings
  468. {
  469. get => GetValue(GlassMappingsProperty) as List<ProductIntegrationSource>;
  470. set => SetValue(GlassMappingsProperty, value);
  471. }
  472. private static readonly DependencyProperty GlassCheckedProperty = DependencyProperty.Register(
  473. nameof(GlassChecked),
  474. typeof(bool),
  475. typeof(AWGMappingWindowViewModel),
  476. new FrameworkPropertyMetadata(defaultValue: true, propertyChangedCallback: SectionCheckedChanged)
  477. );
  478. public bool GlassChecked
  479. {
  480. get => (bool)GetValue(GlassCheckedProperty);
  481. set => SetValue(GlassCheckedProperty, value);
  482. }
  483. private static readonly DependencyProperty LabourMappingsProperty = DependencyProperty.Register(
  484. nameof(LabourMappings),
  485. typeof(List<ActivityIntegrationSource>),
  486. typeof(AWGMappingWindowViewModel)
  487. );
  488. public List<ActivityIntegrationSource>? LabourMappings
  489. {
  490. get => GetValue(LabourMappingsProperty) as List<ActivityIntegrationSource>;
  491. set => SetValue(LabourMappingsProperty, value);
  492. }
  493. private static readonly DependencyProperty LabourCheckedProperty = DependencyProperty.Register(
  494. nameof(LabourChecked),
  495. typeof(bool),
  496. typeof(AWGMappingWindowViewModel),
  497. new FrameworkPropertyMetadata(defaultValue: true, propertyChangedCallback: SectionCheckedChanged)
  498. );
  499. public bool LabourChecked
  500. {
  501. get => (bool)GetValue(LabourCheckedProperty);
  502. set => SetValue(LabourCheckedProperty, value);
  503. }
  504. private static readonly DependencyProperty SectionsProperty = DependencyProperty.Register(
  505. nameof(Sections),
  506. typeof(CoreObservableCollection<KeyValuePair<string, BitmapImage>>),
  507. typeof(AWGMappingWindowViewModel),
  508. new PropertyMetadata(new CoreObservableCollection<KeyValuePair<string, BitmapImage>>())
  509. );
  510. public CoreObservableCollection<KeyValuePair<string, BitmapImage>> Sections
  511. {
  512. get => (CoreObservableCollection<KeyValuePair<string, BitmapImage>>)GetValue(SectionsProperty);
  513. set => SetValue(SectionsProperty, value);
  514. }
  515. private static readonly DependencyProperty SelectedSectionProperty = DependencyProperty.Register(
  516. nameof(SelectedSection),
  517. typeof(KeyValuePair<string, BitmapImage>?),
  518. typeof(AWGMappingWindowViewModel)
  519. );
  520. public KeyValuePair<string, BitmapImage>? SelectedSection
  521. {
  522. get => (KeyValuePair<string, BitmapImage>?)GetValue(SelectedSectionProperty);
  523. set => SetValue(SelectedSectionProperty, value);
  524. }
  525. private static readonly DependencyProperty MappingsCompleteProperty = DependencyProperty.Register(
  526. nameof(MappingsComplete),
  527. typeof(bool),
  528. typeof(AWGMappingWindowViewModel)
  529. );
  530. public bool MappingsComplete
  531. {
  532. get => (bool)GetValue(MappingsCompleteProperty);
  533. set => SetValue(MappingsCompleteProperty, value);
  534. }
  535. private Task<List<TCode>> ExtractMappings<TCode, TType, TEntity, TLink>(
  536. IEnumerable<TType>? items,
  537. Action<TType, TCode>? populate,
  538. Expression<Func<TEntity, object?>> entitycode
  539. )
  540. where TType : IAwgItem
  541. where TCode : BaseIntegrationSource<TEntity, TLink>, IRemotable, IPersistent, new()
  542. where TEntity : Entity, IRemotable, IPersistent, new()
  543. where TLink : EntityLink<TEntity>
  544. {
  545. return Task.Run(() =>
  546. {
  547. var results = new List<TCode>();
  548. if (items == null)
  549. return results;
  550. //var sourceitems = new Dictionary<string, string>();
  551. //foreach (var item in items)
  552. // sourceitems[item.Code] = item.Description;
  553. var keys = items.Select(x => x.Code).Distinct().ToArray();
  554. MultiQuery query = new();
  555. query.Add(
  556. new Filter<TEntity>(entitycode).InList(keys),
  557. Columns.Required<TEntity>().Add(x => x.ID).Add(entitycode)
  558. );
  559. var entitycodecol = $"Entity.{CoreUtils.GetFullPropertyName(entitycode, ".")}";
  560. query.Add(
  561. new Filter<TCode>(x => x.Code).InList(keys),
  562. Columns.Required<TCode>()
  563. .Add(x => x.ID)
  564. .Add(x => x.Code)
  565. .Add(x => x.Entity.ID)
  566. .Add(entitycodecol)
  567. );
  568. query.Query();
  569. var mappings = query.Get<TCode>().ToObjects<TCode>().ToArray();
  570. var entities = query.Get<TEntity>();
  571. foreach (var item in items)
  572. {
  573. var result = new TCode()
  574. {
  575. Code = item.Code,
  576. Description = item.Description
  577. };
  578. populate?.Invoke(item, result);
  579. var mapping = mappings.FirstOrDefault(x => string.Equals(x.Code, item.Code));
  580. if (mapping != null)
  581. result.Entity.CopyFrom(mapping.Entity);
  582. else
  583. {
  584. var entity = entities.Rows.FirstOrDefault(r => Equals(item.Code, r.Get(entitycode)));
  585. if (entity != null)
  586. {
  587. result.Entity.CopyFrom(entity.ToObject<TEntity>());
  588. result.DirectMatch = true;
  589. }
  590. }
  591. results.Add(result);
  592. // result.PropertyChanged += (_, _) =>
  593. // {
  594. // // TMapping mapping = mappingtable.Rows.FirstOrDefault(r =>
  595. // // string.Equals(r.Get<TMapping, String>(c => c.Code), result.Code))?.ToObject<TMapping>();
  596. // // if (mapping == null)
  597. // // mapping = new TMapping() { Code = result.Code };
  598. // // mapping.Entity.ID = result.Entity.ID;
  599. // // new Client<TMapping>().Save(mapping, "Created from BOM Integration Window");
  600. //
  601. // CheckChanged();
  602. // };
  603. }
  604. return results;
  605. });
  606. }
  607. public void CheckChanged()
  608. {
  609. Dispatcher.BeginInvoke(() =>
  610. {
  611. var curSel = SelectedSection?.Key ?? "";
  612. SelectedSection = null;
  613. Sections.Clear();
  614. if (StylesChecked && StyleMappings?.Any() == true)
  615. Sections.Add(new KeyValuePair<string, BitmapImage>("Styles", Resources.palette.AsBitmapImage(64, 64)));
  616. if (GroupsChecked && GroupMappings?.Any() == true)
  617. Sections.Add(
  618. new KeyValuePair<string, BitmapImage>("Groups", Resources.productgroup.AsBitmapImage(64, 64)));
  619. if (SuppliersChecked && SupplierMappings?.Any() == true)
  620. Sections.Add(
  621. new KeyValuePair<string, BitmapImage>("Suppliers", Resources.supplier.AsBitmapImage(64, 64)));
  622. if (DiscountsChecked && DiscountMappings?.Any() == true)
  623. Sections.Add(
  624. new KeyValuePair<string, BitmapImage>("Discounts", Resources.receipt.AsBitmapImage(64, 64)));
  625. if (ProfilesChecked && ProfileMappings?.Any() == true)
  626. Sections.Add(
  627. new KeyValuePair<string, BitmapImage>("Profiles", Resources.profile.AsBitmapImage(64, 64)));
  628. if (GasketsChecked && GasketMappings?.Any() == true)
  629. Sections.Add(new KeyValuePair<string, BitmapImage>("Gaskets", Resources.gasket.AsBitmapImage(64, 64)));
  630. if (ComponentsChecked && ComponentMappings?.Any() == true)
  631. Sections.Add(
  632. new KeyValuePair<string, BitmapImage>("Components", Resources.fixings.AsBitmapImage(64, 64)));
  633. if (GlassChecked && GlassMappings?.Any() == true)
  634. Sections.Add(new KeyValuePair<string, BitmapImage>("Glass", Resources.glass.AsBitmapImage(64, 64)));
  635. if (LabourChecked && LabourMappings?.Any() == true)
  636. Sections.Add(new KeyValuePair<string, BitmapImage>("Labour", Resources.quality.AsBitmapImage(64, 64)));
  637. SelectedSection = Sections.Any(x => string.Equals(x.Key, curSel))
  638. ? Sections.First(x => string.Equals(x.Key, curSel))
  639. : Sections.FirstOrDefault();
  640. var styles = !StylesChecked || (StyleMappings?.Any() != true) || (StyleMappings?.All(x => x.Entity.ID != Guid.Empty) ?? false);
  641. var groups = !GroupsChecked || (GroupMappings?.Any() != true) || (GroupMappings?.All(x => x.Entity.ID != Guid.Empty) ?? false);
  642. var suppliers = !SuppliersChecked || (SupplierMappings?.Any() != true) || (SupplierMappings?.All(x => x.Entity.ID != Guid.Empty) ?? false);
  643. var discounts = !DiscountsChecked || (DiscountMappings?.Any() != true) || (DiscountMappings?.All(x => x.Entity.ID != Guid.Empty) ?? false);
  644. var profiles = !ProfilesChecked || (ProfileMappings?.Any() != true) || (ProfileMappings?.All(x => x.Entity.ID != Guid.Empty) ?? false);
  645. var gaskets = !GasketsChecked || (GasketMappings?.Any() != true) || (GasketMappings?.All(x => x.Entity.ID != Guid.Empty) ?? false);
  646. var components = !ComponentsChecked || (ComponentMappings?.Any() != true) || (ComponentMappings?.All(x => x.Entity.ID != Guid.Empty) ?? false);
  647. var glass = !GlassChecked || (GlassMappings?.Any() != true) || (GlassMappings?.All(x => x.Entity.ID != Guid.Empty) ?? false);
  648. var labour = !LabourChecked || (LabourMappings?.Any() != true) || (LabourMappings?.All(x => x.Entity.ID != Guid.Empty) ?? false);
  649. MappingsComplete = styles && groups && suppliers && discounts && profiles && gaskets && components && glass && labour;
  650. });
  651. }
  652. public ICommand CreateStyle => new ActionCommand(
  653. o =>
  654. {
  655. if (o is IntegrationGridCreateEntityArgs<ProductStyle, ProductStyleIntegrationSource> args)
  656. {
  657. args.Entity.Code = args.Mapping.Code ?? "";
  658. args.Entity.Description = args.Mapping.Description ?? "";
  659. args.Entity.Problem.Notes = ["Created from BOM Integration Window"];
  660. TreatmentTypeLink? type = args.Mapping.StyleType == AwgStyleType.Powdercoated
  661. ? _settings.PowdercoatedType
  662. : args.Mapping.StyleType == AwgStyleType.Anodised
  663. ? _settings.AnodisedType
  664. : args.Mapping.StyleType == AwgStyleType.Varnished
  665. ? _settings.VarnishedType
  666. : args.Mapping.StyleType == AwgStyleType.Taped
  667. ? _settings.TapedType
  668. : null;
  669. if (type != null)
  670. {
  671. args.Entity.TreatmentType.CopyFrom(type);
  672. var product = new Client<Product>().Query(
  673. new Filter<Product>(x => x.Code).IsEqualTo(args.Entity.Code),
  674. Columns.Local<Product>()
  675. ).ToArray<Product>().FirstOrDefault();
  676. if (product == null)
  677. {
  678. product = new Product();
  679. product.Code = args.Entity.Code;
  680. product.Name = args.Entity.Description;
  681. product.Problem.Notes = ["Created from BOM Integration Window"];
  682. product.TreatmentType.CopyFrom(type);
  683. Client.Save(product, "Created from AWG Mapping Window");
  684. }
  685. args.Entity.StockTreatmentProduct.CopyFrom(product);
  686. args.Entity.ManufacturingTreatmentProduct.CopyFrom(product);
  687. }
  688. }
  689. }
  690. );
  691. public ICommand CreateGroup => new ActionCommand(
  692. o =>
  693. {
  694. if (o is IntegrationGridCreateEntityArgs<ProductGroup, ProductGroupIntegrationSource> args)
  695. {
  696. Guid parentid = Guid.Empty;
  697. var parentcodes = args.Mapping.Parent.Split('/').Select(x => x.Trim().ToUpper()).ToArray();
  698. var parents = Client.Query(
  699. new Filter<ProductGroup>(x => x.Code).InList(parentcodes),
  700. Columns.None<ProductGroup>().Add(x => x.ID).Add(x => x.Code)
  701. ).ToArray<ProductGroup>();
  702. foreach (var parentcode in parentcodes)
  703. {
  704. var parent = parents.FirstOrDefault(x => Equals(x.Code,parentcode));
  705. if (parent == null)
  706. {
  707. parent = new ProductGroup();
  708. parent.Code = parentcode;
  709. parent.Description = parentcode.Titleize();
  710. parent.Parent.ID = parentid;
  711. parent.Problem.Notes = ["Created from BOM Integration Window"];
  712. Client.Save(parent, "Created from AWG Mapping Window");
  713. }
  714. parentid = parent.ID;
  715. }
  716. args.Entity.Parent.ID = parentid;
  717. args.Entity.Code = args.Mapping.Code ?? "";
  718. args.Entity.Description = args.Mapping.Description ?? "";
  719. args.Entity.Problem.Notes = ["Created from BOM Integration Window"];
  720. }
  721. }
  722. );
  723. public ICommand CreateSupplier => new ActionCommand(
  724. o =>
  725. {
  726. if (o is IntegrationGridCreateEntityArgs<Supplier, SupplierIntegrationSource> args)
  727. {
  728. args.Entity.Code = args.Mapping.Code ?? "";
  729. args.Entity.Name = args.Mapping.Description ?? "";
  730. args.Entity.Problem.Notes = ["Created from BOM Integration Window"];
  731. }
  732. }
  733. );
  734. public ICommand CreateDiscount => new ActionCommand(
  735. o =>
  736. {
  737. if (o is IntegrationGridCreateEntityArgs<SupplierDiscountGroup, SupplierDiscountGroupIntegrationSource> args)
  738. {
  739. args.Entity.Code = args.Mapping.Code ?? "";
  740. args.Entity.Description = args.Mapping.Description ?? "";
  741. args.Entity.Type = SupplierDiscountGroupType.Discount;
  742. var supplier = SupplierMappings.FirstOrDefault(x => string.Equals(x.Code, args.Mapping.Supplier))?.Entity.ID;
  743. if (supplier == null)
  744. supplier = new Client<Supplier>()
  745. .Query(new Filter<Supplier>(x => x.Code).IsEqualTo(args.Entity.Code),
  746. Columns.None<Supplier>().Add(x => x.ID))
  747. .ToArray<Supplier>()
  748. .FirstOrDefault()?.ID;
  749. if (supplier == null)
  750. throw new Exception($"Unable to locate Supplier [{args.Mapping.Supplier}]");
  751. args.Entity.Supplier.ID = supplier.Value;
  752. args.Entity.Problem.Notes = ["Created from BOM Integration Window"];
  753. }
  754. }
  755. );
  756. public ICommand AfterCreateDiscount => new ActionCommand(
  757. o =>
  758. {
  759. if (o is IntegrationGridCreateEntityArgs<SupplierDiscountGroup, SupplierDiscountGroupIntegrationSource> args)
  760. {
  761. CreateSupplierDiscountInstance(args);
  762. }
  763. }
  764. );
  765. private void CreateSupplierDiscountInstance(IntegrationGridCreateEntityArgs<SupplierDiscountGroup, SupplierDiscountGroupIntegrationSource> args)
  766. {
  767. var discount = new SupplierDiscount();
  768. discount.Group.CopyFrom(args.Entity);
  769. discount.Value = args.Mapping.Discount;
  770. discount.Job.ID = Guid.Empty;
  771. Client.Save(discount, "Created from AWG Mapping Window");
  772. }
  773. public ICommand CreateProfile => new ActionCommand(
  774. o =>
  775. {
  776. if (o is IntegrationGridCreateEntityArgs<Product, ProductIntegrationSource> args)
  777. {
  778. args.Entity.Code = args.Mapping.Code ?? "";
  779. args.Entity.Name = args.Mapping.Description ?? "";
  780. args.Entity.UnitOfMeasure.CopyFrom(_settings.ProfileUom);
  781. var group = GroupMappings?.FirstOrDefault(x => Equals(x.Code, args.Mapping.Group));
  782. if (group != null)
  783. args.Entity.Group.CopyFrom(group.Entity);
  784. args.Entity.Problem.Notes = ["Created from BOM Integration Window"];
  785. CreateImage(args);
  786. }
  787. }
  788. );
  789. public ICommand AfterCreateProduct => new ActionCommand(
  790. o =>
  791. {
  792. if (o is IntegrationGridCreateEntityArgs<Product, ProductIntegrationSource> args)
  793. {
  794. CreateTreatmentParams(args, AwgStyleType.Powdercoated, Settings.PowdercoatedType);
  795. CreateTreatmentParams(args, AwgStyleType.Anodised, Settings.AnodisedType);
  796. CreateTreatmentParams(args, AwgStyleType.Taped, Settings.TapedType);
  797. CreateTreatmentParams(args, AwgStyleType.Varnished, Settings.VarnishedType);
  798. CreateSupplierProduct(args);
  799. }
  800. }
  801. );
  802. private void CreateImage(IntegrationGridCreateEntityArgs<Product, ProductIntegrationSource> args)
  803. {
  804. if (!string.IsNullOrWhiteSpace(_settings.ImageUrl))
  805. {
  806. var model = new LogikalCodeModel() { Code = args.Mapping.Code };
  807. var _expression = new CoreExpression<LogikalCodeModel, string>(_settings.ImageUrl);
  808. if (_expression.Evaluate(model).Get(out var eval, out var e))
  809. {
  810. var tcs = new TaskCompletionSource<byte[]>();
  811. new HttpClient().GetByteArrayAsync(eval)
  812. .ContinueWith(
  813. t =>
  814. {
  815. if (t.IsFaulted)
  816. tcs.SetException(t.Exception);
  817. else
  818. tcs.SetResult(t.Result);
  819. });
  820. try
  821. {
  822. var data = tcs.Task.Result;
  823. var document = new Document()
  824. {
  825. Data = tcs.Task.Result,
  826. CRC = CoreUtils.CalculateCRC(data),
  827. FileName = args.Mapping.Code
  828. };
  829. Client.Save(document,"Created from AWG Mapping Window");
  830. args.Entity.Image.ID = document.ID;
  831. }
  832. catch (Exception exception)
  833. {
  834. Logger.Send(LogType.Error,"",$"Exception in CreateImage(): {exception.Message}");
  835. }
  836. }
  837. }
  838. }
  839. private void CreateTreatmentParams(IntegrationGridCreateEntityArgs<Product, ProductIntegrationSource> args, AwgStyleType type, TreatmentTypeLink link)
  840. {
  841. if (args.Mapping.TreatmentParameters.ContainsKey(type) && !Equals(link.ID,Guid.Empty))
  842. {
  843. ProductTreatment treatment = new();
  844. treatment.Product.CopyFrom(args.Entity);
  845. treatment.TreatmentType.CopyFrom(link);
  846. treatment.Parameter = args.Mapping.TreatmentParameters[type];
  847. Client.Save(treatment,"Created from AWG Mapping Window");
  848. }
  849. }
  850. private void CreateSupplierProduct(IntegrationGridCreateEntityArgs<Product, ProductIntegrationSource> args)
  851. {
  852. var supplier = SupplierMappings?.FirstOrDefault(x => Equals(x.Code, args.Mapping.Supplier));
  853. if (supplier != null)
  854. {
  855. SupplierProduct sp = new SupplierProduct();
  856. sp.Product.ID = args.Entity.ID;
  857. sp.SupplierLink.ID = supplier.Entity.ID;
  858. sp.SupplierCode = args.Mapping.Code;
  859. sp.SupplierDescription = args.Mapping.Description;
  860. sp.Dimensions.CopyFrom(args.Mapping.Dimensions);
  861. var style = StyleMappings?.FirstOrDefault(x => Equals(x.Code, args.Mapping.Style));
  862. if (style != null)
  863. sp.Style.CopyFrom(style.Entity);
  864. sp.TradePrice = args.Mapping.Cost; // * (args.Mapping.Quantity.IsEffectivelyEqual(0.0) ? 1.0 : args.Mapping.Dimensions.Quantity);
  865. Client.Save(sp,"Created from AWG Mapping Window");
  866. }
  867. }
  868. public ICommand CreateGasket => new ActionCommand(
  869. o =>
  870. {
  871. if (o is IntegrationGridCreateEntityArgs<Product, ProductIntegrationSource> args)
  872. {
  873. args.Entity.Code = args.Mapping.Code ?? "";
  874. args.Entity.Name = args.Mapping.Description ?? "";
  875. args.Entity.UnitOfMeasure.CopyFrom(_settings.GasketUom);
  876. var group = GroupMappings?.FirstOrDefault(x => Equals(x.Code, args.Mapping.Group));
  877. if (group != null)
  878. args.Entity.Group.CopyFrom(group.Entity);
  879. args.Entity.Problem.Notes = ["Created from BOM Integration Window"];
  880. }
  881. }
  882. );
  883. public ICommand CreateComponent => new ActionCommand(
  884. o =>
  885. {
  886. if (o is IntegrationGridCreateEntityArgs<Product, ProductIntegrationSource> args)
  887. {
  888. args.Entity.Code = args.Mapping.Code ?? "";
  889. args.Entity.Name = args.Mapping.Description ?? "";
  890. args.Entity.UnitOfMeasure.CopyFrom(_settings.ComponentUom);
  891. var group = GroupMappings?.FirstOrDefault(x => Equals(x.Code, args.Mapping.Group));
  892. if (group != null)
  893. args.Entity.Group.CopyFrom(group.Entity);
  894. args.Entity.Problem.Notes = ["Created from BOM Integration Window"];
  895. }
  896. }
  897. );
  898. public ICommand CreateGlass => new ActionCommand(
  899. o =>
  900. {
  901. if (o is IntegrationGridCreateEntityArgs<Product, ProductIntegrationSource> args)
  902. {
  903. args.Entity.Code = args.Mapping.Code ?? "";
  904. args.Entity.Name = args.Mapping.Description ?? "";
  905. args.Entity.UnitOfMeasure.CopyFrom(_settings.GlassUom);
  906. var group = GroupMappings?.FirstOrDefault(x => Equals(x.Code, args.Mapping.Group));
  907. if (group != null)
  908. args.Entity.Group.CopyFrom(group.Entity);
  909. args.Entity.Problem.Notes = ["Created from BOM Integration Window"];
  910. }
  911. }
  912. );
  913. public ICommand CreateActivity => new ActionCommand(
  914. o =>
  915. {
  916. if (o is IntegrationGridCreateEntityArgs<Activity, ActivityIntegrationSource> args)
  917. {
  918. args.Entity.Code = args.Mapping.Code ?? "";
  919. args.Entity.Description = args.Mapping.Description ?? "";
  920. args.Entity.Problem.Notes = ["Created from BOM Integration Window"];
  921. }
  922. }
  923. );
  924. private class RawDimensions : IBaseDimensions
  925. {
  926. public double Quantity { get; set; }
  927. public double Length { get; set; }
  928. public double Width { get; set; }
  929. public double Height { get; set; }
  930. public double Weight { get; set; }
  931. }
  932. public void GetDiscounts(Action<SupplierDiscountGroupLink, double>? discountCallback)
  933. {
  934. if (DiscountsChecked && Discounts != null)
  935. {
  936. foreach (var discount in Discounts)
  937. {
  938. var discountmapping = DiscountMappings?.FirstOrDefault(x => x.Code == discount.Code);
  939. if (discountmapping != null && discountCallback != null)
  940. discountCallback?.Invoke(discountmapping.Entity,discountmapping.Discount);
  941. }
  942. }
  943. }
  944. public void GetParts(
  945. Action<ProductLink, ProductStyleLink?, IBaseDimensions, double, double>? productCallback,
  946. Action<ActivityLink, TimeSpan, double>? labourCallback)
  947. {
  948. GetParts(Profiles,Gaskets,Components,Glass,Labour,productCallback,labourCallback);
  949. }
  950. public void GetParts<TProfile, TGasket, TComponent, TGlass, TLabour>(
  951. IEnumerable<TProfile>? profiles,
  952. IEnumerable<TGasket>? gaskets,
  953. IEnumerable<TComponent>? components,
  954. IEnumerable<TGlass>? glasses,
  955. IEnumerable<TLabour>? labour,
  956. Action<ProductLink, ProductStyleLink?, IBaseDimensions, double, double>? productCallback,
  957. Action<ActivityLink, TimeSpan, double>? labourCallback)
  958. where TProfile : IAwgProfile
  959. where TGasket : IAwgGasket
  960. where TComponent : IAwgComponent
  961. where TGlass : IAwgGlass
  962. where TLabour : IAwgLabour
  963. {
  964. if (ProfilesChecked && profiles != null)
  965. {
  966. foreach (var profile in profiles)
  967. {
  968. var profilemapping = ProfileMappings?.FirstOrDefault(x => x.Code == profile.Code);
  969. var stylemapping = StyleMappings?.FirstOrDefault(x => string.Equals(x.Code, profile.Finish));
  970. if (profilemapping != null && productCallback is not null)
  971. {
  972. productCallback(
  973. profilemapping.Entity,
  974. stylemapping?.Entity,
  975. new RawDimensions() { Length = profile.Length },
  976. profile.Quantity,
  977. profile.Cost * profile.Quantity);
  978. }
  979. }
  980. }
  981. if (GasketsChecked && gaskets != null)
  982. {
  983. foreach (var gasket in gaskets)
  984. {
  985. var _mapping = GasketMappings?.FirstOrDefault(x => x.Code == gasket.Code);
  986. if (_mapping != null && productCallback is not null)
  987. {
  988. _mapping.ConvertDimensions(
  989. x => x.Dimensions,
  990. x => x.Quantity,
  991. x => x.Cost,
  992. Client<ProductDimensionUnit>.Provider
  993. );
  994. productCallback(
  995. _mapping.Entity,
  996. null,
  997. new RawDimensions() { Length = _mapping.Dimensions.Length },
  998. _mapping.Quantity,
  999. _mapping.Quantity * _mapping.Cost);
  1000. }
  1001. }
  1002. }
  1003. if (ComponentsChecked && components != null)
  1004. {
  1005. foreach (var component in components)
  1006. {
  1007. var _mapping = ComponentMappings?.FirstOrDefault(x => string.Equals(x.Code, component.Code));
  1008. if (_mapping != null && productCallback is not null)
  1009. {
  1010. _mapping.ConvertDimensions(
  1011. x => x.Dimensions,
  1012. x => x.Quantity,
  1013. x => x.Cost,
  1014. Client<ProductDimensionUnit>.Provider
  1015. );
  1016. productCallback(
  1017. _mapping.Entity,
  1018. null,
  1019. new RawDimensions() { Quantity = _mapping.Dimensions.Quantity },
  1020. _mapping.Quantity,
  1021. _mapping.Quantity * _mapping.Cost);
  1022. }
  1023. }
  1024. }
  1025. if (GlassChecked && glasses != null)
  1026. {
  1027. foreach (var glass in glasses)
  1028. {
  1029. var _mapping = GlassMappings?.FirstOrDefault(x => string.Equals(x.Code, glass.Code));
  1030. if (_mapping != null && productCallback is not null)
  1031. {
  1032. productCallback(
  1033. _mapping.Entity,
  1034. null,
  1035. new RawDimensions() { Height = glass.Height, Width = glass.Width },
  1036. glass.Quantity,
  1037. glass.Quantity * glass.Cost);
  1038. }
  1039. }
  1040. }
  1041. if (LabourChecked && labour != null)
  1042. {
  1043. foreach (var activity in labour)
  1044. {
  1045. var _mapping = LabourMappings?.FirstOrDefault(x => string.Equals(x.Code, activity.Code));
  1046. if (_mapping != null && labourCallback is not null)
  1047. {
  1048. labourCallback(
  1049. _mapping.Entity,
  1050. TimeSpan.FromHours(activity.Quantity),
  1051. activity.Quantity * activity.Cost);
  1052. }
  1053. }
  1054. }
  1055. }
  1056. }