AWGMappingWindowViewModel.cs 47 KB

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