浏览代码

Fixed NotesEditor inconsistency and made DatabaseUpdateScript for 8.32 to process all the kanban notes.

Kenric Nugteren 5 月之前
父节点
当前提交
cfee4630bd

+ 23 - 11
prs.desktop/Panels/Manufacturing/ManufacturingPanelColumn.xaml.cs

@@ -19,6 +19,7 @@ using InABox.WPF;
 using InABox.Scripting;
 using System.Threading;
 using InABox.Wpf;
+using InABox.Wpf.Editors;
 
 namespace PRSDesktop
 {
@@ -204,7 +205,7 @@ namespace PRSDesktop
                 var completed = packet.Completed;
 
                 var onhold = packet.OnHold;
-                var issues = string.Join("\n=======================",packet.Problem.Notes);
+                var issues = NotesEditor.FormatNotes(packet.Problem.Notes);
                 var issuesResolved = packet.Problem.Resolved;
 
                 var orderitemid = packet.OrderItem.ID;
@@ -553,6 +554,7 @@ namespace PRSDesktop
             clearpriority.Visibility = priority ? Visibility.Visible : Visibility.Collapsed;
 
             editissues.Visibility = Visibility.Visible;
+            editissues.Header = packets.Count == 1 ? "View/Update Issues" : "Add Issue";
             sethold.Visibility = Security.IsAllowed<CanManagePacketHolds>() && !onhold ? Visibility.Visible : Visibility.Collapsed;
             clearhold.Visibility = Security.IsAllowed<CanManagePacketHolds>() && onhold ? Visibility.Visible : Visibility.Collapsed;
 
@@ -1168,19 +1170,29 @@ namespace PRSDesktop
             var item = (MenuItem)sender;
             var model = (ManufacturingKanban)item.Tag;
             var pkts = GetSelectedPackets(model.ID).ToArray();
-            if (pkts.Length != 1)
+            if (pkts.Length == 1)
             {
-                MessageWindow.ShowMessage("You can only edit one packet at a time", "Error");
-                return;
+                var pkt = pkts.First();
+                var _grid = DynamicGridUtils.CreateDynamicGrid(typeof(DynamicItemsListGrid<>), pkt.Problem.GetType());
+                if (_grid.EditItems(new object[] { pkt.Problem }))
+                {
+                    Progress.ShowModal("Updating Issues", progress => { Client.Save(pkts, "Updated Issues"); });
+                    ClearSelectedKanbans();
+                    OnChanged?.Invoke(this, new EventArgs());
+                }
             }
-
-            var pkt = pkts.First();
-            var _grid = DynamicGridUtils.CreateDynamicGrid(typeof(DynamicItemsListGrid<>), pkt.Problem.GetType());
-            if (_grid.EditItems(new object[] { pkt.Problem }))
+            else
             {
-                Progress.ShowModal("Updating Issues", progress => { new Client<ManufacturingPacket>().Save(pkts, "Updated Issues"); });
-                ClearSelectedKanbans();
-                OnChanged?.Invoke(this, new EventArgs());
+                var issue = "";
+                if(TextBoxDialog.Execute("Enter new issue: ", ref issue) && !issue.IsNullOrWhiteSpace())
+                {
+                    issue = $"{DateTime.Now:yyyy-MM-dd HH:mm:ss} {ClientFactory.UserID}: {issue}";
+                    foreach(var pkt in pkts)
+                    {
+                        pkt.Problem.Notes = pkt.Problem.Notes.Concatenate([issue]);
+                    }
+                    Progress.ShowModal("Updating Issues", progress => { Client.Save(pkts, "Updated Issues"); });
+                }
             }
         }
         

+ 1 - 0
prs.shared/Database Update Scripts/DatabaseUpdateScripts.cs

@@ -54,5 +54,6 @@ public static class DatabaseUpdateScripts
         DataUpdater.RegisterUpdateScript<Update_8_23>();
         DataUpdater.RegisterUpdateScript<Update_8_24>();
         DataUpdater.RegisterUpdateScript<Update_8_25>();
+        DataUpdater.RegisterUpdateScript<Update_8_32>();
     }
 }

+ 62 - 0
prs.shared/Database Update Scripts/Update_8_32.cs

@@ -0,0 +1,62 @@
+using Comal.Classes;
+using InABox.Core;
+using InABox.Database;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace PRS.Shared.Database_Update_Scripts;
+
+internal class Update_8_32 : DatabaseUpdateScript
+{
+    public override VersionNumber Version => new(8, 32);
+
+    public override bool Update()
+    {
+        var provider = DbFactory.NewProvider(Logger.Main);
+
+        Logger.Send(LogType.Information, "", $"Process Kanban Notes");
+        var tasks = provider.Query<Kanban>(
+            null,
+            Columns.None<Kanban>().Add(x => x.ID).Add(x => x.Notes))
+            .ToArray<Kanban>();
+        Utils.Utils.ProcessInChunks(tasks, chunk =>
+        {
+            foreach(var kanban in chunk)
+            {
+                if (kanban.Notes is not null && kanban.Notes.Any(x => x?.Contains("===================================") != false))
+                {
+                    var notes = new List<List<string>>() { new() };
+                    foreach (var line in kanban.Notes)
+                    {
+                        if(line is not null)
+                        {
+                            if (line.Equals("==================================="))
+                            {
+                                notes.Add(new());
+                            }
+                            else
+                            {
+                                notes[^1].Add(line);
+                            }
+                        }
+                        else
+                        {
+                            notes[^1].Add("");
+                        }
+                    }
+                    kanban.Notes = notes.Select(x => string.Join('\n', x)).Where(x => !x.IsNullOrWhiteSpace()).ToArray();
+                }
+            }
+            provider.Save(chunk.Where(x => x.IsChanged()));
+        }, 1000, percent =>
+        {
+            Logger.Send(LogType.Information, "", $"Processing Kanban Notes: {percent:F2}%");
+        });
+        Logger.Send(LogType.Information, "", $"Processing Kanban Notes complete");
+
+        return true;
+    }
+}