JobRequisitionsPanel.xaml.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. using Comal.Classes;
  2. using InABox.Configuration;
  3. using InABox.Core;
  4. using InABox.DynamicGrid;
  5. using InABox.WPF;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Diagnostics;
  9. using System.Linq;
  10. using System.Windows.Controls;
  11. using System.Windows.Media;
  12. namespace PRSDesktop
  13. {
  14. public class JobRequisitionPanelSettings : BaseObject, IGlobalConfigurationSettings
  15. {
  16. [Caption("Default Style for Company", IncludePath = false)]
  17. public ProductStyleLink ProductStyle { get; set; }
  18. public JobRequisitionPanelSettings()
  19. {
  20. ProductStyle = new ProductStyleLink();
  21. }
  22. }
  23. /// <summary>
  24. /// Interaction logic for JobRequisitionsPanel.xaml
  25. /// </summary>
  26. public partial class JobRequisitionsPanel : UserControl, IPanel<JobRequisitionItem>
  27. {
  28. Guid JobID = Guid.Empty;
  29. private JobRequisitionPanelSettings _settings = null;
  30. public JobRequisitionsPanel()
  31. {
  32. InitializeComponent();
  33. }
  34. enum PanelMode
  35. {
  36. Reserve,
  37. Purchase
  38. }
  39. private PanelMode mode;
  40. private PanelMode Mode
  41. {
  42. get => mode;
  43. set
  44. {
  45. mode = value;
  46. SetPanelDetail();
  47. }
  48. }
  49. private void SetPanelDetail()
  50. {
  51. if (Mode == PanelMode.Reserve)
  52. {
  53. reserveCol.Width = new System.Windows.GridLength(1, System.Windows.GridUnitType.Star);
  54. purchaseCol.Width = new System.Windows.GridLength(0);
  55. JobRequiItems.Options.Remove(DynamicGridOption.MultiSelect);
  56. reserveBtn.Background = new SolidColorBrush(Colors.LightGray);
  57. purchaseBtn.Background = new SolidColorBrush(Colors.WhiteSmoke);
  58. }
  59. else if (Mode == PanelMode.Purchase)
  60. {
  61. reserveCol.Width = new System.Windows.GridLength(0);
  62. purchaseCol.Width = new System.Windows.GridLength(1, System.Windows.GridUnitType.Star);
  63. JobRequiItems.Options.Add(DynamicGridOption.MultiSelect);
  64. reserveBtn.Background = new SolidColorBrush(Colors.WhiteSmoke);
  65. purchaseBtn.Background = new SolidColorBrush(Colors.LightGray);
  66. }
  67. }
  68. public bool IsReady { get; set; }
  69. public string SectionName => "Job Requisitions";
  70. public event DataModelUpdateEvent? OnUpdateDataModel;
  71. public void CreateToolbarButtons(IPanelHost host)
  72. {
  73. host.CreateSetupAction(new PanelAction() { Caption = "Product Configuration Settings", Image = PRSDesktop.Resources.specifications, OnExecute = ConfigSettingsClick });
  74. }
  75. private void ConfigSettingsClick(PanelAction obj)
  76. {
  77. var pages = new DynamicEditorPages();
  78. var buttons = new DynamicEditorButtons();
  79. buttons.Add(
  80. "",
  81. PRSDesktop.Resources.help.AsBitmapImage(),
  82. _settings,
  83. (f, i) =>
  84. {
  85. Process.Start(new ProcessStartInfo("https://prsdigital.com.au/wiki/index.php/" + typeof(Equipment).Name.SplitCamelCase().Replace(" ", "_"))
  86. { UseShellExecute = true });
  87. }
  88. );
  89. var propertyEditor = new DynamicEditorForm(typeof(JobRequisitionPanelSettings), pages, buttons);
  90. propertyEditor.OnDefineLookups += sender =>
  91. {
  92. var editor = sender.EditorDefinition as ILookupEditor;
  93. var colname = sender.ColumnName;
  94. var values = editor.Values(colname, new[] { _settings });
  95. sender.LoadLookups(values);
  96. };
  97. propertyEditor.OnEditorValueChanged += (sender, name, value) =>
  98. {
  99. CoreUtils.SetPropertyValue(_settings, name, value);
  100. return new Dictionary<string, object?>();
  101. };
  102. propertyEditor.Items = new BaseObject[] { _settings };
  103. if (propertyEditor.ShowDialog() == true)
  104. {
  105. new GlobalConfiguration<JobRequisitionPanelSettings>().Save(_settings);
  106. holdings.CompanyDefaultStyle = _settings.ProductStyle;
  107. }
  108. }
  109. public DataModel DataModel(Selection selection)
  110. {
  111. var ids = JobRequiItems.ExtractValues(x => x.ID, selection).ToArray();
  112. return new BaseDataModel<JobRequisitionItem>(new Filter<JobRequisitionItem>(x => x.ID).InList(ids));
  113. }
  114. public void Heartbeat(TimeSpan time)
  115. {
  116. }
  117. public void Refresh()
  118. {
  119. JobRequiItems.Refresh(false, true);
  120. }
  121. public Dictionary<string, object[]> Selected()
  122. {
  123. var result = new Dictionary<string, object[]>();
  124. result[typeof(JobRequisitionItem).EntityName()] = JobRequiItems.SelectedRows;
  125. return result;
  126. }
  127. public void Setup()
  128. {
  129. Mode = PanelMode.Reserve;
  130. SetupJobRequiItemGrids();
  131. _settings = new GlobalConfiguration<JobRequisitionPanelSettings>().Load();
  132. holdings.CompanyDefaultStyle = _settings.ProductStyle;
  133. holdings.OnHoldingsReviewRefresh += Holdings_OnHoldingsReviewRefresh;
  134. }
  135. private void Holdings_OnHoldingsReviewRefresh()
  136. {
  137. Refresh();
  138. RefreshJobRequiGrids();
  139. }
  140. private void RefreshJobRequiGrids()
  141. {
  142. JobRequiItems.bRefreshing = false;
  143. JobRequiItems.Refresh(false, true);
  144. }
  145. private void SetupJobRequiItemGrids()
  146. {
  147. JobRequiItems.OnGridRefresh += JobRequiItems_OnGridRefresh;
  148. JobRequiItems.OnJobRequiItemSelected += OnJobRequiItemSelected;
  149. JobRequiItems.Refresh(true, true);
  150. }
  151. private void OnJobRequiItemSelected(CoreRow[] rows)
  152. {
  153. holdings.Item = rows[0].ToObject<JobRequisitionItem>();
  154. purchasing.JobRequiItems = CreateList(rows);
  155. }
  156. private List<JobRequisitionItem> CreateList(CoreRow[] rows)
  157. {
  158. List<JobRequisitionItem> list = new List<JobRequisitionItem>();
  159. foreach (var row in rows)
  160. list.Add(row.ToObject<JobRequisitionItem>());
  161. return list;
  162. }
  163. private void JobRequiItems_OnGridRefresh()
  164. {
  165. RefreshJobRequiGrids();
  166. }
  167. public void Shutdown()
  168. {
  169. }
  170. private void ReserveStock_Clicked(object sender, System.Windows.RoutedEventArgs e)
  171. {
  172. Mode = PanelMode.Reserve;
  173. }
  174. private void PurchaseStock_Clicked(object sender, System.Windows.RoutedEventArgs e)
  175. {
  176. Mode = PanelMode.Purchase;
  177. }
  178. }
  179. }