浏览代码

Added job, supplier and procut group trees to stock summary

Kenric Nugteren 1 年之前
父节点
当前提交
45e6c6d9b7

+ 30 - 3
prs.desktop/Panels/StockSummary/StockSummaryControl.xaml

@@ -4,6 +4,7 @@
              xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
              xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
              xmlns:local="clr-namespace:PRSDesktop"
+             xmlns:stk="clr-namespace:PRSDesktop.Panels.StockSummary"
              xmlns:dynamicGrid="clr-namespace:InABox.DynamicGrid;assembly=InABox.Wpf"
              mc:Ignorable="d"
              d:DesignHeight="900" d:DesignWidth="1000">
@@ -20,7 +21,9 @@
         </dynamicGrid:DynamicSplitPanel.Header>
 
         <dynamicGrid:DynamicSplitPanel.Master>
-            <local:ProductGroupTree x:Name="ProductGroups"/>
+            <local:StockSummaryProductGroupTree x:Name="ProductGroups"
+                                                SelectionChanged="ProductGroups_GroupSelectionChanged"
+                                                AfterRefresh="ProductGroups_AfterRefresh"/>
         </dynamicGrid:DynamicSplitPanel.Master>
     
         <dynamicGrid:DynamicSplitPanel.Detail>
@@ -41,11 +44,35 @@
                 </dynamicGrid:DynamicSplitPanel.Master>
                 
                 <dynamicGrid:DynamicSplitPanel.Detail>
-                    <local:ProductGroupSelector x:Name="GroupSelector" SettingsChanged="GroupSelector_OnSettingsChanged" SelectionChanged="GroupSelector_OnSelectionChanged"/>
+                    <Grid>
+                        <Grid.RowDefinitions>
+                            <RowDefinition Height="Auto"/>
+                            <RowDefinition Height="*"/>
+                        </Grid.RowDefinitions>
+                        <Border BorderBrush="DimGray" BorderThickness="0.75"
+                                Grid.Row="0" Margin="0,0,0,2">
+                            <Label Content="Suppliers" HorizontalContentAlignment="Center"/>
+                        </Border>
+                        <stk:StockSummarySupplierGrid x:Name="SupplierGrid"
+                                                      Grid.Row="1"
+                                                      SelectionChanged="SupplierGrid_SelectionChanged"/>
+                    </Grid>
                 </dynamicGrid:DynamicSplitPanel.Detail>
         
                 <dynamicGrid:DynamicSplitPanel.SecondaryDetail>
-                    <local:JobSelector x:Name="JobSelector" SettingsChanged="JobSelector_OnSettingsChanged" SelectionChanged="JobSelector_OnSelectionChanged" />
+                    <Grid>
+                        <Grid.RowDefinitions>
+                            <RowDefinition Height="Auto"/>
+                            <RowDefinition Height="*"/>
+                        </Grid.RowDefinitions>
+                        <Border BorderBrush="DimGray" BorderThickness="0.75"
+                                Grid.Row="0" Margin="0,0,0,2">
+                            <Label Content="Jobs" HorizontalContentAlignment="Center"/>
+                        </Border>
+                        <stk:StockSummaryJobGrid x:Name="JobGrid"
+                                                 Grid.Row="1"
+                                                 SelectionChanged="JobGrid_SelectionChanged"/>
+                    </Grid>
                 </dynamicGrid:DynamicSplitPanel.SecondaryDetail>
                 
             </dynamicGrid:DynamicSplitPanel>

+ 92 - 53
prs.desktop/Panels/StockSummary/StockSummaryControl.xaml.cs

@@ -1,6 +1,10 @@
+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;
@@ -10,6 +14,8 @@ namespace PRSDesktop;
 
 public partial class StockSummaryControl : UserControl
 {
+    private bool _loadedGroups = false;
+    private bool _refresh = false;
 
     private enum Suppress
     {
@@ -31,23 +37,48 @@ public partial class StockSummaryControl : UserControl
             SplitPanel.View = Properties.SplitPanelSettings.View;
             SplitPanel.AnchorWidth = Properties.SplitPanelSettings.AnchorWidth;
             SplitPanel.DetailHeight = Properties.SplitPanelSettings.DetailHeight;
-            
-            GroupSelector.Settings = Properties.GroupSettings;
-            GroupSelector.Setup();
-            GroupSelector.Selection = Properties.GroupSelection;
-            SummaryGrid.GroupIDs = Properties.GroupSelection.Groups;
-            
-            JobSelector.Settings = Properties.JobSettings;
-            JobSelector.Setup();
-            JobSelector.Selection = Properties.JobSelection;
-            SummaryGrid.JobIDs = Properties.JobSelection.Jobs;
 
+            InitialiseSelectors();
+            
             SummaryGrid.Refresh(true, false);
-
-            ProductGroups.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)
     {
         
@@ -55,8 +86,11 @@ public partial class StockSummaryControl : UserControl
 
     public void Refresh()
     {
-        SummaryGrid.Refresh(false,true);
-        ProductGroups.Refresh(false, true);
+        _refresh = true;
+        if (_loadedGroups)
+        {
+            SummaryGrid.Refresh(false,true);
+        }
     }
 
     public StockSummaryProperties Properties { get; set; }
@@ -74,75 +108,80 @@ public partial class StockSummaryControl : UserControl
     public event LoadSettings<StockSummaryProperties>? LoadSettings;
     
     public event SaveSettings<StockSummaryProperties>? SaveSettings;
-
-    private void GroupSelector_OnSettingsChanged(object sender, ProductGroupSelectorSettingsChangedArgs args)
+    
+    private void SplitPanel_OnOnChanged(object sender, DynamicSplitPanelSettings e)
     {
         if (EventSuppressor.IsSet(Suppress.This))
             return;
-            
-        Properties.GroupSettings = args.Settings;
+        
+        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 GroupSelector_OnSelectionChanged(object sender, ProductGroupSelectorSelectionChangedArgs args)
+    private void SummaryGrid_OnAfterRefresh(object sender, AfterRefreshEventArgs args)
     {
-        if (EventSuppressor.IsSet(Suppress.This))
-            return;
-            
-        Properties.GroupSelection = args.Selection;
-        DoSaveSettings();
-            
-        SummaryGrid.GroupIDs = args.Selection.Groups;
-        SummaryGrid.Refresh(false, true);
+        //Progress.Close();
+        ProductGroups.IsEnabled = true;
+        JobGrid.IsEnabled = true;
+        SupplierGrid.IsEnabled = true;
     }
 
-    private void JobSelector_OnSettingsChanged(object sender, JobSelectorSettingsChangedArgs args)
+    private void DetailSplitPanel_OnChanged(object sender, DynamicSplitPanelSettings e)
+    {
+
+    }
+
+    private void ProductGroups_GroupSelectionChanged(HashSet<Guid> selected)
     {
         if (EventSuppressor.IsSet(Suppress.This))
             return;
-            
-        Properties.JobSettings = args.Settings;
+
+        Properties.ProductGroups = ProductGroups.GetSelectedGroups(false).ToArray();
         DoSaveSettings();
-            
+
+        SummaryGrid.GroupIDs = ProductGroups.GetSelectedGroups(true).ToArray();
+        SummaryGrid.Refresh(false, true);
     }
 
-    private void JobSelector_OnSelectionChanged(object sender, JobSelectorSelectionChangedArgs args)
+    private void SupplierGrid_SelectionChanged(HashSet<Guid> selected)
     {
         if (EventSuppressor.IsSet(Suppress.This))
             return;
         
-        Properties.JobSelection = args.Selection;
+        Properties.Suppliers = selected.ToArray();
         DoSaveSettings();
         
-        SummaryGrid.JobIDs = args.Selection.Jobs;
+        SummaryGrid.SupplierIDs = Properties.Suppliers;
         SummaryGrid.Refresh(false, true);
     }
-    
-    private void SplitPanel_OnOnChanged(object sender, DynamicSplitPanelSettings e)
+
+    private void JobGrid_SelectionChanged(HashSet<Guid> selected)
     {
         if (EventSuppressor.IsSet(Suppress.This))
             return;
         
-        Properties.SplitPanelSettings = e;
+        Properties.Jobs = selected.ToArray();
         DoSaveSettings();
-    }
-    
-    private void SummaryGrid_OnBeforeRefresh(object sender, BeforeRefreshEventArgs args)
-    {
-        //Progress.Show("Loading");
-        GroupSelector.IsEnabled = false;
-        JobSelector.IsEnabled = false;
-    }
-
-    private void SummaryGrid_OnAfterRefresh(object sender, AfterRefreshEventArgs args)
-    {
-        //Progress.Close();
-        GroupSelector.IsEnabled = true;
-        JobSelector.IsEnabled = true;
+        
+        SummaryGrid.JobIDs = Properties.Jobs;
+        SummaryGrid.Refresh(false, true);
     }
 
-    private void DetailSplitPanel_OnChanged(object sender, DynamicSplitPanelSettings e)
+    private void ProductGroups_AfterRefresh(object sender, AfterRefreshEventArgs args)
     {
-
+        SummaryGrid.GroupIDs = ProductGroups.GetSelectedGroups(true).ToArray();
+        _loadedGroups = true;
+        if (_refresh)
+        {
+            Refresh();
+        }
     }
 }

+ 9 - 2
prs.desktop/Panels/StockSummary/StockSummaryGrid.cs

@@ -28,6 +28,7 @@ public class StockSummaryGrid : DynamicDataGrid<StockSummary>, IDataModelSource
     
     public Guid[] GroupIDs { get; set; }
     public Guid[] JobIDs { get; set; }
+    public Guid[] SupplierIDs { get; set; }
 
     private StockSummaryMinimumStockBehaviour MinStockBehaviour { get; set; }
     
@@ -36,8 +37,9 @@ public class StockSummaryGrid : DynamicDataGrid<StockSummary>, IDataModelSource
 
         ColumnsTag = "StockSummaryGrid";
 
-        GroupIDs = new Guid[] { };
-        JobIDs = new Guid[] { };
+        GroupIDs = Array.Empty<Guid>();
+        JobIDs = Array.Empty<Guid>();
+        SupplierIDs = Array.Empty<Guid>();
         
         HiddenColumns.Add(x => x.Product.ID);
         HiddenColumns.Add(x => x.Product.Issues);
@@ -336,6 +338,11 @@ public class StockSummaryGrid : DynamicDataGrid<StockSummary>, IDataModelSource
             : new Filter<StockSummary>(x => x.Job.ID).InList(JobIDs);
         filters.Add(jobFilter.Or(x => x.Job.ID).IsEqualTo(Guid.Empty));
 
+        var supplierFilter = !SupplierIDs.Any()
+            ? new Filter<StockSummary>().None()
+            : new Filter<StockSummary>(x => x.Product.Supplier.SupplierLink.ID).InList(SupplierIDs);
+        filters.Add(supplierFilter.Or(x => x.Product.Supplier.SupplierLink.ID).IsEqualTo(Guid.Empty));
+
         //Filter<StockSummary> _productfilter = new Filter<StockSummary>(x => x.Product.ID).IsNotEqualTo(Guid.Empty);
         //filters.Add(_productfilter);
 

+ 34 - 0
prs.desktop/Panels/StockSummary/StockSummaryJobGrid.cs

@@ -0,0 +1,34 @@
+using Comal.Classes;
+using InABox.Core;
+using InABox.DynamicGrid;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Media.Imaging;
+
+namespace PRSDesktop.Panels.StockSummary;
+
+public class StockSummaryJobGrid : DynamicSelectorGrid<Job>, ISpecificGrid
+{
+    public StockSummaryJobGrid() : base(DynamicActionColumnPosition.Start)
+    {
+        ColumnsTag = "StockSummaryJobSelector";
+    }
+
+    protected override void DoReconfigure(FluentList<DynamicGridOption> options)
+    {
+        base.DoReconfigure(options);
+
+        options.AddRange(DynamicGridOption.FilterRows);
+    }
+
+    public override DynamicGridColumns GenerateColumns()
+    {
+        var columns = new DynamicGridColumns();
+        columns.Add<Job, string>(x => x.JobNumber, 120, "Number", "", Alignment.MiddleLeft);
+        columns.Add<Job, string>(x => x.Name, 0, "Name", "", Alignment.MiddleLeft);
+        return columns;
+    }
+}

+ 55 - 0
prs.desktop/Panels/StockSummary/StockSummaryProductGroupTree.cs

@@ -0,0 +1,55 @@
+using Comal.Classes;
+using InABox.Core;
+using InABox.DynamicGrid;
+using InABox.WPF;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Media.Imaging;
+
+namespace PRSDesktop;
+
+public class StockSummaryProductGroupTree : DynamicSelectorGrid<ProductGroup>, ISpecificGrid
+{
+    public StockSummaryProductGroupTree() : base(DynamicActionColumnPosition.End)
+    {
+        ColumnsTag = "StockSummaryProductGroupSelector";
+    }
+
+    public override DynamicGridColumns GenerateColumns()
+    {
+        var columns = new DynamicGridColumns();
+        columns.Add<ProductGroup, string>(x => x.Description, 0, "Description", "", Alignment.MiddleLeft);
+        return columns;
+    }
+
+    public IEnumerable<Guid> GetSelectedGroups(bool recursive) => 
+        recursive
+            ? SelectedIDs.SelectMany(x => UIComponent.GetChildren(x).Select(x => x.Get<ProductGroup, Guid>(x => x.ID)))
+            : SelectedIDs;
+
+    private DynamicGridTreeUIComponent<ProductGroup>? _uiComponent;
+    private DynamicGridTreeUIComponent<ProductGroup> UIComponent
+    {
+        get
+        {
+            if(_uiComponent is null)
+            {
+                _uiComponent = new DynamicGridTreeUIComponent<ProductGroup>(
+                    x => x.ID,
+                    x => x.Parent.ID)
+                {
+                    Parent = this,
+                    ExpandMode = DynamicTreeGridExpandMode.All
+                };
+            }
+            return _uiComponent;
+        }
+    }
+    protected override IDynamicGridUIComponent<ProductGroup> CreateUIComponent()
+    {
+        return UIComponent;
+    }
+}

+ 24 - 27
prs.desktop/Panels/StockSummary/StockSummaryProperties.cs

@@ -1,35 +1,32 @@
 using InABox.Configuration;
 using InABox.DynamicGrid;
+using System;
 
-namespace PRSDesktop
+namespace PRSDesktop;
+
+public class StockSummaryProperties : IUserConfigurationSettings, IDashboardProperties
 {
-    public class StockSummaryProperties : IUserConfigurationSettings, IDashboardProperties
+    public Guid[] Jobs { get; set; } = Array.Empty<Guid>();
+
+    public DynamicGridSelectedFilterSettings JobFilter { get; set; } = new();
+
+    public Guid[] Suppliers { get; set; } = Array.Empty<Guid>();
+
+    public DynamicGridSelectedFilterSettings SupplierFilter { get; set; } = new();
+
+    public Guid[] ProductGroups { get; set; } = Array.Empty<Guid>();
+
+    public DynamicGridSelectedFilterSettings ProductGroupFilter { get; set; } = new();
+
+    public DynamicSplitPanelSettings SplitPanelSettings { get; set; } = new();
+    
+    public StockSummaryProperties()
     {
-        public JobSelectorSettings JobSettings { get; set; }
-        
-        public JobSelectorData JobSelection { get; set; }
-        
-        public ProductGroupSelectorSettings GroupSettings { get; set; }
-        
-        public ProductGroupSelectorData  GroupSelection { get; set; }
-        
-        public DynamicSplitPanelSettings SplitPanelSettings { get; set; }
-        
-        public StockSummaryProperties()
+        SplitPanelSettings = new DynamicSplitPanelSettings()
         {
-            JobSettings = new JobSelectorSettings();
-            JobSelection = new JobSelectorData();
-            
-            GroupSettings = new ProductGroupSelectorSettings();
-            GroupSelection = new ProductGroupSelectorData();
-
-            SplitPanelSettings = new DynamicSplitPanelSettings()
-            {
-                View = DynamicSplitPanelView.Combined,
-                AnchorWidth = 350,
-                DetailHeight = 500
-
-            };
-        }
+            View = DynamicSplitPanelView.Combined,
+            AnchorWidth = 350,
+            DetailHeight = 500
+        };
     }
 }

+ 33 - 0
prs.desktop/Panels/StockSummary/StockSummarySupplierGrid.cs

@@ -0,0 +1,33 @@
+using Comal.Classes;
+using InABox.Core;
+using InABox.DynamicGrid;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace PRSDesktop.Panels.StockSummary;
+
+public class StockSummarySupplierGrid : DynamicSelectorGrid<Supplier>, ISpecificGrid
+{
+    public StockSummarySupplierGrid() : base(DynamicActionColumnPosition.Start)
+    {
+        ColumnsTag = "StockSummarySupplierSelector";
+    }
+
+    protected override void DoReconfigure(FluentList<DynamicGridOption> options)
+    {
+        base.DoReconfigure(options);
+
+        options.AddRange(DynamicGridOption.FilterRows);
+    }
+
+    public override DynamicGridColumns GenerateColumns()
+    {
+        var columns = new DynamicGridColumns();
+        columns.Add<Supplier, string>(x => x.Code, 120, "Code", "", Alignment.MiddleCenter);
+        columns.Add<Supplier, string>(x => x.Name, 0, "Name", "", Alignment.MiddleLeft);
+        return columns;
+    }
+}