コード例 #1
0
        private IList <JobLogDB.EventLogMaterial> FindOrCreateMaterial(int pallet, int fixturenum, DateTime endUTC, string order, string part, int process, int count)
        {
            var rows = _status.FindMaterialIDs(pallet, fixturenum, endUTC);

            if (rows.Count == 0)
            {
                Log.Warning("Unable to find any material ids for pallet " + pallet.ToString() + "-" +
                            fixturenum.ToString() + " for order " + order + " for event at time " + endUTC.ToString());
                rows = _status.CreateMaterialIDs(pallet, fixturenum, endUTC, order, AllocateMatIds(count, order, part, process), 0);
            }

            if (rows[0].Order != order)
            {
                Log.Warning("MaterialIDs for pallet " + pallet.ToString() + "-" + fixturenum.ToString() +
                            " for event at time " + endUTC.ToString() + " does not have matching orders: " +
                            "expected " + order + " but found " + rows[0].Order);

                rows = _status.CreateMaterialIDs(pallet, fixturenum, endUTC, order, AllocateMatIds(count, order, part, process), 0);
            }

            if (rows.Count < count)
            {
                Log.Warning("Pallet " + pallet.ToString() + "-" + fixturenum.ToString() +
                            " at event time " + endUTC.ToString() + " with order " + order + " was expected to have " +
                            count.ToString() + " material ids, but only " + rows.Count + " were loaded");

                int maxCounter = -1;
                foreach (var row in rows)
                {
                    if (row.LocCounter > maxCounter)
                    {
                        maxCounter = row.LocCounter;
                    }
                }

                //stupid that IList doesn't have AddRange
                foreach (var row in _status.CreateMaterialIDs(
                             pallet, fixturenum, rows[0].LoadedUTC, order, AllocateMatIds(count - rows.Count, order, part, process), maxCounter + 1))
                {
                    rows.Add(row);
                }
            }

            var ret = new List <JobLogDB.EventLogMaterial>();

            foreach (var row in rows)
            {
                if (Settings.SerialType != SerialType.NoAutomaticSerials)
                {
                    CreateSerial(row.MatID, order, part, process, fixturenum.ToString(), _log, Settings);
                }
                ret.Add(new JobLogDB.EventLogMaterial()
                {
                    MaterialID = row.MatID, Process = process, Face = ""
                });
            }
            return(ret);
        }
コード例 #2
0
        public CurrentStatus LoadCurrentInfo()
        {
            using (var cmd = _db.CreateCommand()) {
                var map    = new MakinoToJobMap(_logDb);
                var palMap = new MakinoToPalletMap();

                Load("SELECT PartID, ProcessNumber, ProcessID FROM " + dbo + "Processes", reader => {
                    map.AddProcess(reader.GetInt32(0), reader.GetInt32(1), reader.GetInt32(2));
                });

                //Makino: Parts   MachineWatch: Jobs
                Load("SELECT PartID, PartName, Revision, Comment, Priority FROM " + dbo + "Parts", reader => {
                    var partID = reader.GetInt32(0);

                    var partName = reader.GetString(1);
                    if (!reader.IsDBNull(2))
                    {
                        partName += reader.GetString(2);
                    }

                    var job = map.CreateJob(partName, partID);

                    job.JobCopiedToSystem = true;
                    job.PartName          = reader.GetString(1);
                    if (!reader.IsDBNull(3))
                    {
                        job.Comment = reader.GetString(3);
                    }
                    if (!reader.IsDBNull(4))
                    {
                        job.Priority = reader.GetInt16(4);
                    }
                    job.ManuallyCreatedJob = false;
                    job.CreateMarkerData   = false;
                });


                var devices = Devices();

                Load("SELECT ProcessID, JobNumber, JobID FROM " + dbo + "Jobs", reader => {
                    map.AddJobToProcess(reader.GetInt32(0), reader.GetInt32(1), reader.GetInt32(2));
                });

                Load("SELECT a.JobID, b.Name FROM " + dbo + "MachineJobs a " +
                     "INNER JOIN " + dbo + "NCProgramFiles b " +
                     "ON a.NCProgramFileID = b.NCProgramFileID", reader => {
                    map.AddProgramToJob(reader.GetInt32(0), reader.GetString(1));
                });

                Load("SELECT JobID, FeasibleDeviceID FROM " + dbo + "JobFeasibleDevices", reader => {
                    map.AddAllowedStationToJob(reader.GetInt32(0), devices[reader.GetInt32(1)]);
                });

                map.CompleteStations();

                Load("SELECT a.PalletFixtureID, a.FixtureNumber, a.FixtureID, b.PalletNumber, c.CurDeviceType, c.CurDeviceNumber " +
                     "FROM " + dbo + "PalletFixtures a, " + dbo + "Pallets b, " + dbo + "PalletLocation c " +
                     "WHERE a.PalletID = b.PalletID AND a.PalletID = c.PalletID " +
                     " AND a.FixtureID IS NOT NULL", reader => {
                    var loc = new PalletLocation(PalletLocationEnum.Buffer, "Unknown", 0);
                    if (!reader.IsDBNull(4) && !reader.IsDBNull(5))
                    {
                        loc = ParseDevice(reader.GetInt16(4), reader.GetInt16(5));
                    }

                    palMap.AddPalletInfo(reader.GetInt32(0), reader.GetInt32(1), reader.GetInt32(2),
                                         reader.GetInt32(3), loc);
                });

                Load("SELECT ProcessID, FixtureID FROM " + dbo + "FixtureProcesses", reader => {
                    map.AddFixtureToProcess(reader.GetInt32(0), reader.GetInt32(1),
                                            palMap.PalletsForFixture(reader.GetInt32(1)));
                });

                Load("SELECT OrderID, OrderName, PartID, Comment, Quantity, Priority, StartDate " +
                     "FROM " + dbo + "Orders", reader => {
                    var newJob = map.DuplicateForOrder(reader.GetInt32(0), reader.GetString(1), reader.GetInt32(2));

                    if (!reader.IsDBNull(3))
                    {
                        newJob.Comment = reader.GetString(3);
                    }

                    newJob.SetPlannedCyclesOnFirstProcess(1, reader.GetInt32(4));

                    if (!reader.IsDBNull(5))
                    {
                        newJob.Priority = reader.GetInt16(5);
                    }

                    DateTime start = DateTime.SpecifyKind(reader.GetDateTime(6), DateTimeKind.Local);
                    start          = start.ToUniversalTime();

                    for (int i = 1; i <= newJob.NumProcesses; i++)
                    {
                        newJob.SetSimulatedStartingTimeUTC(i, 1, start);
                    }
                });

                Load("SELECT OrderID, ProcessID, RemainingQuantity, NormalQuantity, ScrapQuantity " +
                     "FROM " + dbo + "Quantities", reader => {
                    map.AddQuantityToProcess(reader.GetInt32(0), reader.GetInt32(1), reader.GetInt32(3));
                });

                Load("SELECT PalletFixtureID, CurProcessID, CurOrderID, CurJobID, WorkStatus " +
                     "FROM " + dbo + "FixtureRun WHERE CurProcessID IS NOT NULL", reader => {
                    int palfixID = reader.GetInt32(0);
                    int orderID  = reader.GetInt32(2);
                    var job      = map.JobForOrder(orderID);

                    string orderName = "";
                    if (job != null)
                    {
                        orderName = job.UniqueStr;
                    }

                    // Lookup (pallet,location) for this palfixID
                    int palletNum;
                    int fixtureNum;
                    palMap.PalletLocInfo(palfixID, out palletNum, out fixtureNum);

                    //look for material id
                    IList <StatusDB.MatIDRow> matIDs;
                    if (_status == null)
                    {
                        matIDs = new List <StatusDB.MatIDRow>();
                    }
                    else
                    {
                        matIDs = _status.FindMaterialIDs(palletNum, fixtureNum, DateTime.UtcNow.AddSeconds(10));
                    }

                    //check material ids share the same order
                    if (orderName != "")
                    {
                        foreach (var m in matIDs)
                        {
                            if (m.Order != orderName)
                            {
                                Log.Debug("Current material on pallet " + palletNum.ToString() +
                                          " loc " + fixtureNum.ToString() + " was expecting orderID " +
                                          orderID.ToString() + " for order " + orderName.ToString() +
                                          ", but found order " + m.Order + " for part loaded at " + m.LoadedUTC.ToString());
                                matIDs.Clear();
                                break;
                            }
                        }
                    }

                    if (matIDs.Count == 0)
                    {
                        var m   = default(StatusDB.MatIDRow);
                        m.MatID = -1;
                        matIDs.Add(m);
                    }

                    foreach (var m in matIDs)
                    {
                        var inProcMat =
                            map.CreateMaterial(
                                orderID, reader.GetInt32(1), reader.GetInt32(3), palletNum,
                                fixtureNum, m.MatID);

                        palMap.AddMaterial(palfixID, inProcMat);
                    }
                });

                //There is a MovePalletFixtureID column which presumebly means rotate through process?
                //Other columns include remachining, cancel, recleaning, offdutyprocess, operation status
                Load("SELECT PalletFixtureID, UnclampJobID, UnclampOrderID, ClampJobID, ClampOrderID, ClampQuantity " +
                     "FROM " + dbo + "WorkSetCommand WHERE PalletFixtureID IS NOT NULL", reader => {
                    var palfixID = reader.GetInt32(0);

                    if (!reader.IsDBNull(1) && !reader.IsDBNull(2))
                    {
                        var unclampJobID = reader.GetInt32(1);
                        var unclampOrder = reader.GetInt32(2);

                        var procNum = map.ProcessForJobID(unclampJobID);
                        var job     = map.JobForOrder(unclampOrder);
                        if (job != null)
                        {
                            palMap.SetMaterialAsUnload(palfixID, job.NumProcesses == procNum);
                        }
                    }

                    if (!reader.IsDBNull(3) && !reader.IsDBNull(4))
                    {
                        var clampJobID = reader.GetInt32(3);
                        var clampOrder = reader.GetInt32(4);

                        var procNum = map.ProcessForJobID(clampJobID);
                        var job     = map.JobForOrder(clampOrder);
                        int qty     = 1;
                        if (!reader.IsDBNull(5))
                        {
                            qty = reader.GetInt32(5);
                        }

                        if (job != null)
                        {
                            palMap.AddMaterialToLoad(palfixID, job.UniqueStr, job.PartName, procNum, qty);
                        }
                    }
                });

                //TODO: inspections (from jobdb), holds

                var st = new CurrentStatus();
                foreach (var j in map.Jobs)
                {
                    st.Jobs.Add(j.UniqueStr, j);
                }
                foreach (var p in palMap.Pallets)
                {
                    st.Pallets.Add(p);
                }
                foreach (var m in palMap.Material)
                {
                    st.Material.Add(m);
                }
                return(st);
            }
        }