ConsignmentsGrid.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. using System;
  2. using System.Diagnostics;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Windows;
  6. using System.Windows.Media.Imaging;
  7. using Comal.Classes;
  8. using InABox.Clients;
  9. using InABox.Core;
  10. using InABox.DynamicGrid;
  11. using InABox.WPF;
  12. namespace PRSDesktop
  13. {
  14. internal class ConsignmentGrid : DynamicDataGrid<Consignment>
  15. {
  16. //Button receive = null;
  17. public ConsignmentGrid()
  18. {
  19. ActionColumns.Add(new DynamicImageColumn(ConsignmentImage, ShowBillOfLading) { Position = DynamicActionColumnPosition.Start });
  20. HiddenColumns.Add(x => x.BillOfLading.ID);
  21. HiddenColumns.Add(x => x.Closed);
  22. HiddenColumns.Add(x => x.Supplier.Code);
  23. }
  24. protected override void DoReconfigure(FluentList<DynamicGridOption> options)
  25. {
  26. base.DoReconfigure(options);
  27. options.AddRange(DynamicGridOption.RecordCount, DynamicGridOption.SelectColumns, DynamicGridOption.FilterRows);
  28. }
  29. public bool ShowAll { get; set; }
  30. public Guid SelectedCategory { get; set; }
  31. public Guid SelectedType { get; set; }
  32. //private bool ReceiveConsignment(Button sender, CoreRow[] rows)
  33. //{
  34. // if (!rows.Any())
  35. // {
  36. // MessageBox.Show("Please select a row first");
  37. // return false;
  38. // }
  39. // if (!rows.First().Get<Consignment, DateTime>(x => x.Closed).IsEmpty())
  40. // {
  41. // MessageBox.Show("Consignment is already closed!");
  42. // return false;
  43. // }
  44. // Guid id = rows.First().Get<Consignment, Guid>(x => x.ID);
  45. // DateTime now = DateTime.Now;
  46. // using (new WaitCursor())
  47. // {
  48. // PurchaseOrderItem[] items = new Client<PurchaseOrderItem>().Load(new Filter<PurchaseOrderItem>(x => x.Consignment.ID).IsEqualTo(id).And(x => x.ReceivedDate).IsEqualTo(DateTime.MinValue));
  49. // foreach (var item in items)
  50. // item.ReceivedDate = now;
  51. // new Client<PurchaseOrderItem>().Save(items, "Consignment Received");
  52. // //Consignment consignment = LoadItem(rows.First());
  53. // //consignment.Closed = now;
  54. // //new Client<Consignment>().Save(consignment, "Consignment Received");
  55. // }
  56. // return true;
  57. //}
  58. //protected override void SelectItems(CoreRow[] rows)
  59. //{
  60. // receive.IsEnabled = (rows != null) && rows.Any(r=>r.Get<Consignment, DateTime>(c => c.Closed).IsEmpty());
  61. // base.SelectItems(rows);
  62. //}
  63. protected override void Reload(Filters<Consignment> criteria, Columns<Consignment> columns, ref SortOrder<Consignment>? sort,
  64. Action<CoreTable?, Exception?> action)
  65. {
  66. if (!ShowAll)
  67. criteria.Add(new Filter<Consignment>(x => x.ActualWarehouseArrival).IsEqualTo(DateTime.MinValue));
  68. if (SelectedCategory != CoreUtils.FullGuid)
  69. criteria.Add(new Filter<Consignment>(x => x.Category.ID).IsEqualTo(SelectedCategory));
  70. if (SelectedType != CoreUtils.FullGuid)
  71. criteria.Add(new Filter<Consignment>(x => x.Type.ID).IsEqualTo(SelectedType));
  72. base.Reload(criteria, columns, ref sort, action);
  73. }
  74. private bool ShowBillOfLading(CoreRow? arg)
  75. {
  76. if(arg is null)
  77. {
  78. return false;
  79. }
  80. var id = arg.Get<Consignment, Guid>(x => x.BillOfLading.ID);
  81. if (!Entity.IsEntityLinkValid<Consignment, PDFDocumentLink>(x => x.BillOfLading, arg))
  82. return false;
  83. var doc = new Client<Document>().Load(new Filter<Document>(x => x.ID).IsEqualTo(id)).FirstOrDefault();
  84. if (doc == null)
  85. {
  86. MessageBox.Show("Unable to Load Document");
  87. return false;
  88. }
  89. var ext = Path.GetExtension(doc.FileName);
  90. var tmpfile = Path.ChangeExtension(Path.GetTempFileName(), ext);
  91. File.WriteAllBytes(tmpfile, doc.Data);
  92. var gsProcessInfo = new ProcessStartInfo();
  93. gsProcessInfo.Verb = "open";
  94. gsProcessInfo.WindowStyle = ProcessWindowStyle.Normal;
  95. gsProcessInfo.FileName = tmpfile;
  96. gsProcessInfo.UseShellExecute = true;
  97. Process.Start(gsProcessInfo);
  98. return false;
  99. }
  100. private BitmapImage? ConsignmentImage(CoreRow? arg)
  101. {
  102. if (arg == null)
  103. return PRSDesktop.Resources.doc_pdf.AsBitmapImage();
  104. var id = arg.Get<Consignment, Guid>(x => x.BillOfLading.ID);
  105. return !Entity.IsEntityLinkValid<Consignment, PDFDocumentLink>(x => x.BillOfLading, arg) ? null : PRSDesktop.Resources.doc_pdf.AsBitmapImage();
  106. }
  107. }
  108. }