StockSummaryControl.xaml.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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. FreeStockCheckBox.IsChecked = Properties.IncludeFreeStock;
  35. SummaryGrid.IncludeFreeStock = Properties.IncludeFreeStock;
  36. InitialiseSelectors();
  37. SummaryGrid.Refresh(true, false);
  38. }
  39. }
  40. private void InitialiseSelectors()
  41. {
  42. ProductGroups.SelectedIDs = Properties.ProductGroups.ToHashSet();
  43. SupplierGrid.SelectedIDs = Properties.Suppliers.ToHashSet();
  44. JobGrid.SelectedIDs = Properties.Jobs.ToHashSet();
  45. ProductGroups.FilterComponent.SetSettings(Properties.ProductGroupFilter, false);
  46. ProductGroups.FilterComponent.OnFiltersSelected += (filters) =>
  47. {
  48. Properties.ProductGroupFilter = filters;
  49. DoSaveSettings();
  50. };
  51. SupplierGrid.FilterComponent.SetSettings(Properties.SupplierFilter, false);
  52. SupplierGrid.FilterComponent.OnFiltersSelected += (filters) =>
  53. {
  54. Properties.SupplierFilter = filters;
  55. DoSaveSettings();
  56. };
  57. JobGrid.FilterComponent.SetSettings(Properties.JobFilter, false);
  58. JobGrid.FilterComponent.OnFiltersSelected += (filters) =>
  59. {
  60. Properties.JobFilter = filters;
  61. DoSaveSettings();
  62. };
  63. ProductGroups.Refresh(true, true);
  64. SupplierGrid.Refresh(true, true);
  65. JobGrid.Refresh(true, true);
  66. SummaryGrid.JobIDs = Properties.Jobs;
  67. SummaryGrid.SupplierIDs = Properties.Suppliers;
  68. }
  69. public void Shutdown(CancelEventArgs? cancel)
  70. {
  71. }
  72. public void Refresh()
  73. {
  74. _refresh = true;
  75. if (_loadedGroups)
  76. {
  77. SummaryGrid.Refresh(false,true);
  78. }
  79. }
  80. public StockSummaryProperties Properties { get; set; }
  81. private void DoLoadSettings()
  82. {
  83. Properties = LoadSettings?.Invoke(this) ?? new StockSummaryProperties();
  84. }
  85. private void DoSaveSettings()
  86. {
  87. SaveSettings?.Invoke(this, Properties);
  88. }
  89. public event LoadSettings<StockSummaryProperties>? LoadSettings;
  90. public event SaveSettings<StockSummaryProperties>? SaveSettings;
  91. private void SplitPanel_OnOnChanged(object sender, DynamicSplitPanelSettings e)
  92. {
  93. if (EventSuppressor.IsSet(Suppress.This))
  94. return;
  95. Properties.SplitPanelSettings = e;
  96. DoSaveSettings();
  97. }
  98. private void SummaryGrid_OnBeforeRefresh(object sender, BeforeRefreshEventArgs args)
  99. {
  100. //Progress.Show("Loading");
  101. ProductGroups.IsEnabled = false;
  102. JobGrid.IsEnabled = false;
  103. SupplierGrid.IsEnabled = false;
  104. }
  105. private void SummaryGrid_OnAfterRefresh(object sender, AfterRefreshEventArgs args)
  106. {
  107. //Progress.Close();
  108. ProductGroups.IsEnabled = true;
  109. JobGrid.IsEnabled = true;
  110. SupplierGrid.IsEnabled = true;
  111. }
  112. private void DetailSplitPanel_OnChanged(object sender, DynamicSplitPanelSettings e)
  113. {
  114. }
  115. private void ProductGroups_GroupSelectionChanged(HashSet<Guid> selected)
  116. {
  117. if (EventSuppressor.IsSet(Suppress.This))
  118. return;
  119. Properties.ProductGroups = ProductGroups.GetSelectedGroups(false).ToArray();
  120. DoSaveSettings();
  121. SummaryGrid.GroupIDs = ProductGroups.GetSelectedGroups(true).ToArray();
  122. SummaryGrid.Refresh(false, true);
  123. }
  124. private void SupplierGrid_SelectionChanged(HashSet<Guid> selected)
  125. {
  126. if (EventSuppressor.IsSet(Suppress.This))
  127. return;
  128. Properties.Suppliers = selected.ToArray();
  129. DoSaveSettings();
  130. SummaryGrid.SupplierIDs = Properties.Suppliers;
  131. SummaryGrid.Refresh(false, true);
  132. }
  133. private void JobGrid_SelectionChanged(HashSet<Guid> selected)
  134. {
  135. if (EventSuppressor.IsSet(Suppress.This))
  136. return;
  137. Properties.Jobs = selected.ToArray();
  138. DoSaveSettings();
  139. SummaryGrid.JobIDs = Properties.Jobs;
  140. SummaryGrid.Refresh(false, true);
  141. }
  142. private void ProductGroups_AfterRefresh(object sender, AfterRefreshEventArgs args)
  143. {
  144. SummaryGrid.GroupIDs = ProductGroups.GetSelectedGroups(true).ToArray();
  145. _loadedGroups = true;
  146. if (_refresh)
  147. {
  148. Refresh();
  149. }
  150. }
  151. private void FreeStockCheckBox_Checked(object sender, RoutedEventArgs e)
  152. {
  153. if (EventSuppressor.IsSet(Suppress.This))
  154. return;
  155. Properties.IncludeFreeStock = FreeStockCheckBox.IsChecked == true;
  156. SummaryGrid.IncludeFreeStock = Properties.IncludeFreeStock;
  157. SummaryGrid.Refresh(false, true);
  158. }
  159. }