Explorar el Código

Improved staging panel refresh code and enforced jobs for setouts

Kenric Nugteren hace 1 año
padre
commit
64c96f859d

+ 1 - 0
prs.desktop/Panels/Staging/Component/StagingSetoutComponentGrid.cs

@@ -33,6 +33,7 @@ namespace PRSDesktop
 
         public StagingSetoutComponentGrid()
         {
+            HiddenColumns.Add(x => x.Description);
             HiddenColumns.Add(x => x.Dimensions.Length);
             HiddenColumns.Add(x => x.Dimensions.Width);
             HiddenColumns.Add(x => x.Dimensions.Height);

+ 8 - 7
prs.desktop/Panels/Staging/Manufacturing/StagingManufacturingPacketComponentGrid.cs

@@ -94,17 +94,18 @@ namespace PRSDesktop
             if(entity == typeof(StagingSetoutComponent))
             {
                 var components = new List<StagingManufacturingPacketComponent>();
-                var bomItems = table.ToObjects<StagingSetoutComponent>().ToList();
-                foreach (var bomItem in bomItems)
+                var setoutComponents = table.ToObjects<StagingSetoutComponent>().ToList();
+                foreach (var setoutComponent in setoutComponents)
                 {
                     var component = CreateItem();
-                    component.Dimensions.CopyFrom(bomItem.Dimensions);
-                    component.Product.ID = bomItem.Product.ID;
-                    component.Quantity = bomItem.Quantity;
+                    component.Dimensions.CopyFrom(setoutComponent.Dimensions);
+                    component.Product.ID = setoutComponent.Product.ID;
+                    component.Quantity = setoutComponent.Quantity;
+                    component.Description = setoutComponent.Description;
                     components.Add(component);
-                    bomItem.StagingManufacturingPacket.ID = Packet.ID;
+                    setoutComponent.StagingManufacturingPacket.ID = Packet.ID;
                 }
-                new Client<StagingSetoutComponent>().Save(bomItems, "Added to packet.");
+                new Client<StagingSetoutComponent>().Save(setoutComponents, "Added to packet.");
                 SaveItems(components.ToArray());
 
                 Refresh(false, true);

+ 1 - 0
prs.desktop/Panels/Staging/StagingPanel.xaml

@@ -29,6 +29,7 @@
                     OnCustomiseSetouts="stagingSetoutGrid_OnCustomiseSetouts" 
                     OnParseComponentFile="stagingSetoutGrid_OnParseComponentFile"
                     OnDoubleClick="StagingSetoutGrid_OnOnDoubleClick"
+                    AfterRefresh="stagingSetoutGrid_AfterRefresh"
                     OnSelectItem="StagingSetoutGrid_OnSelectItem"/>
             </Grid>
         </dynamicgrid:DynamicSplitPanel.Master>

+ 37 - 7
prs.desktop/Panels/Staging/StagingPanel.xaml.cs

@@ -1,4 +1,5 @@
 using Comal.Classes;
+using Comal.Classes;
 using InABox.Core;
 using System;
 using System.Collections.Generic;
@@ -217,7 +218,20 @@ public class Module
             }
         }
 
-        private StagingSetoutDocument? Document { get; set; }
+        private StagingSetoutDocument? _document;
+
+        private StagingSetoutDocument? Document
+        {
+            get => _document;
+            set
+            {
+                _document = value;
+                if(_document is not null)
+                {
+                    ApproveButton.Content = _document.Approved ? "Unapprove" : "Approve";
+                }
+            }
+        }
 
         private byte[]? _documentdata = null;
 
@@ -277,7 +291,14 @@ public class Module
                 Progress.Close();
                 return;
             }
-            
+
+            if (selectedSetouts.Any(x => x.JobLink.ID == Guid.Empty))
+            {
+                MessageBox.Show("Cannot process setout without a linked job.");
+                Progress.Close();
+                return;
+            }
+
             if (ManufacturingPacketList.Packets.Any(x => x.Template.ID == Guid.Empty))
             {
                 MessageBox.Show("Cannot process manufacturing packets without templates.");
@@ -575,6 +596,7 @@ public class Module
                 selectedSetout = null;
 
                 ClearDocuments();
+                refreshing = true;
                 stagingSetoutGrid.Refresh(false, true);
             }
             else
@@ -627,6 +649,7 @@ public class Module
             }
             Document.Approved = !Document.Approved;
             new Client<StagingSetoutDocument>().Save(Document, "");
+            refreshing = true;
             stagingSetoutGrid.Refresh(false, true);
         }
 
@@ -665,6 +688,7 @@ public class Module
 
                 p.Start();
             }
+            refreshing = true;
             stagingSetoutGrid.Refresh(false, true);
         }
         private void OnMarkupComplete()
@@ -675,19 +699,27 @@ public class Module
                 return;
             }
             StagingSetoutGrid.ReloadFile(selectedSetout);
+            refreshing = true;
             stagingSetoutGrid.Refresh(false, true);
         }
 
         #endregion
 
+        private bool refreshing = false;
+
+        private void stagingSetoutGrid_AfterRefresh(object sender, AfterRefreshEventArgs args)
+        {
+            refreshing = false;
+        }
+
         private void StagingSetoutGrid_OnSelectItem(object sender, InABox.DynamicGrid.DynamicGridSelectionEventArgs e)
         {
             var newSetouts = new List<StagingSetout>();
             foreach (var row in e.Rows ?? Enumerable.Empty<CoreRow>())
                 newSetouts.Add(row.ToObject<StagingSetout>());
 
-            if(selectedSetouts.Count == newSetouts.Count
-                && !selectedSetouts.Any(x => !newSetouts.Any(y => x.ID == y.ID)))
+            if(!refreshing && (selectedSetouts.Count == newSetouts.Count
+                && !selectedSetouts.Any(x => !newSetouts.Any(y => x.ID == y.ID))))
             {
                 return;
             }
@@ -743,7 +775,6 @@ public class Module
             docTask.Wait();
             RenderDocuments(docTask.Result);
 
-            ApproveButton.Content = Document!.Approved ? "Unapprove" : "Approve";
             SetMode(mode);
         }
 
@@ -858,7 +889,7 @@ public class Module
         public void Refresh()
         {
             //stagingSetoutGrid.ScanFiles(_settings.SetoutsFolder);
-            stagingSetoutGrid.SelectedRows = Array.Empty<CoreRow>();
+            refreshing = true;
             stagingSetoutGrid.Refresh(false, true);
             /*Document = null;
 
@@ -1184,6 +1215,5 @@ public class Module
                 MessageBox.Show($"Error opening {componentFileName}: {e.Message}");
             }
         }
-
     }
 }