Exemple #1
0
        private static void SchedulePart(
            MazakWriteData transSet, int SchID, string mazakPartName, string mazakComment, int numProcess,
            JobPlan part, int proc1path, int earlierConflicts, bool UseStartingOffsetForDueDate)
        {
            var newSchRow = new MazakScheduleRow();

            newSchRow.Command            = MazakWriteCommand.Add;
            newSchRow.Id                 = SchID;
            newSchRow.PartName           = mazakPartName;
            newSchRow.PlanQuantity       = part.GetPlannedCyclesOnFirstProcess(proc1path);
            newSchRow.CompleteQuantity   = 0;
            newSchRow.FixForMachine      = 0;
            newSchRow.MissingFixture     = 0;
            newSchRow.MissingProgram     = 0;
            newSchRow.MissingTool        = 0;
            newSchRow.MixScheduleID      = 0;
            newSchRow.ProcessingPriority = 0;
            newSchRow.Comment            = mazakComment;

            if (UseStartingOffsetForDueDate)
            {
                if (part.GetSimulatedStartingTimeUTC(1, proc1path) != DateTime.MinValue)
                {
                    var start = part.GetSimulatedStartingTimeUTC(1, proc1path);
                    newSchRow.DueDate  = start.ToLocalTime().Date;
                    newSchRow.Priority = 91 + Math.Min(earlierConflicts, 9);
                }
                else
                {
                    newSchRow.DueDate  = DateTime.Today;
                    newSchRow.Priority = 91;
                }
            }
            else
            {
                newSchRow.Priority = 75;
                newSchRow.DueDate  = DateTime.Parse("1/1/2008 12:00:00 AM");
            }

            bool entireHold = false;

            if (part.HoldEntireJob != null)
            {
                entireHold = part.HoldEntireJob.IsJobOnHold;
            }
            bool machiningHold = false;

            if (part.HoldMachining(1, proc1path) != null)
            {
                machiningHold = part.HoldMachining(1, proc1path).IsJobOnHold;
            }
            newSchRow.HoldMode = (int)HoldPattern.CalculateHoldMode(entireHold, machiningHold);

            int matQty = newSchRow.PlanQuantity;

            if (!string.IsNullOrEmpty(part.GetInputQueue(process: 1, path: proc1path)))
            {
                matQty = 0;
            }

            //need to add all the ScheduleProcess rows
            for (int i = 1; i <= numProcess; i++)
            {
                var newSchProcRow = new MazakScheduleProcessRow();
                newSchProcRow.MazakScheduleRowId = SchID;
                newSchProcRow.ProcessNumber      = i;
                if (i == 1)
                {
                    newSchProcRow.ProcessMaterialQuantity = matQty;
                }
                else
                {
                    newSchProcRow.ProcessMaterialQuantity = 0;
                }
                newSchProcRow.ProcessBadQuantity     = 0;
                newSchProcRow.ProcessExecuteQuantity = 0;
                newSchProcRow.ProcessMachine         = 0;

                newSchRow.Processes.Add(newSchProcRow);
            }

            transSet.Schedules.Add(newSchRow);
        }
Exemple #2
0
        private List <MWI.LogEntry> CheckPendingLoads(int pallet, DateTime t, string foreignID, bool palletCycle, List <MWI.LogEntry> cycle)
        {
            var pending = _log.PendingLoads(pallet.ToString());

            if (pending.Count == 0)
            {
                if (palletCycle)
                {
                    bool hasCompletedUnload = false;
                    foreach (var e in cycle)
                    {
                        if (e.LogType == LogType.LoadUnloadCycle &&
                            e.StartOfCycle == false &&
                            e.Result == "UNLOAD")
                        {
                            hasCompletedUnload = true;
                        }
                    }
                    if (hasCompletedUnload)
                    {
                        _log.CompletePalletCycle(pallet.ToString(), t, foreignID);
                    }
                    else
                    {
                        Log.Debug("Skipping pallet cycle at time {time} because we detected a pallet cycle without unload", t);
                    }
                }

                return(cycle);
            }

            var mat = new Dictionary <string, IEnumerable <JobLogDB.EventLogMaterial> >();

            foreach (var p in pending)
            {
                Log.Debug("Processing pending load {@pending}", p);
                var s = p.Key.Split(',');
                if (s.Length != 3)
                {
                    continue;
                }

                string fullPartName = s[0];
                string jobPartName  = MazakPart.ExtractPartNameFromMazakPartName(fullPartName);

                int proc;
                int fixQty;
                if (!int.TryParse(s[1], out proc))
                {
                    proc = 1;
                }
                if (!int.TryParse(s[2], out fixQty))
                {
                    fixQty = 1;
                }

                _mazakSchedules.FindSchedule(fullPartName, proc, out string unique, out int path, out int numProc);

                JobPlan job = GetJob(unique);

                var mats = new List <JobLogDB.EventLogMaterial>();
                if (job != null && !string.IsNullOrEmpty(job.GetInputQueue(proc, path)))
                {
                    // search input queue for material
                    Log.Debug("Searching queue {queue} for {unique}-{proc} to load",
                              job.GetInputQueue(proc, path), unique, proc);

                    // TODO: filter paths
                    var qs = _log.GetMaterialInQueue(job.GetInputQueue(proc, path)).Where(q => q.Unique == unique).ToList();

                    for (int i = 1; i <= fixQty; i++)
                    {
                        string face;
                        if (fixQty == 1)
                        {
                            face = proc.ToString();
                        }
                        else
                        {
                            face = proc.ToString() + "-" + i.ToString();
                        }
                        if (i <= qs.Count)
                        {
                            var qmat = qs[i - 1];
                            mats.Add(new JobLogDB.EventLogMaterial()
                            {
                                MaterialID = qmat.MaterialID, Process = proc, Face = face
                            });
                        }
                        else
                        {
                            // not enough material in queue
                            Log.Warning("Not enough material in queue {queue} for {part}-{proc}, creating new material for {@pending}",
                                        job.GetInputQueue(proc, path), fullPartName, proc, p);
                            mats.Add(new JobLogDB.EventLogMaterial()
                            {
                                MaterialID = _log.AllocateMaterialID(unique, jobPartName, numProc),
                                Process    = proc,
                                Face       = face
                            });
                        }
                    }
                }
                else if (proc == 1)
                {
                    // create new material
                    Log.Debug("Creating new material for unique {unique} process 1", unique);
                    for (int i = 1; i <= fixQty; i += 1)
                    {
                        string face;
                        if (fixQty == 1)
                        {
                            face = proc.ToString();
                        }
                        else
                        {
                            face = proc.ToString() + "-" + i.ToString();
                        }

                        mats.Add(new JobLogDB.EventLogMaterial()
                        {
                            MaterialID = _log.AllocateMaterialID(unique, jobPartName, numProc),
                            Process    = proc,
                            Face       = face
                        });
                    }
                }
                else
                {
                    // search on pallet in the previous process for material
                    Log.Debug("Searching on pallet for unique {unique} process {proc} to load into process {proc}", unique, proc - 1, proc);
                    var byFace = ParseMaterialFromPreviousEvents(
                        jobPartName: jobPartName,
                        proc: proc - 1,
                        fixQty: fixQty,
                        isUnloadEnd: false,
                        oldEvents: cycle);
                    for (int i = 1; i <= fixQty; i += 1)
                    {
                        string prevFace;
                        string nextFace;
                        if (fixQty == 1)
                        {
                            prevFace = (proc - 1).ToString();
                            nextFace = proc.ToString();
                        }
                        else
                        {
                            prevFace = (proc - 1).ToString() + "-" + i.ToString();
                            nextFace = proc.ToString() + "-" + i.ToString();
                        }

                        if (byFace.ContainsKey(prevFace))
                        {
                            var old = byFace[prevFace];
                            mats.Add(new JobLogDB.EventLogMaterial()
                            {
                                MaterialID = old.MaterialID,
                                Process    = proc,
                                Face       = nextFace
                            });
                        }
                        else
                        {
                            //something went wrong, must create material
                            mats.Add(new JobLogDB.EventLogMaterial()
                            {
                                MaterialID = _log.AllocateMaterialID(unique, jobPartName, numProc),
                                Process    = proc,
                                Face       = nextFace
                            });

                            Log.Warning("Could not find material on pallet {pallet} for previous process {proc}, creating new material for {@pending}",
                                        pallet, proc - 1, p);
                        }
                    }
                }

                mat[p.Key] = mats;
            }

            _log.CompletePalletCycle(pallet.ToString(), t, foreignID, mat, generateSerials: true);

            if (palletCycle)
            {
                return(cycle);
            }
            else
            {
                return(_log.CurrentPalletLog(pallet.ToString()));
            }
        }