Ejemplo n.º 1
0
        private void FillSimulationWorkSchedules(List <PowsSimulationItem> items, int simulationId, int simulationNumber, MrpTask task)
        {
            foreach (var item in items)
            {
                var po   = _context.ProductionOrders.Include(b => b.Article).Single(a => a.Id == item.ProductionOrderId);
                var pows = _context.ProductionOrderWorkSchedules.Single(a => a.Id == item.ProductionOrderWorkScheduleId);

                if (task == MrpTask.None)
                {
                    var schedule = new SimulationWorkschedule()
                    {
                        ParentId          = JsonConvert.SerializeObject(from parent in _context.GetParents(pows) select parent.Id),
                        ProductionOrderId = "[" + po.Id.ToString() + "]",
                        Article           = po.Article.Name,
                        DueTime           = po.Duetime,
                        End                       = pows.EndSimulation,
                        EstimatedEnd              = pows.End,
                        EstimatedStart            = pows.Start,
                        HierarchyNumber           = pows.HierarchyNumber,
                        Machine                   = pows.MachineId == null ? null : _context.Machines.Single(a => a.Id == pows.MachineId).Name,
                        Start                     = pows.StartSimulation,
                        OrderId                   = JsonConvert.SerializeObject(_context.GetOrderIdsFromProductionOrder(po)),
                        SimulationConfigurationId = simulationId,
                        WorkScheduleId            = pows.Id.ToString(),
                        WorkScheduleName          = pows.Name,
                        SimulationType            = SimulationType.Central,
                        SimulationNumber          = simulationNumber,
                    };
                    _context.Add(schedule);
                    //_evaluationContext.Add(schedule.CopyDbPropertiesWithoutId());
                }

                if (task == MrpTask.Backward || task == MrpTask.All)
                {
                    var backward = new SimulationWorkschedule()
                    {
                        ParentId          = JsonConvert.SerializeObject(from parent in _context.GetParents(pows) select parent.ProductionOrderId),
                        ProductionOrderId = "[" + po.Id.ToString() + "]",
                        Article           = po.Article.Name,
                        DueTime           = po.Duetime,
                        End                       = pows.EndBackward,
                        HierarchyNumber           = pows.HierarchyNumber,
                        Start                     = pows.StartBackward,
                        OrderId                   = JsonConvert.SerializeObject(_context.GetOrderIdsFromProductionOrder(po)),
                        SimulationConfigurationId = simulationId,
                        WorkScheduleId            = pows.Id.ToString(),
                        WorkScheduleName          = pows.Name,
                        SimulationType            = SimulationType.BackwardPlanning,
                        SimulationNumber          = simulationNumber,
                        Machine                   = pows.MachineGroupId.ToString()
                    };
                    _context.Add(backward);
                    _evaluationContext.Add(backward.CopyDbPropertiesWithoutId());
                }
                if (task == MrpTask.Forward || task == MrpTask.All)
                {
                    var forward = new SimulationWorkschedule()
                    {
                        ParentId          = JsonConvert.SerializeObject(from parent in _context.GetParents(pows) select parent.ProductionOrderId),
                        ProductionOrderId = "[" + po.Id.ToString() + "]",
                        Article           = po.Article.Name,
                        DueTime           = po.Duetime,
                        End                       = pows.EndForward,
                        HierarchyNumber           = pows.HierarchyNumber,
                        Start                     = pows.StartForward,
                        OrderId                   = JsonConvert.SerializeObject(_context.GetOrderIdsFromProductionOrder(po)),
                        SimulationConfigurationId = simulationId,
                        WorkScheduleId            = pows.Id.ToString(),
                        WorkScheduleName          = pows.Name,
                        SimulationType            = SimulationType.ForwardPlanning,
                        SimulationNumber          = simulationNumber,
                        Machine                   = pows.MachineGroupId.ToString()
                    };
                    _context.Add(forward);
                    _evaluationContext.Add(forward.CopyDbPropertiesWithoutId());
                }
            }
            _context.SaveChanges();
            _evaluationContext.SaveChanges();
        }