|
@@ -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);
|
|
|
}
|
|
|
|
|
|
}
|