コード例 #1
0
 private void BuildLotNumber()
 {
     lotNumber.Text = LotNumberParser.BuildLotNumber(new LotKeyImplementation
     {
         LotKey_DateCreated  = lotDatePicker.Value,
         LotKey_DateSequence = (int)lotDateSequence.Value,
         LotKey_LotTypeId    = (int)lotTypeId.Value
     }).ToString();
     SetQuery();
 }
コード例 #2
0
        private IEnumerable<tblBatchItem> CreateBatchItems(ProductionBatch batch, IDictionary<int, tblBOM> daBOMs)
        {
            var lotNumber = LotNumberParser.BuildLotNumber(batch);
            foreach(var pickedItem in batch.Production.PickedInventory.Items)
            {
                var availableQuantity = pickedItem.Quantity;
                var inventory = _unitOfWork.InventoryRepository.FindByKey(new InventoryKey(pickedItem));
                if(inventory != null)
                {
                    availableQuantity += inventory.Quantity;
                }
                var weight = pickedItem.PackagingProduct.Weight;
                var avaiableWeight = availableQuantity * weight;

                int? astaCalc = null;
                var asta = pickedItem.Lot.Attributes.FirstOrDefault(a => a.AttributeShortName == StaticAttributeNames.Asta.ShortName);
                if(asta != null)
                {
                    var productionDate = asta.AttributeDate;
                    if(batch.Production.Results != null)
                    {
                        productionDate = batch.Production.Results.ProductionEnd;
                    }
                    astaCalc = AstaCalculator.CalculateAsta(asta.AttributeValue, asta.AttributeDate, productionDate, DateTime.UtcNow);
                }

                yield return new tblBatchItem
                    {
                        EntryDate = pickedItem.PickedInventory.TimeStamp.ConvertUTCToLocal(),
                        Lot = LotNumberParser.BuildLotNumber(pickedItem),
                        TTypeID = (int?)TransType.Batching,
                        PkgID = int.Parse(pickedItem.Lot.LotTypeEnum == LotTypeEnum.Packaging ? pickedItem.Lot.PackagingLot.PackagingProduct.Product.ProductCode : pickedItem.PackagingProduct.Product.ProductCode),
                        Tote = pickedItem.ToteKey,
                        Quantity = pickedItem.Quantity,
                        NetWgt = (decimal?)weight,
                        TtlWgt = (decimal?)(pickedItem.Quantity * weight),
                        LocID = pickedItem.FromLocation.LocID.Value,
                        TrtmtID = pickedItem.TreatmentId,
                        EmployeeID = pickedItem.PickedInventory.EmployeeId,
                        NewLot = lotNumber,
                        BatchLot = lotNumber,
                        AstaCalc = astaCalc,
                        AvgAsta = asta == null ? null : (decimal?)asta.AttributeValue,
                        //ODetail = 
                        PackSchID = batch.PackSchedule.PackSchID,
                        AQ = availableQuantity,
                        AW = (decimal?)avaiableWeight,
                        LoBac = batch.Production.ResultingChileLot.AllAttributesAreLoBac,
                    
                        tblBOM = GetDaBOM(daBOMs, pickedItem)
                    };
            }
        }
コード例 #3
0
        private void SetPickedInventory(InventoryShipmentOrder newOrder, tblMove oldOrder, ref bool commitNewContext)
        {
            var MDetail            = OldContext.tblMoveDetails.Any() ? OldContext.tblMoveDetails.Max(m => m.MDetail).AddSeconds(1) : DateTime.UtcNow.ConvertUTCToLocal();
            var oldDetailsToRemove = oldOrder.tblMoveDetails.ToList();

            foreach (var newItem in newOrder.PickedInventory.Items)
            {
                var oldItem = oldDetailsToRemove.FirstOrDefault(d => d.MDetail == newItem.DetailID) ?? oldDetailsToRemove.FirstOrDefault();
                if (oldItem == null)
                {
                    oldItem = new tblMoveDetail
                    {
                        MDetail = MDetail
                    };
                    OldContext.tblMoveDetails.AddObject(oldItem);
                    MDetail = MDetail.AddSeconds(1);
                }
                else
                {
                    oldDetailsToRemove.Remove(oldItem);
                }

                oldItem.MoveNum         = newOrder.MoveNum.Value;
                oldItem.Lot             = LotNumberParser.BuildLotNumber(newItem);
                oldItem.TTypeID         = (int?)newOrder.OrderType.ToTransType();
                oldItem.PkgID           = OldContextHelper.GetPackaging(newItem.PackagingProduct).PkgID;
                oldItem.Quantity        = newItem.Quantity;
                oldItem.NetWgt          = (decimal?)newItem.PackagingProduct.Weight;
                oldItem.TtlWgt          = (decimal?)(newItem.Quantity * newItem.PackagingProduct.Weight);
                oldItem.LocID           = newItem.FromLocation.LocID.Value;
                oldItem.Move2           = newItem.CurrentLocation.LocID.Value;
                oldItem.TrtmtID         = OldContextHelper.GetTreatment(newItem).TrtmtID;
                oldItem.EmployeeID      = newOrder.PickedInventory.EmployeeId;
                oldItem.CustProductCode = newItem.CustomerProductCode;
                oldItem.CustLot         = newItem.CustomerLotCode;

                if (newItem.DetailID != oldItem.MDetail)
                {
                    commitNewContext = true;
                    newItem.DetailID = oldItem.MDetail;
                }
            }

            foreach (var o in oldDetailsToRemove)
            {
                OldContext.tblMoveDetails.DeleteObject(o);
            }
        }
コード例 #4
0
        public override void Synchronize(Func <LotKey> getInput)
        {
            if (getInput == null)
            {
                throw new ArgumentNullException("getInput");
            }
            var lotKey = getInput();

            var productionBatch = UnitOfWork.ProductionBatchRepository.FindByKey(lotKey,
                                                                                 b => b.PackSchedule.WorkType,
                                                                                 b => b.Production.PickedInventory.Items.Select(i => i.PackagingProduct.Product),
                                                                                 b => b.Production.PickedInventory.Items.Select(i => i.FromLocation),
                                                                                 b => b.Production.PickedInventory.Items.Select(i => i.Lot.Attributes),
                                                                                 b => b.Production.PickedInventory.Items.Select(i => i.Lot.PackagingLot.PackagingProduct.Product),
                                                                                 b => b.Production.Results,
                                                                                 b => b.Production.ResultingChileLot.Lot.Attributes.Select(a => a.AttributeName),
                                                                                 b => b.Production.ResultingChileLot.ChileProduct.Ingredients.Select(i => i.AdditiveType));

            if (productionBatch == null)
            {
                throw new Exception(string.Format("Could not find ProductionBatch[{0}] in new context.", lotKey.KeyValue));
            }

            var lotNumber = LotNumberParser.BuildLotNumber(productionBatch);
            var lotSelect = OldContext.tblLots
                            .Where(l => l.Lot == lotNumber)
                            .Select(l => new
            {
                Lot = l,
                l.tblBOMs,
                l.inputBatchItems,
                l.tblLotAttributeHistory
            })
                            .FirstOrDefault();

            if (lotSelect == null)
            {
                throw new Exception(string.Format("Could not find tblLot[{0}] in old context.", lotNumber));
            }

            new SyncProductionBatchPickedInventoryHelper(UnitOfWork, OldContext).SetBOMBatchItems(productionBatch, lotSelect.Lot);

            OldContext.SaveChanges();

            Console.WriteLine(ConsoleOutput.SetPickedItemsForLot, lotNumber);
        }
コード例 #5
0
ファイル: SyncPost.cs プロジェクト: vinneyk/RioValleyChili
 private tblOutgoing CreateOutgoing(InventoryShipmentOrder order, PickedInventoryItem item, Location location, int quantity, bool forMove)
 {
     return(new tblOutgoing
     {
         EntryDate = DateTime.UtcNow.ConvertUTCToLocal().RoundMillisecondsForSQL(),
         Lot = LotNumberParser.BuildLotNumber(item),
         TTypeID = (int?)order.OrderType.ToTransType(),
         PkgID = OldContextHelper.GetPackaging(item.PackagingProduct).PkgID,
         Tote = item.ToteKey,
         Quantity = quantity,
         NetWgt = (decimal?)item.PackagingProduct.Weight,
         TtlWgt = (decimal?)(quantity * item.PackagingProduct.Weight),
         LocID = (int)location.LocID,
         TrtmtID = OldContextHelper.GetTreatment(item).TrtmtID,
         EmployeeID = order.EmployeeId,
         BOMID = 0,
         BatchLot = 0,
         MoveNum = forMove ? order.MoveNum : null,
         MDetail = forMove ? item.DetailID : null,
         OrderNum = !forMove ? order.MoveNum : null,
         ODetail = !forMove ? item.DetailID : null,
         CustProductCode = item.CustomerProductCode
     });
 }
コード例 #6
0
            public void Update()
            {
                //Arrange
                var sampleOrder = RVCUnitOfWork
                                  .SampleOrderRepository.Filter(s => s.SampleID != null && s.Items.Count(i => i.SampleDetailID != null) > 1, i => i.Items)
                                  .OrderByDescending(s => s.Year)
                                  .FirstOrDefault();

                if (sampleOrder == null)
                {
                    Assert.Inconclusive("No suitable SampleOrder to test.");
                }

                var chileProduct = RVCUnitOfWork.ChileProductRepository.Filter(c => true, c => c.Product).FirstOrDefault();

                if (chileProduct == null)
                {
                    Assert.Inconclusive("No ChileProdut to test.");
                }

                var chileLot = RVCUnitOfWork.ChileLotRepository.Filter(c => true).FirstOrDefault();

                if (chileLot == null)
                {
                    Assert.Inconclusive("No ChileLot to test.");
                }

                var parameters = new SetSampleOrderParameters
                {
                    SampleOrderKey = sampleOrder.ToSampleOrderKey(),
                    UserToken      = TestUser.UserName,
                    PrintNotes     = ": D",
                    DateReceived   = new DateTime(2016, 1, 1),
                    DateDue        = new DateTime(2016, 1, 2),
                    Items          = new List <ISampleOrderItemParameters>
                    {
                        new SampleOrderItemParameters
                        {
                            SampleOrderItemKey = sampleOrder.Items.First().ToSampleOrderItemKey(),
                            ProductKey         = chileProduct.ToChileProductKey(),
                            LotKey             = chileLot.ToLotKey(),
                            Quantity           = 321,
                            Description        = "updated this item"
                        }
                    }
                };

                //Act
                var result = Service.SetSampleOrder(parameters);

                result.AssertSuccess();
                var resultString = GetKeyFromConsoleString(ConsoleOutput.SynchedTblSample);

                //Assert
                MockKillSwitch.Verify(k => k.Engage(), Times.Never());

                var sampleId = int.Parse(resultString);

                Assert.AreEqual(sampleOrder.SampleID, sampleId);
                using (var oldContext = new RioAccessSQLEntities())
                {
                    var tblSample = oldContext.tblSamples
                                    .Include(s => s.tblSampleDetails)
                                    .FirstOrDefault(s => s.SampleID == sampleId);
                    Assert.AreEqual(parameters.PrintNotes, tblSample.Notes2Print);

                    var expectedItem = parameters.Items.Single();
                    var resultItem   = tblSample.tblSampleDetails.Single();
                    Assert.AreEqual(expectedItem.Quantity, resultItem.Qty);
                    Assert.AreEqual(expectedItem.Description, resultItem.Desc);
                    Assert.AreEqual(chileProduct.Product.ProductCode, resultItem.ProdID.ToString());
                    Assert.AreEqual(LotNumberParser.BuildLotNumber(chileLot), resultItem.Lot);
                }
            }
コード例 #7
0
        private void SetTblSampleDetails(tblSample tblSample, SampleOrder sampleOrder, ref bool commitNewContext)
        {
            var existingDetails = tblSample.tblSampleDetails.ToDictionary(n => n.SampleDetailID);
            var sampleDetailId = OldContext.tblSampleDetails.Select(n => n.SampleDetailID).DefaultIfEmpty(DateTime.Now.RoundMillisecondsForSQL()).Max();
            var custSpecId = OldContext.tblSampleCustSpecs.Select(n => n.CustSpecID).DefaultIfEmpty(DateTime.Now.RoundMillisecondsForSQL()).Max();
            var rvcMatchId = OldContext.tblSampleRVCMatches.Select(n => n.RVCMatchID).DefaultIfEmpty(DateTime.Now.RoundMillisecondsForSQL()).Max();
            foreach(var item in sampleOrder.Items)
            {
                tblSampleDetail detail = null;
                if(item.SampleDetailID != null && existingDetails.TryGetValue(item.SampleDetailID.Value, out detail))
                {
                    existingDetails.Remove(detail.SampleDetailID);
                }

                if(detail == null)
                {
                    commitNewContext = true;
                    sampleDetailId = sampleDetailId.AddSeconds(1);
                    detail = new tblSampleDetail
                        {
                            SampleDetailID = sampleDetailId,
                            SampleID = tblSample.SampleID,
                            s_GUID = Guid.NewGuid()
                        };
                    OldContext.tblSampleDetails.AddObject(detail);
                    item.SampleDetailID = detail.SampleDetailID;
                }

                detail.ProdID = item.Product == null ? (int?) null : int.Parse(item.Product.ProductCode);
                detail.Lot = item.Lot == null ? (int?) null : LotNumberParser.BuildLotNumber(item.Lot);
                detail.Qty = item.Quantity;
                detail.Desc = item.Description;
                detail.SampleMatch = item.CustomerProductName;

                if(item.Spec == null)
                {
                    DeleteTblSampleCustSpecs(detail);
                }
                else
                {
                    var spec = detail.tblSampleCustSpecs.FirstOrDefault(s => s.CustSpecID == item.Spec.CustSpecID);
                    if(spec == null)
                    {
                        commitNewContext = true;
                        custSpecId = custSpecId.AddSeconds(1);
                        spec = new tblSampleCustSpec
                            {
                                CustSpecID = custSpecId,
                                SampleDetailID = detail.SampleDetailID
                            };
                        OldContext.tblSampleCustSpecs.AddObject(spec);
                        item.Spec.CustSpecID = spec.CustSpecID;
                    }

                    SetSpec(spec, item.Spec);
                }

                if(item.Match == null)
                {
                    DeleteTblSampleRVCMatches(detail);
                }
                else
                {
                    var match = detail.tblSampleRVCMatches.FirstOrDefault(s => s.RVCMatchID == item.Match.RVCMatchID);
                    if(match == null)
                    {
                        commitNewContext = true;
                        rvcMatchId = rvcMatchId.AddSeconds(1);
                        match = new tblSampleRVCMatch
                            {
                                RVCMatchID = rvcMatchId,
                                SampleDetailID = detail.SampleDetailID
                            };
                        OldContext.tblSampleRVCMatches.AddObject(match);
                        item.Match.RVCMatchID = match.RVCMatchID;
                    }

                    SetMatch(match, item.Match);
                }
            }

            foreach(var detail in existingDetails)
            {
                DeleteTblSampleDetail(detail.Value);
            }
        }
コード例 #8
0
        private bool ProcessSerializedPackSchedule(PackSchedule packSchedule, PackScheduleDTO oldPackSchedule, out bool isSerialized)
        {
            isSerialized = true;
            int?pkgID;

            if (!SerializablePackSchedule.DeserializeIntoPackSchedule(packSchedule, oldPackSchedule.Serialized, out pkgID))
            {
                isSerialized = false;
                return(false);
            }

            int?batchTypeId;

            if (oldPackSchedule.BatchLots != null && oldPackSchedule.BatchLots.Any())
            {
                batchTypeId = GetSingleBatchTypeID(oldPackSchedule);
                if (batchTypeId == null)
                {
                    Log(new CallbackParameters(CallbackReason.NoSingleBatchType)
                    {
                        PackSchedule = oldPackSchedule
                    });
                    return(false);
                }
            }
            else
            {
                batchTypeId = oldPackSchedule.BatchTypeID.Value;
            }
            packSchedule.WorkTypeId = WorkTypeFactory.BuildWorkTypeFromBatchTypeID(batchTypeId.Value).Id;

            var packagingProduct = _newContextHelper.GetPackagingProduct(pkgID);

            if (packagingProduct != null)
            {
                packSchedule.PackagingProductId = packagingProduct.Id;
            }
            else if (!SetDeterminedPackaging(packSchedule, oldPackSchedule))
            {
                return(false);
            }


            var productionBatches = packSchedule.ProductionBatches.ToList();

            productionBatches.RemoveAll(batch =>
            {
                var lotKey    = new LotKey(batch);
                var lotNumber = LotNumberParser.BuildLotNumber(lotKey);

                List <DateTime?> ids;
                if (_batchItemPackSchIds.TryGetValue(lotNumber, out ids))
                {
                    if (ids.Any())
                    {
                        if (ids.Any(i => i != oldPackSchedule.PackSchID))
                        {
                            Log(new CallbackParameters(CallbackReason.MismatchedBatchItemPackSchID)
                            {
                                PackSchedule = oldPackSchedule,
                                BatchNumber  = lotNumber
                            });
                        }
                        return(true);
                    }
                }

                _loadCount.AddRead(EntityTypes.ProductionBatch);
                _loadCount.AddRead(EntityTypes.Notebook);
                _loadCount.AddRead(EntityTypes.PickedInventory);
                _loadCount.AddRead(EntityTypes.ChileLot);
                _loadCount.AddRead(EntityTypes.Lot);

                if (!_newContextHelper.LotLoaded(lotKey))
                {
                    Log(new CallbackParameters(CallbackReason.BatchLotNotLoaded)
                    {
                        PackSchedule = oldPackSchedule,
                        LotKey       = lotKey
                    });
                    return(true);
                }

                var dateCreated = batch.LotDateCreated.Date;
                var sequence    = PickedInventoryKeyHelper.Singleton.GetNextSequence(dateCreated);

                batch.Production.PickedInventoryDateCreated = batch.Production.PickedInventory.DateCreated = dateCreated;
                batch.Production.PickedInventorySequence    = batch.Production.PickedInventory.Sequence = sequence;

                var notebook = _notebookFactory.BirthNext(batch.TimeStamp);
                batch.InstructionNotebook            = notebook;
                batch.InstructionNotebookDateCreated = notebook.Date;
                batch.InstructionNotebookSequence    = notebook.Sequence;

                var deserializedProduction = _serializedData.GetDeserialized <SerializableEmployeeIdentifiable>(SerializableType.ChileLotProduction, lotNumber.ToString());
                if (deserializedProduction != null)
                {
                    batch.Production.EmployeeId = deserializedProduction.EmployeeKey.EmployeeKeyId;
                    batch.Production.TimeStamp  = deserializedProduction.TimeStamp;
                }

                return(false);
            });
            packSchedule.ProductionBatches = productionBatches;

            return(true);
        }
コード例 #9
0
        private void SyncPickedItems(tblOrder tblOrder, SalesOrderItem orderItem, ref DateTime lastEntryDate, tblOrderDetail detail)
        {
            var stagedToDelete = detail.tblStagedFGs.ToDictionary(s => s.EntryDate);

            foreach (var picked in orderItem.PickedItems ?? new List <SalesOrderPickedItem>())
            {
                tblStagedFG staged;
                if (picked.PickedInventoryItem.DetailID != null && stagedToDelete.TryGetValue(picked.PickedInventoryItem.DetailID.Value, out staged))
                {
                    stagedToDelete.Remove(staged.EntryDate);
                }
                else
                {
                    lastEntryDate = lastEntryDate.AddSeconds(1);
                    staged        = new tblStagedFG
                    {
                        EntryDate = lastEntryDate,
                        s_GUID    = Guid.NewGuid()
                    };
                    detail.tblStagedFGs.Add(staged);
                    picked.PickedInventoryItem.DetailID = staged.EntryDate;
                    _commitNewContext = true;
                }

                var packaging = OldContextHelper.GetPackaging(picked.PickedInventoryItem.PackagingProduct);
                var treatment = OldContextHelper.GetTreatment(picked.PickedInventoryItem);

                staged.OrderNum        = tblOrder.OrderNum;
                staged.ODetail         = detail.ODetail;
                staged.Lot             = LotNumberParser.BuildLotNumber(picked.PickedInventoryItem);
                staged.TTypeID         = (int?)TransType.Batching; //To match logic found in Access (apnd_PickProdTemp) - RI 2016-3-15
                staged.PkgID           = packaging.PkgID;
                staged.Quantity        = picked.PickedInventoryItem.Quantity;
                staged.NetWgt          = packaging.NetWgt;
                staged.TtlWgt          = picked.PickedInventoryItem.Quantity * packaging.NetWgt;
                staged.LocID           = picked.PickedInventoryItem.CurrentLocation.LocID.Value;
                staged.TrtmtID         = treatment.TrtmtID;
                staged.EmployeeID      = picked.PickedInventoryItem.PickedInventory.EmployeeId;
                staged.CustProductCode = picked.PickedInventoryItem.CustomerProductCode;
                staged.CustLot         = picked.PickedInventoryItem.CustomerLotCode;

                staged.AstaCalc = null;
                var asta = picked.PickedInventoryItem.Lot.Attributes.FirstOrDefault(a => a.AttributeShortName == GlobalKeyHelpers.AstaAttributeNameKey.AttributeNameKey_ShortName);
                if (asta != null)
                {
                    var productionEnd = asta.AttributeDate;
                    if (picked.PickedInventoryItem.Lot.ChileLot != null && picked.PickedInventoryItem.Lot.ChileLot.Production != null && picked.PickedInventoryItem.Lot.ChileLot.Production.Results != null)
                    {
                        productionEnd = picked.PickedInventoryItem.Lot.ChileLot.Production.Results.ProductionEnd;
                    }
                    staged.AstaCalc = AstaCalculator.CalculateAsta(asta.AttributeValue, asta.AttributeDate, productionEnd, DateTime.UtcNow);
                }

                staged.LoBac = false;
                if (picked.PickedInventoryItem.Lot.ChileLot != null)
                {
                    staged.LoBac = picked.PickedInventoryItem.Lot.ChileLot.AllAttributesAreLoBac;
                }
            }

            foreach (var staged in stagedToDelete.Values)
            {
                OldContext.tblStagedFGs.DeleteObject(staged);
            }
        }
コード例 #10
0
        private void SetSchedule(tblProductionSchedule oldProductionSchedule, ProductionSchedule productionSchedule, int lineNumber)
        {
            if (oldProductionSchedule == null)
            {
                OldContext.tblProductionSchedules.AddObject(oldProductionSchedule = new tblProductionSchedule
                {
                    ProductionDate = productionSchedule.ProductionDate,
                    LineNumber     = lineNumber,
                    tblProductionScheduleGroups = new EntityCollection <tblProductionScheduleGroup>()
                });
            }

            oldProductionSchedule.DateCreated = productionSchedule.TimeStamp.ConvertUTCToLocal();
            oldProductionSchedule.CreatedBy   = productionSchedule.EmployeeId;

            var oldGroups = oldProductionSchedule.tblProductionScheduleGroups.ToDictionary(g => g.PSNum);

            foreach (var item in productionSchedule.ScheduledItems)
            {
                tblProductionScheduleGroup oldGroup;
                if (oldGroups.TryGetValue(item.PackSchedule.PSNum.Value, out oldGroup))
                {
                    oldGroups.Remove(item.PackSchedule.PSNum.Value);
                }
                else
                {
                    OldContext.tblProductionScheduleGroups.AddObject(oldGroup = new tblProductionScheduleGroup
                    {
                        ProductionDate             = oldProductionSchedule.ProductionDate,
                        LineNumber                 = oldProductionSchedule.LineNumber,
                        PSNum                      = item.PackSchedule.PSNum.Value,
                        tblProductionScheduleItems = new EntityCollection <tblProductionScheduleItem>()
                    });
                }

                oldGroup.Index                   = item.Index;
                oldGroup.Instructions            = item.PackSchedule.SummaryOfWork;
                oldGroup.FlushBefore             = item.FlushBefore;
                oldGroup.FlushBeforeInstructions = item.FlushBeforeInstructions;
                oldGroup.FlushAfter              = item.FlushAfter;
                oldGroup.FlushAfterInstructions  = item.FlushAfterInstructions;

                var oldItems = oldGroup.tblProductionScheduleItems.ToDictionary(i => i.LotNumber);
                foreach (var batch in item.PackSchedule.ProductionBatches
                         .Where(b => !b.ProductionHasBeenCompleted)
                         .OrderBy(b => b.LotTypeId)
                         .ThenBy(b => b.LotDateCreated)
                         .ThenBy(b => b.LotDateSequence))
                {
                    var lotNumber = LotNumberParser.BuildLotNumber(batch);

                    tblProductionScheduleItem oldItem;
                    if (oldItems.TryGetValue(lotNumber, out oldItem))
                    {
                        oldItems.Remove(lotNumber);
                    }
                    else
                    {
                        OldContext.tblProductionScheduleItems.AddObject(oldItem = new tblProductionScheduleItem
                        {
                            ProductionDate = oldGroup.ProductionDate,
                            LineNumber     = oldGroup.LineNumber,
                            PSNum          = oldGroup.PSNum,
                            LotNumber      = lotNumber
                        });
                    }
                    oldItem.BatchNumber = batch.LotDateSequence;
                }

                foreach (var oldItem in oldItems.Values)
                {
                    OldContext.tblProductionScheduleItems.DeleteObject(oldItem);
                }
            }

            foreach (var oldGroup in oldGroups.Values)
            {
                foreach (var oldItem in oldGroup.tblProductionScheduleItems)
                {
                    OldContext.tblProductionScheduleItems.DeleteObject(oldItem);
                }
                OldContext.tblProductionScheduleGroups.DeleteObject(oldGroup);
            }
        }