소스 검색

DESKTOP - added functionality to staging manufacturing packet components

Nick-PRSDigital@bitbucket.org 2 년 전
부모
커밋
14333164db

+ 17 - 0
prs.classes/Entities/Staging/Manufacturing/StagingManufacturingPacketComponent.cs

@@ -23,12 +23,29 @@ namespace Comal.Classes
 
         public double Width { get; set; }
 
+        public Guid ComponentID { get; set; }
 
         protected override void Init()
         {
             base.Init();
             StagingPacket = new StagingManufacturingPacketLink();
             Product = new ProductLink(() => this);
+            Quantity = 0;
+            Length = 0;
+            Height = 0;
+            ComponentID = Guid.Empty;
+        }
+
+        public ManufacturingPacketComponent CreateComponent(Guid packetID) 
+        {
+            var component = new ManufacturingPacketComponent();
+            component.Packet.ID = packetID;
+            component.Product.ID = Product.ID;
+            component.Quantity = Quantity;
+            component.Length = Length;
+            component.Height = Height;
+            component.Width = Width;
+            return component;
         }
     }
 }

+ 1 - 1
prs.classes/Entities/Stock/StockMovement.cs

@@ -140,7 +140,7 @@ namespace Comal.Classes
         [NullEditor]
         public PurchaseOrderItemLink OrderItem { get; set; }
 
-        //[NullEditor]
+        [NullEditor]
         public JobRequisitionItemLink JobRequisitionItem { get; set; }
 
         [Aggregate(typeof(StockMovementDocumentCount))]

+ 3 - 3
prs.desktop/Panels/Staging/Manufacturing/ManufacturingPacketApprovalControl.xaml.cs

@@ -31,7 +31,7 @@ namespace PRSDesktop
             {
                 stagingsetout = value;
                 packetGrid.StagingSetout = value;
-                componentsGrid.Packet = new StagingManufacturingPacket();
+                componentsGrid.StagingPacket = new StagingManufacturingPacket();
             }
         }
 
@@ -43,7 +43,7 @@ namespace PRSDesktop
                 if (StagingSetout.ID != Guid.Empty)
                 {
                     packetGrid.Refresh(false, true);
-                    componentsGrid.Packet = new StagingManufacturingPacket();
+                    componentsGrid.StagingPacket = new StagingManufacturingPacket();
                 }
         }
 
@@ -55,7 +55,7 @@ namespace PRSDesktop
 
         private void PacketGrid_OnSelectItem(object sender, InABox.DynamicGrid.DynamicGridSelectionEventArgs e)
         {
-            componentsGrid.Packet = packetGrid.SelectedRows.FirstOrDefault().ToObject<StagingManufacturingPacket>();
+            componentsGrid.StagingPacket = packetGrid.SelectedRows.FirstOrDefault().ToObject<StagingManufacturingPacket>();
         }
 
         private void CreatePacketButton_Click(object sender, RoutedEventArgs e)

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

@@ -11,13 +11,13 @@ namespace PRSDesktop
 {
     public class StagingManufacturingPacketComponentGrid : DynamicDataGrid<StagingManufacturingPacketComponent>
     {
-        private StagingManufacturingPacket packet;
-        public StagingManufacturingPacket Packet
+        private StagingManufacturingPacket stagingPacket;
+        public StagingManufacturingPacket StagingPacket
         {
-            get => packet;
+            get => stagingPacket;
             set
             {
-                packet = value;
+                stagingPacket = value;
                 if (value.ID != Guid.Empty)
                 {
                     Options.Add(DynamicGridOption.AddRows);
@@ -40,7 +40,7 @@ namespace PRSDesktop
 
         public StagingManufacturingPacketComponentGrid()
         {
-            Packet = new StagingManufacturingPacket();
+            StagingPacket = new StagingManufacturingPacket();
             Options.Remove(DynamicGridOption.ImportData);
             Options.Remove(DynamicGridOption.ExportData);
             
@@ -49,11 +49,11 @@ namespace PRSDesktop
 
         protected override void Reload(Filters<StagingManufacturingPacketComponent> criteria, Columns<StagingManufacturingPacketComponent> columns, ref SortOrder<StagingManufacturingPacketComponent>? sort, Action<CoreTable?, Exception?> action)
         {
-            if (Packet.ID == Guid.Empty)
+            if (StagingPacket.ID == Guid.Empty)
                 criteria.Add(new Filter<StagingManufacturingPacketComponent>(x => x.ID).IsEqualTo(Guid.Empty));
 
             else
-                criteria.Add(new Filter<StagingManufacturingPacketComponent>(x => x.StagingPacket.ID).IsEqualTo(Packet.ID));
+                criteria.Add(new Filter<StagingManufacturingPacketComponent>(x => x.StagingPacket.ID).IsEqualTo(StagingPacket.ID));
 
             base.Reload(criteria, columns, ref sort, action);
         }
@@ -61,7 +61,7 @@ namespace PRSDesktop
         protected override StagingManufacturingPacketComponent CreateItem()
         {
             var item = base.CreateItem();
-            item.StagingPacket.ID = Packet.ID;
+            item.StagingPacket.ID = StagingPacket.ID;
 
             return item;
         }

+ 11 - 8
prs.desktop/Panels/Staging/Setouts/StagingSetoutGrid.cs

@@ -173,20 +173,23 @@ namespace PRSDesktop
 
         public void DeleteFile(IEntityDocument document)
         {
-            try
+            var file = GetFiles().FirstOrDefault(x => x.Name == document.DocumentLink.FileName);
+            if (file.Exists)
             {
-                var file = GetFiles().FirstOrDefault(x => x.Name == document.DocumentLink.FileName);
-                if (file.Exists)
+                try
                 {
                     file.Attributes = FileAttributes.Normal;
                     file.Delete();
                 }
-
-            }
-            catch (Exception ex)
-            {
-
+                catch (Exception ex)
+                {
+                    MessageBox.Show("If your file is currently open in another program, please close it now and press OK to try again", "Error deleting file", MessageBoxButton.OK);
+                    file.Attributes = FileAttributes.Normal;
+                    file.Delete();
+                }
             }
+            else
+                MessageBox.Show("Could not find file!");  
         }
     }
 }

+ 80 - 34
prs.desktop/Panels/Staging/StagingPanel.xaml.cs

@@ -93,7 +93,7 @@ namespace PRSDesktop
             else
             {
                 if (manufacturingControl.Data.Rows.Count == 0)
-                    if (MessageBox.Show("No Packets created for this setout", "Proceed?", MessageBoxButton.YesNo) != MessageBoxResult.Yes)
+                    if (MessageBox.Show("No Packets created for this setout. Continue?", "Proceed?", MessageBoxButton.YesNo) != MessageBoxResult.Yes)
                         return;
 
                 setout.Number = _item.Number;
@@ -128,7 +128,9 @@ namespace PRSDesktop
         private void CreatePackets(Setout setout)
         {
             List<ManufacturingPacket> packets = new List<ManufacturingPacket>();
-            List<StagingManufacturingPacket> stagings = new List<StagingManufacturingPacket>();
+            List<StagingManufacturingPacket> stagingPackets = new List<StagingManufacturingPacket>();
+
+            //create new manufacturing packets from the staging packets
             foreach (var row in manufacturingControl.Data.Rows)
             {
                 var staging = row.ToObject<StagingManufacturingPacket>();
@@ -148,38 +150,91 @@ namespace PRSDesktop
                 packet.Location = staging.Location;
 
                 packets.Add(packet);
-                stagings.Add(staging);
+                stagingPackets.Add(staging);
             }
 
+            //save the newly created packets to provide an ID
             new Client<ManufacturingPacket>().Save(packets, "Created from Design Management Panel");
 
+            //now work on their stages with the provided packet.ID
             List<ManufacturingPacketStage> stages = new List<ManufacturingPacketStage>();
 
-            foreach (var staging in stagings)
+            Dictionary<StagingManufacturingPacketComponent, ManufacturingPacketComponent> stagingToActualComponents = new Dictionary<StagingManufacturingPacketComponent, ManufacturingPacketComponent>();
+
+            //Handled in this loop:
+            // - staging packets (update packet.ID)
+            // - creation of template stages
+            // - creation of components from staging components
+            foreach (var stagingPacket in stagingPackets)
             {
-                var packet = packets.FirstOrDefault(x => x.Serial == staging.Serial);
-                staging.ManufacturingPacket.ID = packet.ID;
-
-                CoreTable table = new Client<ManufacturingTemplateStage>().Query(
-                    new Filter<ManufacturingTemplateStage>(x => x.Template.ID).IsEqualTo(packet.ManufacturingTemplateLink.ID),
-                                new Columns<ManufacturingTemplateStage>
-                                (
-                                    x => x.Time,
-                                    x => x.Sequence,
-                                    x => x.SequenceType,
-                                    x => x.Section.ID,
-                                    x => x.Section.Name
-                                    ));
-                foreach (var row in table.Rows)
-                {
-                    var packetStage = row.ToObject<ManufacturingTemplateStage>().CreateManufacturingPacketStage();
-                    packetStage.ManufacturingPacketLink.ID = packet.ID;
-                    stages.Add(packetStage);
-                }      
+                var packet = packets.FirstOrDefault(x => x.Serial == stagingPacket.Serial);
+                stagingPacket.ManufacturingPacket.ID = packet.ID;
+
+                stages.AddRange(CreateStagesForTemplate(packet.ManufacturingTemplateLink.ID, packet.ID));
+
+                CreateComponents(stagingPacket.ID, packet.ID, stagingToActualComponents);
+            }
+
+            //save everything
+            MultiSave save = new MultiSave();
+            save.Add(typeof(ManufacturingPacketStage), stages.ToArray());
+            save.Add(typeof(StagingManufacturingPacket), stagingPackets.ToArray());
+            save.Add(typeof(ManufacturingPacketComponent), stagingToActualComponents.Values.ToArray());
+            save.Save(null, "Updated from setout staging screen");
+
+            foreach (var pair in stagingToActualComponents)
+            {
+                var stagingComponent = pair.Key;
+                stagingComponent.ComponentID = pair.Value.ID;
             }
 
-            new Client<ManufacturingPacketStage>().Save(stages, "Created from Design Management Panel");
-            new Client<StagingManufacturingPacket>().Save(stagings, "Added manufacturing packet id on packet creation");
+            new Client<StagingManufacturingPacketComponent>().Save(stagingToActualComponents.Keys.ToArray(), "Updated from setout staging screen");
+        }
+
+        private void CreateComponents(Guid stagingPacketID, Guid packetID, Dictionary<StagingManufacturingPacketComponent, ManufacturingPacketComponent> stagingToActualComponents)
+        {
+           var components = new List<ManufacturingPacketComponent>();
+            CoreTable table = new Client<StagingManufacturingPacketComponent>().Query(
+                new Filter<StagingManufacturingPacketComponent>(x => x.StagingPacket.ID).IsEqualTo(stagingPacketID)
+                .And(x => x.ComponentID).IsEqualTo(Guid.Empty),
+                new Columns<StagingManufacturingPacketComponent>(
+                    x => x.Product.ID,
+                    x => x.Quantity,
+                    x => x.Length,
+                    x => x.Height,
+                    x => x.Width
+                ));
+            foreach (var row in table.Rows)
+            { 
+                var stagingComponent = row.ToObject<StagingManufacturingPacketComponent>();
+                var component = stagingComponent.CreateComponent(packetID);
+                components.Add(component);
+
+                stagingToActualComponents.Add(stagingComponent, component);
+            }
+        }
+
+        private List<ManufacturingPacketStage> CreateStagesForTemplate(Guid templateID, Guid packetID)
+        {
+            var stages = new List<ManufacturingPacketStage>();
+            CoreTable table = new Client<ManufacturingTemplateStage>().Query(
+            new Filter<ManufacturingTemplateStage>(x => x.Template.ID).IsEqualTo(templateID),
+                new Columns<ManufacturingTemplateStage>
+                (
+                    x => x.Time,
+                    x => x.Sequence,
+                    x => x.SequenceType,
+                    x => x.Section.ID,
+                    x => x.Section.Name
+                    ));
+            foreach (var row in table.Rows)
+            {
+                var templateStage = row.ToObject<ManufacturingTemplateStage>();
+                var packetStage = templateStage.CreateManufacturingPacketStage();
+                packetStage.ManufacturingPacketLink.ID = packetID;
+                stages.Add(packetStage);
+            }
+            return stages;
         }
 
         private void DeleteAndRefresh(IEntityDocument stagingsetoutdocument)
@@ -335,13 +390,6 @@ namespace PRSDesktop
 
         private void DocumentPreviewer_OnMarkupSelected(IEntityDocument document)
         {
-            //if (string.IsNullOrWhiteSpace(_settings.MarkupPathway))
-            //{
-            //    MessageBox.Show("Please configure default Markup Program Pathway first");
-            //    return;
-            //}
-
-            //System.Diagnostics.Process.Start(_settings.SetoutsFolder + @"\" + document.DocumentLink.FileName);
             using (Process p = new Process())
             {
                 p.StartInfo = new ProcessStartInfo()
@@ -352,8 +400,6 @@ namespace PRSDesktop
 
                 p.Start();
             }
-
-
         }
 
         public void Shutdown()