Ejemplo n.º 1
0
        /// <summary>
        /// 从配置档中读取数据
        /// </summary>
        /// <param name="inifilepath"></param>
        public static void loadConfigData(string inifilepath)
        {
            try
            {
                //sysconfig
                Param.SysVersion = IniFile.IniReadValue("SysConfig", "SysVersion", @inifilepath);

                //配置档升级

                Int32 ini_Version  = Convert.ToInt32(Param.SysVersion.ToString().Replace(".", "")); //将版本号转换成整数
                Int32 Soft_Version = Convert.ToInt32(Application.ProductVersion.ToString().Replace(".", ""));
                if (ini_Version > Soft_Version)
                {
                    saveLog(Param.logType.SYSLOG.ToString(), "配置档版本高于软件版本...");
                    MessageBox.Show("配置档版本高于软件版本:");
                }
                if (ini_Version > Soft_Version)
                {
                    saveLog(Param.logType.SYSLOG.ToString(), "配置档版本与软件版本匹配...");
                }
                if (ini_Version < Soft_Version)
                {
                    saveLog(Param.logType.SYSLOG.ToString(), "配置档版本低于软件版本...");
                    DialogResult MsgBoxResult;//设置对话框返回值
                    string       MEG = string.Empty;
                    MEG += "配置档版本:" + Param.SysVersion.ToString() + "\n";
                    MEG += "软件版本:" + Application.ProductVersion.ToString() + "\n";
                    MEG += "因版本不匹配,你是否确定要更新配置档版本?" + "\n";
                    MEG += "\n";
                    MEG += "注意:" + "\n" + "1.不更新,仅变更配置档版本号,可能引发参数调用错误" + "\n";
                    MEG += "2.更新后,可能有必要修改部分参数!!!" + "\n";

                    MEG         += "\n";
                    MEG         += "是点击“Yes”,否点击“NO”" + "\n";
                    MsgBoxResult = MessageBox.Show(MEG, "小心操作!!!", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2);

                    if (MsgBoxResult == DialogResult.Yes)
                    {
                        File.Delete(@inifilepath);//删除配置档
                        if (!File.Exists(Param.IniFilePath))
                        {
                            SubFunction.creatInI(Param.IniFilePath);
                        }
                        SubFunction.loadConfigData(Param.IniFilePath);
                        SubFunction.saveLog(Param.logType.SYSLOG.ToString(), "完成配置档更新...");
                    }
                    if (MsgBoxResult == DialogResult.No)
                    {
                        IniFile.IniWriteValue("SysConfig", "SysVersion", Application.ProductVersion, @inifilepath);
                        SubFunction.saveLog(Param.logType.SYSLOG.ToString(), "取消配置档更新,仅更新配置档版本号...");
                        //Application.Exit();
                    }
                }

                Param.FICTStage      = IniFile.IniReadValue("SysConfig", "FICTStage", @inifilepath);
                Param.FixtrueID      = IniFile.IniReadValue("SysConfig", "FixtureID", @inifilepath);
                Param.PCBLine        = IniFile.IniReadValue("SysConfig", "PCBLine", @inifilepath);
                Param.TestingType    = IniFile.IniReadValue("SysConfig", "TestingType", @inifilepath);
                Param.MBType         = IniFile.IniReadValue("SysConfig", "MBType", @inifilepath);
                Param.RobotModule    = IniFile.IniReadValue("SysConfig", "RobotModule", @inifilepath);
                Param.BarcodeType    = IniFile.IniReadValue("SysConfig", "BarcodeType", @inifilepath);
                Param.MaxErrorCount  = Convert.ToInt16(IniFile.IniReadValue("SysConfig", "MaxErrorCount", @inifilepath));
                Param.MaxRetestCount = Convert.ToInt16(IniFile.IniReadValue("SysConfig", "MaxRetestCount", @inifilepath));
                changeString2Bool(IniFile.IniReadValue("SysConfig", "LeftInsert", @inifilepath), ref Param.LeftInsert);
                changeString2Bool(IniFile.IniReadValue("SysConfig", "RightInsert", @inifilepath), ref Param.RightInsert);
                changeString2Bool(IniFile.IniReadValue("SysConfig", "RTC_Use", @inifilepath), ref Param.RTC_Use);
                //MessageBox.Show(IniFile.IniReadValue("SysConfig", "DetectDelay", @inifilepath));
                Param.DetectDelay = Convert.ToInt16(IniFile.IniReadValue("SysConfig", "DetectDelay", @inifilepath));
                Param.ShutDown    = Convert.ToInt16(IniFile.IniReadValue("SysConfig", "ShutDown", @inifilepath));
                changeString2Bool(IniFile.IniReadValue("SysConfig", "LeftInsertRe", @inifilepath), ref Param.LeftInsertRe);
                changeString2Bool(IniFile.IniReadValue("SysConfig", "RightInsertRe", @inifilepath), ref Param.RightInserRe);
                changeString2Bool(IniFile.IniReadValue("SysConfig", "UseCommand", @inifilepath), ref Param.UseCommand);
                //IniFile.IniWriteValue("SysConfig", "InsertDelay", "5", @inifilepath);
                //IniFile.IniWriteValue("SysConfig", "ST_Flag", "0", @inifilepath);
                if (!string.IsNullOrEmpty(IniFile.IniReadValue("SysConfig", "InsertDelay", @inifilepath)))
                {
                    Param.InsertDelay = Convert.ToInt16(IniFile.IniReadValue("SysConfig", "InsertDelay", @inifilepath));
                }

                if (string.IsNullOrEmpty(IniFile.IniReadValue("SysConfig", "NG_Stop", @inifilepath)))
                {
                    changeString2Bool(IniFile.IniReadValue("SysConfig", "NG_Stop", @inifilepath), ref Param.NG_Stop);
                }

                if (string.IsNullOrEmpty(IniFile.IniReadValue("SysConfig", "ST_Flag", @inifilepath)))
                {
                    changeString2Bool(IniFile.IniReadValue("SysConfig", "ST_Flag", @inifilepath), ref Param.ST_Flag);
                }

                if (!string.IsNullOrEmpty(IniFile.IniReadValue("SysConfig", "AD_Module_Type", @inifilepath).Trim()))
                {
                    Param.AD_Module_Type = IniFile.IniReadValue("SysConfig", "AD_Module_Type", @inifilepath).ToUpper();
                }

                if (!string.IsNullOrEmpty(IniFile.IniReadValue("SysConfig", "MB_A_Re", @inifilepath)))
                {
                    changeString2Bool(IniFile.IniReadValue("SysConfig", "MB_A_Re", @inifilepath), ref Param.MB_A_Re);
                }
                if (!string.IsNullOrEmpty(IniFile.IniReadValue("SysConfig", "MB_B_Re", @inifilepath)))
                {
                    changeString2Bool(IniFile.IniReadValue("SysConfig", "MB_B_Re", @inifilepath), ref Param.MB_B_Re);
                }

                //sfcs_set
                changeString2Bool(IniFile.IniReadValue("SFCS_Set", "CheckRouter", @inifilepath), ref Param.CheckRouter);
                changeString2Bool(IniFile.IniReadValue("SFCS_Set", "Web_Use", @inifilepath), ref Param.Web_Use);
                Param.Web_Site = IniFile.IniReadValue("SFCS_Set", "Web_Site", @inifilepath);
                changeString2Bool(IniFile.IniReadValue("SFCS_Set", "OKBBBStatus", @inifilepath), ref Param.OKBBBStatus);
                changeString2Bool(IniFile.IniReadValue("SFCS_Set", "NGBBBStatus", @inifilepath), ref Param.NGBBBStatus);
                Param.SFC_Stage = IniFile.IniReadValue("SFCS_Set", "SFC_Stage", @inifilepath);
                Param.OPID      = IniFile.IniReadValue("SFCS_Set", "OPID", @inifilepath);
                changeString2Bool(IniFile.IniReadValue("SFCS_Set", "Arms_Use", @inifilepath), ref Param.Arms_Use);
                Param.Arms_Version = IniFile.IniReadValue("SFCS_Set", "Arms_Version", @inifilepath);
                Param.Arms_Path    = IniFile.IniReadValue("SFCS_Set", "Arms_Path", @inifilepath);
                Param.Net_Server   = IniFile.IniReadValue("SFCS_Set", "Net_Server", @inifilepath);
                Param.Net_ID       = IniFile.IniReadValue("SFCS_Set", "Net_ID", @inifilepath);
                Param.Net_Password = IniFile.IniReadValue("SFCS_Set", "Net_Password", @inifilepath);
                //db_set

                changeString2Bool(IniFile.IniReadValue("DB_Set", "Center_DataBase_Use", @inifilepath), ref Param.Center_DataBase_Use);
                Param.CenterIP_DataBase_IP       = IniFile.IniReadValue("DB_Set", "CenterIP_DataBase_IP", @inifilepath);
                Param.CenterIP_DataBase_DB       = IniFile.IniReadValue("DB_Set", "CenterIP_DataBase_DB", @inifilepath);
                Param.CenterIP_DataBase_Table    = IniFile.IniReadValue("DB_Set", "CenterIP_DataBase_Table", @inifilepath);
                Param.CenterIP_DataBase_Account  = IniFile.IniReadValue("DB_Set", "CenterIP_DataBase_Account", @inifilepath);
                Param.CenterIP_DataBase_Password = IniFile.IniReadValue("DB_Set", "CenterIP_DataBase_Password", @inifilepath);

                changeString2Bool(IniFile.IniReadValue("DB_Set", "Record_DataBase_Use", @inifilepath), ref Param.Record_DataBase_Use);
                Param.RecordIP_DataBase_IP             = IniFile.IniReadValue("DB_Set", "RecordIP_DataBase_IP", @inifilepath);
                Param.RecordIP_DataBase_DB             = IniFile.IniReadValue("DB_Set", "RecordIP_DataBase_DB", @inifilepath);
                Param.RecordIP_DataBase_TestInfo_Table = IniFile.IniReadValue("DB_Set", "RecordIP_DataBase_TestInfo_Table", @inifilepath);
                Param.RecordIP_DataBase_Station_Table  = IniFile.IniReadValue("DB_Set", "RecordIP_DataBase_Station_Table", @inifilepath);
                Param.RecordIP_DataBase_Account        = IniFile.IniReadValue("DB_Set", "RecordIP_DataBase_Account", @inifilepath);
                Param.RecordIP_DataBase_Password       = IniFile.IniReadValue("DB_Set", "RecordIP_DataBase_Password", @inifilepath);

                //comport
                changeString2Bool(IniFile.IniReadValue("ComPort_Set", "Scanner_Use", @inifilepath), ref Param.Scanner_Use);
                Param.Scanner = IniFile.IniReadValue("ComPort_Set", "Scanner", @inifilepath);
                changeString2Bool(IniFile.IniReadValue("ComPort_Set", "DUT_A_Use", @inifilepath), ref Param.DUT_A_Use);
                Param.DUT_A = IniFile.IniReadValue("ComPort_Set", "DUT_A", @inifilepath);
                changeString2Bool(IniFile.IniReadValue("ComPort_Set", "DUT_B_Use", @inifilepath), ref Param.DUT_B_Use);
                Param.DUT_B = IniFile.IniReadValue("ComPort_Set", "DUT_B", @inifilepath);
                changeString2Bool(IniFile.IniReadValue("ComPort_Set", "PLC_Use", @inifilepath), ref Param.PLC_Use);
                Param.PLC = IniFile.IniReadValue("ComPort_Set", "PLC", @inifilepath);

                //timeout
                Param.Wait_MB_TimeOut          = Convert.ToInt16(IniFile.IniReadValue("TimeOut_Set", "Wait_MB_TimeOut", @inifilepath));
                Param.In_Time_TimeOut          = Convert.ToInt16(IniFile.IniReadValue("TimeOut_Set", "In_Time_TimeOut", @inifilepath));
                Param.PowerONTimeOut           = Convert.ToInt16(IniFile.IniReadValue("TimeOut_Set", "PowerONTimeOut", @inifilepath));
                Param.TestOKTimeOut            = Convert.ToInt16(IniFile.IniReadValue("TimeOut_Set", "TestOKTimeOut", @inifilepath));
                Param.Out_Time_TimeOut         = Convert.ToInt16(IniFile.IniReadValue("TimeOut_Set", "Out_Time_TimeOut", @inifilepath));
                Param.Test_PeriodCycle_TimeOut = Convert.ToInt16(IniFile.IniReadValue("TimeOut_Set", "Test_PeriodCycle_TimeOut", @inifilepath));

                //连接字符串
                Param.Center_DB_ConnStr = "server=" + Param.CenterIP_DataBase_IP + ";user id=" + Param.CenterIP_DataBase_Account + ";password="******";persistsecurityinfo=True;database=" + Param.CenterIP_DataBase_DB;
                Param.Record_DB_ConnStr = "server=" + Param.RecordIP_DataBase_IP + ";user id=" + Param.RecordIP_DataBase_Account + ";password="******";persistsecurityinfo=True;database=" + Param.RecordIP_DataBase_DB;
            }
            catch (Exception ex)
            {
                saveLog(Param.logType.SYSLOG.ToString(), "配置档读取出错,请检查配置档,error:" + ex.Message);
                MessageBox.Show("配置档读取出错,,请检查配置档,error:" + ex.Message);
            }
        }