Explorar o código

- Preventing duplicate ProductInstances.
- Fixed refreshing products not disabling detail grids.

Kenric Nugteren hai 4 meses
pai
achega
2d352b075b

+ 18 - 0
prs.desktop/Panels/Products/Master List/ProductInstanceControl.cs

@@ -83,6 +83,24 @@ public class ProductInstanceControl : DynamicDataGrid<ProductInstance>, IProduct
         return item;
     }
 
+    protected override void DoValidate(ProductInstance[] items, List<string> errors)
+    {
+        base.DoValidate(items, errors);
+
+        // Preventing duplicate items.
+        var currentItems = Data.ToArray<ProductInstance>();
+        foreach(var item in items)
+        {
+            if(currentItems.Any(x => x.ID != item.ID
+                && x.Product.ID == item.Product.ID
+                && x.Style.ID == item.Style.ID
+                && x.Dimensions.Equals(item.Dimensions)))
+            {
+                errors.Add($"There is already an item matching {item.Style.Code} ({item.Dimensions.UnitSize})");
+            }
+        }
+    }
+
     public override DynamicGridColumns GenerateColumns()
     {
         var cols = new DynamicGridColumns();

+ 9 - 9
prs.desktop/Panels/Products/Master List/ProductsPanel.xaml.cs

@@ -107,11 +107,6 @@ namespace PRSDesktop
             //host.CreatePanelAction(new PanelAction() { Caption = "Import Dxf", OnExecute = ImportDxF, Image = PRSDesktop.Resources.design });
         }
 
-        private void ProductSettingsClick(PanelAction obj)
-        {
-            throw new NotImplementedException();
-        }
-
         public string SectionName => "Products";
 
         public DataModel DataModel(Selection selected)
@@ -128,8 +123,12 @@ namespace PRSDesktop
         public void Refresh()
         {
             Groups.Refresh(false, true);
-            //ProductDetails.IsEnabled = false;
-            //Products.Refresh(false, true);
+        }
+
+        private void RefreshProducts()
+        {
+            ProductDetails.IsEnabled = false;
+            Products.Refresh(false, true);
         }
 
         public void Heartbeat(TimeSpan time)
@@ -271,6 +270,7 @@ namespace PRSDesktop
             if (Products.ColumnsTag != newTag)
             {
                 Products.ColumnsTag = newTag;
+                ProductDetails.IsEnabled = false;
                 Products.Refresh(true, true);
             }
         }
@@ -458,7 +458,7 @@ namespace PRSDesktop
             if(e.Rows is null)
             {
                 Products.Groups = null;
-                Products.Refresh(false, true);
+                RefreshProducts();
             }
             else
             {
@@ -475,7 +475,7 @@ namespace PRSDesktop
                     groups.AddRange(Groups.GetChildren(nodeID).Select(x => x.Get<ProductGroup, Guid>(x => x.ID)));
                 }
                 Products.Groups = all ? null : groups.ToArray();
-                Products.Refresh(false, true);
+                RefreshProducts();
             }
         }
     }