Browse Source

Added ability to copy last manufacturing packet in staging panel

Kenric Nugteren 1 năm trước cách đây
mục cha
commit
0cd479d63f

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

@@ -40,9 +40,9 @@ namespace PRSDesktop
         public void InitialiseData(StagingManufacturingPacket packet, CoreTable? data)
         {
             Packet = packet;
-            _data = new CoreTable();
             if (data is not null)
             {
+                _data = new CoreTable();
                 _data.LoadColumns(data.Columns);
                 _data.LoadRows(data.Rows.Where(x => x.Get<StagingManufacturingPacketComponent, Guid>(x => x.Packet.ID) == packet.ID));
             }

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

@@ -134,9 +134,23 @@ namespace PRSDesktop
                 MessageBox.Show("Please select a setout first.");
                 return;
             }
+
+            var lastPacket = group != null ? GetPackets().LastOrDefault(x => x.Group.ID == group.ID) : null;
+            lastPacket ??= GetPackets().LastOrDefault();
             
             var newPacket = new StagingManufacturingPacket();
             newPacket.Job.ID = jobid;
+
+            if(lastPacket != null)
+            {
+                newPacket.Template.ID = lastPacket.Template.ID;
+                newPacket.Template.Synchronise(lastPacket.Template);
+                newPacket.Title = lastPacket.Title;
+                newPacket.ITP.ID = lastPacket.ITP.ID;
+                newPacket.ITP.Synchronise(lastPacket.ITP);
+                newPacket.Location = lastPacket.Location;
+                newPacket.Watermark = lastPacket.Watermark;
+            }
             
             if (group != null)
             {
@@ -157,9 +171,24 @@ namespace PRSDesktop
             newPacket.Serial = $"{serialbase}{iSerial:D3}";
             
             new Client<StagingManufacturingPacket>().Save(newPacket,"Created from Staging Panel");
-            //var grid = DynamicGridUtils.CreateDynamicGrid(typeof(DynamicDataGrid<>), typeof(StagingManufacturingPacket));
-            //if (grid.EditItems(new object[] { newPacket }))
-            //{
+
+            if (lastPacket != null)
+            {
+                var treatments = Client.Query(
+                    new Filter<StagingManufacturingPacketTreatment>(x => x.Packet.ID).IsEqualTo(lastPacket.ID),
+                    new Columns<StagingManufacturingPacketTreatment>()
+                        .Default(ColumnType.IncludeUserProperties, ColumnType.IncludeForeignKeys, ColumnType.ExcludeID)
+                ).ToObjects<StagingManufacturingPacketTreatment>().ToList();
+                foreach(var treatment in treatments)
+                {
+                    treatment.Packet.ID = newPacket.ID;
+                }
+                Client.Save(treatments, "");
+            }
+
+                //var grid = DynamicGridUtils.CreateDynamicGrid(typeof(DynamicDataGrid<>), typeof(StagingManufacturingPacket));
+                //if (grid.EditItems(new object[] { newPacket }))
+                //{
                 StagingManufacturingPacketListItem.CreateStages(newPacket);
                 AddItem(newPacket, null);
                 //OnCollapsed?.Invoke(Collapsed());

+ 1 - 1
prs.desktop/Panels/Staging/Manufacturing/StagingManufacturingPacketStageGrid.cs

@@ -38,9 +38,9 @@ namespace PRSDesktop
         public void InitialiseData(StagingManufacturingPacket packet, CoreTable? data)
         {
             Packet = packet;
-            _data = new CoreTable();
             if(data is not null)
             {
+                _data = new CoreTable();
                 _data.LoadColumns(data.Columns);
                 _data.LoadRows(data.Rows.Where(x => x.Get<StagingManufacturingPacketStage, Guid>(x => x.Packet.ID) == packet.ID));
             }

+ 1 - 1
prs.desktop/Panels/Staging/Manufacturing/StagingManufacturingPacketTreatmentGrid.cs

@@ -34,9 +34,9 @@ public class StagingManufacturingPacketTreatmentGrid : DynamicDataGrid<StagingMa
     public void InitialiseData(StagingManufacturingPacket packet, CoreTable? data)
     {
         Packet = packet;
-        _data = new CoreTable();
         if (data is not null)
         {
+            _data = new CoreTable();
             _data.LoadColumns(data.Columns);
             _data.LoadRows(data.Rows.Where(x => x.Get<StagingManufacturingPacketTreatment, Guid>(x => x.Packet.ID) == packet.ID));
         }