ShipmentGrid.cs 4.4 KB

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