DeliveryRackList.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. using System;
  2. using System.Linq;
  3. using System.Windows;
  4. using Comal.Classes;
  5. using InABox.Clients;
  6. using InABox.Core;
  7. using InABox.DynamicGrid;
  8. using InABox.WPF;
  9. namespace PRSDesktop
  10. {
  11. internal class DeliveryRackList : DynamicDataGrid<Shipment>
  12. {
  13. public DeliveryRackList()
  14. {
  15. Options.AddRange(DynamicGridOption.RecordCount, DynamicGridOption.AddRows, DynamicGridOption.DeleteRows, DynamicGridOption.SelectColumns);
  16. HiddenColumns.Add(x => x.Delivery.ID);
  17. ColumnsTag = "DeliveryRack";
  18. }
  19. public Guid JobID { get; set; }
  20. public Guid DeliveryID { get; set; }
  21. public DateTime Completed { get; set; }
  22. protected override DynamicGridColumns LoadColumns()
  23. {
  24. var columns = new DynamicGridColumns
  25. {
  26. new() { ColumnName = "Code", Width = 40, Caption = "Rack", Alignment = Alignment.MiddleCenter },
  27. new() { ColumnName = "Description", Width = 0, Caption = "Description" },
  28. new() { ColumnName = "ItemCount", Width = 25, Caption = "#", Alignment = Alignment.MiddleCenter }
  29. };
  30. return columns;
  31. }
  32. protected override void DoAdd(bool OpenEditorOnDirectEdit = false)
  33. {
  34. if (DeliveryID == Guid.Empty)
  35. {
  36. MessageBox.Show("Please select a Delivery First");
  37. return;
  38. }
  39. if (!Completed.IsEmpty())
  40. {
  41. MessageBox.Show("You cannot modify a completed delivery!");
  42. return;
  43. }
  44. var grid = new MultiSelectDialog<Shipment>(
  45. new Filter<Shipment>(x => x.Delivery).NotLinkValid(),
  46. null
  47. );
  48. if (grid.ShowDialog())
  49. {
  50. Progress.Show("Adding Racks to Delivery");
  51. var shipments = grid.Items();
  52. var filter = new Filter<DeliveryItem>(x => x.ID).IsEqualTo(CoreUtils.FullGuid);
  53. foreach (var shipment in shipments)
  54. {
  55. filter = filter.Or(x => x.ShipmentLink.ID).IsEqualTo(shipment.ID);
  56. shipment.Delivery.ID = DeliveryID;
  57. }
  58. var items = new Client<DeliveryItem>().Load(filter);
  59. foreach (var item in items)
  60. item.Delivery.ID = DeliveryID;
  61. new Client<DeliveryItem>().Save(items, "Added to Delivery");
  62. new Client<Shipment>().Save(shipments, "Added to Delivery");
  63. DoChanged();
  64. Progress.Close();
  65. }
  66. }
  67. protected override void DeleteItems(params CoreRow[] rows)
  68. {
  69. if (rows == null || !rows.Any())
  70. {
  71. MessageBox.Show("Please select a row first");
  72. return;
  73. }
  74. if (!Completed.IsEmpty())
  75. {
  76. MessageBox.Show("You cannot modify a completed delivery!");
  77. return;
  78. }
  79. Progress.Show("Removing Items from Delivery");
  80. DeliveryItem[] items = { };
  81. foreach (var row in rows)
  82. {
  83. var rackid = row.Get<Shipment, Guid>(x => x.ID);
  84. items = new Client<DeliveryItem>().Load(new Filter<DeliveryItem>(x => x.ShipmentLink.ID).IsEqualTo(rackid));
  85. var shipment = new Client<Shipment>().Load(new Filter<Shipment>(x => x.ID).IsEqualTo(rackid)).FirstOrDefault();
  86. if (shipment != null)
  87. {
  88. shipment.Delivery.ID = Guid.Empty;
  89. new Client<Shipment>().Save(shipment, "Removed from Delivery");
  90. }
  91. if (items.Any())
  92. {
  93. foreach (var item in items)
  94. item.Delivery.ID = Guid.Empty;
  95. new Client<DeliveryItem>().Save(items, "Removed From Delivery");
  96. }
  97. }
  98. DoChanged();
  99. Progress.Close();
  100. }
  101. protected override void Reload(Filters<Shipment> criteria, Columns<Shipment> columns, ref SortOrder<Shipment> sort,
  102. Action<CoreTable, Exception> action)
  103. {
  104. if (DeliveryID != Guid.Empty)
  105. criteria.Add(new Filter<Shipment>(x => x.Delivery.ID).IsEqualTo(DeliveryID));
  106. base.Reload(criteria, columns, ref sort, action);
  107. }
  108. }
  109. }