Ejemplo n.º 1
0
        public string GetGraphizString(CustomerOrderPart customerOrderPart)
        {
            // Demand(CustomerOrder);20;Truck
            string graphizString = $"D: CustomerOrderPart;{ToGraphizString(customerOrderPart)}";

            return(graphizString);
        }
Ejemplo n.º 2
0
        public static void CreateConfirmations(SimulationInterval simulationInterval)
        {
            /*ISimulator simulator = new Simulator();
             * simulator.ProcessCurrentInterval(simulationInterval, _orderGenerator);*/
            // --> (Martin's impl) does not work correctly, use trivial impl instead TODO: Just an info for you Martin

            IDbTransactionData dbTransactionData =
                ZppConfiguration.CacheManager.GetDbTransactionData();
            IAggregator aggregator = ZppConfiguration.CacheManager.GetAggregator();


            // customerOrderParts: set finished if all childs are finished
            DemandToProviderGraph demandToProviderGraph = new DemandToProviderGraph();
            INodes rootNodes = demandToProviderGraph.GetRootNodes();

            foreach (var rootNode in rootNodes)
            {
                if (rootNode.GetEntity().GetType() == typeof(CustomerOrderPart))
                {
                    CustomerOrderPart customerOrderPart = (CustomerOrderPart)rootNode.GetEntity();
                    customerOrderPart.SetReadOnly();

                    bool allChildsAreFinished = true;
                    foreach (var stockExchangeProvider in aggregator.GetAllChildProvidersOf(
                                 customerOrderPart))
                    {
                        if (stockExchangeProvider.IsFinished() == false)
                        {
                            allChildsAreFinished = false;
                            break;
                        }
                    }

                    if (allChildsAreFinished)
                    {
                        customerOrderPart.SetFinished();
                    }
                }
            }

            // no confirmations: some nodes has no state (PrO) or must be adapted differently (COPs)
            // confirmations only for: stockExchanges, purchaseOrderParts, operations
            Type[] typesToAdapt = new Type[]
            {
                typeof(StockExchangeDemand), typeof(StockExchangeProvider),
                typeof(PurchaseOrderPart), typeof(ProductionOrderOperation)
            };

            // operations
            AdaptState(dbTransactionData.ProductionOrderOperationGetAll(), simulationInterval,
                       typesToAdapt);

            // demands
            AdaptState(dbTransactionData.DemandsGetAll(), simulationInterval, typesToAdapt);

            // provider
            AdaptState(dbTransactionData.ProvidersGetAll(), simulationInterval, typesToAdapt);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// convert customer order part to project part view model
        /// </summary>
        /// <param name="customerOrderPart"></param>
        /// <returns></returns>
        public CustomerOrderPartViewModel ConvertToProjectPartView(CustomerOrderPart customerOrderPart)
        {
            CustomerOrderPartViewModel model = new CustomerOrderPartViewModel();

            var _priceSheetRepository    = new PriceSheetRepository();
            var _projectPartRepository   = new ProjectPartRepository();
            var _customerOrderRepository = new CustomerOrderRepository();
            var _foundryOrderRepository  = new FoundryOrderRepository();

            var priceSheetPart   = _priceSheetRepository.GetPriceSheetPart(customerOrderPart.PriceSheetPartId);
            var projectPart      = _projectPartRepository.GetProjectPart((customerOrderPart.ProjectPartId != null) ? customerOrderPart.ProjectPartId : Guid.Empty);
            var priceSheet       = _priceSheetRepository.GetPriceSheet((priceSheetPart != null) ? priceSheetPart.PriceSheetId : Guid.Empty);
            var customerOrder    = _customerOrderRepository.GetCustomerOrder(customerOrderPart.CustomerOrderId);
            var receivedQuantity = _foundryOrderRepository.GetFoundryOrderParts().Where(x => x.CustomerOrderPartId == customerOrderPart.CustomerOrderPartId &&
                                                                                        x.HasBeenReceived).Select(y => y.ReceiptQuantity).Sum();

            model.CustomerOrderPartId   = customerOrderPart.CustomerOrderPartId;
            model.CustomerOrderId       = customerOrderPart.CustomerOrderId;
            model.PONumber              = (!string.IsNullOrEmpty(customerOrder.PONumber)) ? customerOrder.PONumber : "N/A";
            model.ProjectPartId         = customerOrderPart.ProjectPartId;
            model.PriceSheetPartId      = customerOrderPart.PriceSheetPartId;
            model.PriceSheetId          = (priceSheet != null) ? priceSheet.PriceSheetId : Guid.Empty;
            model.AvailableQuantity     = customerOrderPart.AvailableQuantity;
            model.CustomerOrderQuantity = customerOrderPart.Quantity;
            model.PartNumber            = (projectPart != null && !string.IsNullOrEmpty(projectPart.Number)) ? projectPart.Number : "N/A";
            model.PartDescription       = (projectPart != null && !string.IsNullOrEmpty(projectPart.Description)) ? projectPart.Description : "N/A";
            model.PriceSheetNumber      = (priceSheet != null && !string.IsNullOrEmpty(priceSheet.Number)) ? priceSheet.Number : "N/A";
            model.EstArrivalDate        = (customerOrderPart.EstArrivalDate != null) ? customerOrderPart.EstArrivalDate : DateTime.MinValue;
            model.EstArrivalDateStr     = (customerOrderPart.EstArrivalDate != null) ? customerOrderPart.EstArrivalDate.Value.ToShortDateString() : "N/A";
            model.ReceiptQuantity       = receivedQuantity;
            model.Cost  = customerOrderPart.Cost;
            model.Price = customerOrderPart.Price;

            if (_priceSheetRepository != null)
            {
                _priceSheetRepository.Dispose();
                _priceSheetRepository = null;
            }

            if (_projectPartRepository != null)
            {
                _projectPartRepository.Dispose();
                _projectPartRepository = null;
            }

            if (_customerOrderRepository != null)
            {
                _customerOrderRepository.Dispose();
                _customerOrderRepository = null;
            }

            return(model);
        }
Ejemplo n.º 4
0
        public static CustomerOrderPart CreateCustomerOrderPartRandomArticleToBuy(
            int quantity, DueTime dueTime)
        {
            IDbMasterDataCache dbMasterDataCache =
                ZppConfiguration.CacheManager.GetMasterDataCache();
            List <M_Article> articlesToBuy = dbMasterDataCache.M_ArticleGetArticlesToBuy();

            int randomArticleIndex = random.Next(0, articlesToBuy.Count - 1);
            CustomerOrderPart customerOrderPart =
                CreateCustomerOrderPartWithGivenArticle(quantity,
                                                        articlesToBuy[randomArticleIndex], dueTime);

            return(customerOrderPart);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// get customer order part by price sheet part
        /// </summary>
        /// <param name="priceSheetPartId"></param>
        /// <returns></returns>
        public CustomerOrderPart GetCustomerOrderPartByPriceSheetPart(Guid priceSheetPartId)
        {
            var customerOrderPart = new CustomerOrderPart();

            try
            {
                customerOrderPart = _db.CustomerOrderPart.FirstOrDefault(x => x.PriceSheetPartId == priceSheetPartId);
            }
            catch (Exception ex)
            {
                logger.ErrorFormat("Error getting customer order part: {0} ", ex.ToString());
            }

            return(customerOrderPart);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// convert customer order part view model to domain
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public CustomerOrderPart ConvertToDomain(CustomerOrderPartViewModel model)
        {
            CustomerOrderPart part = new CustomerOrderPart();

            part.CustomerOrderPartId = model.CustomerOrderPartId;
            part.ProjectPartId       = model.ProjectPartId;
            part.PartId            = model.PartId;
            part.PriceSheetPartId  = model.PriceSheetPartId;
            part.CustomerOrderId   = model.CustomerOrderId;
            part.AvailableQuantity = model.AvailableQuantity;
            part.Quantity          = model.CustomerOrderQuantity;
            part.EstArrivalDate    = model.EstArrivalDate;
            part.ShipDate          = model.ShipDate;
            part.Price             = model.Price;
            part.Cost = model.Cost;

            return(part);
        }
        ///
        ///
        /// <summary>
        ///     A depth-first-search (DFS) traversal of given tree
        /// </summary>
        /// <returns>
        ///    The List of the traversed nodes in exact order
        /// </returns>
        public INodes TraverseDepthFirst(Action <INode, INodes, INodes> action,
                                         CustomerOrderPart startNode)
        {
            var stack = new Stack <INode>();

            Dictionary <INode, bool> discovered = new Dictionary <INode, bool>();
            INodes traversed = new Nodes();

            stack.Push(new Node(startNode));
            INode parentNode;

            while (stack.Any())
            {
                INode poppedNode = stack.Pop();

                // init dict if node not yet exists
                if (!discovered.ContainsKey(poppedNode))
                {
                    discovered[poppedNode] = false;
                }

                // if node is not discovered
                if (!discovered[poppedNode])
                {
                    traversed.Add(poppedNode);
                    discovered[poppedNode] = true;
                    INodes childNodes = GetSuccessorNodes(poppedNode);
                    action(poppedNode, childNodes, traversed);

                    if (childNodes != null)
                    {
                        foreach (INode node in childNodes)
                        {
                            stack.Push(node);
                        }
                    }
                }
            }

            return(traversed);
        }
        private static void ArchiveFinishedCustomerOrderPartsAndDeleteTheirArrows(
            IDbTransactionData dbTransactionData, IAggregator aggregator)
        {
            Demands copyOfCustomerOrderParts = new Demands();

            copyOfCustomerOrderParts.AddAll(dbTransactionData.CustomerOrderPartGetAll());
            foreach (var demand in copyOfCustomerOrderParts)
            {
                CustomerOrderPart customerOrderPart = (CustomerOrderPart)demand;
                if (customerOrderPart.IsFinished())
                {
                    ArchiveCustomerOrder(customerOrderPart.GetCustomerOrderId());
                    // archive cop
                    List <ILinkDemandAndProvider> arrows =
                        aggregator.GetArrowsFrom(customerOrderPart);
                    dbTransactionData.DeleteAllFrom(arrows);
                    ArchiveDemandOrProvider(customerOrderPart, dbTransactionData, aggregator,
                                            false);
                }
            }
        }
        private static void ArchivedCustomerOrdersWithoutCustomerOrderParts()
        {
            IDbTransactionData dbTransactionData =
                ZppConfiguration.CacheManager.GetDbTransactionData();


            Ids customerOrderIds = new Ids();

            foreach (var demand in dbTransactionData.CustomerOrderPartGetAll())
            {
                CustomerOrderPart customerOrderPart = (CustomerOrderPart)demand;
                customerOrderIds.Add(customerOrderPart.GetCustomerOrderId());
            }

            foreach (var customerOrder in dbTransactionData.CustomerOrderGetAll())
            {
                bool customerOrderHasNoCustomerOrderPart =
                    customerOrderIds.Contains(customerOrder.GetId()) == false;
                if (customerOrderHasNoCustomerOrderPart)
                {
                    ArchiveCustomerOrder(customerOrder.GetId());
                }
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// update customer order part
        /// </summary>
        /// <param name="customerOrderPart"></param>
        /// <returns></returns>
        public OperationResult UpdateCustomerOrderPart(CustomerOrderPart customerOrderPart)
        {
            var operationResult = new OperationResult();

            var existingPart = GetCustomerOrderPart(customerOrderPart.CustomerOrderPartId);

            if (existingPart != null)
            {
                logger.Debug("CustomerOrderPart is being updated.");

                try
                {
                    _db.CustomerOrderPart.Attach(existingPart);

                    _db.Entry(existingPart).CurrentValues.SetValues(customerOrderPart);

                    _db.SaveChanges();

                    operationResult.Success = true;
                    operationResult.Message = "Success";
                }
                catch (Exception ex)
                {
                    operationResult.Success = false;
                    operationResult.Message = "Error";
                    logger.ErrorFormat("Error while updating customer order part: { 0} ", ex.ToString());
                }
            }
            else
            {
                operationResult.Success = false;
                operationResult.Message = "Unable to find selected customer order part.";
            }

            return(operationResult);
        }
Ejemplo n.º 11
0
        public static void CreateConfirmationsOld(SimulationInterval simulationInterval)
        {
            /*ISimulator simulator = new Simulator();
             * simulator.ProcessCurrentInterval(simulationInterval, _orderGenerator);*/
            // --> does not work correctly, use trivial impl instead

            IDbTransactionData dbTransactionData =
                ZppConfiguration.CacheManager.GetDbTransactionData();
            IAggregator aggregator = ZppConfiguration.CacheManager.GetAggregator();

            // stockExchanges, purchaseOrderParts, operations(use PrBom instead):
            // set in progress when startTime is within interval
            DemandOrProviders demandOrProvidersToSetInProgress = new DemandOrProviders();

            demandOrProvidersToSetInProgress.AddAll(
                aggregator.GetDemandsOrProvidersWhereStartTimeIsWithinInterval(simulationInterval,
                                                                               new DemandOrProviders(dbTransactionData.PurchaseOrderPartGetAll())));
            demandOrProvidersToSetInProgress.AddAll(
                aggregator.GetDemandsOrProvidersWhereStartTimeIsWithinInterval(simulationInterval,
                                                                               new DemandOrProviders(dbTransactionData.StockExchangeDemandsGetAll())));
            demandOrProvidersToSetInProgress.AddAll(
                aggregator.GetDemandsOrProvidersWhereStartTimeIsWithinInterval(simulationInterval,
                                                                               new DemandOrProviders(dbTransactionData.StockExchangeProvidersGetAll())));
            demandOrProvidersToSetInProgress.AddAll(
                aggregator.GetDemandsOrProvidersWhereStartTimeIsWithinInterval(simulationInterval,
                                                                               new DemandOrProviders(dbTransactionData.ProductionOrderBomGetAll())));

            foreach (var demandOrProvider in demandOrProvidersToSetInProgress)
            {
                demandOrProvider.SetInProgress();
                demandOrProvider.SetReadOnly();
            }

            // stockExchanges, purchaseOrderParts, operations(use PrBom instead):
            // set finished when endTime is within interval
            DemandOrProviders demandOrProvidersToSetFinished = new DemandOrProviders();

            demandOrProvidersToSetFinished.AddAll(
                aggregator.GetDemandsOrProvidersWhereEndTimeIsWithinIntervalOrBefore(
                    simulationInterval,
                    new DemandOrProviders(dbTransactionData.PurchaseOrderPartGetAll())));
            demandOrProvidersToSetFinished.AddAll(
                aggregator.GetDemandsOrProvidersWhereEndTimeIsWithinIntervalOrBefore(
                    simulationInterval,
                    new DemandOrProviders(dbTransactionData.StockExchangeDemandsGetAll())));
            demandOrProvidersToSetFinished.AddAll(
                aggregator.GetDemandsOrProvidersWhereEndTimeIsWithinIntervalOrBefore(
                    simulationInterval,
                    new DemandOrProviders(dbTransactionData.StockExchangeProvidersGetAll())));
            demandOrProvidersToSetFinished.AddAll(
                aggregator.GetDemandsOrProvidersWhereEndTimeIsWithinIntervalOrBefore(
                    simulationInterval,
                    new DemandOrProviders(dbTransactionData.ProductionOrderBomGetAll())));
            foreach (var demandOrProvider in demandOrProvidersToSetFinished)
            {
                demandOrProvider.SetFinished();
                demandOrProvider.SetReadOnly();
            }

            // customerOrderParts: set finished if all childs are finished
            DemandToProviderGraph demandToProviderGraph = new DemandToProviderGraph();
            INodes rootNodes = demandToProviderGraph.GetRootNodes();

            foreach (var rootNode in rootNodes)
            {
                if (rootNode.GetEntity().GetType() == typeof(CustomerOrderPart))
                {
                    CustomerOrderPart customerOrderPart = (CustomerOrderPart)rootNode.GetEntity();
                    customerOrderPart.SetReadOnly();

                    bool allChildsAreFinished = true;
                    foreach (var stockExchangeProvider in aggregator.GetAllChildProvidersOf(
                                 customerOrderPart))
                    {
                        if (stockExchangeProvider.IsFinished() == false)
                        {
                            allChildsAreFinished = false;
                            break;
                        }
                    }

                    if (allChildsAreFinished)
                    {
                        customerOrderPart.SetFinished();
                    }
                }
            }

            // set operations readonly
            foreach (var operation in dbTransactionData.ProductionOrderOperationGetAll())
            {
                operation.SetReadOnly();
            }

            // set productionOrders readonly
            foreach (var productionOrder in dbTransactionData.ProductionOrderGetAll())
            {
                productionOrder.SetReadOnly();
            }

            // future SEs are still not readonly, set it so
            foreach (var stockExchangeDemand in dbTransactionData.StockExchangeDemandsGetAll())
            {
                stockExchangeDemand.SetReadOnly();
            }

            foreach (var stockExchangeProvider in dbTransactionData.StockExchangeProvidersGetAll())
            {
                stockExchangeProvider.SetReadOnly();
            }
        }
        public void TestApplyConfirmations(string testConfigurationFileName)
        {
            InitThisTest(testConfigurationFileName);

            IDbTransactionData dbTransactionData =
                ZppConfiguration.CacheManager.GetDbTransactionData();
            IAggregator aggregator = ZppConfiguration.CacheManager.GetAggregator();

            // Ein CustomerOrderParts darf kein Kind haben und darf nicht beendet sein
            Ids customerOrderIds = new Ids();

            foreach (var demand in dbTransactionData.CustomerOrderPartGetAll())
            {
                CustomerOrderPart customerOrderPart = (CustomerOrderPart)demand;
                customerOrderIds.Add(customerOrderPart.GetCustomerOrderId());
                Providers childs = aggregator.GetAllChildProvidersOf(customerOrderPart);
                Assert.False(childs.Any());
                Assert.False(customerOrderPart.IsFinished());
            }

            // Ein PurchaseOrderPart darf kein Elter haben und darf nicht beendet sein.
            Ids purchaseOrderIds = new Ids();

            foreach (var demand in dbTransactionData.PurchaseOrderPartGetAll())
            {
                PurchaseOrderPart purchaseOrderPart = (PurchaseOrderPart)demand;
                purchaseOrderIds.Add(purchaseOrderPart.GetPurchaseOrderId());

                Assert.False(purchaseOrderPart.IsFinished());
                Demands demands = aggregator.GetAllParentDemandsOf(demand);
                Assert.True(demands == null || demands.Any() == false);
            }

            // Für jede CustomerOrder muss es mind. noch ein CustomerOrderPart geben.
            foreach (var customerOrder in dbTransactionData.CustomerOrderGetAll())
            {
                Assert.True(customerOrderIds.Contains(customerOrder.GetId()));
            }

            // Für jede PurchaseOrder muss es mind. noch ein PurchaseOrderPart geben.
            foreach (var purchaseOrder in dbTransactionData.PurchaseOrderGetAll())
            {
                Assert.True(purchaseOrderIds.Contains(purchaseOrder.GetId()));
            }

            // Ein StockExchangeProvider muss mind. ein Kind haben.
            foreach (var stockExchangeProvider in dbTransactionData.StockExchangeProvidersGetAll())
            {
                Demands childs = aggregator.GetAllChildDemandsOf(stockExchangeProvider);
                Assert.True(childs.Any());
            }

            // Ein StockExchangeDemand darf nicht beendet und geschlossen sein.
            foreach (var stockExchangeDemand in dbTransactionData.StockExchangeDemandsGetAll())
            {
                bool isOpen = OpenDemandManager.IsOpen((StockExchangeDemand)stockExchangeDemand);
                Assert.False(stockExchangeDemand.IsFinished() && isOpen == false);
            }

            // Eine ProductionOrder darf nicht beendet sein und für eine ProductionOrder
            // muss es mind. eine  Operation geben.
            Ids productionOrderIds = new Ids();
            Ids operationIds       = new Ids();

            foreach (var operation in dbTransactionData.ProductionOrderOperationGetAll())
            {
                Id productionOrderId = operation.GetProductionOrderId();
                if (productionOrderIds.Contains(productionOrderId) == false)
                {
                    productionOrderIds.Add(productionOrderId);
                }

                operationIds.Add(operation.GetId());
            }
            foreach (var provider in dbTransactionData.ProductionOrderGetAll())
            {
                ProductionOrder productionOrder = (ProductionOrder)provider;
                Assert.False(productionOrder.DetermineProductionOrderState()
                             .Equals(State.Finished));
                Assert.True(productionOrderIds.Contains(productionOrder.GetId()));
            }

            // Für jede ProductionOrderBom muss die dazugehörige Operation da sein.
            foreach (var demand in dbTransactionData.ProductionOrderBomGetAll())
            {
                ProductionOrderBom productionOrderBom = (ProductionOrderBom)demand;
                operationIds.Contains(productionOrderBom.GetProductionOrderOperationId());
            }

            // Für jeden DemandToProvider und ProviderToDemand müssen die dazugehörigen
            // Demands und Provider existieren.
            foreach (var demandToProvider in dbTransactionData.DemandToProviderGetAll())
            {
                Demand   demand   = dbTransactionData.DemandsGetById(demandToProvider.GetDemandId());
                Provider provider =
                    dbTransactionData.ProvidersGetById(demandToProvider.GetProviderId());
                Assert.NotNull(demand);
                Assert.NotNull(provider);
            }

            foreach (var providerToDemand in dbTransactionData.ProviderToDemandGetAll())
            {
                Demand   demand   = dbTransactionData.DemandsGetById(providerToDemand.GetDemandId());
                Provider provider =
                    dbTransactionData.ProvidersGetById(providerToDemand.GetProviderId());
                Assert.NotNull(demand);
                Assert.NotNull(provider);
            }
        }