JobDesignDocumentGrid.cs 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. Options.AddRange(DynamicGridOption.RecordCount, DynamicGridOption.SelectColumns);
  15. HiddenColumns.Add(x => x.DocumentLink.ID);
  16. HiddenColumns.Add(x => x.EntityLink.ID);
  17. HiddenColumns.Add(x => x.Superceded);
  18. HiddenColumns.Add(x => x.DocumentLink.FileName);
  19. ActionColumns.Add(new DynamicImageColumn(DocumentImage, ViewDocument) { Position = DynamicActionColumnPosition.Start });
  20. ActionColumns.Add(new DynamicTickColumn<SetoutDocument, DateTime>(
  21. x => x.Superceded,
  22. PRSDesktop.Resources.tick.AsBitmapImage(),
  23. PRSDesktop.Resources.warning.AsBitmapImage(),
  24. PRSDesktop.Resources.tick.AsBitmapImage(),
  25. SupercedeDocument
  26. ));
  27. Options.Remove(DynamicGridOption.AddRows);
  28. Options.Remove(DynamicGridOption.DeleteRows);
  29. Options.Remove(DynamicGridOption.ImportData);
  30. Options.Remove(DynamicGridOption.ExportData);
  31. Options.Remove(DynamicGridOption.EditRows);
  32. }
  33. public Guid SetoutID { get; set; }
  34. protected override SetoutDocument CreateItem()
  35. {
  36. var result = base.CreateItem();
  37. result.EntityLink.ID = SetoutID;
  38. return result;
  39. }
  40. protected override void Reload(Filters<SetoutDocument> criteria, Columns<SetoutDocument> columns, ref SortOrder<SetoutDocument> sort,
  41. Action<CoreTable, Exception> action)
  42. {
  43. criteria.Add(new Filter<SetoutDocument>(x => x.EntityLink.ID).IsEqualTo(SetoutID));
  44. base.Reload(criteria, columns, ref sort, action);
  45. }
  46. private BitmapImage DocumentImage(CoreRow arg)
  47. {
  48. return PRSDesktop.Resources.view.AsBitmapImage();
  49. }
  50. private bool ViewDocument(CoreRow row)
  51. {
  52. var doc = row.ToObject<SetoutDocument>();
  53. var viewer = new DocumentEditor(doc);
  54. //viewer.PrintAllowed = Security.IsAllowed<CanPrintFactoryFloorDrawings>();
  55. viewer.SaveAllowed = Security.IsAllowed<CanSaveFactoryFloorDrawings>();
  56. viewer.ShowDialog();
  57. return false;
  58. }
  59. private bool SupercedeDocument(CoreRow row)
  60. {
  61. var sd = row.ToObject<SetoutDocument>();
  62. sd.Superceded = sd.Superceded.IsEmpty() ? DateTime.Now : DateTime.MinValue;
  63. new Client<SetoutDocument>().Save(sd, string.Format("{0} Superceded Flag", sd.Superceded.IsEmpty() ? "Cleared" : "Set"));
  64. return true;
  65. }
  66. }
  67. }