JobDesignDocumentGrid.cs 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. using System;
  2. using System.Windows.Media.Imaging;
  3. using Comal.Classes;
  4. using InABox.Clients;
  5. using InABox.Core;
  6. using InABox.DynamicGrid;
  7. using InABox.WPF;
  8. namespace PRSDesktop
  9. {
  10. public class JobDesignDocumentGrid : DynamicDataGrid<SetoutDocument>
  11. {
  12. public JobDesignDocumentGrid()
  13. {
  14. HiddenColumns.Add(x => x.DocumentLink.ID);
  15. HiddenColumns.Add(x => x.EntityLink.ID);
  16. HiddenColumns.Add(x => x.Superceded);
  17. HiddenColumns.Add(x => x.DocumentLink.FileName);
  18. ActionColumns.Add(new DynamicImageColumn(DocumentImage, ViewDocument) { Position = DynamicActionColumnPosition.Start });
  19. ActionColumns.Add(new DynamicTickColumn<SetoutDocument, DateTime>(
  20. x => x.Superceded,
  21. PRSDesktop.Resources.tick.AsBitmapImage(),
  22. PRSDesktop.Resources.warning.AsBitmapImage(),
  23. PRSDesktop.Resources.tick.AsBitmapImage(),
  24. SupercedeDocument
  25. ));
  26. }
  27. protected override void DoReconfigure(FluentList<DynamicGridOption> options)
  28. {
  29. base.DoReconfigure(options);
  30. options.BeginUpdate()
  31. .Add(DynamicGridOption.RecordCount)
  32. .Add(DynamicGridOption.SelectColumns)
  33. .Remove(DynamicGridOption.ImportData)
  34. .Remove(DynamicGridOption.ExportData)
  35. .EndUpdate();
  36. }
  37. public Setout Design { get; set; }
  38. protected override SetoutDocument CreateItem()
  39. {
  40. var result = base.CreateItem();
  41. result.EntityLink.ID = Design.ID;
  42. result.EntityLink.Synchronise(Design);
  43. return result;
  44. }
  45. protected override void Reload(Filters<SetoutDocument> criteria, Columns<SetoutDocument> columns, ref SortOrder<SetoutDocument>? sort, Action<CoreTable?, Exception?> action)
  46. {
  47. criteria.Add(new Filter<SetoutDocument>(x => x.EntityLink.ID).IsEqualTo(Design.ID));
  48. base.Reload(criteria, columns, ref sort, action);
  49. }
  50. private BitmapImage DocumentImage(CoreRow arg)
  51. {
  52. return PRSDesktop.Resources.view.AsBitmapImage();
  53. }
  54. private bool ViewDocument(CoreRow row)
  55. {
  56. var doc = row.ToObject<SetoutDocument>();
  57. var viewer = new DocumentEditor(doc);
  58. //viewer.PrintAllowed = Security.IsAllowed<CanPrintFactoryFloorDrawings>();
  59. viewer.SaveAllowed = Security.IsAllowed<CanSaveFactoryFloorDrawings>();
  60. viewer.ShowDialog();
  61. return false;
  62. }
  63. private bool SupercedeDocument(CoreRow row)
  64. {
  65. var sd = row.ToObject<SetoutDocument>();
  66. sd.Superceded = sd.Superceded.IsEmpty() ? DateTime.Now : DateTime.MinValue;
  67. new Client<SetoutDocument>().Save(sd, string.Format("{0} Superceded Flag", sd.Superceded.IsEmpty() ? "Cleared" : "Set"));
  68. return true;
  69. }
  70. protected override bool CanCreateItems()
  71. {
  72. return Design.ID != Guid.Empty;
  73. }
  74. }
  75. }