Files
geomative/GeomativeStudio/cpp/Operator/TaskDataOper.cpp
T
coco df489d5640 a
2026-07-03 16:05:30 +08:00

4455 lines
162 KiB
C++

// TaskDataOper.cpp: implementation of the CTaskDataOper class.
//
//////////////////////////////////////////////////////////////////////
#include "StdAfx.h"
#include "GeoMative.h"
#include "TaskDataOper.h"
#include "TcpClient.h"
#include "GUCodeCreator.h"
#include "FileOperTools.h"
#include "Lock/AutoLock.h"
//#include "CtrlProtocolDef.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
extern float tcp_htonf(float f);
extern float tcp_ntohf(float f);
extern CString OnLineLocalTaskState(BYTE ucTaskStats);
extern CString OnLineTask(BYTE ucTaskStats);
extern CString Tm2GmtStr(time_t t);
extern CString Tm2LocalStr(time_t t);
extern time_t Str2LocalTm(CString szTime);
extern time_t Str2GmtTm(CString szTime);
extern CGeoMativeApp theApp;
extern SYSTEMTIME g_sysCurTime;
extern int g_iUILanguage;
extern int g_UIOffset;
extern int g_iOnLineVersion;
extern CString g_strSaveTestingTaskID;
extern CString g_strSaveSuspendedTaskID;
extern EN_TASK_TESTING_METHOD g_eTestingMethod;
extern void SplitterString(CStringArray &szArray,const CString& szSource, const CString& szSplitter);
extern int GetSigTxPeriod(int iTestType, int iTestPeriod);
extern char ReturnTaskType(BYTE ucTaskType);
extern CString OnLineLocalTaskState(BYTE ucTaskStats);
extern char* G2U(const char* gb2312);
extern char* U2G(const char* utf8);
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
#define MAX_UPLOAD_POINT_NUM (50)
#define MAX_UPLOAD_ELECTRODE_NUM (255)
CTaskDataOper::CTaskDataOper()
{
m_pRecTdData = NULL;
m_pRecTdData.CreateInstance(_uuidof(Recordset));
m_iTdType = -1;
m_bIsOpenTdData = false;
m_iTdType = 0;
m_iTestType = 0;
m_wMaxChannel = 1;
m_tStartTime = 0;
m_tEndTime = 0;
}
CTaskDataOper::~CTaskDataOper()
{
}
int CTaskDataOper::GetDefaultTzID()
{
_RecordsetPtr pRecTz = NULL;
pRecTz.CreateInstance(_uuidof(Recordset));
int iTzID = 0;
try
{
//获取测区ID
CString szSql = _T("");
szSql.Format(_T("select id from tz where PRID in (select id from project where PRname = 'Default') "));
pRecTz->Open(szSql.AllocSysString(), _variant_t((IDispatch*)theApp.m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText);
if (pRecTz->GetRecordCount() < 1)
{
pRecTz->Close();
if (LANG_ZHCN == g_iUILanguage)
AfxMessageBox(_T("退出默认tz id失败"));
else
MessageBoxEx(NULL, _T("Retire default tz id failed"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
return 0;
}
iTzID = pRecTz->GetCollect(_T("ID")).llVal;
pRecTz->Close();
return iTzID;
}
catch(_com_error e)
{
AfxMessageBox(e.Description());
// pRecTz->Close();
return iTzID;
}
}
int CTaskDataOper::Create1DTask(const ST1DTaskParam& stTaskParam,CString strTaskCN)
{
_CommandPtr pCmdIns = NULL;
_RecordsetPtr pRecTd = NULL;
_RecordsetPtr pRecScon = NULL;
_RecordsetPtr pRecTz = NULL;
pRecTd.CreateInstance(_uuidof(Recordset));
pRecScon.CreateInstance(_uuidof(Recordset));
pCmdIns.CreateInstance(_uuidof(Command));
pRecTz.CreateInstance(_uuidof(Command));
pCmdIns->ActiveConnection = theApp.m_pConnection;
CString strCreateDate = _T(""), strCreateTime = _T("");
strCreateDate.Format(_T("%04d-%02d-%02d"),g_sysCurTime.wYear, g_sysCurTime.wMonth, g_sysCurTime.wDay);
strCreateTime.Format(_T("%02d:%02d:%02d"), g_sysCurTime.wHour, g_sysCurTime.wMinute, g_sysCurTime.wSecond);
int iTaskID = 0;
CString szSql;
try
{
szSql.Empty();
szSql.Format(_T("select Eamount, TPamount,CN from scon where id = %d"),stTaskParam.iSptID);
pRecScon->Open(szSql.AllocSysString(), _variant_t((IDispatch*)theApp.m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText);
if (pRecScon->GetRecordCount() < 1)
{
pRecScon->Close();
CString strErr = _T("");
if (LANG_ZHCN == g_iUILanguage)
{
strErr.Format(_T("查询脚本信息(%d)失败"), stTaskParam.iSptID);
AfxMessageBox(strErr);
}
else
{
strErr.Format(_T("Query script information (%d) failed"), stTaskParam.iSptID);
MessageBoxEx(NULL, strErr, STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
}
return -1;
}
int iEAmount = pRecScon->GetCollect(_T("Eamount")).iVal;
int iTPmount = pRecScon->GetCollect(_T("TPamount")).lVal;
CString strSCCN = (pRecScon->GetCollect(_T("CN")).vt == VT_NULL) ? _T("") : (LPCTSTR)(_bstr_t)pRecScon->GetCollect(_T("CN"));
pRecScon->Close();
//获取测区ID
int iTzID = GetDefaultTzID();
if (iTzID < 1)
{
return -1;
}
CString strCreateTaskTime;
strCreateTaskTime = strCreateDate + _T(" ") + strCreateTime;
time_t tCreateTime = Str2GmtTm(strCreateTaskTime);
theApp.m_pConnection->BeginTrans();
szSql.Empty();
szSql.Format(_T("insert into td(TDname,TDCN,Tlocation,TZID,SCID,SCCN,Sname,Stype,Ttype,Eamount,TPamount,CHamount,N,TRwave,TRfrequency,SAfrequency,Cdate,Ctime,CreateTime) "
"values('%s','%s','%s',%d, %u,'%s','%s',%u,%u,%d,%d,1,%d,%d,%d,%d,#%s#,#%s#,%u)"),
stTaskParam.strTDName, strTaskCN, stTaskParam.strTestPlace, iTzID,
stTaskParam.iSptID, strSCCN, stTaskParam.strSptName, stTaskParam.iSptType,
stTaskParam.iTestType, iEAmount, iTPmount, stTaskParam.iStacking,
stTaskParam.iTxWave, stTaskParam.iTxPeriod, stTaskParam.iSAInterval,
strCreateDate, strCreateTime, tCreateTime);
pCmdIns->CommandText = szSql.AllocSysString();
pCmdIns->Execute(NULL, NULL, adCmdText);
pRecTd->Open(_T("select max(ID) as ID from td "), _variant_t((IDispatch*)theApp.m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText);
if (pRecTd->GetRecordCount() > 0)
{
iTaskID = pRecTd->GetCollect(_T("ID")).ulVal;
}
pRecTd->Close();
//插入tdchannel表
szSql.Empty();
szSql.Format(_T("insert into tdchannel(TDID, CHnumber, AR) values (%d, 1, %d)"), iTaskID, stTaskParam.iAR);
pCmdIns->CommandText = szSql.AllocSysString();
pCmdIns->Execute(NULL, NULL, adCmdText);
int iTdChID = 0;
pRecTd->Open(_T("select max(ID) as ID from tdchannel "), _variant_t((IDispatch*)theApp.m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText);
if (pRecTd->GetRecordCount() > 0)
{
iTdChID = pRecTd->GetCollect(_T("ID")).ulVal;
}
pRecTd->Close();
//批量将脚本中的ABMN信息导入到任务中去
szSql.Empty();
szSql.Format(_T("insert into td1dcon(TCHID, TSN, a,b,x,y,N,K,I,V,R0,SP,bUse) select %d, TSN, a, b, x, y, N, K,0,0,0,0,0 from script1d "
"where CHID in (select ID from channel where SCID = %d and CHnumber = 1)"), iTdChID, stTaskParam.iSptID);
pCmdIns->CommandText = szSql.AllocSysString();
pCmdIns->Execute(NULL, NULL, adCmdText);
//在这里需要首先插入接地电阻信息
for (int i = 0; i < 2; i++)
{
szSql.Empty();
szSql.Format(_T("insert into gr(TDID, Ecode) values(%d,%d) "),iTaskID, -1*i-1);
pCmdIns->CommandText = szSql.AllocSysString();
pCmdIns->Execute(NULL, NULL, adCmdText);
}
theApp.m_pConnection->CommitTrans();
return iTaskID;
}
catch (_com_error e)
{
theApp.m_pConnection->RollbackTrans();
AfxMessageBox(e.Description());
return -1;
}
}
CString CTaskDataOper::CreateTaskCN(int iTestType)
{
CString strTaskCN = m_guCodeCreator.GenerateGUIDCode();
CString strDevSN = _T("");
strDevSN.Format("SN%u", m_uiDevID);
strTaskCN.Format("ERI%c%04d%02d%02d%02d%02d%02d_%s", ReturnTaskType(iTestType), \
g_sysCurTime.wYear, g_sysCurTime.wMonth, g_sysCurTime.wDay, \
g_sysCurTime.wHour, g_sysCurTime.wMinute, g_sysCurTime.wSecond, strDevSN);
return strTaskCN;
}
int CTaskDataOper::Create2DTask(const ST2DTaskParam& stTaskParam, CString strTaskCN)
{
_CommandPtr pCmdIns = NULL;
_RecordsetPtr pRecTd = NULL;
_RecordsetPtr pRecScon = NULL;
pRecTd.CreateInstance(_uuidof(Recordset));
pRecScon.CreateInstance(_uuidof(Recordset));
pCmdIns.CreateInstance(_uuidof(Command));
pCmdIns->ActiveConnection = theApp.m_pConnection;
CString strCreateDate = _T(""), strCreateTime = _T("");
strCreateDate.Format(_T("%04d-%02d-%02d"),g_sysCurTime.wYear, g_sysCurTime.wMonth, g_sysCurTime.wDay);
strCreateTime.Format(_T("%02d:%02d:%02d"), g_sysCurTime.wHour, g_sysCurTime.wMinute, g_sysCurTime.wSecond);
CString strValildLayer = _T(""), strValidElec = _T(""), strEspace = _T("");
strValidElec.Format(_T("%d,%d"),stTaskParam.iStartElec, stTaskParam.iEndElec);
strValildLayer.Format(_T("%d,%d"), stTaskParam.iStartLayer, stTaskParam.iEndLayer);
strEspace.Format(_T("%f"), stTaskParam.fEspace);
CString strDevSN = _T(""); strDevSN.Format("SN%u",stTaskParam.uiDevID);
int iTaskID = 0;
CString szSql;
try
{
szSql.Empty();
szSql.Format(_T("select TPamount,CN,PoleDistance from scon where id = %d"),stTaskParam.iSptID);
pRecScon->Open(szSql.AllocSysString(), _variant_t((IDispatch*)theApp.m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText);
if (pRecScon->GetRecordCount() < 1)
{
pRecScon->Close();
CString strErr = _T("");
if (LANG_ZHCN == g_iUILanguage)
{
strErr.Format(_T("查询脚本信息(%d)失败"), stTaskParam.iSptID);
AfxMessageBox(strErr);
}
else
{
strErr.Format(_T("Query script information (%d) failed"), stTaskParam.iSptID);
MessageBoxEx(NULL, strErr, STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
}
return -1;
}
int iTPmount = pRecScon->GetCollect(_T("TPamount")).lVal;
CString strSCCN = (pRecScon->GetCollect(_T("CN")).vt == VT_NULL) ? _T("") : (LPCTSTR)(_bstr_t)pRecScon->GetCollect(_T("CN"));
if (AR_CROSS_HOLE_GEOMATIVE == stTaskParam.iAR
|| AR_CROSS_HOLE_GEOMATIVE_AM == stTaskParam.iAR)
{
strEspace = (pRecScon->GetCollect(_T("PoleDistance")).vt == VT_NULL) ? _T("") : (LPCTSTR)(_bstr_t)pRecScon->GetCollect(_T("PoleDistance"));
}
else if (AR_CROSS_HOLE_TYPE == stTaskParam.iAR)
{
//当为老跨孔偶极装置时,需对数据进行拼接
strEspace.Empty();
strEspace.Format(_T("%.2f,%.2f"), stTaskParam.fEspace, stTaskParam.fHoleSpace);
}
pRecScon->Close();
//获取切割电极后的测点数总数,跨孔装置不需要切割电极
if (!(AR_CROSS_HOLE_GEOMATIVE == stTaskParam.iAR
|| AR_CROSS_HOLE_GEOMATIVE_AM == stTaskParam.iAR))
{
CString strFilter;
szSql.Empty();
szSql.Format(_T("select top 1 C1,C2,P1,P2 from script2d where CHID in (select ID from channel where SCID=%d and CHnumber = 1)"), stTaskParam.iSptID);
pRecScon->Open(szSql.AllocSysString(), _variant_t((IDispatch*)theApp.m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText);
if (pRecScon->GetRecordCount() > 0)
{
CString strA, strB, strM, strN;
strFilter.Empty();
strA = pRecScon->GetCollect(_T("C1")).vt == VT_NULL ? _T("null") : (LPCTSTR)(_bstr_t)pRecScon->GetCollect(_T("C1"));
if (-1 != atoi(strA))
{
strFilter.AppendFormat(_T("and C1>=%d and C1<=%d "), stTaskParam.iStartElec, stTaskParam.iEndElec);
}
strB = pRecScon->GetCollect(_T("C2")).vt == VT_NULL ? _T("null") : (LPCTSTR)(_bstr_t)pRecScon->GetCollect(_T("C2"));
if (-1 != atoi(strB))
{
strFilter.AppendFormat(_T("and C2>=%d and C2<=%d "), stTaskParam.iStartElec, stTaskParam.iEndElec);
}
strM = pRecScon->GetCollect(_T("P1")).vt == VT_NULL ? _T("null") : (LPCTSTR)(_bstr_t)pRecScon->GetCollect(_T("P1"));
if (-1 != atoi(strM))
{
strFilter.AppendFormat(_T("and P1>=%d and P1<=%d "), stTaskParam.iStartElec, stTaskParam.iEndElec);
}
strN = pRecScon->GetCollect(_T("P2")).vt == VT_NULL ? _T("null") : (LPCTSTR)(_bstr_t)pRecScon->GetCollect(_T("P2"));
if (-1 != atoi(strN))
{
strFilter.AppendFormat(_T("and P2>=%d and P2<=%d "), stTaskParam.iStartElec, stTaskParam.iEndElec);
}
}
pRecScon->Close();
szSql.Empty();
szSql.Format(_T("select count(*) as TestPointamount from script2d where CHID in (select ID from channel where SCID = %d and CHnumber = 1) %s"), stTaskParam.iSptID, strFilter);
pRecScon->Open(szSql.AllocSysString(), _variant_t((IDispatch*)theApp.m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText);
if (pRecScon->GetRecordCount() > 0)
{
iTPmount = pRecScon->GetCollect(_T("TestPointamount")).lVal;
}
pRecScon->Close();
}
//获取测区ID
int iTzID = GetDefaultTzID();
if (iTzID < 1)
{
return -1;
}
int iTime = 0;
CString strCreateTaskTime;
strCreateTaskTime = strCreateDate + _T(" ") + strCreateTime;
time_t tCreateTime = Str2GmtTm(strCreateTaskTime);
theApp.m_pConnection->BeginTrans();
szSql.Empty();
szSql.Format(_T("insert into td(TDname,TDCN,Tlocation,TZID,SCID,SCCN,Sname,Stype,Ttype,StartElec,EndElec,Eamount,TPamount,CHamount,N,TRwave,TRfrequency,SAfrequency,"
"Clayout, SkipCable, CRTime, Edistance, rect, rect_loc, Cdate, Ctime,DESN,STime,ETime,TTimer,TdStatus,TestGRFlag,CreateTime) "
"values('%s','%s','%s',%d,%u,'%s','%s',%u,%u,%d,%d,%d,%d,1,%d,%d,%d,%d, %d, %d, %d, '%s', '%s', '%s', #%s#,#%s#,'%s',%d,%d,%d,%d,%d,%u)"),
stTaskParam.strTDName, strTaskCN, stTaskParam.strTestPlace, iTzID,
stTaskParam.iSptID,strSCCN, stTaskParam.strSptName, stTaskParam.iSptType,
stTaskParam.iTestType,stTaskParam.iStartElec, stTaskParam.iEndElec, stTaskParam.iEAmount, iTPmount, stTaskParam.iStacking,
stTaskParam.iTxWave, stTaskParam.iTxPeriod, stTaskParam.iSAInterval,
stTaskParam.iCableLayout, stTaskParam.iSkipCable, stTaskParam.iRollCnt,
strEspace, strValidElec, strValildLayer,
strCreateDate, strCreateTime, strDevSN, iTime, iTime, iTime, EN_TASK_NO_UPLOAD, stTaskParam.ucTestGRFlag, tCreateTime);
pCmdIns->CommandText = szSql.AllocSysString();
pCmdIns->Execute(NULL, NULL, adCmdText);
pRecTd->Open(_T("select max(ID) as ID from td "), _variant_t((IDispatch*)theApp.m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText);
if (pRecTd->GetRecordCount() > 0)
{
iTaskID = pRecTd->GetCollect(_T("ID")).ulVal;
}
pRecTd->Close();
//插入tdchannel表
szSql.Empty();
szSql.Format(_T("insert into tdchannel(TDID, CHnumber, AR) values (%d, 1, %d)"), iTaskID, stTaskParam.iAR);
pCmdIns->CommandText = szSql.AllocSysString();
pCmdIns->Execute(NULL, NULL, adCmdText);
int iTdChID = 0;
pRecTd->Open(_T("select max(ID) as ID from tdchannel "), _variant_t((IDispatch*)theApp.m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText);
if (pRecTd->GetRecordCount() > 0)
{
iTdChID = pRecTd->GetCollect(_T("ID")).ulVal;
}
pRecTd->Close();
if (AR_CROSS_HOLE_GEOMATIVE == stTaskParam.iAR
|| AR_CROSS_HOLE_GEOMATIVE_AM == stTaskParam.iAR)
{
//批量将脚本中的ABMN信息导入到任务中去,用于跨孔装置不需要过滤脚本测点
szSql.Empty();
szSql.Format(_T("insert into td2dcon(TCHID, TSN, C1,C2,P1,P2,N,K,I,V,R0,SP,bUse) select %d, TSN, C1, C2, P1, P2, N, K*%f as K_New,0,0,0,0,0 from script2d "
"where CHID in (select ID from channel where SCID = %d and CHnumber = 1)"), iTdChID, stTaskParam.fEspace, stTaskParam.iSptID);
pCmdIns->CommandText = szSql.AllocSysString();
pCmdIns->Execute(NULL, NULL, adCmdText);
}
else
{
//因为TSN需要从1开始,所以先从scriptXd中查询后插入到tdXdcon中
int iTSN = 1;
std::vector<STTaskDetailBasicData> vtRes;
if (QueryTdDataByElec(stTaskParam.iSptID, stTaskParam.iSptType, stTaskParam.iStartElec, stTaskParam.iEndElec, vtRes))
{
if (vtRes.size() > 0)
{
for (int i = 0; i < vtRes.size(); i++)
{
szSql.Empty();
if (0 == stTaskParam.iSptType)
szSql.Format(_T("insert into td1dcon(TCHID,TSN,a,b,x,y,N,K,I,V,R0,SP,bUse) values(%d,%d,%d,%d,%d,%d,%d,%f,0,0,0,0,0)"), \
iTdChID, iTSN, vtRes.at(i).fA, vtRes.at(i).fB, vtRes.at(i).fX, vtRes.at(i).fY, vtRes.at(i).ucStack, vtRes.at(i).fK*stTaskParam.fEspace);
else
szSql.Format(_T("insert into td2dcon(TCHID,TSN,C1,C2,P1,P2,N,K,I,V,R0,SP,bUse) values(%d,%d,%d,%d,%d,%d,%d,%f,0,0,0,0,0)"), \
iTdChID, iTSN, vtRes.at(i).iA, vtRes.at(i).iB, vtRes.at(i).iM, vtRes.at(i).iN, vtRes.at(i).ucStack, vtRes.at(i).fK*stTaskParam.fEspace);
pCmdIns->CommandText = szSql.AllocSysString();
pCmdIns->Execute(NULL, NULL, adCmdText);
iTSN++;
}
}
}
}
theApp.m_pConnection->CommitTrans();
return iTaskID;
}
catch (_com_error e)
{
theApp.m_pConnection->RollbackTrans();
AfxMessageBox(e.Description());
return -1;
}
}
//根据起始、结束电极编号,查找脚本中对应的测点
bool CTaskDataOper::QueryTdDataByElec(int iSptID, BYTE ucTdType, int iStartElec, int iEndElec, std::vector<STTaskDetailBasicData>& vtRes)
{
CString strSql = _T(""), strErr = _T(""), strScript = _T("");
if (ucTdType > 2)
{
if (LANG_ZHCN == g_iUILanguage)
{
strErr.Format(_T("未知任务类型(%d)"), ucTdType);
AfxMessageBox(strErr);
}
else
{
strErr.Format(_T("Unknow Task type(%d)"), ucTdType);
MessageBoxEx(NULL, strErr, STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
}
return false;
}
vtRes.clear();
_RecordsetPtr pRecTd;
pRecTd.CreateInstance(_uuidof(Recordset));
strScript.Format(_T("script%dd"), ucTdType + 1);
CString strFilter = _T("");
if (iStartElec > 0 && iEndElec > 0)
{
strSql.Empty();
strSql.Format(_T("select top 1 C1,C2,P1,P2 from script2d where CHID in (select ID from channel where SCID=%d and CHnumber = 1)"), iSptID);
pRecTd->Open(strSql.AllocSysString(), _variant_t((IDispatch*)theApp.m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText);
if (pRecTd->GetRecordCount() > 0)
{
CString strA, strB, strM, strN;
strFilter.Empty();
strA = pRecTd->GetCollect(_T("C1")).vt == VT_NULL ? _T("null") : (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("C1"));
if (-1 != atoi(strA))
{
strFilter.AppendFormat(_T("and C1>=%d and C1<=%d "), iStartElec, iEndElec);
}
strB = pRecTd->GetCollect(_T("C2")).vt == VT_NULL ? _T("null") : (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("C2"));
if (-1 != atoi(strB))
{
strFilter.AppendFormat(_T("and C2>=%d and C2<=%d "), iStartElec, iEndElec);
}
strM = pRecTd->GetCollect(_T("P1")).vt == VT_NULL ? _T("null") : (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("P1"));
if (-1 != atoi(strM))
{
strFilter.AppendFormat(_T("and P1>=%d and P1<=%d "), iStartElec, iEndElec);
}
strN = pRecTd->GetCollect(_T("P2")).vt == VT_NULL ? _T("null") : (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("P2"));
if (-1 != atoi(strN))
{
strFilter.AppendFormat(_T("and P2>=%d and P2<=%d "), iStartElec, iEndElec);
}
}
pRecTd->Close();
}
strSql.Empty();
strSql.Format(_T("select * from %s where CHID in (select ID from channel where SCID = %d and CHnumber = 1) %s order by TSN"), strScript, iSptID, strFilter);
try
{
pRecTd->Open(strSql.AllocSysString(), _variant_t((IDispatch*)theApp.m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText);
while (pRecTd->adoEOF == 0)
{
ST_TASK_DETAIL_BASIC_DATA stTaskDetailData;
memset(&stTaskDetailData, 0, sizeof(ST_TASK_DETAIL_BASIC_DATA));
if (0 == ucTdType)
{
stTaskDetailData.fA = pRecTd->GetCollect(_T("a")).fltVal;
stTaskDetailData.fB = pRecTd->GetCollect(_T("b")).fltVal;
stTaskDetailData.fX = pRecTd->GetCollect(_T("x")).fltVal;
stTaskDetailData.fY = pRecTd->GetCollect(_T("y")).fltVal;
}
else
{
stTaskDetailData.iA = pRecTd->GetCollect(_T("C1")).iVal;
stTaskDetailData.iB = pRecTd->GetCollect(_T("C2")).iVal;
stTaskDetailData.iM = pRecTd->GetCollect(_T("P1")).iVal;
stTaskDetailData.iN = pRecTd->GetCollect(_T("P2")).iVal;
}
stTaskDetailData.ucStack = pRecTd->GetCollect(_T("N")).iVal;
stTaskDetailData.fK = pRecTd->GetCollect(_T("K")).fltVal;
vtRes.push_back(stTaskDetailData);
pRecTd->MoveNext();
}
pRecTd->Close();
return true;
}
catch (_com_error e)
{
AfxMessageBox(e.Description());
pRecTd->Close();
return false;
}
}
void CTaskDataOper::AdjustParam()
{
// return;
_CommandPtr pCmdIns = NULL;
pCmdIns.CreateInstance(_uuidof(Command));
pCmdIns->ActiveConnection = theApp.m_pConnection;
CString szSql = _T("");
// szSql = _T("update td set Clayout = 0,Edistance = '1' where id = 1");
szSql = _T("update td set Ttype =1, TRfrequency = 1 where id = 3");
// CString szSql = _T("");
int iTdChID = 5;
// szSql.Format(_T("insert into td3dcon(TCHID, TSN, C1,C2,P1,P2,N,K,I,V,R0,SP) select %d, TSN, C1, C2, P1, P2, N, K,0,0,0,0 from script3d "
// "where CHID in (select ID from channel where SCID = 3 and CHnumber = 1)"), iTdChID);
try
{
theApp.m_pConnection->BeginTrans();
pCmdIns->CommandText = szSql.AllocSysString();
pCmdIns->Execute(NULL, NULL, adCmdText);
theApp.m_pConnection->CommitTrans();
}
catch (_com_error e)
{
theApp.m_pConnection->RollbackTrans();
AfxMessageBox(e.Description());
return ;
}
}
int CTaskDataOper::Create3DTask(const ST3DTaskParam& stTaskParam, CString strTaskCN)
{
_CommandPtr pCmdIns = NULL;
_RecordsetPtr pRecTd = NULL;
_RecordsetPtr pRecScon = NULL;
pRecTd.CreateInstance(_uuidof(Recordset));
pRecScon.CreateInstance(_uuidof(Recordset));
pCmdIns.CreateInstance(_uuidof(Command));
pCmdIns->ActiveConnection = theApp.m_pConnection;
CString strCreateDate = _T(""), strCreateTime = _T("");
strCreateDate.Format(_T("%04d-%02d-%02d"),g_sysCurTime.wYear, g_sysCurTime.wMonth, g_sysCurTime.wDay);
strCreateTime.Format(_T("%02d:%02d:%02d"), g_sysCurTime.wHour, g_sysCurTime.wMinute, g_sysCurTime.wSecond);
CString strGrid = _T("0,0");
CString strDevSN = _T("");
strDevSN.Format("SN%u", m_uiDevID);
int iTaskID = 0;
int iTime = 0;
CString szSql;
try
{
szSql.Empty();
szSql.Format(_T("select Eamount, TPamount, Rect, RectLoc,PoleStep,PoleDistance,CN,LineDirection from scon where id = %d"),stTaskParam.iSptID);
CString strRect, strRectLoc , strPoleStep, strPoleDis,strLineDirection;
pRecScon->Open(szSql.AllocSysString(), _variant_t((IDispatch*)theApp.m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText);
if (pRecScon->GetRecordCount() < 1)
{
pRecScon->Close();
CString strErr = _T("");
if (LANG_ZHCN == g_iUILanguage)
{
strErr.Format(_T("查询脚本信息(%d)失败"), stTaskParam.iSptID);
AfxMessageBox(strErr);
}
else
{
strErr.Format(_T("Query script information (%d) failed"), stTaskParam.iSptID);
MessageBoxEx(NULL, strErr, STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
}
return -1;
}
strRect = (VT_NULL == pRecScon->GetCollect(_T("Rect")).vt) ? _T("") : (LPCTSTR)(_bstr_t)pRecScon->GetCollect(_T("Rect"));
strRectLoc = (VT_NULL == pRecScon->GetCollect(_T("RectLoc")).vt) ? _T("") : (LPCTSTR)(_bstr_t)pRecScon->GetCollect(_T("RectLoc"));
strPoleStep = (VT_NULL == pRecScon->GetCollect(_T("PoleStep")).vt) ? _T("") : (LPCTSTR)(_bstr_t)pRecScon->GetCollect(_T("PoleStep"));
strPoleDis = (VT_NULL == pRecScon->GetCollect(_T("PoleDistance")).vt) ? _T("") : (LPCTSTR)(_bstr_t)pRecScon->GetCollect(_T("PoleDistance"));
int iEAmount = pRecScon->GetCollect(_T("Eamount")).iVal;
int iTPmount = pRecScon->GetCollect(_T("TPamount")).lVal;
int iLineDirection = pRecScon->GetCollect(_T("LineDirection")).bVal;
CString strSCCN = (pRecScon->GetCollect(_T("CN")).vt == VT_NULL) ? _T("") : (LPCTSTR)(_bstr_t)pRecScon->GetCollect(_T("CN"));
pRecScon->Close();
//获取测区ID
int iTzID = GetDefaultTzID();
if (iTzID < 1)
{
return -1;
}
theApp.m_pConnection->BeginTrans();
szSql.Empty();
CString strCreateTaskTime;
strCreateTaskTime = strCreateDate + _T(" ") + strCreateTime;
time_t tCreateTime = Str2GmtTm(strCreateTaskTime);
szSql.Format(_T("insert into td(TDname,TDCN,Tlocation,TZID,\
SCID,SCCN,Sname,Stype,\
Ttype,Eamount,TPamount,CHamount,\
N,TRwave,TRfrequency,SAfrequency,\
Clayout, SkipCable, Espace,Edistance, rect,rect_loc,\
Cdate, Ctime,DESN,STime,ETime,TTimer,TdStatus,TestGRFlag,LineDirection,CreateTime) "
"values('%s','%s','%s',%d,\
%u,'%s','%s',%u\
,%u,%d,%d,1,\
%d,%d,%d,%d,\
%d, %d, '%s','%s', '%s', \
'%s', #%s#,#%s#,'%s',%d,%d,%d,%d,%d,%d,%u)"),
stTaskParam.strTDName, strTaskCN, stTaskParam.strTestPlace, iTzID,
stTaskParam.iSptID, strSCCN, stTaskParam.strSptName, stTaskParam.iSptType,
stTaskParam.iTestType, iEAmount, iTPmount, stTaskParam.iStacking,
stTaskParam.iTxWave, stTaskParam.iTxPeriod, stTaskParam.iSAInterval,
stTaskParam.iCableLayout, stTaskParam.iSkipCable, strPoleStep, strPoleDis, strRect, strRectLoc,
strCreateDate, strCreateTime, strDevSN, iTime, iTime, iTime, EN_TASK_NO_UPLOAD, stTaskParam.ucTestGRFlag, iLineDirection, tCreateTime);
pCmdIns->CommandText = szSql.AllocSysString();
pCmdIns->Execute(NULL, NULL, adCmdText);
pRecTd->Open(_T("select max(ID) as ID from td "), _variant_t((IDispatch*)theApp.m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText);
if (pRecTd->GetRecordCount() > 0)
{
iTaskID = pRecTd->GetCollect(_T("ID")).ulVal;
}
pRecTd->Close();
//插入tdchannel表
szSql.Empty();
szSql.Format(_T("insert into tdchannel(TDID, CHnumber, AR) values (%d, 1, %d)"), iTaskID, stTaskParam.iAR);
pCmdIns->CommandText = szSql.AllocSysString();
pCmdIns->Execute(NULL, NULL, adCmdText);
int iTdChID = 0;
pRecTd->Open(_T("select max(ID) as ID from tdchannel "), _variant_t((IDispatch*)theApp.m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText);
if (pRecTd->GetRecordCount() > 0)
{
iTdChID = pRecTd->GetCollect(_T("ID")).ulVal;
}
pRecTd->Close();
//批量将脚本中的ABMN信息导入到任务中去
szSql.Empty();
szSql.Format(_T("insert into td3dcon(TCHID, TSN, C1,C2,P1,P2,N,K,I,V,R0,SP,bUse) select %d, TSN, C1, C2, P1, P2, N, K,0,0,0,0,0 from script3d "
"where CHID in (select ID from channel where SCID = %d and CHnumber = 1)"), iTdChID, stTaskParam.iSptID);
pCmdIns->CommandText = szSql.AllocSysString();
pCmdIns->Execute(NULL, NULL, adCmdText);
theApp.m_pConnection->CommitTrans();
return iTaskID;
}
catch (_com_error e)
{
theApp.m_pConnection->RollbackTrans();
AfxMessageBox(e.Description());
return -1;
}
}
bool CTaskDataOper::InsertTaskPacketInfo(const std::vector<STTdBrowseInfo>& vtTdBrowseInfo, const STTaskPacketAttr& stAttr)
{
//
_CommandPtr pCmdIns = NULL;
pCmdIns.CreateInstance(_uuidof(Command));
pCmdIns->ActiveConnection = theApp.m_pConnection;
CString szSql = _T("");
try
{
theApp.m_pConnection->BeginTrans();
szSql = "delete from tdTaskPacket";
pCmdIns->CommandText = szSql.AllocSysString();
pCmdIns->Execute(NULL, NULL, adCmdText);
szSql.Empty();
// szSql.Format(_T("insert into tdTaskPacket (MainID,LoopTimes,Interval,PLCID) values (1, %d, %d, '%s')"),
// stAttr.iLoopTimes, stAttr.iInterval, stAttr.strPlcID);
szSql.Format(_T("insert into tdTaskPacket values (1, %d, %d, '%s')"),
stAttr.iLoopTimes, stAttr.iInterval, stAttr.strPlcID);
pCmdIns->CommandText = szSql.AllocSysString();
pCmdIns->Execute(NULL, NULL, adCmdText);
//
szSql = "delete from tdTaskPacketInfo where TaskPacketID = 1";
pCmdIns->CommandText = szSql.AllocSysString();
pCmdIns->Execute(NULL, NULL, adCmdText);
for (int i = 0; i < vtTdBrowseInfo.size(); i++)
{
szSql.Empty();
szSql.Format(_T("insert into tdTaskPacketInfo (TaskID,TaskName,TaskPacketID) values (%d, '%s', 1)"),
vtTdBrowseInfo[i].iTaskID, vtTdBrowseInfo[i].strTaskName);
pCmdIns->CommandText = szSql.AllocSysString();
pCmdIns->Execute(NULL, NULL, adCmdText);
}
theApp.m_pConnection->CommitTrans();
}
catch (_com_error e)
{
AfxMessageBox(e.Description());
AfxMessageBox(e.ErrorMessage());
theApp.m_pConnection->RollbackTrans();
return false;
}
return true;
}
bool CTaskDataOper::InsertPlcStatusData(const STRemPlcDataInfo* pRemPlcData)
{
CString strCreateDate = _T(""), strCreateTime = _T("");
strCreateDate.Format(_T("%04d-%02d-%02d"),g_sysCurTime.wYear, g_sysCurTime.wMonth, g_sysCurTime.wDay);
strCreateTime.Format(_T("%02d:%02d:%02d"), g_sysCurTime.wHour, g_sysCurTime.wMinute, g_sysCurTime.wSecond);
CString szSql = _T("");
szSql.Format(_T("insert into OnlineDevStatus(AnaLogQua1,AnaLogQua2,AnaLogQua3,AnaLogQua4,AnaLogQua5,AnaLogQua6,CtrlK1,CtrlK2,CtrlK3,CtrlK4,RepDate,RepTime)"
" values(%f, %f, %f, %f, %f, %f, %d, %d, %d, %d, #%s#, #%s#)"),
*((float*)(&(pRemPlcData->uiAnaLogQua[0]))), *((float*)(&(pRemPlcData->uiAnaLogQua[1]))),
*((float*)(&(pRemPlcData->uiAnaLogQua[2]))), *((float*)(&(pRemPlcData->uiAnaLogQua[3]))),
*((float*)(&(pRemPlcData->uiAnaLogQua[4]))), *((float*)(&(pRemPlcData->uiAnaLogQua[5]))) ,
pRemPlcData->ucCtrlK1, pRemPlcData->ucCtrlK2, pRemPlcData->ucCtrlK3,
pRemPlcData->ucCtrlK4, strCreateDate, strCreateTime);
_CommandPtr pCmdIns = NULL;
pCmdIns.CreateInstance(_uuidof(Command));
pCmdIns->ActiveConnection = theApp.m_pConnection;
try
{
theApp.m_pConnection->BeginTrans();
pCmdIns->CommandText = szSql.AllocSysString();
pCmdIns->Execute(NULL, NULL, adCmdText);
theApp.m_pConnection->CommitTrans();
return true;
}
catch (_com_error e)
{
CString strInfo = _T("");
strInfo.Format(_T("[%d]InsertPlcStatusData failed, error = %s "),__LINE__,e.Description());
CFileOperTools::GetInstance()->WriteComLog(strInfo);
AfxMessageBox(e.Description());
theApp.m_pConnection->RollbackTrans();
return false;
}
}
int CTaskDataOper::QueryARByTdID(DWORD dwTdID)
{
_RecordsetPtr pRecSpt = NULL;
pRecSpt.CreateInstance(_uuidof(Recordset));
CString strSql = _T("");
strSql.Format(_T("select AR from tdchannel where TDID = %d and CHnumber = 1"), dwTdID);
pRecSpt->Open(strSql.AllocSysString(), _variant_t((IDispatch*)theApp.m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText);
int iAR = 0;
if (pRecSpt->GetRecordCount() > 0)
{
iAR = pRecSpt->GetCollect(_T("AR")).iVal;
}
pRecSpt->Close();
return iAR;
}
void CTaskDataOper::QuerySptByAR(int iAR, std::vector<STQuerySptInfo>& vtQuerySptRes, int iSptType)
{
vtQuerySptRes.clear();
_RecordsetPtr pRecSpt = NULL;
pRecSpt.CreateInstance(_uuidof(Recordset));
CString strSql = _T("");
strSql.Format(_T("select a.SCID as SCID, b.Sname as Sname from channel a, scon b where a.AR = %d and a.SCID = b.ID and b.Stype=%d"), iAR, iSptType);
pRecSpt->Open(strSql.AllocSysString(), _variant_t((IDispatch*)theApp.m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText);
STQuerySptInfo stQuerySpt;
while ((short)0 == pRecSpt->adoEOF)
{
stQuerySpt.iSptID = pRecSpt->GetCollect(_T("SCID")).ulVal;
stQuerySpt.strSptName = (LPCTSTR)(_bstr_t)pRecSpt->GetCollect(_T("Sname"));
vtQuerySptRes.push_back(stQuerySpt);
pRecSpt->MoveNext();
}
pRecSpt->Close();
}
void CTaskDataOper::QuerySptRectByARandSCname(int iAR, CString strSptname, CString& strRect, CString& strPoleStep, CString& strPoleDistance, CString& strLineDirection, BYTE& ucSptType)
{
_RecordsetPtr pRecSpt = NULL;
pRecSpt.CreateInstance(_uuidof(Recordset));
CString strSql = _T("");
strSql.Format(_T("select b.Rect as Rect,b.PoleStep as PoleStep,b.LineDirection as LineDirection,b.PoleDistance as PoleDistance,b.Stype as Stype from channel a, scon b where a.AR = %d and a.SCID = b.ID and b.Sname='%s'"), iAR, strSptname);
pRecSpt->Open(strSql.AllocSysString(), _variant_t((IDispatch*)theApp.m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText);
while ((short)0 == pRecSpt->adoEOF)
{
if (VT_NULL != pRecSpt->GetCollect(_T("Rect")).vt)
strRect = (LPCTSTR)(_bstr_t)pRecSpt->GetCollect(_T("Rect"));
if (VT_NULL != pRecSpt->GetCollect(_T("PoleStep")).vt)
strPoleStep = (LPCTSTR)(_bstr_t)pRecSpt->GetCollect(_T("PoleStep"));
if (VT_NULL != pRecSpt->GetCollect(_T("PoleDistance")).vt)
strPoleDistance = (LPCTSTR)(_bstr_t)pRecSpt->GetCollect(_T("PoleDistance"));
if (VT_NULL != pRecSpt->GetCollect(_T("LineDirection")).vt)
strLineDirection = (LPCTSTR)(_bstr_t)pRecSpt->GetCollect(_T("LineDirection"));
if (VT_NULL != pRecSpt->GetCollect(_T("Stype")).vt)
ucSptType = pRecSpt->GetCollect(_T("Stype")).bVal;
pRecSpt->MoveNext();
}
pRecSpt->Close();
}
bool CTaskDataOper::DeleteTask(int iTaskID)
{
_CommandPtr pCmdDel = NULL;
pCmdDel.CreateInstance(_uuidof(Command));
pCmdDel->ActiveConnection = theApp.m_pConnection;
CString strSql = _T("");
strSql.Format(_T("delete from td where id = %d"), iTaskID);
try
{
theApp.m_pConnection->BeginTrans();
pCmdDel->CommandText = strSql.AllocSysString();
pCmdDel->Execute(NULL, NULL, adCmdText);
theApp.m_pConnection->CommitTrans();
return true;
}
catch (_com_error e)
{
theApp.m_pConnection->RollbackTrans();
AfxMessageBox(e.Description());
return false;
}
}
bool CTaskDataOper::DeleteTaskArray(std::vector<int> vtTaskID)
{
if (vtTaskID.size() == 0)
{
return false;
}
_CommandPtr pCmdDel = NULL;
pCmdDel.CreateInstance(_uuidof(Command));
pCmdDel->ActiveConnection = theApp.m_pConnection;
CString strAppend;
CString strTmp;
CString strSql = _T("");
strSql.Format(_T("delete from td where id in ("));
for (int i = 0; i < vtTaskID.size(); i++)
{
strTmp.Empty();
strTmp.Format("%d", vtTaskID.at(i));
strAppend += strTmp;
if (i + 1 != vtTaskID.size())
{
strAppend += ",";
}
}
strAppend = strAppend + ")";
strSql += strAppend;
try
{
theApp.m_pConnection->BeginTrans();
pCmdDel->CommandText = strSql.AllocSysString();
pCmdDel->Execute(NULL, NULL, adCmdText);
theApp.m_pConnection->CommitTrans();
return true;
}
catch (_com_error e)
{
theApp.m_pConnection->RollbackTrans();
AfxMessageBox(e.Description());
return false;
}
}
bool CTaskDataOper::DeleteTaskArray(std::vector<CString> vtTaskID)
{
if (vtTaskID.size() == 0)
{
return false;
}
_CommandPtr pCmdDel = NULL;
pCmdDel.CreateInstance(_uuidof(Command));
pCmdDel->ActiveConnection = theApp.m_pConnection;
CString strAppend;
CString strTmp;
CString strSql = _T("");
strSql.Format(_T("delete from td where TDCN in ("));
for (int i = 0; i < vtTaskID.size(); i++)
{
strTmp.Empty();
strTmp.Format("'%s'", vtTaskID.at(i));
strAppend += strTmp;
if (i + 1 != vtTaskID.size())
{
strAppend += ",";
}
}
strAppend = strAppend + ")";
strSql += strAppend;
try
{
theApp.m_pConnection->BeginTrans();
pCmdDel->CommandText = strSql.AllocSysString();
pCmdDel->Execute(NULL, NULL, adCmdText);
theApp.m_pConnection->CommitTrans();
CFileOperTools::GetInstance()->WriteComLog(_T("zm:delete local task: ")+strSql);
return true;
}
catch (_com_error e)
{
theApp.m_pConnection->RollbackTrans();
AfxMessageBox(e.Description());
return false;
}
}
void CTaskDataOper::QueryMediumInfo(int iSptType, std::vector<STQueryMediumInfo>& vtQueryAR)
{
vtQueryAR.clear();
_RecordsetPtr pRecAR = NULL;
pRecAR.CreateInstance(_uuidof(Recordset));
CString strSql = _T("");
strSql.Format(_T("select AR, MEname from medium where LANG = %d and "),g_iUILanguage);
CString strTmp = _T("");
switch (iSptType)
{
case 0:
strTmp = _T("AR in (17,18,19,20,21,33)");
break;
case 1:
strTmp = _T("AR in (1,2,3,4,5,6,9,11,16,39,50,40,41,42,43,44,45,47)");
break;
case 2:
strTmp = _T("AR in (21,22,23,24,25,26,27,29,45,46,48,49)");
break;
default:
CString strErr = _T("");
strErr.Format(_T("Unknow Script type, type value = %d"),iSptType);
AfxMessageBox(strErr);
return;
}
strSql = strSql + strTmp;
pRecAR->Open(strSql.AllocSysString(),_variant_t((IDispatch*)theApp.m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText);
STQueryMediumInfo stARInfo;
while ((short)0 == pRecAR->adoEOF)
{
stARInfo.strMediumName.Empty();
stARInfo.iMediumID = pRecAR->GetCollect(_T("AR")).iVal;
stARInfo.strMediumName = (LPCTSTR)(_bstr_t)pRecAR->GetCollect(_T("MEname"));
vtQueryAR.push_back(stARInfo);
pRecAR->MoveNext();
}
pRecAR->Close();
}
void CTaskDataOper::QueryCmInfo(CString strCName, std::vector<STQueryCMInfo>& vtQueryCM)
{
vtQueryCM.clear();
_RecordsetPtr pRecCm = NULL;
pRecCm.CreateInstance(_uuidof(Recordset));
CString strSql = _T("");
strSql.Format(_T("select Clabel, Cvalue from cm where Cname = '%s' and LANG = %d"), strCName, g_iUILanguage);
pRecCm->Open(strSql.AllocSysString(),_variant_t((IDispatch*)theApp.m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText);
STQueryCMInfo stCmInfo;
while ((short)0 == pRecCm->adoEOF)
{
stCmInfo.strCLable.Empty();
stCmInfo.iVal = pRecCm->GetCollect(_T("Cvalue")).iVal;
stCmInfo.strCLable = (LPCTSTR)(_bstr_t)pRecCm->GetCollect(_T("Clabel"));
vtQueryCM.push_back(stCmInfo);
pRecCm->MoveNext();
}
pRecCm->Close();
}
bool CTaskDataOper::Query2DSptInfo(int iSptID, int &iMinLayer,int &iMaxLayer)
{
iMaxLayer = iMinLayer = 0;
_RecordsetPtr pRecSpt = NULL;
pRecSpt.CreateInstance(_uuidof(Recordset));
CString strSql = _T("");
strSql.Format(_T("select min(Layer) as MinLayer, max(Layer) as MaxLayer from script2d where CHID in (select ID from channel where SCID = %d and CHnumber = 1)"), iSptID);
pRecSpt->Open(strSql.AllocSysString(),_variant_t((IDispatch*)theApp.m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText);
bool bRes = false;
if (pRecSpt->GetRecordCount() > 0)
{
iMinLayer = pRecSpt->GetCollect(_T("MinLayer")).lVal;
iMaxLayer = pRecSpt->GetCollect(_T("MaxLayer")).lVal;
bRes = true;
}
pRecSpt->Close();
return bRes;
}
bool CTaskDataOper::QuerySptElecTpMount(int iSptID, int &iEAmount, int &iTpMount)
{
iTpMount = iEAmount = 0;
_RecordsetPtr pRecSpt = NULL;
pRecSpt.CreateInstance(_uuidof(Recordset));
CString strSql = _T("");
strSql.Format(_T("select Eamount,TPamount from scon where ID = %d"), iSptID);
pRecSpt->Open(strSql.AllocSysString(),_variant_t((IDispatch*)theApp.m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText);
if (pRecSpt->GetRecordCount() > 0)
{
iEAmount = pRecSpt->GetCollect(_T("Eamount")).iVal;
iTpMount = pRecSpt->GetCollect(_T("TPamount")).lVal;
pRecSpt->Close();
return true;
}
else
{
pRecSpt->Close();
return false;
}
}
void CTaskDataOper::QueryTdBrowseInfo(std::vector<STTdBrowseInfo>& vtTdBrowseInfo, bool bIsQueryTimerTd)
{
vtTdBrowseInfo.clear();
_RecordsetPtr pRecTd = NULL;
pRecTd.CreateInstance(_uuidof(Recordset));
CString strSql = _T(""), strTxt = _T("");
strTxt = !bIsQueryTimerTd ? _T("") : _T("where IsAutoGenerate is not null");
strSql.Format(_T("select * from td %s"), strTxt);
try
{
STTdBrowseInfo stTdInfo;
pRecTd->Open(strSql.AllocSysString(),_variant_t((IDispatch*)theApp.m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText);
while(0 == pRecTd->adoEOF)
{
stTdInfo.strTaskName = (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("TDname"));
stTdInfo.iTaskID = pRecTd->GetCollect(_T("ID")).llVal;
vtTdBrowseInfo.push_back(stTdInfo);
pRecTd->MoveNext();
}
pRecTd->Close();
}
catch(_com_error e)
{
AfxMessageBox(e.Description());
return;
}
}
void CTaskDataOper::QueryTdBrowseInfo(std::vector<STTdBrowseInfo>& vtTdBrowseInfo, int iSptType, int iType ,bool bIsQueryTimerTd)
{
vtTdBrowseInfo.clear();
_RecordsetPtr pRecTd = NULL;
pRecTd.CreateInstance(_uuidof(Recordset));
CString strSql = _T(""), strTxt = _T("");
strTxt = !bIsQueryTimerTd ? _T("and IsAutoGenerate is null") : _T(" ");
strSql.Format(_T("select * from td where Stype = %d and Ttype = %d %s "), iSptType, iType,strTxt);
try
{
STTdBrowseInfo stTdInfo;
pRecTd->Open(strSql.AllocSysString(),_variant_t((IDispatch*)theApp.m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText);
while(0 == pRecTd->adoEOF)
{
stTdInfo.strTaskName = (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("TDname"));
stTdInfo.iTaskID = pRecTd->GetCollect(_T("ID")).llVal;
vtTdBrowseInfo.push_back(stTdInfo);
pRecTd->MoveNext();
}
pRecTd->Close();
}
catch(_com_error e)
{
AfxMessageBox(e.Description());
return;
}
}
bool CTaskDataOper::QueryTaskPacketAttr(int& iLoopTime, int& iInterval, CString& strPlcID)
{
_RecordsetPtr pRecTd = NULL;
pRecTd.CreateInstance(_uuidof(Recordset));
CString strSql = _T("select * from tdTaskPacket where MainID = 1");
try
{
STTdBrowseInfo stTdInfo;
pRecTd->Open(strSql.AllocSysString(),_variant_t((IDispatch*)theApp.m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText);
if (pRecTd->GetRecordCount()>0)
{
strPlcID = (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("PLCID"));
iLoopTime = pRecTd->GetCollect(_T("LoopTimes")).llVal;
iInterval = pRecTd->GetCollect(_T("Interval")).llVal;
}
pRecTd->Close();
}
catch(_com_error e)
{
AfxMessageBox(e.Description());
return false;
}
return true;
}
bool CTaskDataOper::QueryTaskPacketInfo(std::vector<STTdBrowseInfo>& vtTdBrowseInfo)
{
vtTdBrowseInfo.clear();
_RecordsetPtr pRecTd = NULL;
pRecTd.CreateInstance(_uuidof(Recordset));
CString strSql = _T("select * from tdTaskPacketInfo where TaskPacketID = 1");
try
{
STTdBrowseInfo stTdInfo;
pRecTd->Open(strSql.AllocSysString(),_variant_t((IDispatch*)theApp.m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText);
while(0 == pRecTd->adoEOF)
{
STTdBrowseInfo stTdBrowse;
stTdBrowse.strTaskName = (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("TaskName"));
stTdBrowse.iTaskID = pRecTd->GetCollect(_T("TaskID")).llVal;
vtTdBrowseInfo.push_back(stTdBrowse);
pRecTd->MoveNext();
}
pRecTd->Close();
}
catch(_com_error e)
{
AfxMessageBox(e.Description());
return false;
}
return true;
}
bool CTaskDataOper::QueryTdBasicInfo(int iTaskID, STQueryTaskBasicInfo* pTaskBasicInfo,CString strTaskCN)
{
_RecordsetPtr pRecTd = NULL;
_RecordsetPtr pRecCm = NULL;
pRecTd.CreateInstance(_uuidof(Recordset));
pRecCm.CreateInstance(_uuidof(Recordset));
CString strSql = _T(""), strErr = _T("");
CString strTemp;
if (strTaskCN.IsEmpty())
{
strSql.Format(_T("select a.*, b.AR as AR, b.ID as TdChanID from td a, tdchannel b where a.ID = %d and a.ID = b.TDID and b.CHnumber = 1"), iTaskID);
}
else
{
strSql.Format(_T("select a.*, b.AR as AR, b.ID as TdChanID from td a, tdchannel b where a.TDCN = '%s' and a.ID = b.TDID and b.CHnumber = 1"), strTaskCN);
}
pRecTd->Open(strSql.AllocSysString(),_variant_t((IDispatch*)theApp.m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText);
if (pRecTd->GetRecordCount() > 0)
{
CStringArray strArray;
pTaskBasicInfo->iTaskID = pRecTd->GetCollect(_T("ID")).iVal;
pTaskBasicInfo->iAR = pRecTd->GetCollect(_T("AR")).iVal;
pTaskBasicInfo->iTestType = pRecTd->GetCollect(_T("Ttype")).intVal;
strTemp = pRecTd->GetCollect(_T("TDname")).bstrVal;
strcpy(pTaskBasicInfo->szTaskName, strTemp);
strTemp.Empty();
strTemp = pRecTd->GetCollect(_T("Sname")).bstrVal;
strcpy(pTaskBasicInfo->szSptName, strTemp);
pTaskBasicInfo->iSptType = pRecTd->GetCollect(_T("Stype")).intVal;
pTaskBasicInfo->iStartElec = pRecTd->GetCollect(_T("StartElec")).lVal;
pTaskBasicInfo->iEndElec = pRecTd->GetCollect(_T("EndElec")).lVal;
pTaskBasicInfo->iEamount = pRecTd->GetCollect(_T("Eamount")).lVal;
pTaskBasicInfo->iTestPeriod = pRecTd->GetCollect(_T("TRfrequency")).intVal;
//pTaskBasicInfo->fPoleSpace = (VT_NULL == pRecTd->GetCollect(_T("Edistance")).vt) ? 0 : atof((LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("Edistance")));
strTemp = (pRecTd->GetCollect(_T("Edistance")).vt == VT_NULL) ? _T("") : (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("Edistance"));
strArray.RemoveAll();
SplitterString(strArray, strTemp, ",");
pTaskBasicInfo->fXElecDistance = atof(strArray.GetAt(0));
if (strArray.GetSize() > 1)
{
pTaskBasicInfo->fYElecDistance = atof(strArray.GetAt(1));
}
strTemp = (pRecTd->GetCollect(_T("Espace")).vt == VT_NULL) ? _T("") : (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("Espace"));
strArray.RemoveAll();
SplitterString(strArray, strTemp, ",");
if (strArray.GetSize() >= 2)
{
pTaskBasicInfo->fXElecStep = atof(strArray.GetAt(0));
pTaskBasicInfo->fYElecStep = atof(strArray.GetAt(1));
}
strTemp = (pRecTd->GetCollect(_T("rect")).vt == VT_NULL) ? _T("") : (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("rect"));
strArray.RemoveAll();
SplitterString(strArray, strTemp, ",");
if (strArray.GetSize() >= 4)
{
pTaskBasicInfo->rcGridSize.left = atoi(strArray.GetAt(0));
pTaskBasicInfo->rcGridSize.top = atoi(strArray.GetAt(1));
pTaskBasicInfo->rcGridSize.right = atoi(strArray.GetAt(2));
pTaskBasicInfo->rcGridSize.bottom = atoi(strArray.GetAt(3));
}
pTaskBasicInfo->byLineDirection = (VT_NULL == pRecTd->GetCollect(_T("LineDirection")).vt) ? 0 : pRecTd->GetCollect(_T("LineDirection")).bVal;
pTaskBasicInfo->ucStack = (VT_NULL == pRecTd->GetCollect(_T("N")).vt) ? 1 : pRecTd->GetCollect(_T("N")).intVal;
pTaskBasicInfo->iSAInterval = (VT_NULL == pRecTd->GetCollect(_T("SAfrequency")).vt) ? 0 : pRecTd->GetCollect(_T("SAfrequency")).intVal;
pTaskBasicInfo->iCableLayout = (VT_NULL == pRecTd->GetCollect(_T("Clayout")).vt) ? 0 : pRecTd->GetCollect(_T("Clayout")).iVal;
pTaskBasicInfo->iTdChannelID = pRecTd->GetCollect(_T("TdChanID")).lVal;
strTemp = pRecTd->GetCollect(_T("TDCN")).bstrVal;
strcpy(pTaskBasicInfo->ucTaskID, strTemp);//, sizeof(pTaskBasicInfo->ucTaskID));
pTaskBasicInfo->ucOrgFlg = (VT_NULL == pRecTd->GetCollect(_T("OrgFlg")).vt) ? 0 : pRecTd->GetCollect(_T("OrgFlg")).lVal;
pTaskBasicInfo->uiStartTime = (VT_NULL == pRecTd->GetCollect(_T("STime")).vt) ? 0 : pRecTd->GetCollect(_T("STime")).lVal;
pTaskBasicInfo->uiEndTime = (VT_NULL == pRecTd->GetCollect(_T("ETime")).vt) ? 0 : pRecTd->GetCollect(_T("ETime")).lVal;
pTaskBasicInfo->uiTimerTime = (VT_NULL == pRecTd->GetCollect(_T("TTimer")).vt) ? 0 : pRecTd->GetCollect(_T("TTimer")).lVal;
//lVal
pTaskBasicInfo->uiCreateTime = (VT_NULL == pRecTd->GetCollect(_T("CreateTime")).vt) ? 0 : pRecTd->GetCollect(_T("CreateTime")).lVal;
pTaskBasicInfo->uiTotalNum = (VT_NULL == pRecTd->GetCollect(_T("TPamount")).vt) ? 0 : pRecTd->GetCollect(_T("TPamount")).lVal;
pTaskBasicInfo->ucTestGRFlag = (VT_NULL == pRecTd->GetCollect(_T("TestGRFlag")).vt) ? 0 : pRecTd->GetCollect(_T("TestGRFlag")).lVal;
CString strSCCN = (pRecTd->GetCollect(_T("SCCN")).vt == VT_NULL) ? _T("") : (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("SCCN"));
strcpy(pTaskBasicInfo->ucScriptCN, strSCCN);
strTemp = (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("rect_loc")).bstrVal;
strArray.RemoveAll();
SplitterString(strArray, strTemp, ",");
pTaskBasicInfo->uiStartLayer = 1;
pTaskBasicInfo->uiEndLayer = 1;
//if (!strArray.IsEmpty()&&(2 <= strArray.GetSize()))
if (2 == strArray.GetSize())
{
pTaskBasicInfo->uiStartLayer = atoi(strArray[0]); //atoi(strArray.GetAt(0));
pTaskBasicInfo->uiEndLayer = atoi(strArray[1]); //atoi(strArray.GetAt(1));
}
if (pTaskBasicInfo->iSptType == 1)
{
//暂时屏蔽,因为这里的有效电极的功能还未开发
// CString strRect = _T("");
// strRect = (VT_NULL == pRecTd->GetCollect(_T("rect")).vt) ? _T("") : (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("rect"));
// pTaskBasicInfo->iStartElec = pTaskBasicInfo->iEndElec = 0;
// if(!strRect.IsEmpty())
// {
// CStringArray arrPole;
// arrPole.RemoveAll();
// SplitterString(arrPole, strRect, _T(","));
// if(arrPole.GetSize() != 2)
// AfxMessageBox(_T("Parser 2D pole information error"));
// else
// {
// pTaskBasicInfo->iStartElec = atoi(arrPole[0]);
// pTaskBasicInfo->iEndElec = atoi(arrPole[1]);
// }
//
// }
//二维切割脚本的电极,因此不能取默认值,需从数据库读取实际需操作的电极
//pTaskBasicInfo->iStartElec = 1;
//pTaskBasicInfo->iEndElec = pTaskBasicInfo->iEamount;
}
else if(pTaskBasicInfo->iSptType == 2)
{
pTaskBasicInfo->iStartElec = 1;
pTaskBasicInfo->iEndElec = pTaskBasicInfo->iEamount;
}
else
{
pTaskBasicInfo->iStartElec = -2;
if (theApp.m_ucIsMultiChannel > 0)
pTaskBasicInfo->iEndElec = -2;
else
pTaskBasicInfo->iEndElec = -1*(theApp.m_ucMaxChannel+1);
}
pRecTd->Close();
strSql.Empty();
strSql.Format(_T("select MEname from medium where AR = %d and LANG = %d"),pTaskBasicInfo->iAR, g_iUILanguage);
pRecCm->Open(strSql.AllocSysString(),_variant_t((IDispatch*)theApp.m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText);
if (pRecCm->GetRecordCount() > 0)
{
CString strTemp;
strTemp = (LPCTSTR)(_bstr_t)pRecCm->GetCollect(_T("MEname"));
strcpy(pTaskBasicInfo->szARName, strTemp);
pRecCm->Close();
}
else
{
strErr.Empty();
pRecCm->Close();
if (LANG_ZHCN == g_iUILanguage)
{
strErr.Format(_T("未知装置类型(%d)"), pTaskBasicInfo->iAR);
AfxMessageBox(strErr);
}
else
{
strErr.Format(_T("Unknow medium type(%d)"), pTaskBasicInfo->iAR);
MessageBoxEx(NULL, strErr, STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
}
return false;
}
return true;
}
else
{
pRecTd->Close();
return false;
}
}
/*bool CTaskDataOper::QueryTdBasicInfoByTDCN(CString strTaskCN, STQueryTaskBasicInfo* pTaskBasicInfo)
{
_RecordsetPtr pRecTd = NULL;
_RecordsetPtr pRecCm = NULL;
pRecTd.CreateInstance(_uuidof(Recordset));
pRecCm.CreateInstance(_uuidof(Recordset));
CString strSql = _T(""), strErr = _T("");
CString strTaskId;
strSql.Format(_T("select a.*, b.AR as AR, b.ID as TdChanID from td a, tdchannel b where a.TDCN = '%s' and a.ID = b.TDID and b.CHnumber = 1"), strTaskCN);
pRecTd->Open(strSql.AllocSysString(), _variant_t((IDispatch*)theApp.m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText);
if (pRecTd->GetRecordCount() > 0)
{
pTaskBasicInfo->iAR = pRecTd->GetCollect(_T("AR")).iVal;
pTaskBasicInfo->iTestType = pRecTd->GetCollect(_T("Ttype")).lVal;
pTaskBasicInfo->strTaskName = pRecTd->GetCollect(_T("TDname")).bstrVal;
pTaskBasicInfo->strSptName = pRecTd->GetCollect(_T("Sname")).bstrVal;
pTaskBasicInfo->iSptType = pRecTd->GetCollect(_T("Stype")).iVal;
pTaskBasicInfo->iEamount = pRecTd->GetCollect(_T("Eamount")).iVal;
pTaskBasicInfo->iTestPeriod = pRecTd->GetCollect(_T("TRfrequency")).iVal;
pTaskBasicInfo->fPoleSpace = (VT_NULL == pRecTd->GetCollect(_T("Edistance")).vt) ? 0 : atof((LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("Edistance")));
pTaskBasicInfo->ucStack = (VT_NULL == pRecTd->GetCollect(_T("N")).vt) ? 1 : pRecTd->GetCollect(_T("N")).iVal;
pTaskBasicInfo->iSAInterval = (VT_NULL == pRecTd->GetCollect(_T("SAfrequency")).vt) ? 0 : pRecTd->GetCollect(_T("SAfrequency")).iVal;
pTaskBasicInfo->iCableLayout = (VT_NULL == pRecTd->GetCollect(_T("Clayout")).vt) ? 0 : pRecTd->GetCollect(_T("Clayout")).iVal;
pTaskBasicInfo->iTdChannelID = pRecTd->GetCollect(_T("TdChanID")).lVal;
strTaskId = pRecTd->GetCollect(_T("TDCN")).bstrVal;
strcpy(pTaskBasicInfo->ucTaskID, strTaskId);//, sizeof(pTaskBasicInfo->ucTaskID));
pTaskBasicInfo->ucOrgFlg = (VT_NULL == pRecTd->GetCollect(_T("OrgFlg")).vt) ? 0 : pRecTd->GetCollect(_T("OrgFlg")).iVal;
pTaskBasicInfo->uiStartTime = (VT_NULL == pRecTd->GetCollect(_T("STime")).vt) ? 0 : pRecTd->GetCollect(_T("STime")).iVal;
pTaskBasicInfo->uiEndTime = (VT_NULL == pRecTd->GetCollect(_T("ETime")).vt) ? 0 : pRecTd->GetCollect(_T("ETime")).iVal;
pTaskBasicInfo->uiTimerTime = (VT_NULL == pRecTd->GetCollect(_T("TTimer")).vt) ? 0 : pRecTd->GetCollect(_T("TTimer")).iVal;
pTaskBasicInfo->uiTotalNum = (VT_NULL == pRecTd->GetCollect(_T("TPamount")).vt) ? 0 : pRecTd->GetCollect(_T("TPamount")).iVal;
CString RectLocal = (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("rect_loc")).bstrVal;
CStringArray strArray;
strArray.RemoveAll();
SplitterString(strArray, RectLocal, ",");
pTaskBasicInfo->uiStartLayer = 1;
pTaskBasicInfo->uiEndLayer = 1;
//if (!strArray.IsEmpty()&&(2 <= strArray.GetSize()))
if (2 == strArray.GetSize())
{
pTaskBasicInfo->uiStartLayer = atoi(strArray[0]); //atoi(strArray.GetAt(0));
pTaskBasicInfo->uiEndLayer = atoi(strArray[1]); //atoi(strArray.GetAt(1));
}
if (pTaskBasicInfo->iSptType == 1)
{
//暂时屏蔽,因为这里的有效电极的功能还未开发
// CString strRect = _T("");
// strRect = (VT_NULL == pRecTd->GetCollect(_T("rect")).vt) ? _T("") : (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("rect"));
// pTaskBasicInfo->iStartElec = pTaskBasicInfo->iEndElec = 0;
// if(!strRect.IsEmpty())
// {
// CStringArray arrPole;
// arrPole.RemoveAll();
// SplitterString(arrPole, strRect, _T(","));
// if(arrPole.GetSize() != 2)
// AfxMessageBox(_T("Parser 2D pole information error"));
// else
// {
// pTaskBasicInfo->iStartElec = atoi(arrPole[0]);
// pTaskBasicInfo->iEndElec = atoi(arrPole[1]);
// }
//
// }
pTaskBasicInfo->iStartElec = 1;
pTaskBasicInfo->iEndElec = pTaskBasicInfo->iEamount;
}
else if (pTaskBasicInfo->iSptType == 2)
{
pTaskBasicInfo->iStartElec = 1;
pTaskBasicInfo->iEndElec = pTaskBasicInfo->iEamount;
}
else
{
pTaskBasicInfo->iStartElec = -2;
if (theApp.m_ucIsMultiChannel > 0)
pTaskBasicInfo->iEndElec = -2;
else
pTaskBasicInfo->iEndElec = -1 * (theApp.m_ucMaxChannel + 1);
}
pRecTd->Close();
strSql.Empty();
strSql.Format(_T("select MEname from medium where AR = %d and LANG = %d"), pTaskBasicInfo->iAR, g_iUILanguage);
pRecCm->Open(strSql.AllocSysString(), _variant_t((IDispatch*)theApp.m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText);
if (pRecCm->GetRecordCount() > 0)
{
pTaskBasicInfo->strARName = (LPCTSTR)(_bstr_t)pRecCm->GetCollect(_T("MEname"));
pRecCm->Close();
}
else
{
strErr.Empty();
strErr.Format(_T("Unknow medium type(%d)"), pTaskBasicInfo->iAR);
pRecCm->Close();
AfxMessageBox(strErr);
return false;
}
return true;
}
else
{
pRecTd->Close();
return false;
}
}*/
bool CTaskDataOper::QueryOnLineTdDataFromSev(STRemTaskArg stTaskArg,UINT32 uiStartPoint, UINT32 uiEndPoint, char *pData)
{
if (NULL == pData)
{
return false;
}
int iLen = 0;
char *chStr = pData;
memcpy(chStr, stTaskArg.ucTaskID, MAX_NAME_LEN * sizeof(BYTE));
UINT32 uiNetStartPoint = htonl(uiStartPoint); //转网络序给云端
UINT32 uiNetEndPoint = htonl(uiEndPoint);
memcpy(&chStr[MAX_NAME_LEN * sizeof(BYTE)], &uiNetStartPoint, sizeof(UINT32));
memcpy(&chStr[MAX_NAME_LEN * sizeof(BYTE)+sizeof(UINT32)], &uiNetEndPoint, sizeof(UINT32));
int iSendLen = MAX_NAME_LEN * sizeof(BYTE)+2 * sizeof(UINT32);
theApp.m_NetWorkOper.SetSuspendForThread(true);
CAutoLock autoLock(theApp.m_NetWorkOper.GetNetCriticalSection());
if (!theApp.m_NetWorkOper.SendCtrlMsgDirect(EN_REQ_DOWNLOAD_DATA_INFO, 0xFFFFFFFF, 1, (char*)chStr, iSendLen))
{
theApp.m_NetWorkOper.SetSuspendForThread(false);
if (theApp.m_NetWorkOper.GetLinkStatus())
{
if (LANG_ZHCN == g_iUILanguage)
AfxMessageBox(_T("下载任务数据发送失败"));
else
MessageBoxEx(NULL, _T("Download task data send failed."), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
}
return false;
}
int iTotalPoint = (uiEndPoint - uiStartPoint + 1);
int iRevLen = MAX_NAME_LEN*sizeof(BYTE)+sizeof(UINT32)+iTotalPoint*(11 * sizeof(float)+2 * sizeof(BYTE));
CString strLog;
strLog.Format(_T("zm:接收数据长度iRevLen=%d\n"), iRevLen);
OutputDebugString(strLog);
if (EN_RECV_SUCCESS == theApp.m_NetWorkOper.RecvMsgDirect(chStr, &iLen, iRevLen, 6000))
{
STSynTaskDataRes *ptTaskDataHeader = (STSynTaskDataRes *)chStr;
if ((iLen < iRevLen) || (iTotalPoint != ntohl(ptTaskDataHeader->dwPointNum)))
{
theApp.m_NetWorkOper.SetSuspendForThread(false);
return false;
}
}
theApp.m_NetWorkOper.SetSuspendForThread(false);
return true;
}
bool CTaskDataOper::QueryOnLineTdRgFromSev(STRemTaskArg stTaskArg,char *pRg)
{
char *chStr = pRg;
int iLen = 0;
if (NULL == pRg) { return false; }
memcpy(chStr, &stTaskArg.ucTaskID, MAX_NAME_LEN* sizeof(BYTE));
UINT32 uiStartElec = htonl(stTaskArg.uiStartElec); //转网络字节序给云端
UINT32 uiEndElec = htonl(stTaskArg.uiEndElec);
memcpy(&chStr[MAX_NAME_LEN* sizeof(BYTE)], &uiStartElec, sizeof(UINT32));
memcpy(&chStr[MAX_NAME_LEN* sizeof(BYTE)+sizeof(UINT32)], &uiEndElec, sizeof(UINT32));
int iSendLen = MAX_NAME_LEN * sizeof(BYTE)+2 * sizeof(UINT32);
theApp.m_NetWorkOper.SetSuspendForThread(true);
CAutoLock autoLock(theApp.m_NetWorkOper.GetNetCriticalSection());
if (!theApp.m_NetWorkOper.SendCtrlMsgDirect(EN_REQ_DOWNLOAD_RG_INFO, 0xFFFFFFFF, 1, (char*)chStr, iSendLen))
{
theApp.m_NetWorkOper.SetSuspendForThread(false);
if (LANG_ZHCN == g_iUILanguage)
AfxMessageBox(_T("下载任务接地电阻发送失败"));
else
MessageBoxEx(NULL, _T("Download task Rg send failed."), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
return false;
}
INT32 cTotalElec = (stTaskArg.uiEndElec - stTaskArg.uiStartElec + 1);
int iRevLen = cTotalElec * sizeof(STMeasuSigGRResult) + sizeof(INT32) + MAX_NAME_LEN;
if (EN_RECV_SUCCESS == theApp.m_NetWorkOper.RecvMsgDirect(chStr, &iLen, iRevLen, 5000))
{
INT32* pTotalElec = (INT32*)(&chStr[MAX_NAME_LEN]);
INT32 chRecElenNum = ntohl(*pTotalElec);
if ((iLen < iRevLen) || (cTotalElec != chRecElenNum))
{
theApp.m_NetWorkOper.SetSuspendForThread(false);
if (LANG_ZHCN == g_iUILanguage)
AfxMessageBox(_T("下载任务接地电阻接收失败"));
else
MessageBoxEx(NULL, _T("Download task Rg recv failed."), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
return false;
}
}
theApp.m_NetWorkOper.SetSuspendForThread(false);
return true;
}
bool CTaskDataOper::QueryOnLineElecInfoFromSev(STRemTaskArg stTaskArg, char* pElecInfo)
{
char *chStr = pElecInfo;
int iLen = 0;
if (NULL == pElecInfo)
{
return false;
}
memcpy(chStr, &stTaskArg.ucTaskID, MAX_NAME_LEN* sizeof(BYTE));
int iSendLen = MAX_NAME_LEN;
CAutoLock autoLock(theApp.m_NetWorkOper.GetNetCriticalSection());
if (!theApp.m_NetWorkOper.SendCtrlMsgDirect(EN_DOWNLOAD_ELECTRODE_COORDINATES_INFO, 0xFFFFFFFF, 1, (char*)chStr, iSendLen))
{
if (LANG_ZHCN == g_iUILanguage)
AfxMessageBox(_T("下载任务电极坐标发送失败"));
else
MessageBoxEx(NULL, _T("Download task electrode coordinates failed to send."), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
return false;
}
if (EN_RECV_SUCCESS == theApp.m_NetWorkOper.RecvMsgDirect(chStr, &iLen, 20080, 5000))
{
INT32* pTotalElec = (INT32*)(&chStr[MAX_NAME_LEN*2+sizeof(float)]);
INT32 chRecElenNum = ntohl(*pTotalElec);
if (chRecElenNum < 1)
{
theApp.m_NetWorkOper.SetSuspendForThread(false);
if (LANG_ZHCN == g_iUILanguage)
AfxMessageBox(_T("下载任务电极坐标接收失败"));
else
MessageBoxEx(NULL, _T("Failed to receive the download task electrode coordinates."), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
return false;
}
}
return true;
}
bool CTaskDataOper::QueryOnLineTdAttrFromSev(STRemTaskTable stTaskTable, STRemTaskArg *pstTaskArg)
{
char chSendStr[50] = {0};
char chMsgSyn[300] = { 0 };
chSendStr[0] = 0; chSendStr[1] = 0; chSendStr[2] = 0; chSendStr[3] = 1;
strncpy(&chSendStr[4], stTaskTable.ucTaskID, MAX_NAME_LEN*sizeof(BYTE));
theApp.m_NetWorkOper.SetSuspendForThread(true);
int iSendLen = sizeof(UINT32)+sizeof(BYTE)*MAX_NAME_LEN;
CAutoLock autoLock(theApp.m_NetWorkOper.GetNetCriticalSection());
if (!theApp.m_NetWorkOper.SendCtrlMsgDirect(EN_REQ_DOWNLOAD_TASK_ARG, 0xFFFFFFFF, 1, chSendStr, iSendLen))
{
if (LANG_ZHCN == g_iUILanguage)
AfxMessageBox(_T("同步任务参数发送失败"));
else
MessageBoxEx(NULL, _T("Synchronization task arguments send failed."), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
return false;
}
int iLen = 0;
if (EN_RECV_SUCCESS == theApp.m_NetWorkOper.RecvMsgDirect(chMsgSyn, &iLen, sizeof(chMsgSyn), 2000))
{
UINT32 *uiRevData = NULL;
uiRevData = (UINT32*)(chMsgSyn);
UINT32 uiRevDataNum = ntohl(uiRevData[0]);
if ((uiRevDataNum < 1) || (iLen < (sizeof(UINT32)+uiRevDataNum * sizeof(STRemTaskArg))))
{
theApp.m_NetWorkOper.SetSuspendForThread(false);
return false;
}
STRemTaskArg *ptTaskArg = (STRemTaskArg *)(chMsgSyn + sizeof(UINT32));
memcpy(pstTaskArg, ptTaskArg, sizeof(STRemTaskArg));
}
theApp.m_NetWorkOper.SetSuspendForThread(false);
STRemTaskArg *ptTaskArg = pstTaskArg;
strcpy(ptTaskArg->ucTDName, U2G(ptTaskArg->ucTDName));
strcpy(ptTaskArg->ucSciptName, U2G(ptTaskArg->ucSciptName));
ptTaskArg->stMeasuArg.ucTestType = ptTaskArg->stMeasuArg.ucTestType;
ptTaskArg->stMeasuArg.ucSptType = ptTaskArg->stMeasuArg.ucSptType;
ptTaskArg->stMeasuArg.iSAInterval = ntohl(ptTaskArg->stMeasuArg.iSAInterval);
//ptTaskArg->stMeasuArg.fElecSpace = tcp_ntohf(ptTaskArg->stMeasuArg.fElecSpace);
ptTaskArg->stMeasuArg.fXElecDistance = tcp_ntohf(ptTaskArg->stMeasuArg.fXElecDistance);
ptTaskArg->stMeasuArg.fYElecDistance = tcp_ntohf(ptTaskArg->stMeasuArg.fYElecDistance);
ptTaskArg->stMeasuArg.fXElecStep = tcp_ntohf(ptTaskArg->stMeasuArg.fXElecStep);
ptTaskArg->stMeasuArg.fYElecStep = tcp_ntohf(ptTaskArg->stMeasuArg.fYElecStep);
ptTaskArg->stMeasuArg.rcGridSize.left = ntohl(ptTaskArg->stMeasuArg.rcGridSize.left);
ptTaskArg->stMeasuArg.rcGridSize.top = ntohl(ptTaskArg->stMeasuArg.rcGridSize.top);
ptTaskArg->stMeasuArg.rcGridSize.right = ntohl(ptTaskArg->stMeasuArg.rcGridSize.right);
ptTaskArg->stMeasuArg.rcGridSize.bottom = ntohl(ptTaskArg->stMeasuArg.rcGridSize.bottom);
ptTaskArg->stMeasuArg.byLineDirection = ptTaskArg->stMeasuArg.byLineDirection;
ptTaskArg->uiStartElec = ntohl(ptTaskArg->uiStartElec);
ptTaskArg->uiEndElec = ntohl(ptTaskArg->uiEndElec);
ptTaskArg->uiStartLayer = ntohl(ptTaskArg->uiStartLayer);
ptTaskArg->uiEndLayer = ntohl(ptTaskArg->uiEndLayer);
ptTaskArg->uiStartTime = ntohl(ptTaskArg->uiStartTime);
ptTaskArg->uiEndTime = ntohl(ptTaskArg->uiEndTime);
ptTaskArg->uiTimerTime = ntohl(ptTaskArg->uiTimerTime);
ptTaskArg->uiTotalNum = ntohl(ptTaskArg->uiTotalNum);
ptTaskArg->uiCreateTime = ntohl(ptTaskArg->uiCreateTime);
return true;
}
#define MAX_DOWNLOAD_POINT_NUM (50)
/*bool CTaskDataOper::DownloadOnLineTd(STTaskListItem& iTaskpt)//单任务下载
{
STTaskListItem *pstTaskInfo = &iTaskpt;
STRemTaskTable *pstTaskTable = (STRemTaskTable *)&iTaskpt;
STRemTaskArg stTaskArg;
if (!QueryOnLineTdAttrFromSev(*pstTaskTable, &stTaskArg))//任务参数获取
{
return false;
}
char *pRg =(char*)malloc(sizeof(char)* 2700);
if (!QueryOnLineTdRgFromSev(stTaskArg,pRg))//接地电阻获取
{
if (NULL != pRg) { free(pRg); pRg = NULL; }
//return false;
}
CString szDevSN; szDevSN.Format(_T("SN%u"), m_uiDevID);
DWORD dwTdID;
//判断任务是否存在
BOOL bTaskExistFlg = theApp.m_pTdManager->OnlineCheckTdExist(pstTaskTable->ucTaskID, szDevSN, &dwTdID);
DWORD dwTotalElec = stTaskArg.uiEndElec - stTaskArg.uiStartElec + 1;
if (!bTaskExistFlg)
{
theApp.m_pTdManager->OnlineSevTDListSynToDB(&stTaskArg, szDevSN); //更新任务参数信息
if (NULL != pRg && EN_TASK_YES_SYN == pstTaskInfo->eSynStatus)
{
for (int i = 0; i < dwTotalElec; i++)
{
char *pData = (&pRg[1 + i*sizeof(STMeasuSigGRResult)]);
UpdateGrData(dwTdID, pData, stTaskArg.stMeasuArg.ucSptType, 1);
}
}
}
else
{
dwTdID = theApp.m_pTdManager->OnLineImportTdHeadToDB(&stTaskArg, szDevSN);//新建任务并插入任务参数信息
if (NULL != pRg)
{
InsertGrData(dwTdID, (DWORD)dwTotalElec, &pRg[1], stTaskArg.stMeasuArg.ucSptType);
}
}
if (NULL != pRg) { free(pRg); }
STQueryTaskBasicInfo stTaskBasicInfo;
QueryTdBasicInfo(dwTdID, &stTaskBasicInfo);
char *pData = (char*)malloc(sizeof(char)* 4095);
int i = 1;
UINT32 uiStartPoint = 1;
UINT32 uiEndPoint;
int iRecvNum = MAX_DOWNLOAD_POINT_NUM;
for (i = 1; i < stTaskArg.uiTotalNum + 1; i++)
{
if (i%MAX_DOWNLOAD_POINT_NUM == 0)
{
uiEndPoint = i;
}
else if (i == stTaskArg.uiTotalNum)
{
uiEndPoint = stTaskArg.uiTotalNum; // -uiStartPoint + 1;
}
else
{
continue;
}
int iSendCount;
for (iSendCount = 0; iSendCount < 3; iSendCount++) //失败重新下载三次
{
if (QueryOnLineTdDataFromSev(stTaskArg, uiStartPoint, uiEndPoint, pData))
{
break;
}
Sleep(200);
}
if (3 < iSendCount)//下载三次失败退出下载
{
if (NULL != pData) { free(pData); }
return false;
}
UINT32 iTotalPoint = uiEndPoint - uiStartPoint + 1;
for (int j = 0; j < iTotalPoint; j++)
{
if (!bTaskExistFlg)
{
STTaskDataRes *ptTaskData = (STTaskDataRes *)(pData + MAX_NAME_LEN * sizeof(BYTE)+sizeof(UINT32)+i*sizeof(STTaskDataRes));
STMeasuDataResBasic stMeasuBasicData;
stMeasuBasicData.iID = ntohl(ptTaskData->dwID);
stMeasuBasicData.fV = tcp_ntohf(ptTaskData->fV);
stMeasuBasicData.fI = tcp_ntohf(ptTaskData->fI);
stMeasuBasicData.fR0 = tcp_ntohf(ptTaskData->fR0);
stMeasuBasicData.fSP = tcp_ntohf(ptTaskData->fSP);
stMeasuBasicData.fK = tcp_ntohf(ptTaskData->fK);
stMeasuBasicData.ucAlram = ptTaskData->ucAlram;
stMeasuBasicData.ucStack = ptTaskData->ucStack;
stMeasuBasicData.fR0_LC = tcp_ntohf(ptTaskData->fR0_LC);
int iAttachLen = (1 == stTaskArg.stMeasuArg.ucTestType) ? sizeof(STMeasuDataResAttachIP) : 0;
UpdateTdBasicData(stTaskArg.stMeasuArg.ucSptType, stTaskArg.stMeasuArg.ucTestType, \
stTaskBasicInfo.iTdChannelID, stMeasuBasicData.iID, &stMeasuBasicData, ptTaskData + 1 + (j + 1)*sizeof(STMeasuDataResBasic)+j*iAttachLen);
}
else
{
STTaskDataRes *ptTaskData = (STTaskDataRes *)(pData + MAX_NAME_LEN * sizeof(BYTE)+sizeof(UINT32)+j*sizeof(STTaskDataRes));
STTaskDataRes stMeasuBasicData;
stMeasuBasicData.dwID = ntohl(ptTaskData->dwID);
stMeasuBasicData.fA = tcp_ntohf(ptTaskData->fA);
stMeasuBasicData.fB = tcp_ntohf(ptTaskData->fB);
stMeasuBasicData.fM = tcp_ntohf(ptTaskData->fM);
stMeasuBasicData.fN = tcp_ntohf(ptTaskData->fN);
stMeasuBasicData.fK = tcp_ntohf(ptTaskData->fK);
stMeasuBasicData.fV = tcp_ntohf(ptTaskData->fV);
stMeasuBasicData.fI = tcp_ntohf(ptTaskData->fI);
stMeasuBasicData.fR0 = tcp_ntohf(ptTaskData->fR0);
stMeasuBasicData.fSP = tcp_ntohf(ptTaskData->fSP);
stMeasuBasicData.fK = tcp_ntohf(ptTaskData->fK);
stMeasuBasicData.ucAlram = ptTaskData->ucAlram;
stMeasuBasicData.ucStack = ptTaskData->ucStack;
stMeasuBasicData.fR0_LC = tcp_ntohf(ptTaskData->fR0_LC);
OnlineDownloadRes2DData(&stMeasuBasicData, stTaskBasicInfo.iTdChannelID);
}
}
uiStartPoint = i + 1;
}
if (NULL != pData) { free(pData); }
return true;
}*/
/*bool CTaskDataOper::DownloadOnLineTdArray(std::vector<int> vtTaskpt)//多任务下载
{
for (int i = 0; i < vtTaskpt.size(); i++)
{
if (!DownloadOnLineTd(vtTaskpt))
{
return false;
}
}
}*/
void CTaskDataOper::QueryOnLineTdAttrToCtrl(CListCtrl& listAttr, STTaskListItem taskItem, STRemTaskArg *pstTaskArg)
{
char chSptType[][10] = { "VES", "2D", "3D" };
char chSendStr[50] = { 0 };
char chMsgSyn[300] = { 0 };
chSendStr[0] = 0; chSendStr[1] = 0; chSendStr[2] = 0; chSendStr[3] = 1;
strncpy(&chSendStr[4], taskItem.szTaskID, MAX_NAME_LEN*sizeof(BYTE));
theApp.m_NetWorkOper.SetSuspendForThread(false);
int iSendLen = sizeof(UINT32)+sizeof(BYTE)*MAX_NAME_LEN;
CAutoLock autoLock(theApp.m_NetWorkOper.GetNetCriticalSection());
if (!theApp.m_NetWorkOper.SendCtrlMsgDirect(EN_REQ_DOWNLOAD_TASK_ARG, 0xFFFFFFFF, 1, chSendStr, iSendLen))
{
theApp.m_NetWorkOper.SetSuspendForThread(false);
if (LANG_ZHCN == g_iUILanguage)
AfxMessageBox(_T("同步任务参数发送失败"));
else
MessageBoxEx(NULL, _T("Synchronization task arguments send failed."), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
return;
}
int iLen = 0;
if (EN_RECV_SUCCESS == theApp.m_NetWorkOper.RecvMsgDirect(chMsgSyn, &iLen, sizeof(chMsgSyn), 2000))
{
UINT32 *uiRevData = NULL;
uiRevData = (UINT32*)(chMsgSyn);
UINT32 uiRevDataNum = ntohl(uiRevData[0]);
if ((uiRevDataNum < 1) || (iLen < (sizeof(UINT32)+uiRevDataNum * sizeof(STRemTaskArg))))
{
theApp.m_NetWorkOper.SetSuspendForThread(false);
return;
}
STRemTaskArg *ptTaskArg = (STRemTaskArg *)(chMsgSyn + sizeof(UINT32));
//int iIndex = (int)VAL_ZERO;
//for (iIndex = 0; iIndex < uiRevDataNum; iIndex++)
{
ptTaskArg->stMeasuArg.iSAInterval = ntohl(ptTaskArg->stMeasuArg.iSAInterval);
//ptTaskArg->stMeasuArg.fElecSpace = tcp_ntohf(ptTaskArg->stMeasuArg.fElecSpace);
ptTaskArg->uiStartElec = ntohl(ptTaskArg->uiStartElec);
ptTaskArg->uiEndElec = ntohl(ptTaskArg->uiEndElec);
ptTaskArg->uiStartLayer = ntohl(ptTaskArg->uiStartLayer);
ptTaskArg->uiEndLayer = ntohl(ptTaskArg->uiEndLayer);
ptTaskArg->uiStartTime = ntohl(ptTaskArg->uiStartTime);
ptTaskArg->uiEndTime = ntohl(ptTaskArg->uiEndTime);
ptTaskArg->uiTimerTime = ntohl(ptTaskArg->uiTimerTime);
ptTaskArg->uiTotalNum = ntohl(ptTaskArg->uiTotalNum);
time_t tmTime = ptTaskArg->uiStartTime;
CString szTimeStart = Tm2LocalStr(tmTime);//Tm2GmtStr(tmTime);
tmTime = ptTaskArg->uiEndTime;
CString szTimeEnd = Tm2LocalStr(tmTime);//Tm2GmtStr(tmTime);
tmTime = ptTaskArg->uiTimerTime;
CString szTimeTimer = Tm2LocalStr(tmTime);//Tm2GmtStr(tmTime);
memcpy(pstTaskArg, ptTaskArg, sizeof(STRemTaskArg));//拷贝给后面用
CString str;
listAttr.SetItemText(0, 2, (LPCTSTR)(_bstr_t)U2G(ptTaskArg->ucTDName));
listAttr.SetItemText(1, 2, (LPCTSTR)(_bstr_t)ptTaskArg->ucTaskID);
listAttr.SetItemText(2, 2, (LPCTSTR)(_bstr_t)U2G(ptTaskArg->ucSciptName));
listAttr.SetItemText(3, 2, (LPCTSTR)(_bstr_t)chSptType[ptTaskArg->stMeasuArg.ucSptType]);
str.Empty(); str.Format(_T("%d"), ptTaskArg->uiEndElec-ptTaskArg->uiStartElec+1);
listAttr.SetItemText(6, 2, (LPCTSTR)(_bstr_t)str);
str.Empty(); str.Format(_T("%d"), ptTaskArg->uiTotalNum);
listAttr.SetItemText(7, 2, (LPCTSTR)(_bstr_t)str);
listAttr.SetItemText(8, 2, (LPCTSTR)(_bstr_t)ptTaskArg->stMeasuArg.ucStacking);
str.Empty();
m_iTestType = ptTaskArg->stMeasuArg.ucTestType;
if (0 == m_iTestType)
str = _T("0+0-");
else if (1 == m_iTestType)
str = _T("+0-0");
else
str = _T("0");
listAttr.SetItemText(9, 2, str);
//只有激电才有发射周期
str.Empty();
if (1 == ptTaskArg->stMeasuArg.ucTestType)
str.Format(_T("%d"), GetSigTxPeriod(ptTaskArg->stMeasuArg.ucTestType, ptTaskArg->stMeasuArg.ucTxPeriod) / 1000);
listAttr.SetItemText(10, 2, str);
//三维电极间距
if (2 == ptTaskArg->stMeasuArg.ucSptType)
{
str.Format(_T("%.2f,%.2f"), ptTaskArg->stMeasuArg.fXElecDistance, ptTaskArg->stMeasuArg.fYElecDistance);
}
//一维、二维电极间距
else
{
str.Format(_T("%.2f"), ptTaskArg->stMeasuArg.fXElecDistance);
}
listAttr.SetItemText(12, 2, str);
//listAttr.SetItemText(5, 2, (LPCTSTR)(_bstr_t)ptTaskArg->stMeasuArg.ucArrayType);
//listAttr.SetItemText(4, 2, (LPCTSTR)(_bstr_t)ptTaskArg->stMeasuArg.ucCableLayout(LPCTSTR)(_bstr_t)pRecCm->GetCollect(_T("Clabel")));
//listAttr.SetItemText(11, 2, (LPCTSTR)(_bstr_t)pRecCm->GetCollect(_T("Clabel")));
CString strSql = _T("");
_RecordsetPtr pRecCm = NULL;
pRecCm.CreateInstance(_uuidof(Recordset));
strSql.Empty();
strSql.Format(_T("select MEname from medium where AR = %d and LANG = %d"), ptTaskArg->stMeasuArg.ucArrayType, g_iUILanguage);
pRecCm->Open(strSql.AllocSysString(), _variant_t((IDispatch*)theApp.m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText);
if (pRecCm->GetRecordCount() > 0)
{
listAttr.SetItemText(5, 2, (LPCTSTR)(_bstr_t)pRecCm->GetCollect(_T("MEname")));
}
pRecCm->Close();
strSql.Empty();
strSql.Format(_T("select Clabel from cm where Cname = 'Ttype' and Cvalue = %d and LANG = %d"), m_iTestType, g_iUILanguage);
pRecCm->Open(strSql.AllocSysString(), _variant_t((IDispatch*)theApp.m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText);
if (pRecCm->GetRecordCount() > 0)
{
listAttr.SetItemText(4, 2, (LPCTSTR)(_bstr_t)pRecCm->GetCollect(_T("Clabel")));
}
pRecCm->Close();
if (ptTaskArg->stMeasuArg.ucCableLayout >= 0)
{
strSql.Empty();
strSql.Format(_T("select Clabel from cm where Cname = 'Clayout' and Cvalue = %d and LANG = %d"), ptTaskArg->stMeasuArg.ucCableLayout, g_iUILanguage);
pRecCm->Open(strSql.AllocSysString(), _variant_t((IDispatch*)theApp.m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText);
if (pRecCm->GetRecordCount() > 0)
{
listAttr.SetItemText(11, 2, (LPCTSTR)(_bstr_t)pRecCm->GetCollect(_T("Clabel")));
}
pRecCm->Close();
}
//填状态信息
_RecordsetPtr pRecTd = NULL;
pRecTd.CreateInstance(_uuidof(Recordset));
CString strTaskId = ptTaskArg->ucTaskID;
strTaskId.TrimLeft(); strTaskId.TrimRight();
strSql.Empty();
strSql.Format(_T("select TdStatus from td where TDCN = '%s'"), ptTaskArg->ucTaskID);
pRecTd->Open(strSql.AllocSysString(), _variant_t((IDispatch*)theApp.m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText);
BYTE bTdStatus;
if (pRecTd->GetRecordCount() > 0)
{
bTdStatus = pRecTd->GetCollect(_T("TdStatus")).bVal;
}
else
{
bTdStatus = EN_TASK_NO_DOWNLOAD;
}
pRecTd->Close();
str.Empty();
CString szTdStatus = OnLineLocalTaskState(bTdStatus);
listAttr.SetItemText(13, 2, (LPCTSTR)(_bstr_t)szTdStatus);
}
}
theApp.m_NetWorkOper.SetSuspendForThread(false);
}
void CTaskDataOper::QueryTdAttrToCtrl(CListCtrl& listAttr, int iTaskID)
{
//首先清空之前的数据信息
int iItemCnt = listAttr.GetItemCount();
for (int i = 0; i < iItemCnt; i++)
{
listAttr.SetItemText(i, 2, _T(""));
}
_RecordsetPtr pRecTd = NULL;
_RecordsetPtr pRecCm = NULL;
pRecTd.CreateInstance(_uuidof(Recordset));
pRecCm.CreateInstance(_uuidof(Recordset));
CString strSql = _T(""), strErr = _T("");
strSql.Format(_T("select a.*, b.AR as AR from td a, tdchannel b where a.ID = %d and a.ID = b.TDID and b.CHnumber = 1"), iTaskID);
char chSptType[][10] = {"VES", "2D", "3D"};
try
{
pRecTd->Open(strSql.AllocSysString(),_variant_t((IDispatch*)theApp.m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText);
int iAR = 0, iTType = 0, iClayout = -1, iTxPeriod = 0;
CString strTxt;
int iIndex = 0;
if (g_iOnLineVersion != EN_ON_LIEN_VERSION_1)
{
iIndex = 1;
}
if (pRecTd->GetRecordCount() > 0)
{
listAttr.SetItemText(0, 2, (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("TDname")));
listAttr.SetItemText(1 + iIndex, 2, (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("Sname")));
listAttr.SetItemText(2 + iIndex, 2, chSptType[pRecTd->GetCollect(_T("Stype")).iVal]);
listAttr.SetItemText(5 + iIndex, 2, (VT_NULL == pRecTd->GetCollect(_T("Eamount")).vt) ? _T("") : (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("Eamount")));
listAttr.SetItemText(6 + iIndex, 2, (VT_NULL == pRecTd->GetCollect(_T("TPamount")).vt) ? _T("") : (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("TPamount")));
listAttr.SetItemText(7 + iIndex, 2, (VT_NULL == pRecTd->GetCollect(_T("N")).vt) ? _T("") : (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("N")));
if (g_iOnLineVersion != EN_ON_LIEN_VERSION_1)
{
listAttr.SetItemText(1, 2, (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("TDCN")));
BYTE bTdStatus = pRecTd->GetCollect(_T("TdStatus")).bVal;
CString szTdStatus = OnLineLocalTaskState(bTdStatus);
listAttr.SetItemText(13, 2, (LPCTSTR)(_bstr_t)szTdStatus);
}
iAR = pRecTd->GetCollect(_T("AR")).iVal;
iTType = pRecTd->GetCollect(_T("Ttype")).iVal;
m_iTestType = iTType;
strTxt.Empty();
if (0 == m_iTestType)
strTxt = _T("0+0-");
else if (1 == m_iTestType)
strTxt = _T("+0-0");
else
strTxt = _T("0");
listAttr.SetItemText(8 + iIndex, 2, strTxt);
iClayout = (VT_NULL == pRecTd->GetCollect(_T("Clayout")).vt) ? -1 : pRecTd->GetCollect(_T("Clayout")).iVal;
iTxPeriod = (VT_NULL == pRecTd->GetCollect(_T("TRfrequency")).vt) ? -1 : pRecTd->GetCollect(_T("TRfrequency")).iVal;
//只有激电才有发射周期
strTxt.Empty();
if (1 == m_iTestType)
strTxt.Format(_T("%d"),GetSigTxPeriod(iTType, iTxPeriod)/1000);
listAttr.SetItemText(9 + iIndex, 2, strTxt);
listAttr.SetItemText(11 + iIndex, 2, (VT_NULL == pRecTd->GetCollect(_T("Edistance")).vt) ? _T("") : (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("Edistance")));
strSql.Empty();
strSql.Format(_T("select MEname from medium where AR = %d and LANG = %d"),iAR, g_iUILanguage);
pRecCm->Open(strSql.AllocSysString(),_variant_t((IDispatch*)theApp.m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText);
if (pRecCm->GetRecordCount() > 0)
{
listAttr.SetItemText(4 + iIndex, 2, (LPCTSTR)(_bstr_t)pRecCm->GetCollect(_T("MEname")));
}
pRecCm->Close();
strSql.Empty();
strSql.Format(_T("select Clabel from cm where Cname = 'Ttype' and Cvalue = %d and LANG = %d"), iTType, g_iUILanguage);
pRecCm->Open(strSql.AllocSysString(),_variant_t((IDispatch*)theApp.m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText);
if (pRecCm->GetRecordCount() > 0)
{
listAttr.SetItemText(3 + iIndex, 2, (LPCTSTR)(_bstr_t)pRecCm->GetCollect(_T("Clabel")));
}
pRecCm->Close();
if (iClayout >= 0)
{
strSql.Empty();
strSql.Format(_T("select Clabel from cm where Cname = 'Clayout' and Cvalue = %d and LANG = %d"), iClayout, g_iUILanguage);
pRecCm->Open(strSql.AllocSysString(),_variant_t((IDispatch*)theApp.m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText);
if (pRecCm->GetRecordCount() > 0)
{
listAttr.SetItemText(10 + iIndex, 2, (LPCTSTR)(_bstr_t)pRecCm->GetCollect(_T("Clabel")));
}
pRecCm->Close();
}
}
pRecTd->Close();
}
catch(_com_error e)
{
AfxMessageBox(e.Description());
pRecTd->Close();
pRecCm->Close();
}
}
#define MAX_REFRESH_POINT (50)
void CTaskDataOper::QueryOnLineTdDataToCtrl(STRemTaskArg stTaskArg, std::vector<STTaskDetailBasicData>& vtData)
{
UINT32 uiStartPoint;
UINT32 uiEndPoint;
UINT32 uiMaxRefreshNum = MAX_REFRESH_POINT;
char chStr[2700] = { 0 };
//服务器记录的是下一个需要测试的点
if (stTaskArg.uiTotalNum != stTaskArg.uiCurrentPoint)
{
stTaskArg.uiCurrentPoint = stTaskArg.uiCurrentPoint - 1;
}
if (stTaskArg.uiCurrentPoint < MAX_REFRESH_POINT)//if (stTaskArg.uiTotalNum < MAX_REFRESH_POINT)
{
//uiMaxRefreshNum = stTaskArg.uiTotalNum;
uiMaxRefreshNum = stTaskArg.uiCurrentPoint;
uiStartPoint = 1;
//uiEndPoint = stTaskArg.uiTotalNum;
uiEndPoint = stTaskArg.uiCurrentPoint;
}
else
{
//uiStartPoint = stTaskArg.uiTotalNum - MAX_REFRESH_POINT + 1;
//uiEndPoint = stTaskArg.uiTotalNum;
uiStartPoint = stTaskArg.uiCurrentPoint - MAX_REFRESH_POINT + 1;
uiEndPoint = stTaskArg.uiCurrentPoint;
}
memcpy(chStr, stTaskArg.ucTaskID, MAX_NAME_LEN * sizeof(BYTE));
UINT32 uiNetStartPoint = htonl(uiStartPoint); //转网络序给云端
UINT32 uiNetEndPoint = htonl(uiEndPoint);
memcpy(&chStr[MAX_NAME_LEN * sizeof(BYTE)], &uiNetStartPoint, sizeof(UINT32));
memcpy(&chStr[MAX_NAME_LEN * sizeof(BYTE)+sizeof(UINT32)], &uiNetEndPoint, sizeof(UINT32));
theApp.m_NetWorkOper.SetSuspendForThread(true);
CAutoLock autoLock(theApp.m_NetWorkOper.GetNetCriticalSection());
if (!theApp.m_NetWorkOper.SendCtrlMsgDirect(EN_REQ_DOWNLOAD_DATA_INFO, 0xFFFFFFFF, 1, (char*)chStr, MAX_NAME_LEN * sizeof(BYTE)+2 * sizeof(UINT32)))
{
theApp.m_NetWorkOper.SetSuspendForThread(false);
if (LANG_ZHCN == g_iUILanguage)
AfxMessageBox(_T("下载任务数据发送失败"));
else
MessageBoxEx(NULL, _T("Download task data send failed."), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
return;
}
int iLen = 0;
int iRevLen = MAX_NAME_LEN*sizeof(BYTE)+sizeof(UINT32)+uiMaxRefreshNum*(11 * sizeof(float)+2 * sizeof(BYTE));
if (EN_RECV_SUCCESS == theApp.m_NetWorkOper.RecvMsgDirect(chStr, &iLen, iRevLen, 6000))
{
vtData.clear();
STSynTaskDataRes *ptTaskDataHeader = (STSynTaskDataRes *)chStr;
if ((iLen < iRevLen) || (uiMaxRefreshNum != ntohl(ptTaskDataHeader->dwPointNum)))
{
theApp.m_NetWorkOper.SetSuspendForThread(false);
//AfxMessageBox(_T("Download task data recv failed."));
return;
}
for (int i = 0; i < uiMaxRefreshNum; i++)
{
STTaskDataRes *ptTaskData = (STTaskDataRes *)(chStr + MAX_NAME_LEN * sizeof(BYTE)+sizeof(UINT32)+i*sizeof(STTaskDataRes));
STTaskDataRes stMeasuBasicData;
stMeasuBasicData.dwID = ntohl(ptTaskData->dwID);
stMeasuBasicData.fA = tcp_ntohf(ptTaskData->fA);
stMeasuBasicData.fB = tcp_ntohf(ptTaskData->fB);
stMeasuBasicData.fM = tcp_ntohf(ptTaskData->fM);
stMeasuBasicData.fN = tcp_ntohf(ptTaskData->fN);
stMeasuBasicData.fK = tcp_ntohf(ptTaskData->fK);
stMeasuBasicData.fV = tcp_ntohf(ptTaskData->fV);
stMeasuBasicData.fI = tcp_ntohf(ptTaskData->fI);
stMeasuBasicData.fR0 = tcp_ntohf(ptTaskData->fR0);
stMeasuBasicData.fSP = tcp_ntohf(ptTaskData->fSP);
stMeasuBasicData.ucAlram = ptTaskData->ucAlram;
stMeasuBasicData.ucStack = ptTaskData->ucStack;
stMeasuBasicData.fR0_LC = tcp_ntohf(ptTaskData->fR0_LC);
STTaskDetailBasicData stTaskDetailData;
stTaskDetailData.iID = stMeasuBasicData.dwID;
stTaskDetailData.iA = stMeasuBasicData.fA;
stTaskDetailData.iB = stMeasuBasicData.fB;
stTaskDetailData.iM = stMeasuBasicData.fM;
stTaskDetailData.iN = stMeasuBasicData.fN;
stTaskDetailData.fK = stMeasuBasicData.fK;
stTaskDetailData.fV = stMeasuBasicData.fV;
stTaskDetailData.fI = stMeasuBasicData.fI;
stTaskDetailData.fR0 = stMeasuBasicData.fR0;
stTaskDetailData.fSP = stMeasuBasicData.fSP;
stTaskDetailData.ucStack = stMeasuBasicData.ucStack;
stTaskDetailData.ucIsUse = 1;// stMeasuBasicData.ucAlram;
vtData.push_back(stTaskDetailData);
}
}
theApp.m_NetWorkOper.SetSuspendForThread(false);
}
void CTaskDataOper::QueryTdDataToCtrl(CListCtrl& listData, int iTaskID, int iSptType, int iTestType)
{
listData.DeleteAllItems();
_RecordsetPtr pRecTd = NULL;
pRecTd.CreateInstance(_uuidof(Recordset));
CString strSql = _T("");
strSql.Format(_T("select * from td%ddcon where TCHID in (select id from tdchannel where TDID = %d and CHnumber=1) and bUse <> 0"),iSptType+1, iTaskID);
try
{
pRecTd->Open(strSql.AllocSysString(),_variant_t((IDispatch*)theApp.m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText);
CString strIndex;
int iItemIndex = 0;
VARIANT varIndex;
varIndex.vt = VT_BSTR;
float fVal, fV, fI;
int iSubIndex;
while(0 == pRecTd->adoEOF)
{
listData.InsertItem(iItemIndex, _T(""));
iSubIndex = 0;
strIndex = (0 == iSptType) ? _T("a") : _T("C1");
varIndex.bstrVal=(_bstr_t)strIndex;
listData.SetItemText(iItemIndex, iSubIndex++, (VT_NULL == pRecTd->GetCollect(varIndex).vt) ? _T("") : (LPCTSTR)(_bstr_t)pRecTd->GetCollect(varIndex));
strIndex = (0 == iSptType) ? _T("b") : _T("C2");
varIndex.bstrVal=(_bstr_t)strIndex;
listData.SetItemText(iItemIndex, iSubIndex++, (VT_NULL == pRecTd->GetCollect(varIndex).vt) ? _T("") : (LPCTSTR)(_bstr_t)pRecTd->GetCollect(varIndex));
//
strIndex = (0 == iSptType) ? _T("x") : _T("P1");
varIndex.bstrVal=(_bstr_t)strIndex;
listData.SetItemText(iItemIndex, iSubIndex++, (VT_NULL == pRecTd->GetCollect(varIndex).vt) ? _T("") : (LPCTSTR)(_bstr_t)pRecTd->GetCollect(varIndex));
strIndex = (0 == iSptType) ? _T("y") : _T("P2");
varIndex.bstrVal=(_bstr_t)strIndex;
listData.SetItemText(iItemIndex, iSubIndex++, (VT_NULL == pRecTd->GetCollect(varIndex).vt) ? _T("") : (LPCTSTR)(_bstr_t)pRecTd->GetCollect(varIndex));
listData.SetItemText(iItemIndex, iSubIndex++, (VT_NULL == pRecTd->GetCollect(_T("N")).vt) ? _T("") : (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("N")));
strIndex.Empty();
strIndex.Format(_T("%.2f"),(VT_NULL == pRecTd->GetCollect(_T("K")).vt) ? 0 : pRecTd->GetCollect(_T("K")).fltVal);
listData.SetItemText(iItemIndex, iSubIndex++, strIndex);
fV = (VT_NULL == pRecTd->GetCollect(_T("V")).vt) ? 0 : pRecTd->GetCollect(_T("V")).fltVal;
fI = (VT_NULL == pRecTd->GetCollect(_T("I")).vt) ? 0 : pRecTd->GetCollect(_T("I")).fltVal;
strIndex.Empty();
strIndex.Format(_T("%.2f"), fV);
listData.SetItemText(iItemIndex, iSubIndex++, strIndex);
strIndex.Empty();
strIndex.Format(_T("%.2f"),fI);
listData.SetItemText(iItemIndex, iSubIndex++, strIndex);
//电阻R
if (0 == iTestType)
{
strIndex.Empty();
strIndex.Format(_T("%.2f"),(fabs(fI) <= 0.000001) ? 0 : fV/fI);
listData.SetItemText(iItemIndex, iSubIndex++, strIndex);
}
//R0
strIndex.Empty();
strIndex.Format(_T("%.2f"),(VT_NULL == pRecTd->GetCollect(_T("R0")).vt) ? 0 : pRecTd->GetCollect(_T("R0")).fltVal);
listData.SetItemText(iItemIndex, iSubIndex++, strIndex);
//SP
strIndex.Empty();
strIndex.Format(_T("%.2f"),(VT_NULL == pRecTd->GetCollect(_T("SP")).vt) ? 0 : pRecTd->GetCollect(_T("SP")).fltVal);
listData.SetItemText(iItemIndex, iSubIndex++, strIndex);
iItemIndex++;
pRecTd->MoveNext();
}
pRecTd->Close();
}
catch(_com_error e)
{
AfxMessageBox(e.Description());
pRecTd->Close();
}
}
bool CTaskDataOper::OpenTdData(int iTaskID, BYTE ucTdType, WORD wStartTSN, WORD wMaxChannel)
{
CString strSql = _T(""), strErr = _T(""), strTd = _T("");
if (ucTdType > 2)
{
if (LANG_ZHCN == g_iUILanguage)
{
strErr.Format(_T("未知任务类型(%d)"), ucTdType);
AfxMessageBox(strErr);
}
else
{
strErr.Format(_T("Unknow Task type(%d)"), ucTdType);
MessageBoxEx(NULL, strErr, STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
}
return false;
}
m_iTdType = ucTdType;
strTd.Format(_T("td%ddcon"),m_iTdType+1);
CString strFilter = _T("");
if(wStartTSN > 0)
strFilter.Format(_T("and TSN >= %d"), wStartTSN);
m_iTdType = ucTdType;
strSql.Format(_T("select * from %s where TCHID in (select ID from tdchannel where TDID = %d and CHnumber = 1) %s order by TSN"), strTd,iTaskID, strFilter);
try
{
m_pRecTdData->Open(strSql.AllocSysString(),_variant_t((IDispatch*)theApp.m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText);
m_bIsOpenTdData = true;
m_wMaxChannel = wMaxChannel;
return true;
}
catch (_com_error e)
{
m_bIsOpenTdData = false;
AfxMessageBox(e.Description());
return false;
}
}
int CTaskDataOper::QueryNextTdBasicData(std::vector<STSigSndDataInfo>& vtTestData)
{
vtTestData.clear();
float fA, fB;
try
{
int iIndex = 0;
STSigSndDataInfo stSigData;
while (0 == m_pRecTdData->adoEOF)
{
memset(&stSigData, 0, sizeof(STSigSndDataInfo));
iIndex++;
stSigData.dwTsn = m_pRecTdData->GetCollect(_T("TSN")).lVal;
// CString strTxt = (0 == m_ucTdType) ? _T("a") : _T("C1");
//如果是一维的话,则下位机不需要ABMN的信息,所以这里都设置为0
if(0 == m_iTdType)
{
// stSigData.iA = stSigData.iB = 0;
// stSigData.iM = stSigData.iN = 0;
stSigData.fA = m_pRecTdData->GetCollect(_T("a")).fltVal;
stSigData.fB = m_pRecTdData->GetCollect(_T("b")).fltVal;
stSigData.fM = m_pRecTdData->GetCollect(_T("x")).fltVal;
stSigData.fN = m_pRecTdData->GetCollect(_T("y")).fltVal;
if (1 == iIndex)
{
fA = stSigData.fA;
fB = stSigData.fB;
}
else
{
if ((stSigData.fA) != fA || (stSigData.fB != fB) || iIndex > m_wMaxChannel)
return 1;
else
{
//在下发的时候需要将ABMN设置为0
stSigData.fA = stSigData.fB = 0;
stSigData.fM = stSigData.fN = 0;
}
}
}
else
{
stSigData.fA = m_pRecTdData->GetCollect(_T("C1")).iVal;
stSigData.fB = m_pRecTdData->GetCollect(_T("C2")).iVal;
stSigData.fM = m_pRecTdData->GetCollect(_T("P1")).iVal;
stSigData.fN = m_pRecTdData->GetCollect(_T("P2")).iVal;
// stSigData.fA = stSigData.fB = 0;
// stSigData.fX = stSigData.fY = 0;
if ( 1== iIndex)
{
fA = stSigData.fA;
fB = stSigData.fB;
}
else
{
if ((stSigData.fA) != fA || (stSigData.fB != fB)|| iIndex > m_wMaxChannel)
return 1;
}
}
stSigData.ucStack = m_pRecTdData->GetCollect(_T("N")).iVal;
stSigData.fK = m_pRecTdData->GetCollect(_T("K")).fltVal;
vtTestData.push_back(stSigData);
m_pRecTdData->MoveNext();
// return 1;
}
return 1;
}
catch (_com_error e)
{
AfxMessageBox(e.Description());
return -1;
}
}
bool CTaskDataOper::QueryTdDataFromTsn(int iTaskID, BYTE ucTdType, WORD wStartTSN, int iCnt, std::vector<STTaskDetailBasicData>& vtRes)
{
CString strSql = _T(""), strErr = _T(""), strTd = _T("");
if (ucTdType > 2)
{
if (LANG_ZHCN == g_iUILanguage)
{
strErr.Format(_T("未知任务类型(%d)"), ucTdType);
AfxMessageBox(strErr);
}
else
{
strErr.Format(_T("Unknow Task type(%d)"), ucTdType);
MessageBoxEx(NULL, strErr, STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
}
return false;
}
vtRes.clear();
//m_iTdType = ucTdType;
_RecordsetPtr pRecTd;
pRecTd.CreateInstance(_uuidof(Recordset));
strTd.Format(_T("td%ddcon"),ucTdType+1);
CString strFilter = _T("");
if(wStartTSN > 0)
{
if(iCnt >= 0)
strFilter.Format(_T("and TSN >= %d and TSN < %d"), wStartTSN, wStartTSN + iCnt);
else
strFilter.Format(_T("and TSN >= %d and TSN < %d"), wStartTSN + iCnt, wStartTSN);
}
strSql.Format(_T("select * from %s where TCHID in (select ID from tdchannel where TDID = %d and CHnumber = 1) %s order by TSN"), strTd,iTaskID, strFilter);
try
{
pRecTd->Open(strSql.AllocSysString(),_variant_t((IDispatch*)theApp.m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText);
while(pRecTd->adoEOF == 0 )
{
ST_TASK_DETAIL_BASIC_DATA stTaskDetailData;
memset(&stTaskDetailData, 0, sizeof(ST_TASK_DETAIL_BASIC_DATA));
if(0 == ucTdType)
{
// stTaskDetailData.iA = stTaskDetailData.iB = 0;
// stTaskDetailData.iM = stTaskDetailData.iN = 0;
stTaskDetailData.fA = pRecTd->GetCollect(_T("a")).fltVal;
stTaskDetailData.fB = pRecTd->GetCollect(_T("b")).fltVal;
stTaskDetailData.fX = pRecTd->GetCollect(_T("x")).fltVal;
stTaskDetailData.fY = pRecTd->GetCollect(_T("y")).fltVal;
}
else
{
stTaskDetailData.iA = pRecTd->GetCollect(_T("C1")).iVal;
stTaskDetailData.iB = pRecTd->GetCollect(_T("C2")).iVal;
stTaskDetailData.iM = pRecTd->GetCollect(_T("P1")).iVal;
stTaskDetailData.iN = pRecTd->GetCollect(_T("P2")).iVal;
// pMeasuBasicReq->fA = pMeasuBasicReq->fB = 0;
// pMeasuBasicReq->fX = pMeasuBasicReq->fY = 0;
}
stTaskDetailData.iID = pRecTd->GetCollect(_T("TSN")).lVal;
stTaskDetailData.ucStack = pRecTd->GetCollect(_T("N")).iVal;
stTaskDetailData.fK = pRecTd->GetCollect(_T("K")).fltVal;
stTaskDetailData.ucIsUse = pRecTd->GetCollect(_T("bUse")).boolVal;
if (0 != stTaskDetailData.ucIsUse)
{
stTaskDetailData.fV = pRecTd->GetCollect(_T("V")).fltVal;
stTaskDetailData.fI = pRecTd->GetCollect(_T("I")).fltVal;
stTaskDetailData.fR0 = pRecTd->GetCollect(_T("R0")).fltVal;
stTaskDetailData.fSP = pRecTd->GetCollect(_T("SP")).fltVal;
}
vtRes.push_back(stTaskDetailData);
pRecTd->MoveNext();
}
pRecTd->Close();
return true;
}
catch (_com_error e)
{
AfxMessageBox(e.Description());
pRecTd->Close();
return false;
}
}
//查询井最大深度
bool CTaskDataOper::QueryElecMaxWellDepthByCN(CString strScriptCN, BYTE ucTdType, STElecCoordinatesInfoHead& stElecInfoHead)
{
CString strSql = _T(""), strErr = _T("");
if (strScriptCN.IsEmpty())
{
if (LANG_ZHCN == g_iUILanguage)
{
strErr.Format(_T("脚本唯一标志"));
AfxMessageBox(strErr);
}
else
{
strErr.Format(_T("Script unique flag"));
MessageBoxEx(NULL, strErr, STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
}
return false;
}
_RecordsetPtr pRecTd;
pRecTd.CreateInstance(_uuidof(Recordset));
strSql.Format(_T("select WellMaxDepth from scon where CN='%s'"), strScriptCN);
try
{
pRecTd->Open(strSql.AllocSysString(), _variant_t((IDispatch*)theApp.m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText);
if (pRecTd->GetRecordCount() > 0)
{
stElecInfoHead.fMaxWellDepth = pRecTd->GetCollect(_T("WellMaxDepth")).fltVal;
}
pRecTd->Close();
}
catch (_com_error e)
{
AfxMessageBox(e.Description());
pRecTd->Close();
return false;
}
return true;
}
bool CTaskDataOper::QueryElecCoordinatesDataByCN(CString strScriptCN, BYTE ucTdType, WORD wStartSSN, int iCnt, std::vector<STElecCoordinatesInfoBody>& vtRes)
{
CString strSql = _T(""), strErr = _T("");
if (strScriptCN.IsEmpty())
{
if (LANG_ZHCN == g_iUILanguage)
{
strErr.Format(_T("脚本唯一标志"));
AfxMessageBox(strErr);
}
else
{
strErr.Format(_T("Script unique flag"));
MessageBoxEx(NULL, strErr, STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
}
return false;
}
vtRes.clear();
//m_iTdType = ucTdType;
_RecordsetPtr pRecTd;
pRecTd.CreateInstance(_uuidof(Recordset));
CString strFilter = _T("");
if (wStartSSN > 0)
{
if (iCnt >= 0)
strFilter.Format(_T("and SSN >= %d and SSN < %d"), wStartSSN, wStartSSN + iCnt);
else
strFilter.Format(_T("and SSN >= %d and SSN < %d"), wStartSSN + iCnt, wStartSSN);
}
strSql.Format(_T("select ElectrodeID,X,Y,Z from TCoordinatesInfo where ScriptCN='%s' %s order by SSN"), strScriptCN, strFilter);
try
{
pRecTd->Open(strSql.AllocSysString(), _variant_t((IDispatch*)theApp.m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText);
STElecCoordinatesInfoBody stTaskDetailData;
while (pRecTd->adoEOF == 0)
{
memset(&stTaskDetailData, 0, sizeof(STElecCoordinatesInfoBody));
stTaskDetailData.uiElecID = pRecTd->GetCollect(_T("ElectrodeID")).intVal;
stTaskDetailData.fX = pRecTd->GetCollect(_T("X")).fltVal;
stTaskDetailData.fY = pRecTd->GetCollect(_T("Y")).fltVal;
stTaskDetailData.fZ = pRecTd->GetCollect(_T("Z")).fltVal;
vtRes.push_back(stTaskDetailData);
pRecTd->MoveNext();
}
pRecTd->Close();
return true;
}
catch (_com_error e)
{
AfxMessageBox(e.Description());
pRecTd->Close();
return false;
}
}
bool CTaskDataOper::QueryPlcStatusData(std::vector<STPlcStatusInfo>& vtPlcStatus)
{
vtPlcStatus.clear();
CString strSql = _T("");
_RecordsetPtr pRecQuery;
pRecQuery.CreateInstance(_uuidof(Recordset));
strSql.Format(_T("select * from OnlineDevStatus order by id desc"));
try
{
pRecQuery->Open(strSql.AllocSysString(),_variant_t((IDispatch*)theApp.m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText);
STPlcStatusInfo stPlcStatus;
while(pRecQuery->adoEOF == 0 )
{
stPlcStatus.fAnalog[0] = pRecQuery->GetCollect(_T("AnaLogQua1")).fltVal;
stPlcStatus.fAnalog[1] = pRecQuery->GetCollect(_T("AnaLogQua2")).fltVal;
stPlcStatus.fAnalog[2] = pRecQuery->GetCollect(_T("AnaLogQua3")).fltVal;
stPlcStatus.fAnalog[3] = pRecQuery->GetCollect(_T("AnaLogQua4")).fltVal;
stPlcStatus.fAnalog[4] = pRecQuery->GetCollect(_T("AnaLogQua5")).fltVal;
stPlcStatus.fAnalog[5] = pRecQuery->GetCollect(_T("AnaLogQua6")).fltVal;
stPlcStatus.shCtrl[0] = pRecQuery->GetCollect(_T("CtrlK1")).iVal;
stPlcStatus.shCtrl[1] = pRecQuery->GetCollect(_T("CtrlK2")).iVal;
stPlcStatus.shCtrl[2] = pRecQuery->GetCollect(_T("CtrlK3")).iVal;
stPlcStatus.shCtrl[3] = pRecQuery->GetCollect(_T("CtrlK4")).iVal;
stPlcStatus.strRepDate.Empty();
stPlcStatus.strRepDate = (LPCTSTR)(_bstr_t)pRecQuery->GetCollect(_T("RepDate"));
stPlcStatus.strRepTime.Empty();
stPlcStatus.strRepTime = (LPCTSTR)(_bstr_t)pRecQuery->GetCollect(_T("RepTime"));
vtPlcStatus.push_back(stPlcStatus);
pRecQuery->MoveNext();
}
return true;
}
catch(_com_error e)
{
AfxMessageBox(e.Description());
return false;
}
}
bool CTaskDataOper::CreateSigTaskByAuto(const STTdBrowseInfo& stBasicTask, CString strTime, STTdBrowseInfo& stNewTask)
{
strTime.TrimLeft();
strTime.TrimRight();
CString strTxt = strTime,strErr = _T("");
// strTxt.TrimRight(_T(":00"));
strTxt.Remove(' ');
strTxt.Remove('-');
strTxt.Remove(':');
CStringArray strArrTime;
strArrTime.RemoveAll();
SplitterString(strArrTime, strTime, _T(" "));
if (strArrTime.GetSize() != 2)
{
if (LANG_ZHCN == g_iUILanguage)
{
strErr.Format(_T("解析时间错误.时间值 = %s"), strTime);
AfxMessageBox(strErr);
}
else
{
strErr.Format(_T("Parser time error.time value = %s"), strTime);
MessageBoxEx(NULL, strErr, STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
}
return false;
}
CString strNewTaskName = "";
strNewTaskName.Format(_T("%s_%s"), stBasicTask.strTaskName, strTxt);
CString strSql = _T("");
_RecordsetPtr pRecTd;
pRecTd.CreateInstance(_uuidof(Recordset));
_CommandPtr pCmdIns = NULL;
pCmdIns.CreateInstance(_uuidof(Command));
pCmdIns->ActiveConnection = theApp.m_pConnection;
int iNewTaskID = 0;
CGUCodeCreator guCode;
try
{
theApp.m_pConnection->BeginTrans();
strSql.Empty();
strSql.Format(_T("insert into td(TDname,TDCN,Tlocation,TZID,SCID,SCCN,Sname,Stype,Ttype,Tmode,Eamount,TPamount,CHamount,N,")
_T("TRwave,TRfrequency,Ifrequency,SAfrequency,Clayout,SkipCable,Espace,Edistance,Rdirection,CRtime,Cdate,Ctime) ")
_T("select '%s', '%s',Tlocation,TZID,SCID,SCCN,Sname,Stype,Ttype,Tmode,Eamount,TPamount,CHamount,N,TRwave,TRfrequency,")
_T("Ifrequency,SAfrequency,Clayout,SkipCable,Espace,Edistance,Rdirection,CRtime,#%s#,#%s# from td where ID = %d"),
strNewTaskName, guCode.GenerateGUIDCode(), strArrTime.GetAt(0), strArrTime.GetAt(1), stBasicTask.iTaskID);
pCmdIns->CommandText = strSql.AllocSysString();
pCmdIns->Execute(NULL, NULL, adCmdText);
strSql.Empty();
strSql.Format(_T("select ID, Stype,Edistance from td where ID in (select max(ID) as ID from td)"));
pRecTd->Open(strSql.AllocSysString(),_variant_t((IDispatch*)theApp.m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText);
iNewTaskID = pRecTd->GetCollect(_T("ID")).lVal;
int iSptType = pRecTd->GetCollect(_T("Stype")).iVal;
strTxt = (pRecTd->GetCollect(_T("Edistance")).vt == VT_NULL) ? _T("") : (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("Edistance"));
float fEdistance = 1;
if (1 == iSptType)
{
if (!strTxt.IsEmpty())
fEdistance = atof(strTxt);
}
pRecTd->Close();
strSql.Empty();
strSql.Format(_T("insert into tdchannel(TDID,CHnumber,AR) select %d,CHnumber,AR from tdchannel where TDID=%d and CHnumber=1 "),iNewTaskID, stBasicTask.iTaskID);
pCmdIns->CommandText = strSql.AllocSysString();
pCmdIns->Execute(NULL, NULL, adCmdText);
strSql.Empty();
strSql.Format(_T("select max(ID) as ID from tdchannel "));
pRecTd->Open(strSql.AllocSysString(),_variant_t((IDispatch*)theApp.m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText);
int iNewChanelID = pRecTd->GetCollect(_T("ID")).llVal;
pRecTd->Close();
strSql.Empty();
CString strTmp = (iSptType > 0) ? _T("C1,C2,P1,P2") : _T("a,b,x,y");
strSql.Format(_T("insert into td%ddcon(TCHID,TSN,%s,N,K,I,V,R0,SP,bUse) select %d,TSN,%s,N,K*%f as K_New,0,0,0,0,0 from td%ddcon where TCHID in ")
_T("(select id from tdchannel where TDID=%d and CHnumber=1)"),
iSptType+1, strTmp, iNewChanelID, strTmp, fEdistance,iSptType+1, stBasicTask.iTaskID);
pCmdIns->CommandText = strSql.AllocSysString();
pCmdIns->Execute(NULL, NULL, adCmdText);
theApp.m_pConnection->CommitTrans();
stNewTask.iTaskID = iNewTaskID;
stNewTask.strTaskName = strNewTaskName;
return true;
}
catch(_com_error e)
{
theApp.m_pConnection->RollbackTrans();
AfxMessageBox(e.Description());
AfxMessageBox(strSql);
return false;
}
}
bool CTaskDataOper::CreateTaskPacket(const std::vector<STTdBrowseInfo>& vtBasicTaskPacket, CString strSysTime, std::vector<STTdBrowseInfo>& vtNewTaskPacket)
{
vtNewTaskPacket.clear();
for (int i = 0; i < vtBasicTaskPacket.size(); i++)
{
STTdBrowseInfo stTdBorwse;
if (!CreateSigTaskByAuto(vtBasicTaskPacket[i], strSysTime, stTdBorwse))
{
if (LANG_ZHCN == g_iUILanguage)
AfxMessageBox(_T("创建自动任务包失败"));
else
MessageBoxEx(NULL, _T("Create auto task packet failed"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
vtNewTaskPacket.clear();
return false;
}
vtNewTaskPacket.push_back(stTdBorwse);
}
return true;
}
bool CTaskDataOper::AddTimerTask(int iTaskID, CString strTaskName, CString strTime, CString strPlcID)
{
strTime.TrimLeft();
strTime.TrimRight();
CString strTxt = strTime;
static UINT32 uiNumber = 0;
// strTxt.TrimRight(_T(":00"));
strTxt = strTxt.Left(strTxt.GetLength()-3);
strTxt.Remove(' ');
strTxt.Remove('-');
strTxt.Remove(':');
CString strNewTaskName = strTaskName, strSql = _T(""),strErr = _T("");
// strNewTaskName.Format(_T("%s_%s"),strTaskName, strTxt);
CStringArray strArrTime;
strArrTime.RemoveAll();
SplitterString(strArrTime, strTime, _T(" "));
if (strArrTime.GetSize() != 2)
{
if (LANG_ZHCN == g_iUILanguage)
{
strErr.Format(_T("解析时间错误.时间值 = %s"), strTime);
AfxMessageBox(strErr);
}
else
{
strErr.Format(_T("Parser time error.time value = %s"), strTime);
MessageBoxEx(NULL, strErr, STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
}
return false;
}
_RecordsetPtr pRecTd;
pRecTd.CreateInstance(_uuidof(Recordset));
_CommandPtr pCmdIns = NULL;
pCmdIns.CreateInstance(_uuidof(Command));
pCmdIns->ActiveConnection = theApp.m_pConnection;
int iNewTaskID = 0;
CGUCodeCreator guCode;
STQueryTaskBasicInfo stTaskBasicInfo;
QueryTdBasicInfo(iTaskID, &stTaskBasicInfo);
CString szTmpTime = strArrTime.GetAt(0)+" "+strArrTime.GetAt(1);
UINT32 uiTimerTime = Str2GmtTm(szTmpTime);
CString strDevSN = _T(""); strDevSN.Format("SN%u",m_uiDevID);
CString strTaskCN;
strTaskCN.Format("ERI%c%04d%02d%02d%02d%02d%02d%d_%s", ReturnTaskType(stTaskBasicInfo.iTestType), \
g_sysCurTime.wYear, g_sysCurTime.wMonth, g_sysCurTime.wDay, \
g_sysCurTime.wHour, g_sysCurTime.wMinute, g_sysCurTime.wSecond,uiNumber, strDevSN);
uiNumber++;
try
{
theApp.m_pConnection->BeginTrans();
strSql.Empty();
strSql.Format(_T("insert into td(TDname,TDCN,Tlocation,TZID,SCID,SCCN,Sname,Stype,Ttype,Tmode,Eamount,TPamount,CHamount,N,")
_T("TRwave,TRfrequency,Ifrequency,SAfrequency,Clayout,SkipCable,Espace,Edistance,Rdirection,CRtime,rect,rect_loc,Cdate,Ctime,DESN,TTimer,OrgFlg) ")
_T("select '%s', '%s',Tlocation,TZID,SCID,SCCN,Sname,Stype,Ttype,Tmode,Eamount,TPamount,CHamount,N,TRwave,TRfrequency,")
_T("Ifrequency,SAfrequency,Clayout,SkipCable,Espace,Edistance,Rdirection,CRtime,rect,rect_loc,#%s#,#%s#,'%s',%d,%d from td where ID = %d"),
strNewTaskName, strTaskCN, strArrTime.GetAt(0), strArrTime.GetAt(1), strDevSN, uiTimerTime, stTaskBasicInfo.ucOrgFlg, iTaskID);
pCmdIns->CommandText = strSql.AllocSysString();
pCmdIns->Execute(NULL, NULL, adCmdText);
strSql.Empty();
strSql.Format(_T("select ID, Stype,Edistance from td where ID in (select max(ID) as ID from td)"));
pRecTd->Open(strSql.AllocSysString(),_variant_t((IDispatch*)theApp.m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText);
iNewTaskID = pRecTd->GetCollect(_T("ID")).lVal;
int iSptType = pRecTd->GetCollect(_T("Stype")).iVal;
strTxt = (pRecTd->GetCollect(_T("Edistance")).vt == VT_NULL) ? _T("") : (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("Edistance"));
float fEdistance = 1;
if (1 == iSptType)
{
if (!strTxt.IsEmpty())
fEdistance = atof(strTxt);
}
pRecTd->Close();
strSql.Empty();
strSql.Format(_T("insert into tdchannel(TDID,CHnumber,AR) select %d,CHnumber,AR from tdchannel where TDID=%d and CHnumber=1 "),iNewTaskID, iTaskID);
pCmdIns->CommandText = strSql.AllocSysString();
pCmdIns->Execute(NULL, NULL, adCmdText);
strSql.Empty();
strSql.Format(_T("select max(ID) as ID from tdchannel "));
pRecTd->Open(strSql.AllocSysString(),_variant_t((IDispatch*)theApp.m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText);
int iNewChanelID = pRecTd->GetCollect(_T("ID")).llVal;
pRecTd->Close();
strSql.Empty();
CString strTmp = (iSptType > 0) ? _T("C1,C2,P1,P2") : _T("a,b,x,y");
strSql.Format(_T("insert into td%ddcon(TCHID,TSN,%s,N,K,I,V,R0,SP,bUse) select %d,TSN,%s,N,K*%f as K_New,0,0,0,0,0 from td%ddcon where TCHID in ")
_T("(select id from tdchannel where TDID=%d and CHnumber=1)"),
iSptType+1, strTmp, iNewChanelID, strTmp, fEdistance,iSptType+1, iTaskID);
pCmdIns->CommandText = strSql.AllocSysString();
pCmdIns->Execute(NULL, NULL, adCmdText);
strSql.Empty();
strSql.Format(_T("insert into task_timer (TDID,TdName,RunDate,RunTime,PLCID) values (%d, '%s', #%s#, #%s#,'%s')"),
iNewTaskID, strNewTaskName, strArrTime.GetAt(0), strArrTime.GetAt(1), strPlcID);
pCmdIns->CommandText = strSql.AllocSysString();
pCmdIns->Execute(NULL, NULL, adCmdText);
theApp.m_pConnection->CommitTrans();
return true;
}
catch(_com_error e)
{
theApp.m_pConnection->RollbackTrans();
AfxMessageBox(e.Description());
AfxMessageBox(strSql);
return false;
}
}
bool CTaskDataOper::QueryTdSigBasicData(int iTaskID, BYTE ucTdType, WORD wTSN, LPSTSigSndDataInfo pMeasuBasicReq)
{
CString strSql = _T(""), strErr = _T(""), strTd = _T("");
if (ucTdType > 2)
{
if (LANG_ZHCN == g_iUILanguage)
{
strErr.Format(_T("未知任务类型(%d)"), ucTdType);
AfxMessageBox(strErr);
}
else
{
strErr.Format(_T("Unknow Task type(%d)"), ucTdType);
MessageBoxEx(NULL, strErr, STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
}
return false;
}
_RecordsetPtr pRecTd;
pRecTd.CreateInstance(_uuidof(Recordset));
strTd.Format(_T("td%ddcon"),ucTdType+1);
strSql.Format(_T("select * from %s where TCHID in (select ID from tdchannel where TDID = %d and CHnumber = 1) and TSN = %d"), strTd,iTaskID, wTSN);
try
{
pRecTd->Open(strSql.AllocSysString(),_variant_t((IDispatch*)theApp.m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText);
if (pRecTd->GetRecordCount() < 1)
{
if (LANG_ZHCN == g_iUILanguage)
AfxMessageBox(_T("未查询到该数据信息"));
else
MessageBoxEx(NULL, _T("No query this data infomation"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
pRecTd->Close();
return false;
}
pMeasuBasicReq->dwTsn = wTSN;
// CString strTxt = (0 == m_ucTdType) ? _T("a") : _T("C1");
//如果是一维的话,则下位机不需要ABMN的信息,所以这里都设置为0
if(0 == ucTdType)
{
pMeasuBasicReq->fA = pRecTd->GetCollect(_T("a")).fltVal;
pMeasuBasicReq->fB = pRecTd->GetCollect(_T("b")).fltVal;
pMeasuBasicReq->fM = pRecTd->GetCollect(_T("x")).fltVal;
pMeasuBasicReq->fN = pRecTd->GetCollect(_T("y")).fltVal;
}
else
{
pMeasuBasicReq->fA = pRecTd->GetCollect(_T("C1")).iVal;
pMeasuBasicReq->fB = pRecTd->GetCollect(_T("C2")).iVal;
pMeasuBasicReq->fM = pRecTd->GetCollect(_T("P1")).iVal;
pMeasuBasicReq->fN = pRecTd->GetCollect(_T("P2")).iVal;
// pMeasuBasicReq->fA = pMeasuBasicReq->fB = 0;
// pMeasuBasicReq->fX = pMeasuBasicReq->fY = 0;
}
pMeasuBasicReq->ucStack = pRecTd->GetCollect(_T("N")).iVal;
pMeasuBasicReq->fK = pRecTd->GetCollect(_T("K")).fltVal;
pRecTd->Close();
return true;
}
catch (_com_error e)
{
AfxMessageBox(e.Description());
pRecTd->Close();
return false;
}
}
/*
void CTaskDataOper::InitialTaskTreeCtrl(CTreeCtrl& taskTree,int iSptType)
{
taskTree.DeleteAllItems();
CString strItem;
strItem.LoadString(IDS_TASK_TREE_ROOT+g_UIOffset);
HTREEITEM hRoot = taskTree.InsertItem(strItem,TVI_ROOT,TVI_LAST);
_RecordsetPtr pRecTd = NULL;
pRecTd.CreateInstance(_uuidof(Recordset));
CString strSql = _T("");
strSql.Format(_T("select ID, TDname from td where Stype = %d"), iSptType);
try
{
pRecTd->Open(strSql.AllocSysString(),_variant_t((IDispatch*)theApp.m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText);
HTREEITEM hChild;
DWORD dwTaskID = 0;
while(0 == pRecTd->adoEOF)
{
hChild = taskTree.InsertItem((VT_NULL == pRecTd->GetCollect(_T("TDname")).vt) ? _T("NULL") : (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("TDname")), hRoot);
dwTaskID = pRecTd->GetCollect(_T("ID")).lVal;
taskTree.SetItemData(hChild, dwTaskID);
pRecTd->MoveNext();
}
pRecTd->Close();
}
catch (_com_error e)
{
AfxMessageBox(e.Description());
pRecTd->Close();
}
}
*/
bool CTaskDataOper::OnlineUploadRes2DArg(DWORD dwTdID, STQueryTaskBasicInfo stQueryTdInfo)
{
int iLen = 0;
char chSendStr[500] = { 0 };
char chMsgSyn[1000] = { 0 };
//填基本信息
STRemTaskArg stTaskArg;
memset(&stTaskArg, 0, sizeof(stTaskArg));
stTaskArg.stMeasuArg.ucTxPeriod = stQueryTdInfo.iTestPeriod;
stTaskArg.stMeasuArg.ucTestType = stQueryTdInfo.iTestType;
stTaskArg.stMeasuArg.ucSptType = stQueryTdInfo.iSptType;
stTaskArg.stMeasuArg.ucCableLayout = stQueryTdInfo.iCableLayout;
stTaskArg.stMeasuArg.ucStacking = stQueryTdInfo.ucStack;
stTaskArg.stMeasuArg.iSAInterval = stQueryTdInfo.iSAInterval;
stTaskArg.stMeasuArg.ucArrayType = stQueryTdInfo.iAR;
//stTaskArg.stMeasuArg.fElecSpace = stQueryTdInfo.fPoleSpace;
stTaskArg.stMeasuArg.fXElecDistance = stQueryTdInfo.fXElecDistance;
stTaskArg.stMeasuArg.fYElecDistance = stQueryTdInfo.fYElecDistance;
stTaskArg.stMeasuArg.fXElecStep = stQueryTdInfo.fXElecStep;
stTaskArg.stMeasuArg.fYElecStep = stQueryTdInfo.fYElecStep;
stTaskArg.stMeasuArg.rcGridSize = stQueryTdInfo.rcGridSize;
stTaskArg.stMeasuArg.byLineDirection = stQueryTdInfo.byLineDirection;
stTaskArg.ucOrgFlg = stQueryTdInfo.ucOrgFlg;
strcpy(stTaskArg.ucTDName, G2U(stQueryTdInfo.szTaskName));
strcpy(stTaskArg.ucTaskID, stQueryTdInfo.ucTaskID);
strcpy(stTaskArg.ucSciptName, G2U(stQueryTdInfo.szSptName));
stTaskArg.uiStartElec = stQueryTdInfo.iStartElec;
stTaskArg.uiEndElec = stQueryTdInfo.iEndElec;
stTaskArg.uiStartLayer = stQueryTdInfo.uiStartLayer;
stTaskArg.uiEndLayer = stQueryTdInfo.uiEndLayer;
stTaskArg.uiStartTime = stQueryTdInfo.uiStartTime;
stTaskArg.uiEndTime = stQueryTdInfo.uiEndTime;
stTaskArg.uiTimerTime = stQueryTdInfo.uiTimerTime;
stTaskArg.uiTotalNum = stQueryTdInfo.uiTotalNum;
stTaskArg.ucOrgFlg = stQueryTdInfo.ucOrgFlg;
stTaskArg.ucTestGRFlag = stQueryTdInfo.ucTestGRFlag;
stTaskArg.uiCreateTime = stQueryTdInfo.uiCreateTime;
//字节序转换
UINT32 uiTaskNum = 1;//htonl(uiTaskNum);
uiTaskNum = htonl(uiTaskNum);
stTaskArg.stMeasuArg.iSAInterval = htonl(stTaskArg.stMeasuArg.iSAInterval);
//stTaskArg.stMeasuArg.fElecSpace = tcp_htonf(stTaskArg.stMeasuArg.fElecSpace);
stTaskArg.stMeasuArg.fXElecDistance = tcp_htonf(stTaskArg.stMeasuArg.fXElecDistance);
stTaskArg.stMeasuArg.fYElecDistance = tcp_htonf(stTaskArg.stMeasuArg.fYElecDistance);
stTaskArg.stMeasuArg.fXElecStep = tcp_htonf(stTaskArg.stMeasuArg.fXElecStep);
stTaskArg.stMeasuArg.fYElecStep = tcp_htonf(stTaskArg.stMeasuArg.fYElecStep);
stTaskArg.stMeasuArg.rcGridSize.left = htonl(stTaskArg.stMeasuArg.rcGridSize.left);
stTaskArg.stMeasuArg.rcGridSize.right = htonl(stTaskArg.stMeasuArg.rcGridSize.right);
stTaskArg.stMeasuArg.rcGridSize.top = htonl(stTaskArg.stMeasuArg.rcGridSize.top);
stTaskArg.stMeasuArg.rcGridSize.bottom = htonl(stTaskArg.stMeasuArg.rcGridSize.bottom);
stTaskArg.stMeasuArg.byLineDirection = stTaskArg.stMeasuArg.byLineDirection;
stTaskArg.uiStartElec = htonl(stTaskArg.uiStartElec);
stTaskArg.uiEndElec = htonl(stTaskArg.uiEndElec);
stTaskArg.uiStartLayer = htonl(stTaskArg.uiStartLayer);
stTaskArg.uiEndLayer = htonl(stTaskArg.uiEndLayer);
stTaskArg.uiStartTime = htonl(stTaskArg.uiStartTime);
stTaskArg.uiEndTime = htonl(stTaskArg.uiEndTime);
stTaskArg.uiTimerTime = htonl(stTaskArg.uiTimerTime);
stTaskArg.uiTotalNum = htonl(stTaskArg.uiTotalNum);
stTaskArg.uiCreateTime = htonl(stTaskArg.uiCreateTime);
memcpy(chSendStr, &uiTaskNum, sizeof(UINT32));
memcpy(&chSendStr[sizeof(UINT32)], &stTaskArg, sizeof(stTaskArg));
theApp.m_NetWorkOper.SetSuspendForThread(true);
CAutoLock autoLock(theApp.m_NetWorkOper.GetNetCriticalSection());
if (!theApp.m_NetWorkOper.SendCtrlMsgDirect(EN_UPLOAD_TASK_ARG, 0xFFFFFFFF, 1, (char*)chSendStr, sizeof(UINT32)+sizeof(stTaskArg)))
{
theApp.m_NetWorkOper.SetSuspendForThread(false);
if (LANG_ZHCN == g_iUILanguage)
AfxMessageBox(_T("上传任务参数发送失败"));
else
MessageBoxEx(NULL, _T("Upload task parameter send failed."), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
return FALSE;
}
if (EN_RECV_SUCCESS == theApp.m_NetWorkOper.RecvMsgDirect(chMsgSyn, &iLen, sizeof(char), 5000))
{
if ((iLen != sizeof(BYTE)) || (EN_RECV_SUCCESS != chMsgSyn[0]))
{
theApp.m_NetWorkOper.SetSuspendForThread(false);
if (LANG_ZHCN == g_iUILanguage)
AfxMessageBox(_T("上传任务参数接收失败"));
else
MessageBoxEx(NULL, _T("Upload task parameter recv failed."), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
return FALSE;
}
}
theApp.m_NetWorkOper.SetSuspendForThread(false);
return TRUE;
}
bool CTaskDataOper::OnlineUploadRes2DRg(DWORD dwTdID, STQueryTaskBasicInfo stQueryTdInfo)
{
int iLen = 0;
char chSendStr[100] = { 0 };
char chMsgSyn[10] = { 0 };
STRemTaskArg stTaskArg;
stTaskArg.uiStartElec = htonl(stQueryTdInfo.iStartElec);
stTaskArg.uiEndElec = htonl(stQueryTdInfo.iEndElec);
memcpy(chSendStr, &stQueryTdInfo.ucTaskID, MAX_NAME_LEN * sizeof(BYTE));
memcpy(&chSendStr[MAX_NAME_LEN * sizeof(BYTE)], &stTaskArg.uiStartElec, sizeof(UINT32));
memcpy(&chSendStr[MAX_NAME_LEN * sizeof(BYTE)+sizeof(UINT32)], &stTaskArg.uiEndElec, sizeof(UINT32));
theApp.m_NetWorkOper.SetSuspendForThread(true);
CAutoLock autoLock(theApp.m_NetWorkOper.GetNetCriticalSection());
if (!theApp.m_NetWorkOper.SendCtrlMsgDirect(EN_UPLOAD_RG_INF, 0xFFFFFFFF, 1, (char*)chSendStr, MAX_NAME_LEN * sizeof(BYTE)+2 * sizeof(UINT32)))
{
theApp.m_NetWorkOper.SetSuspendForThread(false);
if (LANG_ZHCN == g_iUILanguage)
AfxMessageBox(_T("上传任务接地电阻发送失败"));
else
MessageBoxEx(NULL, _T("Upload task Rg send failed."), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
return FALSE;
}
if (EN_RECV_SUCCESS == theApp.m_NetWorkOper.RecvMsgDirect(chMsgSyn, &iLen, sizeof(chMsgSyn), 5000))
{
if ((iLen != sizeof(BYTE)) || (EN_RECV_SUCCESS != chMsgSyn[0]))
{
theApp.m_NetWorkOper.SetSuspendForThread(false);
if (LANG_ZHCN == g_iUILanguage)
AfxMessageBox(_T("上传任务接地电阻接收失败"));
else
MessageBoxEx(NULL, _T("Upload task Rg recv failed."), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
return FALSE;
}
}
theApp.m_NetWorkOper.SetSuspendForThread(false);
return TRUE;
}
bool CTaskDataOper::UploadElecCoordinatesInfo(DWORD dwTdID, STQueryTaskBasicInfo stQueryTdInfo)
{
char chSendstr[4095] = { 0 };
char chMsgSyn[10] = { 0 };
int i = 1;
int iSendNum = MAX_UPLOAD_ELECTRODE_NUM;
int iStartPoint = 1;
int iLen = 0;
int iDataStart = MAX_NAME_LEN * sizeof(char) + MAX_NAME_LEN * sizeof(char) + sizeof(UINT32) + sizeof(float);
int iPointNum = 0;
ST_ELECTRODECOORDINATES_INFO_HEAD stElecInfo;
QueryElecMaxWellDepthByCN(stQueryTdInfo.ucScriptCN, stQueryTdInfo.iSptType, stElecInfo);
ST_ELECTRODE_COORDINATES_INFO_BODY stElecBody;
std::vector<ST_ELECTRODE_COORDINATES_INFO_BODY> vtData;
iStartPoint = 1;
for (i = 1; i < stQueryTdInfo.iEamount + 1; i++)
{
if (i%MAX_UPLOAD_ELECTRODE_NUM == 0)
{
iSendNum = MAX_UPLOAD_ELECTRODE_NUM;
}
else if (i == stQueryTdInfo.iEamount)
{
iSendNum = stQueryTdInfo.iEamount - iStartPoint + 1;
}
else
{
continue;
}
if (QueryElecCoordinatesDataByCN(stQueryTdInfo.ucScriptCN, stQueryTdInfo.iSptType, iStartPoint, iSendNum, vtData))
{
if (vtData.empty())
{
return false;
}
memcpy(chSendstr, stQueryTdInfo.ucTaskID, sizeof(stQueryTdInfo.ucTaskID));
//memcpy(&chSendstr[MAX_NAME_LEN], stQueryTdInfo.strSptName, MAX_NAME_LEN);
memcpy(&chSendstr[MAX_NAME_LEN], stQueryTdInfo.ucScriptCN, MAX_NAME_LEN);
stElecInfo.fMaxWellDepth = tcp_htonf(stElecInfo.fMaxWellDepth);
memcpy(&chSendstr[2 * MAX_NAME_LEN], &stElecInfo.fMaxWellDepth, sizeof(stElecInfo.fMaxWellDepth));
iPointNum = htonl(iSendNum);
memcpy(&chSendstr[2 * MAX_NAME_LEN+sizeof(float)], &iPointNum, sizeof(iPointNum));
int iSendLen = iDataStart + sizeof(ST_ELECTRODE_COORDINATES_INFO_BODY)*iSendNum;//sizeof(STTaskDataRes);
for (int j = 0; j < vtData.size(); j++)
{
memset(&stElecBody, 0, sizeof(stElecBody));
stElecBody.uiElecID = htonl(vtData[j].uiElecID);
stElecBody.fX = tcp_htonf(vtData[j].fX);
stElecBody.fY = tcp_htonf(vtData[j].fY);
stElecBody.fZ = tcp_htonf(vtData[j].fZ);
memcpy(&chSendstr[iDataStart + j*sizeof(ST_ELECTRODE_COORDINATES_INFO_BODY)], &stElecBody, sizeof(ST_ELECTRODE_COORDINATES_INFO_BODY));
}
CAutoLock autoLock(theApp.m_NetWorkOper.GetNetCriticalSection());
if (!theApp.m_NetWorkOper.SendCtrlMsgDirect(EN_UPLOAD_ELECTRODE_COORDINATES_INFO, 0xFFFFFFFF, 1, (char*)chSendstr, iSendLen))
{
if (LANG_ZHCN == g_iUILanguage)
AfxMessageBox(_T("上传电极坐标信息发送失败"));
else
MessageBoxEx(NULL, _T("Failed to send the uploaded electrode coordinate information."), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
return FALSE;
}
if (EN_RECV_SUCCESS == theApp.m_NetWorkOper.RecvMsgDirect(chMsgSyn, &iLen, sizeof(chMsgSyn), 5000))
{
if ((iLen != sizeof(BYTE)) || (EN_RECV_SUCCESS != chMsgSyn[0]))
{
theApp.m_NetWorkOper.SetSuspendForThread(false);
if (LANG_ZHCN == g_iUILanguage)
AfxMessageBox(_T("上传电极坐标信息接收失败"));
else
MessageBoxEx(NULL, _T("Failed to receive the uploaded electrode coordinate information."), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
return FALSE;
}
}
}
iStartPoint = i + 1;
}
return TRUE;
}
bool CTaskDataOper::OnlineUploadRes2DData(DWORD dwTdID, STQueryTaskBasicInfo stQueryTdInfo)
{
char chSendstr[4095] = { 0 };
char chMsgSyn[10] = { 0 };
int i = 1;
int iSendNum = MAX_UPLOAD_POINT_NUM;
int iStartPoint = 1;
int iLen = 0;
int iDataStart = MAX_NAME_LEN * sizeof(BYTE)+sizeof(UINT32);
std::vector<STTaskDetailBasicData> vtData;
theApp.m_NetWorkOper.SetSuspendForThread(true);
iStartPoint = 1;
for (i = 1; i < stQueryTdInfo.uiTotalNum+1; i++)
{
if (i%MAX_UPLOAD_POINT_NUM == 0)
{
iSendNum = MAX_UPLOAD_POINT_NUM;
}
else if (i == stQueryTdInfo.uiTotalNum)
{
iSendNum = stQueryTdInfo.uiTotalNum - iStartPoint + 1;
}
else
{
continue;
}
if (QueryTdDataFromTsn(dwTdID, stQueryTdInfo.iSptType, iStartPoint, iSendNum, vtData))
{
if (vtData.empty())
{
return false;
}
memcpy(chSendstr, stQueryTdInfo.ucTaskID, sizeof(stQueryTdInfo.ucTaskID));
int iPointNum = htonl(iSendNum);
memcpy(&chSendstr[sizeof(stQueryTdInfo.ucTaskID)], &iPointNum, sizeof(iPointNum));
int iSendLen = MAX_NAME_LEN * sizeof(BYTE)+sizeof(UINT32)+sizeof(STTaskDataRes)*iSendNum;//sizeof(STTaskDataRes);
for (int j = 0; j < vtData.size(); j++)
{
STTaskDataRes stTaskDataRes;
stTaskDataRes.dwID = htonl(vtData[j].iID);
stTaskDataRes.fA = tcp_htonf(vtData[j].iA);
stTaskDataRes.fB = tcp_htonf(vtData[j].iB);
stTaskDataRes.fM = tcp_htonf(vtData[j].iM);
stTaskDataRes.fN = tcp_htonf(vtData[j].iN);
stTaskDataRes.fK = tcp_htonf(vtData[j].fK);
stTaskDataRes.fV = tcp_htonf(vtData[j].fV);
stTaskDataRes.fI = tcp_htonf(vtData[j].fI);
stTaskDataRes.fR0 = tcp_htonf(vtData[j].fR0);
stTaskDataRes.fSP = tcp_htonf(vtData[j].fSP);
stTaskDataRes.fR0_LC = 0;// tcp_htonf(vtData[j].); //暂填0,若后面要用此接口上传已测任务,需改 by quxy 20181103
stTaskDataRes.ucStack = vtData[j].ucStack;
stTaskDataRes.ucAlram = 0; //暂填0,若后面要用此接口上传已测任务,需改 by quxy 20181103
memcpy(&chSendstr[iDataStart + j*sizeof(STTaskDataRes)], &stTaskDataRes, sizeof(STTaskDataRes));
}
CAutoLock autoLock(theApp.m_NetWorkOper.GetNetCriticalSection());
if (!theApp.m_NetWorkOper.SendCtrlMsgDirect(EN_UPLOAD_DATA_INF, 0xFFFFFFFF, 1, (char*)chSendstr, iSendLen))
{
theApp.m_NetWorkOper.SetSuspendForThread(false);
if (LANG_ZHCN == g_iUILanguage)
AfxMessageBox(_T("上传任务数据发送失败"));
else
MessageBoxEx(NULL, _T("Upload task data send failed."), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
return FALSE;
}
if (EN_RECV_SUCCESS == theApp.m_NetWorkOper.RecvMsgDirect(chMsgSyn, &iLen, sizeof(chMsgSyn), 5000))
{
if ((iLen != sizeof(BYTE)) || (EN_RECV_SUCCESS != chMsgSyn[0]))
{
theApp.m_NetWorkOper.SetSuspendForThread(false);
if (LANG_ZHCN == g_iUILanguage)
AfxMessageBox(_T("上传任务数据接收失败"));
else
MessageBoxEx(NULL, _T("Upload task data recv failed."), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
return FALSE;
}
}
}
iStartPoint = i+1;
}
theApp.m_NetWorkOper.SetSuspendForThread(false);
return TRUE;
}
bool CTaskDataOper::OnlineUploadRes2DTask(DWORD dwTdID)
{
CString strLog = _T("");
STQueryTaskBasicInfo stQueryTdInfo;
memset(stQueryTdInfo.ucTaskID, 0, sizeof(stQueryTdInfo.ucTaskID));
if (!QueryTdBasicInfo(dwTdID, &stQueryTdInfo))
{
strLog.Format(_T("[%s][%d]Query task information failed. taskid = %d"), dwTdID);
CFileOperTools::GetInstance()->WriteComLog(strLog);
if (LANG_ZHCN == g_iUILanguage)
AfxMessageBox(_T("查询任务信息失败"));
else
MessageBoxEx(NULL, _T("Query task infomation failed."), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
return FALSE;
}
if (FALSE == OnlineUploadRes2DArg(dwTdID, stQueryTdInfo))//upload parameter
{
return FALSE;
}
if (FALSE == OnlineUploadRes2DRg(dwTdID, stQueryTdInfo))//upload Rg
{
return FALSE;
}
if (FALSE == OnlineUploadRes2DData(dwTdID, stQueryTdInfo))//upload point data
{
return FALSE;
}
int i = (int)VAL_ZERO;
HTREEITEM hChild;
CString szName_Status;
_CommandPtr pCmdIns = NULL;
pCmdIns.CreateInstance(_uuidof(Command));
pCmdIns->ActiveConnection = theApp.m_pConnection;
theApp.m_pConnection->BeginTrans();
CString strSql;
strSql.Empty();
strSql.Format(_T("update td set TdStatus = %d where TDCN = '%s'"), EN_TASK_YES_SYN, stQueryTdInfo.ucTaskID);
pCmdIns->CommandText = strSql.AllocSysString();
pCmdIns->Execute(NULL, NULL, adCmdText);
theApp.m_pConnection->CommitTrans();
return TRUE;
}
bool CTaskDataOper::OnlineDownloadRes2DData(BYTE ucTdType, STTaskDataRes *ptTaskData, DWORD dwChID)
{
_RecordsetPtr pRecTdCha;
_CommandPtr pCmdIns;
CString szSql = _T("");
int iTdRecIndex = (int)VAL_ZERO;
pRecTdCha.CreateInstance(_uuidof(Recordset));
pCmdIns.CreateInstance(_uuidof(Command));
pCmdIns->ActiveConnection = theApp.m_pConnection;
CString strTd, strErr;
if (ucTdType > 2)
{
if (LANG_ZHCN == g_iUILanguage)
{
strErr.Format(_T("未知任务类型(%d)"), ucTdType);
AfxMessageBox(strErr);
}
else
{
strErr.Format(_T("Unknow Task type(%d)"), ucTdType);
MessageBoxEx(NULL, strErr, STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
}
return false;
}
strTd.Format(_T("td%ddcon"), ucTdType + 1);
int iA = (int)ptTaskData->fA;
int iB = (int)ptTaskData->fB;
int iM = (int)ptTaskData->fM;
int iN = (int)ptTaskData->fN;
CString szfK; szfK.Format("%0.4f", ptTaskData->fK);
CString szfI; szfI.Format("%0.4f", ptTaskData->fI);
CString szfV; szfV.Format("%0.4f", ptTaskData->fV);
CString szfR0; szfR0.Format("%0.4f", ptTaskData->fR0);
CString szfSP; szfSP.Format("%0.4f", ptTaskData->fSP);
CString szR0LC; szR0LC.Format("%0.4f", ptTaskData->fR0_LC);
theApp.m_pConnection->BeginTrans();
try
{
szSql.Empty();
szSql.Format(_T("insert into %s(TCHID,TSN,C1,C2,P1,P2,N,K,I,V,R0,SP,bUse,R0_LC) values(%u,%d,%d,%d,%d,%d,%d,%s,%s,%s,%s,%s,%d,%s)"),
strTd,
dwChID,
ptTaskData->dwID,
iA,
iB,
iM,
iN,
ptTaskData ->ucStack,
szfK,
szfI,
szfV,
szfR0,
szfSP,
TRUE,
szR0LC);
CString strLog;
strLog.Format(_T("zm:CTaskDataOper::OnlineDownloadRes2DData %s \n"),szSql);
OutputDebugString(strLog);
pCmdIns->CommandText = szSql.AllocSysString();
pCmdIns->Execute(NULL, NULL, adCmdText);
}
catch (_com_error e)
{
AfxMessageBox(e.Description());
theApp.m_pConnection->RollbackTrans();
return FALSE;
}
theApp.m_pConnection->CommitTrans();
return TRUE;
}
bool CTaskDataOper::UpdateTdBasicData(BYTE ucTdType, BYTE ucTestType,int iTdChannelID, int iTsn, LPSTMeasuBasicDataRes pMeasuBasicData,void *pAttachData)
{
CString szSql, strErr, strTd = _T("");
if (ucTdType > 2)
{
if (LANG_ZHCN == g_iUILanguage)
{
strErr.Format(_T("未知任务类型(%d)"), ucTdType);
AfxMessageBox(strErr);
}
else
{
strErr.Format(_T("Unknow Task type(%d)"), ucTdType);
MessageBoxEx(NULL, strErr, STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
}
return false;
}
strTd.Format(_T("td%ddcon"),ucTdType+1);
_CommandPtr pCmdIns = NULL;
pCmdIns.CreateInstance(_uuidof(Command));
pCmdIns->ActiveConnection = theApp.m_pConnection;
try
{
float fM0_LC = (1 == ucTestType) ? *((float*)pAttachData) : 0;
theApp.m_pConnection->BeginTrans();
szSql.Empty();
szSql.Format(_T("update %s set N = %d, K = %f, I = %f, V = %f, R0 = %f, SP = %f, R0_LC = %f, M0_LC = %f, bUse = 1 where TCHID = %d and TSN = %d"),
strTd, pMeasuBasicData->ucStack, pMeasuBasicData->fK, pMeasuBasicData->fI,
pMeasuBasicData->fV, pMeasuBasicData->fR0, pMeasuBasicData->fSP,
pMeasuBasicData->fR0_LC, fM0_LC, iTdChannelID, pMeasuBasicData->iID);
OutputDebugString(_T("zm:CTaskDataOper::UpdateTdBasicData() ") + szSql + _T("\n"));
pCmdIns->CommandText = szSql.AllocSysString();
pCmdIns->Execute(NULL, NULL, adCmdText);
//如果是IP数据的话
if (1 == ucTestType)
{
LPMeasuDataIPAttr pMeasuDataIPAttr = (LPMeasuDataIPAttr)pAttachData;
pMeasuDataIPAttr->wHL = ntohs(pMeasuDataIPAttr->wHL);
if (pMeasuDataIPAttr->ucTWCnt > 20)
{
strErr.Empty();
if (LANG_ZHCN == g_iUILanguage)
{
strErr.Format(_T("数据包里的时窗个数(%d)错误"), pMeasuDataIPAttr->ucTWCnt);
AfxMessageBox(strErr);
}
else
{
strErr.Format(_T("Error in number of time Windows in packet (%d)"), pMeasuDataIPAttr->ucTWCnt);
MessageBoxEx(NULL, strErr, STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
}
}
else
{
CString strTWIndex = _T(""), strTmp = _T(""), strTWVal = _T(""), strTWValTmp = _T("");
int iInterval = 20*sizeof(float);
for (int i = 0; i < pMeasuDataIPAttr->ucTWCnt; i++)
{
strTmp.Empty();
strTmp.Format(_T(",TW%dIndex "),i);
strTWIndex = strTWIndex + strTmp;
strTmp.Empty();
strTmp.Format(_T("%f;0.0;%f;0.0"),pMeasuDataIPAttr->fETA[i],pMeasuDataIPAttr->fM0[i]);
strTWValTmp.Empty();
strTWValTmp.Format(_T(",'%s' "),strTmp);
strTWVal = strTWVal + strTWValTmp;
}
szSql.Empty();
szSql.Format(_T("insert into td_spc_attr(TCHID,TSN,THL,D,r,TWCNT %s) values(%d, %d, %f, %f, %f, %d %s)"),strTWIndex,
iTdChannelID, pMeasuBasicData->iID, (float)(pMeasuDataIPAttr->wHL), pMeasuDataIPAttr->fD,
pMeasuDataIPAttr->fr, pMeasuDataIPAttr->ucTWCnt, strTWVal);
CString strLog;
strLog.Format(_T("zm:CTaskDataOper::UpdateTdBasicData %s \n"), szSql);
OutputDebugString(strLog);
pCmdIns->CommandText = szSql.AllocSysString();
pCmdIns->Execute(NULL, NULL, adCmdText);
}
}
theApp.m_pConnection->CommitTrans();
return true;
}
catch (_com_error e)
{
theApp.m_pConnection->RollbackTrans();
AfxMessageBox(e.Description());
return false;
}
}
bool CTaskDataOper::UpdateTdBasicData(BYTE ucTdType, BYTE ucTestType, int iTdChannelID, int iTsn, LPSTMeasuBasicDataResEx pMeasuBasicData, void *pAttachData)
{
CString szSql, strErr, strTd = _T("");
if (ucTdType > 2)
{
if (LANG_ZHCN == g_iUILanguage)
{
strErr.Format(_T("未知任务类型(%d)"), ucTdType);
AfxMessageBox(strErr);
}
else
{
strErr.Format(_T("Unknow Task type(%d)"), ucTdType);
MessageBoxEx(NULL, strErr, STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
}
return false;
}
strTd.Format(_T("td%ddcon"), ucTdType + 1);
_CommandPtr pCmdIns = NULL;
pCmdIns.CreateInstance(_uuidof(Command));
pCmdIns->ActiveConnection = theApp.m_pConnection;
try
{
float fM0_LC = (1 == ucTestType) ? *((float*)pAttachData) : 0;
theApp.m_pConnection->BeginTrans();
szSql.Empty();
szSql.Format(_T("update %s set N = %d, K = %f, I = %f, V = %f, R0 = %f, SP = %f, R0_LC = %f, M0_LC = %f, bUse = 1 where TCHID = %d and TSN = %d"),
strTd, pMeasuBasicData->ucStack, pMeasuBasicData->fK, pMeasuBasicData->fI,
pMeasuBasicData->fV, pMeasuBasicData->fR0, pMeasuBasicData->fSP,
pMeasuBasicData->fR0_LC, fM0_LC, iTdChannelID, pMeasuBasicData->iID);
pCmdIns->CommandText = szSql.AllocSysString();
pCmdIns->Execute(NULL, NULL, adCmdText);
//如果是IP数据的话
if (1 == ucTestType)
{
LPMeasuDataIPAttr pMeasuDataIPAttr = (LPMeasuDataIPAttr)pAttachData;
pMeasuDataIPAttr->wHL = ntohs(pMeasuDataIPAttr->wHL);
if (pMeasuDataIPAttr->ucTWCnt > 20)
{
strErr.Empty();
if (LANG_ZHCN == g_iUILanguage)
{
strErr.Format(_T("数据包里的时窗个数(%d)错误"), pMeasuDataIPAttr->ucTWCnt);
AfxMessageBox(strErr);
}
else
{
strErr.Format(_T("Error in number of time Windows in packet (%d)"), pMeasuDataIPAttr->ucTWCnt);
MessageBoxEx(NULL, strErr, STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
}
}
else
{
CString strTWIndex = _T(""), strTmp = _T(""), strTWVal = _T(""), strTWValTmp = _T("");
int iInterval = 20 * sizeof(float);
for (int i = 0; i < pMeasuDataIPAttr->ucTWCnt; i++)
{
strTmp.Empty();
strTmp.Format(_T(",TW%dIndex "), i);
strTWIndex = strTWIndex + strTmp;
strTmp.Empty();
strTmp.Format(_T("%f;0.0;%f;0.0"), pMeasuDataIPAttr->fETA[i], pMeasuDataIPAttr->fM0[i]);
strTWValTmp.Empty();
strTWValTmp.Format(_T(",'%s' "), strTmp);
strTWVal = strTWVal + strTWValTmp;
}
szSql.Empty();
szSql.Format(_T("insert into td_spc_attr(TCHID,TSN,THL,D,r,TWCNT %s) values(%d, %d, %f, %f, %f, %d %s)"), strTWIndex,
iTdChannelID, pMeasuBasicData->iID, (float)(pMeasuDataIPAttr->wHL), pMeasuDataIPAttr->fD,
pMeasuDataIPAttr->fr, pMeasuDataIPAttr->ucTWCnt, strTWVal);
pCmdIns->CommandText = szSql.AllocSysString();
pCmdIns->Execute(NULL, NULL, adCmdText);
}
}
theApp.m_pConnection->CommitTrans();
return true;
}
catch (_com_error e)
{
theApp.m_pConnection->RollbackTrans();
AfxMessageBox(e.Description());
return false;
}
}
void CTaskDataOper::InitOnLineTaskTreeCtrl(CTreeCtrl& taskTree, int iSptType, std::map<CString, STRemTaskTable> mapTaskList, HWND hWnd)
{
taskTree.DeleteAllItems();
CString strItem;
strItem.LoadString(IDS_TASK_TREE_ROOT + g_UIOffset);
HTREEITEM hRoot = taskTree.InsertItem(strItem, TVI_ROOT, TVI_LAST);
if (g_eTestingMethod != EN_TASK_SUSPENDED)
g_strSaveTestingTaskID = _T("");
//获取测区ID
int iTzID = GetDefaultTzID();
if (iTzID < 1)
{
return;
}
int iExists = 0;
CString strLog;
CString strDevSn;
strDevSn.Format(_T("SN%u"), m_uiDevID);
//CFileOperTools::GetInstance()->WriteComLog(_T("zm:*********************loadding task list begin******************"));
OutputDebugString(_T("zm:*********************loadding task list begin******************\n"));
STTaskListItem* pTaskItem = NULL;
CString strTaskName;
_RecordsetPtr pRecTd = NULL;
pRecTd.CreateInstance(_uuidof(Recordset));
int i = (int)VAL_ZERO;
int iFindRet = 0;
CString szTaskID;
CString strSql = _T("");
std::map<CString, CString> mapLocalDataBaseData;//存放本地数据库与云端同时存在的任务
strSql.Format(_T("select ID, TDname,TDCN,TdStatus,CreateTime from td where Stype = %d and TZID = %d and CreateTime>=%u and CreateTime<=%u and DESN='%s'"), iSptType, iTzID, (unsigned long)m_tStartTime, (unsigned long)m_tEndTime, strDevSn);
//strSql.Format(_T("select ID, TDname,TDCN,TdStatus,CreateTime from td where Stype = %d and TZID = %d"), iSptType, iTzID);
try
{
pRecTd->Open(strSql.AllocSysString(), _variant_t((IDispatch*)theApp.m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText);
HTREEITEM hChild;
while (0 == pRecTd->adoEOF)
{
/*time_t tmCreateTime = pRecTd->GetCollect(_T("CreateTime")).vt == VT_NULL ? 0 : pRecTd->GetCollect(_T("CreateTime")).uintVal;
if (tmCreateTime != 0)
{
CString strCreateTime = Tm2LocalStr(tmCreateTime);
strCreateTime += "\n";
OutputDebugString(strCreateTime);
if (!(tmCreateTime >= m_tStartTime && tmCreateTime <= m_tEndTime))
{
pRecTd->MoveNext();
continue;
}
}*/
pTaskItem = new STTaskListItem();
szTaskID.Empty();
if (VT_NULL != pRecTd->GetCollect(_T("TDCN")).vt)
{
szTaskID = pRecTd->GetCollect(_T("TDCN"));
}
strcpy(pTaskItem->szTaskID, szTaskID);
iExists = mapTaskList.count(szTaskID);
//服务端不存在
if (0 == iExists)
{
if (VT_NULL != pRecTd->GetCollect(_T("TDname")).vt)
{
strTaskName = pRecTd->GetCollect(_T("TDname"));
}
strcpy(pTaskItem->szTDName, strTaskName.GetBuffer());
//strTaskName += " " + OnLineLocalTaskState(EN_TASK_NO_UPLOAD);
strTaskName = OnLineLocalTaskState(EN_TASK_NO_UPLOAD) + _T(" ") + strTaskName;
hChild = taskTree.InsertItem((LPCTSTR)(_bstr_t)strTaskName, hRoot);
//bTaskStats = pRecTd->GetCollect(_T("TdStatus")).bVal;
pTaskItem->eSynStatus = EN_TASK_NO_UPLOAD;//(EN_TASK_LOCAL_STATUSE)bTaskStats;//暂不取库的状态,待列表状态更新存库
pTaskItem->byTestStatus = 0;//从数据读取默认测试状态为0
taskTree.SetItemData(hChild, (DWORD_PTR)pTaskItem);
}
else
{
mapLocalDataBaseData[szTaskID] = szTaskID;
}
pRecTd->MoveNext();
}
pRecTd->Close();
}
catch (_com_error e)
{
AfxMessageBox(e.Description());
pRecTd->Close();
}
HTREEITEM hChild;
CString szName_Status;
_CommandPtr pCmdIns = NULL;
pCmdIns.CreateInstance(_uuidof(Command));
pCmdIns->ActiveConnection = theApp.m_pConnection;
BYTE byTaskStatus = 0;
UINT32 uiTaskNum = mapTaskList.size();
std::map<CString, STRemTaskTable>::iterator iter=mapTaskList.begin();
for (i = 0; i<uiTaskNum,iter != mapTaskList.end(); i++,iter++)
{
iExists = mapLocalDataBaseData.count(iter->first);
if (iExists == 0)//不存在
{
byTaskStatus = EN_TASK_NO_DOWNLOAD;//fill No download status;
}
else//存在
{
byTaskStatus = EN_TASK_YES_SYN;
//清除已存在的
mapLocalDataBaseData.erase(iter->first);
theApp.m_pConnection->BeginTrans();
strSql.Empty();
strSql.Format(_T("update td set TdStatus = %d where TDCN = '%s'"), EN_TASK_YES_SYN, iter->second.ucTaskID);
pCmdIns->CommandText = strSql.AllocSysString();
pCmdIns->Execute(NULL, NULL, adCmdText);
theApp.m_pConnection->CommitTrans();
}
szName_Status.Empty();
szName_Status.Format(_T("%s %s %s"), OnLineLocalTaskState(byTaskStatus), OnLineTask(iter->second.ucTaskStats), U2G(iter->second.ucTDName));
hChild = taskTree.InsertItem((LPCTSTR)(_bstr_t)szName_Status, hRoot);//It used TaskID now ,it used taskname when port change.先用ID,待改接口
STTaskListItem* pTaskItem = new STTaskListItem;
strcpy(pTaskItem->szTaskID, iter->second.ucTaskID);
strcpy(pTaskItem->szTDName, U2G(iter->second.ucTDName));
pTaskItem->eSynStatus = (EN_TASK_LOCAL_STATUSE)byTaskStatus;
pTaskItem->byTestStatus = iter->second.ucTaskStats;
//strLog.Format(_T("zm:taskid=%s, taskname=%s, syn status=%d,test status=%d\n"), pTaskItem->szTaskID, pTaskItem->szTDName, pTaskItem->eSynStatus, pTaskItem->byTestStatus);
//CFileOperTools::GetInstance()->WriteComLog(strLog);
//OutputDebugString(strLog);
if (10 <= iter->second.ucTaskStats && iter->second.ucTaskStats < 20)
{
g_strSaveTestingTaskID = iter->second.ucTaskID;
taskTree.SelectItem(hChild);
::SendMessage(hWnd, WM_MSG_SET_CURRENT_SELECT_TASK, (WPARAM)pTaskItem, 0);
//strLog.Format(_T("zm:taskid=%s, taskname=%s, syn status=%d,test status=%d [10,20) save to g_strSaveTestingTaskID=%s\n"), pTaskItem->szTaskID, pTaskItem->szTDName, pTaskItem->eSynStatus, pTaskItem->byTestStatus, g_strSaveTestingTaskID);
//CFileOperTools::GetInstance()->WriteComLog(strLog);
//OutputDebugString(strLog);
}
else if (g_eTestingMethod == EN_TASK_SUSPENDED
&& iter->second.ucTaskStats == EN_TASK_STATE_STOP_TEST
&& g_strSaveSuspendedTaskID.CompareNoCase(iter->second.ucTaskID) == 0)
{
taskTree.SelectItem(hChild);
::SendMessage(hWnd, WM_MSG_SET_CURRENT_SELECT_TASK, (WPARAM)pTaskItem, 0);
}
taskTree.SetItemData(hChild, (DWORD)pTaskItem);
}
//加载结束后更新实时窗口按钮显示状态
::SendMessage(hWnd, WM_MSG_UPDATE_REALTIME_WND_BTN_STATUS, 0, 0);
OutputDebugString(_T("zm:*********************loadding task list end******************\n"));
}
/*
void CTaskDataOper::InitialOnLineTaskTreeCtrl(CTreeCtrl& taskTree, int iSptType, UINT32 uiTaskNum, STRemTaskTable *ptTaskTable, HWND hWnd)//by quyx 20181031
{
//m_vtLocalTaskID.clear();
taskTree.DeleteAllItems();
CString strItem;
strItem.LoadString(IDS_TASK_TREE_ROOT + g_UIOffset);
HTREEITEM hRoot = taskTree.InsertItem(strItem, TVI_ROOT, TVI_LAST);
if (g_eTestingMethod != EN_TASK_SUSPENDED)
g_strSaveTestingTaskID = _T("");
///////////////////////It gets task's information from the cloud server//////////////////////////////
//SYSTEMTIME sysTm;
// int iMaxRecvLen = sizeof(UINT32)+300 * sizeof(STRemTaskTable);
// char *chMsgSyn = (char *)malloc(iMaxRecvLen);//[4096] = { 0 };
// char chSendStr[20] = { 0 };
// STRemTaskTable *ptTaskTable = NULL;
// UINT32 uiTaskNum = 0;
//
// time_t tm;
// //GetSystemTime(&sysTm);
// int uiCurTime = (int)time(&tm);
// uiCurTime += 3600 * 8;
// int uiStartTime = uiCurTime - 30 * 24 * 3600;
//
// theApp.m_NetWorkOper.SetSuspendForThread(true);
// UINT32 uiDevID = htonl(m_uiDevID);
// uiCurTime = htonl(uiCurTime);
// uiStartTime = htonl(uiStartTime);
// memcpy(chSendStr, &uiDevID, sizeof(UINT32));
// memcpy(&chSendStr[sizeof(UINT32)], &uiStartTime, sizeof(UINT32));
// memcpy(&chSendStr[2 * sizeof(UINT32)], &uiCurTime, sizeof(UINT32));
// chSendStr[3 * sizeof(UINT32)] = (char)(iSptType&0xFF);
// if (!theApp.m_NetWorkOper.SendCtrlMsgDirect(EN_REQ_DOWNLOAD_TASK_TABLE, 0xFFFFFFFF, 1, chSendStr, 3 * sizeof(UINT32)+sizeof(char)))
// {
// theApp.m_NetWorkOper.SetSuspendForThread(false);
// AfxMessageBox(_T("Synchronization task table send failed."));
// return;
// }
// int iLen = 0;
// if (EN_RECV_SUCCESS == theApp.m_NetWorkOper.RecvMsgDirect(chMsgSyn, &iLen, iMaxRecvLen, 5000))
// {
// UINT32 *uiRevData = (UINT32*)(chMsgSyn);
// uiTaskNum = ntohl(uiRevData[0]);
// if ((uiRevData[0] < 1) || (iLen < (sizeof(UINT32)+uiTaskNum * sizeof(STRemTaskTable))))
// {
// theApp.m_NetWorkOper.SetSuspendForThread(false);
// if (uiRevData[0] > 0){ AfxMessageBox(_T("Synchronization task table recv failed. recv length is error!")); }
// //return;
// }
// ptTaskTable = (STRemTaskTable *)(&chMsgSyn[sizeof(UINT32)]);
//
// }
// theApp.m_NetWorkOper.SetSuspendForThread(false);
///////////////////////It gets task's information from the local database//////////////////////////////
//获取测区ID
int iTzID = GetDefaultTzID();
if (iTzID < 1)
{
return;
}
CString strLog;
CFileOperTools::GetInstance()->WriteComLog(_T("zm:*********************loadding task list begin******************"));
STTaskListItem* pTaskItem = NULL;
CString strTaskID, strTaskName;
BYTE bTaskStats = 0;
_RecordsetPtr pRecTd = NULL;
pRecTd.CreateInstance(_uuidof(Recordset));
CString strSql = _T("");
strSql.Format(_T("select ID, TDname,TDCN,TdStatus,CreateTime from td where Stype = %d and TZID = %d and CreateTime>=%u and CreateTime<=%u"), iSptType, iTzID, (unsigned long)m_tStartTime, (unsigned long)m_tEndTime);
BYTE *ucLocalStatus = (BYTE*)malloc(uiTaskNum * sizeof(BYTE));
try
{
pRecTd->Open(strSql.AllocSysString(), _variant_t((IDispatch*)theApp.m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText);
HTREEITEM hChild;
//DWORD dwTaskID = 0;
while (0 == pRecTd->adoEOF)
{
time_t tmCreateTime = pRecTd->GetCollect(_T("CreateTime")).vt == VT_NULL ? 0 : pRecTd->GetCollect(_T("CreateTime")).uintVal;
if (tmCreateTime != 0)
{
CString strCreateTime = Tm2LocalStr(tmCreateTime);
strCreateTime += "\n";
OutputDebugString(strCreateTime);
if (!(tmCreateTime >= m_tStartTime && tmCreateTime <= m_tEndTime))
{
pRecTd->MoveNext();
continue;
}
}
pTaskItem = new STTaskListItem();
CString szTaskID; szTaskID.Empty();
CString szDevSn; szDevSn.Empty(); szDevSn.Format(_T("SN%u"), m_uiDevID);
if (VT_NULL != pRecTd->GetCollect(_T("TDCN")).vt)
{
szTaskID = pRecTd->GetCollect(_T("TDCN"));
}
strcpy(pTaskItem->szTaskID, szTaskID);
if (-1 == szTaskID.Find(_T(szDevSn)))
{
pRecTd->MoveNext(); continue;
}
//保存本地数据库
//m_vtLocalTaskID.push_back(szTaskID);
int i = (int)VAL_ZERO;
for (i = 0; i < uiTaskNum; i++)
{
if (-1 != szTaskID.Find(_T(ptTaskTable[i].ucTaskID)))
{
ucLocalStatus[i] = EN_TASK_YES_SYN;
break;
}
}
if (i < uiTaskNum)
{ pRecTd->MoveNext(); continue; }//It found this task form the cloud tasks. 发现云端有此任务,先不加载,以云端优先
if (VT_NULL != pRecTd->GetCollect(_T("TDname")).vt)
{
strTaskName = pRecTd->GetCollect(_T("TDname"));
}
strcpy(pTaskItem->szTDName, strTaskName.GetBuffer());
//strTaskName += " " + OnLineLocalTaskState(EN_TASK_NO_UPLOAD);
strTaskName =OnLineLocalTaskState(EN_TASK_NO_UPLOAD) + _T(" ") + strTaskName;
hChild = taskTree.InsertItem((LPCTSTR)(_bstr_t)strTaskName, hRoot);
//dwTaskID = pRecTd->GetCollect(_T("ID")).lVal;
//strTaskID.Format(_T("%u"), dwTaskID);
//strcpy(pTaskItem->szTaskID, strTaskID.GetBuffer());
//bTaskStats = pRecTd->GetCollect(_T("TdStatus")).bVal;
pTaskItem->eSynStatus = EN_TASK_NO_UPLOAD;//(EN_TASK_LOCAL_STATUSE)bTaskStats;//暂不取库的状态,待列表状态更新存库
pTaskItem->byTestStatus = 0;//从数据读取默认测试状态为0
taskTree.SetItemData(hChild, (DWORD_PTR)pTaskItem);
pRecTd->MoveNext();
}
pRecTd->Close();
}
catch (_com_error e)
{
AfxMessageBox(e.Description());
pRecTd->Close();
}
int i = (int)VAL_ZERO;
HTREEITEM hChild;
CString szName_Status;
_CommandPtr pCmdIns = NULL;
pCmdIns.CreateInstance(_uuidof(Command));
pCmdIns->ActiveConnection = theApp.m_pConnection;
for (i = 0; i < uiTaskNum; i++)
{
if (EN_TASK_YES_SYN != ucLocalStatus[i])
{
ucLocalStatus[i] = EN_TASK_NO_DOWNLOAD; //fill No download status;
}
else
{
theApp.m_pConnection->BeginTrans();
strSql.Empty();
strSql.Format(_T("update td set TdStatus = %d where TDCN = '%s'"), EN_TASK_YES_SYN, ptTaskTable[i].ucTaskID);
pCmdIns->CommandText = strSql.AllocSysString();
pCmdIns->Execute(NULL, NULL, adCmdText);
theApp.m_pConnection->CommitTrans();
}
szName_Status.Empty();
szName_Status.Format(_T("%s %s %s"), OnLineLocalTaskState(ucLocalStatus[i]), OnLineTask(ptTaskTable[i].ucTaskStats), U2G(ptTaskTable[i].ucTDName));
hChild = taskTree.InsertItem((LPCTSTR)(_bstr_t)szName_Status, hRoot);//It used TaskID now ,it used taskname when port change.先用ID,待改接口
STTaskListItem* pTaskItem = new STTaskListItem;
strcpy(pTaskItem->szTaskID, ptTaskTable[i].ucTaskID);
strcpy(pTaskItem->szTDName, U2G(ptTaskTable[i].ucTDName));
pTaskItem->eSynStatus = (EN_TASK_LOCAL_STATUSE)ucLocalStatus[i];
pTaskItem->byTestStatus = ptTaskTable[i].ucTaskStats;
strLog.Format(_T("zm:taskid=%s, taskname=%s, syn status=%d,test status=%d"), pTaskItem->szTaskID, pTaskItem->szTDName, pTaskItem->eSynStatus, pTaskItem->byTestStatus);
CFileOperTools::GetInstance()->WriteComLog(strLog);
if (10 <= ptTaskTable[i].ucTaskStats && ptTaskTable[i].ucTaskStats < 20)
{
g_strSaveTestingTaskID = ptTaskTable[i].ucTaskID;
taskTree.SelectItem(hChild);
::SendMessage(hWnd, WM_MSG_SET_CURRENT_SELECT_TASK, (WPARAM)pTaskItem, 0);
strLog.Format(_T("zm:taskid=%s, taskname=%s, syn status=%d,test status=%d [10,20) save to g_strSaveTestingTaskID=%s"), pTaskItem->szTaskID, pTaskItem->szTDName, pTaskItem->eSynStatus, pTaskItem->byTestStatus, g_strSaveTestingTaskID);
CFileOperTools::GetInstance()->WriteComLog(strLog);
}
else if (g_eTestingMethod == EN_TASK_SUSPENDED
&& ptTaskTable[i].ucTaskStats == EN_TASK_STATE_STOP_TEST
&& g_strSaveSuspendedTaskID.CompareNoCase(ptTaskTable[i].ucTaskID) == 0)
{
taskTree.SelectItem(hChild);
::SendMessage(hWnd, WM_MSG_SET_CURRENT_SELECT_TASK, (WPARAM)pTaskItem, 0);
}
taskTree.SetItemData(hChild, (DWORD)pTaskItem);
}
//加载结束后更新实时窗口按钮显示状态
::SendMessage(hWnd, WM_MSG_UPDATE_REALTIME_WND_BTN_STATUS, 0, 0);
CFileOperTools::GetInstance()->WriteComLog(_T("zm:*********************loadding task list end******************"));
if (NULL != ucLocalStatus)
{
free(ucLocalStatus);
}
// if (NULL != chMsgSyn)
// {
// free(chMsgSyn);
// }
}
*/
/*
void CTaskDataOper::AppendOnLineTaskTreeCtrl(CTreeCtrl& taskTree, int iSptType, UINT32 uiTaskNum, STRemTaskTable *ptTaskTable, HWND hWnd)//by quyx 20181031
{
//taskTree.DeleteAllItems();
// CString strItem;
// strItem.LoadString(IDS_TASK_TREE_ROOT + g_UIOffset);
// HTREEITEM hRoot = taskTree.InsertItem(strItem, TVI_ROOT, TVI_LAST);
HTREEITEM hRoot = taskTree.GetRootItem();
if (hRoot == NULL)
{
CString strItem;
strItem.LoadString(IDS_TASK_TREE_ROOT + g_UIOffset);
hRoot = taskTree.InsertItem(strItem, TVI_ROOT, TVI_LAST);
}
//if (g_eTestingMethod != EN_TASK_SUSPENDED)
// g_strSaveTestingTaskID = _T("");
//获取测区ID
int iTzID = GetDefaultTzID();
if (iTzID < 1)
{
return;
}
CString strLog;
CFileOperTools::GetInstance()->WriteComLog(_T("zm:*********************Appendding task list begin******************"));
STTaskListItem* pTaskItem = NULL;
CString strTaskID, strTaskName;
BYTE bTaskStats = 0;
CString strSql = _T("");
_RecordsetPtr pRecTd = NULL;
pRecTd.CreateInstance(_uuidof(Recordset));
strSql.Format(_T("select ID, TDname,TDCN,TdStatus,CreateTime from td where Stype = %d and TZID = %d and CreateTime>=%u and CreateTime <=%u"), iSptType, iTzID, (unsigned long)m_tStartTime, (unsigned long)m_tEndTime);
BYTE *ucLocalStatus = (BYTE*)malloc(uiTaskNum * sizeof(BYTE));
try
{
pRecTd->Open(strSql.AllocSysString(), _variant_t((IDispatch*)theApp.m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText);
HTREEITEM hChild;
//DWORD dwTaskID = 0;
while (0 == pRecTd->adoEOF)
{
time_t tmCreateTime = pRecTd->GetCollect(_T("CreateTime")).vt == VT_NULL ? 0 : pRecTd->GetCollect(_T("CreateTime")).uintVal;
if (tmCreateTime == 0)
{
pRecTd->MoveNext();
continue;
}
CString strCreateTime = Tm2LocalStr(tmCreateTime);
strCreateTime += "\n";
OutputDebugString(_T("zm:task create time:")+strCreateTime);
if (!(tmCreateTime >= m_tStartTime && tmCreateTime <= m_tEndTime))
{
pRecTd->MoveNext();
continue;
}
pTaskItem = new STTaskListItem();
CString szTaskID; szTaskID.Empty();
CString szDevSn; szDevSn.Empty(); szDevSn.Format(_T("SN%u"), m_uiDevID);
if (VT_NULL != pRecTd->GetCollect(_T("TDCN")).vt){ szTaskID = pRecTd->GetCollect(_T("TDCN")); }
strcpy(pTaskItem->szTaskID, szTaskID);
if (-1 == szTaskID.Find(_T(szDevSn)))
{
pRecTd->MoveNext(); continue;
}
int i = (int)VAL_ZERO;
for (i = 0; i < uiTaskNum; i++)
{
if (-1 != szTaskID.Find(_T(ptTaskTable[i].ucTaskID)))
{
ucLocalStatus[i] = EN_TASK_YES_SYN;
break;
}
}
if (i < uiTaskNum)
{
pRecTd->MoveNext(); continue;
}//It found this task form the cloud tasks. 发现云端有此任务,先不加载,以云端优先
if (VT_NULL != pRecTd->GetCollect(_T("TDname")).vt)
{
strTaskName = pRecTd->GetCollect(_T("TDname"));
}
strcpy(pTaskItem->szTDName, strTaskName.GetBuffer());
//strTaskName += " " + OnLineLocalTaskState(EN_TASK_NO_UPLOAD);
strTaskName = OnLineLocalTaskState(EN_TASK_NO_UPLOAD) + _T(" ") + strTaskName;
hChild = taskTree.InsertItem((LPCTSTR)(_bstr_t)strTaskName, hRoot);
//dwTaskID = pRecTd->GetCollect(_T("ID")).lVal;
//strTaskID.Format(_T("%u"), dwTaskID);
//strcpy(pTaskItem->szTaskID, strTaskID.GetBuffer());
//bTaskStats = pRecTd->GetCollect(_T("TdStatus")).bVal;
pTaskItem->eSynStatus = EN_TASK_NO_UPLOAD;//(EN_TASK_LOCAL_STATUSE)bTaskStats;//暂不取库的状态,待列表状态更新存库
pTaskItem->byTestStatus = 0;//从数据读取默认测试状态为0
taskTree.SetItemData(hChild, (DWORD_PTR)pTaskItem);
pRecTd->MoveNext();
}
pRecTd->Close();
}
catch (_com_error e)
{
AfxMessageBox(e.Description());
pRecTd->Close();
}
int i = (int)VAL_ZERO;
HTREEITEM hChild;
CString szName_Status;
_CommandPtr pCmdIns = NULL;
pCmdIns.CreateInstance(_uuidof(Command));
pCmdIns->ActiveConnection = theApp.m_pConnection;
for (i = 0; i < uiTaskNum; i++)
{
if (EN_TASK_YES_SYN != ucLocalStatus[i])
{
ucLocalStatus[i] = EN_TASK_NO_DOWNLOAD; //fill No download status;
}
else
{
theApp.m_pConnection->BeginTrans();
strSql.Empty();
strSql.Format(_T("update td set TdStatus = %d where TDCN = '%s'"), EN_TASK_YES_SYN, ptTaskTable[i].ucTaskID);
pCmdIns->CommandText = strSql.AllocSysString();
pCmdIns->Execute(NULL, NULL, adCmdText);
theApp.m_pConnection->CommitTrans();
}
szName_Status.Empty(); szName_Status.Format(_T("%s %s %s"),OnLineLocalTaskState(ucLocalStatus[i]), OnLineTask(ptTaskTable[i].ucTaskStats), U2G(ptTaskTable[i].ucTDName));
hChild = taskTree.InsertItem((LPCTSTR)(_bstr_t)szName_Status, hRoot);//It used TaskID now ,it used taskname when port change.先用ID,待改接口
STTaskListItem* pTaskItem = new STTaskListItem;
strcpy(pTaskItem->szTaskID, ptTaskTable[i].ucTaskID);
strcpy(pTaskItem->szTDName, U2G(ptTaskTable[i].ucTDName));
pTaskItem->eSynStatus = (EN_TASK_LOCAL_STATUSE)ucLocalStatus[i];
pTaskItem->byTestStatus = ptTaskTable[i].ucTaskStats;
strLog.Format(_T("zm:taskid=%s, taskname=%s, syn status=%d,test status=%d"), pTaskItem->szTaskID, pTaskItem->szTDName, pTaskItem->eSynStatus, pTaskItem->byTestStatus);
CFileOperTools::GetInstance()->WriteComLog(strLog);
if (10 <= ptTaskTable[i].ucTaskStats && ptTaskTable[i].ucTaskStats < 20)
{
g_strSaveTestingTaskID = ptTaskTable[i].ucTaskID;
taskTree.SelectItem(hChild);
::SendMessage(hWnd, WM_MSG_SET_CURRENT_SELECT_TASK, (WPARAM)pTaskItem, 0);
strLog.Format(_T("zm:taskid=%s, taskname=%s, syn status=%d,test status=%d [10,20) save to g_strSaveTestingTaskID=%s"), pTaskItem->szTaskID, pTaskItem->szTDName, pTaskItem->eSynStatus, pTaskItem->byTestStatus, g_strSaveTestingTaskID);
CFileOperTools::GetInstance()->WriteComLog(strLog);
}
else if (g_eTestingMethod == EN_TASK_SUSPENDED
&& ptTaskTable[i].ucTaskStats == EN_TASK_STATE_STOP_TEST
&& g_strSaveSuspendedTaskID.CompareNoCase(ptTaskTable[i].ucTaskID) == 0)
{
taskTree.SelectItem(hChild);
::SendMessage(hWnd, WM_MSG_SET_CURRENT_SELECT_TASK, (WPARAM)pTaskItem, 0);
}
taskTree.SetItemData(hChild, (DWORD)pTaskItem);
}
//加载结束后更新实时窗口按钮显示状态
::SendMessage(hWnd, WM_MSG_UPDATE_REALTIME_WND_BTN_STATUS, 0, 0);
CFileOperTools::GetInstance()->WriteComLog(_T("zm:*********************Appendding task list end******************"));
if (NULL != ucLocalStatus)
{
free(ucLocalStatus);
}
// if (NULL != chMsgSyn)
// {
// free(chMsgSyn);
// }
}
*/
void CTaskDataOper::InitialTaskTreeCtrl(CTreeCtrl& taskTree,int iSptType)
{
taskTree.DeleteAllItems();
CString strItem;
strItem.LoadString(IDS_TASK_TREE_ROOT+g_UIOffset);
HTREEITEM hRoot = taskTree.InsertItem(strItem,TVI_ROOT,TVI_LAST);
//获取测区ID
int iTzID = GetDefaultTzID();
if (iTzID < 1)
{
return;
}
_RecordsetPtr pRecTd = NULL;
pRecTd.CreateInstance(_uuidof(Recordset));
CString strSql = _T("");
strSql.Format(_T("select ID, TDname from td where Stype = %d and TZID = %d"), iSptType, iTzID);
try
{
pRecTd->Open(strSql.AllocSysString(),_variant_t((IDispatch*)theApp.m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText);
HTREEITEM hChild;
DWORD dwTaskID = 0;
while(0 == pRecTd->adoEOF)
{
hChild = taskTree.InsertItem((VT_NULL == pRecTd->GetCollect(_T("TDname")).vt) ? _T("NULL") : (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("TDname")), hRoot);
dwTaskID = pRecTd->GetCollect(_T("ID")).lVal;
taskTree.SetItemData(hChild, dwTaskID);
pRecTd->MoveNext();
}
pRecTd->Close();
}
catch (_com_error e)
{
AfxMessageBox(e.Description());
pRecTd->Close();
}
}
bool CTaskDataOper::UpdateGrData(int iTaskID, const char* pData, int iSptType, int iAddedVal)
{
_CommandPtr pCmdIns = NULL;
pCmdIns.CreateInstance(_uuidof(Command));
pCmdIns->ActiveConnection = theApp.m_pConnection;
_RecordsetPtr pRecGr = NULL;
pRecGr.CreateInstance(_uuidof(Recordset));
CString strCreateDate = _T(""), strCreateTime = _T("");
strCreateDate.Format(_T("%04d-%02d-%02d"),g_sysCurTime.wYear, g_sysCurTime.wMonth, g_sysCurTime.wDay);
strCreateTime.Format(_T("%02d:%02d:%02d"), g_sysCurTime.wHour, g_sysCurTime.wMinute, g_sysCurTime.wSecond);
CString szSql;
bool bIsStartTrans = false;
try
{
STMeasuSigGRResult* pGrInfo = (STMeasuSigGRResult*)pData;
INT32 iElecID = 0;
if (0 == iSptType)
iElecID = (char)ntohl(pGrInfo->ucElecID);
else
iElecID = ntohl(pGrInfo->ucElecID);
szSql.Empty();
szSql.Format("select * from gr where TDID = %d and Ecode = %d", iTaskID, iElecID);
pRecGr->Open(szSql.AllocSysString(),_variant_t((IDispatch*)theApp.m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText);
if (pRecGr->GetRecordCount() < 1)
{
pRecGr->Close();
return InsertGrData(iTaskID, 1, pData, iSptType);
}
else
{
pRecGr->Close();
theApp.m_pConnection->BeginTrans();
bIsStartTrans = true;
szSql.Empty();
szSql.Format(_T("update gr set OMvalue = %d, StatusCode = %d, OM1value = %d, StatusCode1 = %d, Mdate = #%s#, Mtime = #%s# "
"where TDID = %d and Ecode = %d "),
(int)(ntohl(pGrInfo->iP1)),pGrInfo->ucP1Status, (int)(ntohl(pGrInfo->iP2)), pGrInfo->ucP2Status,
strCreateDate, strCreateTime, iTaskID, pGrInfo->ucElecID+iAddedVal);
pCmdIns->CommandText = szSql.AllocSysString();
pCmdIns->Execute(NULL, NULL, adCmdText);
theApp.m_pConnection->CommitTrans();
return true;
}
}
catch (_com_error e)
{
if (bIsStartTrans)
{
theApp.m_pConnection->RollbackTrans();
}
AfxMessageBox(e.Description());
return false;
}
}
//新增电极坐标信息
bool CTaskDataOper::InsertCoordinatesData(CString strTaskID, WORD wGrNum, const char* pData, float fMaxWellDepth, int iSptType)
{
_CommandPtr pCmdIns = NULL;
pCmdIns.CreateInstance(_uuidof(Command));
pCmdIns->ActiveConnection = theApp.m_pConnection;
CString strCreateTime = _T("");
strCreateTime.Format(_T("%04d-%02d-%02d %02d:%02d:%02d"), g_sysCurTime.wYear, g_sysCurTime.wMonth, g_sysCurTime.wDay, g_sysCurTime.wHour, g_sysCurTime.wMinute, g_sysCurTime.wSecond);
CString szSql;
INT32 iElecID = 0;
try
{
theApp.m_pConnection->BeginTrans();
//修改最大井深
szSql.Format(_T("update td set WellMaxDepth=%.2f where TDCN='%s'"), tcp_htonf(fMaxWellDepth), strTaskID);
pCmdIns->CommandText = szSql.AllocSysString();
pCmdIns->Execute(NULL, NULL, adCmdText);
STElecCoordinatesInfoBody* pElecInfo = NULL;
for (int i = 0; i < wGrNum; i++)
{
pElecInfo = (STElecCoordinatesInfoBody*)&pData[i*sizeof(STElecCoordinatesInfoBody)];
if (0 == iSptType)
iElecID = (char)ntohl(pElecInfo->uiElecID);
else
iElecID = ntohl(pElecInfo->uiElecID);
szSql.Empty();
szSql.Format(_T("insert into TTaskBindElecInfo(SN,TaskID,ElectrodeID,X,Y,Z,CreateTime) values(%d,'%s',%d,%.2f,%.2f,%.2f,'%s')"),\
i+1, strTaskID, iElecID, tcp_htonf(pElecInfo->fX), tcp_htonf(pElecInfo->fY), tcp_htonf(pElecInfo->fZ), strCreateTime);
pCmdIns->CommandText = szSql.AllocSysString();
pCmdIns->Execute(NULL, NULL, adCmdText);
}
theApp.m_pConnection->CommitTrans();
return true;
}
catch (_com_error e)
{
theApp.m_pConnection->RollbackTrans();
AfxMessageBox(e.Description());
return false;
}
}
void CTaskDataOper::DeleteOldPlcStatusData()
{
_CommandPtr pCmdDel = NULL;
pCmdDel.CreateInstance(_uuidof(Command));
pCmdDel->ActiveConnection = theApp.m_pConnection;
CString strSql = _T("");
strSql.Format(_T("delete from OnlineDevStatus where id in (select id from OnlineDevStatus where DateDiff(\"d\", RepDate, date()) > 10)"));
try
{
theApp.m_pConnection->BeginTrans();
pCmdDel->CommandText = strSql.AllocSysString();
pCmdDel->Execute(NULL, NULL, adCmdText);
theApp.m_pConnection->CommitTrans();
}
catch(_com_error e)
{
AfxMessageBox(e.Description());
theApp.m_pConnection->RollbackTrans();
}
}
bool CTaskDataOper::InsertGrData(int iTaskID, WORD wGrNum, const char* pData, int iSptType)
{
_CommandPtr pCmdIns = NULL;
pCmdIns.CreateInstance(_uuidof(Command));
pCmdIns->ActiveConnection = theApp.m_pConnection;
CString strCreateDate = _T(""), strCreateTime = _T("");
strCreateDate.Format(_T("%04d-%02d-%02d"),g_sysCurTime.wYear, g_sysCurTime.wMonth, g_sysCurTime.wDay);
strCreateTime.Format(_T("%02d:%02d:%02d"), g_sysCurTime.wHour, g_sysCurTime.wMinute, g_sysCurTime.wSecond);
CString szSql;
INT32 iElecID = 0;
try
{
theApp.m_pConnection->BeginTrans();
/* CString strTxt = _T("");*/
for (int i = 0; i < wGrNum; i++)
{
STMeasuSigGRResult* pGrInfo = (STMeasuSigGRResult*)&pData[i*sizeof(STMeasuSigGRResult)];
if (0 == iSptType)
iElecID = (char)ntohl(pGrInfo->ucElecID);
else
iElecID = ntohl(pGrInfo->ucElecID);
szSql.Empty();
szSql.Format(_T("insert into gr(TDID ,Ecode , OMvalue, StatusCode, OM1value, StatusCode1, Mdate, Mtime) "
"values(%d, %d, %d, %d, %d, %d,#%s#, #%s#)"),
iTaskID, iElecID, (int)(ntohl(pGrInfo->iP1)), pGrInfo->ucP1Status,
(int)(ntohl(pGrInfo->iP2)), pGrInfo->ucP2Status, strCreateDate, strCreateTime);
pCmdIns->CommandText = szSql.AllocSysString();
pCmdIns->Execute(NULL, NULL, adCmdText);
}
theApp.m_pConnection->CommitTrans();
return true;
}
catch (_com_error e)
{
theApp.m_pConnection->RollbackTrans();
AfxMessageBox(e.Description());
return false;
}
}
bool CTaskDataOper::DeleteGrInfo(int iTaskID, WORD wElecID, BYTE ucDelFlag)
{
_CommandPtr pCmdIns = NULL;
pCmdIns.CreateInstance(_uuidof(Command));
pCmdIns->ActiveConnection = theApp.m_pConnection;
CString szSql = _T(""), strErr = _T("");
switch (ucDelFlag)
{
case EN_DEL_ALL:
szSql.Format(_T("delete from gr where tdid = %d"), iTaskID);
break;
case EN_DEL_SIG:
szSql.Format(_T("delete from gr where tdid = %d and Ecode = %d"),iTaskID, wElecID);
break;
case EN_DEL_FROM_ID:
szSql.Format(_T("delete from gr where tdid = %d and Ecode >= %d"),iTaskID, wElecID);
break;
default:
if (LANG_ZHCN == g_iUILanguage)
{
strErr.Format(_T("未知删除标志(%d)"), ucDelFlag);
AfxMessageBox(strErr);
}
else
{
strErr.Format(_T("Unknow delete flag(%d)"), ucDelFlag);
MessageBoxEx(NULL, strErr, STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
}
return false;
}
try
{
theApp.m_pConnection->BeginTrans();
pCmdIns->CommandText = szSql.AllocSysString();
pCmdIns->Execute(NULL, NULL, adCmdText);
theApp.m_pConnection->CommitTrans();
return true;
}
catch (_com_error e)
{
theApp.m_pConnection->RollbackTrans();
AfxMessageBox(e.Description());
return false;
}
}
bool CTaskDataOper::DeleteTimerTask(const std::vector<int>& vtTask)
{
if (vtTask.size() < 1)
{
if (LANG_ZHCN == g_iUILanguage)
AfxMessageBox(_T("不需要删除定时任务"));
else
MessageBoxEx(NULL, _T("No need to delete timer task"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
return false;
}
CString szSql = _T(""), strTxt = _T(""), strErr = _T("");
strTxt.Format(_T("%d"), vtTask[0]);
for (int i = 1; i < vtTask.size(); i++)
{
strErr.Empty();
strErr.Format(_T(",%d"), vtTask[i]);
strTxt = strTxt + strErr;
}
_CommandPtr pCmdIns = NULL;
pCmdIns.CreateInstance(_uuidof(Command));
pCmdIns->ActiveConnection = theApp.m_pConnection;
try
{
theApp.m_pConnection->BeginTrans();
szSql.Format(_T("delete from task_timer where TDID in (%s)"), strTxt);
pCmdIns->CommandText = szSql.AllocSysString();
pCmdIns->Execute(NULL, NULL, adCmdText);
theApp.m_pConnection->CommitTrans();
return true;
}
catch (_com_error e)
{
theApp.m_pConnection->RollbackTrans();
AfxMessageBox(e.Description());
return false;
}
}
bool CTaskDataOper::DeleteTimerTask(UINT32 uiTDID)
{
CString szSql = _T(""), strTxt = _T(""), strErr = _T("");
_CommandPtr pCmdIns = NULL;
pCmdIns.CreateInstance(_uuidof(Command));
pCmdIns->ActiveConnection = theApp.m_pConnection;
try
{
theApp.m_pConnection->BeginTrans();
szSql.Format(_T("delete from task_timer where TDID = %u"), uiTDID);
pCmdIns->CommandText = szSql.AllocSysString();
pCmdIns->Execute(NULL, NULL, adCmdText);
theApp.m_pConnection->CommitTrans();
return true;
}
catch (_com_error e)
{
theApp.m_pConnection->RollbackTrans();
AfxMessageBox(e.Description());
return false;
}
}
bool CTaskDataOper::DeleteTdDataInfo(BYTE ucTdType, int iTaskID, WORD wTsn, BYTE ucDelFlag)
{
_CommandPtr pCmdIns = NULL;
pCmdIns.CreateInstance(_uuidof(Command));
pCmdIns->ActiveConnection = theApp.m_pConnection;
CString szSql = _T(""), strErr = _T(""), strTd = _T("");
if (ucTdType > 2)
{
if (LANG_ZHCN == g_iUILanguage)
{
strErr.Format(_T("未知任务类型(%d)"), ucTdType);
AfxMessageBox(strErr);
}
else
{
strErr.Format(_T("Unknow Task type(%d)"), ucTdType);
MessageBoxEx(NULL, strErr, STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
}
return false;
}
strTd.Format(_T("td%ddcon"),ucTdType+1);
switch (ucDelFlag)
{
case EN_DEL_ALL:
szSql.Format(_T("delete from %s where TCHID in (select id from tdchannel where TDID = %d and CHnumber = 1)"), strTd, iTaskID);
break;
case EN_DEL_SIG:
szSql.Format(_T("delete from %s where TCHID in (select id from tdchannel where TDID = %d and CHnumber = 1) and TSN = %d"),
strTd, iTaskID, wTsn);
break;
case EN_DEL_FROM_ID:
szSql.Format(_T("delete from %s where TCHID in (select id from tdchannel where TDID = %d and CHnumber = 1) and TSN >= %d"),
strTd, iTaskID, wTsn);
break;
default:
if (LANG_ZHCN == g_iUILanguage)
{
strErr.Format(_T("未知删除类型(%d)"), ucDelFlag);
AfxMessageBox(strErr);
}
else
{
strErr.Format(_T("Unknow Delete type(%d)"), ucDelFlag);
MessageBoxEx(NULL, strErr, STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
}
return false;
}
try
{
theApp.m_pConnection->BeginTrans();
pCmdIns->CommandText = szSql.AllocSysString();
pCmdIns->Execute(NULL, NULL, adCmdText);
theApp.m_pConnection->CommitTrans();
return true;
}
catch (_com_error e)
{
theApp.m_pConnection->RollbackTrans();
AfxMessageBox(e.Description());
return false;
}
}
void CTaskDataOper::QueryTimerTaskValiad(std::vector<STTimerTask>& vtTimerTask, const SYSTEMTIME &sysCurTime)
{
vtTimerTask.clear();
_RecordsetPtr pRecTd = NULL;
pRecTd.CreateInstance(_uuidof(Recordset));
CString strSql = _T(""), strDate = _T(""), strTime = _T("");
strDate.Format(_T("#%04d-%d-%d#"),sysCurTime.wYear, sysCurTime.wMonth,sysCurTime.wDay);
strTime.Format(_T("#%d:%d:00#"), sysCurTime.wHour, sysCurTime.wMinute);
strSql.Format(_T("select * from task_timer where RunDate > %s or (RunDate = %s and RunTime > %s) order by RunDate,RunTime"), strDate, strDate,strTime);
STTimerTask stTimeTd;
try
{
pRecTd->Open(strSql.AllocSysString(),_variant_t((IDispatch*)theApp.m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText);
while(0 == pRecTd->adoEOF)
{
stTimeTd.uiTaskID = pRecTd->GetCollect(_T("TDID")).llVal;
stTimeTd.strTaskName = (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("TdName"));
stTimeTd.strRunTime.Empty();
stTimeTd.strRunTime.Format(_T("%s %s"), (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("RunDate")),(LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("RunTime")));
stTimeTd.strPlcID=(LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("PLCID"));
vtTimerTask.push_back(stTimeTd);
pRecTd->MoveNext();
}
pRecTd->Close();
}
catch (_com_error e)
{
AfxMessageBox(e.Description());
}
}