ソースを参照

Fixed delivery bugs and big performance improvements

Kenric Nugteren 1 年間 前
コミット
62ec6a0e58

+ 1 - 1
prs.desktop/Panels/Delivery/DeliveryItemsList.cs

@@ -16,7 +16,7 @@ namespace PRSDesktop
         
         public Delivery? Master { get; set; }
 
-        public Filter<DeliveryItem> MasterDetailFilter => Master != null
+        public Filter<DeliveryItem> MasterDetailFilter => Master is not null && Master.ID != Guid.Empty
             ? new Filter<DeliveryItem>(x => x.Delivery.ID).IsEqualTo(Master.ID)
             : new Filter<DeliveryItem>().None();
         

+ 2 - 2
prs.desktop/Panels/Delivery/DeliveryPanel.xaml.cs

@@ -231,10 +231,10 @@ namespace PRSDesktop
             Items.Master = _delivery;
             Items.Refresh(false, true);
 
-            Racks.Delivery = _delivery;
+            Racks.Master = _delivery;
             Racks.Refresh(false, true);
 
-            Requis.Delivery = _delivery;
+            Requis.Master = _delivery;
             Requis.Refresh(false, true);
             
             Bookings.Refresh();

+ 103 - 105
prs.desktop/Panels/Delivery/DeliveryRackList.cs

@@ -8,144 +8,142 @@ using InABox.DynamicGrid;
 using InABox.WPF;
 using InABox.Wpf;
 
-namespace PRSDesktop
+namespace PRSDesktop;
+
+internal class DeliveryRackList : DynamicDataGrid<Shipment>, IMasterDetailControl<Delivery,Shipment>
 {
-    internal class DeliveryRackList : DynamicDataGrid<Shipment>, IMasterDetailControl<Delivery,Shipment>
+    public Delivery? Master { get; set; }
+
+    public Filter<Shipment> MasterDetailFilter => Master != null && Master.ID != Guid.Empty
+        ? new Filter<Shipment>(x => x.Delivery.ID).IsEqualTo(Master.ID)
+        : new Filter<Shipment>().None();
+    
+    public DeliveryRackList()
     {
-        public Delivery? Master { get; set; }
+        HiddenColumns.Add(x => x.Delivery.ID);
+        ColumnsTag = "DeliveryRack";
+    }
 
-        public Filter<Shipment> MasterDetailFilter => Master != null
-            ? new Filter<Shipment>(x => x.Delivery.ID).IsEqualTo(Master.ID)
-            : new Filter<Shipment>().None();
-        
-        public DeliveryRackList()
+    protected override void DoReconfigure(FluentList<DynamicGridOption> options)
+    {
+        base.DoReconfigure(options);
+        options.AddRange(DynamicGridOption.RecordCount, DynamicGridOption.AddRows, DynamicGridOption.DeleteRows, DynamicGridOption.SelectColumns);
+    }
+
+    protected override DynamicGridColumns LoadColumns()
+    {
+        var columns = new DynamicGridColumns
         {
-            HiddenColumns.Add(x => x.Delivery.ID);
-            ColumnsTag = "DeliveryRack";
-        }
+            new() { ColumnName = "Code", Width = 40, Caption = "Rack", Alignment = Alignment.MiddleCenter },
+            new() { ColumnName = "Description", Width = 0, Caption = "Description" },
+            new() { ColumnName = "ItemCount", Width = 25, Caption = "#", Alignment = Alignment.MiddleCenter }
+        };
+        return columns;
+    }
 
-        protected override void DoReconfigure(FluentList<DynamicGridOption> options)
+    protected override void DoAdd(bool OpenEditorOnDirectEdit = false)
+    {
+        if ((Master?.ID ?? Guid.Empty) == Guid.Empty)
         {
-            base.DoReconfigure(options);
-            options.AddRange(DynamicGridOption.RecordCount, DynamicGridOption.AddRows, DynamicGridOption.DeleteRows, DynamicGridOption.SelectColumns);
+            MessageBox.Show("Please select a Delivery First");
+            return;
         }
-        
-        public Delivery Delivery { get; set; }
 
-        protected override DynamicGridColumns LoadColumns()
+        if (!Master.Completed.IsEmpty())
         {
-            var columns = new DynamicGridColumns
-            {
-                new() { ColumnName = "Code", Width = 40, Caption = "Rack", Alignment = Alignment.MiddleCenter },
-                new() { ColumnName = "Description", Width = 0, Caption = "Description" },
-                new() { ColumnName = "ItemCount", Width = 25, Caption = "#", Alignment = Alignment.MiddleCenter }
-            };
-            return columns;
+            MessageBox.Show("You cannot modify a completed delivery!");
+            return;
         }
 
-        protected override void DoAdd(bool OpenEditorOnDirectEdit = false)
+
+        var grid = new MultiSelectDialog<Shipment>(
+            new Filter<Shipment>(x => x.Delivery).NotLinkValid(),
+            new Columns<Shipment>(x => x.ID)
+                .Add(x => x.Delivery.ID)
+        );
+        if (grid.ShowDialog())
         {
-            if ((Delivery?.ID ?? Guid.Empty) == Guid.Empty)
+            Progress.Show("Adding Racks to Delivery");
+
+            var shipments = grid.Data().ToObjects<Shipment>();
+            var filter = new Filter<DeliveryItem>(x => x.ID).IsEqualTo(CoreUtils.FullGuid);
+            foreach (var shipment in shipments)
             {
-                MessageBox.Show("Please select a Delivery First");
-                return;
+                filter = filter.Or(x => x.ShipmentLink.ID).IsEqualTo(shipment.ID);
+                shipment.Delivery.ID = Master.ID;
+                shipment.Delivery.Synchronise(Master);
             }
 
-            if (!Delivery.Completed.IsEmpty())
+            var items = new Client<DeliveryItem>().Query(filter, new Columns<DeliveryItem>(x => x.Delivery.ID)).ToArray<DeliveryItem>();
+            foreach (var item in items)
             {
-                MessageBox.Show("You cannot modify a completed delivery!");
-                return;
+                item.Delivery.ID = Master.ID;
+                item.Delivery.Synchronise(Master);
             }
 
+            new Client<DeliveryItem>().Save(items, "Added to Delivery");
+            new Client<Shipment>().Save(shipments, "Added to Delivery");
 
-            var grid = new MultiSelectDialog<Shipment>(
-                new Filter<Shipment>(x => x.Delivery).NotLinkValid(),
-                null
-            );
-            if (grid.ShowDialog())
-            {
-                Progress.Show("Adding Racks to Delivery");
-
-                var shipments = grid.Items();
-                var filter = new Filter<DeliveryItem>(x => x.ID).IsEqualTo(CoreUtils.FullGuid);
-                foreach (var shipment in shipments)
-                {
-                    filter = filter.Or(x => x.ShipmentLink.ID).IsEqualTo(shipment.ID);
-                    shipment.Delivery.ID = Delivery.ID;
-                    shipment.Delivery.Synchronise(Delivery);
-                }
-
-                var items = new Client<DeliveryItem>().Load(filter);
-                foreach (var item in items)
-                {
-                    item.Delivery.ID = Delivery.ID;
-                    item.Delivery.Synchronise(Delivery);
-                }
-
-                new Client<DeliveryItem>().Save(items, "Added to Delivery");
-                new Client<Shipment>().Save(shipments, "Added to Delivery");
+            DoChanged();
 
-                DoChanged();
+            Progress.Close();
+        }
+    }
 
-                Progress.Close();
-            }
+    protected override void DeleteItems(params CoreRow[] rows)
+    {
+        
+        if ((Master?.ID ?? Guid.Empty) == Guid.Empty)
+        {
+            MessageBox.Show("Please select a Delivery First");
+            return;
+        }
+        
+        if (rows?.Any() != true)
+        {
+            MessageBox.Show("Please select a row first");
+            return;
         }
 
-        protected override void DeleteItems(params CoreRow[] rows)
+        if (!Master.Completed.IsEmpty())
         {
-            
-            if ((Delivery?.ID ?? Guid.Empty) == Guid.Empty)
-            {
-                MessageBox.Show("Please select a Delivery First");
-                return;
-            }
-            
-            if (rows?.Any() != true)
-            {
-                MessageBox.Show("Please select a row first");
-                return;
-            }
+            MessageBox.Show("You cannot modify a completed delivery!");
+            return;
+        }
 
-            if (!Delivery.Completed.IsEmpty())
-            {
-                MessageBox.Show("You cannot modify a completed delivery!");
-                return;
-            }
+        Progress.Show("Removing Items from Delivery");
 
-            Progress.Show("Removing Items from Delivery");
+        DeliveryItem[] items = { };
 
-            DeliveryItem[] items = { };
+        foreach (var row in rows)
+        {
+            var rackid = row.Get<Shipment, Guid>(x => x.ID);
+            items = new Client<DeliveryItem>().Load(new Filter<DeliveryItem>(x => x.ShipmentLink.ID).IsEqualTo(rackid));
+            var shipment = new Client<Shipment>().Load(new Filter<Shipment>(x => x.ID).IsEqualTo(rackid)).FirstOrDefault();
+            if (shipment != null)
+            {
+                shipment.Delivery.ID = Guid.Empty;
+                new Client<Shipment>().Save(shipment, "Removed from Delivery");
+            }
 
-            foreach (var row in rows)
+            if (items.Any())
             {
-                var rackid = row.Get<Shipment, Guid>(x => x.ID);
-                items = new Client<DeliveryItem>().Load(new Filter<DeliveryItem>(x => x.ShipmentLink.ID).IsEqualTo(rackid));
-                var shipment = new Client<Shipment>().Load(new Filter<Shipment>(x => x.ID).IsEqualTo(rackid)).FirstOrDefault();
-                if (shipment != null)
-                {
-                    shipment.Delivery.ID = Guid.Empty;
-                    new Client<Shipment>().Save(shipment, "Removed from Delivery");
-                }
-
-                if (items.Any())
-                {
-                    foreach (var item in items)
-                        item.Delivery.ID = Guid.Empty;
-                    new Client<DeliveryItem>().Save(items, "Removed From Delivery");
-                }
+                foreach (var item in items)
+                    item.Delivery.ID = Guid.Empty;
+                new Client<DeliveryItem>().Save(items, "Removed From Delivery");
             }
+        }
 
-            DoChanged();
+        DoChanged();
 
-            Progress.Close();
-        }
+        Progress.Close();
+    }
 
 
-        protected override void Reload(Filters<Shipment> criteria, Columns<Shipment> columns, ref SortOrder<Shipment>? sort, Action<CoreTable?, Exception?> action)
-        {
-            
-            criteria.Add(MasterDetailFilter);
-            base.Reload(criteria, columns, ref sort, action);
-        }
+    protected override void Reload(Filters<Shipment> criteria, Columns<Shipment> columns, ref SortOrder<Shipment>? sort, Action<CoreTable?, Exception?> action)
+    {
+        
+        criteria.Add(MasterDetailFilter);
+        base.Reload(criteria, columns, ref sort, action);
     }
 }

+ 9 - 14
prs.desktop/Panels/Delivery/DeliveryRequiList.cs

@@ -15,7 +15,7 @@ namespace PRSDesktop
 
         public Delivery? Master { get; set; }
 
-        public Filter<Requisition> MasterDetailFilter => Master != null
+        public Filter<Requisition> MasterDetailFilter => Master != null && Master.ID != Guid.Empty
             ? new Filter<Requisition>(x => x.Delivery.ID).IsEqualTo(Master.ID)
             : new Filter<Requisition>().None();
         
@@ -30,8 +30,6 @@ namespace PRSDesktop
             base.DoReconfigure(options);
             options.AddRange(DynamicGridOption.RecordCount, DynamicGridOption.AddRows, DynamicGridOption.DeleteRows, DynamicGridOption.SelectColumns);
         }
-        
-        public Delivery Delivery { get; set; }
 
         protected override DynamicGridColumns LoadColumns()
         {
@@ -47,13 +45,13 @@ namespace PRSDesktop
 
         protected override void DoAdd(bool OpenEditorOnDirectEdit = false)
         {
-            if (Delivery.ID == Guid.Empty)
+            if (Master.ID == Guid.Empty)
             {
                 MessageBox.Show("Please select a Delivery First");
                 return;
             }
 
-            if (!Delivery.Completed.IsEmpty())
+            if (!Master.Completed.IsEmpty())
             {
                 MessageBox.Show("You cannot modify a completed delivery!");
                 return;
@@ -61,7 +59,7 @@ namespace PRSDesktop
 
 
             var grid = new MultiSelectDialog<Requisition>(
-                new Filter<Requisition>(x => x.JobLink.ID).IsEqualTo(Delivery.Job.ID).And(x => x.Archived).IsEqualTo(DateTime.MinValue)
+                new Filter<Requisition>(x => x.JobLink.ID).IsEqualTo(Master.Job.ID).And(x => x.Archived).IsEqualTo(DateTime.MinValue)
                     .And(x => x.Delivery).NotLinkValid(),
                 null
             );
@@ -74,14 +72,14 @@ namespace PRSDesktop
                 foreach (var requi in requis)
                 {
                     filter = filter.Or(x => x.RequisitionLink.ID).IsEqualTo(requi.ID);
-                    requi.Delivery.ID = Delivery.ID;
+                    requi.Delivery.ID = Master.ID;
                 }
 
                 var items = new Client<DeliveryItem>().Load(filter);
                 foreach (var item in items)
                 {
-                    item.Delivery.ID = Delivery.ID;
-                    item.Delivery.Synchronise(Delivery);
+                    item.Delivery.ID = Master.ID;
+                    item.Delivery.Synchronise(Master);
                 }
 
                 new Client<DeliveryItem>().Save(items, "Added to Delivery");
@@ -101,7 +99,7 @@ namespace PRSDesktop
                 return;
             }
 
-            if (!Delivery.Completed.IsEmpty())
+            if (!Master.Completed.IsEmpty())
             {
                 MessageBox.Show("You cannot modify a completed delivery!");
                 return;
@@ -137,10 +135,7 @@ namespace PRSDesktop
 
         protected override void Reload(Filters<Requisition> criteria, Columns<Requisition> columns, ref SortOrder<Requisition>? sort, Action<CoreTable?, Exception?> action)
         {
-            if (Delivery.ID == Guid.Empty)
-                criteria.Add(new Filter<Requisition>(x => x.Delivery.ID).None());
-            else
-                criteria.Add(new Filter<Requisition>(x => x.Delivery.ID).IsEqualTo(Delivery.ID));
+            criteria.Add(MasterDetailFilter);
             base.Reload(criteria, columns, ref sort, action);
         }
     }

+ 4 - 1
prs.desktop/Panels/Shipments/ShipmentItemGrid.cs

@@ -26,6 +26,7 @@ namespace PRSDesktop
         {
             base.DoReconfigure(options);
             options.AddRange(DynamicGridOption.RecordCount, DynamicGridOption.SelectColumns, DynamicGridOption.MultiSelect);
+            options.Remove(DynamicGridOption.EditRows);
         }
 
         public Guid CurrentShipmentID { get; set; }
@@ -71,7 +72,9 @@ namespace PRSDesktop
         protected override void DoAdd(bool OpenEditorOnDirectEdit = false)
         {
             var dlg = new MultiSelectDialog<DeliveryItem>(
-                new Filter<DeliveryItem>(x => x.ShipmentLink).NotLinkValid(),
+                new Filter<DeliveryItem>(x => x.ShipmentLink.ID).IsEqualTo(Guid.Empty)
+                    .And(x => x.DeliveredDate).IsEqualTo(DateTime.MinValue)
+                    .And(x => x.ManufacturingPacketLink.ID).IsNotEqualTo(Guid.Empty),
                 DataColumns()
             );
             if (dlg.ShowDialog())