DeliveredOnSiteGrid.cs 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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. ParentID = 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 DynamicImageColumn() { Image = InstalledImage, Action = InstalledClick });
  28. ActionColumns.Add(new DynamicMapColumn<DeliveryItem>(this, x => x.Location) { Position = DynamicActionColumnPosition.Start });
  29. ActionColumns.Add(new DynamicImageColumn(DocumentsImage, DocumentsClick) { Position = DynamicActionColumnPosition.Start });
  30. HiddenColumns.Add(x => x.Documents);
  31. ActionColumns.Add(new DynamicImageColumn(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 ParentID { get; set; }
  49. public JobPanelSettings Settings { get; set; }
  50. private BitmapImage? SetoutImage(CoreRow arg)
  51. {
  52. if (arg == null)
  53. return null;
  54. return arg.IsEntityLinkValid<DeliveryItem, SetoutLink>(x => x.ManufacturingPacketLink.SetoutLink) ? setout : null;
  55. }
  56. private bool SetoutClick(CoreRow arg)
  57. {
  58. if (arg == null)
  59. return false;
  60. var setoutid = arg.EntityLinkID<DeliveryItem, SetoutLink>(x => x.ManufacturingPacketLink.SetoutLink) ?? Guid.Empty;
  61. if (setoutid != Guid.Empty)
  62. {
  63. var table = new Client<SetoutDocument>().Query(new Filter<SetoutDocument>(x => x.EntityLink.ID).IsEqualTo(setoutid));
  64. IEntityDocument[] docs = table.Rows.Select(r => r.ToObject<SetoutDocument>()).ToArray();
  65. var viewer = new DocumentEditor(docs);
  66. //viewer.PrintAllowed = Security.IsAllowed<CanPrintFactoryFloorDrawings>();
  67. viewer.SaveAllowed = Security.IsAllowed<CanSaveFactoryFloorDrawings>();
  68. viewer.Watermark = arg.Get<DeliveryItem, string>(x => x.ManufacturingPacketLink.WaterMark);
  69. viewer.ShowDialog();
  70. }
  71. return false;
  72. }
  73. private bool DocumentsClick(CoreRow arg)
  74. {
  75. if (arg == null)
  76. return false;
  77. var docs = new List<IEntityDocument>();
  78. using (new WaitCursor())
  79. {
  80. var deliveryid = arg.Get<DeliveryItem, Guid>(x => x.Delivery.ID);
  81. var table = new Client<DeliveryDocument>().Query(
  82. new Filter<DeliveryDocument>(x => x.EntityLink.ID).IsEqualTo(deliveryid)
  83. );
  84. foreach (var row in table.Rows)
  85. docs.Add(row.ToObject<DeliveryDocument>());
  86. }
  87. if (docs.Any())
  88. {
  89. var editor = new DocumentEditor(docs.ToArray());
  90. //editor.PrintAllowed = Security.IsAllowed<CanPrintFactoryFloorDrawings>();
  91. editor.SaveAllowed = Security.IsAllowed<CanSaveFactoryFloorDrawings>();
  92. editor.ShowDialog();
  93. }
  94. else
  95. {
  96. MessageBox.Show("No Documents Available!");
  97. }
  98. return false;
  99. }
  100. private BitmapImage DocumentsImage(CoreRow arg)
  101. {
  102. if (arg == null)
  103. return docs;
  104. return arg.Get<Delivery, int>(x => x.Documents) > 0 ? docs : null;
  105. }
  106. //private bool InstalledClick(CoreRow arg)
  107. //{
  108. // Guid id = arg.Get<DeliveryItem, Guid>(x => x.ID);
  109. // DeliveryItem item = new Client<DeliveryItem>().Load(new Filter<DeliveryItem>(x => x.ID).IsEqualTo(id)).FirstOrDefault();
  110. // if (item != null)
  111. // {
  112. // item.InstalledDate = item.InstalledDate.IsEmpty() ? DateTime.Now : DateTime.MinValue;
  113. // new Client<DeliveryItem>().Save(item, item.InstalledDate.IsEmpty() ? "Installed Flag Cleared" : "Item Marked as Installed");
  114. // }
  115. // return true;
  116. //}
  117. //private BitmapImage InstalledImage(CoreRow arg)
  118. //{
  119. // if (arg == null)
  120. // return Lifter;
  121. // DateTime date = arg.Get<DeliveryItem, DateTime>(x => x.InstalledDate);
  122. // return date.IsEmpty() ? null : Tick;
  123. //}
  124. protected override void Reload(Filters<DeliveryItem> criteria, Columns<DeliveryItem> columns, ref SortOrder<DeliveryItem> sort,
  125. Action<CoreTable, Exception> action)
  126. {
  127. var filter = new Filter<DeliveryItem>(x => x.DeliveredDate).IsNotEqualTo(DateTime.MinValue);
  128. if (!string.IsNullOrWhiteSpace(Search))
  129. filter = filter.TextSearch(
  130. Search,
  131. x => x.Barcode,
  132. x => x.Description,
  133. x => x.JobLink.Name,
  134. x => x.JobLink.JobNumber,
  135. x => x.Location.Address,
  136. x => x.Reference,
  137. x => x.Title,
  138. x => x.ShipmentCode,
  139. x => x.ShipmentLink.Code
  140. );
  141. criteria.Add(filter);
  142. criteria.Add(new Filter<DeliveryItem>(x => x.DeliveredDate).IsGreaterThanOrEqualTo(StartDate.Date));
  143. criteria.Add(new Filter<DeliveryItem>(x => x.DeliveredDate).IsLessThan(EndDate == DateTime.MaxValue
  144. ? DateTime.MaxValue
  145. : EndDate.AddDays(1)));
  146. if (ParentID != Guid.Empty)
  147. criteria.Add(new Filter<DeliveryItem>(x => x.JobLink.ID).IsEqualTo(ParentID));
  148. sort = new SortOrder<DeliveryItem>(x => x.Barcode);
  149. base.Reload(criteria, columns, ref sort, action);
  150. }
  151. }
  152. }