示例#1
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";
        }
示例#2
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;
            }
        }