ConsignmentsGrid.cs 4.6 KB

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