using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Windows; using System.Windows.Controls; using Comal.Classes; using InABox.Configuration; using InABox.Core; using InABox.DynamicGrid; using InABox.WPF; namespace PRSDesktop; public partial class StockSummaryControl : UserControl { private bool _loadedGroups = false; private bool _refresh = false; private enum Suppress { This } public StockSummaryControl() { using (new EventSuppressor(Suppress.This)) InitializeComponent(); } public void Setup() { using (new EventSuppressor(Suppress.This)) { DoLoadSettings(); SplitPanel.View = Properties.SplitPanelSettings.View; SplitPanel.AnchorWidth = Properties.SplitPanelSettings.AnchorWidth; SplitPanel.DetailHeight = Properties.SplitPanelSettings.DetailHeight; InitialiseSelectors(); SummaryGrid.Refresh(true, false); } } private void InitialiseSelectors() { ProductGroups.SelectedIDs = Properties.ProductGroups.ToHashSet(); SupplierGrid.SelectedIDs = Properties.Suppliers.ToHashSet(); JobGrid.SelectedIDs = Properties.Jobs.ToHashSet(); ProductGroups.FilterComponent.SetSettings(Properties.ProductGroupFilter, false); ProductGroups.FilterComponent.OnFiltersSelected += (filters) => { Properties.ProductGroupFilter = filters; DoSaveSettings(); }; SupplierGrid.FilterComponent.SetSettings(Properties.SupplierFilter, false); SupplierGrid.FilterComponent.OnFiltersSelected += (filters) => { Properties.SupplierFilter = filters; DoSaveSettings(); }; JobGrid.FilterComponent.SetSettings(Properties.JobFilter, false); JobGrid.FilterComponent.OnFiltersSelected += (filters) => { Properties.JobFilter = filters; DoSaveSettings(); }; ProductGroups.Refresh(true, true); SupplierGrid.Refresh(true, true); JobGrid.Refresh(true, true); SummaryGrid.JobIDs = Properties.Jobs; SummaryGrid.SupplierIDs = Properties.Suppliers; } public void Shutdown(CancelEventArgs? cancel) { } public void Refresh() { _refresh = true; if (_loadedGroups) { SummaryGrid.Refresh(false,true); } } public StockSummaryProperties Properties { get; set; } private void DoLoadSettings() { Properties = LoadSettings?.Invoke(this) ?? new StockSummaryProperties(); } private void DoSaveSettings() { SaveSettings?.Invoke(this, Properties); } public event LoadSettings? LoadSettings; public event SaveSettings? SaveSettings; private void SplitPanel_OnOnChanged(object sender, DynamicSplitPanelSettings e) { if (EventSuppressor.IsSet(Suppress.This)) return; Properties.SplitPanelSettings = e; DoSaveSettings(); } private void SummaryGrid_OnBeforeRefresh(object sender, BeforeRefreshEventArgs args) { //Progress.Show("Loading"); ProductGroups.IsEnabled = false; JobGrid.IsEnabled = false; SupplierGrid.IsEnabled = false; } private void SummaryGrid_OnAfterRefresh(object sender, AfterRefreshEventArgs args) { //Progress.Close(); ProductGroups.IsEnabled = true; JobGrid.IsEnabled = true; SupplierGrid.IsEnabled = true; } private void DetailSplitPanel_OnChanged(object sender, DynamicSplitPanelSettings e) { } private void ProductGroups_GroupSelectionChanged(HashSet selected) { if (EventSuppressor.IsSet(Suppress.This)) return; Properties.ProductGroups = ProductGroups.GetSelectedGroups(false).ToArray(); DoSaveSettings(); SummaryGrid.GroupIDs = ProductGroups.GetSelectedGroups(true).ToArray(); SummaryGrid.Refresh(false, true); } private void SupplierGrid_SelectionChanged(HashSet selected) { if (EventSuppressor.IsSet(Suppress.This)) return; Properties.Suppliers = selected.ToArray(); DoSaveSettings(); SummaryGrid.SupplierIDs = Properties.Suppliers; SummaryGrid.Refresh(false, true); } private void JobGrid_SelectionChanged(HashSet selected) { if (EventSuppressor.IsSet(Suppress.This)) return; Properties.Jobs = selected.ToArray(); DoSaveSettings(); SummaryGrid.JobIDs = Properties.Jobs; SummaryGrid.Refresh(false, true); } private void ProductGroups_AfterRefresh(object sender, AfterRefreshEventArgs args) { SummaryGrid.GroupIDs = ProductGroups.GetSelectedGroups(true).ToArray(); _loadedGroups = true; if (_refresh) { Refresh(); } } }