public cSaveDataToSQL() { TmpResult = new cNetResult(); Load(); new Thread(() => FlushDataToRemot()) { IsBackground = true }.Start(); }
private cNetResult GetNetResult(string McgsSendStr) { cNetResult netResult = new cNetResult(); string[] tempStr = McgsSendStr.Split('~'); //0:"D",1:"OK",2:TestTime,3:ThisNo,4:StepId......... netResult.RunResult.mTestTime = DateTime.Parse(tempStr[2]); // netResult.RunResult.mTestNo = Num.IntParse(tempStr[3]); // netResult.RunResult.mStepId = Num.IntParse(tempStr[4]); netResult.RunResult.mStep = tempStr[5]; netResult.RunResult.mMode = tempStr[6]; // netResult.RunResult.mJiQi = Num.IntParse(tempStr[7]); // netResult.RunResult.mIsPass = bool.Parse(tempStr[8]); // netResult.RunResult.mId = tempStr[9]; // netResult.RunResult.mBar = tempStr[10]; // for (int i = 0; i < cMain.DataShow; i++) { netResult.StepResult.mData[i] = Num.DoubleParse(tempStr[11 + i * 2]); // netResult.StepResult.mIsDataPass[i] = Num.IntParse(tempStr[12 + i * 2]); // } netResult.StepResult.mIsStepPass = Num.IntParse(tempStr[11 + 2 * cMain.DataShow]); return(netResult); }
private void FrmAutoTest_mDataReciveString(object o, RecieveStringArgs e) { string[] tempStr = e.RemostHost.Split('.'); int RemoteNum = Num.IntParse(tempStr[3]) - 101; cMain.isUdpInitError[RemoteNum] = true; string readStr = e.ReadStr; if (readStr.IndexOf("A~OK") >= 0) { string[] tempstr = readStr.Split('~'); int remoteNum = Num.IntParse(tempstr[3]); switch (tempstr[2]) { case "OVER": McgsUdp[remoteNum - 1].fUdpSend("A~OK~OVER"); cMain.isAccessDiQi = cMain.isAccessDiQi.Replace("," + string.Format("{0:D2},", remoteNum), ","); break; case "HOLD": //McgsUdp[remoteNum - 1].fUdpSend("A~OK~HOLD"); if (cMain.isAccessDiQi.IndexOf(string.Format(",{0:D2},", remoteNum)) < 0) { cMain.isAccessDiQi = cMain.isAccessDiQi + string.Format("{0:D2},", remoteNum); } break; case "ACCESS": return; } tempstr = null; tempstr = cMain.isAccessDiQi.Split(','); if (tempstr.Length >= 3) { McgsUdp[Num.IntParse(tempstr[1]) - 1].fUdpSend("A~OK~ACCESS"); } } if (readStr.IndexOf("E~OK") >= 0)//关机返回 { is_E_Ok = true; } if (readStr.IndexOf("B~OK") >= 0)//条码 { is_B_OK[RemoteNum] = true; } if (readStr.IndexOf("S~OK") >= 0)//系统设置 { is_S_OK = true; } if (readStr.IndexOf("T~OK") >= 0)//停机 { is_T_OK = true; } if (readStr.IndexOf("N~OK") >= 0)//下一步 { is_N_OK = true; } if (readStr.IndexOf("K~OK") >= 0)//开始 { is_K_OK = true; } if (readStr.IndexOf("U~OK") >= 0)//更新 { is_U_OK = true; } if (readStr.IndexOf("D~OK") >= 0)//当前实时数据 { is_D_OK = true; mNetResult = GetNetResult(readStr); cMain.mCurrentData[mNetResult.RunResult.mTestNo - 1] = mNetResult; lastGetDataTime[mNetResult.RunResult.mTestNo - 1] = Environment.TickCount; } if (readStr.IndexOf("J~OK") >= 0) { is_J_OK = true; cMain.mNetResult = GetNetResult(readStr); cData.SaveJianCeData(cMain.mNetResult); cMain.mTempNetResult[cMain.mNetResult.RunResult.mTestNo - 1].RunResult[cMain.mNetResult.RunResult.mStepId] = cMain.mNetResult.RunResult; cMain.mTempNetResult[cMain.mNetResult.RunResult.mTestNo - 1].StepResult[cMain.mNetResult.RunResult.mStepId] = cMain.mNetResult.StepResult; McgsUdp[cMain.mNetResult.RunResult.mTestNo - 1].fUdpSend("J~OK"); //if ((cMain.isPrint) && (cMain.mNetResult.RunResult.mId != "") && (cMain.mNetResult.StepResult.mIsStepPass == 0)) //{ // DataTable tmpDt = cData.GetErrorReport(cMain.mNetResult); // frmPrint fp = new frmPrint(tmpDt); // fp.Show(); // if (!fp.IsDisposed) // { // fp.Close(); // fp.Dispose(); // } //} } if (readStr.IndexOf("R~OK") >= 0)//此处已实现条码读取上来,并发送成功标志,但上位机这头暂时未处理.(防止和232串口读条码不兼容) { is_R_OK = true; string[] tempstr = readStr.Split('~'); indexAtBar = Num.IntParse(tempstr[2]) - 1; McgsUdp[indexAtBar].fUdpSend("R~OK"); if (isSetSendBarFrm) { sendBarFrm.SendBarMethod(tempstr[3]); } } if (readStr.IndexOf("X~OK") >= 0) { string[] tempstr = readStr.Split('~'); indexAtBar = Num.IntParse(tempstr[2]) - 1; } if (readStr.IndexOf("O~OK") >= 0) { string[] tempstr = readStr.Split('~'); cMain.mTodayData.TestCount[0]++; if (Num.BoolParse(tempstr[3])) { cMain.mTodayData.TestCount[1]++; } else { cMain.mTodayData.TestCount[2]++; } for (int i = 0; i < cMain.mTodayData.TestCount.Length; i++) { cTodayData.WriteToday("TestCount" + i.ToString(), cMain.mTodayData.TestCount[i].ToString()); } } }
public static bool SaveJianCeData(cNetResult mNetResult) { bool returnResult = false; int i; string sqlCommand = "Insert into AllData values({0}{1}{2})"; string tempStrHead = "#{0:yyyy-MM-dd HH:mm:ss}#,'{1}','{2}','{3}',{4},{5},'{6}',{7},'{8}'"; string tempStrData = ""; string tempStrBool = ""; bool stepResult = true; try { if (mNetResult.StepResult.mIsStepPass == 0) { stepResult = false; } tempStrHead = string.Format(tempStrHead, mNetResult.RunResult.mTestTime, mNetResult.RunResult.mBar, mNetResult.RunResult.mId, mNetResult.RunResult.mMode, mNetResult.RunResult.mTestNo, mNetResult.RunResult.mJiQi, stepResult.ToString(), mNetResult.RunResult.mStepId, mNetResult.RunResult.mStep); for (i = 0; i < 50; i++) { if (i < cMain.DataShow) { tempStrData = tempStrData + "," + mNetResult.StepResult.mData[i].ToString(); if (mNetResult.StepResult.mIsDataPass[i] == 0) { tempStrBool = tempStrBool + ",false"; } else { tempStrBool = tempStrBool + ",true"; } } else { tempStrData = tempStrData + ",0"; tempStrBool = tempStrBool + ",true"; } } sqlCommand = string.Format(sqlCommand, tempStrHead, tempStrData, tempStrBool); if (upData(sqlCommand, ConnData) > 0) { returnResult = true; } else { returnResult = false; } } catch (Exception exc) { cMain.WriteErrorToLog("cData SaveJianCeData is Error " + exc.ToString()); returnResult = false; } return(returnResult); }