ソースを参照

Digital form improvements

Kenric Nugteren 1 年間 前
コミット
21687c7bca

+ 15 - 9
prs.classes/FormFields/DFLayoutAddTaskField/DFLayoutAddTaskFieldProperties.cs

@@ -8,7 +8,7 @@ using System.Text;
 
 namespace PRSClasses
 {
-    public class DFLayoutAddTaskFieldProperties : DFLayoutFieldProperties<int?>
+    public class DFLayoutAddTaskFieldProperties : DFLayoutFieldProperties<int?, int?>
     {
         public KanbanTypeLink TaskType { get; set; }
 
@@ -30,18 +30,24 @@ namespace PRSClasses
             SetProperty("TaskType", TaskType.ID);
         }
 
-        public override string FormatValue(object value)
+        public override int? DeserializeValue(DFLoadStorageEntry entry)
         {
-            return string.Format("{0}", value);
+            return entry.GetValue<int?>();
+        }
+
+        public override void SerializeValue(DFSaveStorageEntry entry, int? value)
+        {
+            entry.SetValue(value);
         }
 
-        public override object? ParseValue(object value)
+        public override int? GetValue(int? value)
         {
-            if (value is int)
-                return value;
-            if (int.TryParse(value as string, out var result))
-                return result;
-            return null;
+            return value;
+        }
+
+        public override string FormatValue(object? value)
+        {
+            return string.Format("{0}", value);
         }
     }
 }

+ 9 - 13
prs.desktop/Dashboards/Common/DigitalFormsDashboard.xaml.cs

@@ -1040,23 +1040,19 @@ namespace PRSDesktop
                     var bHasData = false;
                     if (variables.Any())
                     {
-                        var dict = Serialization.Deserialize<Dictionary<string, object>>(form.FormData);
+                        var dict = Serialization.Deserialize<Dictionary<string, object?>>(form.FormData);
                         if(dict is not null)
                         {
-                            foreach (var key in dict.Keys)
+                            var storage = new DFLoadStorage(dict, null);
+                            foreach (var variable in variables)
                             {
-                                var variable = variables.FirstOrDefault(x => string.Equals(key, x.Code));
-                                var type = variable?.FieldType();
-                                if (variable != null)
+                                var value = variable.Deserialize(storage.GetEntry(variable.Code));
+                                var format = variable.FormatValue(value);
+                                var sKey = variable.Code.Replace("/", " ");
+                                if (data.Columns.Contains(sKey))
                                 {
-                                    var value = variable.ParseValue(dict[key]);
-                                    var format = variable.FormatValue(value);
-                                    var sKey = key.Replace("/", " ");
-                                    if (data.Columns.Contains(sKey))
-                                    {
-                                        dataRow[sKey] = format;
-                                        bHasData = true;
-                                    }
+                                    dataRow[sKey] = format;
+                                    bHasData = true;
                                 }
                             }
                         }

+ 7 - 7
prs.desktop/Dashboards/Common/QADashboard.xaml.cs

@@ -654,15 +654,15 @@ namespace PRSDesktop
                         var bHasData = false;
                         if (variables.Any())
                         {
-                            var dict = Serialization.Deserialize<Dictionary<string, object>>(qadata);
-                            foreach (var key in dict.Keys)
+                            var dict = Serialization.Deserialize<Dictionary<string, object?>>(qadata);
+                            if (dict is not null)
                             {
-                                var variable = variables.FirstOrDefault(x => string.Equals(key, x.Code));
-                                if (variable != null)
+                                var storage = new DFLoadStorage(dict, null);
+                                foreach(var variable in variables)
                                 {
-                                    var value = variable.ParseValue(dict[key]);
-                                    object format = variable.FormatValue(value);
-                                    var sKey = key.Replace("/", " ");
+                                    var value = variable.Deserialize(storage.GetEntry(variable.Code));
+                                    var format = variable.FormatValue(value);
+                                    var sKey = variable.Code.Replace("/", " ");
                                     if (data.Columns.Contains(sKey))
                                     {
                                         datarow[sKey] = format;

+ 5 - 6
prs.shared/FormFields/DFAddTaskControl.cs

@@ -16,7 +16,7 @@ using TextBox = System.Windows.Controls.TextBox;
 
 namespace PRS.Shared
 {
-    public class DFAddTaskControl : DynamicFormFieldControl<DFLayoutAddTaskField, DFLayoutAddTaskFieldProperties, int?>
+    public class DFAddTaskControl : DynamicFormFieldControl<DFLayoutAddTaskField, DFLayoutAddTaskFieldProperties, int?, int?>
     {
         private IntegerTextBox Number = null!; // Late-initialisation
         private Button Button = null!; // Late-initialisation
@@ -62,15 +62,14 @@ namespace PRS.Shared
             }
         }
 
-        public override void Deserialize(string serialized)
+        public override int? GetSerializedValue()
         {
-            if (int.TryParse(serialized, out int i))
-                SetValue(i);
+            return GetValue();
         }
 
-        public override string Serialize()
+        public override void SetSerializedValue(int? value)
         {
-            return GetValue()?.ToString() ?? "";
+            SetValue(value);
         }
 
         public override int? GetValue()