DeliveredOnSiteGrid.cs 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Windows;
  5. using System.Windows.Media.Imaging;
  6. using Comal.Classes;
  7. using InABox.Clients;
  8. using InABox.Core;
  9. using InABox.DynamicGrid;
  10. using InABox.WPF;
  11. namespace PRSDesktop
  12. {
  13. public class DeliveredOnSiteGrid : DynamicDataGrid<DeliveryItem>, IJobControl, IDataModelSource
  14. {
  15. private readonly BitmapImage docs = PRSDesktop.Resources.doc_png.AsBitmapImage();
  16. private BitmapImage Lifter = PRSDesktop.Resources.lifter.AsBitmapImage();
  17. private readonly BitmapImage setout = PRSDesktop.Resources.design.AsBitmapImage();
  18. private BitmapImage Tick = PRSDesktop.Resources.tick.AsBitmapImage();
  19. //bool bTodayOnly = false;
  20. public DeliveredOnSiteGrid()
  21. {
  22. JobID = Guid.Empty;
  23. Options.AddRange(DynamicGridOption.RecordCount, DynamicGridOption.SelectColumns, DynamicGridOption.EditRows, DynamicGridOption.FilterRows,
  24. DynamicGridOption.MultiSelect);
  25. HiddenColumns.Add(x => x.Delivery.ID);
  26. //HiddenColumns.Add(x => x.InstalledDate);
  27. //ActionColumns.Add(new DynamicActionColumn() { Image = InstalledImage, Action = InstalledClick });
  28. ActionColumns.Add(new DynamicMapColumn<DeliveryItem>(this, x => x.Location) { Position = DynamicActionColumnPosition.Start });
  29. ActionColumns.Add(new DynamicActionColumn(DocumentsImage, DocumentsClick) { Position = DynamicActionColumnPosition.Start });
  30. HiddenColumns.Add(x => x.Documents);
  31. ActionColumns.Add(new DynamicActionColumn(SetoutImage, SetoutClick) { Position = DynamicActionColumnPosition.Start });
  32. HiddenColumns.Add(x => x.ManufacturingPacketLink.ID);
  33. HiddenColumns.Add(x => x.ManufacturingPacketLink.WaterMark);
  34. HiddenColumns.Add(x => x.ManufacturingPacketLink.SetoutLink.ID);
  35. HiddenColumns.Add(x => x.ManufacturingPacketLink.SetoutLink.Deleted);
  36. }
  37. public DateTime StartDate { get; set; } = DateTime.MinValue;
  38. public DateTime EndDate { get; set; } = DateTime.MaxValue;
  39. public string Search { get; set; } = "";
  40. public CoreTable Items { get; private set; }
  41. public event DataModelUpdateEvent OnUpdateDataModel;
  42. public string SectionName => "Delivered On Site";
  43. public DataModel DataModel(Selection selection)
  44. {
  45. var ids = ExtractValues(x => x.ID, selection).ToArray();
  46. return new DeliveryItemDataModel(new Filter<DeliveryItem>(x => x.ID).InList(ids));
  47. }
  48. public Guid JobID { get; set; }
  49. private BitmapImage? SetoutImage(CoreRow arg)
  50. {
  51. if (arg == null)
  52. return null;
  53. return arg.IsEntityLinkValid<DeliveryItem, SetoutLink>(x => x.ManufacturingPacketLink.SetoutLink) ? setout : null;
  54. }
  55. private bool SetoutClick(CoreRow arg)
  56. {
  57. if (arg == null)
  58. return false;
  59. var setoutid = arg.EntityLinkID<DeliveryItem, SetoutLink>(x => x.ManufacturingPacketLink.SetoutLink) ?? Guid.Empty;
  60. if (setoutid != Guid.Empty)
  61. {
  62. var table = new Client<SetoutDocument>().Query(new Filter<SetoutDocument>(x => x.EntityLink.ID).IsEqualTo(setoutid));
  63. IEntityDocument[] docs = table.Rows.Select(r => r.ToObject<SetoutDocument>()).ToArray();
  64. var viewer = new DocumentEditor(docs);
  65. viewer.PrintAllowed = Security.IsAllowed<CanPrintFactoryFloorDrawings>();
  66. viewer.SaveAllowed = Security.IsAllowed<CanSaveFactoryFloorDrawings>();
  67. viewer.Watermark = arg.Get<DeliveryItem, string>(x => x.ManufacturingPacketLink.WaterMark);
  68. viewer.ShowDialog();
  69. }
  70. return false;
  71. }
  72. private bool DocumentsClick(CoreRow arg)
  73. {
  74. if (arg == null)
  75. return false;
  76. var docs = new List<IEntityDocument>();
  77. using (new WaitCursor())
  78. {
  79. var deliveryid = arg.Get<DeliveryItem, Guid>(x => x.Delivery.ID);
  80. var table = new Client<DeliveryDocument>().Query(
  81. new Filter<DeliveryDocument>(x => x.EntityLink.ID).IsEqualTo(deliveryid)
  82. );
  83. foreach (var row in table.Rows)
  84. docs.Add(row.ToObject<DeliveryDocument>());
  85. }
  86. if (docs.Any())
  87. {
  88. var editor = new DocumentEditor(docs.ToArray());
  89. editor.PrintAllowed = Security.IsAllowed<CanPrintFactoryFloorDrawings>();
  90. editor.SaveAllowed = Security.IsAllowed<CanSaveFactoryFloorDrawings>();
  91. editor.ShowDialog();
  92. }
  93. else
  94. {
  95. MessageBox.Show("No Documents Available!");
  96. }
  97. return false;
  98. }
  99. private BitmapImage DocumentsImage(CoreRow arg)
  100. {
  101. if (arg == null)
  102. return docs;
  103. return arg.Get<Delivery, int>(x => x.Documents) > 0 ? docs : null;
  104. }
  105. //private bool InstalledClick(CoreRow arg)
  106. //{
  107. // Guid id = arg.Get<DeliveryItem, Guid>(x => x.ID);
  108. // DeliveryItem item = new Client<DeliveryItem>().Load(new Filter<DeliveryItem>(x => x.ID).IsEqualTo(id)).FirstOrDefault();
  109. // if (item != null)
  110. // {
  111. // item.InstalledDate = item.InstalledDate.IsEmpty() ? DateTime.Now : DateTime.MinValue;
  112. // new Client<DeliveryItem>().Save(item, item.InstalledDate.IsEmpty() ? "Installed Flag Cleared" : "Item Marked as Installed");
  113. // }
  114. // return true;
  115. //}
  116. //private BitmapImage InstalledImage(CoreRow arg)
  117. //{
  118. // if (arg == null)
  119. // return Lifter;
  120. // DateTime date = arg.Get<DeliveryItem, DateTime>(x => x.InstalledDate);
  121. // return date.IsEmpty() ? null : Tick;
  122. //}
  123. protected override void Reload(Filters<DeliveryItem> criteria, Columns<DeliveryItem> columns, ref SortOrder<DeliveryItem> sort,
  124. Action<CoreTable, Exception> action)
  125. {
  126. var filter = new Filter<DeliveryItem>(x => x.DeliveredDate).IsNotEqualTo(DateTime.MinValue);
  127. if (!string.IsNullOrWhiteSpace(Search))
  128. filter = filter.TextSearch(
  129. Search,
  130. x => x.Barcode,
  131. x => x.Description,
  132. x => x.JobLink.Name,
  133. x => x.JobLink.JobNumber,
  134. x => x.Location.Address,
  135. x => x.Reference,
  136. x => x.Title,
  137. x => x.ShipmentCode,
  138. x => x.ShipmentLink.Code
  139. );
  140. criteria.Add(filter);
  141. criteria.Add(new Filter<DeliveryItem>(x => x.DeliveredDate).IsGreaterThanOrEqualTo(StartDate.Date));
  142. criteria.Add(new Filter<DeliveryItem>(x => x.DeliveredDate).IsLessThan(EndDate == DateTime.MaxValue
  143. ? DateTime.MaxValue
  144. : EndDate.AddDays(1)));
  145. if (JobID != Guid.Empty)
  146. criteria.Add(new Filter<DeliveryItem>(x => x.JobLink.ID).IsEqualTo(JobID));
  147. sort = new SortOrder<DeliveryItem>(x => x.Barcode);
  148. base.Reload(criteria, columns, ref sort, action);
  149. }
  150. }
  151. }