Browse Source

Staging BOM stuff.

Kenric Nugteren 2 năm trước cách đây
mục cha
commit
aecf6ca553

+ 3 - 6
prs.classes/Entities/Manufacturing/ManufacturingPacket/ManufacturingPacketComponent.cs

@@ -4,7 +4,7 @@ namespace Comal.Classes
 {
     [UserTracking(typeof(ManufacturingPacket))]
     [Caption("Components")]
-    public class ManufacturingPacketComponent : Entity, IRemotable, IPersistent, IOneToMany<ManufacturingPacket>, ILicense<ManufacturingLicense>
+    public class ManufacturingPacketComponent : DimensionedEntity<ProductDimensions>, IRemotable, IPersistent, IOneToMany<ManufacturingPacket>, ILicense<ManufacturingLicense>
     {
         [EntityRelationship(DeleteAction.Cascade)]
         public ManufacturingPacketLink Packet { get; set; }
@@ -14,17 +14,14 @@ namespace Comal.Classes
 
         public int Quantity { get; set; }
 
-        public double Height { get; set; }
-
-        public double Width { get; set; }
-
-        public double Length { get; set; }
+        public override ProductDimensions Dimensions { get; set; }
 
         protected override void Init()
         {
             base.Init();
             Packet = new ManufacturingPacketLink();
             Product = new ProductLink(() => this);
+            Dimensions = new ProductDimensions(() => this);
         }
     }
 }

+ 13 - 0
prs.classes/Entities/Staging/BOM/StagingBOM.cs

@@ -0,0 +1,13 @@
+using InABox.Core;
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace Comal.Classes
+{
+    public class StagingBOM : Entity, IRemotable, IPersistent
+    {
+        public string FileName { get; set; }
+
+    }
+}

+ 58 - 0
prs.classes/Entities/Staging/BOM/StagingBOMItem.cs

@@ -0,0 +1,58 @@
+using InABox.Core;
+using Newtonsoft.Json.Linq;
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace Comal.Classes
+{
+    public class StagingBOMItem : DimensionedEntity<ProductDimensions>, IRemotable, IPersistent, IOneToMany<StagingBOM>
+    {
+        [EditorSequence(1)]
+        public ProductLink Product { get; set; }
+
+        [EditorSequence(2)]
+        [DimensionsEditor(typeof(ProductDimensions))]
+        public override ProductDimensions Dimensions { get; set; }
+
+        [EditorSequence(3)]
+        public int Quantity { get; set; }
+
+        [NullEditor]
+        public StagingBOMLink StagingBOM { get; set; }
+
+        [NullEditor]
+        public StagingSetoutLink StagingSetout { get; set; }
+
+        [NullEditor]
+        public StagingManufacturingPacketLink StagingManufacturingPacket { get; set; }
+
+        [NullEditor]
+        public long Sequence { get; set; }
+
+        protected override void Init()
+        {
+            base.Init();
+
+            StagingBOM = new StagingBOMLink();
+            StagingSetout = new StagingSetoutLink();
+            Product = new ProductLink(() => this);
+            Dimensions = new ProductDimensions(() => this);
+            StagingManufacturingPacket = new StagingManufacturingPacketLink();
+        }
+
+        public void CopyFrom(StagingBOMItem source, bool observing = false)
+        {
+            if (!observing)
+                SetObserving(false);
+            StagingBOM.ID = source.StagingBOM.ID;
+            StagingSetout.ID = source.StagingSetout.ID;
+            Product.ID = source.Product.ID;
+            StagingManufacturingPacket.ID = source.StagingManufacturingPacket.ID;
+            Dimensions.CopyFrom(source.Dimensions);
+            Quantity = source.Quantity;
+            if (!observing)
+                SetObserving(true);
+        }
+    }
+}

+ 12 - 0
prs.classes/Entities/Staging/BOM/StagingBOMLink.cs

@@ -0,0 +1,12 @@
+using InABox.Core;
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace Comal.Classes
+{
+    public class StagingBOMLink : EntityLink<StagingBOM>
+    {
+        public override Guid ID { get; set; }
+    }
+}

+ 5 - 15
prs.classes/Entities/Staging/Manufacturing/Packet/StagingManufacturingPacketComponent.cs

@@ -5,7 +5,7 @@ using System.Text;
 
 namespace Comal.Classes
 {
-    public class StagingManufacturingPacketComponent : Entity, IPersistent, IRemotable, ILicense<ManufacturingLicense>
+    public class StagingManufacturingPacketComponent : DimensionedEntity<ProductDimensions>, IPersistent, IRemotable, ILicense<ManufacturingLicense>
     {
         [NullEditor]
         public StagingManufacturingPacketLink Packet { get; set; }
@@ -16,14 +16,8 @@ namespace Comal.Classes
         [EditorSequence(2)]
         public int Quantity { get; set; }
 
-        [EditorSequence(3)]
-        public double Length { get; set; }
-
-        public double Height { get; set; }
-
-        public double Width { get; set; }
-
-        public Guid ComponentID { get; set; }
+        [DimensionsEditor(typeof(ProductDimensions))]
+        public override ProductDimensions Dimensions { get; set; }
 
         protected override void Init()
         {
@@ -31,9 +25,7 @@ namespace Comal.Classes
             Packet = new StagingManufacturingPacketLink();
             Product = new ProductLink(() => this);
             Quantity = 1;
-            Length = 0;
-            Height = 0;
-            ComponentID = Guid.Empty;
+            Dimensions = new ProductDimensions(() => this);
         }
 
         public ManufacturingPacketComponent CreateComponent(Guid packetID) 
@@ -42,9 +34,7 @@ namespace Comal.Classes
             component.Packet.ID = packetID;
             component.Product.ID = Product.ID;
             component.Quantity = Quantity;
-            component.Length = Length;
-            component.Height = Height;
-            component.Width = Width;
+            component.Dimensions.CopyFrom(Dimensions);
             return component;
         }
         

+ 3 - 2
prs.desktop/Panels/DataEntry/DataEntryGrid.cs

@@ -8,6 +8,7 @@ using System;
 using System.Collections.Generic;
 using System.IO;
 using System.Linq;
+using System.Windows;
 using System.Windows.Media.Imaging;
 
 namespace PRSDesktop
@@ -153,7 +154,7 @@ namespace PRSDesktop
             Refresh(false,true);
         }
         
-        protected override void OnRowsDragStart(CoreRow[] rows)
+        protected override DragDropEffects OnRowsDragStart(CoreRow[] rows)
         {
             var table = new CoreTable();
 
@@ -165,7 +166,7 @@ namespace PRSDesktop
                 table.Rows.Add(newRow);
             }
 
-            DragTable(typeof(Document), table);
+            return DragTable(typeof(Document), table);
         }
 
         public void UploadDocument(string filename, byte[] data, Guid tagID)

+ 2 - 2
prs.desktop/Panels/Products/Master List/ProductsGrid.cs

@@ -271,8 +271,8 @@ namespace PRSDesktop
             cec.Value = total;
         }
 
-        protected override void Reload(Filters<Product> criteria, Columns<Product> columns, ref SortOrder<Product> sort,
-            Action<CoreTable, Exception> action)
+        protected override void Reload(Filters<Product> criteria, Columns<Product> columns, ref SortOrder<Product>? sort,
+            Action<CoreTable?, Exception?> action)
         {
             if (!_includeexpired)
                 criteria.Add(new Filter<Product>(x => x.Expired).IsEqualTo(DateTime.MinValue));

+ 14 - 0
prs.desktop/Panels/Staging/BOM/StagingBOMGrid.cs

@@ -0,0 +1,14 @@
+using Comal.Classes;
+using InABox.DynamicGrid;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace PRSDesktop
+{
+    public class StagingBOMGrid : DynamicDataGrid<StagingBOM>
+    {
+    }
+}

+ 150 - 0
prs.desktop/Panels/Staging/BOM/StagingBOMItemGrid.cs

@@ -0,0 +1,150 @@
+using Comal.Classes;
+using InABox.Clients;
+using InABox.Core;
+using InABox.DynamicGrid;
+using InABox.WPF;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+
+namespace PRSDesktop
+{
+    public class StagingBOMItemGrid : DynamicDataGrid<StagingBOMItem>
+    {
+        private StagingSetout? _stagingSetout = null;
+        public StagingSetout? StagingSetout
+        {
+            get => _stagingSetout;
+            set
+            {
+                if(_stagingSetout == value)
+                {
+                    return;
+                }
+                _stagingSetout = value;
+                Reconfigure();
+                Refresh(false, true);
+            }
+        }
+
+        public StagingBOMItemGrid()
+        {
+            HiddenColumns.Add(x => x.Dimensions.Length);
+            HiddenColumns.Add(x => x.Dimensions.Width);
+            HiddenColumns.Add(x => x.Dimensions.Height);
+            HiddenColumns.Add(x => x.Dimensions.Weight);
+            HiddenColumns.Add(x => x.Dimensions.Quantity);
+            HiddenColumns.Add(x => x.Dimensions.Unit.ID);
+            HiddenColumns.Add(x => x.Dimensions.UnitSize);
+            HiddenColumns.Add(x => x.Dimensions.Value);
+            HiddenColumns.Add(x => x.Quantity);
+            HiddenColumns.Add(x => x.Product.ID);
+            HiddenColumns.Add(x => x.Sequence);
+            HiddenColumns.Add(x => x.StagingBOM.ID);
+            HiddenColumns.Add(x => x.StagingSetout.ID);
+            HiddenColumns.Add(x => x.StagingManufacturingPacket.ID);
+
+            ActionColumns.Add(new DynamicImageColumn(PRSDesktop.Resources.split.AsBitmapImage(), Split));
+        }
+
+        private bool Split(CoreRow? row)
+        {
+            if(row is null)
+            {
+                return false;
+            }
+
+            var quantity = row.Get<StagingBOMItem, int>(x => x.Quantity);
+
+            if(quantity <= 1)
+            {
+                MessageBox.Show($"Cannot split item with quantity {quantity}");
+                return false;
+            }
+
+            int value = quantity / 2;
+            while (quantity <= 3 || NumberEdit.Execute("Please enter how many items to split on.", int.MinValue, int.MaxValue, ref value))
+            {
+                if (value >= 1 && value < quantity)
+                {
+                    var item = row.ToObject<StagingBOMItem>();
+                    var newItem = CreateItem();
+                    newItem.CopyFrom(item);
+                    newItem.Quantity = quantity - value;
+                    newItem.Sequence = item.Sequence + 1;
+                    item.Quantity = value;
+
+                    var items = new List<StagingBOMItem> { item, newItem };
+                    var s = newItem.Sequence + 2;
+                    for (int j = row.Index + 1; j < Data.Rows.Count; ++j, ++s)
+                    {
+                        var sequencedItem = Data.Rows[j].ToObject<StagingBOMItem>();
+                        sequencedItem.Sequence = s;
+                        items.Add(sequencedItem);
+                    }
+
+                    SaveItems(items.ToArray());
+                    return true;
+                }
+                else
+                {
+                    MessageBox.Show($"Value must be in the range [1,{quantity - 1}]");
+                }
+            }
+            return false;
+        }
+
+        protected override StagingBOMItem CreateItem()
+        {
+            var item = base.CreateItem();
+            item.StagingSetout.ID = StagingSetout?.ID ?? Guid.Empty;
+            item.Sequence = Data.Rows.Last().Get<StagingBOMItem, long>(x => x.Sequence) + 1;
+            return item;
+        }
+
+        protected override void DoReconfigure(FluentList<DynamicGridOption> options)
+        {
+            base.DoReconfigure(options);
+            options.Remove(DynamicGridOption.AddRows);
+            options.Remove(DynamicGridOption.EditRows);
+            options.Remove(DynamicGridOption.DeleteRows);
+
+            options.Add(DynamicGridOption.MultiSelect);
+            options.Add(DynamicGridOption.SelectColumns);
+            if (StagingSetout is not null)
+            {
+                options.Add(DynamicGridOption.DragSource);
+            }
+        }
+
+        protected override DragDropEffects OnRowsDragStart(CoreRow[] rows)
+        {
+            var effect = base.OnRowsDragStart(rows);
+            Refresh(false, true);
+            return effect;
+        }
+
+        protected override void Reload(Filters<StagingBOMItem> criteria, Columns<StagingBOMItem> columns, ref SortOrder<StagingBOMItem>? sort, Action<CoreTable?, Exception?> action)
+        {
+            if (sort == null)
+                sort = new SortOrder<StagingBOMItem>(x => x.Sequence);
+            else
+                sort.ThenBy(x => x.Sequence);
+
+            if (StagingSetout is null)
+            {
+                criteria.Add(new Filter<StagingBOMItem>().None());
+            }
+            else
+            {
+                criteria.Add(new Filter<StagingBOMItem>(x => x.StagingSetout.ID).IsEqualTo(StagingSetout.ID));
+                criteria.Add(new Filter<StagingBOMItem>(x => x.StagingManufacturingPacket.ID).IsEqualTo(Guid.Empty));
+            }
+            base.Reload(criteria, columns, ref sort, action);
+        }
+    }
+}

+ 30 - 1
prs.desktop/Panels/Staging/Manufacturing/StagingManufacturingPacketComponentGrid.cs

@@ -1,4 +1,6 @@
-using Comal.Classes;
+using com.sun.security.ntlm;
+using Comal.Classes;
+using InABox.Clients;
 using InABox.Core;
 using InABox.DynamicGrid;
 using System;
@@ -6,6 +8,7 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
+using System.Windows;
 
 namespace PRSDesktop
 {
@@ -55,6 +58,7 @@ namespace PRSDesktop
                 options.Add(DynamicGridOption.EditRows);
                 options.Add(DynamicGridOption.DeleteRows);
                 options.Add(DynamicGridOption.DirectEdit);
+                options.Add(DynamicGridOption.DragTarget);
             }
 
             options.EndUpdate();
@@ -71,6 +75,31 @@ namespace PRSDesktop
             base.Reload(criteria, columns, ref sort, action);
         }
 
+        protected override void OnDragEnd(Type entity, CoreTable table, DragEventArgs e)
+        {
+            base.OnDragEnd(entity, table, e);
+
+            if(entity == typeof(StagingBOMItem))
+            {
+                var components = new List<StagingManufacturingPacketComponent>();
+                var bomItems = table.ToObjects<StagingBOMItem>().ToList();
+                foreach (var bomItem in bomItems)
+                {
+                    var component = CreateItem();
+                    component.Dimensions.CopyFrom(bomItem.Dimensions);
+                    component.Product.ID = bomItem.Product.ID;
+                    component.Quantity = bomItem.Quantity;
+                    components.Add(component);
+                    bomItem.StagingManufacturingPacket.ID = Packet.ID;
+                }
+                new Client<StagingBOMItem>().Save(bomItems, "Added to packet.");
+                SaveItems(components.ToArray());
+
+                Refresh(false, true);
+                e.Effects = DragDropEffects.Move;
+            }
+        }
+
         protected override StagingManufacturingPacketComponent CreateItem()
         {
             var item = base.CreateItem();

+ 2 - 2
prs.desktop/Panels/Staging/Manufacturing/StagingManufacturingPacketGrid.cs

@@ -55,11 +55,11 @@ namespace PRSDesktop.Panels.Staging
 
         private void StagingManufacturingPacketGrid_OnEditorLoaded(IDynamicEditorForm editor, StagingManufacturingPacket[] items)
         {
-            if (items.Count() == 1 && items.FirstOrDefault().Job.ID != Guid.Empty)
+            if (items.Length == 1 && items.First().Job.ID != Guid.Empty)
             {
+                var item = items.First();
                 Dispatcher.BeginInvoke(() =>
                 {
-                    var item = items.FirstOrDefault();
                     var itermediate = item.ITP.ID;
                     LoadITPLookups(editor, item.Job.ID);
                     item.ITP.ID = itermediate;

+ 4 - 0
prs.desktop/Panels/Staging/Manufacturing/StagingManufacturingPacketList.xaml.cs

@@ -39,6 +39,10 @@ namespace PRSDesktop
             get => _setout;
             set
             {
+                if(_setout == value)
+                {
+                    return;
+                }
                 _setout = value;
                 if(value is null)
                 {

+ 38 - 30
prs.desktop/Panels/Staging/StagingPanel.xaml

@@ -20,8 +20,8 @@
         <dynamicgrid:DynamicSplitPanel.Master>
             <Grid x:Name="masterGrid">
                 <Grid.RowDefinitions>
-                    <RowDefinition Height="2*"/>
-                    <RowDefinition Height="0"/>
+                    <RowDefinition Height="*"/>
+                    <RowDefinition Height="*"/>
                 </Grid.RowDefinitions>
                 <local:StagingSetoutGrid 
                     Grid.Row="0" 
@@ -29,7 +29,10 @@
                     OnCustomiseSetouts="stagingSetoutGrid_OnCustomiseSetouts" 
                     OnDoubleClick="StagingSetoutGrid_OnOnDoubleClick"
                     OnSelectItem="StagingSetoutGrid_OnSelectItem"/>
-                <local:StagingMaterialListGrid Grid.Row="1" x:Name="stagingMaterialListGrid"/>
+                <local:StagingBOMGrid x:Name="BOMGrid"
+                                      OnChanged="BOMGrid_OnChanged"
+                                      Grid.Row="1"
+                                      Margin="0,5,0,0"/>
             </Grid>
         </dynamicgrid:DynamicSplitPanel.Master>
         
@@ -118,50 +121,55 @@
                         </Border>
                     </DockPanel>
                 </dynamicgrid:DynamicSplitPanel.DetailHeader>
-                
+
                 <dynamicgrid:DynamicSplitPanel.Detail>
                     <Grid>
                         <Grid.RowDefinitions>
                             <RowDefinition Height="*"/>
                             <RowDefinition Height="Auto"/>
+                            <RowDefinition Height="*"/>
+                            <RowDefinition Height="Auto"/>
                         </Grid.RowDefinitions>
                         <local:StagingManufacturingPacketList x:Name="ManufacturingPacketList" OnCollapsed="ManufacturingPacketList_OnCollapsed"
-                                                              Grid.Row="0" Changed="ManufacturingPacketList_OnChanged"/>
+                                                            Grid.Row="0" Changed="ManufacturingPacketList_OnChanged"/>
+                        <GridSplitter Grid.Row="1"/>
+                        <local:StagingBOMItemGrid x:Name="BOMItemGrid"
+                                                  Grid.Row="2"
+                                                  Margin="0,5,0,0"/>
                         <DockPanel 
-                            LastChildFill="False"
-                            Grid.Row="1"
-                            Margin="0,2,0,0"
-                            Height="30">
+                                LastChildFill="False"
+                                Grid.Row="3"
+                                Margin="0,2,0,0"
+                                Height="30">
                             <Button 
-                                DockPanel.Dock="Right"
-                                Content="Process"
-                                x:Name="ProcessButton"
-                                Padding="20,0"
-                                BorderBrush="Gray" BorderThickness="0.75" 
-                                Click="ProcessButton_Click"/>
+                                    DockPanel.Dock="Right"
+                                    Content="Process"
+                                    x:Name="ProcessButton"
+                                    Padding="20,0"
+                                    BorderBrush="Gray" BorderThickness="0.75" 
+                                    Click="ProcessButton_Click"/>
 
                             <Border BorderBrush="Gray" BorderThickness="0.75" DockPanel.Dock="Left" Padding="10,0">
                                 <StackPanel Orientation="Horizontal" VerticalAlignment="Center">
                                     <Label
-                                        Content="Total Time"
-                                        HorizontalContentAlignment="Center"
-                                        VerticalContentAlignment="Center"
-                                        Margin="0"
-                                        FontWeight="DemiBold"
-                                        Foreground="Gray"
-                                        Padding="0"/>
+                                            Content="Total Time"
+                                            HorizontalContentAlignment="Center"
+                                            VerticalContentAlignment="Center"
+                                            Margin="0"
+                                            FontWeight="DemiBold"
+                                            Foreground="Gray"
+                                            Padding="0"/>
                                     <Label
-                                        x:Name="TimeRequired"
-                                        HorizontalContentAlignment="Center"
-                                        VerticalContentAlignment="Center"
-                                        Margin="5,0,0,0"
-                                        Foreground="Gray"
-                                        Padding="0"/>
-                              </StackPanel>
+                                            x:Name="TimeRequired"
+                                            HorizontalContentAlignment="Center"
+                                            VerticalContentAlignment="Center"
+                                            Margin="5,0,0,0"
+                                            Foreground="Gray"
+                                            Padding="0"/>
+                                </StackPanel>
                             </Border>
                         </DockPanel>
                     </Grid>
-
                 </dynamicgrid:DynamicSplitPanel.Detail>
 
             </dynamicgrid:DynamicSplitPanel>

+ 35 - 13
prs.desktop/Panels/Staging/StagingPanel.xaml.cs

@@ -85,7 +85,7 @@ public class Module
         /// </summary>
         private List<StagingSetout> selectedSetouts = new();
 
-        private CoreTable? _templateGroups = null;
+        private CoreTable _templateGroups = null!;
 
         #region Script Stuff
 
@@ -136,7 +136,6 @@ public class Module
         {
             InitializeComponent();
             SectionName = nameof(StagingPanel);
-            
         }
 
         public void Setup()
@@ -152,14 +151,19 @@ public class Module
 
             //stagingSetoutGrid.ScanFiles(_settings.SetoutsFolder);
             stagingSetoutGrid.Refresh(true, false);
+            BOMGrid.Refresh(true, false);
+            BOMItemGrid.Refresh(true, false);
             
         }
 
+        private bool CanViewPackets() => MainPanel.View != DynamicSplitPanelView.Master && NestedPanel.View != DynamicSplitPanelView.Master;
+
         private void NestedPanel_OnChanged(object sender, DynamicSplitPanelSettings e)
         {
-            if(e.View != DynamicSplitPanelView.Master && ManufacturingPacketList.Setout != selectedSetout)
+            if(CanViewPackets())
             {
                 ManufacturingPacketList.Setout = selectedSetout;
+                BOMItemGrid.StagingSetout = selectedSetout;
             }
         }
 
@@ -448,10 +452,10 @@ public class Module
                     Serial = stagingPacket.Serial,
                     Title = stagingPacket.Title,
                     Quantity = stagingPacket.Quantity,
-                    BarcodeQty = String.IsNullOrWhiteSpace(stagingPacket.BarcodeQuantity) 
+                    BarcodeQty = string.IsNullOrWhiteSpace(stagingPacket.BarcodeQuantity) 
                         ? stagingPacket.Quantity 
                         : int.Parse(stagingPacket.BarcodeQuantity),
-                    WaterMark = String.IsNullOrWhiteSpace(stagingPacket.Watermark) 
+                    WaterMark = string.IsNullOrWhiteSpace(stagingPacket.Watermark) 
                         ? stagingPacket.Group.Watermark
                         : stagingPacket.Watermark,
                     Location = stagingPacket.Location
@@ -488,11 +492,16 @@ public class Module
                     .Query(
                         new Filter<StagingManufacturingPacketComponent>(x => x.Packet.ID).IsEqualTo(stagingPacket.ID),
                         new Columns<StagingManufacturingPacketComponent>(x=>x.Packet.ID)
-                            .Add(x=>x.Product.ID)
-                            .Add(x=>x.Quantity)
-                            .Add(x=>x.Length)
-                            .Add(x=>x.Height)
-                            .Add(x=>x.Width)
+                            .Add(x => x.Product.ID)
+                            .Add(x => x.Quantity)
+                            .Add(x => x.Dimensions.Unit.ID)
+                            .Add(x => x.Dimensions.Quantity)
+                            .Add(x => x.Dimensions.Length)
+                            .Add(x => x.Dimensions.Width)
+                            .Add(x => x.Dimensions.Height)
+                            .Add(x => x.Dimensions.Weight)
+                            .Add(x => x.Dimensions.Value)
+                            .Add(x => x.Dimensions.UnitSize)
                     );
                 
                 newComponents.AddRange(components.ToObjects<StagingManufacturingPacketComponent>()
@@ -595,7 +604,7 @@ public class Module
             {
                 try
                 {
-                    File.WriteAllBytes(selectedSetout?.OriginalPath, _documentdata);
+                    File.WriteAllBytes(selectedSetout.OriginalPath, _documentdata);
                     selectedSetout.OriginalCRC = CoreUtils.CalculateCRC(_documentdata);
                     new Client<StagingSetout>().Save(selectedSetout,"Updated Source File with markups");
                     UpdateOriginalButton.Visibility = Visibility.Collapsed;
@@ -685,6 +694,7 @@ public class Module
                 Document = null;
                 ManufacturingPacketList.Setout = null;
                 CollapsePacketsButton.IsEnabled = false;
+                BOMItemGrid.StagingSetout = null;
                 SetMode(DocumentMode.Markup);
                 return;
             }
@@ -704,13 +714,15 @@ public class Module
                 Document = null;
                 ManufacturingPacketList.Setout = null;
                 CollapsePacketsButton.IsEnabled = false;
+                BOMItemGrid.StagingSetout = null;
                 return;
             }
 
             Document = doc;
-            if(MainPanel.View != DynamicSplitPanelView.Master && NestedPanel.View != DynamicSplitPanelView.Master)
+            if(CanViewPackets())
             {
                 ManufacturingPacketList.Setout = selectedSetout;
+                BOMItemGrid.StagingSetout = selectedSetout;
             }
             CollapsePacketsButton.IsEnabled = true;
             var mode =
@@ -822,6 +834,7 @@ public class Module
             Document = null;
 
             ManufacturingPacketList.Setout = null;
+            BOMItemGrid.StagingSetout = null;
             CalculateTime();
         }
 
@@ -843,7 +856,7 @@ public class Module
 
         private void AddPacketButton_Click(object sender, RoutedEventArgs e)
         {
-            if (_templateGroups.Rows.Any())
+            if (_templateGroups.Rows.Any() == true)
             {
                 ContextMenu menu = new ContextMenu();
                 foreach (var row in _templateGroups.Rows)
@@ -941,6 +954,7 @@ public class Module
         private void StagingSetoutGrid_OnOnDoubleClick(object sender, HandledEventArgs args)
         {
             ManufacturingPacketList.Setout = selectedSetout;
+            BOMItemGrid.StagingSetout = selectedSetout;
             MainPanel.View = DynamicSplitPanelView.Detail;
             NestedPanel.View = DynamicSplitPanelView.Combined;
             args.Handled = true;
@@ -962,5 +976,13 @@ public class Module
            CalculateTime();
            UpdateStagingSetoutGrid();
         }
+
+        private void BOMGrid_OnChanged(object sender, EventArgs e)
+        {
+            if (CanViewPackets())
+            {
+                BOMItemGrid.Refresh(false, true);
+            }
+        }
     }
 }