Browse Source

Fix to onchanged getting called for dimensions editor.
Products panel disables while refreshing.

Kenric Nugteren 1 year ago
parent
commit
1c1fe15b1a

+ 2 - 1
prs.desktop/Panels/Products/Master List/ProductsPanel.xaml

@@ -19,7 +19,8 @@
         </dynamicgrid:DynamicSplitPanel.Header>
 
         <dynamicgrid:DynamicSplitPanel.Master>
-            <local:ProductsGrid Grid.Column="0" Grid.Row="1" Grid.RowSpan="2" x:Name="Products" />
+            <local:ProductsGrid Grid.Column="0" Grid.Row="1" Grid.RowSpan="2" x:Name="Products"
+                                AfterRefresh="Products_AfterRefresh"/>
         </dynamicgrid:DynamicSplitPanel.Master>
 
         <dynamicgrid:DynamicSplitPanel.Detail>

+ 6 - 0
prs.desktop/Panels/Products/Master List/ProductsPanel.xaml.cs

@@ -84,6 +84,7 @@ namespace PRSDesktop
 
         public void Refresh()
         {
+            ProductDetails.IsEnabled = false;
             Products.Refresh(false, true);
             //RefreshSubPage(ProductDetails.SelectedContent as IProductGrid);
         }
@@ -163,6 +164,11 @@ namespace PRSDesktop
             return env;
         }
 
+        private void Products_AfterRefresh(object sender, AfterRefreshEventArgs args)
+        {
+            ProductDetails.IsEnabled = true;
+        }
+
         private void RefreshSubPage(IProductControl control)
         {
             if (SplitPanel.View == DynamicSplitPanelView.Master)

+ 28 - 8
prs.shared/Editors/Dimensions/DimensionsEditorControl.cs

@@ -123,7 +123,7 @@ namespace PRS.Shared
 
         private void UpdateColumn(int column, bool visible, DoubleTextBox box)
         {
-            if (!visible)
+            if (!visible && box.Value != 0.0 && box.Value != null)
             {
                 box.Value = 0.0;
             }
@@ -180,8 +180,30 @@ namespace PRS.Shared
             return box;
         }
 
+        private TUnit? GetSelectedUnit()
+        {
+            if (Combo.SelectedValue is not Guid unitID) return null;
+            if (Combo.SelectedItem is not Tuple<string, TUnit> tuple) return null;
+            return tuple.Item2;
+        }
+        private bool IsBoxVisible(DoubleTextBox box)
+        {
+            var unit = GetSelectedUnit();
+            if (unit is null) return false;
+
+            if (box == QuantityBox) return unit.HasQuantity;
+            if (box == LengthBox) return unit.HasLength;
+            if (box == WidthBox) return unit.HasWidth;
+            if (box == HeightBox) return unit.HasHeight;
+            if (box == WeightBox) return unit.HasWeight;
+
+            return false;
+        }
+
         private void Box_ValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
         {
+            // Don't trigger value changed if invisible, this will have been handled by the SelectionChanged event handler.
+            if (d is not DoubleTextBox box || !IsBoxVisible(box)) return;
             CheckChanged();
         }
 
@@ -239,19 +261,17 @@ namespace PRS.Shared
             if (!property.StartsWith($"{ColumnName}.")) return;
             property = property[(ColumnName.Length + 1)..];
 
-            if (value is null) return;
-
             if (property == "Unit.ID")
             {
                 Combo.SelectedValue = value is Guid guid ? guid : Guid.Empty;
                 return;
             }
 
-            if (property == "Quantity") QuantityBox.Value = (double)value;
-            if (property == "Length") LengthBox.Value = (double)value;
-            if (property == "Width") WidthBox.Value = (double)value;
-            if (property == "Height") HeightBox.Value = (double)value;
-            if (property == "Weight") WeightBox.Value = (double)value;
+            if (property == "Quantity") QuantityBox.Value = (double)(value ?? 0.0);
+            if (property == "Length") LengthBox.Value = (double)(value ?? 0.0);
+            if (property == "Width") WidthBox.Value = (double)(value ?? 0.0);
+            if (property == "Height") HeightBox.Value = (double)(value ?? 0.0);
+            if (property == "Weight") WeightBox.Value = (double)(value ?? 0.0);
         }
 
     }