瀏覽代碼

Merged stock relocation windows and Stock selection page

Kenric Nugteren 1 年之前
父節點
當前提交
e1e8a7decf

+ 29 - 0
prs.desktop/Panels/Products/Locations/StockHoldingRelocationGrid.cs

@@ -0,0 +1,29 @@
+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.Products.Locations;
+
+public class StockHoldingRelocationItem : JobRequisitionItemSelectionItem
+{
+    public string ItemNumber { get; set; }
+
+    public string Text { get; set; }
+}
+
+public class StockHoldingRelocationGrid : JobRequisitionItemSelectionGrid<StockHoldingRelocationItem>
+{
+    public override DynamicGridColumns GenerateColumns()
+    {
+        var columns = new DynamicGridColumns();
+
+        columns.Add<StockHoldingRelocationItem, string>(x => x.ItemNumber, 0, "#", "", Alignment.MiddleLeft);
+        columns.Add<StockHoldingRelocationItem, string>(x => x.Text, 0, "Description", "", Alignment.MiddleLeft);
+
+        return columns;
+    }
+}

+ 2 - 185
prs.desktop/Panels/Products/Locations/StockHoldingRelocationWindow.xaml

@@ -154,192 +154,9 @@
                 VerticalContentAlignment="Center"
                 Background="WhiteSmoke"/>
         </Grid>
-        
-        <Border 
-            Grid.Row="1"
-            Margin="5,0,5,5" 
-            BorderBrush="Silver" 
-            BorderThickness="0.75" >
-            
-            <ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Hidden">
-                
-                <Grid>
-                    <Grid.RowDefinitions>
-                        <RowDefinition Height="40"/>
-                        <RowDefinition Height="*"/>
-                        <RowDefinition Height="40"/>
-                    </Grid.RowDefinitions>
-                    
-                    <Grid Grid.Row="0" Background="Silver">
-                        <Grid.ColumnDefinitions>
-                            <ColumnDefinition Width="30"/>
-                            <ColumnDefinition Width="*"/>
-                            <ColumnDefinition Width="60"/>
-                            <ColumnDefinition Width="50"/>
-                            <ColumnDefinition Width="30"/>
-                            <ColumnDefinition Width="60"/>
-                            <ColumnDefinition Width="30"/>
-                            <ColumnDefinition Width="50"/>
-                        </Grid.ColumnDefinitions>
-                        <Label Grid.Column="0" Content="#" HorizontalContentAlignment="Center" FontWeight="Bold" VerticalContentAlignment="Center" />
-                        <Label Grid.Column="1" Content="Description" HorizontalContentAlignment="Center" FontWeight="Bold" VerticalContentAlignment="Center" />
-                        <Label Grid.Column="2" Content="Total" HorizontalContentAlignment="Center" FontWeight="Bold" VerticalContentAlignment="Center" />
-                        <Label Grid.Column="5" Content="Quantity" HorizontalContentAlignment="Center" FontWeight="Bold" VerticalContentAlignment="Center" />
-                    </Grid>
-            
-                    <ItemsControl 
-                        ItemsSource="{Binding Items}"
-                        Grid.Row="1">
-                        <ItemsControl.ItemTemplate>
-                            <DataTemplate DataType="local:StockHoldingRelocationItem">
-                                
-                                <Border 
-                                    BorderBrush="LightGray" 
-                                    BorderThickness="0,0,0,0.75" 
-                                    Padding="5">
-                                    
-                                    <Grid>
-                                        <Grid.ColumnDefinitions>
-                                            <ColumnDefinition Width="30"/>
-                                            <ColumnDefinition Width="*"/>
-                                            <ColumnDefinition Width="60"/>
-                                            <ColumnDefinition Width="50"/>
-                                            <ColumnDefinition Width="30"/>
-                                            <ColumnDefinition Width="60"/>
-                                            <ColumnDefinition Width="30"/>
-                                            <ColumnDefinition Width="50"/>
-                                        </Grid.ColumnDefinitions>
-                                        
-                                        <Grid.RowDefinitions>
-                                            <RowDefinition Height="30" />
-                                        </Grid.RowDefinitions>
-                                        
-                                        <Label 
-                                            Grid.Column="0" 
-                                            Content="{Binding ItemNumber}" 
-                                            FontWeight="Bold"
-                                            VerticalAlignment="Center"/>
-                                        
-                                        <TextBlock
-                                            Grid.Column="1" 
-                                            VerticalAlignment="Center"
-                                            Text="{Binding Text}"
-                                            TextWrapping="NoWrap"
-                                            TextTrimming="CharacterEllipsis"
-                                            Margin="5,0,0,0"/>
-                                        
-                                        <syncfusion:DoubleTextBox 
-                                            Grid.Column="2" 
-                                            Value="{Binding Quantity}" 
-                                            IsEnabled="{Binding Editable}"
-                                            IsReadOnly="True"
-                                            HorizontalContentAlignment="Center"
-                                            VerticalAlignment="Stretch"
-                                            VerticalContentAlignment="Center"
-                                            Margin="5,0,0,0"
-                                            Background="WhiteSmoke"/>
-                                        
-                                        <Button 
-                                            Grid.Column="3" 
-                                            Content="None" 
-                                            Tag="{Binding}" 
-                                            Click="None_Click"
-                                            IsEnabled="{Binding Editable}"
-                                            Margin="5,0,0,0"/>
-                                        
-                                        <Button 
-                                            Grid.Column="4" 
-                                            Content="-" 
-                                            Tag="{Binding}" 
-                                            Click="Minus_Click"
-                                            IsEnabled="{Binding Editable}"
-                                            Margin="5,0,0,0"/>
-                                        
-                                        <syncfusion:DoubleTextBox 
-                                            Grid.Column="5" 
-                                            Value="{Binding Issued}" 
-                                            MinValue="0" 
-                                            MaxValue="{Binding MaxValue}"
-                                            HorizontalContentAlignment="Center"
-                                            VerticalAlignment="Stretch"
-                                            VerticalContentAlignment="Center"
-                                            Margin="5,0,0,0"
-                                            IsEnabled="{Binding Editable}"
-                                            Background="LightYellow"/>
-                                        
-                                        <Button 
-                                            Grid.Column="6" 
-                                            Content="+" 
-                                            Tag="{Binding}" 
-                                            Click="Plus_Click"
-                                            IsEnabled="{Binding Editable}"
-                                            Margin="5,0,0,0"/>
-                                        
-                                        <Button 
-                                            Grid.Column="7" 
-                                            Content="All" 
-                                            Tag="{Binding}" 
-                                            Click="All_Click"
-                                            IsEnabled="{Binding Editable}"
-                                            Margin="5,0,0,0"/>
-                                        
-                                    </Grid>
-                                </Border>
-                            </DataTemplate>
-                        </ItemsControl.ItemTemplate>
-                        <ItemsControl.ItemsPanel>
-                            <ItemsPanelTemplate>
-                                <StackPanel/>
-                            </ItemsPanelTemplate>
-                        </ItemsControl.ItemsPanel>
-                    </ItemsControl>
-                    
-                    <Border Grid.Row="2" BorderBrush="Silver" BorderThickness="0,0.75,0,0" Background="WhiteSmoke">
-                        <Grid>
-                            <Grid.ColumnDefinitions>
-                                <ColumnDefinition Width="30"/>
-                                <ColumnDefinition Width="*"/>
-                                <ColumnDefinition Width="60"/>
-                                <ColumnDefinition Width="50"/>
-                                <ColumnDefinition Width="30"/>
-                                <ColumnDefinition Width="60"/>
-                                <ColumnDefinition Width="30"/>
-                                <ColumnDefinition Width="50"/>
-                            </Grid.ColumnDefinitions>
-                            
-                            <TextBlock 
-                                Grid.Column="0" 
-                                Grid.ColumnSpan="2" 
-                                Text="Total to Transfer/Issue" 
-                                FontWeight="Bold" 
-                                VerticalAlignment="Center" 
-                                Margin="5,0,0,0"/>
-                            
-                            <syncfusion:DoubleTextBox 
-                                Grid.Column="2" 
-                                Value="{Binding TotalQuantity}" 
-                                IsReadOnly="True"
-                                HorizontalContentAlignment="Center"
-                                VerticalAlignment="Stretch"
-                                VerticalContentAlignment="Center"
-                                Margin="0,5,5,5"
-                                Background="WhiteSmoke"/>
 
-                            <syncfusion:DoubleTextBox 
-                                Grid.Column="5"
-                                Value="{Binding TotalIssued}" 
-                                IsReadOnly="True"
-                                HorizontalContentAlignment="Center"
-                                VerticalAlignment="Stretch"
-                                VerticalContentAlignment="Center"
-                                Margin="0,5,5,5"
-                                Background="LightGreen"/>
-                        </Grid>
-                    </Border>
-                    
-                </Grid>
-            </ScrollViewer>
-        </Border>
+        <local:StockHoldingRelocationGrid x:Name="Grid" Grid.Row="1"/>
+
         <DockPanel Grid.Row="2" LastChildFill="False">
             <Button x:Name="CancelButton" Click="CancelButton_Click"
                     Content="Cancel"

+ 12 - 139
prs.desktop/Panels/Products/Locations/StockHoldingRelocationWindow.xaml.cs

@@ -21,82 +21,12 @@ using System.Windows.Shapes;
 
 namespace PRSDesktop.Panels.Products.Locations;
 
-public class StockHoldingRelocationItem : INotifyPropertyChanged
-{
-    public string ItemNumber { get; set; }
-
-    public string Text { get; set; }
-
-    public double Quantity { get; set; }
-
-    private double _issued;
-    public double Issued
-    {
-        get => _issued;
-        set
-        {
-            _issued = value;
-            OnPropertyChanged();
-        }
-    }
-
-    public double MaxValue { get; set; }
-
-    private bool _editable = true;
-    public bool Editable
-    {
-        get => _editable;
-        set
-        {
-            _editable = value;
-            OnPropertyChanged();
-        }
-    }
-
-    public Guid ID { get; set; }
-
-    public JobRequisitionItem JRI { get; set; }
-
-
-    public event PropertyChangedEventHandler? PropertyChanged;
-
-    protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null)
-    {
-        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
-    }
-}
 
 /// <summary>
 /// Interaction logic for StockHoldingRelocationWindow.xaml
 /// </summary>
 public partial class StockHoldingRelocationWindow : Window, INotifyPropertyChanged
 {
-    public ObservableCollection<StockHoldingRelocationItem> Items { get; set; } = new();
-
-    private double _totalQuantity;
-    public double TotalQuantity
-    {
-        get => _totalQuantity;
-        set
-        {
-            _totalQuantity = value;
-            OnPropertyChanged();
-        }
-    }
-
-
-    private double _totalIssued;
-    public double TotalIssued
-    {
-        get => _totalIssued;
-        set
-        {
-            _totalIssued = value;
-            OnPropertyChanged();
-            OnPropertyChanged(nameof(CanSave));
-        }
-    }
-
     public StockHolding From { get; private init; }
 
     public bool ShowHeader => ShowFrom || IsTargetEditable || IsJobEditable;
@@ -149,10 +79,8 @@ public partial class StockHoldingRelocationWindow : Window, INotifyPropertyChang
             OnPropertyChanged($"{nameof(Job)}.{nameof(Job.JobNumber)}");
             OnPropertyChanged($"{nameof(Job)}.{nameof(Job.Name)}");
 
-            SetObserving(false);
-
             var jobID = value?.ID ?? Guid.Empty;
-            foreach(var item in Items)
+            foreach(var item in Grid.Items)
             {
                 if(item.JRI.ID != Guid.Empty && item.JRI.Job.ID != jobID)
                 {
@@ -164,8 +92,6 @@ public partial class StockHoldingRelocationWindow : Window, INotifyPropertyChang
                     item.Editable = true;
                 }
             }
-
-            SetObserving(true);
         }
     }
 
@@ -184,7 +110,7 @@ public partial class StockHoldingRelocationWindow : Window, INotifyPropertyChang
         }
     }
 
-    public bool CanSave => (!IsTargetEditable || To is not null) && TotalIssued > 0;
+    public bool CanSave => (!IsTargetEditable || To is not null) && Grid.TotalIssued > 0;
 
     public StockHoldingRelocationWindow(StockHolding from, IEnumerable<JobRequisitionItem> items)
     {
@@ -195,27 +121,18 @@ public partial class StockHoldingRelocationWindow : Window, INotifyPropertyChang
         InitializeComponent();
 
         SetRequisitionItems(items);
-
-        Items.CollectionChanged += (o, e) => Recalculate();
     }
 
-    private bool _observing = false;
-    public void SetObserving(bool observing)
+    private void Grid_PropertyChanged(object sender, PropertyChangedEventArgs e)
     {
-        if(_observing != observing)
+        if(e.PropertyName == nameof(Grid.TotalIssued))
         {
-            _observing = observing;
-            if (_observing)
-            {
-                Recalculate();
-            }
+            OnPropertyChanged(nameof(CanSave));
         }
     }
 
     public void SetRequisitionItems(IEnumerable<JobRequisitionItem> items)
     {
-        SetObserving(false);
-
         var rItems = items.AsIList();
 
         var rIDs = rItems.Select(x => x.ID).Where(x => x != Guid.Empty).ToArray();
@@ -226,6 +143,7 @@ public partial class StockHoldingRelocationWindow : Window, INotifyPropertyChang
             .ToObjects<StockMovement>().GroupBy(x => x.JobRequisitionItem.ID).ToDictionary(x => x.Key, x => x.Sum(x => x.Units));
 
         var requidItems = new List<StockHoldingRelocationItem>();
+        var newItems = new List<StockHoldingRelocationItem>();
         foreach(var item in rItems)
         {
             var qty = item.ID != Guid.Empty ? quantities.GetValueOrDefault(item.ID) : item.Qty;
@@ -243,14 +161,12 @@ public partial class StockHoldingRelocationWindow : Window, INotifyPropertyChang
                 Text = item.ID == Guid.Empty
                     ? "Unrequisitioned Items"
                     : $"{item.Job.JobNumber}: {item.Requisition.Number} {item.Requisition.Description} ({qty})",
-                ID = item.ID,
                 JRI = item
             };
 
-            newItem.PropertyChanged += (o, e) => Recalculate();
             if(item.ID == Guid.Empty)
             {
-                Items.Add(newItem);
+                newItems.Add(newItem);
             }
             else
             {
@@ -262,29 +178,23 @@ public partial class StockHoldingRelocationWindow : Window, INotifyPropertyChang
         foreach(var item in requidItems)
         {
             item.ItemNumber = $"{i}. ";
-            Items.Add(item);
+            newItems.Add(item);
             ++i;
         }
-        SetObserving(true);
+
+        Grid.Items = newItems;
+        Grid.Refresh(true, true);
     }
 
     public Dictionary<Guid, double> GetQuantities()
     {
-        return Items.ToDictionary(x => x.ID, x => x.Issued);
+        return Grid.Items.ToDictionary(x => x.JRI.ID, x => x.Issued);
     }
     public StockLocation GetTargetLocation()
     {
         return To ?? new StockLocation();
     }
 
-    private void Recalculate()
-    {
-        if (!_observing) return;
-
-        TotalQuantity = Items.Sum(x => x.Quantity);
-        TotalIssued = Items.Sum(x => x.Issued);
-    }
-
     public event PropertyChangedEventHandler? PropertyChanged;
 
     protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null)
@@ -292,43 +202,6 @@ public partial class StockHoldingRelocationWindow : Window, INotifyPropertyChang
         PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
     }
 
-    #region Quantity Buttons
-
-    private void Minus_Click(object sender, RoutedEventArgs e)
-    {
-        if (sender is not FrameworkElement element || element.Tag is not StockHoldingRelocationItem item) return;
-
-        item.Issued = Math.Max(0, item.Issued - 1);
-    }
-
-    private void Plus_Click(object sender, RoutedEventArgs e)
-    {
-        if (sender is not FrameworkElement element || element.Tag is not StockHoldingRelocationItem item) return;
-
-        if(item.ID == Guid.Empty)
-        {
-            item.Issued += 1;
-        }
-        else
-        {
-            item.Issued = Math.Min(item.Issued + 1, item.Quantity);
-        }
-    }
-    private void None_Click(object sender, RoutedEventArgs e)
-    {
-        if (sender is not FrameworkElement element || element.Tag is not StockHoldingRelocationItem item) return;
-
-        item.Issued = 0;
-    }
-    private void All_Click(object sender, RoutedEventArgs e)
-    {
-        if (sender is not FrameworkElement element || element.Tag is not StockHoldingRelocationItem item) return;
-
-        item.Issued = Math.Max(0, item.Quantity);
-    }
-
-    #endregion
-
     #region Target Location
 
     private bool DoLookupLocation(string? column, string? value)

+ 1 - 1
prs.desktop/Panels/Reservation Management/JobRequisitionItemSelectionGrid.cs

@@ -21,7 +21,7 @@ using System.Windows.Controls;
 using System.Windows.Data;
 using System.Windows.Media;
 
-namespace PRSDesktop.Panels.Reservation_Management;
+namespace PRSDesktop;
 
 public class JobRequisitionItemSelectionItem : BaseObject
 {

+ 0 - 1
prs.desktop/Panels/Reservation Management/StockSelectionPage.xaml.cs

@@ -14,7 +14,6 @@ using InABox.Core;
 using InABox.DynamicGrid;
 using InABox.Wpf;
 using javax.swing;
-using PRSDesktop.Panels.Reservation_Management;
 
 namespace PRSDesktop;