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 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结束!"); } }
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+"进程关闭完成"); }
/// <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()); } }
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 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 + " :进程关闭完成"); }
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; } }
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结束"); } }
/// <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(); } }