Пример #1
0
        public override void Synchronize(Func <PackScheduleKey> getInput)
        {
            if (getInput == null)
            {
                throw new ArgumentNullException("getInput");
            }
            var packScheduleKey = getInput();

            var newPackSchedule = UnitOfWork.PackScheduleRepository.SelectPackScheduleForSynch(packScheduleKey);
            var oldPackSchedule = OldContext.tblPackSches.Select(p => new
            {
                packSchedule = p,
                lots         = p.tblLots
            }).FirstOrDefault(p => p.packSchedule.PackSchID == newPackSchedule.PackSchID);

            if (oldPackSchedule == null)
            {
                throw new Exception(string.Format("Could not find tblPackSch[{0}] record.", newPackSchedule.PackSchID));
            }
            SynchronizePackScheduleHelper.SynchronizeOldContextPackSchedule(oldPackSchedule.packSchedule, newPackSchedule);

            OldContext.SaveChanges();

            Console.Write(ConsoleOutput.UpdatedPackSchedule, oldPackSchedule.packSchedule.PackSchID.ToPackSchIdString());
        }
        private tblPackSch CreateNewPackSchedule(PackSchedule packSchedule, bool useSuppliedPSNum)
        {
            var packSchId  = packSchedule.TimeStamp.ConvertLocalToUTC().RoundMillisecondsForSQL();
            var tblPackSch = new tblPackSch
            {
                SerializedKey = packSchedule.ToPackScheduleKey(),
                PackSchID     = packSchId,
                PSNum         = useSuppliedPSNum && packSchedule.PSNum != null ? packSchedule.PSNum.Value :
                                OldContext.tblPackSches.Select(p => p.PSNum).Where(p => p != null).DefaultIfEmpty(0).Max().Value + 1,
                PSStatus   = 1,
                SetTrtmtID = 0
            };

            SynchronizePackScheduleHelper.SynchronizeOldContextPackSchedule(tblPackSch, packSchedule);
            return(tblPackSch);
        }
Пример #3
0
        public override void Synchronize(Func <LotKey> getInput)
        {
            if (getInput == null)
            {
                throw new ArgumentNullException("getInput");
            }
            var lotNumber = LotNumberBuilder.BuildLotNumber(getInput());

            var tblLot = OldContext.tblLots
                         .Include
                         (
                l => l.inputBatchItems,
                l => l.tblBatchInstr,
                l => l.tblBOMs,
                l => l.tblLotAttributeHistory,
                l => l.tblIncomings,
                l => l.tblOutgoingInputs,
                l => l.tblPackSch
                         )
                         .FirstOrDefault(l => l.Lot == lotNumber);

            if (tblLot == null)
            {
                throw new Exception(string.Format("tblLot[{0}] not found.", lotNumber));
            }

            if (tblLot.tblPackSch == null)
            {
                throw new Exception(string.Format("tblPackSch record for tblLot[{0}] not found.", lotNumber));
            }

            var newPackSchedule = UnitOfWork.PackScheduleRepository.SelectPackScheduleForSynch(new PackSchIdKey(tblLot.tblPackSch.PackSchID));

            SynchronizePackScheduleHelper.SynchronizeOldContextPackSchedule(tblLot.tblPackSch, newPackSchedule);

            new DeleteTblLotHelper(OldContext).DeleteLot(tblLot);

            OldContext.SaveChanges();

            Console.WriteLine(ConsoleOutput.RemovedProductionBatch, lotNumber);
        }