JobDesignDocumentGrid.cs 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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,
  46. Action<CoreTable, Exception> action)
  47. {
  48. criteria.Add(new Filter<SetoutDocument>(x => x.EntityLink.ID).IsEqualTo(Design.ID));
  49. base.Reload(criteria, columns, ref sort, action);
  50. }
  51. private BitmapImage DocumentImage(CoreRow arg)
  52. {
  53. return PRSDesktop.Resources.view.AsBitmapImage();
  54. }
  55. private bool ViewDocument(CoreRow row)
  56. {
  57. var doc = row.ToObject<SetoutDocument>();
  58. var viewer = new DocumentEditor(doc);
  59. //viewer.PrintAllowed = Security.IsAllowed<CanPrintFactoryFloorDrawings>();
  60. viewer.SaveAllowed = Security.IsAllowed<CanSaveFactoryFloorDrawings>();
  61. viewer.ShowDialog();
  62. return false;
  63. }
  64. private bool SupercedeDocument(CoreRow row)
  65. {
  66. var sd = row.ToObject<SetoutDocument>();
  67. sd.Superceded = sd.Superceded.IsEmpty() ? DateTime.Now : DateTime.MinValue;
  68. new Client<SetoutDocument>().Save(sd, string.Format("{0} Superceded Flag", sd.Superceded.IsEmpty() ? "Cleared" : "Set"));
  69. return true;
  70. }
  71. protected override bool CanCreateItems()
  72. {
  73. return Design.ID != Guid.Empty;
  74. }
  75. }
  76. }