瀏覽代碼

Merge remote-tracking branch 'origin/kenric' into frank

frogsoftware 1 年之前
父節點
當前提交
587aa9d502

+ 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<string?, string?>
     {
         public KanbanTypeLink TaskType { get; set; }
 
@@ -30,18 +30,24 @@ namespace PRSClasses
             SetProperty("TaskType", TaskType.ID);
         }
 
-        public override string FormatValue(object value)
+        public override string? DeserializeValue(DFLoadStorageEntry entry)
         {
-            return string.Format("{0}", value);
+            return entry.GetValue<string>();
+        }
+
+        public override void SerializeValue(DFSaveStorageEntry entry, string? value)
+        {
+            entry.SetValue(value);
         }
 
-        public override object? ParseValue(object value)
+        public override string? GetValue(string? 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(string? 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;

+ 16 - 10
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, string?, string?>
     {
         private IntegerTextBox Number = null!; // Late-initialisation
         private Button Button = null!; // Late-initialisation
@@ -62,25 +62,31 @@ namespace PRS.Shared
             }
         }
 
-        public override void Deserialize(string serialized)
+        public override string? GetSerializedValue()
         {
-            if (int.TryParse(serialized, out int i))
-                SetValue(i);
+            return GetValue();
         }
 
-        public override string Serialize()
+        public override void SetSerializedValue(string? value)
         {
-            return GetValue()?.ToString() ?? "";
+            SetValue(value);
         }
 
-        public override int? GetValue()
+        public override string? GetValue()
         {
-            return Number.Value.HasValue ? Convert.ToInt32(Number.Value.Value) : null;
+            return Number.Value?.ToString();
         }
 
-        public override void SetValue(int? value)
+        public override void SetValue(string? value)
         {
-            Number.Value = value;
+            if(int.TryParse(value, out var i))
+            {
+                Number.Value = i;
+            }
+            else
+            {
+                Number.Value = null;
+            }
             Button.IsEnabled = FormDesignGrid.IsEditing && value == null;
         }
 

+ 57 - 42
prs.shared/Posters/Timberline/PurchaseOrderTimberlinePoster.cs

@@ -234,6 +234,7 @@ public class Module
                 .Add(x => x.Description)
                 .Add(x => x.ReceivedDate)
                 .Add(x => x.Job.JobNumber)
+                .Add(x => x.CostCentre.Code)
                 .Add(x => x.TaxCode.Code)
                 .Add(x => x.Qty)
                 .Add(x => x.Cost)
@@ -412,65 +413,79 @@ public class Module
                     }
                 }
 
-                var logDlg = new OpenFileDialog
+                while (true)
                 {
-                    InitialDirectory = Path.GetDirectoryName(dlg.FileName),
-                    FileName = "JCREJECT.JCC",
-                    Filter = "Rejected Item Files (*.jcc) | *.jcc;*.JCC | All Files (*.*) | *.*",
-                    Title = "Please select JCREJECT.JCC"
-                };
-                if (logDlg.ShowDialog() == true)
-                {
-                    var rejectedHeaders = new List<PurchaseOrderTimberlineHeader?>();
-                    var rejectedLines = new List<PurchaseOrderTimberlineLine?>();
-                    using (var reader = new StreamReader(logDlg.FileName))
+                    var logDlg = new OpenFileDialog
+                    {
+                        InitialDirectory = Path.GetDirectoryName(dlg.FileName),
+                        FileName = "JCREJECT.JCC",
+                        Filter = "Rejected Item Files (*.jcc) | *.jcc;*.JCC | All Files (*.*) | *.*",
+                        Title = "Please select JCREJECT.JCC"
+                    };
+                    if (logDlg.ShowDialog() == true)
                     {
-                        using var csv = new CsvReader(reader, new CsvConfiguration(CultureInfo.InvariantCulture)
+                        var rejectedHeaders = new List<PurchaseOrderTimberlineHeader?>();
+                        var rejectedLines = new List<PurchaseOrderTimberlineLine?>();
+                        using (var reader = new StreamReader(logDlg.FileName))
                         {
-                            HasHeaderRecord = false
-                        });
+                            using var csv = new CsvReader(reader, new CsvConfiguration(CultureInfo.InvariantCulture)
+                            {
+                                HasHeaderRecord = false
+                            });
 
-                        while (csv.Read())
-                        {
-                            var id = csv.GetField(0);
-                            if(id == "C")
+                            while (csv.Read())
                             {
-                                var header = csv.GetRecord<PurchaseOrderTimberlineHeader>();
-                                if(header is not null)
+                                var id = csv.GetField(0);
+                                if (id == "C")
                                 {
-                                    var entry = POs.Items.FirstOrDefault(x => x.Item2?.CommitmentID.Equals(header.CommitmentID) == true);
-                                    if(entry is not null)
+                                    var header = csv.GetRecord<PurchaseOrderTimberlineHeader>();
+                                    if (header is not null)
                                     {
-                                        (entry.Item1 as IPostable).FailPost("");
+                                        var entry = POs.Items.FirstOrDefault(x => x.Item2?.CommitmentID.Equals(header.CommitmentID) == true);
+                                        if (entry is not null)
+                                        {
+                                            (entry.Item1 as IPostable).FailPost("");
+                                        }
                                     }
-                                }
-                                else
-                                {
-                                    Logger.Send(LogType.Error, "", "PO Timberline export: Unable to parse header from CSV line in rejection file.");
-                                    MessageBox.Show("Invalid line in file; skipping.");
-                                }
-                            }
-                            else if(id == "CI")
-                            {
-                                var line = csv.GetRecord<PurchaseOrderTimberlineLine>();
-                                if (line is not null)
-                                {
-                                    var entry = POs.Items.FirstOrDefault(x => x.Item2?.CommitmentID.Equals(line.CommitmentID) == true);
-                                    if (entry is not null)
+                                    else
                                     {
-                                        (entry.Item1 as IPostable).FailPost("");
+                                        Logger.Send(LogType.Error, "", "PO Timberline export: Unable to parse header from CSV line in rejection file.");
+                                        MessageBox.Show("Invalid line in file; skipping.");
                                     }
                                 }
-                                else
+                                else if (id == "CI")
                                 {
-                                    Logger.Send(LogType.Error, "", "PO Timberline export: Unable to parse line from CSV line in rejection file.");
-                                    MessageBox.Show("Invalid line in file; skipping.");
+                                    var line = csv.GetRecord<PurchaseOrderTimberlineLine>();
+                                    if (line is not null)
+                                    {
+                                        var entry = POs.Items.FirstOrDefault(x => x.Item2?.CommitmentID.Equals(line.CommitmentID) == true);
+                                        if (entry is not null)
+                                        {
+                                            (entry.Item1 as IPostable).FailPost("");
+                                        }
+                                    }
+                                    else
+                                    {
+                                        Logger.Send(LogType.Error, "", "PO Timberline export: Unable to parse line from CSV line in rejection file.");
+                                        MessageBox.Show("Invalid line in file; skipping.");
+                                    }
                                 }
                             }
                         }
+                        return POs;
+                    }
+                    else
+                    {
+                        if (MessageBox.Show("Do you wish to cancel the export?", "Cancel Export?", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
+                        {
+                            throw new PostCancelledException();
+                        }
+                        else if (MessageBox.Show("Did everything post successfully?", "Successful?", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
+                        {
+                            return POs;
+                        }
                     }
                 }
-                return POs;
             }
             else
             {