ShipmentGrid.cs 4.4 KB

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