SupplierPurchaseOrderItemOneToMany.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Windows;
  5. using System.Windows.Controls;
  6. using Comal.Classes;
  7. using FastReport.DevComponents.WinForms.Drawing;
  8. using InABox.Core;
  9. using InABox.DynamicGrid;
  10. namespace PRSDesktop
  11. {
  12. public class SupplierPurchaseOrderItemOneToMany : DynamicOneToManyGrid<PurchaseOrder,PurchaseOrderItem>
  13. {
  14. private readonly Button bill;
  15. public SupplierPurchaseOrderItemOneToMany() : base()
  16. {
  17. HiddenColumns.Add(x => x.BillLine.ID);
  18. HiddenColumns.Add(x => x.BillLine.Deleted);
  19. bill = AddButton("Enter Bill", null, SupplierPurchaseOrderItems.EnterBill);
  20. bill.IsEnabled = false;
  21. }
  22. protected override void SelectItems(CoreRow[]? rows)
  23. {
  24. bill.IsEnabled =
  25. rows != null
  26. && !rows.Any(r => r.IsEntityLinkValid<PurchaseOrderItem, BillLineLink>(x => x.BillLine));
  27. base.SelectItems(rows);
  28. }
  29. protected override void OnAfterEditorValueChanged(DynamicEditorGrid grid, PurchaseOrderItem[] items, string columnnname, Dictionary<string, object?> changes)
  30. {
  31. base.OnAfterEditorValueChanged(grid, items, columnnname, changes);
  32. if (columnnname.Equals("Product.ID") || columnnname.Equals("Job.ID") || columnnname.StartsWith("Dimensions."))
  33. {
  34. PurchaseOrder.UpdateCosts(
  35. items,
  36. Item.SupplierLink.ID,
  37. changes
  38. );
  39. }
  40. }
  41. protected override Dictionary<string, object?> EditorValueChanged(IDynamicEditorForm editor, PurchaseOrderItem[] items, string name,
  42. object value)
  43. {
  44. var results = base.EditorValueChanged(editor, items, name, value);
  45. if (name.Equals("ProductLink.TaxCode.ID"))
  46. DynamicGridUtils.UpdateEditorValue(items, "TaxCode.ID", (Guid)value, results);
  47. return results;
  48. }
  49. }
  50. }