StockSummaryControl.xaml.cs 5.0 KB

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