ConsignmentParcelGrid.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. public class ConsignmentParcelGrid : DynamicDataGrid<ConsignmentParcel>
  10. {
  11. public Guid ConsignmentID { get; set; }
  12. public bool Completed { get; set; }
  13. protected override DynamicGridColumns LoadColumns()
  14. {
  15. var columns = new DynamicGridColumns();
  16. columns.Add<ConsignmentParcel>(x => x.Description, 0, "Parcels", "", Alignment.MiddleLeft);
  17. return columns;
  18. }
  19. protected override void Reload(
  20. Filters<ConsignmentParcel> criteria, Columns<ConsignmentParcel> columns, ref SortOrder<ConsignmentParcel>? sort,
  21. CancellationToken token, Action<CoreTable?, Exception?> action)
  22. {
  23. criteria.Add(Filter<ConsignmentParcel>.Where(x => x.Consignment.ID).IsEqualTo(ConsignmentID));
  24. base.Reload(criteria, columns, ref sort, token, (table,exception) =>
  25. {
  26. if ((ConsignmentID != CoreUtils.FullGuid) && (table != null))
  27. {
  28. var row = table.NewRow();
  29. row.Set<ConsignmentParcel, Guid>(x => x.ID, CoreUtils.FullGuid);
  30. row.Set<ConsignmentParcel, string>(x => x.Description, "(All Items)");
  31. table.Rows.Insert(0, row);
  32. row = table.NewRow();
  33. row.Set<ConsignmentParcel, Guid>(x => x.ID, Guid.Empty);
  34. row.Set<ConsignmentParcel, string>(x => x.Description, "(Unallocated Items)");
  35. table.Rows.Add(row);
  36. }
  37. action(table,exception);
  38. });
  39. }
  40. protected override bool CanCreateItems()
  41. {
  42. if (ConsignmentID == Guid.Empty)
  43. {
  44. MessageWindow.ShowMessage("Please select a Consignment first!", "Error");
  45. return false;
  46. }
  47. if (Completed)
  48. {
  49. MessageWindow.ShowMessage("Cannot Modify a Completed Requisition!", "Error");
  50. return false;
  51. }
  52. return base.CanCreateItems();
  53. }
  54. public override ConsignmentParcel CreateItem()
  55. {
  56. var item = base.CreateItem();
  57. item.Consignment.ID = ConsignmentID;
  58. return item;
  59. }
  60. protected override void DoEdit()
  61. {
  62. Guid id = SelectedRows.FirstOrDefault()?.Get<ConsignmentParcel, Guid>(x => x.ID) ?? Guid.Empty;
  63. if ((id == CoreUtils.FullGuid) || (id == Guid.Empty))
  64. MessageWindow.ShowMessage("You cannot edit this item!", "Error");
  65. else
  66. base.DoEdit();
  67. }
  68. }