JobDesignGrid.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. using System;
  2. using System.Windows;
  3. using System.Windows.Media.Imaging;
  4. using Comal.Classes;
  5. using InABox.Core;
  6. using InABox.DynamicGrid;
  7. using InABox.WPF;
  8. using PRSDesktop.Panels.Jobs;
  9. namespace PRSDesktop
  10. {
  11. internal class JobDesignGrid : DynamicDataGrid<Setout>, IJobControl
  12. {
  13. private BitmapImage barcode = PRSDesktop.Resources.barcode.AsBitmapImage();
  14. private BitmapImage design = PRSDesktop.Resources.design.AsBitmapImage();
  15. private BitmapImage qacheck = PRSDesktop.Resources.checklist.AsBitmapImage();
  16. private BitmapImage tick = PRSDesktop.Resources.tick.AsBitmapImage();
  17. public JobDesignGrid()
  18. {
  19. Options.AddRange(DynamicGridOption.RecordCount, DynamicGridOption.SelectColumns, DynamicGridOption.FilterRows, DynamicGridOption.ImportData);
  20. //ActionColumns.Add(
  21. // new DynamicTickColumn<Setout>(PRSDesktop.Resources.design.AsBitmapImage(), x => x.Designed)
  22. // {
  23. // Action = DesignedClick
  24. // }
  25. // );
  26. //ActionColumns.Add(new DynamicTickColumn<Setout>(PRSDesktop.Resources.checklist.AsBitmapImage(), x => x.Checked));
  27. //ActionColumns.Add(new DynamicTickColumn<Setout>(PRSDesktop.Resources.factory.AsBitmapImage(), x => x.Issued));
  28. //ActionColumns.Add(new DynamicImageColumn() { Image = DesignedImage, Action = DesignedClick });
  29. //ActionColumns.Add(new DynamicImageColumn() { Image = CheckedImage, Action = CheckedClick });
  30. //ActionColumns.Add(new DynamicImageColumn() { Image = BarcodeImage, Action = BarcodeClick });
  31. //HiddenColumns.Add(x => x.Designed);
  32. //HiddenColumns.Add(x => x.Checked);
  33. //HiddenColumns.Add(x => x.Issued);
  34. //OnAddItem += DoAddItem;
  35. //OnEditItem += DoEditItem;
  36. }
  37. public CoreTable Setouts { get; private set; }
  38. public Guid ParentID { get; set; }
  39. public JobPanelSettings Settings { get; set; }
  40. protected override void DoImport()
  41. {
  42. var window = new JobDesignImportWindow();
  43. if (window.ShowDialog() == true)
  44. Refresh(false,true);
  45. }
  46. protected override void Reload(Filters<Setout> criteria, Columns<Setout> columns, ref SortOrder<Setout> sort,
  47. Action<CoreTable, Exception> action)
  48. {
  49. criteria.Add(new Filter<Setout>(x => x.JobLink.ID).IsEqualTo(ParentID));
  50. sort = new SortOrder<Setout>(x => x.Number, SortDirection.Descending);
  51. base.Reload(criteria, columns, ref sort, action);
  52. }
  53. protected override void DoAdd(bool OpenEditorOnDirectEdit = false)
  54. {
  55. if (ParentID.Equals(Guid.Empty) || ParentID.Equals(CoreUtils.FullGuid))
  56. MessageBox.Show("Please select a Job first!");
  57. else
  58. base.DoAdd();
  59. }
  60. protected override Setout CreateItem()
  61. {
  62. var setout = base.CreateItem();
  63. setout.JobLink.ID = ParentID;
  64. //setout.Job = new Client<Job>().Load(new Filter<Job>(x => x.ID).IsEqualTo(CurrentJobID)).FirstOrDefault();
  65. return setout;
  66. }
  67. //public override bool EditItems(Setout[] items)
  68. //{
  69. // Setout item = items.FirstOrDefault();
  70. // if (item == null)
  71. // return false;
  72. // SetoutDetails form = new SetoutDetails(item);
  73. // return form.ShowDialog() == true;
  74. //}
  75. //private BitmapImage DesignedImage(DataRow row)
  76. //{
  77. // if (row == null)
  78. // return design;
  79. // DateTime designed = row.Get<Setout, DateTime>(x => x.Designed);
  80. // //DateTime qachecked = row.Get<Setout, DateTime>(x => x.Checked);
  81. // //DateTime issued = row.Get<Setout, DateTime>(x => x.Issued);
  82. // return designed.IsEmpty() /* && qachecked.IsEmpty() && issued.IsEmpty() */ ? null : tick;
  83. //}
  84. //private bool DesignedClick(CoreRow row)
  85. //{
  86. // Setout setout = LoadItem(row);
  87. // bool designed = setout.Designed.IsEmpty();
  88. // setout.Designed = designed ? DateTime.Now : DateTime.MinValue;
  89. // //setout.Checked = DateTime.MinValue;
  90. // //setout.Issued = DateTime.MinValue;
  91. // //foreach (SetoutStage stage in setout.Stages)
  92. // //{
  93. // // stage.Started = DateTime.MinValue;
  94. // // stage.Completed = DateTime.MinValue;
  95. // //}
  96. // new Client<Setout>().Save(setout,"Setout Designed Flag set to " + (setout.Designed.IsEmpty()? "false" : "true"));
  97. // return true;
  98. //}
  99. //private BitmapImage CheckedImage(DataRow row)
  100. //{
  101. // if (row == null)
  102. // return qacheck;
  103. // DateTime qachecked = row.Get<Setout, DateTime>(x => x.Checked);
  104. // //DateTime issued = row.Get<Setout, DateTime>(x => x.Issued);
  105. // return qachecked.IsEmpty() /* && issued.IsEmpty() */ ? null : tick;
  106. //}
  107. //private bool CheckedClick(DataRow row)
  108. //{
  109. // //Setout setout = LoadItem(row);
  110. // //bool qachecked = setout.Checked.IsEmpty();
  111. // //setout.Designed = qachecked ? setout.Designed.IsEmpty() ? DateTime.Now : setout.Designed : setout.Designed;
  112. // //setout.Checked = qachecked ? DateTime.Now : DateTime.MinValue;
  113. // //setout.Issued = DateTime.MinValue;
  114. // //foreach (SetoutStage stage in setout.Stages)
  115. // //{
  116. // // stage.Started = DateTime.MinValue;
  117. // // stage.Completed = DateTime.MinValue;
  118. // //}
  119. // ////if (issue)
  120. // //// setout.MoveNext();
  121. // //new Client<Setout>().Save(setout, "Setout QA Flag set to " + (setout.Designed.IsEmpty() ? "false" : "true"));
  122. // //return true;
  123. // return false;
  124. //}
  125. //private BitmapImage BarcodeImage(DataRow row)
  126. //{
  127. // if (row == null)
  128. // return barcode;
  129. // DateTime issued = row.Get<Setout, DateTime>(x => x.Issued);
  130. // return issued.IsEmpty() ? null : barcode;
  131. //}
  132. //private bool BarcodeClick(DataRow row)
  133. //{
  134. // //DateTime issued = row.Get<Setout, DateTime>(x => x.Issued);
  135. // //if (issued.IsEmpty())
  136. // // return false;
  137. // return false;
  138. //}
  139. }
  140. }