JobRFIPanel.xaml.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Windows;
  5. using System.Windows.Controls;
  6. using Comal.Classes;
  7. using InABox.Core;
  8. using InABox.DynamicGrid;
  9. using InABox.WPF;
  10. namespace PRSDesktop
  11. {
  12. public class JobRFIGrid : DynamicDataGrid<JobRFI>
  13. {
  14. public Guid ParentID { get; set; }
  15. public JobRFIGrid()
  16. {
  17. Options
  18. .BeginUpdate()
  19. .Clear()
  20. .Add(DynamicGridOption.AddRows)
  21. .Add(DynamicGridOption.EditRows)
  22. .Add(DynamicGridOption.DeleteRows)
  23. .Add(DynamicGridOption.FilterRows)
  24. .Add(DynamicGridOption.SelectColumns)
  25. .Add(DynamicGridOption.AddRows)
  26. .EndUpdate();
  27. }
  28. protected override void Reload(Filters<JobRFI> criteria, Columns<JobRFI> columns, ref SortOrder<JobRFI>? sort, Action<CoreTable?, Exception?> action)
  29. {
  30. criteria.Add(new Filter<JobRFI>(c => c.Job.ID).IsEqualTo(ParentID));
  31. base.Reload(criteria, columns, ref sort, action);
  32. }
  33. protected override JobRFI CreateItem()
  34. {
  35. var result = base.CreateItem();
  36. result.Job.ID = ParentID;
  37. return result;
  38. }
  39. public JobRFI[] LoadRFIs(CoreRow[]? rows)
  40. {
  41. return LoadItems(rows);
  42. }
  43. }
  44. public partial class JobRFIPanel : UserControl, IPanel<JobRFI>, IJobControl
  45. {
  46. public Guid ParentID { get; set; }
  47. public JobRFIPanel()
  48. {
  49. InitializeComponent();
  50. }
  51. private void DynamicSplitPanel_OnOnChanged(object sender, DynamicSplitPanelSettings e)
  52. {
  53. if (e.View == DynamicSplitPanelView.Master)
  54. RFIs.Options.Add(DynamicGridOption.MultiSelect);
  55. else
  56. RFIs.Options.Remove(DynamicGridOption.MultiSelect);
  57. }
  58. private JobRFI[]? _rfis = null;
  59. private void RFIs_OnOnSelectItem(object sender, DynamicGridSelectionEventArgs e)
  60. {
  61. ReloadRFIs();
  62. }
  63. private void ReloadRFIs()
  64. {
  65. if (RFIs.SelectedRows?.Any() == true)
  66. {
  67. _rfis = RFIs.LoadRFIs(RFIs.SelectedRows);
  68. RFIs.InitialiseEditorForm(RFIEditor, _rfis);
  69. RFIEditor.Visibility = Visibility.Visible;
  70. }
  71. else
  72. {
  73. _rfis = null;
  74. RFIEditor.Visibility = Visibility.Hidden;
  75. }
  76. }
  77. private void RFI_OnOnOK()
  78. {
  79. using (new WaitCursor())
  80. {
  81. var cancel = new System.ComponentModel.CancelEventArgs();
  82. RFIEditor.SaveItem(cancel);
  83. if (!cancel.Cancel)
  84. ReloadRFIs();
  85. }
  86. }
  87. private void RFI_OnOnCancel()
  88. {
  89. ReloadRFIs();
  90. }
  91. #region IPanel Stuff
  92. public void Setup()
  93. {
  94. RFIs.Refresh(true, false);
  95. }
  96. public void Shutdown()
  97. {
  98. }
  99. public void Refresh()
  100. {
  101. RFIs.Refresh(false, true);
  102. }
  103. public string SectionName => "Job RFIs";
  104. public DataModel DataModel(Selection selection)
  105. {
  106. return new BaseDataModel<JobRFI>(new Filter<JobRFI>(x => x.Job.ID).IsEqualTo(ParentID));
  107. }
  108. public event DataModelUpdateEvent? OnUpdateDataModel;
  109. public bool IsReady { get; set; }
  110. public void CreateToolbarButtons(IPanelHost host)
  111. {
  112. }
  113. public Dictionary<string, object[]> Selected()
  114. {
  115. return new Dictionary<string, object[]>();
  116. }
  117. public void Heartbeat(TimeSpan time)
  118. {
  119. }
  120. #endregion
  121. }
  122. }