public void CountThreadProc()
        {
            string strLog = string.Empty;
            //bu_Peng bu_p = new bu_Peng();
            try
            {
                AutoAPP.MainForm._runnerFov = this;
                if (this.running == true)
                {
                    //BoundCPUX();
                    int iCore = Environment.ProcessorCount;
                    //iCore--;
                    iCore--;
                    SetThreadAffinityMask(GetCurrentThread(), new UIntPtr(SetCpuID(iCore)));
                    //bu_Peng.SaveDataForLHfoxNG(strConnectString, strLastPcbPath, strLastPcbFile, strLastAppsettingTmpFile, strAppsettingPath, appSettingHandle, timer, log);
                    bu_Peng bp = new bu_Peng();
                    //bp._configData = _configData;
                    bp.ReadFovImages( Aconfig, this._ExToFovImagePath, this._appSettingHandle);
                }

            }
            catch (Exception ex)
            {
               // log.WriteErr("警告 ! " + ex.ToString(), ThreadName);
                AppLogHelp.WriteWarning(LogFileFormate.FOVPCB,ThreadName+ ex.Message);
                return;
            }
            finally
            {
                //log.WriteLog("线程Fov结束!", ThreadName);
                //AutoAPP.MainForm.bFov = true;
                AppLogHelp.WriteLog(LogFileFormate.FOVPCB, ThreadName + "线程Fov结束!");
            }
        }
Esempio n. 2
0
 public string TestConnectionFox(string strMysqlConn)
 {
     try
     {
         string          strReturn = "测试未链接";
         MySqlConnection conn      = new MySqlConnection(strMysqlConn);
         try
         {
             if (conn.State != System.Data.ConnectionState.Open)
             {
                 conn.Open();
             }
         }
         catch (System.Exception ex)
         {
             strReturn = strMysqlConn.ToString() + "连接出错:" + ex.Message.ToString();
             //log.WriteErr("错误 ! " + strReturn, "Main");
             AppLogHelp.WriteLog(LogFileFormate.MES, "TestConnectionFox" + strReturn);
         }
         finally
         {
             if (conn.State == ConnectionState.Open)
             {
                 conn.Close();
                 strReturn = "测试链接成功!";
             }
         }
         AppLogHelp.WriteLog(LogFileFormate.MES, "TestConnectionFox" + strReturn);
         return(strReturn);
     }
     catch (System.Exception ex)
     {
         throw ex;
     }
 }
        public void Stop()
        {
            this.running = false;
                //log.WriteLog("进程关闭开始", ThreadName);
                try
                {
                    while (this.threadProcess != null && (this.threadProcess.ThreadState == System.Threading.ThreadState.Background
                        | this.threadProcess.ThreadState == System.Threading.ThreadState.Running |
                        this.threadProcess.ThreadState == System.Threading.ThreadState.WaitSleepJoin))
                    {
                        Thread.Sleep(300);
                        this.threadProcess.Abort();
                        //log.WriteLog("进程关闭完成", ThreadName);
                        AppLogHelp.WriteLog(LogFileFormate.FOVPCB, "进程关闭完成");

                    }
                }
                catch (Exception exx)
                {
                    //log.WriteLog("进程关闭完成", ThreadName);
                    return;
                }
                //log.WriteLog("进程关闭完成", ThreadName);
                AppLogHelp.WriteLog(LogFileFormate.FOVPCB, ThreadName+"进程关闭完成");
        }
Esempio n. 4
0
        /// <summary>
        ///  连接测试
        /// </summary>
        /// <param name="strMySQLConnect"></param>
        /// <param name="log"></param>
        /// <returns></returns>
        public string TestConnection(string strMySQLConnect)
        {
            try
            {
                string          strReturn = "连接测试成功!";
                MySqlConnection conn      = new MySqlConnection(strMySQLConnect);
                MySqlCommand    cmd       = null;
                try
                {
                    if (conn.State != System.Data.ConnectionState.Open)
                    {
                        conn.Open();
                    }
                    cmd = conn.CreateCommand();
                    // cmd.CommandText = "  SELECT * from tbpadmeasure  LIMIT 1  ";
                    cmd.CommandText = "  SELECT TRIGGER_NAME from  information_schema.TRIGGERS where TRIGGER_NAME ='TBBoard_delete_Before_trigger';   ";
                    object objScalar = cmd.ExecuteScalar();
                    if (objScalar == DBNull.Value || objScalar == null)
                    {
//                        cmd.CommandText = @"create trigger TBBoard_delete_Before_trigger
//                                           BEFORE delete on TBBoard for each row
//                                           begin
//                                             DELETE from TBPadMeasure  where PCBID = old.PCBID;
//                                             DELETE FROM TBBarCode WHERE PCBID = old.PCBID;
//                                           end; ";
//                        cmd.ExecuteNonQuery();
                    }
                    else
                    {
                        //add by peng 20190319 delete trigger ;
                        cmd.CommandText = "DROP TRIGGER TBBoard_delete_Before_trigger ;";
                        cmd.ExecuteScalar();
                    }
                }
                catch (System.Exception ex)
                {
                    strReturn = strMySQLConnect.ToString() + "连接出错:" + ex.Message.ToString();
                    //log.WriteErr("错误 ! " + strReturn, "Main");
                    AppLogHelp.WriteError(LogFileFormate.SQL, "TestConnection " + strReturn);
                }
                finally   // moditied by peng 20190319
                {
                    conn.Close();
                    cmd.Dispose();
                    conn.Dispose();
                }

                //log.WriteLog(strReturn, "Main");
                return(strReturn);
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 5
0
 /// <summary>
 /// 线程开始
 /// </summary>
 /// <param name="dtStart"></param>
 /// <param name="dtEnd"></param>
 /// <param name="log"></param>
 public void AutoStart(DateTime dtStart, DateTime dtEnd, bool blnBackUpData, string strBackFilePath, bool blnDeleteDataEveryHour, int iPCBLimit)
 {
     try
     {
         runnerDeleteData = new ThreadProcess(dtStart, dtEnd, blnBackUpData, strBackFilePath, blnDeleteDataEveryHour, iPCBLimit);
         runnerDeleteData.Run();
     }
     catch (Exception ex)
     {
         AppLogHelp.WriteLog(LogFileFormate.Delete, ThreadName + ex.ToString());
     }
 }
Esempio n. 6
0
        public void CountThreadProc()
        {
            string    strLog = string.Empty;
            bu_Joch   bu     = new bu_Joch();
            DataTable dt     = new DataTable();

            try
            {
                int intRowNo = 0;

                if (this.running == true)
                {
                    dt = bu.GetDataTableFromEXFO(this.strConnectString, this.strDatatableName);

                    strLog = string.Format("GetSPCData开始,{0}", dtStartTime.ToString("yyyy-MM-dd HH:mm:ss") + "~" + dtEndTime.ToString("yyyy-MM-dd HH:mm:ss"));
                    //log.WriteLog(strLog, ThreadName);
                    AppLogHelp.WriteLog(LogFileFormate.MES, ThreadName + strLog);

                    dt = bu.GetSPCDataForEXFO(this.strConnectString, this.strDatatableName, dtStartTime, dtEndTime);
                    if (dt != null)
                    {
                        intRowNo = dt.Rows.Count;
                        strLog   = string.Format("GetSPCData结束,共获取{1}日期之前下的{0}条记录", intRowNo, dtStartTime.ToString("yyyy-MM-dd HH:mm:ss") + "~" + dtEndTime.ToString("yyyy-MM-dd HH:mm:ss"));
                        //log.WriteLog(strLog, ThreadName);
                        AppLogHelp.WriteLog(LogFileFormate.MES, ThreadName + strLog);
                        if (intRowNo > 0)
                        {
                            bu.BulkToDB(this.strConnectString, dt, null);
                            strLog = string.Format("Insert  SPCData结束,共同步{1}日期之前下的{0}条记录", intRowNo, dtStartTime.ToString("yyyy-MM-dd HH:mm:ss") + "~" + dtEndTime.ToString("yyyy-MM-dd HH:mm:ss"));
                            //log.WriteLog(strLog, ThreadName);
                            AppLogHelp.WriteLog(LogFileFormate.MES, ThreadName + strLog);
                        }
                    }
                    else
                    {
                        strLog = "GetSPCData结束, NULL ";
                        //log.WriteLog(strLog, ThreadName);
                        AppLogHelp.WriteLog(LogFileFormate.MES, ThreadName + strLog);
                    }
                }
            }
            catch (Exception ex)
            {
                //log.WriteErr("错误 ! " + ex.ToString(), ThreadName);
                AppLogHelp.WriteLog(LogFileFormate.MES, ThreadName + "错误 ! " + ex.ToString());
            }
            finally
            {
                //log.WriteLog("线程EXFO结束!", ThreadName);
                AppLogHelp.WriteLog(LogFileFormate.MES, ThreadName + strLog);
            }
        }
 public void Run()
 {
     try
     {
         this.running                = true;
         this.threadProcess          = new Thread(new ThreadStart(CountThreadProc));
         this.threadProcess.Priority = ThreadPriority.Normal;
         this.threadProcess.Start();
     }
     catch (Exception ex)
     {
         //log.WriteErr("错误 ! " + ex.ToString(), ThreadName);
         AppLogHelp.WriteError(LogFileFormate.MES, ThreadName + ex.ToString());
     }
 }
Esempio n. 8
0
 public void AutoStart(DateTime dtEndTime, bool blnBackUpData, string strBackFilePath, bool blnDeleteDataEveryHour, int iPCBLimit)
 {
     try
     {
         runnerDeleteData = new ThreadProcess(dtEndTime, blnBackUpData, strBackFilePath, blnDeleteDataEveryHour, iPCBLimit);
         runnerDeleteData.Run();
     }
     catch (Exception ex)
     {
         //log.WriteErr("错误 ! " + ex.ToString(), ThreadName);
         AppLogHelp.WriteError(LogFileFormate.Delete, ThreadName + " 错误 ! :" + ex.ToString());
         // moditied by peng 20190314
         throw ex;
     }
 }
Esempio n. 9
0
        public void Stop()
        {
            this.running = false;


            while (this.threadProcess != null && (this.threadProcess.ThreadState != ThreadState.Aborted ||
                                                  this.threadProcess.ThreadState == System.Threading.ThreadState.Background ||
                                                  this.threadProcess.ThreadState == System.Threading.ThreadState.Running))
            {
                Thread.Sleep(300);
                this.threadProcess.Abort();
            }

            //log.WriteLog("进程关闭完成", ThreadName);
            AppLogHelp.WriteLog(LogFileFormate.MES, ThreadName + " :进程关闭完成");
        }
Esempio n. 10
0
        public int LoadDataFromFile(string strTableName, string strBackUpFile, string strConnect)
        {
            MySqlConnection connMySQL = new MySqlConnection(strConnect);
            MySqlCommand    cmdMySQL  = new MySqlCommand();
            int             intReturn = 0;

            try
            {
                if (File.Exists(strBackUpFile))
                {
                    if (string.IsNullOrEmpty(strTableName))
                    {
                        strTableName = Path.GetFileNameWithoutExtension(strBackUpFile).Split('_')[0];
                    }

                    strBackUpFile = strBackUpFile.Replace("\\", "\\\\");
                    string strSQL = string.Format("LOAD DATA INFILE \"{0}\" INTO TABLE {1} FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY '\n';", strBackUpFile, strTableName);

                    connMySQL.Open();
                    cmdMySQL = connMySQL.CreateCommand();
                    cmdMySQL.CommandTimeout = Properties.Settings.Default.SQLTimeOut;
                    cmdMySQL.CommandText    = strSQL;
                    intReturn += cmdMySQL.ExecuteNonQuery();
                }
            }
            catch (Exception ex)
            {
                //log.WriteErr(strBackUpFile + "Load Data Exception :" + ex.ToString());
                AppLogHelp.WriteError(LogFileFormate.Delete, ThreadName + " " + strBackUpFile + "Load Data Exception :" + ex.ToString());
                //throw ex;
                //return;
                return(-1);
            }
            finally
            {
                if (connMySQL.State == ConnectionState.Open)
                {
                    connMySQL.Close();
                }
                cmdMySQL.Dispose();
            }
            return(intReturn);
        }
Esempio n. 11
0
        public void CountThreadProc()
        {
            string strLog = string.Empty;

            try
            {
                bu_Joch bu       = new bu_Joch();
                int     intRowNo = 0;
                AutoAPP.MainForm._runnerDeleteProcess = this;
                if (this.running == true)
                {
                    intRowNo = bu.DeleteAndBackupDataByDays(dtStartTime, dtEndTime, 2, strConnectString, blnBackupData, strBackFilePath, blnDeleteEveryHour, _iPCBLimit);
                    strLog   = string.Format("删除结束,共删除{1}日期之前下的{0}条记录", intRowNo, dtStartTime.ToString("yyyy-MM-dd HH:mm:ss") + "~" + dtEndTime.ToString("yyyy-MM-dd HH:mm:ss"));
                    if (blnBackupData)
                    {
                        strLog += "\r\n  数据备份目录:" + strBackFilePath;
                    }
                    else
                    {
                        strLog += "\r\n 无数据备份!";
                    }

                    //log.WriteLog(strLog, ThreadName);
                    AppLogHelp.WriteLog(LogFileFormate.Delete, ThreadName + " :" + strLog);
                }
            }
            catch (Exception ex)
            {
                //log.WriteErr("错误 ! " + ex.ToString(), ThreadName);
                AppLogHelp.WriteError(LogFileFormate.Delete, ThreadName + "错误 ! " + ex.ToString());
                return;
            }
            finally
            {
                AppLogHelp.WriteLog(LogFileFormate.Delete, ThreadName + " :结束");
                this.running = false;
            }
        }
Esempio n. 12
0
        public void CountThreadProc()
        {
            string strLog = string.Empty;

            //bu_Peng bu_p = new bu_Peng();
            try
            {
                AutoAPP.MainForm._runnerLuBangTong = this;
                if (this.running == true)
                {
                    BoundCPUX();
                    //bu_Peng.SaveDataForLHfoxNG(strConnectString, strLastPcbPath, strLastPcbFile, strLastAppsettingTmpFile, strAppsettingPath, appSettingHandle, timer, log);
                    bu_Peng bp = new bu_Peng();
                    //bp._configData = _configData;
                    bp.SaveDataLuBangTong(_AtbUSERNO,
                                          _AtbMO,
                                          _AtbITEMVALUE,
                                          _AtbMachineNo,
                                          _AtbOn,
                                          _AtbSf,
                                          _AclientId,
                                          _AclientSecret, _AStatusURL, _AsErrorUrl);
                }
            }
            catch (Exception ex)
            {
                //log.WriteErr("错误 ! " + ex.ToString(), ThreadName);
                //AppLogHelp.WriteLog(LogFileFormate.MES, ThreadName + " :进程关闭完成");
                //throw ex;
            }
            finally
            {
                //log.WriteLog("线程ThreadProcessLuBangTong结束!", ThreadName);
                AppLogHelp.WriteLog(LogFileFormate.MES, ThreadName + " 线程ThreadProcessLuBangTong结束");
            }
        }
Esempio n. 13
0
        private String SaveWholePCBImagePrivate(string strBarcode, string strDateTime, String strJobName,
                                                List <APP_SaveOrLoadImgDataInFo> AFovs,

                                                ref AppSettingData AappSettingData,
                                                ref InspectConfig.ConfigData Aconfig,
                                                DateTime AdtStartTime,
                                                string AstrPerWidthHeight,
                                                Basefunction _baseFuc,
                                                ImgCSCoreIM.ST_SaveOrLoadImgData stSave, string ip
                                                )
        {
            //String strPre = "SaveWholePCBImage:";
            String strMsg = string.Empty;

            try
            {
                if (String.IsNullOrEmpty(_strCurrentJobName) || !String.Equals(_strCurrentJobName, strJobName))
                {
                    _strCurrentJobName          = strJobName;
                    _bHasGetBoardBackGroudColor = false;
                    Array.Clear(_arrBoardBackGroudColor, 0, _arrBoardBackGroudColor.Length);
                }
                strJobName = Path.GetFileNameWithoutExtension(strJobName);
                if (AFovs == null)
                {
                    strMsg = "Fov Img is Null";
                    return(strMsg);
                }


                //if (ABrdRes.jugResult == JudgeRes.Unmeasured)
                //    return (strMsg = ABrdRes.jugResult.ToString());
                int   AiFOVWidth = 0, AiFOVHeight = 0;
                float AfPixelSizeX0um = Aconfig._pixelSizeX0, AfPixelSizeY0um = Aconfig._pixelSizeY0;
                AfPixelSizeX0um = 19.95233f; AfPixelSizeY0um = 19.9552f;
                int index     = 0;
                int iFovCount = AFovs.Count;
                unsafe
                {
                    for (index = 0; index < iFovCount; ++index)
                    {
                        if (AFovs[index].stImgData.byImgDataR == null)
                        {
                            strMsg = "Fov Img is Null";
                            return(strMsg);
                        }
                    }
                }
                String strDayTime = strDateTime;

                string strPath = AappSettingData.stDataExpVT.stSavePCBImageParams.strSaveImagePath;
                if (string.IsNullOrEmpty(strPath) == false)
                {
                    strPath = strPath + "\\" + ip;
                }
                if (_baseFuc.DirCheck(ref strPath) == -1)
                {
                    strMsg = strPath + "Could not be created;";
                    return(strMsg);
                }
                //get board barcode
                String strboardBarcode = strBarcode;
                //    AappSettingData, (byte)ABrdRes.LaneNo);//Q.F.2017.04.13
                String strTime = AdtStartTime.ToString("yyyyMMddHHmmss");
                if (string.Equals(strboardBarcode.ToUpper(), "NOREAD"))
                {
                    strboardBarcode = strTime;
                }
                string strFileName = "";
                if (AappSettingData.stDataExpVT.stSavePCBImageParams.bEnabled == true)
                {
                    switch ((EM_SavePCBImageCustomer)AappSettingData.stDataExpVT.stSavePCBImageParams.Customer)
                    {
                    case EM_SavePCBImageCustomer.HuaWei:
                    {
                        if (!string.IsNullOrEmpty(AappSettingData.stDataExpVT.stSavePCBImageParams.TaskOrder))
                        {
                            strPath = Path.Combine(strPath, AappSettingData.stDataExpVT.stSavePCBImageParams.TaskOrder);
                            if (_baseFuc.DirCheck(ref strPath) == -1)
                            {
                                strMsg = strPath + "Could not be created;";
                                return(strMsg);
                            }
                            //strPath = Path.Combine(strPath, strboardBarcode);
                            //if (_baseFuc.DirCheck(ref strPath) == -1)
                            //{
                            //    strMsg = strPath + "Could not be created;";
                            //    return strMsg;
                            //}
                        }
                        else
                        {
                            strPath = Path.Combine(strPath, strDayTime);
                            if (_baseFuc.DirCheck(ref strPath) == -1)
                            {
                                strMsg = strPath + "Could not be created;";
                                return(strMsg);
                            }
                        }
                        strFileName = strboardBarcode + PubStaticParam.RS_UnderLineSplit + strTime + PubStaticParam.RS_UnderLineSplit + strJobName;
                        strFileName = Path.Combine(strPath, strFileName);
                        break;
                    }

                    case EM_SavePCBImageCustomer.JobBarcodePerDay:
                    {
                        strPath = Path.Combine(strPath, strDayTime);
                        if (_baseFuc.DirCheck(ref strPath) == -1)
                        {
                            strMsg = strPath + "Could not be created;";
                            return(strMsg);
                        }
                        strFileName = Path.Combine(strPath, strJobName + PubStaticParam.RS_UnderLineSplit + strboardBarcode + PubStaticParam.RS_UnderLineSplit + strTime);
                        break;
                    }

                    default:
                    {
                        break;
                    }
                    }
                }
                AiFOVWidth  = AFovs[0].stImgData.iWidth;
                AiFOVHeight = AFovs[0].stImgData.iHeight;
                int intRange     = (int)(iFovCount / _iProcessorCount) + 1;
                int lImageLength = AiFOVWidth * AiFOVHeight;
                ImgCSCoreIM.ColorFactorParams stColorFactors = AappSettingData.stColorFactorParams;

                //cal Hue for backgroud
                int hue = 0, saturation = 0, value = 0;

                Color rgb = Color.Black;
                //cal larger image size
                int WholeImageWidth = 0, WholeImageHeight = 0;

                double MinXMM = AFovs[0].fPosXmm;
                double MaxXMM = AFovs[0].fPosXmm;
                double MinYMM = AFovs[0].fPosYmm;
                double MaxYMM = AFovs[0].fPosYmm;

                for (index = 1; index < iFovCount; ++index)
                {
                    if (MinXMM > AFovs[index].fPosXmm)//correctedXmm
                    {
                        MinXMM = AFovs[index].fPosXmm;
                    }
                    if (MaxXMM < AFovs[index].fPosXmm)
                    {
                        MaxXMM = AFovs[index].fPosXmm;
                    }
                    if (MinYMM > AFovs[index].fPosYmm)//correctedYmm
                    {
                        MinYMM = AFovs[index].fPosYmm;
                    }
                    if (MaxYMM < AFovs[index].fPosYmm)
                    {
                        MaxYMM = AFovs[index].fPosYmm;
                    }
                }
                WholeImageWidth   = (int)Math.Ceiling((MaxXMM - MinXMM) * F_MM2UM / AfPixelSizeX0um);
                WholeImageHeight  = (int)Math.Ceiling((MaxYMM - MinYMM) * F_MM2UM / AfPixelSizeY0um);
                WholeImageWidth  += AiFOVWidth;
                WholeImageHeight += AiFOVHeight;
                int lLength = WholeImageWidth * WholeImageHeight;
                if (_imgByte2DR == null || _imgByte2DR.Length != lLength)
                {
                    _imgByte2DR = new byte[lLength];
                    _imgByte2DG = new byte[lLength];
                    _imgByte2DB = new byte[lLength];
                }
                Array.Clear(_imgByte2DR, 0, lLength);
                Array.Clear(_imgByte2DG, 0, lLength);
                Array.Clear(_imgByte2DB, 0, lLength);


                if (_imgByte2DRFov == null || _imgByte2DRFov.Length != lLength)
                {
                    _imgByte2DRFov = new byte[lImageLength];
                    _imgByte2DGFov = new byte[lImageLength];
                    _imgByte2DBFov = new byte[lImageLength];
                }
                Array.Clear(_imgByte2DRFov, 0, lImageLength);
                Array.Clear(_imgByte2DGFov, 0, lImageLength);
                Array.Clear(_imgByte2DBFov, 0, lImageLength);


                float  fFovWMM = AiFOVWidth * AfPixelSizeX0um * 0.001f;
                float  fFovHMM = AiFOVHeight * AfPixelSizeY0um * 0.001f;
                double LeftXMM = MinXMM; // -fFovWMM * 0.5;
                double LeftYMM = MinYMM; // -fFovHMM * 0.5;
                //for (index = 0; index < lLength; ++index)
                //{
                //    _imgByte2DG[index] = rgb.G;
                //    _imgByte2DB[index] = rgb.B;
                //    _imgByte2DB[index] = rgb.R;
                //}
                int   i = 0, j = 0;
                float fFactor    = 1.0f;
                short shColorPer = 0;
                //Parallel.ForEach(Partitioner.Create(0, iFovCount, intRange), range =>
                //{
                //for (int a = range.Item1; a < range.Item2; ++a)
                for (index = 0; index < iFovCount; ++index)
                {
                    unsafe
                    {
                        // recal rgb value
                        if (stColorFactors.byRGB2DFactorR != 100)
                        {
                            shColorPer = (short)(stColorFactors.byRGB2DFactorR * 1.28);
                            for (i = 0; i < lImageLength; ++i)
                            {
                                _imgByte2DRFov[i] = (byte)((AFovs[index].stImgData.byImgDataR[i] * shColorPer) >> 7);
                            }
                        }
                        else
                        {
                            Array.Copy(AFovs[index].stImgData.byImgDataR, _imgByte2DRFov, lImageLength);
                        }
                        if (stColorFactors.byRGB2DFactorG != 100)
                        {
                            //fFactor = stColorFactors.byRGB2DFactorR * 0.01f;
                            shColorPer = (short)(stColorFactors.byRGB2DFactorG * 1.28);
                            for (i = 0; i < lImageLength; ++i)
                            {
                                // _imgByte2DRFov[i] = (byte)(AFovs[a]._rgbImg[0][i] * fFactor);
                                _imgByte2DGFov[i] = (byte)((AFovs[index].stImgData.byImgDataG[i] * shColorPer) >> 7);
                            }
                        }
                        else
                        {
                            Array.Copy(AFovs[index].stImgData.byImgDataG, _imgByte2DGFov, lImageLength);
                        }
                        if (stColorFactors.byRGB2DFactorB != 100)
                        {
                            //fFactor = stColorFactors.byRGB2DFactorR * 0.01f;
                            shColorPer = (short)(stColorFactors.byRGB2DFactorB * 1.28);
                            for (i = 0; i < lImageLength; ++i)
                            {
                                // _imgByte2DRFov[i] = (byte)(AFovs[a]._rgbImg[0][i] * fFactor);
                                _imgByte2DBFov[i] = (byte)((AFovs[index].stImgData.byImgDataB[i] * shColorPer) >> 7);
                            }
                        }
                        else
                        {
                            Array.Copy(AFovs[index].stImgData.byImgDataB, _imgByte2DBFov, lImageLength);
                        }
                    }
                    int iShiftX = (int)Math.Ceiling((AFovs[index].fPosXmm - LeftXMM) / AfPixelSizeX0um * F_MM2UM);
                    int iShiftY = (int)Math.Ceiling((AFovs[index].fPosYmm - LeftYMM) / AfPixelSizeY0um * F_MM2UM);//Q.F.2018.01.04
                    int iStartX = 0;
                    int iStartY = 0;
                    if (iShiftX < 0)
                    {
                        iStartX = 0 - iShiftX;
                    }
                    if (iShiftY < 0)
                    {
                        iStartY = 0 - iShiftY;
                    }
                    for (i = iStartY; i < AiFOVHeight; ++i)
                    {
                        Array.Copy(_imgByte2DRFov, i * AiFOVWidth + iStartX,
                                   _imgByte2DR, (i + iShiftY) * WholeImageWidth + (0 + iShiftX),
                                   AiFOVWidth - iStartX);
                        Array.Copy(_imgByte2DGFov, i * AiFOVWidth + iStartX,
                                   _imgByte2DG, (i + iShiftY) * WholeImageWidth + (0 + iShiftX),
                                   AiFOVWidth - iStartX);
                        Array.Copy(_imgByte2DBFov, i * AiFOVWidth + iStartX,
                                   _imgByte2DB, (i + iShiftY) * WholeImageWidth + (0 + iShiftX),
                                   AiFOVWidth - iStartX);
                    }
                }
                //});

                Rectangle rect         = new Rectangle(0, 0, WholeImageWidth, WholeImageHeight);
                int       iWidthNew    = 0;
                int       iHeightNew   = 0;
                bool      bAdjustWIdth = false;
                AappSettingData.stDataExpVT.stSavePCBImageParams.byImageAdjustPercent = 30;

                if (AappSettingData.stDataExpVT.stSavePCBImageParams.byImageAdjustPercent < 100)
                {
                    bAdjustWIdth = true;
                    iWidthNew    = (int)System.Math.Ceiling(WholeImageWidth * AappSettingData.stDataExpVT.stSavePCBImageParams.byImageAdjustPercent * 0.01);
                    iHeightNew   = (int)System.Math.Ceiling(WholeImageHeight * AappSettingData.stDataExpVT.stSavePCBImageParams.byImageAdjustPercent * 0.01);
                }
                //else
                //{
                //    bAdjustWIdth = true;
                //    iWidthNew = int.Parse(AstrPerWidthHeight.Split('@')[0]);
                //    iHeightNew = int.Parse(AstrPerWidthHeight.Split('@')[1]);
                //}
                //if (string.IsNullOrEmpty(AstrPerWidthHeight) == false)
                //{
                //    bAdjustWIdth = true;
                //    iWidthNew = int.Parse(AstrPerWidthHeight.Split('@')[0]);
                //    iHeightNew = int.Parse(AstrPerWidthHeight.Split('@')[1]);
                //}
                //Q.F.2018.08.29
                AappSettingData.stDataExpVT.stSavePCBImageParams.bFillBlack = true;
                if (AappSettingData.stDataExpVT.stSavePCBImageParams.bFillBlack == true &&
                    _bHasGetBoardBackGroudColor == false)
                {
                    Array.Clear(_fParams, 0, _fParams.Length);
                    _fParams[0] = WholeImageWidth;
                    _fParams[1] = WholeImageHeight;
                    _bHasGetBoardBackGroudColor = true;
                    CvFunction.GetPcbBcgrdColor(_imgByte2DR, _imgByte2DG, _imgByte2DB, _fParams, _arrBoardBackGroudColor);
                }
                int iSaveImageMode = 1;
                //strboardBarcode = Path.GetFileNameWithoutExtension(strJobName) + "_" + strboardBarcode + "_" + strTime;
                // string strFileName = "";//Path.Combine(strPath, strboardBarcode);
                switch ((ImgCSCoreIM.EM_ImageFormat)AappSettingData.stDataExpVT.stSavePCBImageParams.ImageFormat)
                {
                case EM_ImageFormat.bmp:
                {
                    strFileName   += ".bmp";
                    iSaveImageMode = 2;
                    //resultBitMap.Save(strFileName, System.Drawing.Imaging.ImageFormat.Jpeg);
                    break;
                }

                default:
                {
                    strFileName += ".jpg";
                    if (iSaveImageMode >= 2)
                    {
                        iSaveImageMode = 1;
                    }
                    //resultBitMap.Save(strFileName, System.Drawing.Imaging.ImageFormat.Jpeg);
                    break;
                }
                }
                Bitmap resultBitMap = null;
                //Stopwatch stopWatch = new Stopwatch();
                //stopWatch.Reset();
                //stopWatch.Start();

                if (bAdjustWIdth == false)
                {
                    if (AappSettingData.stDataExpVT.stSavePCBImageParams.bFillBlack == true)
                    {
                        Array.Clear(_fParams, 0, _fParams.Length);
                        _fParams[0] = WholeImageWidth;
                        _fParams[1] = WholeImageHeight;
                        _fParams[2] = _arrBoardBackGroudColor[0];
                        _fParams[3] = _arrBoardBackGroudColor[1];
                        _fParams[4] = _arrBoardBackGroudColor[2];
                        _fParams[5] = 1;
                        byte[] imgByte2DTmp = new byte[_imgByte2DB.Length];
                        CvFunction.FillPcbBlackHole(_imgByte2DR, _imgByte2DG, _imgByte2DB,
                                                    _fParams, _imgByte2DR, _imgByte2DG, _imgByte2DB);
                    }

                    switch (iSaveImageMode)
                    {
                    case 0:
                    {
                        unsafe
                        {
                            resultBitMap = new Bitmap(WholeImageWidth, WholeImageHeight, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                            System.Drawing.Imaging.BitmapData bmpData = resultBitMap.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite, resultBitMap.PixelFormat);
                            IntPtr iPtr = bmpData.Scan0;
                            int    iStride = bmpData.Stride;
                            int    iBytes = iStride * WholeImageHeight;
                            byte[] PixelValues = new byte[iBytes];
                            int    iPoint = 0;
                            int    offSet = iStride - WholeImageWidth * 3;
                            byte   byG = 0, byB = 0, byR = 0;
                            //for (i = 0; i < WholeImageHeight; ++i)
                            //{
                            //    for (j = 0; j < WholeImageWidth; ++j)
                            //    {
                            for (index = 0; index < lLength; ++index)
                            {
                                //index = i * WholeImageWidth + j;


                                byG = _imgByte2DG[index];
                                byB = _imgByte2DB[index];
                                byR = _imgByte2DR[index];


                                PixelValues[iPoint++] = byB;
                                PixelValues[iPoint++] = byG;
                                PixelValues[iPoint++] = byR;
                                // }

                                // iPoint += 3;
                                iPoint += offSet;
                            }
                            //
                            System.Runtime.InteropServices.Marshal.Copy(PixelValues, 0, iPtr, iBytes);
                            resultBitMap.UnlockBits(bmpData);
                            resultBitMap.Save(strFileName, System.Drawing.Imaging.ImageFormat.Jpeg);
                        }
                        break;
                    }

                    case 1:
                    {
                        //ImgCSCoreIM.ST_SaveOrLoadImgData stSave = new ImgCSCoreIM.ST_SaveOrLoadImgData();
                        stSave.iImgFormat = 1;
                        stSave.bUseOpcv   = false;
                        stSave.byImgDataR = _imgByte2DR;
                        stSave.byImgDataG = _imgByte2DG;
                        stSave.byImgDataB = _imgByte2DB;
                        stSave.iWidth     = WholeImageWidth;
                        stSave.iHeight    = WholeImageHeight;
                        _baseFuc.SaveImg(strFileName, stSave, 80);

                        stSave.byImgDataR = null;
                        stSave.byImgDataG = null;
                        stSave.byImgDataB = null;
                        break;
                    }

                    case 2:
                    {
                        //ImgCSCoreIM.ST_SaveOrLoadImgData stSave = new ImgCSCoreIM.ST_SaveOrLoadImgData();
                        stSave.iImgFormat = 0;
                        stSave.bUseOpcv   = true;
                        stSave.byImgDataR = _imgByte2DR;
                        stSave.byImgDataG = _imgByte2DG;
                        stSave.byImgDataB = _imgByte2DB;
                        stSave.iWidth     = WholeImageWidth;
                        stSave.iHeight    = WholeImageHeight;
                        _baseFuc.SaveImg(strFileName, stSave, 100);

                        stSave.byImgDataR = null;
                        stSave.byImgDataG = null;
                        stSave.byImgDataB = null;
                        break;
                    }

                    default:
                    {
                        break;
                    }
                    }
                }
                else
                {
                    unsafe
                    {
                        int lImageLengthNew = iWidthNew * iHeightNew;

                        if (_imgByte2DRReSize == null || _imgByte2DRReSize.Length != lImageLengthNew)
                        {
                            _imgByte2DRReSize = new byte[lImageLengthNew];
                            _imgByte2DGReSize = new byte[lImageLengthNew];
                            _imgByte2DBReSize = new byte[lImageLengthNew];
                        }
                        Array.Clear(_imgByte2DRReSize, 0, lImageLengthNew);
                        Array.Clear(_imgByte2DGReSize, 0, lImageLengthNew);
                        Array.Clear(_imgByte2DBReSize, 0, lImageLengthNew);


                        //_imgBi[0].RGBImageScale(_imgByte2DB,
                        //             _imgByte2DG,
                        //             _imgByte2DB,
                        //             WholeImageWidth, WholeImageHeight,
                        //             r, g, b, iWidthNew, iHeightNew);
                        Array.Clear(_fParams, 0, _fParams.Length);
                        _fParams[0] = WholeImageWidth;
                        _fParams[1] = WholeImageHeight;
                        _fParams[2] = iWidthNew;
                        _fParams[3] = iHeightNew;
                        _fParams[4] = 0;
                        _baseFuc.ResizeImgByOpcv(_imgByte2DR,
                                                 _imgByte2DG,
                                                 _imgByte2DB,
                                                 _imgByte2DRReSize, _imgByte2DGReSize, _imgByte2DBReSize, _fParams);

                        AappSettingData.stDataExpVT.stSavePCBImageParams.bFillBlack = true;
                        if (AappSettingData.stDataExpVT.stSavePCBImageParams.bFillBlack == true)
                        {
                            Array.Clear(_fParams, 0, _fParams.Length);
                            _fParams[0] = iWidthNew;
                            _fParams[1] = iHeightNew;
                            _fParams[2] = _arrBoardBackGroudColor[0];
                            _fParams[3] = _arrBoardBackGroudColor[1];
                            _fParams[4] = _arrBoardBackGroudColor[2];
                            _fParams[5] = 1;
                            //byte[] imgByte2DTmp = new byte[r.Length];
                            CvFunction.FillPcbBlackHole(_imgByte2DRReSize, _imgByte2DGReSize, _imgByte2DBReSize,
                                                        _fParams, _imgByte2DRReSize, _imgByte2DGReSize, _imgByte2DBReSize);
                        }

                        rect = new Rectangle(0, 0, iWidthNew, iHeightNew);


                        switch (iSaveImageMode)
                        {
                        case 0:
                        {
                            unsafe
                            {
                                resultBitMap = new Bitmap(iWidthNew, iHeightNew, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                                //Rectangle rect = new Rectangle(0, 0, AiFOVWidth, AiFOVHeight);
                                // Rectangle rect = new Rectangle(0, 0, WholeImageWidth, WholeImageHeight);
                                System.Drawing.Imaging.BitmapData bmpData = resultBitMap.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite, resultBitMap.PixelFormat);
                                IntPtr iPtr = bmpData.Scan0;
                                int    iStride = bmpData.Stride;
                                int    iBytes = iStride * iHeightNew;
                                byte[] PixelValues = new byte[iBytes];
                                int    iPoint = 0;
                                int    offSet = iStride - iWidthNew * 3;
                                byte   byG = 0, byB = 0, byR = 0;

                                for (i = 0; i < iHeightNew; ++i)
                                {
                                    for (j = 0; j < iWidthNew; ++j)
                                    {
                                        index = i * iWidthNew + j;
                                        byG   = _imgByte2DGReSize[index];
                                        byB   = _imgByte2DBReSize[index];
                                        byR   = _imgByte2DRReSize[index];


                                        PixelValues[iPoint++] = byB;
                                        PixelValues[iPoint++] = byG;
                                        PixelValues[iPoint++] = byR;
                                    }

                                    // iPoint += 3;
                                    iPoint += offSet;
                                }
                                //
                                System.Runtime.InteropServices.Marshal.Copy(PixelValues, 0, iPtr, iBytes);
                                resultBitMap.UnlockBits(bmpData);
                                resultBitMap.Save(strFileName, System.Drawing.Imaging.ImageFormat.Jpeg);

                                PixelValues = null;
                            }
                            break;
                        }

                        case 1:
                        {
                            //ImgCSCoreIM.ST_SaveOrLoadImgData stSave = new ImgCSCoreIM.ST_SaveOrLoadImgData();
                            stSave.iImgFormat = 1;
                            stSave.bUseOpcv   = false;
                            stSave.byImgDataR = _imgByte2DRReSize;
                            stSave.byImgDataG = _imgByte2DGReSize;
                            stSave.byImgDataB = _imgByte2DBReSize;
                            stSave.iWidth     = iWidthNew;
                            stSave.iHeight    = iHeightNew;
                            _baseFuc.SaveImg(strFileName, stSave, 80);

                            stSave.byImgDataR = null;
                            stSave.byImgDataG = null;
                            stSave.byImgDataB = null;
                            break;
                        }

                        case 2:
                        {
                            //ImgCSCoreIM.ST_SaveOrLoadImgData stSave = new ImgCSCoreIM.ST_SaveOrLoadImgData();
                            stSave.iImgFormat = 0;
                            stSave.bUseOpcv   = true;
                            stSave.byImgDataR = _imgByte2DRReSize;
                            stSave.byImgDataG = _imgByte2DGReSize;
                            stSave.byImgDataB = _imgByte2DBReSize;
                            stSave.iWidth     = iWidthNew;
                            stSave.iHeight    = iHeightNew;
                            _baseFuc.SaveImg(strFileName, stSave, 100);

                            stSave.byImgDataR = null;
                            stSave.byImgDataG = null;
                            stSave.byImgDataB = null;

                            break;
                        }

                        default:
                        {
                            break;
                        }
                        }



                        //strboardBarcode = Path.GetFileNameWithoutExtension(strJobName) + "_" + strboardBarcode + "_" + strTime;
                        //string strFileName = Path.Combine(strPath, strboardBarcode);
                        //switch ((ImgCSCoreIM.EM_ImageFormat)AappSettingData.stDataExpVT.stSavePCBImageParams.ImageFormat)
                        //{
                        //    default:
                        //        {
                        //            strFileName += ".jpg";
                        //            resultBitMap.Save(strFileName, System.Drawing.Imaging.ImageFormat.Jpeg);
                        //            break;
                        //        }
                        //}
                    }
                }
                if (resultBitMap != null)
                {
                    resultBitMap.Dispose();
                }

                //stopWatch.Stop();
                //MessageBox.Show("iSaveImageMode:" + iSaveImageMode + "\t" + stopWatch.ElapsedMilliseconds);
            }
            catch (System.Exception ex)
            {
                //MessageBox.Show(ex.ToString());
                strMsg += ex.ToString();
                AppLogHelp.WriteError(LogFileFormate.FOVPCB, "SaveWholePCBImagePrivate " + strMsg);
            }
            finally
            {
                //_arrBoardBackGroudColor = null;

                _imgByte2DR = null;
                _imgByte2DG = null;
                _imgByte2DB = null;

                _imgByte2DRFov = null;
                _imgByte2DGFov = null;
                _imgByte2DBFov = null;

                _imgByte2DRReSize = null;
                _imgByte2DGReSize = null;
                _imgByte2DBReSize = null;
                GC.Collect();
            }

            return(strMsg);
        }
Esempio n. 14
0
        /// <summary>
        /// 删除intDays天前的数据 不删除job信息.
        ///  删除表TBBoard和TBPadMeasure和TbRealTimeResources三个表数据.
        /// </summary>
        /// <param name="stSPCDeleteData"></param>
        /// <returns></returns>
        public int DeleteAndBackupDataByDays(DateTime dtStartTime, DateTime dtEndTime, int intSPCDataBaseType, string strConnect, bool blnBackUpData, string strBackFilePath, bool blnDeleteDataEveryHour, int iPCBLimit)
        {
            MySqlConnection  connMySQL = new MySqlConnection(strConnect);
            MySqlCommand     cmdMySQL  = new MySqlCommand();
            MySqlTransaction tranMySQL;
            MySqlDataAdapter daptMySQL = new MySqlDataAdapter();
            DataTable        dtReturn  = new DataTable();

            int    intReturn = 0;
            string strBackUpPadMeasureSQL = string.Empty;
            string strBackUpBoardSQL      = string.Empty;
            string strBackUpBarcodeSQL    = string.Empty;
            //string strBackUpRealTimeResourcesSQL = string.Empty;
            string strBackUpFile = string.Empty;
            string strPCBID      = string.Empty;

            string strDeletePadMeasureSQL = string.Empty;
            string strDeleteBoardSQL      = string.Empty;
            string strDeleteBarcodeSQL    = string.Empty;

            // string strDeleteRealTimeResourcesSQL = string.Empty;

            try
            {
                switch (intSPCDataBaseType)
                {
                case 2:
                {
                    string strSelectPCBID = string.Empty;

                    if (blnDeleteDataEveryHour)
                    {
                        int iDeletePCBLimtCount = iPCBLimit;
                        if (iDeletePCBLimtCount > 0)
                        {
                            strSelectPCBID = " SELECT   PCBID  FROM spidb.TBBoard WHERE StartTime >= '" + dtStartTime.ToString(RS_FORMAT_DATETIME) + "'  and StartTime <= '" + dtEndTime.ToString(RS_FORMAT_DATETIME) + "' Limit " + iDeletePCBLimtCount + ";";
                        }
                        else
                        {
                            strSelectPCBID = " SELECT   PCBID  FROM spidb.TBBoard WHERE StartTime >= '" + dtStartTime.ToString(RS_FORMAT_DATETIME) + "'  and StartTime <= '" + dtEndTime.ToString(RS_FORMAT_DATETIME) + "' Limit 100 ;";
                        }
                    }
                    else
                    {
                        strSelectPCBID = " SELECT   PCBID  FROM spidb.TBBoard WHERE StartTime >= '" + dtStartTime.ToString(RS_FORMAT_DATETIME) + "'  and StartTime <= '" + dtEndTime.ToString(RS_FORMAT_DATETIME) + "';";
                    }

                    if (connMySQL.State != ConnectionState.Open)
                    {
                        //log.WriteLog("select pcb 打开..","查询PCB");
                        connMySQL.Open();
                    }
                    cmdMySQL = connMySQL.CreateCommand();
                    cmdMySQL.CommandTimeout = Properties.Settings.Default.SQLTimeOut;
                    cmdMySQL.CommandText    = strSelectPCBID;
                    daptMySQL.SelectCommand = cmdMySQL;
                    daptMySQL.Fill(dtReturn);

                    //if (connMySQL.State == ConnectionState.Open)    //moditied by peng 20190314
                    //{
                    //    connMySQL.Close();
                    //    log.WriteLog("select pcb 关闭..", "查询PCB");
                    //}
                    //cmdMySQL.Dispose();
                    //daptMySQL.Dispose();
                    foreach (DataRow dr in dtReturn.Rows)
                    {
                        int iPCBCount = 0;
                        //  strPCBID += dr[0].ToString() + ",";
                        strPCBID = dr[0].ToString() + ",";
                        //   }
                        if (strPCBID.Length > 1)
                        {
                            strPCBID = strPCBID.Remove(strPCBID.Length - 1, 1);

                            strDeletePadMeasureSQL = string.Format("DELETE FROM spidb.TBPadMeasure WHERE PCBID = '{0}';  ", strPCBID);

                            strDeleteBarcodeSQL = string.Format("DELETE FROM spidb.TBBarCode  WHERE PCBID = '{0}';  ", strPCBID);

                            strDeleteBoardSQL = string.Format(" DELETE FROM	 spidb.TBBoard  WHERE PCBID = '{0}';  ", strPCBID);
                        }

                        if (blnBackUpData)
                        {
                            strBackUpPadMeasureSQL = " SELECT `PCBID`, `PadID`, `LineNo`, `JobIndex`, `PadIndex`, `ABSHeight`, `ABSArea`, `ABSVolume`, `ShiftX`, `ShiftY`, `PerHeight`, `PerArea`, `PerVolume`, `ABSShape`, `BridgeType`, `DefectType`, `JudgeRes`, `BaseType`, `ArrayIDIndex`, `PadArea`  into OUTFILE '{1}' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY '\n' from spidb.TBPadMeasure   where PCBID in ({0}) ;";

                            if (!Directory.Exists(strBackFilePath))
                            {
                                Directory.CreateDirectory(strBackFilePath);
                            }

                            strBackUpFile = Path.Combine(strBackFilePath, "TBPadMeasure" + "_" + strPCBID + "_" + DateTime.Now.ToString(RS_Format_DateTimeFileName) + ".backup");

                            if (File.Exists(strBackUpFile))
                            {
                                strBackUpFile = Path.Combine(strBackFilePath, "TBPadMeasure" + "_" + strPCBID + "_" + DateTime.Now.AddSeconds(1).ToString(RS_Format_DateTimeFileName) + ".backup");
                            }

                            strBackUpFile = strBackUpFile.Replace("\\", "\\\\");
                            //log.WriteLog("TBPadMeasure备份文件:" + strBackUpFile, ThreadName);
                            AppLogHelp.WriteLog(LogFileFormate.Delete, ThreadName + " TBPadMeasure备份文件:" + strBackUpFile);
                            strBackUpPadMeasureSQL = string.Format(strBackUpPadMeasureSQL, strPCBID, strBackUpFile);

                            strBackUpBoardSQL = " SELECT* into OUTFILE '{1}' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY '\n' from TBBoard  where PCBID in ({0}) ; ";

                            strBackUpFile = Path.Combine(strBackFilePath, "TBBoard" + "_" + strPCBID + "_" + DateTime.Now.ToString(RS_Format_DateTimeFileName) + ".backup");

                            if (File.Exists(strBackUpFile))
                            {
                                strBackUpFile = Path.Combine(strBackFilePath, "TBBoard" + "_" + strPCBID + "_" + DateTime.Now.AddSeconds(1).ToString(RS_Format_DateTimeFileName) + ".backup");
                            }
                            strBackUpFile = strBackUpFile.Replace("\\", "\\\\");
                            //log.WriteLog("TBBoard备份文件:" + strBackUpFile, ThreadName);
                            AppLogHelp.WriteLog(LogFileFormate.Delete, ThreadName + " TBPadMeasure备份文件:" + strBackUpFile);
                            strBackUpBoardSQL = string.Format(strBackUpBoardSQL, strPCBID, strBackUpFile);

                            strBackUpBarcodeSQL = " SELECT * into OUTFILE '{1}' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY '\n' from TBBarCode  where PCBID in ({0}) ;";
                            strBackUpFile       = Path.Combine(strBackFilePath, "TBBarCode" + "_" + strPCBID + "_" + DateTime.Now.ToString(RS_Format_DateTimeFileName) + ".backup");

                            if (File.Exists(strBackUpFile))
                            {
                                strBackUpFile = Path.Combine(strBackFilePath, "TBBarCode" + "_" + strPCBID + "_" + DateTime.Now.AddSeconds(1).ToString(RS_Format_DateTimeFileName) + ".backup");
                            }
                            strBackUpFile = strBackUpFile.Replace("\\", "\\\\");
                            //log.WriteLog("TBBarCode备份文件:" + strBackUpFile, ThreadName);
                            AppLogHelp.WriteLog(LogFileFormate.Delete, ThreadName + " " + "TBBarCode备份文件:" + strBackUpFile);

                            strBackUpBarcodeSQL = string.Format(strBackUpBarcodeSQL, strPCBID, strBackUpFile);
                        }

                        if (connMySQL.State != ConnectionState.Open)
                        {
                            connMySQL.Open();
                        }
                        tranMySQL               = connMySQL.BeginTransaction();
                        cmdMySQL                = connMySQL.CreateCommand();
                        cmdMySQL.Transaction    = tranMySQL;
                        cmdMySQL.CommandTimeout = 0;
                        try
                        {
                            //cmdMySQL.CommandText += " START TRANSACTION;";
                            cmdMySQL.CommandText += strBackUpBoardSQL;
                            cmdMySQL.CommandText += strBackUpBarcodeSQL;
                            cmdMySQL.CommandText += strBackUpPadMeasureSQL;
                            // cmdMySQL.CommandText += strBackUpRealTimeResourcesSQL;

                            //cmdMySQL.CommandText = strDeleteSimplePadSQL;
                            //intReturn += cmdMySQL.ExecuteNonQuery();
                            cmdMySQL.CommandText = strDeleteBoardSQL;
                            iPCBCount            = cmdMySQL.ExecuteNonQuery();
                            cmdMySQL.CommandText = strDeleteBarcodeSQL;
                            cmdMySQL.ExecuteNonQuery();
                            cmdMySQL.CommandText = strDeletePadMeasureSQL;
                            cmdMySQL.ExecuteNonQuery();
                            //intReturn += cmdMySQL.ExecuteNonQuery();
                            //intReturn += cmdMySQL.ExecuteNonQuery();
                            //cmdMySQL.CommandText += strDeleteRealTimeResourcesSQL;
                            //cmdMySQL.CommandText += " COMMIT;";

                            //log.WriteLog(strDeleteBoardSQL + strDeleteBarcodeSQL+strDeletePadMeasureSQL, ThreadName);
                            AppLogHelp.WriteLog(LogFileFormate.Delete, ThreadName + " " + strDeleteBoardSQL + strDeleteBarcodeSQL + strDeletePadMeasureSQL);
                            //if (connMySQL.State != ConnectionState.Open)
                            //{
                            //    connMySQL.Open();
                            //    //log.WriteLog("del pcb 打开..pcbid:" + strPCBID, "del PCB");
                            //}
                            //intReturn += cmdMySQL.ExecuteNonQuery();
                            tranMySQL.Commit();
                            //  "START TRANSACTION;" + SQL + "COMMIT;";
                        }
                        catch (Exception ex)
                        {
                            //intReturn = -1;
                            //   if (connMySQL.State != ConnectionState.Open)k
                            //   {
                            //       connMySQL.Open();
                            //   }
                            ////   tranMySQL.Rollback();

                            connMySQL.Close();
                            cmdMySQL.Dispose();
                            tranMySQL.Dispose();
                            // log.WriteErr("错误 ! " + ex.ToString(), ThreadName);
                            AppLogHelp.WriteLog(LogFileFormate.Delete, ThreadName + "错误 ! " + ex.ToString());

                            return(-1);
                        }
                        finally
                        {
                            //if (connMySQL.State == ConnectionState.Open)
                            //{//moditied by peng 20190314
                            connMySQL.Close();
                            cmdMySQL.Dispose();
                            tranMySQL.Dispose();
                            // }

                            //log.WriteLog("删除了" + strPCBID + "下的(" + iPCBCount.ToString() + ")条记录!");
                            AppLogHelp.WriteLog(LogFileFormate.Delete, "删除了" + strPCBID + "下的(" + iPCBCount.ToString() + ")条记录!");
                            intReturn += iPCBCount;
                            //   tranMySQL.Dispose();
                        }
                        //log.WriteLog("Sleep(2000)");
                        System.Threading.Thread.Sleep(2000);
                    }
                    break;
                }

                default:
                    break;
                }
                return(intReturn);
            }
            catch (Exception ex)
            {
                connMySQL.Close();
                cmdMySQL.Dispose();
                //log.WriteErr("错误 ! " + ex.ToString(), ThreadName);
                AppLogHelp.WriteError(LogFileFormate.Delete, ThreadName + " " + "错误 ! " + ex.ToString());

                return(-1);
            }
            finally
            {
                //daptMySQL.Dispose();
                //if (connMySQL.State == ConnectionState.Open) //moditied by peng 20190314
                //{
                connMySQL.Close();
                //}
                cmdMySQL.Dispose();
                daptMySQL.Dispose();
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
        }