ShipmentGrid.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. using System;
  2. using System.Drawing;
  3. using System.Linq;
  4. using System.Windows.Controls;
  5. using Comal.Classes;
  6. using InABox.Clients;
  7. using InABox.Core;
  8. using InABox.DynamicGrid;
  9. using InABox.Reports;
  10. using InABox.Core.Reports;
  11. using InABox.Wpf.Reports;
  12. using InABox.WPF;
  13. namespace PRSDesktop
  14. {
  15. public class ShipmentGrid : DynamicDataGrid<Shipment>
  16. {
  17. private bool bShowAll = true;
  18. private ReportTemplate template;
  19. public ShipmentGrid()
  20. {
  21. ActionColumns.Add(new DynamicMapColumn<Shipment>(this, x => x.TrackerLink.Location));
  22. HiddenColumns.Add(x => x.BarCode);
  23. HiddenColumns.Add(x => x.ItemCount);
  24. HiddenColumns.Add(x => x.Delivery.ID);
  25. //ActionColumns.Add(new DynamicImageColumn() { Action = DeliveryDocketClick, Image = (o) => PRSDesktop.Resources.printer.AsBitmapImage() });
  26. AddButton("Hide Empty", PRSDesktop.Resources.target.AsBitmapImage(Color.White), ToggleVisible);
  27. //AddButton("", PRSDesktop.Resources.barcode.AsBitmapImage(), PrintBarcodeClick);
  28. }
  29. protected override void DoReconfigure(FluentList<DynamicGridOption> options)
  30. {
  31. base.DoReconfigure(options);
  32. options.AddRange(DynamicGridOption.RecordCount, DynamicGridOption.SelectColumns);
  33. }
  34. public Guid CurrentShipmentID { get; set; }
  35. protected override void SelectItems(CoreRow[] rows)
  36. {
  37. CurrentShipmentID = rows.Any() ? rows.First().Get<Shipment, Guid>(x => x.ID) : Guid.Empty;
  38. base.SelectItems(rows);
  39. }
  40. protected override bool FilterRecord(CoreRow row)
  41. {
  42. if (bShowAll)
  43. return true;
  44. if (row.Get<Shipment, int>(x => x.ItemCount) > 0)
  45. return true;
  46. if (row.Get<Shipment, Guid>(x => x.ID) == CurrentShipmentID)
  47. return true;
  48. return false;
  49. }
  50. private bool ToggleVisible(Button sender, CoreRow[] rows)
  51. {
  52. if (bShowAll)
  53. {
  54. UpdateButton(sender, PRSDesktop.Resources.target.AsBitmapImage(Color.White), "Show All");
  55. bShowAll = false;
  56. }
  57. else
  58. {
  59. UpdateButton(sender, PRSDesktop.Resources.target.AsBitmapImage(Color.White), "Hide Empty");
  60. bShowAll = true;
  61. }
  62. return true;
  63. }
  64. protected override void Reload(Filters<Shipment> criteria, Columns<Shipment> columns, ref SortOrder<Shipment>? sort, Action<CoreTable?, Exception?> action)
  65. {
  66. sort = new SortOrder<Shipment>(x => x.Code);
  67. base.Reload(criteria, columns, ref sort, action);
  68. }
  69. private bool DeliveryDocketClick(CoreRow row)
  70. {
  71. var id = row.Get<Shipment, Guid>(x => x.ID);
  72. var model = new ShipmentDataModel(new Filter<Shipment>(x => x.ID).IsEqualTo(id));
  73. var client = new Client<ReportTemplate>();
  74. template = client.Load(
  75. new Filter<ReportTemplate>(x => x.Section).IsEqualTo("Rack List").And(x => x.Name).IsEqualTo("Delivery Docket"),
  76. new SortOrder<ReportTemplate>(x => x.Name)
  77. ).FirstOrDefault();
  78. if (template == null)
  79. template = new ReportTemplate { DataModel = model.Name, Section = "Rack List", Name = "Delivery Docket" };
  80. ReportUtils.PreviewReport(template, model, false, Security.IsAllowed<CanDesignReports>());
  81. return false;
  82. }
  83. //private bool PrintBarcodeClick(Button btn, CoreRow[] rows)
  84. //{
  85. // if (rows.Length != 1)
  86. // {
  87. // MessageBox.Show("Please select a Rack first!");
  88. // return false;
  89. // }
  90. // CoreRow row = rows.First();
  91. // Guid id = row.Get<Shipment, Guid>(x => x.ID);
  92. // ShipmentDataModel model = new ShipmentDataModel(new Filter<Shipment>(x => x.ID).IsEqualTo(id));
  93. // Client<ReportTemplate> client = new Client<ReportTemplate>();
  94. // template = client.Load(
  95. // new Filter<ReportTemplate>(x => x.Section).IsEqualTo("Rack List").And(x => x.Name).IsEqualTo("Bar Code"),
  96. // new SortOrder<ReportTemplate>(x => x.Name)
  97. // ).FirstOrDefault();
  98. // if (template == null)
  99. // template = new ReportTemplate() { Section = "Rack List", Name = "Bar Code" };
  100. // ReportUtils.PreviewReport(template, model, false, Security.IsAllowed<CanDesignReports>());
  101. // return false;
  102. //}
  103. }
  104. }