StockSummaryControl.xaml.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Linq;
  5. using System.Windows;
  6. using System.Windows.Controls;
  7. using Comal.Classes;
  8. using InABox.Configuration;
  9. using InABox.Core;
  10. using InABox.DynamicGrid;
  11. using InABox.WPF;
  12. namespace PRSDesktop;
  13. public partial class StockSummaryControl : UserControl
  14. {
  15. private bool _loadedGroups = false;
  16. private bool _refresh = false;
  17. private enum Suppress
  18. {
  19. This
  20. }
  21. public StockSummaryControl()
  22. {
  23. using (new EventSuppressor(Suppress.This))
  24. InitializeComponent();
  25. }
  26. public void Setup()
  27. {
  28. using (new EventSuppressor(Suppress.This))
  29. {
  30. DoLoadSettings();
  31. SplitPanel.View = Properties.SplitPanelSettings.View;
  32. SplitPanel.AnchorWidth = Properties.SplitPanelSettings.AnchorWidth;
  33. SplitPanel.DetailHeight = Properties.SplitPanelSettings.DetailHeight;
  34. Optimise.IsChecked = Properties.Optimise;
  35. SummaryGrid.Optimise = Properties.Optimise;
  36. AllStock.IsChecked = Properties.AllStock;
  37. SummaryGrid.AllStock = Properties.AllStock;
  38. RequiredOnly.IsChecked = Properties.RequiredOnly;
  39. SummaryGrid.RequiredOnly = Properties.RequiredOnly;
  40. InitialiseSelectors();
  41. SummaryGrid.Refresh(true, false);
  42. }
  43. }
  44. private void InitialiseSelectors()
  45. {
  46. ProductGroups.SelectedIDs = Properties.ProductGroups.ToHashSet();
  47. SupplierGrid.SelectedIDs = Properties.Suppliers.ToHashSet();
  48. JobGrid.SelectedIDs = Properties.Jobs.ToHashSet();
  49. ProductGroups.FilterComponent.SetSettings(Properties.ProductGroupFilter, false);
  50. ProductGroups.FilterComponent.OnFiltersSelected += (filters) =>
  51. {
  52. Properties.ProductGroupFilter = filters;
  53. DoSaveSettings();
  54. };
  55. SupplierGrid.FilterComponent.SetSettings(Properties.SupplierFilter, false);
  56. SupplierGrid.FilterComponent.OnFiltersSelected += (filters) =>
  57. {
  58. Properties.SupplierFilter = filters;
  59. DoSaveSettings();
  60. };
  61. JobGrid.FilterComponent.SetSettings(Properties.JobFilter, false);
  62. JobGrid.FilterComponent.OnFiltersSelected += (filters) =>
  63. {
  64. Properties.JobFilter = filters;
  65. DoSaveSettings();
  66. };
  67. ProductGroups.Refresh(true, true);
  68. SupplierGrid.Refresh(true, true);
  69. JobGrid.Refresh(true, true);
  70. SummaryGrid.JobIDs = Properties.Jobs;
  71. SummaryGrid.SupplierIDs = Properties.Suppliers.ToHashSet();
  72. }
  73. public void Shutdown(CancelEventArgs? cancel)
  74. {
  75. }
  76. public void Refresh()
  77. {
  78. _refresh = true;
  79. if (_loadedGroups)
  80. {
  81. SummaryGrid.Refresh(false,true);
  82. }
  83. }
  84. public StockSummaryProperties Properties { get; set; }
  85. private void DoLoadSettings()
  86. {
  87. Properties = LoadSettings?.Invoke(this) ?? new StockSummaryProperties();
  88. }
  89. private void DoSaveSettings()
  90. {
  91. SaveSettings?.Invoke(this, Properties);
  92. }
  93. public event LoadSettings<StockSummaryProperties>? LoadSettings;
  94. public event SaveSettings<StockSummaryProperties>? SaveSettings;
  95. private void SplitPanel_OnOnChanged(object sender, DynamicSplitPanelSettings e)
  96. {
  97. if (EventSuppressor.IsSet(Suppress.This))
  98. return;
  99. Properties.SplitPanelSettings = e;
  100. DoSaveSettings();
  101. }
  102. private void SummaryGrid_OnBeforeRefresh(object sender, BeforeRefreshEventArgs args)
  103. {
  104. //Progress.Show("Loading");
  105. ProductGroups.IsEnabled = false;
  106. JobGrid.IsEnabled = false;
  107. SupplierGrid.IsEnabled = false;
  108. SummaryGrid.IsEnabled = false;
  109. }
  110. private void SummaryGrid_OnAfterRefresh(object sender, AfterRefreshEventArgs args)
  111. {
  112. //Progress.Close();
  113. ProductGroups.IsEnabled = true;
  114. JobGrid.IsEnabled = true;
  115. SupplierGrid.IsEnabled = true;
  116. SummaryGrid.IsEnabled = true;
  117. }
  118. private void DetailSplitPanel_OnChanged(object sender, DynamicSplitPanelSettings e)
  119. {
  120. }
  121. private void ProductGroups_GroupSelectionChanged(HashSet<Guid> selected)
  122. {
  123. if (EventSuppressor.IsSet(Suppress.This))
  124. return;
  125. Properties.ProductGroups = ProductGroups.GetSelectedGroups(false).ToArray();
  126. DoSaveSettings();
  127. SummaryGrid.GroupIDs = ProductGroups.GetSelectedGroups(true).ToArray();
  128. SummaryGrid.Refresh(false, true);
  129. }
  130. private void SupplierGrid_SelectionChanged(HashSet<Guid> selected)
  131. {
  132. if (EventSuppressor.IsSet(Suppress.This))
  133. return;
  134. Properties.Suppliers = selected.ToArray();
  135. DoSaveSettings();
  136. SummaryGrid.SupplierIDs = Properties.Suppliers.ToHashSet();
  137. SummaryGrid.Refresh(false, false);
  138. }
  139. private void JobGrid_SelectionChanged(HashSet<Guid> selected)
  140. {
  141. if (EventSuppressor.IsSet(Suppress.This))
  142. return;
  143. Properties.Jobs = selected.ToArray();
  144. DoSaveSettings();
  145. SummaryGrid.JobIDs = Properties.Jobs;
  146. SummaryGrid.Refresh(false, true);
  147. }
  148. private void ProductGroups_AfterRefresh(object sender, AfterRefreshEventArgs args)
  149. {
  150. SummaryGrid.GroupIDs = ProductGroups.GetSelectedGroups(true).ToArray();
  151. _loadedGroups = true;
  152. if (_refresh)
  153. {
  154. Refresh();
  155. }
  156. }
  157. private void AllStock_Checked(object sender, RoutedEventArgs e)
  158. {
  159. if (EventSuppressor.IsSet(Suppress.This))
  160. return;
  161. Properties.AllStock = AllStock.IsChecked == true;
  162. DoSaveSettings();
  163. SummaryGrid.AllStock = Properties.AllStock;
  164. SummaryGrid.Refresh(false,false);
  165. }
  166. private void RequiredOnly_Checked(object sender, RoutedEventArgs e)
  167. {
  168. if (EventSuppressor.IsSet(Suppress.This))
  169. return;
  170. Properties.RequiredOnly = RequiredOnly.IsChecked == true;
  171. DoSaveSettings();
  172. SummaryGrid.RequiredOnly = Properties.RequiredOnly;
  173. SummaryGrid.Refresh(false,false);
  174. }
  175. private void Optimise_Checked(object sender, RoutedEventArgs e)
  176. {
  177. if (EventSuppressor.IsSet(Suppress.This))
  178. return;
  179. Properties.Optimise = Optimise.IsChecked == true;
  180. DoSaveSettings();
  181. SummaryGrid.Optimise = Properties.Optimise;
  182. SummaryGrid.Refresh(false,false);
  183. }
  184. }