Beispiel #1
0
        public override void Synchronize(Func <SyncSalesOrderParameters> getInput)
        {
            lock (_lock)
            {
                if (getInput == null)
                {
                    throw new ArgumentNullException("getInput");
                }

                var parameters = getInput();
                var key        = parameters.SalesOrderKey;
                var salesOrder = GetSalesOrder(key);
                if (salesOrder == null)
                {
                    throw new Exception(string.Format("Could not find SalesOrder with key[{0}].", key));
                }

                _commitNewContext = false;
                var oldOrder = GetOldOrder(salesOrder, parameters.New);
                oldOrder.SetSalesOrder(salesOrder);
                SyncOrderItems(salesOrder, oldOrder);

                if (_commitNewContext)
                {
                    UnitOfWork.Commit();
                }
                OldContext.SaveChanges();

                Console.WriteLine(ConsoleOutput.SyncTblOrder, salesOrder.InventoryShipmentOrder.MoveNum);
            }
        }
Beispiel #2
0
        public override void Synchronize(Func <InventoryAdjustmentKey> getInput)
        {
            if (getInput == null)
            {
                throw new ArgumentNullException("getInput");
            }
            var key = getInput();
            var inventoryAdjustment = UnitOfWork.InventoryAdjustmentRepository.FindByKey(key,
                                                                                         a => a.Notebook.Notes,
                                                                                         a => a.Items.Select(i => i.PackagingProduct.Product),
                                                                                         a => a.Items.Select(i => i.Location),
                                                                                         a => a.Items.Select(i => i.Treatment),
                                                                                         a => a.Items.Select(i => i.Lot.PackagingLot.PackagingProduct.Product));

            var adjustId      = inventoryAdjustment.TimeStamp.ConvertUTCToLocal().RoundMillisecondsForSQL();
            var newAdjustment = new tblAdjust
            {
                AdjustID   = adjustId,
                EmployeeID = inventoryAdjustment.EmployeeId,
                Reason     = inventoryAdjustment.Notebook.Notes.Select(n => n.Text).FirstOrDefault()
            };

            AddOutgoingRecords(newAdjustment, inventoryAdjustment.Items);

            OldContext.tblAdjusts.AddObject(newAdjustment);
            OldContext.SaveChanges();
            Console.WriteLine(ConsoleOutput.AddedAdjust, newAdjustment.AdjustID.ToString(DateTimeExtensions.SQLDateTimeFormat));
        }
Beispiel #3
0
        public override void Synchronize(Func <ProductionScheduleKey> getInput)
        {
            var productionScheduleKey = getInput();

            var productionSchedule = UnitOfWork.ProductionScheduleRepository.FindByKey(productionScheduleKey,
                                                                                       p => p.ScheduledItems.Select(i => i.PackSchedule.ProductionBatches));

            var    location = UnitOfWork.LocationRepository.FindByKey(productionScheduleKey.ToLocationKey());
            string street;
            int    row;

            LocationDescriptionHelper.GetStreetRow(location.Description, out street, out row);

            var oldProductionSchedule = OldContext.tblProductionSchedules
                                        .Include(p => p.tblProductionScheduleGroups.Select(g => g.tblProductionScheduleItems))
                                        .FirstOrDefault(p => p.ProductionDate == productionScheduleKey.ProductionScheduleKey_ProductionDate && (int)p.LineNumber == row);

            if (productionSchedule == null)
            {
                if (oldProductionSchedule != null)
                {
                    DeleteSchedule(oldProductionSchedule);
                }
            }
            else
            {
                SetSchedule(oldProductionSchedule, productionSchedule, row);
            }

            OldContext.SaveChanges();

            Console.WriteLine(ConsoleOutput.SyncProductionSchedule, productionScheduleKey.ProductionScheduleKey_ProductionDate.ToString("yyyyMMdd"), row);
        }
        public override void Synchronize(Func <int?> getInput)
        {
            if (getInput == null)
            {
                throw new ArgumentNullException("getInput");
            }

            var orderNum = getInput();
            var order    = OldContext.tblOrders
                           .Include(o => o.tblOrderDetails.Select(d => d.tblStagedFGs))
                           .FirstOrDefault(o => o.OrderNum == orderNum);

            if (order == null)
            {
                throw new Exception(string.Format("Could not find customer order with key[{0}].", orderNum));
            }

            foreach (var detail in order.tblOrderDetails.ToList())
            {
                foreach (var staged in detail.tblStagedFGs.ToList())
                {
                    OldContext.tblStagedFGs.DeleteObject(staged);
                }

                OldContext.tblOrderDetails.DeleteObject(detail);
            }

            OldContext.tblOrders.DeleteObject(order);

            OldContext.SaveChanges();

            Console.WriteLine(ConsoleOutput.RemovedTblOrder, orderNum);
        }
Beispiel #5
0
        public override void Synchronize(Func <NotebookKey> getInput)
        {
            if (getInput == null)
            {
                throw new ArgumentNullException("getInput");
            }

            var notebookKey = getInput();
            var notebook    = UnitOfWork.NotebookRepository.FindByKey(notebookKey, n => n.Notes);

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

            var productionBatch = UnitOfWork.ProductionBatchRepository.Filter(b => b.InstructionNotebookDateCreated == notebook.Date && b.InstructionNotebookSequence == notebook.Sequence).FirstOrDefault();

            if (productionBatch != null)
            {
                var lotNumber = LotNumberBuilder.BuildLotNumber(productionBatch);
                new SyncTblBatchInstr(OldContext).Synchronize(notebook, lotNumber);
                OldContext.SaveChanges();

                Console.WriteLine(ConsoleOutput.UpdatedBatchInstructions, lotNumber);
                return;
            }

            var contract = UnitOfWork.ContractRepository.GetContractForSynch(notebookKey);

            if (contract != null)
            {
                new SyncContract(UnitOfWork).Synchronize(contract, false);
            }
        }
Beispiel #6
0
        public sealed override void Synchronize(Func <LotKey> getInput)
        {
            if (getInput == null)
            {
                throw new ArgumentNullException("getInput");
            }
            var key        = getInput();
            var production = UnitOfWork.ChileLotProductionRepository.FindByKey(key,
                                                                               m => m.ResultingChileLot.ChileProduct.Product,
                                                                               m => m.Results.ProductionLineLocation,
                                                                               m => m.Results.ResultItems.Select(i => i.PackagingProduct.Product),
                                                                               m => m.Results.ResultItems.Select(i => i.Location),
                                                                               m => m.PickedInventory.Items.Select(i => i.PackagingProduct.Product),
                                                                               m => m.PickedInventory.Items.Select(i => i.FromLocation),
                                                                               m => m.PickedInventory.Items.Select(i => i.Treatment));

            bool newLot;
            var  tblLot = GetOrCreateLot(production, out newLot);

            SetIncomingRecords(tblLot, production.Results.ResultItems);
            SetOutgoingRecords(tblLot, production);

            OldContext.SaveChanges();
            Console.Write(newLot ? ConsoleOutput.AddedLot : ConsoleOutput.UpdatedLot, tblLot.Lot);
        }
Beispiel #7
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());
        }
        public override void Synchronize(Func <IntraWarehouseOrderKey> getInput)
        {
            if (getInput == null)
            {
                throw new ArgumentNullException("getInput");
            }

            var orderKey = getInput();
            var order    = UnitOfWork.IntraWarehouseOrderRepository.FindByKey(orderKey,
                                                                              o => o.PickedInventory.Items.Select(i => i.PackagingProduct.Product),
                                                                              o => o.PickedInventory.Items.Select(i => i.FromLocation),
                                                                              o => o.PickedInventory.Items.Select(i => i.CurrentLocation));

            if (order == null)
            {
                throw new Exception(string.Format("IntraWarehouseOrder[{0}] not found in new context.", orderKey));
            }

            bool createdNew;
            var  oldOrder = Synchronize(order, out createdNew);

            if (createdNew)
            {
                UnitOfWork.Commit();
            }
            OldContext.SaveChanges();

            Console.Write(ConsoleOutput.SynchronizedIntraWarehouserMovement, oldOrder.RinconID.ToString(DateTimeFormat));
        }
        public override void Synchronize(Func <SynchronizeCustomerProductSpecs> getInput)
        {
            if (getInput == null)
            {
                throw new ArgumentNullException("getInput");
            }

            var    parameters = getInput();
            int    prodID;
            string company_IA;

            if (parameters.Delete != null)
            {
                Delete(parameters.Delete, out prodID, out company_IA);
            }
            else if (parameters.ChileProductKey != null && parameters.CustomerKey != null)
            {
                Serialize(parameters.ChileProductKey, parameters.CustomerKey, out prodID, out company_IA);
            }
            else
            {
                return;
            }

            OldContext.SaveChanges();

            Console.WriteLine(ConsoleOutput.UpdatedCustomerSpecs, company_IA, prodID);
        }
Beispiel #10
0
        public override void Synchronize(Func <List <Contract> > getInput)
        {
            if (getInput == null)
            {
                throw new ArgumentNullException("getInput");
            }

            var contracts = getInput();

            if (contracts.Any())
            {
                foreach (var contract in contracts)
                {
                    var oldContract = OldContext.tblContracts.FirstOrDefault(c => c.ContractID == contract.ContractId);
                    if (oldContract == null)
                    {
                        throw new Exception(string.Format("Could not find tblContract[{0}] referenced by Contract[{1}]", contract.ContractId, new ContractKey(contract)));
                    }
                    oldContract.KStatus = ContractStatus.Completed.ToString();
                }

                OldContext.SaveChanges();

                Console.WriteLine(ConsoleOutput.CompletedExpiredContracts, contracts.Count);
            }
            else
            {
                Console.WriteLine(ConsoleOutput.NoExpiredContracts);
            }
        }
Beispiel #11
0
        public override void Synchronize(Func <SalesOrderKey> getInput)
        {
            if (getInput == null)
            {
                throw new ArgumentNullException("getInput");
            }

            var orderKey = getInput();
            var order    = UnitOfWork.SalesOrderRepository.FindByKey(orderKey, o => o.InventoryShipmentOrder);
            var tblOrder = OldContext.tblOrders
                           .FirstOrDefault(o => o.OrderNum == order.InventoryShipmentOrder.MoveNum);

            if (tblOrder == null)
            {
                throw new Exception(string.Format("Could not find tblOrder[{0}]", order.InventoryShipmentOrder.MoveNum));
            }

            tblOrder.Status       = (int?)tblOrderStatus.Invoiced;
            tblOrder.InvoiceDate  = order.InvoiceDate;
            tblOrder.InvoiceNotes = order.InvoiceNotes;

            OldContext.SaveChanges();

            Console.WriteLine(ConsoleOutput.InvoicedOrder, tblOrder.OrderNum);
        }
        public override void Synchronize(Func <LotKey> getInput)
        {
            if (getInput == null)
            {
                throw new ArgumentNullException("getInput");
            }
            var lotKey = getInput();

            var oldLot    = new SyncLotHelper(OldContext, UnitOfWork, OldContextHelper).SynchronizeOldLot(lotKey, false, false);
            var inventory = UnitOfWork.InventoryRepository
                            .Filter(i => i.LotDateCreated == lotKey.LotKey_DateCreated && i.LotDateSequence == lotKey.LotKey_DateSequence && i.LotTypeId == lotKey.LotKey_LotTypeId,
                                    i => i.PackagingProduct.Product,
                                    i => i.Location,
                                    i => i.Treatment)
                            .ToList();

            foreach (var item in inventory)
            {
                OldContext.tblIncomings.AddObject(CreateIncoming(oldLot, item));
            }

            OldContext.SaveChanges();

            Console.Write(ConsoleOutput.ReceivedInventory, oldLot.Lot);
        }
        public override void Synchronize(Func<SyncSampleOrderParameters> getInput)
        {
            if(getInput == null) { throw new ArgumentNullException("getInput"); }

            var parameters = getInput();

            lock(Lock)
            {
                string message;
                var commitNewContext = false;
                if(parameters.DeleteSampleID != null)
                {
                    DeleteSampleOrder(parameters.DeleteSampleID.Value);
                    message = string.Format(ConsoleOutput.DeletedTblSample, parameters.DeleteSampleID);
                }
                else if(parameters.SampleOrderKey != null)
                {
                    var tblSample = Sync(parameters.SampleOrderKey, out commitNewContext);
                    message = string.Format(ConsoleOutput.SynchedTblSample, tblSample.SampleID);
                }
                else
                {
                    return;
                }

                OldContext.SaveChanges();
                if(commitNewContext)
                {
                    UnitOfWork.Commit();
                }

                Console.WriteLine(message);
            }
        }
Beispiel #14
0
        public override void Synchronize(Func <int?> getInput)
        {
            if (getInput == null)
            {
                throw new ArgumentNullException("getInput");
            }

            var contractId = getInput();

            if (contractId == null)
            {
                return;
            }

            var contract = OldContext.tblContracts.Include("tblContractDetails").FirstOrDefault(c => c.ContractID == contractId.Value);

            foreach (var detail in contract.tblContractDetails.ToList())
            {
                OldContext.tblContractDetails.DeleteObject(detail);
            }
            OldContext.tblContracts.DeleteObject(contract);
            OldContext.SaveChanges();

            Console.Write(ConsoleOutput.RemovedContract, contractId);
        }
Beispiel #15
0
        public override void Synchronize(Func <LotKey> getInput)
        {
            var lotNumber = LotNumberBuilder.BuildLotNumber(getInput());

            new DeleteTblLotHelper(OldContext).DeleteLots(lotNumber);
            OldContext.SaveChanges();
            Console.WriteLine(ConsoleOutput.DeletedTblLot, lotNumber);
        }
        public override void Synchronize(Func <TreatmentOrderKey> getInput)
        {
            if (getInput == null)
            {
                throw new ArgumentNullException("getInput");
            }
            var treatmentOrderKey = getInput();

            var treatmentOrder = UnitOfWork.TreatmentOrderRepository.FindByKey(treatmentOrderKey, o => o.InventoryShipmentOrder.PickedInventory.Items.Select(i => i.CurrentLocation));

            if (treatmentOrder == null)
            {
                throw new Exception(string.Format("Could not find TreatmentOrder[{0}].", treatmentOrderKey));
            }

            var oldOrder = OldContext.tblMoves.Where(m => m.MoveNum == treatmentOrder.InventoryShipmentOrder.MoveNum)
                           .Select(m => new
            {
                tblMove = m,
                details = m.tblMoveDetails.Select(d => d.tblPackaging)
            }).FirstOrDefault();

            if (oldOrder == null)
            {
                throw new Exception(string.Format("Could not find tblMove[{0}].", treatmentOrder.InventoryShipmentOrder.MoveNum));
            }

            var oldTreatment = OldContextHelper.GetTreatment(treatmentOrder);
            var firstItem    = treatmentOrder.InventoryShipmentOrder.PickedInventory.Items.FirstOrDefault();

            if (firstItem == null)
            {
                throw new Exception("No PickedInventoryItems in TreatmentOrder.");
            }

            foreach (var oldDetail in oldOrder.tblMove.tblMoveDetails)
            {
                OldContext.tblOutgoings.AddObject(CreateOutgoing(treatmentOrder, oldDetail));

                oldDetail.TrtmtID = oldTreatment.TrtmtID;
                oldDetail.LocID   = firstItem.CurrentLocation.LocID.Value;
                OldContext.tblOutgoings.AddObject(CreateOutgoing(treatmentOrder, oldDetail, -1));
            }

            oldOrder.tblMove.Returned = treatmentOrder.Returned.ConvertUTCToLocal();
            oldOrder.tblMove.Status   = (int?)tblOrderStatus.Treated;

            OldContext.SaveChanges();

            Console.Write(ConsoleOutput.ReceivedTreatmentOrder, oldOrder.tblMove.MoveNum);
        }
        public override void Synchronize(Func <LotKey> getInput)
        {
            if (getInput == null)
            {
                throw new ArgumentNullException("getInput");
            }
            var productionBatchKey = getInput();

            var productionBatch = UnitOfWork.ProductionBatchRepository.FindByKey(productionBatchKey,
                                                                                 b => b.Production.Results,
                                                                                 b => b.Production.ResultingChileLot.Lot,
                                                                                 b => b.PackSchedule.PackagingProduct.Product,
                                                                                 b => b.PackSchedule.ChileProduct.Product,
                                                                                 b => b.PackSchedule.ProductionLineLocation,
                                                                                 b => b.PackSchedule.ProductionBatches.Select(p => p.Production.PickedInventory));

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

            var lotNumber = LotNumberBuilder.BuildLotNumber(productionBatch);
            var lot       = OldContext.tblLots.FirstOrDefault(l => l.Lot == lotNumber);

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

            var oldPackSchedule = OldContext.tblPackSches.FirstOrDefault(p => p.PackSchID == productionBatch.PackSchedule.PackSchID);

            if (oldPackSchedule == null)
            {
                throw new Exception(string.Format("tblPackSch[{0}] could not be found.", productionBatch.PackSchedule.PackSchID));
            }
            oldPackSchedule.Serialized = SerializablePackSchedule.Serialize(productionBatch.PackSchedule);

            var serialized = new SerializedData(OldContext);

            serialized[SerializableType.ChileLotProduction, lotNumber] = new SerializableEmployeeIdentifiable(productionBatch.Production);
            if (productionBatch.Production.Results != null)
            {
                serialized[SerializableType.LotProductionResults, lotNumber] = new SerializableEmployeeIdentifiable(productionBatch.Production.Results);
            }

            OldContext.SaveChanges();

            Console.Write(ConsoleOutput.UpdatedLot, lot.Lot);
        }
        public override void Synchronize(Func <List <int?> > getInput)
        {
            var contactIds = getInput().Where(c => c != null).Distinct().ToList();

            foreach (var contact in contactIds)
            {
                var oldContact = OldContext.Contacts.FirstOrDefault(c => c.ID == contact.Value);
                if (oldContact != null)
                {
                    OldContext.Contacts.DeleteObject(oldContact);
                }
            }

            OldContext.SaveChanges();

            contactIds.ForEach(i => Console.WriteLine(ConsoleOutput.DeletedContact, i));
        }
Beispiel #19
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);
        }
Beispiel #20
0
        public override void Synchronize(Func <DateTime?> getInput)
        {
            var tblProfileKey = getInput();

            if (tblProfileKey != null)
            {
                var tblProfile = OldContext.tblProfiles.FirstOrDefault(t => t.EntryDate == tblProfileKey);
                if (tblProfile != null)
                {
                    OldContext.tblProfiles.DeleteObject(tblProfile);
                }

                OldContext.SaveChanges();

                Console.WriteLine(ConsoleOutput.DeletedTblProfile, tblProfileKey);
            }
        }
Beispiel #21
0
        public override void Synchronize(Func <SyncLocationsParameters> getInput)
        {
            var parameters = getInput();
            var keys       = parameters.Locations.Select(k => new LocationKey(k)).ToList();

            if (keys.Any())
            {
                bool newContext;
                var  oldLocations = SynchronizeLocations(parameters.EmployeeKey, keys, out newContext);
                if (newContext)
                {
                    UnitOfWork.Commit();
                }
                OldContext.SaveChanges();

                Console.Write(ConsoleOutput.SyncLocation, oldLocations[0].LocID);
            }
        }
Beispiel #22
0
        public void Synchronize(Contract contract, bool createNew)
        {
            if (contract == null)
            {
                throw new ArgumentNullException("contract");
            }
            _commitNewContext = false;

            var oldContract = GetOrCreateContract(contract, createNew);

            SynchronizeOldContract(contract, oldContract);
            if (_commitNewContext)
            {
                UnitOfWork.Commit();
            }

            OldContext.SaveChanges();

            Console.Write(ConsoleOutput.SynchronizedContract, oldContract.ContractID);
        }
Beispiel #23
0
        public sealed override void Synchronize(Func <LotKey> getInput)
        {
            if (getInput == null)
            {
                throw new ArgumentNullException("getInput");
            }

            var key      = getInput();
            var received = UnitOfWork.ChileMaterialsReceivedRepository.FindByKey(key,
                                                                                 r => r.ChileLot.Lot,
                                                                                 r => r.ChileProduct.Product,
                                                                                 r => r.Items.Select(i => i.PackagingProduct.Product),
                                                                                 r => r.Items.Select(i => i.Location));

            var oldLot = SyncDehydratedReceived(received);

            OldContext.SaveChanges();

            Console.WriteLine(ConsoleOutput.SyncDehydratedReceived, oldLot.Lot);
        }
Beispiel #24
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);
        }
        public override void Synchronize(Func <SyncCreatePackScheduleParameters> getInput)
        {
            if (getInput == null)
            {
                throw new ArgumentNullException("getInput");
            }
            var parameters      = getInput();
            var packScheduleKey = parameters.PackScheduleKey;

            var newPackSchedule = UnitOfWork.PackScheduleRepository.SelectPackScheduleForSynch(packScheduleKey);
            var oldPackSchedule = CreateNewPackSchedule(newPackSchedule, parameters.UseSuppliedPSNum);

            OldContext.tblPackSches.AddObject(oldPackSchedule);
            OldContext.SaveChanges();

            newPackSchedule.PackSchID = oldPackSchedule.PackSchID;
            newPackSchedule.PSNum     = oldPackSchedule.PSNum;
            UnitOfWork.Commit();

            Console.Write(ConsoleOutput.AddedPackSchedule, oldPackSchedule.PackSchID.ToPackSchIdString());
        }
Beispiel #26
0
        public override void Synchronize(Func <InventoryShipmentOrderKey> getInput)
        {
            if (getInput == null)
            {
                throw new ArgumentNullException("getInput");
            }

            var key   = getInput();
            var order = UnitOfWork.InventoryShipmentOrderRepository.FindByKey(key,
                                                                              o => o.PickedInventory.Items.Select(i => i.PackagingProduct.Product),
                                                                              o => o.PickedInventory.Items.Select(i => i.FromLocation),
                                                                              o => o.PickedInventory.Items.Select(i => i.CurrentLocation));

            if (order == null)
            {
                throw new Exception(string.Format("Could not find InventoryShipmentOrder[{0}].", key));
            }

            if (order.MoveNum == null)
            {
                throw new Exception(string.Format("InventoryShipmentOrder[{0}].MoveNum is null.", key));
            }

            switch (order.OrderType)
            {
            case InventoryShipmentOrderTypeEnum.InterWarehouseOrder:
            case InventoryShipmentOrderTypeEnum.TreatmentOrder:
                SyncMove(order);
                break;

            case InventoryShipmentOrderTypeEnum.SalesOrder:
            case InventoryShipmentOrderTypeEnum.MiscellaneousOrder:
                SyncOrder(order);
                break;
            }

            OldContext.SaveChanges();

            Console.WriteLine(ConsoleOutput.PostedOrder, order.MoveNum);
        }
        public override void Synchronize(Func <InventoryShipmentOrderKey> getInput)
        {
            if (getInput == null)
            {
                throw new ArgumentNullException("getInput");
            }

            var newOrderKey = getInput();
            var newOrder    = UnitOfWork.InventoryShipmentOrderRepository
                              .FindByKey(newOrderKey, o => o.ShipmentInformation);

            if (newOrder == null)
            {
                throw new Exception(string.Format("Could not find InventoryShipmentOrder[{0}].", newOrderKey));
            }

            if (newOrder.MoveNum == null)
            {
                throw new Exception(string.Format("InventoryShipmentOrder[{0}].MoveNum is null.", newOrderKey));
            }

            switch (newOrder.OrderType)
            {
            case InventoryShipmentOrderTypeEnum.InterWarehouseOrder:
            case InventoryShipmentOrderTypeEnum.TreatmentOrder:
                SetMoveShipment(newOrder);
                OldContext.SaveChanges();
                Console.WriteLine(ConsoleOutput.SetShipmentTblMove, newOrder.MoveNum);
                break;

            case InventoryShipmentOrderTypeEnum.SalesOrder:
            case InventoryShipmentOrderTypeEnum.MiscellaneousOrder:
                SetOrderShipment(newOrder);
                OldContext.SaveChanges();
                Console.WriteLine(ConsoleOutput.SetShipmentTblOrder, newOrder.MoveNum);
                break;

            default: throw new ArgumentOutOfRangeException("order.OrderType");
            }
        }
Beispiel #28
0
        public override void Synchronize(Func <SyncProductParameters> getInput)
        {
            if (getInput == null)
            {
                throw new ArgumentNullException("getInput");
            }

            var parameters = getInput();
            var product    = UnitOfWork.ProductRepository.FindByKey(parameters.ProductKey);
            int?id         = null;
            var message    = "";

            switch (product.ProductType)
            {
            case ProductTypeEnum.Additive:
                id      = SyncAdditiveProduct(product).ProdID;
                message = ConsoleOutput.SynchedTblProduct;
                break;

            case ProductTypeEnum.Chile:
                id      = SyncChileProduct(product, parameters.DeletedIngredients).ProdID;
                message = ConsoleOutput.SynchedTblProduct;
                break;

            case ProductTypeEnum.Packaging:
                id      = SyncPackagingProduct(product).PkgID;
                message = ConsoleOutput.SynchedTblPackaging;
                break;

            case ProductTypeEnum.NonInventory:
                id      = SyncNonInventoryProduct(product).ProdID;
                message = ConsoleOutput.SynchedTblProduct;
                break;
            }

            OldContext.SaveChanges();

            Console.WriteLine(message, id);
        }
Beispiel #29
0
        public override void Synchronize(Func <SyncInventoryShipmentOrderParameters> getInput)
        {
            if (getInput == null)
            {
                throw new ArgumentNullException("getInput");
            }

            var parameters = getInput();
            var key        = parameters.InventoryShipmentOrderKey;

            bool commitNewContext;
            var  tblMove = Synchronize(key, parameters.New, out commitNewContext);

            if (commitNewContext)
            {
                UnitOfWork.Commit();
            }

            OldContext.SaveChanges();

            Console.Write(ConsoleOutput.SyncTblMove, tblMove.MoveNum);
        }
Beispiel #30
0
        public override void Synchronize(Func <DateTime?> getInput)
        {
            if (getInput == null)
            {
                throw new ArgumentNullException("getInput");
            }
            var input = getInput();

            if (input == null)
            {
                throw new Exception("PackSchId from method return is null.");
            }
            var packSchId = input.Value;

            var packSch = OldContext.tblPackSches
                          .Select(p => new
            {
                packSchedule = p,
                lots         = p.tblLots.Select(l => l.Lot).Concat(p.tblBatchItems.Where(i => i.BatchLot != null || i.NewLot != null).Select(i => (i.BatchLot ?? i.NewLot).Value)).Distinct(),
            })
                          .FirstOrDefault(p => p.packSchedule.PackSchID == packSchId);

            if (packSch == null)
            {
                throw new Exception(string.Format("Could not find tblPackSches[{0}]", packSchId));
            }

            foreach (var scheduledItem in OldContext.tblProductionScheduleItems.Where(i => i.PSNum == packSch.packSchedule.PSNum).ToList())
            {
                OldContext.tblProductionScheduleItems.DeleteObject(scheduledItem);
            }

            new DeleteTblLotHelper(OldContext).DeleteLots(packSch.lots.ToArray());
            OldContext.tblPackSches.DeleteObject(packSch.packSchedule);
            OldContext.SaveChanges();

            Console.WriteLine(ConsoleOutput.RemovedPackSchedule, packSchId.ToPackSchIdString());
        }