瀏覽代碼

Improved interface for EnclosedEntity editor controls, by autoprefixing ColumnName to value access methods.

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

+ 6 - 15
prs.shared/Editors/CoreTime/CoreTimeEditorControl.cs

@@ -385,21 +385,15 @@ namespace PRS.Shared
             return int.MaxValue;
         }
 
-        public override Dictionary<string, object?> GetValues()
+        protected override IEnumerable<KeyValuePair<string, object?>> GetChildValues()
         {
-            return new Dictionary<string, object?>
-            {
-                { $"{ColumnName}.Start", Time.Start },
-                { $"{ColumnName}.Duration", Time.Duration },
-                { $"{ColumnName}.Finish", Time.Finish }
-            };
+            yield return new("Start", Time.Start);
+            yield return new("Duration", Time.Duration);
+            yield return new("Finish", Time.Finish);
         }
 
-        public override object? GetValue(string property)
+        protected override object? GetChildValue(string property)
         {
-            if (!property.StartsWith($"{ColumnName}.")) return null;
-            property = property[(ColumnName.Length + 1)..];
-
             if (property == "Start") return Time.Start;
             if (property == "Duration") return Time.Duration;
             if (property == "Finish") return Time.Finish;
@@ -407,11 +401,8 @@ namespace PRS.Shared
             return null;
         }
 
-        public override void SetValue(string property, object? value)
+        protected override void SetChildValue(string property, object? value)
         {
-            if (!property.StartsWith($"{ColumnName}.")) return;
-            property = property[(ColumnName.Length + 1)..];
-
             if (value is not TimeSpan timeSpan) return;
 
             if (property == "Start") Time.Start = timeSpan;

+ 10 - 19
prs.shared/Editors/Dimensions/DimensionsEditorControl.cs

@@ -232,11 +232,8 @@ namespace PRS.Shared
             CheckChanged();
         }
 
-        public override object? GetValue(string property)
+        protected override object? GetChildValue(string property)
         {
-            if (!property.StartsWith($"{ColumnName}.")) return null;
-            property = property[(ColumnName.Length + 1)..];
-
             if (property == "Quantity") return QuantityBox.Value ?? 0.0;
             if (property == "Length") return LengthBox.Value ?? 0.0;
             if (property == "Width") return WidthBox.Value ?? 0.0;
@@ -246,25 +243,19 @@ namespace PRS.Shared
 
             return null;
         }
-        public override Dictionary<string, object?> GetValues()
+
+        protected override IEnumerable<KeyValuePair<string, object?>> GetChildValues()
         {
-            var values = new Dictionary<string, object?>
-            {
-                {$"{ColumnName}.Quantity", QuantityBox.Value ?? 0.0},
-                {$"{ColumnName}.Length", LengthBox.Value ?? 0.0},
-                {$"{ColumnName}.Width", WidthBox.Value ?? 0.0},
-                {$"{ColumnName}.Height", HeightBox.Value ?? 0.0},
-                {$"{ColumnName}.Weight", WeightBox.Value ?? 0.0},
-                {$"{ColumnName}.Unit.ID", Combo.SelectedValue is Guid guid ? guid : Guid.Empty }
-            };
-            return values;
+            yield return new("Quantity", QuantityBox.Value ?? 0.0);
+            yield return new("Length", LengthBox.Value ?? 0.0);
+            yield return new("Width", WidthBox.Value ?? 0.0);
+            yield return new("Height", HeightBox.Value ?? 0.0);
+            yield return new("Weight", WeightBox.Value ?? 0.0);
+            yield return new("Unit.ID", Combo.SelectedValue is Guid guid ? guid : Guid.Empty);
         }
 
-        public override void SetValue(string property, object? value)
+        protected override void SetChildValue(string property, object? value)
         {
-            if (!property.StartsWith($"{ColumnName}.")) return;
-            property = property[(ColumnName.Length + 1)..];
-
             if (property == "Unit.ID")
             {
                 Combo.SelectedValue = value is Guid guid ? guid : Guid.Empty;

+ 7 - 16
prs.shared/Editors/ProductCharge/ProductChargeEditor.cs

@@ -136,11 +136,8 @@ namespace PRS.Shared
             return _dockpanel;
         }
         
-        public override void SetValue(string property, object? value)
+        protected override void SetChildValue(string property, object? value)
         {
-            if (!property.StartsWith($"{ColumnName}.")) return;
-            property = property[(ColumnName.Length + 1)..];
-
             if (property == nameof(_productCharge.Chargeable) && value is bool b)
             {
                 _productCharge.Chargeable = b;
@@ -169,11 +166,8 @@ namespace PRS.Shared
             }
         }
 
-        public override object? GetValue(string property)
+        protected override object? GetChildValue(string property)
         {
-            if (!property.StartsWith($"{ColumnName}.")) return null;
-            property = property[(ColumnName.Length + 1)..];
-
             if (property == nameof(_productCharge.Chargeable)) return _productCharge.Chargeable;
             if (property == nameof(_productCharge.Markup)) return _productCharge.Markup;
             if (property == nameof(_productCharge.Price)) return _productCharge.Price;
@@ -182,15 +176,12 @@ namespace PRS.Shared
             return null;
         }
 
-        public override Dictionary<string, object?> GetValues()
+        protected override IEnumerable<KeyValuePair<string, object?>> GetChildValues()
         {
-            return new Dictionary<string, object?>
-            {
-                { $"{ColumnName}.{nameof(_productCharge.Chargeable)}", _productCharge.Chargeable },
-                { $"{ColumnName}.{nameof(_productCharge.Markup)}", _productCharge.Markup },
-                { $"{ColumnName}.{nameof(_productCharge.Price)}", _productCharge.Price },
-                { $"{ColumnName}.{nameof(_productCharge.PriceType)}", _productCharge.PriceType }
-            };
+            yield return new(nameof(_productCharge.Chargeable), _productCharge.Chargeable);
+            yield return new(nameof(_productCharge.Markup), _productCharge.Markup);
+            yield return new(nameof(_productCharge.Price), _productCharge.Price);
+            yield return new(nameof(_productCharge.PriceType), _productCharge.PriceType);
         }
         
         private void _chargeable_Changed(object sender, SelectionChangedEventArgs e)