123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187 |
- 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<StockSummaryProperties>? LoadSettings;
-
- public event SaveSettings<StockSummaryProperties>? 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<Guid> 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<Guid> 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<Guid> 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();
- }
- }
- }
|