JobOrderGrid.cs 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using System;
  2. using System.Linq;
  3. using System.Threading;
  4. using Comal.Classes;
  5. using InABox.Core;
  6. using InABox.DynamicGrid;
  7. using InABox.Wpf;
  8. namespace PRSDesktop
  9. {
  10. public class JobOrderGrid : DynamicDataGrid<PurchaseOrderItem>, IMasterDetailControl<Job,PurchaseOrderItem>, IDataModelSource
  11. {
  12. public Job? Master { get; set; }
  13. public Filter<PurchaseOrderItem> MasterDetailFilter => (Master?.ID ?? Guid.Empty) != Guid.Empty
  14. ? new Filter<PurchaseOrderItem>(x => x.Job.ID).IsEqualTo(Master.ID)
  15. : new Filter<PurchaseOrderItem>().None();
  16. public JobOrderGrid()
  17. {
  18. ColumnsTag = "JobOrders";
  19. HiddenColumns.Add(x => x.PurchaseOrderLink.SupplierLink.ID);
  20. HiddenColumns.Add(x => x.PurchaseOrderLink.Category.ID);
  21. HiddenColumns.Add(x => x.ID);
  22. HiddenColumns.Add(x => x.Product.ID);
  23. HiddenColumns.Add(x => x.Product.Code);
  24. HiddenColumns.Add(x => x.Product.Name);
  25. HiddenColumns.Add(x => x.Description);
  26. HiddenColumns.Add(x => x.TaxCode.ID);
  27. HiddenColumns.Add(x => x.TaxCode.Code);
  28. HiddenColumns.Add(x => x.TaxCode.Description);
  29. HiddenColumns.Add(x => x.TaxCode.Rate);
  30. HiddenColumns.Add(x => x.TaxRate);
  31. HiddenColumns.Add(x => x.ExTax);
  32. HiddenColumns.Add(x => x.Tax);
  33. HiddenColumns.Add(x => x.IncTax);
  34. HiddenColumns.Add(x => x.BillLine.ID);
  35. HiddenColumns.Add(x => x.Consignment.ID);
  36. HiddenColumns.Add(x => x.Product.DigitalForm.ID);
  37. HiddenColumns.Add(x => x.Product.DigitalForm.Description);
  38. HiddenColumns.Add(x => x.PurchaseOrderLink.SupplierLink.Code);
  39. HiddenColumns.Add(x => x.PurchaseOrderLink.SupplierLink.Name);
  40. }
  41. protected override void DoReconfigure(DynamicGridOptions options)
  42. {
  43. base.DoReconfigure(options);
  44. options.RecordCount = true;
  45. options.SelectColumns = true;
  46. options.FilterRows = true;
  47. options.MultiSelect = true;
  48. options.ExportData = true;
  49. }
  50. public event DataModelUpdateEvent? OnUpdateDataModel;
  51. public string SectionName => "Job Orders";
  52. public DataModel DataModel(Selection selection)
  53. {
  54. var ids = ExtractValues(x => x.ID, selection).ToArray();
  55. return new BaseDataModel<PurchaseOrderItem>(new Filter<PurchaseOrderItem>(x => x.ID).InList(ids));
  56. }
  57. protected override void Reload(
  58. Filters<PurchaseOrderItem> criteria, Columns<PurchaseOrderItem> columns, ref SortOrder<PurchaseOrderItem>? sort,
  59. CancellationToken token, Action<CoreTable?, Exception?> action)
  60. {
  61. criteria.Add(MasterDetailFilter);
  62. base.Reload(criteria, columns, ref sort, token, action);
  63. }
  64. }
  65. }