Esempio n. 1
0
 protected OpenDatabaseKitDB(string dbConnStr, MazakDbType ty)
 {
     MazakType = ty;
     if (MazakType != MazakDbType.MazakSmooth)
     {
         ready4ConectPath = System.IO.Path.Combine(dbConnStr, "ready4Conect.mdb");
     }
 }
Esempio n. 2
0
        public override void CreateDatabaseRow(MazakPartRow newPart, string fixture, MazakDbType mazakTy)
        {
            var newPartProcRow = new MazakPartProcessRow();

            newPartProcRow.PartName      = Part.PartName;
            newPartProcRow.ProcessNumber = ProcessNumber;
            newPartProcRow.Fixture       = fixture;
            newPartProcRow.FixQuantity   = Math.Max(1, Job.PartsPerPallet(ProcessNumber, Path));

            newPartProcRow.ContinueCut = 0;
            //newPartProcRow.FixPhoto = "";
            //newPartProcRow.RemovePhoto = "";
            newPartProcRow.WashType = 0;

            char[] FixLDS   = { '0', '0', '0', '0', '0', '0', '0', '0', '0', '0' };
            char[] UnfixLDS = { '0', '0', '0', '0', '0', '0', '0', '0', '0', '0' };
            char[] Cut      = { '0', '0', '0', '0', '0', '0', '0', '0' };

            string program = "";

            foreach (var routeEntry in Job.GetMachiningStop(ProcessNumber, Path))
            {
                program = routeEntry.ProgramName;
                foreach (int statNum in routeEntry.Stations)
                {
                    Cut[statNum - 1] = statNum.ToString()[0];
                }
            }

            foreach (int statNum in Job.LoadStations(ProcessNumber, Path))
            {
                FixLDS[statNum - 1] = statNum.ToString()[0];
            }

            foreach (int statNum in Job.UnloadStations(ProcessNumber, Path))
            {
                UnfixLDS[statNum - 1] = statNum.ToString()[0];
            }

            newPartProcRow.MainProgram = program;
            newPartProcRow.FixLDS      = new string(FixLDS);
            newPartProcRow.RemoveLDS   = new string(UnfixLDS);
            newPartProcRow.CutMc       = new string(Cut);

            if (mazakTy != MazakDbType.MazakVersionE)
            {
                newPartProcRow.FixLDS    = ConvertStatStrV1ToV2(newPartProcRow.FixLDS).ToString();
                newPartProcRow.RemoveLDS = ConvertStatStrV1ToV2(newPartProcRow.RemoveLDS).ToString();
                newPartProcRow.CutMc     = ConvertStatStrV1ToV2(newPartProcRow.CutMc).ToString();
            }

            newPart.Processes.Add(newPartProcRow);
        }
Esempio n. 3
0
 public OpenDatabaseKitTransactionDB(string dbConnStr, MazakDbType ty)
     : base(dbConnStr, ty)
 {
     if (MazakType == MazakDbType.MazakWeb || MazakType == MazakDbType.MazakVersionE)
     {
         _connectionStr = "Provider=Microsoft.Jet.OLEDB.4.0;Password=\"\";" +
                          "User ID=Admin;" +
                          "Data Source=" + System.IO.Path.Combine(dbConnStr, "FCNETUSER1.mdb") + ";" +
                          "Mode=Share Deny None;";
     }
     else
     {
         _connectionStr = dbConnStr + ";Database=FCNETUSER01";
     }
 }
Esempio n. 4
0
        private static PalletLocation FindPalletLocation(IMachineGroupName machName, MazakSchedulesPartsPallets mazakData, MazakDbType dbType, int palletNum)
        {
            foreach (var palLocRow in mazakData.PalletPositions)
            {
                if (palLocRow.PalletNumber == palletNum)
                {
                    if (dbType != MazakDbType.MazakVersionE)
                    {
                        return(ParseStatNameWeb(machName, palLocRow.PalletPosition));
                    }
                    else
                    {
                        return(ParseStatNameVerE(machName, palLocRow.PalletPosition));
                    }
                }
            }

            return(new PalletLocation(PalletLocationEnum.Buffer, "Buffer", 0));
        }
Esempio n. 5
0
        public static CurrentStatus Build(JobDB jobDB, JobLogDB log, FMSSettings fmsSettings, IMachineGroupName machineGroupName, IQueueSyncFault queueSyncFault, MazakDbType dbType, MazakAllData mazakData, DateTime utcNow)
        {
            //Load process and path numbers
            Dictionary <string, int> uniqueToMaxPath;
            Dictionary <string, int> uniqueToMaxProcess;

            CalculateMaxProcAndPath(mazakData, out uniqueToMaxPath, out uniqueToMaxProcess);

            var currentLoads = new List <LoadAction>(mazakData.LoadActions);

            var curStatus = new CurrentStatus();

            foreach (var k in fmsSettings.Queues)
            {
                curStatus.QueueSizes[k.Key] = k.Value;
            }
            if (mazakData.Alarms != null)
            {
                foreach (var alarm in mazakData.Alarms)
                {
                    if (!string.IsNullOrEmpty(alarm.AlarmMessage))
                    {
                        curStatus.Alarms.Add(alarm.AlarmMessage);
                    }
                }
            }
            if (queueSyncFault.CurrentQueueMismatch)
            {
                curStatus.Alarms.Add("Queue contents and Mazak schedule quantity mismatch.");
            }

            var jobsBySchID = new Dictionary <long, InProcessJob>();
            var pathBySchID = new Dictionary <long, MazakPart.IProcToPath>();

            foreach (var schRow in mazakData.Schedules)
            {
                if (!MazakPart.IsSailPart(schRow.PartName))
                {
                    continue;
                }

                MazakPartRow partRow = null;
                foreach (var p in mazakData.Parts)
                {
                    if (p.PartName == schRow.PartName)
                    {
                        partRow = p;
                        break;
                    }
                }
                if (partRow == null)
                {
                    continue;
                }

                //Parse data from the database
                var partName = partRow.PartName;
                int loc      = partName.IndexOf(':');
                if (loc >= 0)
                {
                    partName = partName.Substring(0, loc);
                }
                string jobUnique = "";
                MazakPart.IProcToPath procToPath = null;
                bool manual = false;
                if (!string.IsNullOrEmpty(partRow.Comment))
                {
                    MazakPart.ParseComment(partRow.Comment, out jobUnique, out procToPath, out manual);
                }

                if (!uniqueToMaxProcess.ContainsKey(jobUnique))
                {
                    continue;
                }

                int numProc      = uniqueToMaxProcess[jobUnique];
                int maxProc1Path = uniqueToMaxPath[jobUnique];

                InProcessJob job;

                //Create or lookup the job
                if (curStatus.Jobs.ContainsKey(jobUnique))
                {
                    job = curStatus.Jobs[jobUnique];
                }
                else
                {
                    var jobPaths = new int[numProc];
                    for (int i = 0; i < numProc; i++)
                    {
                        jobPaths[i] = maxProc1Path;
                    }
                    job                   = new InProcessJob(jobUnique, numProc, jobPaths);
                    job.PartName          = partName;
                    job.JobCopiedToSystem = true;
                    curStatus.Jobs.Add(jobUnique, job);
                }
                jobsBySchID.Add(schRow.Id, job);
                pathBySchID.Add(schRow.Id, procToPath);

                //Job Basics
                job.SetPlannedCyclesOnFirstProcess(procToPath.PathForProc(proc: 1), schRow.PlanQuantity);
                AddCompletedToJob(schRow, job, procToPath);
                job.Priority = schRow.Priority;
                if (((HoldPattern.HoldMode)schRow.HoldMode) == HoldPattern.HoldMode.FullHold)
                {
                    job.HoldEntireJob.UserHold = true;
                }
                else
                {
                    job.HoldEntireJob.UserHold = false;
                }

                AddRoutingToJob(mazakData, partRow, job, machineGroupName, procToPath, dbType);
            }

            var loadedJobs = new HashSet <string>();

            foreach (var j in jobsBySchID.Values)
            {
                if (loadedJobs.Contains(j.UniqueStr))
                {
                    continue;
                }
                loadedJobs.Add(j.UniqueStr);
                AddDataFromJobDB(jobDB, j);
            }

            //Now add pallets

            foreach (var palRow in mazakData.Pallets)
            {
                if (palRow.PalletNumber > 0 && !curStatus.Pallets.ContainsKey(palRow.PalletNumber.ToString()))
                {
                    var palName = palRow.PalletNumber.ToString();
                    var palLoc  = FindPalletLocation(machineGroupName, mazakData, dbType, palRow.PalletNumber);

                    //Create the pallet
                    PalletStatus status = new PalletStatus()
                    {
                        Pallet = palName,
                        CurrentPalletLocation = palLoc,
                        FixtureOnPallet       = palRow.Fixture,
                        NumFaces = 1,
                        OnHold   = false
                    };
                    curStatus.Pallets.Add(status.Pallet, status);

                    var oldCycles = log.CurrentPalletLog(palName);

                    //Add the material currently on the pallet
                    foreach (var palSub in mazakData.PalletSubStatuses)
                    {
                        if (palSub.PalletNumber != palRow.PalletNumber)
                        {
                            continue;
                        }
                        if (palSub.FixQuantity <= 0)
                        {
                            continue;
                        }
                        if (!jobsBySchID.ContainsKey(palSub.ScheduleID))
                        {
                            continue;
                        }

                        status.NumFaces = Math.Max(status.NumFaces, palSub.PartProcessNumber);

                        var job        = jobsBySchID[palSub.ScheduleID];
                        var procToPath = pathBySchID[palSub.ScheduleID];

                        var matIDs = new Queue <long>(FindMatIDsFromOldCycles(oldCycles, job.UniqueStr, palSub.PartProcessNumber));

                        for (int i = 1; i <= palSub.FixQuantity; i++)
                        {
                            int  face  = palSub.PartProcessNumber;
                            long matID = -1;
                            if (matIDs.Count > 0)
                            {
                                matID = matIDs.Dequeue();
                            }

                            var matDetails = log.GetMaterialDetails(matID);
                            var inProcMat  = new InProcessMaterial()
                            {
                                MaterialID          = matID,
                                JobUnique           = job.UniqueStr,
                                PartName            = job.PartName,
                                Process             = palSub.PartProcessNumber,
                                Path                = procToPath.PathForProc(palSub.PartProcessNumber),
                                Serial              = matDetails?.Serial,
                                WorkorderId         = matDetails?.Workorder,
                                SignaledInspections =
                                    log.LookupInspectionDecisions(matID)
                                    .Where(x => x.Inspect)
                                    .Select(x => x.InspType)
                                    .Distinct()
                                    .ToList(),
                                LastCompletedMachiningRouteStopIndex =
                                    oldCycles.Any(
                                        c => c.LogType == LogType.MachineCycle &&
                                        !c.StartOfCycle &&
                                        c.Material.Any(m => m.MaterialID == matID && m.Process == palSub.PartProcessNumber)
                                        )
                    ? (int?)0
                    : null,
                                Location = new InProcessMaterialLocation()
                                {
                                    Type   = InProcessMaterialLocation.LocType.OnPallet,
                                    Pallet = status.Pallet,
                                    Face   = face
                                },
                                Action = new InProcessMaterialAction()
                                {
                                    Type = InProcessMaterialAction.ActionType.Waiting
                                }
                            };
                            curStatus.Material.Add(inProcMat);

                            //check for unloading or transfer
                            var loadNext = CheckLoadOfNextProcess(currentLoads, job.UniqueStr, palSub.PartProcessNumber, palLoc);
                            var unload   = CheckUnload(currentLoads, job.UniqueStr, palSub.PartProcessNumber, palLoc);

                            if (loadNext != null)
                            {
                                var start = FindLoadStartFromOldCycles(oldCycles, matID);
                                inProcMat.Action = new InProcessMaterialAction()
                                {
                                    Type                  = InProcessMaterialAction.ActionType.Loading,
                                    LoadOntoFace          = palSub.PartProcessNumber + 1,
                                    LoadOntoPallet        = status.Pallet,
                                    ProcessAfterLoad      = palSub.PartProcessNumber + 1,
                                    PathAfterLoad         = procToPath.PathForProc(palSub.PartProcessNumber + 1),
                                    ElapsedLoadUnloadTime = start != null ? (TimeSpan?)utcNow.Subtract(start.EndTimeUTC) : null
                                };
                            }
                            else if (unload != null)
                            {
                                var start = FindLoadStartFromOldCycles(oldCycles, matID);
                                inProcMat.Action = new InProcessMaterialAction()
                                {
                                    Type =
                                        palSub.PartProcessNumber == job.NumProcesses
                            ? InProcessMaterialAction.ActionType.UnloadToCompletedMaterial
                            : InProcessMaterialAction.ActionType.UnloadToInProcess,
                                    UnloadIntoQueue = job.GetOutputQueue(
                                        process: palSub.PartProcessNumber,
                                        path: procToPath.PathForProc(palSub.PartProcessNumber)),
                                    ElapsedLoadUnloadTime = start != null ? (TimeSpan?)utcNow.Subtract(start.EndTimeUTC) : null
                                };
                            }
                            else
                            {
                                // detect if machining
                                var start = FindMachineStartFromOldCycles(oldCycles, matID);
                                if (start != null)
                                {
                                    var machStop    = job.GetMachiningStop(inProcMat.Process, inProcMat.Path).FirstOrDefault();
                                    var elapsedTime = utcNow.Subtract(start.EndTimeUTC);
                                    inProcMat.Action = new InProcessMaterialAction()
                                    {
                                        Type = InProcessMaterialAction.ActionType.Machining,
                                        ElapsedMachiningTime           = elapsedTime,
                                        ExpectedRemainingMachiningTime =
                                            machStop != null?machStop.ExpectedCycleTime.Subtract(elapsedTime) : TimeSpan.Zero
                                    };
                                }
                            }
                        }
                    }

                    if (palLoc.Location == PalletLocationEnum.LoadUnload)
                    {
                        var start       = FindLoadStartFromOldCycles(oldCycles);
                        var elapsedLoad = start != null ? (TimeSpan?)utcNow.Subtract(start.EndTimeUTC) : null;
                        AddLoads(log, currentLoads, status.Pallet, palLoc, elapsedLoad, curStatus);
                        AddUnloads(log, currentLoads, status, elapsedLoad, oldCycles, curStatus);
                    }
                }
            }

            //now queued
            var seenMatIds = new HashSet <long>(curStatus.Material.Select(m => m.MaterialID));

            foreach (var mat in log.GetMaterialInAllQueues())
            {
                // material could be in the process of being loaded
                if (seenMatIds.Contains(mat.MaterialID))
                {
                    continue;
                }
                var matLogs  = log.GetLogForMaterial(mat.MaterialID);
                int lastProc = 0;
                foreach (var entry in log.GetLogForMaterial(mat.MaterialID))
                {
                    foreach (var entryMat in entry.Material)
                    {
                        if (entryMat.MaterialID == mat.MaterialID)
                        {
                            lastProc = Math.Max(lastProc, entryMat.Process);
                        }
                    }
                }
                var matDetails = log.GetMaterialDetails(mat.MaterialID);
                curStatus.Material.Add(new InProcessMaterial()
                {
                    MaterialID          = mat.MaterialID,
                    JobUnique           = mat.Unique,
                    PartName            = mat.PartName,
                    Process             = lastProc,
                    Path                = 1,
                    Serial              = matDetails?.Serial,
                    WorkorderId         = matDetails?.Workorder,
                    SignaledInspections =
                        log.LookupInspectionDecisions(mat.MaterialID)
                        .Where(x => x.Inspect)
                        .Select(x => x.InspType)
                        .Distinct()
                        .ToList(),
                    Location = new InProcessMaterialLocation()
                    {
                        Type          = InProcessMaterialLocation.LocType.InQueue,
                        CurrentQueue  = mat.Queue,
                        QueuePosition = mat.Position,
                    },
                    Action = new InProcessMaterialAction()
                    {
                        Type = InProcessMaterialAction.ActionType.Waiting
                    }
                });
            }


            var notCopied = jobDB.LoadJobsNotCopiedToSystem(DateTime.UtcNow.AddHours(-WriteJobs.JobLookbackHours), DateTime.UtcNow);

            foreach (var j in notCopied.Jobs)
            {
                if (curStatus.Jobs.ContainsKey(j.UniqueStr))
                {
                    //The copy to the cell succeeded but the DB has not yet been updated.
                    //The thread which copies jobs will soon notice and update the database
                    //so we can ignore it for now.
                }
                else
                {
                    curStatus.Jobs.Add(j.UniqueStr, new InProcessJob(j));
                }
            }

            foreach (var j in curStatus.Jobs)
            {
                foreach (var d in jobDB.LoadDecrementsForJob(j.Value.UniqueStr))
                {
                    j.Value.Decrements.Add(d);
                }
            }

            return(curStatus);
        }
Esempio n. 6
0
        private static void AddRoutingToJob(MazakSchedulesPartsPallets mazakData, MazakPartRow partRow, JobPlan job, IMachineGroupName machineGroupName, MazakPart.IProcToPath procToPath, MazakDbType mazakTy)
        {
            //Add routing and pallets
            foreach (var partProcRow in partRow.Processes)
            {
                var path = procToPath.PathForProc(partProcRow.ProcessNumber);
                job.SetPartsPerPallet(partProcRow.ProcessNumber, path, partProcRow.FixQuantity);
                job.SetPathGroup(partProcRow.ProcessNumber, path, path);
                job.SetHoldMachining(partProcRow.ProcessNumber, path, job.HoldMachining(partProcRow.ProcessNumber, path));
                job.SetHoldLoadUnload(partProcRow.ProcessNumber, path, job.HoldLoadUnload(partProcRow.ProcessNumber, path));

                //Routing
                string fixStr    = partProcRow.FixLDS;
                string cutStr    = partProcRow.CutMc;
                string removeStr = partProcRow.RemoveLDS;

                if (mazakTy != MazakDbType.MazakVersionE)
                {
                    fixStr    = ConvertStatIntV2ToV1(Convert.ToInt32(fixStr));
                    cutStr    = ConvertStatIntV2ToV1(Convert.ToInt32(cutStr));
                    removeStr = ConvertStatIntV2ToV1(Convert.ToInt32(removeStr));
                }

                foreach (char c in fixStr)
                {
                    if (c != '0')
                    {
                        job.AddLoadStation(partProcRow.ProcessNumber, path, int.Parse(c.ToString()));
                    }
                }
                foreach (char c in removeStr)
                {
                    if (c != '0')
                    {
                        job.AddUnloadStation(partProcRow.ProcessNumber, path, int.Parse(c.ToString()));
                    }
                }

                JobMachiningStop routeStop = null;
                foreach (char c in cutStr)
                {
                    if (c != '0')
                    {
                        if (routeStop == null)
                        {
                            routeStop = new JobMachiningStop(machineGroupName.MachineGroupName);
                            job.AddMachiningStop(partProcRow.ProcessNumber, path, routeStop);
                        }
                        routeStop.Stations.Add(int.Parse(c.ToString()));
                    }
                }

                if (routeStop != null)
                {
                    routeStop.ProgramName = partProcRow.MainProgram;
                }

                //Planned Pallets
                foreach (var palRow in mazakData.Pallets)
                {
                    if (palRow.PalletNumber > 0 &&
                        palRow.Fixture == partProcRow.Fixture &&
                        !job.HasPallet(partProcRow.ProcessNumber, path, palRow.PalletNumber.ToString()))
                    {
                        job.AddProcessOnPallet(partProcRow.ProcessNumber, path, palRow.PalletNumber.ToString());
                    }
                }
            }
        }
Esempio n. 7
0
        public OpenDatabaseKitReadDB(string dbConnStr, MazakDbType ty, LoadOperationsFromFile loadOper)
            : base(dbConnStr, ty)
        {
            _loadOper = loadOper;
            if (MazakType == MazakDbType.MazakWeb || MazakType == MazakDbType.MazakVersionE)
            {
                _connectionStr = "Provider=Microsoft.Jet.OLEDB.4.0;Password=\"\";User ID=Admin;" +
                                 "Data Source=" + System.IO.Path.Combine(dbConnStr, "FCREADDAT01.mdb") + ";" +
                                 "Mode=Share Deny Write;";
            }
            else
            {
                _connectionStr = dbConnStr + ";Database=FCREADDAT01";
            }

            _fixtureSelect = "SELECT FixtureName, Comment FROM Fixture";

            if (MazakType != MazakDbType.MazakVersionE)
            {
                _palletSelect = "SELECT PalletNumber, FixtureGroup AS FixtureGroupV2, Fixture, RecordID FROM Pallet";
            }
            else
            {
                _palletSelect = "SELECT PalletNumber, Angle AS AngleV1, Fixture, RecordID FROM Pallet";
            }

            if (MazakType != MazakDbType.MazakSmooth)
            {
                _partSelect     = "SELECT Id, PartName, Comment, Price, TotalProcess FROM Part";
                _partSelect     = @"SELECT
            PartName,
            Comment,
            Price,
            TotalProcess
          FROM Part";
                _partProcSelect = "SELECT ContinueCut, CutMc, FixLDS, FixPhoto, FixQuantity, Fixture, MainProgram, PartName, ProcessNumber, RemoveLDS, RemovePhoto, WashType FROM PartProcess";
                _partProcSelect = @"SELECT
            PartName,
            ProcessNumber,
            FixQuantity,
            ContinueCut,
            CutMc,
            FixLDS,
            FixPhoto,
            Fixture,
            MainProgram,
            RemoveLDS,
            RemovePhoto,
            WashType
          FROM PartProcess";

                _scheduleSelect     = @"SELECT
            ScheduleID As Id,
            Comment,
            PartName,
            PlanQuantity,
            CompleteQuantity,
            Priority,
            DueDate,
            FixForMachine,
            HoldMode,
            MissingFixture,
            MissingProgram,
            MissingTool,
            MixScheduleID,
            ProcessingPriority
          FROM Schedule";
                _scheduleProcSelect = @"SELECT
            ScheduleID As MazakScheduleRowId,
            ProcessNumber,
            ProcessMaterialQuantity,
            ProcessExecuteQuantity,
            ProcessBadQuantity,
            ProcessMachine
          FROM ScheduleProcess";
            }
            else
            {
                _partSelect     = @"SELECT
            PartName,
            Comment,
            Price,
            TotalProcess,
            MaterialName,
            Part_1,
            Part_2,
            Part_3,
            Part_4,
            Part_5,
            CheckCount,
            ProductCount
          FROM Part";
                _partProcSelect = @"SELECT
            PartName,
            ProcessNumber,
            FixQuantity,
            ContinueCut,
            CutMc,
            FixLDS,
            FixPhoto,
            Fixture,
            MainProgram,
            RemoveLDS,
            RemovePhoto,
            WashType,
            PartProcess_1,
            PartProcess_2,
            PartProcess_3,
            PartProcess_4,
            FixTime,
            RemoveTime,
            CreateToolList_RA
          FROM PartProcess";

                _scheduleSelect     = @"SELECT
            ScheduleID As Id,
            Comment,
            PartName,
            PlanQuantity,
            CompleteQuantity,
            Priority,
            DueDate,
            FixForMachine,
            HoldMode,
            MissingFixture,
            MissingProgram,
            MissingTool,
            MixScheduleID,
            ProcessingPriority,
            Schedule_1,
            Schedule_2,
            Schedule_3,
            Schedule_4,
            Schedule_5,
            Schedule_6,
            StartDate,
            SetNumber,
            SetQuantity,
            SetNumberSets
          FROM Schedule";
                _scheduleProcSelect = @"SELECT
            ScheduleID As MazakScheduleRowId,
            ProcessNumber,
            ProcessMaterialQuantity,
            ProcessExecuteQuantity,
            ProcessBadQuantity,
            ProcessMachine,
            FixedMachineFlag,
            FixedMachineNumber,
            ScheduleProcess_1,
            ScheduleProcess_2,
            ScheduleProcess_3,
            ScheduleProcess_4,
            ScheduleProcess_5
          FROM ScheduleProcess";
            }

            // normally would use a join to determine FixQuantity as part of the schedule proc row,
            // but the mazak readdb has no indexes and no keys, so everything is a table scan.
            _partProcFixQty = "SELECT PartName, ProcessNumber, FixQuantity FROM PartProcess";

            _palSubStatusSelect = "SELECT FixQuantity, FixtureName, PalletNumber, PartName, PartProcessNumber, ScheduleID FROM PalletSubStatus";
            _palPositionSelect  = "SELECT PalletNumber, PalletPosition FROM PalletPosition WHERE PalletNumber > 0";
            _mainProgSelect     = "SELECT MainProgram, Comment FROM MainProgram";
            _alarmSelect        = "SELECT AlarmNumber, AlarmMessage FROM Alarm";
        }
Esempio n. 8
0
        public MazakBackend(IConfiguration configuration, FMSSettings st)
        {
            var    cfg         = configuration.GetSection("Mazak");
            string localDbPath = cfg.GetValue <string>("Database Path");

            MazakType = DetectMazakType(cfg, localDbPath);

            // database settings
            string sqlConnectString = cfg.GetValue <string>("SQL ConnectionString");
            string dbConnStr;

            if (MazakType == MazakDbType.MazakSmooth)
            {
                if (!string.IsNullOrEmpty(sqlConnectString))
                {
                    dbConnStr = sqlConnectString;
                }
                else if (!string.IsNullOrEmpty(localDbPath))
                {
                    // old installers put sql server computer name in localDbPath
                    dbConnStr = "Server=" + localDbPath + "\\pmcsqlserver;" +
                                "User ID=mazakpmc;Password=Fms-978";
                }
                else
                {
                    var b = new System.Data.SqlClient.SqlConnectionStringBuilder();
                    b.UserID     = "mazakpmc";
                    b.Password   = "******";
                    b.DataSource = "(local)";
                    dbConnStr    = b.ConnectionString;
                }
            }
            else
            {
                dbConnStr = localDbPath;
                if (string.IsNullOrEmpty(dbConnStr))
                {
                    dbConnStr = "c:\\Mazak\\NFMS\\DB";
                }
            }

            // log csv
            string logPath = cfg.GetValue <string>("Log CSV Path");

            if (logPath == null || logPath == "")
            {
                logPath = "c:\\Mazak\\FMS\\Log";
            }

            if (MazakType != MazakDbType.MazakVersionE && !System.IO.Directory.Exists(logPath))
            {
                Log.Error("Log CSV Directory {path} does not exist.  Set the directory in the config.ini file.", logPath);
            }
            else if (MazakType != MazakDbType.MazakVersionE)
            {
                Log.Information("Loading log CSV files from {logcsv}", logPath);
            }

            // general config
            string useStarting  = cfg.GetValue <string>("Use Starting Offset For Due Date");
            string useStarting2 = cfg.GetValue <string>("Use Starting Offset");

            if (string.IsNullOrEmpty(useStarting))
            {
                if (string.IsNullOrEmpty(useStarting2))
                {
                    UseStartingOffsetForDueDate = true;
                }
                else
                {
                    UseStartingOffsetForDueDate = Convert.ToBoolean(useStarting2);
                }
            }
            else
            {
                UseStartingOffsetForDueDate = Convert.ToBoolean(useStarting);
            }
            //Perhaps this should be a new setting, but if you don't check for pallets used once
            //then you don't care if all faces on a pallet are full so might as well use priority
            //which causes pallet positions to go empty.
            CheckPalletsUsedOnce = !UseStartingOffsetForDueDate;

            ProgramDirectory = cfg.GetValue <string>("Program Directory");
            if (string.IsNullOrEmpty(ProgramDirectory))
            {
                ProgramDirectory = "C:\\NCProgs";
            }

            // serial settings
            string serialPerMaterial = cfg.GetValue <string>("Assign Serial Per Material");

            if (!string.IsNullOrEmpty(serialPerMaterial))
            {
                bool result;
                if (bool.TryParse(serialPerMaterial, out result))
                {
                    if (!result)
                    {
                        st.SerialType = SerialType.AssignOneSerialPerCycle;
                    }
                }
            }

            Log.Debug(
                "Configured UseStartingOffsetForDueDate = {useStarting}",
                UseStartingOffsetForDueDate);

            jobLog = new BlackMaple.MachineFramework.JobLogDB(st);
            jobLog.Open(
                System.IO.Path.Combine(st.DataDirectory, "log.db"),
                System.IO.Path.Combine(st.DataDirectory, "insp.db"),
                startingSerial: st.StartingSerial
                );

            jobDB = new BlackMaple.MachineFramework.JobDB();
            var jobInspName = System.IO.Path.Combine(st.DataDirectory, "jobinspection.db");

            if (System.IO.File.Exists(jobInspName))
            {
                jobDB.Open(jobInspName);
            }
            else
            {
                jobDB.Open(System.IO.Path.Combine(st.DataDirectory, "mazakjobs.db"));
            }

            _writeDB = new OpenDatabaseKitTransactionDB(dbConnStr, MazakType);

            if (MazakType == MazakDbType.MazakVersionE)
            {
                loadOper = new LoadOperationsFromFile(cfg, enableWatcher: true);
            }
            else if (MazakType == MazakDbType.MazakWeb)
            {
                loadOper = new LoadOperationsFromFile(cfg, enableWatcher: false); // web instead watches the log csv files
            }
            else
            {
                loadOper = null; // smooth db doesn't use the load operations file
            }
            var openReadDb = new OpenDatabaseKitReadDB(dbConnStr, MazakType, loadOper);

            if (MazakType == MazakDbType.MazakSmooth)
            {
                _readDB = new SmoothReadOnlyDB(dbConnStr, openReadDb);
            }
            else
            {
                _readDB = openReadDb;
            }

            queues = new MazakQueues(jobLog, jobDB, _writeDB);
            var sendToExternal = new SendMaterialToExternalQueue();

            hold = new HoldPattern(_writeDB, _readDB, jobDB, true);
            var writeJobs = new WriteJobs(_writeDB, _readDB, hold, jobDB, jobLog, st, CheckPalletsUsedOnce, UseStartingOffsetForDueDate, ProgramDirectory);
            var decr      = new DecrementPlanQty(jobDB, _writeDB, _readDB);

            if (MazakType == MazakDbType.MazakWeb || MazakType == MazakDbType.MazakSmooth)
            {
                logDataLoader = new LogDataWeb(logPath, jobLog, jobDB, writeJobs, sendToExternal, _readDB, queues, st);
            }
            else
            {
#if USE_OLEDB
                logDataLoader = new LogDataVerE(jobLog, jobDB, sendToExternal, writeJobs, _readDB, queues, st);
#else
                throw new Exception("Mazak Web and VerE are not supported on .NET core");
#endif
            }

            routing = new RoutingInfo(_writeDB, writeJobs, _readDB, logDataLoader, jobDB, jobLog, writeJobs, queues, decr,
                                      CheckPalletsUsedOnce, st);

            logDataLoader.NewEntries += OnNewLogEntries;
            if (loadOper != null)
            {
                loadOper.LoadActions += OnLoadActions;
            }
        }
Esempio n. 9
0
 public abstract void CreateDatabaseRow(MazakPartRow newPart, string fixture, MazakDbType mazakTy);