// RspCETd.cpp: implementation of the CRspCETd class. // ////////////////////////////////////////////////////////////////////// #include "geomative.h" #include "RspCETd.h" #include "TdChannel.h" #include "OpRspCEMarineSettingDlg.h" #include "opexec2drsptestsetdlg.h" #include "excel.h" #include "DispCERSPGrapDlg.h" #include "disptdrecsplinesgrapdlg.h" #include "OperTxtFile.h" using namespace excel9; #ifdef _DEBUG #undef THIS_FILE static char THIS_FILE[]=__FILE__; #define new DEBUG_NEW #endif extern int g_iLanguage; extern BOOL GetSubStringInHeadAndTail(const CString& szSource, CString& szSub, const CString& szHead, const CString& szTail); extern CString GetGrCodeText(int iCode); extern int g_UIOffset; extern int g_iUILanguage; extern char *g_chRecMode[30]; extern char *g_chCurPoleDepoly[35]; ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// extern HHOOK hHook; extern LRESULT __stdcall CBTHookProc(long nCode, WPARAM wParam, LPARAM lParam); CRspCETd::CRspCETd(DWORD dwID, _ConnectionPtr& pConnection):CTestingData(dwID, pConnection) { } CRspCETd::~CRspCETd() { ClearTdChaList(); } BOOL CRspCETd::SaveData() { CTdChannel* pTdChannel = NULL; _RecordsetPtr pRecTd; _CommandPtr pCmdIns; CString szSql = _T(""); int iChIndex = (int)VAL_ZERO; pRecTd.CreateInstance(_uuidof(Recordset)); pCmdIns.CreateInstance(_uuidof(Command)); pCmdIns->ActiveConnection = m_pConnection; try { m_pConnection->BeginTrans(); // int iPoleStep = atoi(this->m_szEDistance.GetBuffer(0)); float fPoleDistance = (float)atof(this->m_szEDistance.GetBuffer(0)); szSql.Empty(); szSql.Format(_T("insert into td(TDname,TDCN,Tlocation,DEID,DESN,TZID,SCID,SCCN,Sname,Stype,Ttype,Tmode,Eamount,TPamount,CHamount,N,TRwave,TRfrequency,Ifrequency," "SAfrequency,Clayout,Espace,Edistance,weather,WDIR,temperature,height,humidity,Cdate,Ctime,Tdate,Ttime,Rdirection,CRtime,PM,OP,QA) " "values('%s','%s','%s',%u,'%s',%u,%u,'%s','%s',%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%.2f,%.2f,%d,%d,%.2f,%.2f,%.2f,#%s#,#%s#,#%s#,#%s#,%d,%d,'%s','%s','%s')"), this->m_szTdName, this->m_szTdCN, this->m_szTLocation, this->m_pDevice->m_dwID, this->m_pDevice->m_szDevSN, this->m_dwTzID, this->m_dwSCID, this->m_szSCCN, this->m_szSName, this->m_iSType, this->m_iTType, this->m_iTMode, this->m_iEAmount, this->m_iTPAmount, this->m_iCHAmount, this->m_iN, this->m_iTRWave, this->m_iTRFrequency, this->m_iIFrequency, this->m_iSAFrequency, this->m_iCLayout, this->m_fESpace, //this->m_szEDistance, fPoleDistance, this->m_iWeather, this->m_iWDIR, this->m_fTemperature, this->m_fHeight, this->m_fHumidity, this->m_szCDate, this->m_szCTime, this->m_szTDate, this->m_szTTime, this->m_iRDirection, this->m_iCRtime, this->m_szPM, this->m_szOP, this->m_szQA); pCmdIns->CommandText = szSql.AllocSysString(); pCmdIns->Execute(NULL, NULL, adCmdText); pRecTd->Open(_T("select max(ID) as ID from td"), _variant_t((IDispatch*)m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText); if ((long)VAL_ZERO != pRecTd->GetRecordCount()) { this->m_dwID = (int)pRecTd->GetCollect(_T("ID")).ulVal; } pRecTd->Close(); iChIndex = (int)VAL_ZERO; while (iChIndex < m_tdChaList.GetCount()) { pTdChannel = NULL; pTdChannel = (CTdChannel*)m_tdChaList.GetAt(m_tdChaList.FindIndex(iChIndex)); pTdChannel->SaveRspCETdData(m_dwID); iChIndex++; } // if (TRUE != this->SaveOrgDataToDB(m_dwID)) // { // throw; // } this->SaveOrgDataToDB(m_dwID); m_pConnection->CommitTrans(); } catch(...) { m_pConnection->RollbackTrans(); // AfxMessageBox(e.Description()); return FALSE; } return TRUE; } BOOL CRspCETd::LoadData(CLinkList& m_medLinkList) { CTdChannel* pTdChannel = NULL; DWORD dwSCID = (DWORD)VAL_ZERO; DWORD dwMedHandle = (DWORD)VAL_ZERO; int iEAmount = (int)VAL_ZERO; _RecordsetPtr pRecTd; _RecordsetPtr pRecCh; _RecordsetPtr pRecTdCon; CString szSql = _T(""); int iChIndex = (int)VAL_ZERO; if ((int)VAL_ZERO == m_tdChaList.GetCount()) { pRecTd.CreateInstance(_uuidof(Recordset)); pRecCh.CreateInstance(_uuidof(Recordset)); szSql.Empty(); szSql.Format(_T("select SCID,Eamount from td where ID = %u"), this->m_dwID); pRecTd->Open(szSql.AllocSysString(), _variant_t((IDispatch*)m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText); if ((long)VAL_ZERO != pRecTd->GetRecordCount()) { dwSCID = (DWORD)pRecTd->GetCollect(_T("SCID")).ulVal; iEAmount = (int)pRecTd->GetCollect(_T("Eamount")).iVal; } pRecTd->Close(); szSql.Empty(); szSql.Format(_T("select ID,ChNumber,AR from tdchannel where TDID = %u"), this->m_dwID); pRecCh->Open(szSql.AllocSysString(), _variant_t((IDispatch*)m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText); while ((short)VAL_ZERO == pRecCh->adoEOF) { pTdChannel = new CTdChannel(dwSCID, (int)pRecCh->GetCollect(_T("ChNumber")).iVal, this->m_pConnection); pTdChannel->m_dwID = (DWORD)pRecCh->GetCollect(_T("ID")).ulVal; pTdChannel->m_iEAmount = iEAmount; dwMedHandle = m_handleProcessor.GenerateHandle((int)pRecCh->GetCollect(_T("AR")).iVal, PZ_STYLE_MED_DEF); pTdChannel->m_pMedium = m_medLinkList.Find(dwMedHandle); if (TRUE == pTdChannel->LoadRspCETdData()) { this->m_tdChaList.AddTail((void*)pTdChannel); } pRecCh->MoveNext(); } pRecCh->Close(); } return TRUE; } void CRspCETd::ClearTdChaList() { CTdChannel* pTdChannel = NULL; int iTdChannelIndex = (int)VAL_ZERO; iTdChannelIndex = (int)VAL_ZERO; while (iTdChannelIndex < this->m_tdChaList.GetCount()) { pTdChannel = NULL; pTdChannel = (CTdChannel *)this->m_tdChaList.GetAt(this->m_tdChaList.FindIndex(iTdChannelIndex)); pTdChannel->ClearCESptRecList(); delete pTdChannel; iTdChannelIndex++; } this->m_tdChaList.RemoveAll(); } BOOL CRspCETd::SaveCERSPSetInfo(COpExec2DRSPTestSetDlg* pOpExec2DRSPTestSetDlg, CLinkList& m_medLinkList) { _RecordsetPtr pRecTdChaList = NULL; CString szSql = _T(""); CString szLbText = _T(""); CString szPro = _T(""); CString szPrCN = _T(""); CString szTzName = _T(""); CString szTzCN = _T(""); DWORD dwMedHandle = (DWORD)VAL_ZERO; int iChNum = (int)VAL_ZERO; int iSptIndex = (int)VAL_ZERO; POSITION posSpt; CTime tCT; CString szEdCon = _T(""); DWORD dwSptHandle = (DWORD)VAL_ZERO; DWORD dwSptID = (DWORD)VAL_ZERO; tCT = CTime::GetCurrentTime(); this->m_szTdName = pOpExec2DRSPTestSetDlg->m_szName; this->m_szTdCN = _T("VESR")+tCT.FormatGmt(_T("%Y%m%d"))+tCT.FormatGmt(_T("%H%M%S")); this->m_szTLocation = pOpExec2DRSPTestSetDlg->m_szLocation; this->m_dwID = (DWORD)VAL_ZERO; this->m_pDevice = (CDevice*)pOpExec2DRSPTestSetDlg->m_cbDESN.GetItemData(pOpExec2DRSPTestSetDlg->m_cbDESN.GetCurSel()); posSpt = pOpExec2DRSPTestSetDlg->m_opCESptSelDlg.m_ceSptList.GetFirstSelectedItemPosition(); iSptIndex = pOpExec2DRSPTestSetDlg->m_opCESptSelDlg.m_ceSptList.GetNextSelectedItem(posSpt); dwSptHandle = pOpExec2DRSPTestSetDlg->m_opCESptSelDlg.m_ceSptList.GetItemData(iSptIndex); dwSptID = this->m_handleProcessor.GetIDFromHandle(dwSptHandle); this->m_dwSCID = dwSptID; this->m_szSCCN = pOpExec2DRSPTestSetDlg->m_opCESptSelDlg.m_ceSptList.GetItemText(iSptIndex, 0); this->m_szSName = pOpExec2DRSPTestSetDlg->m_opCESptSelDlg.m_ceSptList.GetItemText(iSptIndex, 1); this->m_iSType = (int)VAL_ZERO; this->m_iTType = (int)VAL_ZERO; this->m_iEAmount = atoi(pOpExec2DRSPTestSetDlg->m_opCESptSelDlg.m_ceSptList.GetItemText(iSptIndex, 2)); // this->m_iCHAmount = atoi(pOpExec2DRSPTestSetDlg->m_opCESptSelDlg.m_ceSptList.GetItemText(iSptIndex, 3)); // this->m_iTPAmount = atoi(pOpExec2DRSPTestSetDlg->m_opCESptSelDlg.m_ceSptList.GetItemText(iSptIndex, 4)); this->m_iCHAmount = (int)VAL_ONE; this->m_iTPAmount = atoi(pOpExec2DRSPTestSetDlg->m_opCESptSelDlg.m_ceSptList.GetItemText(iSptIndex, 3)); szPro.Empty(); pOpExec2DRSPTestSetDlg->m_cbPrName.GetLBText(pOpExec2DRSPTestSetDlg->m_cbPrName.GetCurSel(), szPro); szPrCN.Empty(); GetSubStringInHeadAndTail(szPro, szPrCN, _T("("), _T(")")); this->m_szPrCN = szPrCN; szTzName.Empty(); pOpExec2DRSPTestSetDlg->m_cbTzName.GetLBText(pOpExec2DRSPTestSetDlg->m_cbTzName.GetCurSel(), szTzName); this->m_szTzName = szTzName; szTzCN.Empty(); GetSubStringInHeadAndTail(szTzName, szTzCN, _T("("), _T(")")); this->m_szTzCN = szTzCN; this->m_dwTzID = pOpExec2DRSPTestSetDlg->m_cbTzName.GetItemData(pOpExec2DRSPTestSetDlg->m_cbTzName.GetCurSel()); this->m_iCLayout = pOpExec2DRSPTestSetDlg->m_cbCLayout.GetCurSel(); szEdCon.Empty(); pOpExec2DRSPTestSetDlg->m_edESpace.GetWindowText(szEdCon); this->m_fESpace = (float)atof(szEdCon.GetBuffer(0)); this->m_szEDistance = pOpExec2DRSPTestSetDlg->m_szEDistance; this->m_iCRtime = (int)VAL_ZERO; this->m_iRDirection = (int)VAL_ZERO; this->m_iIFrequency = pOpExec2DRSPTestSetDlg->m_iIFrequency; this->m_iSAFrequency = pOpExec2DRSPTestSetDlg->m_iSAFrequency; this->m_iTRFrequency = pOpExec2DRSPTestSetDlg->m_iTRFrenquency; this->m_fTRPeriod = pOpExec2DRSPTestSetDlg->m_fTRPeriod; this->m_fTRPeriod = 1000/(float)atof(szLbText); this->m_iTMode = pOpExec2DRSPTestSetDlg->m_iTestMode; this->m_iTRWave = m_iTRWave; szEdCon.Empty(); pOpExec2DRSPTestSetDlg->m_edHeight.GetWindowText(szEdCon); this->m_fHeight = (float)atof(szEdCon.GetBuffer(0)); szEdCon.Empty(); pOpExec2DRSPTestSetDlg->m_edHumidity.GetWindowText(szEdCon); this->m_fHumidity = (float)atof(szEdCon.GetBuffer(0)); szEdCon.Empty(); pOpExec2DRSPTestSetDlg->m_edTemperature.GetWindowText(szEdCon); this->m_fTemperature = (float)atof(szEdCon.GetBuffer(0)); this->m_iWDIR = pOpExec2DRSPTestSetDlg->m_cbWDIR.GetCurSel(); this->m_iWeather = pOpExec2DRSPTestSetDlg->m_cbWeather.GetCurSel(); this->m_iN = (int)VAL_ONE; this->m_szCDate = tCT.FormatGmt(_T("%Y-%m-%d")); this->m_szCTime = tCT.FormatGmt(_T("%H:%M:%S")); this->m_szTDate = tCT.FormatGmt(_T("%Y-%m-%d")); this->m_szTTime = tCT.FormatGmt(_T("%H:%M:%S")); this->m_iRCamount = (int)VAL_ZERO; this->m_iRDirection = (int)VAL_ZERO; this->m_iCRtime = (int)VAL_ZERO; this->m_szOP = pOpExec2DRSPTestSetDlg->m_szOP; this->m_szPM = pOpExec2DRSPTestSetDlg->m_szPM; this->m_szQA = pOpExec2DRSPTestSetDlg->m_szQA; this->m_tdChaList.RemoveAll(); pRecTdChaList.CreateInstance(_uuidof(Recordset)); szSql.Empty(); szSql.Format(_T("select CHnumber,AR from channel where SCID = %u order by CHnumber"), this->m_dwSCID); pRecTdChaList->Open(szSql.AllocSysString(), _variant_t((IDispatch*)m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText); while ((short)VAL_ZERO == pRecTdChaList->adoEOF) { iChNum = pRecTdChaList->GetCollect(_T("CHnumber")).iVal; CTdChannel* pTdChannel = new CTdChannel(this->m_dwSCID, iChNum, m_pConnection); dwMedHandle = m_handleProcessor.GenerateHandle(pRecTdChaList->GetCollect(_T("AR")).iVal, PZ_STYLE_MED_DEF); pTdChannel->m_pMedium = m_medLinkList.Find(dwMedHandle); pTdChannel->m_iEAmount = this->m_iEAmount; this->m_tdChaList.AddTail((void*)pTdChannel); pRecTdChaList->MoveNext(); } pRecTdChaList->Close(); return TRUE; } BOOL CRspCETd::SaveHeadInfoToFile(CString& szFilePath, CString& szFileName) { CMarkup* pXML = new CMarkup; CTdChannel* pTdChannel = NULL; POSITION pos; CString szCon = _T(""); CString szFile = _T(""); pXML->SetDoc("\r\n"); pXML->AddElem("measure"); pXML->AddChildElem(_T("measure_name"), this->m_szTdName); pXML->AddChildElem(_T("measure_location"), this->m_szTLocation); pXML->AddChildElem(_T("measure_script_id"), this->m_szSCCN); pXML->AddChildElem(_T("measure_script_name"), this->m_szSName); pXML->AddChildElem(_T("measure_script_type"), 0); pXML->AddChildElem(_T("measure_type"), 0); pXML->AddChildElem(_T("measure_mode"), this->m_iTMode); pXML->AddChildElem(_T("medium_set")); pXML->IntoElem(); pos = this->m_tdChaList.GetHeadPosition(); while (pos != NULL) { pTdChannel = (CTdChannel*)m_tdChaList.GetNext(pos); if(pTdChannel != NULL) { szCon.Empty(); szCon.Format(_T("%d:%d"), pTdChannel->m_iChNum, pTdChannel->m_pMedium->m_iAR); pXML->AddChildElem(_T("medium"), szCon); } } pXML->OutOfElem(); pXML->AddChildElem(_T("pole_count"), this->m_iEAmount); pXML->AddChildElem(_T("pole_distance"), this->m_szEDistance); szCon.Empty(); szCon.Format(_T("%.2f"), this->m_fESpace); pXML->AddChildElem(_T("pole_gap"), szCon); pXML->AddChildElem(_T("rect"), _T("")); pXML->AddChildElem(_T("rect_loc"), _T("")); pXML->AddChildElem(_T("wires_layout"), this->m_iCLayout); pXML->AddChildElem(_T("point_count"), this->m_iTPAmount); pXML->AddChildElem(_T("rolling_times"), 0); pXML->AddChildElem(_T("rolling_direction"), 0); pXML->AddChildElem(_T("rolling_step"), _T("")); pXML->AddChildElem(_T("channel_count"), this->m_iCHAmount); pXML->AddChildElem(_T("iterations"), 1); pXML->AddChildElem(_T("emit_source"), _T("")); pXML->AddChildElem(_T("wave_shape"), this->m_iTRWave); pXML->AddChildElem(_T("period"), this->m_iTRFrequency); pXML->AddChildElem(_T("industrial_frequency"), this->m_iIFrequency); pXML->AddChildElem(_T("sample_rate"), this->m_iSAFrequency); pXML->AddChildElem(_T("sample_interval"), _T("")); pXML->AddChildElem(_T("v_gain"), _T("")); pXML->AddChildElem(_T("i_gain"), _T("")); szCon.Empty(); szCon.Format(_T("%.2f"), this->m_fTemperature); pXML->AddChildElem(_T("temperature"), szCon); szCon.Empty(); szCon.Format(_T("%.2f"), this->m_fHeight); pXML->AddChildElem(_T("height"), szCon); szCon.Empty(); szCon.Format(_T("%.2f"), this->m_fHumidity); pXML->AddChildElem(_T("humidity"), szCon); pXML->AddChildElem(_T("weather"), this->m_iWeather); pXML->AddChildElem(_T("wind_direction"), this->m_iWDIR); pXML->AddChildElem(_T("create_date"), this->m_szCDate); pXML->AddChildElem(_T("create_time"), this->m_szCTime); pXML->AddChildElem(_T("test_date"), this->m_szTDate); pXML->AddChildElem(_T("test_time"), this->m_szTTime); pXML->AddChildElem(_T("PM"), this->m_szPM); pXML->AddChildElem(_T("OP"), this->m_szOP); pXML->AddChildElem(_T("QA"), this->m_szQA); pXML->AddChildElem(_T("apparent_chargeability")); //m0 pXML->IntoElem(); pXML->AddChildElem(_T("m0")); pXML->AddChildElem(_T("m1")); pXML->AddChildElem(_T("m2")); pXML->AddChildElem(_T("m3")); pXML->AddChildElem(_T("m4")); pXML->AddChildElem(_T("m5")); pXML->AddChildElem(_T("m6")); pXML->AddChildElem(_T("m7")); pXML->AddChildElem(_T("m8")); pXML->AddChildElem(_T("m9")); pXML->OutOfElem(); //m9 szFilePath.Empty(); szFilePath.GetBufferSetLength(2048); ::GetCurrentDirectory(2048, szFilePath.GetBuffer(szFilePath.GetLength())); szFilePath.ReleaseBuffer(); szFilePath = szFilePath + "\\CACHE\\projects\\"; szFilePath += this->m_szPrCN + "\\" + this->m_szTzCN + "\\"; szFileName.Empty(); szFileName = this->m_szTdCN+_T(".xml"); szFile.Empty(); szFile = szFilePath + szFileName; DeleteFile(szFile); pXML->Save(szFile); delete pXML; return TRUE; } bool CRspCETd::ShowConList(CListCtrl &tdConList) { _RecordsetPtr pRecConList = NULL; CString szSql = _T(""); CString szValue = _T(""); int iIndex = (int)VAL_ZERO; pRecConList.CreateInstance(_uuidof(Recordset)); if (VAL_ZERO != tdConList.GetItemCount()) { tdConList.DeleteAllItems(); } szSql.Empty(); szSql.Format(_T("select top %d TSN,a,b,x,y,N,K,I,V,R0,SP,bUse from td1dcon where TEST_FLAG = 1 and TCHID in (select ID from tdchannel where TDID = %u order by TCHID) order by TSN"), ONE_PAGE_DATA_NUMBER, m_dwID); OutputDebugString(szSql + _T("\n")); try { pRecConList->Open(szSql.AllocSysString(), _variant_t((IDispatch*)m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText); } catch (_com_error e) { hHook = SetWindowsHookEx(WH_CBT,(HOOKPROC)CBTHookProc,AfxGetInstanceHandle(),NULL); AfxMessageBox((LPCTSTR)e.Description()); } CString strDBVal = _T(""); float fV = 0, fI = 0, fR = 0; while ((short)VAL_ZERO == pRecConList->adoEOF) { if (pRecConList->GetCollect(_T("bUse")).boolVal != 0)//0为access数据库中的false { tdConList.InsertItem(iIndex, (LPCTSTR)(_bstr_t)pRecConList->GetCollect(_T("a"))); tdConList.SetItemText(iIndex, 1, (LPCTSTR)(_bstr_t)pRecConList->GetCollect(_T("b"))); tdConList.SetItemText(iIndex, 2, (LPCTSTR)(_bstr_t)pRecConList->GetCollect(_T("x"))); tdConList.SetItemText(iIndex, 3, (LPCTSTR)(_bstr_t)pRecConList->GetCollect(_T("y"))); tdConList.SetItemText(iIndex, 4, (LPCTSTR)(_bstr_t)pRecConList->GetCollect(_T("N"))); strDBVal.Empty(); strDBVal.Format(_T("%f"),(float)pRecConList->GetCollect(_T("K")).fltVal); tdConList.SetItemText(iIndex, 5, strDBVal); strDBVal.Empty(); strDBVal.Format(_T("%f"),(float)pRecConList->GetCollect(_T("I")).fltVal); tdConList.SetItemText(iIndex, 6, strDBVal); fI = (float)pRecConList->GetCollect(_T("I")).fltVal; strDBVal.Empty(); strDBVal.Format(_T("%f"),(float)pRecConList->GetCollect(_T("V")).fltVal); tdConList.SetItemText(iIndex, 7, strDBVal); fV = (float)pRecConList->GetCollect(_T("V")).fltVal; //添加R fR = (0 == fI) ? 0 : fV/fI; strDBVal.Empty(); strDBVal.Format(_T("%f"),fR); tdConList.SetItemText(iIndex, 8, strDBVal); strDBVal.Empty(); strDBVal.Format(_T("%f"),(float)pRecConList->GetCollect(_T("R0")).fltVal); tdConList.SetItemText(iIndex, 9, strDBVal); strDBVal.Empty(); strDBVal.Format(_T("%f"),(float)pRecConList->GetCollect(_T("SP")).fltVal); tdConList.SetItemText(iIndex, 10, strDBVal); tdConList.SetItemData(iIndex, (int)pRecConList->GetCollect(_T("TSN")).lVal); iIndex++; } pRecConList->MoveNext(); } pRecConList->Close(); return true; } bool CRspCETd::ShowGrList(CListCtrl &tdGrList) { _RecordsetPtr pRecGrList = NULL; _RecordsetPtr pRecTdchannel = NULL; CString szSql = _T(""); CString szLabel = _T(""); int iIndex = (int)VAL_ZERO; int iAR = 0; pRecGrList.CreateInstance(_uuidof(Recordset)); pRecTdchannel.CreateInstance(_uuidof(Recordset)); if ((int)VAL_ZERO != tdGrList.GetItemCount()) { tdGrList.DeleteAllItems(); } try { szSql.Empty(); szSql.Format(_T("select AR from tdchannel where TDID = %u"),m_dwID); pRecTdchannel->Open(szSql.AllocSysString(), _variant_t((IDispatch*)m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText); if (pRecTdchannel->GetRecordCount() < 0) { if (LANG_ZHCN == g_iUILanguage) AfxMessageBox(_T("查询任务AR信息错误")); else MessageBoxEx(NULL, _T("Query task AR information failed"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)); pRecTdchannel->Close(); return false; } iAR = pRecTdchannel->GetCollect(_T("AR")).iVal; pRecTdchannel->Close(); szSql.Empty(); szSql.Format(_T("select Ecode,Format(Mdate,'YYYY-MM-DD') as Mdate,Format(Mtime,'HH:MM:SS') as Mtime, OMvalue, ") _T(" StatusCode, OM1value, StatusCode1 from gr where TDID = %u order by Val(Ecode) desc"), m_dwID); pRecGrList->Open(szSql.AllocSysString(), _variant_t((IDispatch*)m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText); int iOMVal = -1, iOMVal1 = -1; CString strOMVal, strOM1Val; CString strMdate, strMtime; CString strStatus, strStatus1; CString strElectrode = _T(""); while ((short)VAL_ZERO == pRecGrList->adoEOF) { strElectrode.Empty(); strElectrode = (LPCTSTR)(_bstr_t)pRecGrList->GetCollect(_T("Ecode")); strElectrode.TrimLeft(); strElectrode.TrimRight(); if (_T("-1") == strElectrode) { strElectrode = _T("AB"); } else if (_T("-2") == strElectrode) { strElectrode = _T("MN"); } else { int iElectrode = atoi(strElectrode); if (iElectrode < -2) { strElectrode.Empty(); strElectrode.Format(_T("MN%d"),abs(iElectrode)-2); } else { //CString strErr = _T(""); //if (LANG_ZHCN == g_iUILanguage) //{ // strErr.Format(_T("没有期望的电极编号(%s)."), strElectrode); // AfxMessageBox(strErr); //} //else //{ // strErr.Format(_T("Unexpected electrode id(%s)."), strElectrode); // MessageBoxEx(NULL, strErr, STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)); //} //pRecGrList->Close(); //return false; strElectrode.Empty(); strElectrode.Format(_T("%d"), abs(iElectrode)); } } tdGrList.InsertItem(iIndex, strElectrode); strOMVal.Empty(); strOM1Val.Empty(); strMdate.Empty(); strMtime.Empty(); strStatus.Empty(); strStatus1.Empty(); iOMVal = (pRecGrList->GetCollect(_T("OMvalue")).vt == VT_NULL)?-1:(int)pRecGrList->GetCollect(_T("OMvalue")).lVal; if (-1 != iOMVal) { strOMVal.Format(_T("%d"),iOMVal); strMdate = (LPCTSTR)(_bstr_t)pRecGrList->GetCollect(_T("Mdate")); strMtime = (LPCTSTR)(_bstr_t)pRecGrList->GetCollect(_T("Mtime")); strStatus = GetGrCodeText((int)pRecGrList->GetCollect(_T("StatusCode")).lVal); } int iStartIndex = 0; tdGrList.SetItemText(iIndex, ++iStartIndex, strOMVal); tdGrList.SetItemText(iIndex, ++iStartIndex, strStatus); // if (AR_MARINE == iAR) // { // iOMVal1 = (int)pRecGrList->GetCollect(_T("OM1value")).lVal; // if (-1 != iOMVal1) // { // strOM1Val.Format(_T("%d"),iOMVal1); // strStatus1 = GetGrCodeText((int)pRecGrList->GetCollect(_T("StatusCode1")).lVal); // } // tdGrList.SetItemText(iIndex, ++iStartIndex, strOM1Val); // tdGrList.SetItemText(iIndex, ++iStartIndex, strStatus1); // } tdGrList.SetItemText(iIndex, ++iStartIndex, strMdate); tdGrList.SetItemText(iIndex, ++iStartIndex, strMtime); iIndex++; pRecGrList->MoveNext(); } } catch(_com_error e) { hHook = SetWindowsHookEx(WH_CBT,(HOOKPROC)CBTHookProc,AfxGetInstanceHandle(),NULL); AfxMessageBox((LPCTSTR)e.Description()); pRecGrList->Close(); return false; } pRecGrList->Close(); return true; } bool CRspCETd::ShowDetailInfo(CListCtrl &tdDetailList) { _RecordsetPtr pRecTd = NULL; _RecordsetPtr pRecTdHead = NULL; _RecordsetPtr pRecDev = NULL; _RecordsetPtr pRecPara = NULL; _RecordsetPtr pRecCm = NULL; _RecordsetPtr pRecTdSpcAttr = NULL; CString szSql; CString szLabel; int iRowIndex = (int)VAL_ZERO; while (tdDetailList.GetItemCount() != iRowIndex) { tdDetailList.SetItemText(iRowIndex, 1, _T("")); iRowIndex++; } pRecTd.CreateInstance(_uuidof(Recordset)); pRecTdHead.CreateInstance(_uuidof(Recordset)); pRecDev.CreateInstance(_uuidof(Recordset)); pRecPara.CreateInstance(_uuidof(Recordset)); pRecCm.CreateInstance(_uuidof(Recordset)); pRecTdSpcAttr.CreateInstance(_uuidof(Recordset)); szSql.Empty(); szSql.Format(_T("select a.ID,TDname,Tlocation,DESN,SCCN,Sname,Stype,Ttype,Tmode,Eamount,TPamount,CHamount,N,TRwave,TRfrequency,Ifrequency,SAfrequency,Clayout,Espace,Edistance,weather,WDIR," "temperature,height,humidity,Format(a.Cdate,'YYYY-MM-DD') as Cdate,Format(a.Ctime,'HH:MM:SS') as Ctime,Format(a.Tdate,'YYYY-MM-DD') as Tdate,Format(a.Ttime,'HH:MM:SS') as Ttime," "Rdirection,CRtime,IIf(IsNull(a.PM),'',a.PM) as PM,IIf(IsNull(a.OP),'',a.OP) as OP,IIf(IsNull(a.QA),'',a.QA) as QA, b.AR as AR from td a, tdchannel b where a.ID = %u and a.ID = b.TDID"), m_dwID); pRecTd->Open(szSql.AllocSysString(), _variant_t((IDispatch*)m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText); iRowIndex = 0; if ((long)VAL_ZERO != pRecTd->GetRecordCount()) { tdDetailList.SetItemText(iRowIndex++, 1, (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("TDname"))); tdDetailList.SetItemText(iRowIndex++, 1, (pRecTd->GetCollect(_T("DESN")).vt == VT_NULL) ? _T("") : (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("DESN"))); tdDetailList.SetItemText(iRowIndex++, 1, (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("Sname"))); szSql.Empty(); szSql.Format(_T("select Clabel from cm where Cname = 'Stype' and Lang = %d and Cvalue = %s"), g_iLanguage, pRecTd->GetCollect(_T("Stype")).vt == VT_NULL ? _T("-1") : (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("Stype"))); pRecCm->Open(szSql.AllocSysString(), _variant_t((IDispatch*)m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText); if ((long)VAL_ZERO != pRecCm->GetRecordCount()) { tdDetailList.SetItemText(iRowIndex++, 1, (LPCTSTR)(_bstr_t)pRecCm->GetCollect(_T("Clabel"))); } else { tdDetailList.SetItemText(iRowIndex++, 1, _T("")); } pRecCm->Close(); szSql.Empty(); szSql.Format(_T("select Clabel from cm where Cname = 'Ttype' and Lang = %d and Cvalue = %s"), g_iLanguage, pRecTd->GetCollect(_T("Ttype")).vt == VT_NULL ? _T("-1") : (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("Ttype"))); pRecCm->Open(szSql.AllocSysString(), _variant_t((IDispatch*)m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText); if ((long)VAL_ZERO != pRecCm->GetRecordCount()) { tdDetailList.SetItemText(iRowIndex++, 1, (LPCTSTR)(_bstr_t)pRecCm->GetCollect(_T("Clabel"))); } else { tdDetailList.SetItemText(iRowIndex++, 1, _T("")); } pRecCm->Close(); szSql.Empty(); szSql.Format(_T("select Clabel from cm where Cname = 'Tmode' and Lang = %d and Cvalue = %s"), g_iLanguage, pRecTd->GetCollect(_T("Tmode")).vt == VT_NULL ? _T("-1") : (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("Tmode"))); pRecCm->Open(szSql.AllocSysString(), _variant_t((IDispatch*)m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText); if ((long)VAL_ZERO != pRecCm->GetRecordCount()) { // tdDetailList.SetItemText(6, 1, (LPCTSTR)(_bstr_t)pRecCm->GetCollect(_T("Clabel"))); } pRecCm->Close(); ///////////////////////////////////加入装置类型//////////////////////////// szSql.Empty(); szSql.Format(_T("select MEname from medium where LANG = %d and AR in (select AR from tdchannel where TDID = %d)"), g_iLanguage, m_dwID); pRecCm->Open(szSql.AllocSysString(), _variant_t((IDispatch*)m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText); if ((long)VAL_ZERO != pRecCm->GetRecordCount()) { tdDetailList.SetItemText(iRowIndex++, 1, (LPCTSTR)(_bstr_t)pRecCm->GetCollect(_T("MEname"))); } else { tdDetailList.SetItemText(iRowIndex++, 1, _T("")); } pRecCm->Close(); ////////////////////////////////////////////////////////////////////////// tdDetailList.SetItemText(iRowIndex++, 1, (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("Eamount"))); szSql.Empty(); szSql.Format(_T("select count(*) as TotalPoints from td%ddcon where TCHID = %d"), pRecTd->GetCollect(_T("Stype")).vt == VT_NULL ? 1 : pRecTd->GetCollect(_T("Stype")).iVal + 1, m_dwID); pRecCm->Open(szSql.AllocSysString(), _variant_t((IDispatch*)m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText); if ((long)VAL_ZERO != pRecCm->GetRecordCount()) { tdDetailList.SetItemText(iRowIndex++, 1, (LPCTSTR)(_bstr_t)pRecCm->GetCollect(_T("TotalPoints"))); } else { tdDetailList.SetItemText(iRowIndex++, 1, _T("")); } pRecCm->Close(); tdDetailList.SetItemText(iRowIndex++, 1, (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("TPamount"))); tdDetailList.SetItemText(iRowIndex++, 1, (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("CHamount"))); tdDetailList.SetItemText(iRowIndex++, 1, (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("N"))); szSql.Empty(); szSql.Format(_T("select Clabel from cm where Cname = 'TRwave' and Lang = %d and Cvalue = %s"), g_iLanguage, pRecTd->GetCollect(_T("TRwave")).vt == VT_NULL ? _T("-1") : (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("TRwave"))); pRecCm->Open(szSql.AllocSysString(), _variant_t((IDispatch*)m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText); if ((long)VAL_ZERO != pRecCm->GetRecordCount()) { tdDetailList.SetItemText(iRowIndex++, 1, (LPCTSTR)(_bstr_t)pRecCm->GetCollect(_T("Clabel"))); } else { tdDetailList.SetItemText(iRowIndex++, 1, _T("")); } pRecCm->Close(); if ((0 == pRecTd->GetCollect(_T("Ttype")).iVal) || (1 == pRecTd->GetCollect(_T("Ttype")).iVal)) { szSql.Empty(); szSql.Format(_T("select Clabel from cm where Cname = 'Trfrequency' and Lang = %d and Cvalue = %s"), g_iLanguage, pRecTd->GetCollect(_T("Trfrequency")).vt == VT_NULL ? _T("-1") : (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("Trfrequency"))); pRecCm->Open(szSql.AllocSysString(), _variant_t((IDispatch*)m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText); if ((long)VAL_ZERO != pRecCm->GetRecordCount()) { tdDetailList.SetItemText(iRowIndex++, 1, (LPCTSTR)(_bstr_t)pRecCm->GetCollect(_T("Clabel"))); } else { tdDetailList.SetItemText(iRowIndex++, 1, _T("")); } pRecCm->Close(); } else if (2 == pRecTd->GetCollect(_T("Ttype")).iVal) { szSql.Empty(); szSql.Format(_T("select Clabel from cm where Cname = 'Trfrequencyself' and Lang = %d and Cvalue = %s"), g_iLanguage, pRecTd->GetCollect(_T("Trfrequency")).vt == VT_NULL ? _T("-1") : (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("Trfrequency"))); pRecCm->Open(szSql.AllocSysString(), _variant_t((IDispatch*)m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText); if ((long)VAL_ZERO != pRecCm->GetRecordCount()) { tdDetailList.SetItemText(iRowIndex++, 1, pRecCm->GetCollect(_T("Clabel")).vt == VT_NULL ? _T("") : (LPCTSTR)(_bstr_t)pRecCm->GetCollect(_T("Clabel"))); } else { tdDetailList.SetItemText(iRowIndex++, 1, _T("")); } pRecCm->Close(); } szSql.Empty(); szSql.Format(_T("select Clabel from cm where Cname = 'Ifrequency' and Lang = %d and Cvalue = %s"), g_iLanguage, pRecTd->GetCollect(_T("Ifrequency")).vt == VT_NULL ? _T("-1") : (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("Ifrequency"))); pRecCm->Open(szSql.AllocSysString(), _variant_t((IDispatch*)m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText); if ((long)VAL_ZERO != pRecCm->GetRecordCount()) { tdDetailList.SetItemText(iRowIndex++, 1, pRecCm->GetCollect(_T("Clabel")).vt == VT_NULL ? _T("") : (LPCTSTR)(_bstr_t)pRecCm->GetCollect(_T("Clabel"))); } else { tdDetailList.SetItemText(iRowIndex++, 1, _T("")); } pRecCm->Close(); szSql.Empty(); szSql.Format(_T("select Clabel from cm where Cname = 'Clayout' and Lang = %d and Cvalue = %s"), g_iLanguage, pRecTd->GetCollect(_T("Clayout")).vt == VT_NULL ? _T("-1") : (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("Clayout"))); pRecCm->Open(szSql.AllocSysString(), _variant_t((IDispatch*)m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText); if ((long)VAL_ZERO != pRecCm->GetRecordCount()) { tdDetailList.SetItemText(iRowIndex++, 1, (LPCTSTR)(_bstr_t)pRecCm->GetCollect(_T("Clabel"))); } else { tdDetailList.SetItemText(iRowIndex++, 1, _T("")); } pRecCm->Close(); // tdDetailList.SetItemText(16, 1, (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("Espace"))); tdDetailList.SetItemText(iRowIndex, 1, (pRecTd->GetCollect(_T("Edistance")).vt == VT_NULL) ? _T("") : (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("Edistance"))); int iAR = pRecTd->GetCollect(_T("AR")).iVal; //如果是海上测量,则需要加入海上测量装置的属性 int iStartIndex = iRowIndex; if (iAR == AR_MARINE) { CString strTmpSql = _T(""); strTmpSql.Format(_T("select a.* from td1dSpcAttr a, tdchannel b where a.TCHID = b.ID and b.TDID = %u"),m_dwID); pRecTdSpcAttr->Open(strTmpSql.AllocSysString(), _variant_t((IDispatch*)m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText); int iTmp = 0; CString strInfo = _T(""); if (pRecTdSpcAttr->GetRecordCount() > 0) { float fVal = 0; iStartIndex++; if(pRecTdSpcAttr->GetCollect(_T("Spacing")).vt != VT_NULL) { strInfo.Empty(); strInfo.Format(_T("%.2f"),pRecTdSpcAttr->GetCollect(_T("Spacing")).fltVal); tdDetailList.SetItemText(iStartIndex, 1, strInfo); } //Interval iStartIndex++; if(pRecTdSpcAttr->GetCollect(_T("PoleInterval")).vt != VT_NULL) { strInfo.Empty(); strInfo.Format(_T("%.2f"),pRecTdSpcAttr->GetCollect(_T("PoleInterval")).fltVal); tdDetailList.SetItemText(iStartIndex, 1, strInfo); } //DipoleNo strInfo = (pRecTdSpcAttr->GetCollect(_T("DipoleNo")).vt != VT_NULL) ? (LPCTSTR)(_bstr_t)pRecTdSpcAttr->GetCollect(_T("DipoleNo")) : _T(""); tdDetailList.SetItemText(++iStartIndex, 1, strInfo); //RecordMode iTmp = pRecTdSpcAttr->GetCollect(_T("RecordMode")).iVal; iStartIndex++; if (iTmp > 2 || iTmp < 0) { strInfo.Empty(); if (LANG_ZHCN == g_iUILanguage) { strInfo.Format(_T("查询记录模式值无效,值= %d"), iTmp); AfxMessageBox(strInfo); } else { strInfo.Format(_T("Query recording mode value invalid, value = %d"), iTmp); MessageBoxEx(NULL, strInfo, STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)); } } else tdDetailList.SetItemText(iStartIndex, 1, g_chRecMode[iTmp]); //CurPoleDepoly iStartIndex++; iTmp = pRecTdSpcAttr->GetCollect(_T("CurPoleDepoly")).iVal; if (iTmp > 1 || iTmp < 0) { strInfo.Empty(); if (LANG_ZHCN == g_iUILanguage) { strInfo.Format(_T("查询当前孔depolyment值无效, 值 = %d"), iTmp); AfxMessageBox(strInfo); } else { strInfo.Format(_T("Query current pole depolyment value invalid, value = %d"), iTmp); MessageBoxEx(NULL, strInfo, STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)); } } else tdDetailList.SetItemText(iStartIndex, 1, g_chCurPoleDepoly[iTmp]); //MovingSpeed iStartIndex++; if (pRecTdSpcAttr->GetCollect(_T("MovingSpeed")).vt != VT_NULL) { fVal = pRecTdSpcAttr->GetCollect(_T("MovingSpeed")).fltVal; strInfo.Empty(); if (fVal < 0) strInfo = _T("Auto"); else strInfo.Format(_T("%.2f m/s"), fVal); tdDetailList.SetItemText(iStartIndex, 1, strInfo); } //RecordDistance iStartIndex++; if(pRecTdSpcAttr->GetCollect(_T("RecordDistance")).vt != VT_NULL) { strInfo.Empty(); strInfo.Format(_T("%.2f"),pRecTdSpcAttr->GetCollect(_T("RecordDistance")).fltVal); tdDetailList.SetItemText(iStartIndex, 1, strInfo); } } else { if (LANG_ZHCN == g_iUILanguage) AfxMessageBox(_T("在数据库不能找到marin 信息")); else MessageBoxEx(NULL, _T("Can not found marin information in database"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)); iStartIndex += 7; } pRecTdSpcAttr->Close(); } szSql.Empty(); szSql.Format(_T("select Clabel from cm where Cname = 'weather' and Lang = %d and Cvalue = %s"), g_iLanguage, pRecTd->GetCollect(_T("weather")).vt == VT_NULL ? _T("-1") : (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("weather"))); pRecCm->Open(szSql.AllocSysString(), _variant_t((IDispatch*)m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText); iStartIndex++; if ((long)VAL_ZERO != pRecCm->GetRecordCount()) { tdDetailList.SetItemText(iStartIndex, 1, (LPCTSTR)(_bstr_t)pRecCm->GetCollect(_T("Clabel"))); } pRecCm->Close(); szSql.Empty(); szSql.Format(_T("select Clabel from cm where Cname = 'WDIR' and Lang = %d and Cvalue = %s"), g_iLanguage, pRecTd->GetCollect(_T("WDIR")).vt == VT_NULL ? _T("-1") : (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("WDIR"))); pRecCm->Open(szSql.AllocSysString(), _variant_t((IDispatch*)m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText); iStartIndex++; if ((long)VAL_ZERO != pRecCm->GetRecordCount()) { tdDetailList.SetItemText(iStartIndex, 1, (LPCTSTR)(_bstr_t)pRecCm->GetCollect(_T("Clabel"))); } pRecCm->Close(); CString szDefault = _T(""); szDefault = (pRecTd->GetCollect(_T("temperature")).vt == VT_NULL) ?_T(""):(LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("temperature")); if (szDefault == "-9999")//若为该值则不显示东西 { szDefault = ""; } tdDetailList.SetItemText(++iStartIndex, 1, szDefault); tdDetailList.SetItemText(++iStartIndex, 1, (pRecTd->GetCollect(_T("height")).vt == VT_NULL) ?_T(""):(LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("height"))); szDefault = (pRecTd->GetCollect(_T("humidity")).vt == VT_NULL) ?_T(""):(LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("humidity")); if (szDefault == "-9999")//若为该值则不显示东西 { szDefault = ""; } tdDetailList.SetItemText(++iStartIndex, 1, szDefault); tdDetailList.SetItemText(++iStartIndex, 1, (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("Cdate"))); tdDetailList.SetItemText(++iStartIndex, 1, (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("Ctime"))); tdDetailList.SetItemText(++iStartIndex, 1, (pRecTd->GetCollect(_T("Tdate")).vt == VT_NULL) ?_T(""):(LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("Tdate"))); tdDetailList.SetItemText(++iStartIndex, 1, (pRecTd->GetCollect(_T("Ttime")).vt == VT_NULL) ?_T(""):(LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("Ttime"))); szSql.Empty(); szSql.Format(_T("select Clabel from cm where Cname = 'Rdirection' and Lang = %d and Cvalue = %s"), g_iLanguage, pRecTd->GetCollect(_T("Rdirection")).vt == VT_NULL ? _T("-1") : (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("Rdirection"))); pRecCm->Open(szSql.AllocSysString(), _variant_t((IDispatch*)m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText); if ((long)VAL_ZERO != pRecCm->GetRecordCount()) { // tdDetailList.SetItemText(27, 1, pRecCm->GetCollect(_T("Clabel")).vt == VT_NULL ? _T("") : (LPCTSTR)(_bstr_t)pRecCm->GetCollect(_T("Clabel"))); } pRecCm->Close(); tdDetailList.SetItemText(++iStartIndex, 1, (pRecTd->GetCollect(_T("OP")).vt == VT_NULL) ?_T(""):(LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("OP"))); tdDetailList.SetItemText(++iStartIndex, 1, (pRecTd->GetCollect(_T("QA")).vt == VT_NULL) ?_T(""):(LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("QA"))); } pRecTd->Close(); return true; } /* bool CRspCETd::ShowDetailInfo(CListCtrl &tdDetailList) { _RecordsetPtr pRecTd = NULL; _RecordsetPtr pRecTdHead = NULL; _RecordsetPtr pRecDev = NULL; _RecordsetPtr pRecPara = NULL; _RecordsetPtr pRecCm = NULL; CString szSql; CString szLabel; int iRowIndex = (int)VAL_ZERO; while (tdDetailList.GetItemCount() != iRowIndex) { tdDetailList.SetItemText(iRowIndex, 1, _T("")); iRowIndex++; } pRecTd.CreateInstance(_uuidof(Recordset)); pRecTdHead.CreateInstance(_uuidof(Recordset)); pRecDev.CreateInstance(_uuidof(Recordset)); pRecPara.CreateInstance(_uuidof(Recordset)); pRecCm.CreateInstance(_uuidof(Recordset)); szSql.Empty(); szSql.Format(_T("select ID,TDname,Tlocation,DESN,SCCN,Sname,Stype,Ttype,Tmode,Eamount,TPamount,CHamount,N,TRwave,TRfrequency,Ifrequency,SAfrequency,Clayout,Espace,Edistance,weather,WDIR," "temperature,height,humidity,Format(Cdate,'YYYY-MM-DD') as Cdate,Format(Ctime,'HH:MM:SS') as Ctime,Format(Tdate,'YYYY-MM-DD') as Tdate,Format(Ttime,'HH:MM:SS') as Ttime," "Rdirection,CRtime,IIf(IsNull(PM),'',PM) as PM,IIf(IsNull(OP),'',OP) as OP,IIf(IsNull(QA),'',QA) as QA from td where ID = %u"), m_dwID); pRecTd->Open(szSql.AllocSysString(), _variant_t((IDispatch*)m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText); if ((long)VAL_ZERO != pRecTd->GetRecordCount()) { tdDetailList.SetItemText(0, 1, (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("TDname"))); // tdDetailList.SetItemText(1, 1, (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("Tlocation"))); tdDetailList.SetItemText(1, 1, (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("DESN"))); // tdDetailList.SetItemText(2, 1, (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("SCCN"))); tdDetailList.SetItemText(2, 1, (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("Sname"))); szSql.Empty(); szSql.Format(_T("select Clabel from cm where Cname = 'Stype' and Lang = %d and Cvalue = %s"), g_iLanguage, pRecTd->GetCollect(_T("Stype")).vt == VT_NULL ? _T("-1") : (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("Stype"))); pRecCm->Open(szSql.AllocSysString(), _variant_t((IDispatch*)m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText); if ((long)VAL_ZERO != pRecCm->GetRecordCount()) { tdDetailList.SetItemText(3, 1, (LPCTSTR)(_bstr_t)pRecCm->GetCollect(_T("Clabel"))); } pRecCm->Close(); szSql.Empty(); szSql.Format(_T("select Clabel from cm where Cname = 'Ttype' and Lang = %d and Cvalue = %s"), g_iLanguage, pRecTd->GetCollect(_T("Ttype")).vt == VT_NULL ? _T("-1") : (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("Ttype"))); pRecCm->Open(szSql.AllocSysString(), _variant_t((IDispatch*)m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText); if ((long)VAL_ZERO != pRecCm->GetRecordCount()) { tdDetailList.SetItemText(4, 1, (LPCTSTR)(_bstr_t)pRecCm->GetCollect(_T("Clabel"))); } pRecCm->Close(); szSql.Empty(); szSql.Format(_T("select Clabel from cm where Cname = 'Tmode' and Lang = %d and Cvalue = %s"), g_iLanguage, pRecTd->GetCollect(_T("Tmode")).vt == VT_NULL ? _T("-1") : (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("Tmode"))); pRecCm->Open(szSql.AllocSysString(), _variant_t((IDispatch*)m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText); if ((long)VAL_ZERO != pRecCm->GetRecordCount()) { // tdDetailList.SetItemText(6, 1, (LPCTSTR)(_bstr_t)pRecCm->GetCollect(_T("Clabel"))); } pRecCm->Close(); tdDetailList.SetItemText(5, 1, (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("Eamount"))); tdDetailList.SetItemText(6, 1, (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("TPamount"))); tdDetailList.SetItemText(7, 1, (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("CHamount"))); tdDetailList.SetItemText(8, 1, (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("N"))); szSql.Empty(); szSql.Format(_T("select Clabel from cm where Cname = 'TRwave' and Lang = %d and Cvalue = %s"), g_iLanguage, pRecTd->GetCollect(_T("TRwave")).vt == VT_NULL ? _T("-1") : (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("TRwave"))); pRecCm->Open(szSql.AllocSysString(), _variant_t((IDispatch*)m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText); if ((long)VAL_ZERO != pRecCm->GetRecordCount()) { tdDetailList.SetItemText(9, 1, (LPCTSTR)(_bstr_t)pRecCm->GetCollect(_T("Clabel"))); } pRecCm->Close(); if ((0 == pRecTd->GetCollect(_T("Ttype")).iVal) || (1 == pRecTd->GetCollect(_T("Ttype")).iVal)) { szSql.Empty(); szSql.Format(_T("select Clabel from cm where Cname = 'Trfrequency' and Lang = %d and Cvalue = %s"), g_iLanguage, pRecTd->GetCollect(_T("Trfrequency")).vt == VT_NULL ? _T("-1") : (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("Trfrequency"))); pRecCm->Open(szSql.AllocSysString(), _variant_t((IDispatch*)m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText); if ((long)VAL_ZERO != pRecCm->GetRecordCount()) { tdDetailList.SetItemText(10, 1, (LPCTSTR)(_bstr_t)pRecCm->GetCollect(_T("Clabel"))); } pRecCm->Close(); } else if (2 == pRecTd->GetCollect(_T("Ttype")).iVal) { szSql.Empty(); szSql.Format(_T("select Clabel from cm where Cname = 'Trfrequencyself' and Lang = %d and Cvalue = %s"), g_iLanguage, pRecTd->GetCollect(_T("Trfrequency")).vt == VT_NULL ? _T("-1") : (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("Trfrequency"))); pRecCm->Open(szSql.AllocSysString(), _variant_t((IDispatch*)m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText); if ((long)VAL_ZERO != pRecCm->GetRecordCount()) { tdDetailList.SetItemText(10, 1, pRecCm->GetCollect(_T("Clabel")).vt == VT_NULL ? _T("") : (LPCTSTR)(_bstr_t)pRecCm->GetCollect(_T("Clabel"))); } pRecCm->Close(); } szSql.Empty(); szSql.Format(_T("select Clabel from cm where Cname = 'Ifrequency' and Lang = %d and Cvalue = %s"), g_iLanguage, pRecTd->GetCollect(_T("Ifrequency")).vt == VT_NULL ? _T("-1") : (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("Ifrequency"))); pRecCm->Open(szSql.AllocSysString(), _variant_t((IDispatch*)m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText); if ((long)VAL_ZERO != pRecCm->GetRecordCount()) { tdDetailList.SetItemText(11, 1, pRecCm->GetCollect(_T("Clabel")).vt == VT_NULL ? _T("") : (LPCTSTR)(_bstr_t)pRecCm->GetCollect(_T("Clabel"))); } pRecCm->Close(); if (0 == pRecTd->GetCollect(_T("Ifrequency")).iVal) { szSql.Empty(); szSql.Format(_T("select Clabel from cm where Cname = 'SAfrequency50' and Lang = %d and Cvalue = %s"), g_iLanguage, pRecTd->GetCollect(_T("SAfrequency")).vt == VT_NULL ? _T("-1") : (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("SAfrequency"))); pRecCm->Open(szSql.AllocSysString(), _variant_t((IDispatch*)m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText); if ((long)VAL_ZERO != pRecCm->GetRecordCount()) { tdDetailList.SetItemText(12, 1, pRecCm->GetCollect(_T("Clabel")).vt == VT_NULL ? _T("") : (LPCTSTR)(_bstr_t)pRecCm->GetCollect(_T("Clabel"))); } pRecCm->Close(); } else if (1 == pRecTd->GetCollect(_T("Ifrequency")).iVal) { szSql.Empty(); szSql.Format(_T("select Clabel from cm where Cname = 'SAfrequency60' and Lang = %d and Cvalue = %s"), g_iLanguage, pRecTd->GetCollect(_T("SAfrequency")).vt == VT_NULL ? _T("-1") : (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("SAfrequency"))); pRecCm->Open(szSql.AllocSysString(), _variant_t((IDispatch*)m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText); if ((long)VAL_ZERO != pRecCm->GetRecordCount()) { tdDetailList.SetItemText(12, 1, (LPCTSTR)(_bstr_t)pRecCm->GetCollect(_T("Clabel"))); } pRecCm->Close(); } szSql.Empty(); szSql.Format(_T("select Clabel from cm where Cname = 'Clayout' and Lang = %d and Cvalue = %s"), g_iLanguage, pRecTd->GetCollect(_T("Clayout")).vt == VT_NULL ? _T("-1") : (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("Clayout"))); pRecCm->Open(szSql.AllocSysString(), _variant_t((IDispatch*)m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText); if ((long)VAL_ZERO != pRecCm->GetRecordCount()) { tdDetailList.SetItemText(13, 1, (LPCTSTR)(_bstr_t)pRecCm->GetCollect(_T("Clabel"))); } pRecCm->Close(); // tdDetailList.SetItemText(16, 1, (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("Espace"))); tdDetailList.SetItemText(14, 1, (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("Edistance"))); szSql.Empty(); szSql.Format(_T("select Clabel from cm where Cname = 'weather' and Lang = %d and Cvalue = %s"), g_iLanguage, pRecTd->GetCollect(_T("weather")).vt == VT_NULL ? _T("-1") : (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("weather"))); pRecCm->Open(szSql.AllocSysString(), _variant_t((IDispatch*)m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText); if ((long)VAL_ZERO != pRecCm->GetRecordCount()) { tdDetailList.SetItemText(15, 1, (LPCTSTR)(_bstr_t)pRecCm->GetCollect(_T("Clabel"))); } pRecCm->Close(); szSql.Empty(); szSql.Format(_T("select Clabel from cm where Cname = 'WDIR' and Lang = %d and Cvalue = %s"), g_iLanguage, pRecTd->GetCollect(_T("WDIR")).vt == VT_NULL ? _T("-1") : (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("WDIR"))); pRecCm->Open(szSql.AllocSysString(), _variant_t((IDispatch*)m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText); if ((long)VAL_ZERO != pRecCm->GetRecordCount()) { tdDetailList.SetItemText(16, 1, (LPCTSTR)(_bstr_t)pRecCm->GetCollect(_T("Clabel"))); } pRecCm->Close(); CString szDefault = _T(""); szDefault = (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("temperature")); if (szDefault == "-9999")//若为该值则不显示东西 { szDefault = ""; } tdDetailList.SetItemText(17, 1, szDefault); tdDetailList.SetItemText(18, 1, (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("height"))); szDefault = (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("humidity")); if (szDefault == "-9999")//若为该值则不显示东西 { szDefault = ""; } tdDetailList.SetItemText(19, 1, szDefault); tdDetailList.SetItemText(20, 1, (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("Cdate"))); tdDetailList.SetItemText(21, 1, (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("Ctime"))); tdDetailList.SetItemText(22, 1, (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("Tdate"))); tdDetailList.SetItemText(23, 1, (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("Ttime"))); szSql.Empty(); szSql.Format(_T("select Clabel from cm where Cname = 'Rdirection' and Lang = %d and Cvalue = %s"), g_iLanguage, pRecTd->GetCollect(_T("Rdirection")).vt == VT_NULL ? _T("-1") : (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("Rdirection"))); pRecCm->Open(szSql.AllocSysString(), _variant_t((IDispatch*)m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText); if ((long)VAL_ZERO != pRecCm->GetRecordCount()) { // tdDetailList.SetItemText(27, 1, pRecCm->GetCollect(_T("Clabel")).vt == VT_NULL ? _T("") : (LPCTSTR)(_bstr_t)pRecCm->GetCollect(_T("Clabel"))); } pRecCm->Close(); // tdDetailList.SetItemText(28, 1, (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("CRtime"))); tdDetailList.SetItemText(24, 1, (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("PM"))); tdDetailList.SetItemText(25, 1, (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("OP"))); tdDetailList.SetItemText(26, 1, (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("QA"))); } pRecTd->Close(); return true; } */ BOOL CRspCETd::SaveTdToExcelFile(CString f_szFileName) { if (PathFileExists(f_szFileName)) { if (0 == DeleteFile(f_szFileName)) return FALSE; } _Application* pComApp = new _Application; Workbooks comBooks; _Workbook comBook; Sheets comSheets; _Worksheet comSheet01; _Worksheet comSheet02; _Worksheet comSheet03; COleVariant covOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR); // CString szCurFilePath = _T(""); // CString szCurFile = _T(""); // // CFileDialog dlgSaveFile(FALSE, "xlsx", "", OFN_OVERWRITEPROMPT|OFN_HIDEREADONLY|OFN_NOCHANGEDIR, "Excel file(*.xlsx)|*.xlsx||", NULL); // // szCurFilePath.Empty(); // szCurFilePath.GetBufferSetLength(256); // ::GetCurrentDirectory(szCurFilePath.GetLength(), szCurFilePath.GetBuffer(szCurFilePath.GetLength())); // szCurFilePath.ReleaseBuffer(); // // dlgSaveFile.m_ofn.lpstrTitle = _T("Save"); // dlgSaveFile.m_ofn.lpstrInitialDir = szCurFilePath; // // // if (dlgSaveFile.DoModal() == IDOK) // { // szCurFile.Empty(); // szCurFile = dlgSaveFile.GetPathName(); // DeleteFile(szCurFile); if( !pComApp->CreateDispatch(_T("Excel.Application"), NULL) ) { hHook = SetWindowsHookEx(WH_CBT,(HOOKPROC)CBTHookProc,AfxGetInstanceHandle(),NULL); AfxMessageBox("Can't build excel application!"); return FALSE; } comBooks = pComApp->GetWorkbooks(); comBook = comBooks.Add(covOptional); comSheets = comBook.GetSheets(); int iSheetCnt = comSheets.GetCount(); int iNeedCreateCnt = 3 - iSheetCnt; if (iNeedCreateCnt > 0) { /////////////////////VC插入sheet页到指定位置//////////////////////////////////////////////// /* 插入sheet的函数用 sheets.Add(Before, After,Count,Type) Before Variant 类型,可选。指定工作表对象,新建的工作表将置于此工作表之前。 After Variant 类型,可选。指定工作表对象,新建的工作表将置于此工作表之后。 Count Variant 类型,可选。要创建的工作表的数目。默认值为一。 Type Variant 类型,可选。工作表类型。 如果我们默认参数都为vtMissing,则 插入sheet的位置时在当前激活sheet页之前,而且时只插入一个sheet页 sheets.Add(vtMissing, vtMissing,vtMissing,vtMissing) 假如我们要求插入到第二个sheet之后,第三个sheet之前,我们应该按照下面的方法写 sheets.Add(-variant_t(sheets.GetItem(COleVariant((short)2))), -variant_t(sheets.GetItem(COleVariant((short)3))),-variant_t((long)1),vtMissing) */ //在这里covOptional可以等同于vtMissing comSheets.Add(covOptional, _variant_t(comSheets.GetItem(COleVariant((short)iSheetCnt))),_variant_t((long)iNeedCreateCnt), covOptional); } comSheet01 = comSheets.GetItem(COleVariant((short)1)); comSheet01.SetName(_T("Head")); this->SaveTdHeadToExcelFile(&comSheet01); comSheet02 = comSheets.GetItem(COleVariant((short)2)); comSheet02.SetName(_T("DAT")); this->SaveTdConToExcelFile(&comSheet02); comSheet03 = comSheets.GetItem(COleVariant((short)3)); comSheet03.SetName(_T("GR")); this->SaveTdGRToExcelFile(&comSheet03); // comApp.SetVisible(TRUE); // comApp.SetUserControl(TRUE); comBook.SaveAs(COleVariant(f_szFileName), covOptional, covOptional, covOptional, covOptional, covOptional, 0, covOptional, covOptional, covOptional, covOptional, covOptional); comSheet01.ReleaseDispatch(); comSheet02.ReleaseDispatch(); comSheet03.ReleaseDispatch(); comSheets.ReleaseDispatch(); comBook.Close(covOptional, COleVariant(""), covOptional); comBook.ReleaseDispatch(); comBooks.Close(); comBooks.ReleaseDispatch(); pComApp->Quit(); pComApp->ReleaseDispatch(); if (pComApp != NULL) { delete pComApp; pComApp = NULL; } // } // else // { // return FALSE; // } return TRUE; } BOOL CRspCETd::SaveTdToCsvFile(CString f_szFileName) { if (PathFileExists(f_szFileName)) { if (0 == DeleteFile(f_szFileName)) return FALSE; } FILE* pCsvFile; pCsvFile = fopen(f_szFileName, "w+"); if (NULL == pCsvFile) { CString str = _T(""); if (LANG_ZHCN == g_iUILanguage) { str.Format(_T("无法构建csv应用程序!错误码 %d"), GetLastError()); AfxMessageBox(str); } else { str.Format(_T("Can't build csv application!,err = %d"), GetLastError()); MessageBoxEx(NULL, str, STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)); } return FALSE; } this->SaveTdHeadToCsvFile(pCsvFile); this->SaveTdConToCsvFile(pCsvFile, f_szFileName.Left(f_szFileName.GetLength() - 4)); this->SaveTdGRToCsvFile(pCsvFile); fclose(pCsvFile); return TRUE; } BOOL CRspCETd::SaveTdGRToExcelFile(_Worksheet* const pComSheet) { Range comRange; excel9::Font comFont; Range comCols; _RecordsetPtr pRecGrList = NULL; CString szSql = _T(""); CString szRow = _T(""); _RecordsetPtr pRecTdchannel = NULL; pRecTdchannel.CreateInstance(_uuidof(Recordset)); szSql.Empty(); szSql.Format(_T("select AR from tdchannel where TDID = %u"),m_dwID); pRecTdchannel->Open(szSql.AllocSysString(), _variant_t((IDispatch*)m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText); if (pRecTdchannel->GetRecordCount() <= 0) { AfxMessageBox(_T("Query task AR information failed")); pRecTdchannel->Close(); return false; } int iAR = pRecTdchannel->GetCollect(_T("AR")).iVal; pRecTdchannel->Close(); int iIndex = (int)0; CHAR COL = 'A'; iIndex = 1; szRow.Empty(); szRow.Format(_T("%c%d"), COL++, iIndex); comRange = pComSheet->GetRange(COleVariant(szRow),COleVariant(szRow)); comRange.SetValue2(COleVariant((iAR == MEDIUM_ID_PROFILE ? (_T("Point Num")) : (_T("Electrode ID"))))); comFont = comRange.GetFont(); comFont.SetBold(COleVariant((short)TRUE)); comCols = comRange.GetEntireColumn(); comCols.AutoFit(); szRow.Empty(); szRow.Format(_T("%c%d"), COL++, iIndex); comRange = pComSheet->GetRange(COleVariant(szRow),COleVariant(szRow)); comRange.SetValue2(COleVariant(_T("Test date"))); comFont = comRange.GetFont(); comFont.SetBold(COleVariant((short)TRUE)); comCols = comRange.GetEntireColumn(); comCols.AutoFit(); szRow.Empty(); szRow.Format(_T("%c%d"), COL++, iIndex); comRange = pComSheet->GetRange(COleVariant(szRow),COleVariant(szRow)); comRange.SetValue2(COleVariant(_T("Test time"))); comFont = comRange.GetFont(); comFont.SetBold(COleVariant((short)TRUE)); comCols = comRange.GetEntireColumn(); comCols.AutoFit(); szRow.Empty(); szRow.Format(_T("%c%d"), COL++, iIndex); comRange = pComSheet->GetRange(COleVariant(szRow),COleVariant(szRow)); comRange.SetValue2(COleVariant(_T("P1 Rg(ohm)"))); comFont = comRange.GetFont(); comFont.SetBold(COleVariant((short)TRUE)); comCols = comRange.GetEntireColumn(); comCols.AutoFit(); szRow.Empty(); szRow.Format(_T("%c%d"), COL++, iIndex); comRange = pComSheet->GetRange(COleVariant(szRow),COleVariant(szRow)); comRange.SetValue2(COleVariant(_T("Status"))); comFont = comRange.GetFont(); comFont.SetBold(COleVariant((short)TRUE)); comCols = comRange.GetEntireColumn(); comCols.AutoFit(); // if (AR_MARINE == iAR) // { // szRow.Empty(); // szRow.Format(_T("F%d"), iIndex); // comRange = pComSheet->GetRange(COleVariant(szRow),COleVariant(szRow)); // comRange.SetValue2(COleVariant(_T("P2 Rg(ohm)"))); // comFont = comRange.GetFont(); // comFont.SetBold(COleVariant((short)TRUE)); // comCols = comRange.GetEntireColumn(); // comCols.AutoFit(); // // szRow.Empty(); // szRow.Format(_T("G%d"), iIndex); // comRange = pComSheet->GetRange(COleVariant(szRow),COleVariant(szRow)); // comRange.SetValue2(COleVariant(_T("Status1"))); // comFont = comRange.GetFont(); // comFont.SetBold(COleVariant((short)TRUE)); // comCols = comRange.GetEntireColumn(); // comCols.AutoFit(); // } pRecGrList.CreateInstance(_uuidof(Recordset)); szSql.Empty(); if (iAR == MEDIUM_ID_PROFILE) szSql.Format(_T("select b.POINT_NUM as ID,Format(a.Mdate,'YYYY-MM-DD') as Mdate,Format(a.Mtime,'HH:MM:SS') as Mtime,a.OMvalue as OMvalue, a.OM1value,") _T(" a.StatusCode as StatusCode, a.StatusCode1 from gr a, td1dcon b where a.TDID = %u and a.TDID = b.TCHID and a.Ecode = b.TSN order by b.POINT_NUM desc"), m_dwID); else szSql.Format(_T("select Ecode as ID,Format(Mdate,'YYYY-MM-DD') as Mdate,Format(Mtime,'HH:MM:SS') as Mtime,OMvalue, OM1value,") _T(" StatusCode, StatusCode1 from gr where TDID = %u order by Val(Ecode) desc"), m_dwID); pRecGrList->Open(szSql.AllocSysString(), _variant_t((IDispatch*)m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText); int iOMVal = -1, iOMVal1 = -1; CString strOMVal,strOM1Val; CString strMdate, strMtime; CString strStatus,strStatus1; while ((short)0 == pRecGrList->adoEOF) { iIndex++; COL = 'A'; if (pRecGrList->GetCollect(_T("OMvalue")).vt == VT_NULL) { pRecGrList->MoveNext(); continue; } szRow.Empty(); szRow.Format(_T("%c%d"), COL++, iIndex); CString strElectrode = (LPCTSTR)(_bstr_t)pRecGrList->GetCollect(_T("ID")); strElectrode.TrimLeft(); strElectrode.TrimRight(); if (_T("-1") == strElectrode) { strElectrode = _T("AB"); } else if (_T("-2") == strElectrode) { strElectrode = _T("MN"); } else { int iElectrode = atoi(strElectrode); if (iElectrode < -2) { strElectrode.Empty(); strElectrode.Format(_T("MN%d"),abs(iElectrode)-2); } else { //CString strErr = _T(""); //if (LANG_ZHCN == g_iUILanguage) //{ // strErr.Format(_T("没有期望的电极编号(%s)."), strElectrode); // AfxMessageBox(strErr); //} //else //{ // strErr.Format(_T("Unexpected electrode id(%s)."), strElectrode); // MessageBoxEx(NULL, strErr, STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)); //} //pRecGrList->Close(); //return false; strElectrode.Empty(); strElectrode.Format(_T("%d"), abs(iElectrode)); } } comRange = pComSheet->GetRange(COleVariant(szRow),COleVariant(szRow)); comRange.SetValue2(COleVariant(strElectrode)); strOMVal.Empty(); strOM1Val.Empty(); strMdate.Empty(); strMtime.Empty(); strStatus.Empty(); strStatus1.Empty(); iOMVal = (int)pRecGrList->GetCollect(_T("OMvalue")).lVal; if (-1 != iOMVal) { strOMVal.Format(_T("%d"),iOMVal); strMdate = (LPCTSTR)(_bstr_t)pRecGrList->GetCollect(_T("Mdate")); strMtime = (LPCTSTR)(_bstr_t)pRecGrList->GetCollect(_T("Mtime")); strStatus = GetGrCodeText((int)pRecGrList->GetCollect(_T("StatusCode")).lVal); } szRow.Empty(); szRow.Format(_T("%c%d"), COL++, iIndex); comRange = pComSheet->GetRange(COleVariant(szRow),COleVariant(szRow)); comRange.SetValue2(COleVariant(strMdate)); szRow.Empty(); szRow.Format(_T("%c%d"), COL++, iIndex); comRange = pComSheet->GetRange(COleVariant(szRow),COleVariant(szRow)); comRange.SetValue2(COleVariant(strMtime)); szRow.Empty(); szRow.Format(_T("%c%d"), COL++, iIndex); comRange = pComSheet->GetRange(COleVariant(szRow),COleVariant(szRow)); comRange.SetValue2(COleVariant(strOMVal)); szRow.Empty(); szRow.Format(_T("%c%d"), COL++, iIndex); comRange = pComSheet->GetRange(COleVariant(szRow),COleVariant(szRow)); comRange.SetValue2(COleVariant(strStatus)); // if (AR_MARINE == iAR) // { // iOMVal1 = (int)pRecGrList->GetCollect(_T("OM1value")).lVal; // if (-1 != iOMVal1) // { // strOM1Val.Format(_T("%d"),iOMVal1); // strStatus1 = GetGrCodeText((int)pRecGrList->GetCollect(_T("StatusCode1")).lVal); // } // szRow.Empty(); // szRow.Format(_T("F%d"), iIndex); // comRange = pComSheet->GetRange(COleVariant(szRow),COleVariant(szRow)); // comRange.SetValue2(COleVariant(strOMVal)); // // szRow.Empty(); // szRow.Format(_T("G%d"), iIndex); // comRange = pComSheet->GetRange(COleVariant(szRow),COleVariant(szRow)); // } pRecGrList->MoveNext(); } pRecGrList->Close(); return TRUE; } BOOL CRspCETd::SaveTdGRToCsvFile(FILE* pFile) { _RecordsetPtr pRecGrList = NULL; CString szSql = _T(""); CString szRow = _T(""); _RecordsetPtr pRecTdchannel = NULL; pRecTdchannel.CreateInstance(_uuidof(Recordset)); szSql.Empty(); szSql.Format(_T("select AR from tdchannel where TDID = %u"), m_dwID); pRecTdchannel->Open(szSql.AllocSysString(), _variant_t((IDispatch*)m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText); if (pRecTdchannel->GetRecordCount() <= 0) { AfxMessageBox(_T("Query task AR information failed")); pRecTdchannel->Close(); return false; } int iAR = pRecTdchannel->GetCollect(_T("AR")).iVal; pRecTdchannel->Close(); int iIndex = (int)0; iIndex = 1; szRow.Empty(); szRow += (iAR == MEDIUM_ID_PROFILE ? (_T("Point Num")) : (_T("Electrode ID"))); szRow += ','; szRow += ((_T("Test date"))); szRow += ','; szRow += ((_T("Test time"))); szRow += ','; szRow += ((_T("P1 Rg(Ω)"))); szRow += ','; szRow += ((_T("Status"))); szRow += "\n"; fwrite(szRow, 1, szRow.GetLength(), pFile); fflush(pFile); pRecGrList.CreateInstance(_uuidof(Recordset)); szSql.Empty(); if (iAR == MEDIUM_ID_PROFILE) szSql.Format(_T("select b.POINT_NUM as ID,Format(a.Mdate,'YYYY-MM-DD') as Mdate,Format(a.Mtime,'HH:MM:SS') as Mtime,a.OMvalue as OMvalue, a.OM1value,") _T(" a.StatusCode as StatusCode, a.StatusCode1 from gr a, td1dcon b where a.TDID = %u and a.TDID = b.TCHID and a.Ecode = b.TSN order by b.POINT_NUM desc"), m_dwID); else szSql.Format(_T("select Ecode as ID,Format(Mdate,'YYYY-MM-DD') as Mdate,Format(Mtime,'HH:MM:SS') as Mtime,OMvalue, OM1value,") _T(" StatusCode, StatusCode1 from gr where TDID = %u order by Val(Ecode) desc"), m_dwID); pRecGrList->Open(szSql.AllocSysString(), _variant_t((IDispatch*)m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText); int iOMVal = -1, iOMVal1 = -1; CString strOMVal, strOM1Val; CString strMdate, strMtime; CString strStatus, strStatus1; while ((short)0 == pRecGrList->adoEOF) { iIndex++; if (pRecGrList->GetCollect(_T("OMvalue")).vt == VT_NULL) { pRecGrList->MoveNext(); continue; } szRow.Empty(); CString strElectrode = (LPCTSTR)(_bstr_t)pRecGrList->GetCollect(_T("ID")); strElectrode.TrimLeft(); strElectrode.TrimRight(); if (_T("-1") == strElectrode) { strElectrode = _T("AB"); } else if (_T("-2") == strElectrode) { strElectrode = _T("MN"); } else { int iElectrode = atoi(strElectrode); if (iElectrode < -2) { strElectrode.Empty(); strElectrode.Format(_T("MN%d"), abs(iElectrode) - 2); } else { //CString strErr = _T(""); //if (LANG_ZHCN == g_iUILanguage) //{ // strErr.Format(_T("没有期望的电极编号(%s)."), strElectrode); // AfxMessageBox(strErr); //} //else //{ // strErr.Format(_T("Unexpected electrode id(%s)."), strElectrode); // MessageBoxEx(NULL, strErr, STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)); //} //pRecGrList->Close(); //return false; strElectrode.Empty(); strElectrode.Format(_T("%d"), abs(iElectrode)); } } szRow += strElectrode; szRow += ','; strOMVal.Empty(); strOM1Val.Empty(); strMdate.Empty(); strMtime.Empty(); strStatus.Empty(); strStatus1.Empty(); iOMVal = (int)pRecGrList->GetCollect(_T("OMvalue")).lVal; if (-1 != iOMVal) { strOMVal.Format(_T("%d"), iOMVal); strMdate = (LPCTSTR)(_bstr_t)pRecGrList->GetCollect(_T("Mdate")); strMtime = (LPCTSTR)(_bstr_t)pRecGrList->GetCollect(_T("Mtime")); strStatus = GetGrCodeText((int)pRecGrList->GetCollect(_T("StatusCode")).lVal); } szRow += ((strMdate)); szRow += ','; szRow += ((strMtime)); szRow += ','; szRow += ((strOMVal)); szRow += ','; szRow += ((strStatus)); szRow += "\n"; fwrite(szRow, 1, szRow.GetLength(), pFile); pRecGrList->MoveNext(); } fflush(pFile); pRecGrList->Close(); return TRUE; } BOOL CRspCETd::DisplayGraph() { CDispCERSPGrapDlg* pDispCERSPGrapDlg = new CDispCERSPGrapDlg(this); pDispCERSPGrapDlg->DoModal(); delete pDispCERSPGrapDlg; return TRUE; } BOOL CRspCETd::DisplayTPSplinesGraph(int iTSN) { ((CTdChannel*)this->m_tdChaList.GetAt(this->m_tdChaList.FindIndex(0)))->GetTdRecord(iTSN)->DisplayRawDataSplines(); return TRUE; } BOOL CRspCETd::SaveTdHeadToExcelFile(_Worksheet* const pComSheet) { Range comRange; excel9::Font comFont; Range comCols; _RecordsetPtr pRecTd = NULL; _RecordsetPtr pRecTdHead = NULL; _RecordsetPtr pRecDev = NULL; _RecordsetPtr pRecPara = NULL; _RecordsetPtr pRecCm = NULL; _RecordsetPtr pRecTdSpcAttr = NULL; CString szSql; CString szLabel; int iAR = 0; int iRowIndex = (int)0; pRecTd.CreateInstance(_uuidof(Recordset)); pRecTdHead.CreateInstance(_uuidof(Recordset)); pRecDev.CreateInstance(_uuidof(Recordset)); pRecPara.CreateInstance(_uuidof(Recordset)); pRecCm.CreateInstance(_uuidof(Recordset)); pRecTdSpcAttr.CreateInstance(_uuidof(Recordset)); szSql.Empty(); szSql.Format(_T("select a.ID,TDname,Tlocation,DESN,SCCN,Sname,Stype,Ttype,Tmode,Eamount,TPamount,CHamount,N,TRwave,TRfrequency,Ifrequency,SAfrequency,Clayout,Espace,Edistance,weather,WDIR," "temperature,height,humidity,Format(a.Cdate,'YYYY-MM-DD') as Cdate,Format(a.Ctime,'HH:MM:SS') as Ctime,Format(a.Tdate,'YYYY-MM-DD') as Tdate,Format(a.Ttime,'HH:MM:SS') as Ttime," "Rdirection,CRtime,IIf(IsNull(a.PM),'',a.PM) as PM,IIf(IsNull(a.OP),'',a.OP) as OP,IIf(IsNull(a.QA),'',a.QA) as QA, b.AR as AR from td a, tdchannel b where a.ID = %u and a.ID = b.TDID"), m_dwID); pRecTd->Open(szSql.AllocSysString(), _variant_t((IDispatch*)m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText); CString strRowTitle; int iStartIndex = 0; CString strStIndex = _T(""); if ((long)0 != pRecTd->GetRecordCount()) { comRange = pComSheet->GetRange(COleVariant(_T("A1")),COleVariant(_T("A1"))); if (LANG_ZHCN == g_iUILanguage) comRange.SetValue2(COleVariant(_T("测试任务名称"))); else comRange.SetValue2(COleVariant(_T("Test data name"))); iAR = pRecTd->GetCollect(_T("AR")).iVal; comFont = comRange.GetFont(); comFont.SetBold(COleVariant((short)TRUE)); strRowTitle.Empty(); strRowTitle.LoadString(IDS_DB_TD_DESN+g_UIOffset); comRange = pComSheet->GetRange(COleVariant(_T("A2")),COleVariant(_T("A2"))); comRange.SetValue2(COleVariant(strRowTitle)); comFont = comRange.GetFont(); comFont.SetBold(COleVariant((short)TRUE)); strRowTitle.Empty(); strRowTitle.LoadString(IDS_DB_TD_SNAME+g_UIOffset); comRange = pComSheet->GetRange(COleVariant(_T("A3")),COleVariant(_T("A3"))); comRange.SetValue2(COleVariant(strRowTitle)); comFont = comRange.GetFont(); comFont.SetBold(COleVariant((short)TRUE)); strRowTitle.Empty(); strRowTitle.LoadString(IDS_DB_TD_STYPE+g_UIOffset); comRange = pComSheet->GetRange(COleVariant(_T("A4")),COleVariant(_T("A4"))); comRange.SetValue2(COleVariant(strRowTitle)); comFont = comRange.GetFont(); comFont.SetBold(COleVariant((short)TRUE)); strRowTitle.Empty(); strRowTitle.LoadString(IDS_DB_TD_TTYPE+g_UIOffset); comRange = pComSheet->GetRange(COleVariant(_T("A5")),COleVariant(_T("A5"))); comRange.SetValue2(COleVariant(strRowTitle)); comFont = comRange.GetFont(); comFont.SetBold(COleVariant((short)TRUE)); strRowTitle.Empty(); strRowTitle.LoadString(IDS_ARRAY_TYPE+g_UIOffset); comRange = pComSheet->GetRange(COleVariant(_T("A6")),COleVariant(_T("A6"))); comRange.SetValue2(COleVariant(strRowTitle)); comFont = comRange.GetFont(); comFont.SetBold(COleVariant((short)TRUE)); strRowTitle.Empty(); strRowTitle.LoadString(IDS_DB_TD_EAMOUNT+g_UIOffset); comRange = pComSheet->GetRange(COleVariant(_T("A7")),COleVariant(_T("A7"))); comRange.SetValue2(COleVariant(strRowTitle)); comFont = comRange.GetFont(); comFont.SetBold(COleVariant((short)TRUE)); strRowTitle.Empty(); strRowTitle.LoadString(IDS_DB_TD_TPAMOUNT+g_UIOffset); comRange = pComSheet->GetRange(COleVariant(_T("A8")),COleVariant(_T("A8"))); comRange.SetValue2(COleVariant(strRowTitle)); comFont = comRange.GetFont(); comFont.SetBold(COleVariant((short)TRUE)); strRowTitle.Empty(); strRowTitle.LoadString(IDS_DB_TD_CHAMOUNT+g_UIOffset); comRange = pComSheet->GetRange(COleVariant(_T("A9")),COleVariant(_T("A9"))); comRange.SetValue2(COleVariant(strRowTitle)); comFont = comRange.GetFont(); comFont.SetBold(COleVariant((short)TRUE)); strRowTitle.Empty(); strRowTitle.LoadString(IDS_DB_TD_N+g_UIOffset); comRange = pComSheet->GetRange(COleVariant(_T("A10")),COleVariant(_T("A10"))); comRange.SetValue2(COleVariant(strRowTitle)); comFont = comRange.GetFont(); comFont.SetBold(COleVariant((short)TRUE)); strRowTitle.Empty(); strRowTitle.LoadString(IDS_DB_TD_TRWAVE+g_UIOffset); comRange = pComSheet->GetRange(COleVariant(_T("A11")),COleVariant(_T("A11"))); comRange.SetValue2(COleVariant(strRowTitle)); comFont = comRange.GetFont(); comFont.SetBold(COleVariant((short)TRUE)); strRowTitle.Empty(); strRowTitle.LoadString(IDS_DB_TD_TRFREQUENCY+g_UIOffset); comRange = pComSheet->GetRange(COleVariant(_T("A12")),COleVariant(_T("A12"))); comRange.SetValue2(COleVariant(strRowTitle)); comFont = comRange.GetFont(); comFont.SetBold(COleVariant((short)TRUE)); strRowTitle.Empty(); strRowTitle.LoadString(IDS_DB_TD_IFREQUENCY+g_UIOffset); comRange = pComSheet->GetRange(COleVariant(_T("A13")),COleVariant(_T("A13"))); comRange.SetValue2(COleVariant(strRowTitle)); comFont = comRange.GetFont(); comFont.SetBold(COleVariant((short)TRUE)); strRowTitle.Empty(); strRowTitle.LoadString(IDS_DB_TD_CLAYOUT+g_UIOffset); comRange = pComSheet->GetRange(COleVariant(_T("A14")),COleVariant(_T("A14"))); comRange.SetValue2(COleVariant(strRowTitle)); comFont = comRange.GetFont(); comFont.SetBold(COleVariant((short)TRUE)); strRowTitle.Empty(); strRowTitle.LoadString(IDS_DB_TD_EDISTANCE+g_UIOffset); comRange = pComSheet->GetRange(COleVariant(_T("A15")),COleVariant(_T("A15"))); comRange.SetValue2(COleVariant(strRowTitle)); comFont = comRange.GetFont(); comFont.SetBold(COleVariant((short)TRUE)); iStartIndex = 15; if (AR_MARINE == iAR) { strStIndex.Empty(); strStIndex.Format(_T("A%d"),++iStartIndex); strRowTitle.Empty(); strRowTitle.LoadString(IDS_DB_TD_SPACING+g_UIOffset); comRange = pComSheet->GetRange(COleVariant(strStIndex),COleVariant(strStIndex)); comRange.SetValue2(COleVariant(strRowTitle)); comFont = comRange.GetFont(); comFont.SetBold(COleVariant((short)TRUE)); strStIndex.Empty(); strStIndex.Format(_T("A%d"),++iStartIndex); strRowTitle.Empty(); strRowTitle.LoadString(IDS_DB_TD_INTERVAL+g_UIOffset); comRange = pComSheet->GetRange(COleVariant(strStIndex),COleVariant(strStIndex)); comRange.SetValue2(COleVariant(strRowTitle)); comFont = comRange.GetFont(); comFont.SetBold(COleVariant((short)TRUE)); strStIndex.Empty(); strStIndex.Format(_T("A%d"),++iStartIndex); strRowTitle.Empty(); strRowTitle.LoadString(IDS_DB_TD_DIPOLE_NO+g_UIOffset); comRange = pComSheet->GetRange(COleVariant(strStIndex),COleVariant(strStIndex)); comRange.SetValue2(COleVariant(strRowTitle)); comFont = comRange.GetFont(); comFont.SetBold(COleVariant((short)TRUE)); strStIndex.Empty(); strStIndex.Format(_T("A%d"),++iStartIndex); strRowTitle.Empty(); strRowTitle.LoadString(IDS_DB_TD_REC_MODE+g_UIOffset); comRange = pComSheet->GetRange(COleVariant(strStIndex),COleVariant(strStIndex)); comRange.SetValue2(COleVariant(strRowTitle)); comFont = comRange.GetFont(); comFont.SetBold(COleVariant((short)TRUE)); strStIndex.Empty(); strStIndex.Format(_T("A%d"),++iStartIndex); strRowTitle.Empty(); strRowTitle.LoadString(IDS_DB_TD_CUR_POLE_DEPOLE+g_UIOffset); comRange = pComSheet->GetRange(COleVariant(strStIndex),COleVariant(strStIndex)); comRange.SetValue2(COleVariant(strRowTitle)); comFont = comRange.GetFont(); comFont.SetBold(COleVariant((short)TRUE)); strStIndex.Empty(); strStIndex.Format(_T("A%d"),++iStartIndex); strRowTitle.Empty(); strRowTitle.LoadString(IDS_DB_TD_MOVE_SPEED+g_UIOffset); comRange = pComSheet->GetRange(COleVariant(strStIndex),COleVariant(strStIndex)); comRange.SetValue2(COleVariant(strRowTitle)); comFont = comRange.GetFont(); comFont.SetBold(COleVariant((short)TRUE)); strStIndex.Empty(); strStIndex.Format(_T("A%d"),++iStartIndex); strRowTitle.Empty(); strRowTitle.LoadString(IDS_DB_TD_REC_DISTANCE+g_UIOffset); comRange = pComSheet->GetRange(COleVariant(strStIndex),COleVariant(strStIndex)); comRange.SetValue2(COleVariant(strRowTitle)); comFont = comRange.GetFont(); comFont.SetBold(COleVariant((short)TRUE)); } strStIndex.Empty(); strStIndex.Format(_T("A%d"),++iStartIndex); strRowTitle.Empty(); strRowTitle.LoadString(IDS_DB_TD_WEATHER+g_UIOffset); comRange = pComSheet->GetRange(COleVariant(strStIndex),COleVariant(strStIndex)); comRange.SetValue2(COleVariant(strRowTitle)); comFont = comRange.GetFont(); comFont.SetBold(COleVariant((short)TRUE)); strStIndex.Empty(); strStIndex.Format(_T("A%d"),++iStartIndex); strRowTitle.Empty(); strRowTitle.LoadString(IDS_DB_TD_WDIR+g_UIOffset); comRange = pComSheet->GetRange(COleVariant(strStIndex),COleVariant(strStIndex)); comRange.SetValue2(COleVariant(strRowTitle)); comFont = comRange.GetFont(); comFont.SetBold(COleVariant((short)TRUE)); strStIndex.Empty(); strStIndex.Format(_T("A%d"),++iStartIndex); strRowTitle.Empty(); strRowTitle.LoadString(IDS_DB_TD_TEMPERATURE+g_UIOffset); comRange = pComSheet->GetRange(COleVariant(strStIndex),COleVariant(strStIndex)); comRange.SetValue2(COleVariant(strRowTitle)); comFont = comRange.GetFont(); comFont.SetBold(COleVariant((short)TRUE)); strStIndex.Empty(); strStIndex.Format(_T("A%d"),++iStartIndex); strRowTitle.Empty(); strRowTitle.LoadString(IDS_DB_TD_HEIGHT+g_UIOffset); comRange = pComSheet->GetRange(COleVariant(strStIndex),COleVariant(strStIndex)); comRange.SetValue2(COleVariant(strRowTitle)); comFont = comRange.GetFont(); comFont.SetBold(COleVariant((short)TRUE)); strStIndex.Empty(); strStIndex.Format(_T("A%d"),++iStartIndex); strRowTitle.Empty(); strRowTitle.LoadString(IDS_DB_TD_HUMIDITY+g_UIOffset); comRange = pComSheet->GetRange(COleVariant(strStIndex),COleVariant(strStIndex)); comRange.SetValue2(COleVariant(strRowTitle)); comFont = comRange.GetFont(); comFont.SetBold(COleVariant((short)TRUE)); strStIndex.Empty(); strStIndex.Format(_T("A%d"),++iStartIndex); strRowTitle.Empty(); strRowTitle.LoadString(IDS_DB_TD_CDATE+g_UIOffset); comRange = pComSheet->GetRange(COleVariant(strStIndex),COleVariant(strStIndex)); comRange.SetValue2(COleVariant(strRowTitle)); comFont = comRange.GetFont(); comFont.SetBold(COleVariant((short)TRUE)); strStIndex.Empty(); strStIndex.Format(_T("A%d"),++iStartIndex); strRowTitle.Empty(); strRowTitle.LoadString(IDS_DB_TD_CTIME+g_UIOffset); comRange = pComSheet->GetRange(COleVariant(strStIndex),COleVariant(strStIndex)); comRange.SetValue2(COleVariant(strRowTitle)); comFont = comRange.GetFont(); comFont.SetBold(COleVariant((short)TRUE)); strStIndex.Empty(); strStIndex.Format(_T("A%d"),++iStartIndex); strRowTitle.Empty(); strRowTitle.LoadString(IDS_DB_TD_TDATE+g_UIOffset); comRange = pComSheet->GetRange(COleVariant(strStIndex),COleVariant(strStIndex)); comRange.SetValue2(COleVariant(strRowTitle)); comFont = comRange.GetFont(); comFont.SetBold(COleVariant((short)TRUE)); strStIndex.Empty(); strStIndex.Format(_T("A%d"),++iStartIndex); strRowTitle.Empty(); strRowTitle.LoadString(IDS_DB_TD_TTIME+g_UIOffset); comRange = pComSheet->GetRange(COleVariant(strStIndex),COleVariant(strStIndex)); comRange.SetValue2(COleVariant(strRowTitle)); comFont = comRange.GetFont(); comFont.SetBold(COleVariant((short)TRUE)); strStIndex.Empty(); strStIndex.Format(_T("A%d"),++iStartIndex); strRowTitle.Empty(); strRowTitle.LoadString(IDS_DB_TD_OP+g_UIOffset); comRange = pComSheet->GetRange(COleVariant(strStIndex),COleVariant(strStIndex)); comRange.SetValue2(COleVariant(strRowTitle)); comFont = comRange.GetFont(); comFont.SetBold(COleVariant((short)TRUE)); strStIndex.Empty(); strStIndex.Format(_T("A%d"),++iStartIndex); strRowTitle.Empty(); strRowTitle.LoadString(IDS_DB_TD_QA+g_UIOffset); comRange = pComSheet->GetRange(COleVariant(strStIndex),COleVariant(strStIndex)); comRange.SetValue2(COleVariant(strRowTitle)); comFont = comRange.GetFont(); comFont.SetBold(COleVariant((short)TRUE)); comCols = comRange.GetEntireColumn(); comCols.AutoFit(); comRange = pComSheet->GetRange(COleVariant(_T("B1")),COleVariant(_T("B1"))); comRange.SetValue2(COleVariant((LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("TDname")))); // comRange = pComSheet->GetRange(COleVariant(_T("B2")),COleVariant(_T("B2"))); // comRange.SetValue2(COleVariant((LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("Tlocation")))); comRange = pComSheet->GetRange(COleVariant(_T("B2")),COleVariant(_T("B2"))); comRange.SetValue2(COleVariant((pRecTd->GetCollect(_T("DESN")).vt == VT_NULL)?_T(""):(LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("DESN")))); // comRange = pComSheet->GetRange(COleVariant(_T("B4")),COleVariant(_T("B4"))); // comRange.SetValue2(COleVariant((LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("SCCN")))); comRange = pComSheet->GetRange(COleVariant(_T("B3")),COleVariant(_T("B3"))); comRange.SetValue2(COleVariant((LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("Sname")))); szSql.Empty(); szSql.Format(_T("select Clabel from cm where Cname = 'Stype' and Lang = %d and Cvalue = %s"), g_iLanguage, pRecTd->GetCollect(_T("Stype")).vt == VT_NULL ? _T("-1") : (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("Stype"))); pRecCm->Open(szSql.AllocSysString(), _variant_t((IDispatch*)m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText); if ((long)0 != pRecCm->GetRecordCount()) { comRange = pComSheet->GetRange(COleVariant(_T("B4")),COleVariant(_T("B4"))); comRange.SetValue2(COleVariant((LPCTSTR)(_bstr_t)pRecCm->GetCollect(_T("Clabel")))); } pRecCm->Close(); szSql.Empty(); szSql.Format(_T("select Clabel from cm where Cname = 'Ttype' and Lang = %d and Cvalue = %s"), g_iLanguage, pRecTd->GetCollect(_T("Ttype")).vt == VT_NULL ? _T("-1") : (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("Ttype"))); pRecCm->Open(szSql.AllocSysString(), _variant_t((IDispatch*)m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText); if ((long)0 != pRecCm->GetRecordCount()) { comRange = pComSheet->GetRange(COleVariant(_T("B5")),COleVariant(_T("B5"))); comRange.SetValue2(COleVariant((LPCTSTR)(_bstr_t)pRecCm->GetCollect(_T("Clabel")))); } pRecCm->Close(); szSql.Empty(); szSql.Format(_T("select Clabel from cm where Cname = 'Tmode' and Lang = %d and Cvalue = %s"), g_iLanguage, pRecTd->GetCollect(_T("Tmode")).vt == VT_NULL ? _T("-1") : (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("Tmode"))); pRecCm->Open(szSql.AllocSysString(), _variant_t((IDispatch*)m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText); if ((long)0 != pRecCm->GetRecordCount()) { // comRange = pComSheet->GetRange(COleVariant(_T("B8")),COleVariant(_T("B8"))); // comRange.SetValue2(COleVariant((LPCTSTR)(_bstr_t)pRecCm->GetCollect(_T("Clabel")))); } pRecCm->Close(); ///////////////////////////////////加入装置类型//////////////////////////// szSql.Empty(); szSql.Format(_T("select MEname from medium where LANG = %d and AR in (select AR from tdchannel where TDID = %d)"), g_iLanguage, m_dwID); pRecCm->Open(szSql.AllocSysString(), _variant_t((IDispatch*)m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText); if ((long)VAL_ZERO != pRecCm->GetRecordCount()) { comRange = pComSheet->GetRange(COleVariant(_T("B6")),COleVariant(_T("B6"))); comRange.SetValue2(COleVariant((LPCTSTR)(_bstr_t)pRecCm->GetCollect(_T("MEname")))); } pRecCm->Close(); ////////////////////////////////////////////////////////////////////////// comRange = pComSheet->GetRange(COleVariant(_T("B7")),COleVariant(_T("B7"))); comRange.SetValue2(COleVariant((LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("Eamount")))); comRange = pComSheet->GetRange(COleVariant(_T("B8")),COleVariant(_T("B8"))); comRange.SetValue2(COleVariant((LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("TPamount")))); comRange = pComSheet->GetRange(COleVariant(_T("B9")),COleVariant(_T("B9"))); comRange.SetValue2(COleVariant((LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("CHamount")))); comRange = pComSheet->GetRange(COleVariant(_T("B10")),COleVariant(_T("B10"))); comRange.SetValue2(COleVariant((LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("N")))); szSql.Empty(); szSql.Format(_T("select Clabel from cm where Cname = 'TRwave' and Lang = %d and Cvalue = %s"), g_iLanguage, pRecTd->GetCollect(_T("TRwave")).vt == VT_NULL ? _T("-1") : (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("TRwave"))); pRecCm->Open(szSql.AllocSysString(), _variant_t((IDispatch*)m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText); if ((long)0 != pRecCm->GetRecordCount()) { comRange = pComSheet->GetRange(COleVariant(_T("B11")),COleVariant(_T("B11"))); comRange.SetValue2(COleVariant((LPCTSTR)(_bstr_t)pRecCm->GetCollect(_T("Clabel")))); } pRecCm->Close(); if ((0 == pRecTd->GetCollect(_T("Ttype")).iVal) || (1 == pRecTd->GetCollect(_T("Ttype")).iVal)) { szSql.Empty(); szSql.Format(_T("select Clabel from cm where Cname = 'Trfrequency' and Lang = %d and Cvalue = %s"), g_iLanguage, pRecTd->GetCollect(_T("Trfrequency")).vt == VT_NULL ? _T("-1") : (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("Trfrequency"))); pRecCm->Open(szSql.AllocSysString(), _variant_t((IDispatch*)m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText); if ((long)0 != pRecCm->GetRecordCount()) { comRange = pComSheet->GetRange(COleVariant(_T("B12")),COleVariant(_T("B12"))); comRange.SetValue2(COleVariant((LPCTSTR)(_bstr_t)pRecCm->GetCollect(_T("Clabel")))); } pRecCm->Close(); } else if (2 == pRecTd->GetCollect(_T("Ttype")).iVal) { szSql.Empty(); szSql.Format(_T("select Clabel from cm where Cname = 'Trfrequencyself' and Lang = %d and Cvalue = %s"), g_iLanguage, pRecTd->GetCollect(_T("Trfrequency")).vt == VT_NULL ? _T("-1") : (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("Trfrequency"))); pRecCm->Open(szSql.AllocSysString(), _variant_t((IDispatch*)m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText); if ((long)0 != pRecCm->GetRecordCount()) { comRange = pComSheet->GetRange(COleVariant(_T("B12")),COleVariant(_T("B12"))); comRange.SetValue2(COleVariant((LPCTSTR)(_bstr_t)pRecCm->GetCollect(_T("Clabel")))); } pRecCm->Close(); } szSql.Empty(); szSql.Format(_T("select Clabel from cm where Cname = 'Ifrequency' and Lang = %d and Cvalue = %s"), g_iLanguage, pRecTd->GetCollect(_T("Ifrequency")).vt == VT_NULL ? _T("-1") : (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("Ifrequency"))); pRecCm->Open(szSql.AllocSysString(), _variant_t((IDispatch*)m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText); if ((long)0 != pRecCm->GetRecordCount()) { comRange = pComSheet->GetRange(COleVariant(_T("B13")),COleVariant(_T("B13"))); comRange.SetValue2(COleVariant((LPCTSTR)(_bstr_t)pRecCm->GetCollect(_T("Clabel")))); } pRecCm->Close(); szSql.Empty(); szSql.Format(_T("select Clabel from cm where Cname = 'Clayout' and Lang = %d and Cvalue = %s"), g_iLanguage, pRecTd->GetCollect(_T("Clayout")).vt == VT_NULL ? _T("-1") : (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("Clayout"))); pRecCm->Open(szSql.AllocSysString(), _variant_t((IDispatch*)m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText); if ((long)0 != pRecCm->GetRecordCount()) { comRange = pComSheet->GetRange(COleVariant(_T("B14")),COleVariant(_T("B14"))); comRange.SetValue2(COleVariant((LPCTSTR)(_bstr_t)pRecCm->GetCollect(_T("Clabel")))); } pRecCm->Close(); comRange = pComSheet->GetRange(COleVariant(_T("B15")),COleVariant(_T("B15"))); comRange.SetValue2(COleVariant((pRecTd->GetCollect(_T("Edistance")).vt == VT_NULL) ? "" :(LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("Edistance")))); iStartIndex = 15; if (AR_MARINE == iAR) { CString strTmpSql = _T(""); strTmpSql.Format(_T("select a.* from td1dSpcAttr a, tdchannel b where a.TCHID = b.ID and b.TDID = %u"), m_dwID); pRecTdSpcAttr->Open(strTmpSql.AllocSysString(), _variant_t((IDispatch*)m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText); int iTmp = 0; CString strInfo = _T(""); if (pRecTdSpcAttr->GetRecordCount() > 0) { float fVal = 0; strStIndex.Empty(); strStIndex.Format(_T("B%d"),++iStartIndex); if(pRecTdSpcAttr->GetCollect(_T("Spacing")).vt != VT_NULL) { strInfo.Empty(); strInfo.Format(_T("%.2f"),pRecTdSpcAttr->GetCollect(_T("Spacing")).fltVal); comRange = pComSheet->GetRange(COleVariant(strStIndex),COleVariant(strStIndex)); comRange.SetValue2(COleVariant(strInfo)); } //Interval strStIndex.Empty(); strStIndex.Format(_T("B%d"),++iStartIndex); if(pRecTdSpcAttr->GetCollect(_T("PoleInterval")).vt != VT_NULL) { strInfo.Empty(); strInfo.Format(_T("%.2f"),pRecTdSpcAttr->GetCollect(_T("PoleInterval")).fltVal); comRange = pComSheet->GetRange(COleVariant(strStIndex),COleVariant(strStIndex)); comRange.SetValue2(COleVariant(strInfo)); } //DipoleNo strStIndex.Empty(); strStIndex.Format(_T("B%d"),++iStartIndex); strInfo = (pRecTdSpcAttr->GetCollect(_T("DipoleNo")).vt != VT_NULL) ? (LPCTSTR)(_bstr_t)pRecTdSpcAttr->GetCollect(_T("DipoleNo")) : _T(""); comRange = pComSheet->GetRange(COleVariant(strStIndex),COleVariant(strStIndex)); comRange.SetValue2(COleVariant(strInfo)); //RecordMode iTmp = pRecTdSpcAttr->GetCollect(_T("RecordMode")).iVal; strStIndex.Empty(); strStIndex.Format(_T("B%d"),++iStartIndex); if (iTmp > 2 || iTmp < 0) { strInfo.Empty(); if (LANG_ZHCN == g_iUILanguage) { strInfo.Format(_T("查询记录模式值无效,值= %d"), iTmp); AfxMessageBox(strInfo); } else { strInfo.Format(_T("Query recording mode value invalid, value = %d"), iTmp); MessageBoxEx(NULL, strInfo, STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)); } } else { comRange = pComSheet->GetRange(COleVariant(strStIndex),COleVariant(strStIndex)); comRange.SetValue2(COleVariant(g_chRecMode[iTmp])); } //CurPoleDepoly strStIndex.Empty(); strStIndex.Format(_T("B%d"),++iStartIndex); iTmp = pRecTdSpcAttr->GetCollect(_T("CurPoleDepoly")).iVal; if (iTmp > 1 || iTmp < 0) { strInfo.Empty(); if (LANG_ZHCN == g_iUILanguage) { strInfo.Format(_T("查询当前孔depolyment值无效,值 = %d"), iTmp); AfxMessageBox(strInfo); } else { strInfo.Format(_T("Query current pole depolyment value invalid, value = %d"), iTmp); MessageBoxEx(NULL, strInfo, STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)); } } else { comRange = pComSheet->GetRange(COleVariant(strStIndex),COleVariant(strStIndex)); comRange.SetValue2(COleVariant(g_chCurPoleDepoly[iTmp])); } //MovingSpeed strStIndex.Empty(); strStIndex.Format(_T("B%d"),++iStartIndex); if (pRecTdSpcAttr->GetCollect(_T("MovingSpeed")).vt != VT_NULL) { fVal = pRecTdSpcAttr->GetCollect(_T("MovingSpeed")).fltVal; strInfo.Empty(); if (fVal < 0) strInfo = _T("Auto"); else strInfo.Format(_T("%.2f m/s"), fVal); comRange = pComSheet->GetRange(COleVariant(strStIndex),COleVariant(strStIndex)); comRange.SetValue2(COleVariant(strInfo)); } //RecordDistance strStIndex.Empty(); strStIndex.Format(_T("B%d"),++iStartIndex); if(pRecTdSpcAttr->GetCollect(_T("RecordDistance")).vt != VT_NULL) { strInfo.Empty(); strInfo.Format(_T("%.2f"),pRecTdSpcAttr->GetCollect(_T("RecordDistance")).fltVal); comRange = pComSheet->GetRange(COleVariant(strStIndex),COleVariant(strStIndex)); comRange.SetValue2(COleVariant(strInfo)); } } else { if (LANG_ZHCN == g_iUILanguage) AfxMessageBox(_T("在数据库不能找到marin 信息")); else MessageBoxEx(NULL, _T("Can not found marin information in database"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)); iStartIndex += 7; } pRecTdSpcAttr->Close(); } strStIndex.Empty(); strStIndex.Format(_T("B%d"),++iStartIndex); szSql.Empty(); szSql.Format(_T("select Clabel from cm where Cname = 'weather' and Lang = %d and Cvalue = %s"), g_iLanguage, pRecTd->GetCollect(_T("weather")).vt == VT_NULL ? _T("-1") : (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("weather"))); pRecCm->Open(szSql.AllocSysString(), _variant_t((IDispatch*)m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText); if ((long)0 != pRecCm->GetRecordCount()) { comRange = pComSheet->GetRange(COleVariant(strStIndex),COleVariant(strStIndex)); comRange.SetValue2(COleVariant((LPCTSTR)(_bstr_t)pRecCm->GetCollect(_T("Clabel")))); } pRecCm->Close(); strStIndex.Empty(); strStIndex.Format(_T("B%d"),++iStartIndex); szSql.Empty(); szSql.Format(_T("select Clabel from cm where Cname = 'WDIR' and Lang = %d and Cvalue = %s"), g_iLanguage, pRecTd->GetCollect(_T("WDIR")).vt == VT_NULL ? _T("-1") : (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("WDIR"))); pRecCm->Open(szSql.AllocSysString(), _variant_t((IDispatch*)m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText); if ((long)0 != pRecCm->GetRecordCount()) { comRange = pComSheet->GetRange(COleVariant(strStIndex),COleVariant(strStIndex)); comRange.SetValue2(COleVariant((LPCTSTR)(_bstr_t)pRecCm->GetCollect(_T("Clabel")))); } pRecCm->Close(); strStIndex.Empty(); strStIndex.Format(_T("B%d"),++iStartIndex); CString strTmp = _T(""); float fTmp = (pRecTd->GetCollect(_T("temperature")).vt == VT_NULL) ? -9999:(float)pRecTd->GetCollect(_T("temperature")).fltVal; if (fTmp > -9000) { strTmp.Format(_T("%f"),fTmp); } comRange = pComSheet->GetRange(COleVariant(strStIndex),COleVariant(strStIndex)); comRange.SetValue2(COleVariant(strTmp)); strStIndex.Empty(); strStIndex.Format(_T("B%d"),++iStartIndex); comRange = pComSheet->GetRange(COleVariant(strStIndex),COleVariant(strStIndex)); comRange.SetValue2(COleVariant((pRecTd->GetCollect(_T("height")).vt == VT_NULL) ? _T(""):(LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("height")))); strStIndex.Empty(); strStIndex.Format(_T("B%d"),++iStartIndex); strTmp.Empty(); fTmp = (pRecTd->GetCollect(_T("humidity")).vt == VT_NULL) ? -9999:(float)pRecTd->GetCollect(_T("humidity")).fltVal; if (fTmp > -9000) { strTmp.Format(_T("%f"),fTmp); } comRange = pComSheet->GetRange(COleVariant(strStIndex),COleVariant(strStIndex)); comRange.SetValue2(COleVariant(strTmp)); strStIndex.Empty(); strStIndex.Format(_T("B%d"),++iStartIndex); comRange = pComSheet->GetRange(COleVariant(strStIndex),COleVariant(strStIndex)); comRange.SetValue2(COleVariant((LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("Cdate")))); strStIndex.Empty(); strStIndex.Format(_T("B%d"),++iStartIndex); comRange = pComSheet->GetRange(COleVariant(strStIndex),COleVariant(strStIndex)); comRange.SetValue2(COleVariant((LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("Ctime")))); strStIndex.Empty(); strStIndex.Format(_T("B%d"),++iStartIndex); comRange = pComSheet->GetRange(COleVariant(strStIndex),COleVariant(strStIndex)); comRange.SetValue2(COleVariant((pRecTd->GetCollect(_T("Tdate")).vt == VT_NULL) ? _T(""):(LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("Tdate")))); strStIndex.Empty(); strStIndex.Format(_T("B%d"),++iStartIndex); comRange = pComSheet->GetRange(COleVariant(strStIndex),COleVariant(strStIndex)); comRange.SetValue2(COleVariant((pRecTd->GetCollect(_T("Ttime")).vt == VT_NULL) ? _T(""):(LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("Ttime")))); //这个不用加 szSql.Empty(); szSql.Format(_T("select Clabel from cm where Cname = 'Rdirection' and Lang = %d and Cvalue = %s"), g_iLanguage, pRecTd->GetCollect(_T("Rdirection")).vt == VT_NULL ? _T("-1") : (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("Rdirection"))); pRecCm->Open(szSql.AllocSysString(), _variant_t((IDispatch*)m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText); if ((long)0 != pRecCm->GetRecordCount()) { // comRange = pComSheet->GetRange(COleVariant(_T("B29")),COleVariant(_T("B29"))); // comRange.SetValue2(COleVariant((LPCTSTR)(_bstr_t)pRecCm->GetCollect(_T("Clabel")))); } pRecCm->Close(); strStIndex.Empty(); strStIndex.Format(_T("B%d"),++iStartIndex); comRange = pComSheet->GetRange(COleVariant(strStIndex),COleVariant(strStIndex)); comRange.SetValue2(COleVariant((pRecTd->GetCollect(_T("OP")).vt == VT_NULL) ? _T(""):(LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("OP")))); strStIndex.Empty(); strStIndex.Format(_T("B%d"),++iStartIndex); comRange = pComSheet->GetRange(COleVariant(strStIndex),COleVariant(strStIndex)); comRange.SetValue2(COleVariant((pRecTd->GetCollect(_T("QA")).vt == VT_NULL) ? _T(""):(LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("QA")))); comCols = comRange.GetEntireColumn(); comCols.AutoFit(); } pRecTd->Close(); return TRUE; } BOOL CRspCETd::SaveTdConToExcelFile(_Worksheet* const pComSheet) { Range comRange; excel9::Font comFont; Range comCols; _RecordsetPtr pRecConList = NULL; CString szSql = _T(""); CString szRow = _T(""); pRecConList.CreateInstance(_uuidof(Recordset)); szSql.Empty(); szSql.Format(_T("select a,b,x,y,N,K,I,V,R0,SP,bUse,R0_LC,M0_LC,POINT_NUM from td1dcon where TEST_FLAG = 1 and TCHID in (select ID from tdchannel where TDID = %u order by TCHID) order by TSN"), m_dwID); try { pRecConList->Open(szSql.AllocSysString(), _variant_t((IDispatch*)m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText); } catch (_com_error e) { hHook = SetWindowsHookEx(WH_CBT, (HOOKPROC)CBTHookProc, AfxGetInstanceHandle(), NULL); AfxMessageBox((LPCTSTR)e.Description()); } int iIndex = (int)0; CHAR COL = 'A'; iIndex = 1; if (pRecConList->GetCollect(_T("POINT_NUM")).iVal >= 0) { szRow.Empty(); szRow.Format(_T("%c%d"), COL++, iIndex); comRange = pComSheet->GetRange(COleVariant(szRow), COleVariant(szRow)); comRange.SetValue2(COleVariant(_T("Point Num"))); } szRow.Empty(); szRow.Format(_T("%c%d"), COL++, iIndex); comRange = pComSheet->GetRange(COleVariant(szRow),COleVariant(szRow)); comRange.SetValue2(COleVariant(_T("a"))); comFont = comRange.GetFont(); comFont.SetBold(COleVariant((short)TRUE)); szRow.Empty(); szRow.Format(_T("%c%d"), COL++, iIndex); comRange = pComSheet->GetRange(COleVariant(szRow),COleVariant(szRow)); comRange.SetValue2(COleVariant(_T("b"))); comFont = comRange.GetFont(); comFont.SetBold(COleVariant((short)TRUE)); szRow.Empty(); szRow.Format(_T("%c%d"), COL++, iIndex); comRange = pComSheet->GetRange(COleVariant(szRow),COleVariant(szRow)); comRange.SetValue2(COleVariant(_T("x"))); comFont = comRange.GetFont(); comFont.SetBold(COleVariant((short)TRUE)); szRow.Empty(); szRow.Format(_T("%c%d"), COL++, iIndex); comRange = pComSheet->GetRange(COleVariant(szRow),COleVariant(szRow)); comRange.SetValue2(COleVariant(_T("y"))); comFont = comRange.GetFont(); comFont.SetBold(COleVariant((short)TRUE)); szRow.Empty(); szRow.Format(_T("%c%d"), COL++, iIndex); comRange = pComSheet->GetRange(COleVariant(szRow),COleVariant(szRow)); comRange.SetValue2(COleVariant(_T("Stacking"))); comFont = comRange.GetFont(); comFont.SetBold(COleVariant((short)TRUE)); szRow.Empty(); szRow.Format(_T("%c%d"), COL++, iIndex); comRange = pComSheet->GetRange(COleVariant(szRow),COleVariant(szRow)); comRange.SetValue2(COleVariant(_T("K"))); comFont = comRange.GetFont(); comFont.SetBold(COleVariant((short)TRUE)); szRow.Empty(); szRow.Format(_T("%c%d"), COL++, iIndex); comRange = pComSheet->GetRange(COleVariant(szRow),COleVariant(szRow)); comRange.SetValue2(COleVariant(_T("I(mA)"))); comFont = comRange.GetFont(); comFont.SetBold(COleVariant((short)TRUE)); szRow.Empty(); szRow.Format(_T("%c%d"), COL++, iIndex); comRange = pComSheet->GetRange(COleVariant(szRow),COleVariant(szRow)); comRange.SetValue2(COleVariant(_T("V(mV)"))); comFont = comRange.GetFont(); comFont.SetBold(COleVariant((short)TRUE)); szRow.Empty(); szRow.Format(_T("%c%d"), COL++, iIndex); comRange = pComSheet->GetRange(COleVariant(szRow),COleVariant(szRow)); comRange.SetValue2(COleVariant(_T("R(Ohm)"))); comFont = comRange.GetFont(); comFont.SetBold(COleVariant((short)TRUE)); szRow.Empty(); szRow.Format(_T("%c%d"), COL++, iIndex); comRange = pComSheet->GetRange(COleVariant(szRow),COleVariant(szRow)); comRange.SetValue2(COleVariant(_T("R0"))); comFont = comRange.GetFont(); comFont.SetBold(COleVariant((short)TRUE)); szRow.Empty(); szRow.Format(_T("%c%d"), COL++, iIndex); comRange = pComSheet->GetRange(COleVariant(szRow),COleVariant(szRow)); comRange.SetValue2(COleVariant(_T("SP"))); comFont = comRange.GetFont(); comFont.SetBold(COleVariant((short)TRUE)); szRow.Empty(); szRow.Format(_T("%c%d"), COL++, iIndex); comRange = pComSheet->GetRange(COleVariant(szRow),COleVariant(szRow)); comRange.SetValue2(COleVariant(_T("R0_RD"))); comFont = comRange.GetFont(); comFont.SetBold(COleVariant((short)TRUE)); float fV = 0, fI = 0, fR = 0; CString strText = _T(""); while ((short)0 == pRecConList->adoEOF) { if (pRecConList->GetCollect(_T("bUse")).boolVal != 0)//0为access数据库中的false { COL = 'A'; iIndex++; if (pRecConList->GetCollect(_T("POINT_NUM")).iVal >= 0) { szRow.Empty(); szRow.Format(_T("%c%d"), COL++, iIndex); comRange = pComSheet->GetRange(COleVariant(szRow), COleVariant(szRow)); comRange.SetValue2(COleVariant((LPCTSTR)(_bstr_t)pRecConList->GetCollect(_T("POINT_NUM")))); } szRow.Empty(); szRow.Format(_T("%c%d"), COL++, iIndex); comRange = pComSheet->GetRange(COleVariant(szRow),COleVariant(szRow)); comRange.SetValue2(COleVariant((LPCTSTR)(_bstr_t)pRecConList->GetCollect(_T("a")))); // comCols = comRange.GetEntireColumn(); // comCols.AutoFit(); szRow.Empty(); szRow.Format(_T("%c%d"), COL++, iIndex); comRange = pComSheet->GetRange(COleVariant(szRow),COleVariant(szRow)); comRange.SetValue2(COleVariant((LPCTSTR)(_bstr_t)pRecConList->GetCollect(_T("b")))); // comCols = comRange.GetEntireColumn(); // comCols.AutoFit(); szRow.Empty(); szRow.Format(_T("%c%d"), COL++, iIndex); comRange = pComSheet->GetRange(COleVariant(szRow),COleVariant(szRow)); comRange.SetValue2(COleVariant((LPCTSTR)(_bstr_t)pRecConList->GetCollect(_T("x")))); // comCols = comRange.GetEntireColumn(); // comCols.AutoFit(); szRow.Empty(); szRow.Format(_T("%c%d"), COL++, iIndex); comRange = pComSheet->GetRange(COleVariant(szRow),COleVariant(szRow)); comRange.SetValue2(COleVariant((LPCTSTR)(_bstr_t)pRecConList->GetCollect(_T("y")))); // comCols = comRange.GetEntireColumn(); // comCols.AutoFit(); szRow.Empty(); szRow.Format(_T("%c%d"), COL++, iIndex); comRange = pComSheet->GetRange(COleVariant(szRow),COleVariant(szRow)); comRange.SetValue2(COleVariant((LPCTSTR)(_bstr_t)pRecConList->GetCollect(_T("N")))); // comCols = comRange.GetEntireColumn(); // comCols.AutoFit(); szRow.Empty(); szRow.Format(_T("%c%d"), COL++, iIndex); comRange = pComSheet->GetRange(COleVariant(szRow),COleVariant(szRow)); strText.Empty(); strText.Format(_T("%f"), pRecConList->GetCollect(_T("K")).fltVal); comRange.SetValue2(COleVariant(strText)); // comCols = comRange.GetEntireColumn(); // comCols.AutoFit(); szRow.Empty(); szRow.Format(_T("%c%d"), COL++, iIndex); comRange = pComSheet->GetRange(COleVariant(szRow),COleVariant(szRow)); strText.Empty(); strText.Format(_T("%f"), pRecConList->GetCollect(_T("I")).fltVal); comRange.SetValue2(COleVariant(strText)); // comCols = comRange.GetEntireColumn(); // comCols.AutoFit(); szRow.Empty(); szRow.Format(_T("%c%d"), COL++, iIndex); comRange = pComSheet->GetRange(COleVariant(szRow),COleVariant(szRow)); strText.Empty(); strText.Format(_T("%f"), pRecConList->GetCollect(_T("V")).fltVal); comRange.SetValue2(COleVariant(strText)); // comCols = comRange.GetEntireColumn(); // comCols.AutoFit(); //添加R fV = (float)pRecConList->GetCollect(_T("V")).fltVal; fI = (float)pRecConList->GetCollect(_T("I")).fltVal; fR = (0 == fI) ? 0 : fV/fI; strText.Empty(); strText.Format(_T("%f"),fR); szRow.Empty(); szRow.Format(_T("%c%d"), COL++, iIndex); comRange = pComSheet->GetRange(COleVariant(szRow),COleVariant(szRow)); comRange.SetValue2(COleVariant(strText)); szRow.Empty(); szRow.Format(_T("%c%d"), COL++, iIndex); comRange = pComSheet->GetRange(COleVariant(szRow),COleVariant(szRow)); strText.Empty(); strText.Format(_T("%f"), pRecConList->GetCollect(_T("R0")).fltVal); comRange.SetValue2(COleVariant(strText)); // comCols = comRange.GetEntireColumn(); // comCols.AutoFit(); szRow.Empty(); szRow.Format(_T("%c%d"), COL++, iIndex); comRange = pComSheet->GetRange(COleVariant(szRow),COleVariant(szRow)); strText.Empty(); strText.Format(_T("%f"), pRecConList->GetCollect(_T("SP")).fltVal); comRange.SetValue2(COleVariant(strText)); szRow.Empty(); szRow.Format(_T("%c%d"), COL++, iIndex); strText.Empty(); strText.Format(_T("%f%%"), pRecConList->GetCollect(_T("R0_LC")).fltVal); comRange = pComSheet->GetRange(COleVariant(szRow),COleVariant(szRow)); comRange.SetValue2(COleVariant(strText)); // comCols = comRange.GetEntireColumn(); // comCols.AutoFit(); } pRecConList->MoveNext(); } pRecConList->Close(); return TRUE; } BOOL CRspCETd::SaveTdHeadToCsvFile(FILE* pFile) { _RecordsetPtr pRecTd = NULL; _RecordsetPtr pRecTdHead = NULL; _RecordsetPtr pRecDev = NULL; _RecordsetPtr pRecPara = NULL; _RecordsetPtr pRecCm = NULL; _RecordsetPtr pRecTdSpcAttr = NULL; CString szSql; CString szLabel; int iAR = 0; int iRowIndex = (int)0; pRecTd.CreateInstance(_uuidof(Recordset)); pRecTdHead.CreateInstance(_uuidof(Recordset)); pRecDev.CreateInstance(_uuidof(Recordset)); pRecPara.CreateInstance(_uuidof(Recordset)); pRecCm.CreateInstance(_uuidof(Recordset)); pRecTdSpcAttr.CreateInstance(_uuidof(Recordset)); szSql.Empty(); szSql.Format(_T("select a.ID,TDname,Tlocation,DESN,SCCN,Sname,Stype,Ttype,Tmode,Eamount,TPamount,CHamount,N,TRwave,TRfrequency,Ifrequency,SAfrequency,Clayout,Espace,Edistance,weather,WDIR," "temperature,height,humidity,Format(a.Cdate,'YYYY-MM-DD') as Cdate,Format(a.Ctime,'HH:MM:SS') as Ctime,Format(a.Tdate,'YYYY-MM-DD') as Tdate,Format(a.Ttime,'HH:MM:SS') as Ttime," "Rdirection,CRtime,IIf(IsNull(a.PM),'',a.PM) as PM,IIf(IsNull(a.OP),'',a.OP) as OP,IIf(IsNull(a.QA),'',a.QA) as QA, b.AR as AR from td a, tdchannel b where a.ID = %u and a.ID = b.TDID"), m_dwID); pRecTd->Open(szSql.AllocSysString(), _variant_t((IDispatch*)m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText); CString strRowTitle; CStringArray arrHead; if ((long)0 != pRecTd->GetRecordCount()) { strRowTitle.Empty(); if (LANG_ZHCN == g_iUILanguage) strRowTitle = _T("测试任务名称"); else strRowTitle = _T("Test data name"); arrHead.Add(strRowTitle + _T(',')); strRowTitle.Empty(); strRowTitle.LoadString(IDS_DB_TD_DESN + g_UIOffset); arrHead.Add(strRowTitle + _T(',')); strRowTitle.Empty(); strRowTitle.LoadString(IDS_DB_TD_SNAME + g_UIOffset); arrHead.Add(strRowTitle + _T(',')); strRowTitle.Empty(); strRowTitle.LoadString(IDS_DB_TD_STYPE + g_UIOffset); arrHead.Add(strRowTitle + _T(',')); strRowTitle.Empty(); strRowTitle.LoadString(IDS_DB_TD_TTYPE + g_UIOffset); arrHead.Add(strRowTitle + _T(',')); strRowTitle.Empty(); strRowTitle.LoadString(IDS_ARRAY_TYPE + g_UIOffset); arrHead.Add(strRowTitle + _T(',')); strRowTitle.Empty(); strRowTitle.LoadString(IDS_DB_TD_EAMOUNT + g_UIOffset); arrHead.Add(strRowTitle + _T(',')); strRowTitle.Empty(); strRowTitle.LoadString(IDS_DB_TD_TPAMOUNT + g_UIOffset); arrHead.Add(strRowTitle + _T(',')); strRowTitle.Empty(); strRowTitle.LoadString(IDS_DB_TD_CHAMOUNT + g_UIOffset); arrHead.Add(strRowTitle + _T(',')); strRowTitle.Empty(); strRowTitle.LoadString(IDS_DB_TD_N + g_UIOffset); arrHead.Add(strRowTitle + _T(',')); strRowTitle.Empty(); strRowTitle.LoadString(IDS_DB_TD_TRWAVE + g_UIOffset); arrHead.Add(strRowTitle + _T(',')); strRowTitle.Empty(); strRowTitle.LoadString(IDS_DB_TD_TRFREQUENCY + g_UIOffset); arrHead.Add(strRowTitle + _T(',')); strRowTitle.Empty(); strRowTitle.LoadString(IDS_DB_TD_IFREQUENCY + g_UIOffset); arrHead.Add(strRowTitle + _T(',')); strRowTitle.Empty(); strRowTitle.LoadString(IDS_DB_TD_CLAYOUT + g_UIOffset); arrHead.Add(strRowTitle + _T(',')); strRowTitle.Empty(); strRowTitle.LoadString(IDS_DB_TD_EDISTANCE + g_UIOffset); arrHead.Add(strRowTitle + _T(',')); if (AR_MARINE == iAR) { strRowTitle.Empty(); strRowTitle.LoadString(IDS_DB_TD_SPACING + g_UIOffset); arrHead.Add(strRowTitle + _T(',')); strRowTitle.Empty(); strRowTitle.LoadString(IDS_DB_TD_INTERVAL + g_UIOffset); arrHead.Add(strRowTitle + _T(',')); strRowTitle.Empty(); strRowTitle.LoadString(IDS_DB_TD_DIPOLE_NO + g_UIOffset); arrHead.Add(strRowTitle + _T(',')); strRowTitle.Empty(); strRowTitle.LoadString(IDS_DB_TD_REC_MODE + g_UIOffset); arrHead.Add(strRowTitle + _T(',')); strRowTitle.Empty(); strRowTitle.LoadString(IDS_DB_TD_CUR_POLE_DEPOLE + g_UIOffset); arrHead.Add(strRowTitle + _T(',')); strRowTitle.Empty(); strRowTitle.LoadString(IDS_DB_TD_MOVE_SPEED + g_UIOffset); arrHead.Add(strRowTitle + _T(',')); strRowTitle.Empty(); strRowTitle.LoadString(IDS_DB_TD_REC_DISTANCE + g_UIOffset); arrHead.Add(strRowTitle + _T(',')); } strRowTitle.Empty(); strRowTitle.LoadString(IDS_DB_TD_WEATHER + g_UIOffset); arrHead.Add(strRowTitle + _T(',')); strRowTitle.Empty(); strRowTitle.LoadString(IDS_DB_TD_WDIR + g_UIOffset); arrHead.Add(strRowTitle + _T(',')); strRowTitle.Empty(); strRowTitle.LoadString(IDS_DB_TD_TEMPERATURE + g_UIOffset); arrHead.Add(strRowTitle + _T(',')); strRowTitle.Empty(); strRowTitle.LoadString(IDS_DB_TD_HEIGHT + g_UIOffset); arrHead.Add(strRowTitle + _T(',')); strRowTitle.Empty(); strRowTitle.LoadString(IDS_DB_TD_HUMIDITY + g_UIOffset); arrHead.Add(strRowTitle + _T(',')); strRowTitle.Empty(); strRowTitle.LoadString(IDS_DB_TD_CDATE + g_UIOffset); arrHead.Add(strRowTitle + _T(',')); strRowTitle.Empty(); strRowTitle.LoadString(IDS_DB_TD_CTIME + g_UIOffset); arrHead.Add(strRowTitle + _T(',')); strRowTitle.Empty(); strRowTitle.LoadString(IDS_DB_TD_TDATE + g_UIOffset); arrHead.Add(strRowTitle + _T(',')); strRowTitle.Empty(); strRowTitle.LoadString(IDS_DB_TD_TTIME + g_UIOffset); arrHead.Add(strRowTitle + _T(',')); strRowTitle.Empty(); strRowTitle.LoadString(IDS_DB_TD_OP + g_UIOffset); arrHead.Add(strRowTitle + _T(',')); strRowTitle.Empty(); strRowTitle.LoadString(IDS_DB_TD_QA + g_UIOffset); arrHead.Add(strRowTitle + _T(',')); ///////////////////////////////////////////////////// int i = 0; arrHead[i++] += ((LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("TDname"))); arrHead[i++] += (((pRecTd->GetCollect(_T("DESN")).vt == VT_NULL) ? _T("") : (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("DESN")))); arrHead[i++] += ((LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("Sname"))); szSql.Empty(); szSql.Format(_T("select Clabel from cm where Cname = 'Stype' and Lang = %d and Cvalue = %s"), g_iLanguage, pRecTd->GetCollect(_T("Stype")).vt == VT_NULL ? _T("-1") : (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("Stype"))); pRecCm->Open(szSql.AllocSysString(), _variant_t((IDispatch*)m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText); if ((long)0 != pRecCm->GetRecordCount()) { arrHead[i++] += (((LPCTSTR)(_bstr_t)pRecCm->GetCollect(_T("Clabel")))); } pRecCm->Close(); szSql.Empty(); szSql.Format(_T("select Clabel from cm where Cname = 'Ttype' and Lang = %d and Cvalue = %s"), g_iLanguage, pRecTd->GetCollect(_T("Ttype")).vt == VT_NULL ? _T("-1") : (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("Ttype"))); pRecCm->Open(szSql.AllocSysString(), _variant_t((IDispatch*)m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText); if ((long)0 != pRecCm->GetRecordCount()) { arrHead[i++] += (((LPCTSTR)(_bstr_t)pRecCm->GetCollect(_T("Clabel")))); } pRecCm->Close(); szSql.Empty(); szSql.Format(_T("select Clabel from cm where Cname = 'Tmode' and Lang = %d and Cvalue = %s"), g_iLanguage, pRecTd->GetCollect(_T("Tmode")).vt == VT_NULL ? _T("-1") : (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("Tmode"))); pRecCm->Open(szSql.AllocSysString(), _variant_t((IDispatch*)m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText); if ((long)0 != pRecCm->GetRecordCount()) { } pRecCm->Close(); ///////////////////////////////////加入装置类型//////////////////////////// szSql.Empty(); szSql.Format(_T("select MEname from medium where LANG = %d and AR in (select AR from tdchannel where TDID = %d)"), g_iLanguage, m_dwID); pRecCm->Open(szSql.AllocSysString(), _variant_t((IDispatch*)m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText); if ((long)VAL_ZERO != pRecCm->GetRecordCount()) { arrHead[i++] += (((LPCTSTR)(_bstr_t)pRecCm->GetCollect(_T("MEname")))); } pRecCm->Close(); ////////////////////////////////////////////////////////////////////////// arrHead[i++] += (((LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("Eamount")))); arrHead[i++] += (((LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("TPamount")))); arrHead[i++] += (((LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("CHamount")))); arrHead[i++] += (((LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("N")))); szSql.Empty(); szSql.Format(_T("select Clabel from cm where Cname = 'TRwave' and Lang = %d and Cvalue = %s"), g_iLanguage, pRecTd->GetCollect(_T("TRwave")).vt == VT_NULL ? _T("-1") : (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("TRwave"))); pRecCm->Open(szSql.AllocSysString(), _variant_t((IDispatch*)m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText); if ((long)0 != pRecCm->GetRecordCount()) { arrHead[i++] += (((LPCTSTR)(_bstr_t)pRecCm->GetCollect(_T("Clabel")))); } pRecCm->Close(); if ((0 == pRecTd->GetCollect(_T("Ttype")).iVal) || (1 == pRecTd->GetCollect(_T("Ttype")).iVal)) { szSql.Empty(); szSql.Format(_T("select Clabel from cm where Cname = 'Trfrequency' and Lang = %d and Cvalue = %s"), g_iLanguage, pRecTd->GetCollect(_T("Trfrequency")).vt == VT_NULL ? _T("-1") : (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("Trfrequency"))); pRecCm->Open(szSql.AllocSysString(), _variant_t((IDispatch*)m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText); if ((long)0 != pRecCm->GetRecordCount()) { arrHead[i++] += (((LPCTSTR)(_bstr_t)pRecCm->GetCollect(_T("Clabel")))); } pRecCm->Close(); } else if (2 == pRecTd->GetCollect(_T("Ttype")).iVal) { szSql.Empty(); szSql.Format(_T("select Clabel from cm where Cname = 'Trfrequencyself' and Lang = %d and Cvalue = %s"), g_iLanguage, pRecTd->GetCollect(_T("Trfrequency")).vt == VT_NULL ? _T("-1") : (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("Trfrequency"))); pRecCm->Open(szSql.AllocSysString(), _variant_t((IDispatch*)m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText); if ((long)0 != pRecCm->GetRecordCount()) { arrHead[i++] += (((LPCTSTR)(_bstr_t)pRecCm->GetCollect(_T("Clabel")))); } pRecCm->Close(); } szSql.Empty(); szSql.Format(_T("select Clabel from cm where Cname = 'Ifrequency' and Lang = %d and Cvalue = %s"), g_iLanguage, pRecTd->GetCollect(_T("Ifrequency")).vt == VT_NULL ? _T("-1") : (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("Ifrequency"))); pRecCm->Open(szSql.AllocSysString(), _variant_t((IDispatch*)m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText); if ((long)0 != pRecCm->GetRecordCount()) { arrHead[i++] += (((LPCTSTR)(_bstr_t)pRecCm->GetCollect(_T("Clabel")))); } pRecCm->Close(); szSql.Empty(); szSql.Format(_T("select Clabel from cm where Cname = 'Clayout' and Lang = %d and Cvalue = %s"), g_iLanguage, pRecTd->GetCollect(_T("Clayout")).vt == VT_NULL ? _T("-1") : (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("Clayout"))); pRecCm->Open(szSql.AllocSysString(), _variant_t((IDispatch*)m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText); if ((long)0 != pRecCm->GetRecordCount()) { arrHead[i++] += (((LPCTSTR)(_bstr_t)pRecCm->GetCollect(_T("Clabel")))); } pRecCm->Close(); arrHead[i++] += (((pRecTd->GetCollect(_T("Edistance")).vt == VT_NULL) ? "" : (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("Edistance")))); if (AR_MARINE == iAR) { CString strTmpSql = _T(""); strTmpSql.Format(_T("select a.* from td1dSpcAttr a, tdchannel b where a.TCHID = b.ID and b.TDID = %u"), m_dwID); pRecTdSpcAttr->Open(strTmpSql.AllocSysString(), _variant_t((IDispatch*)m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText); int iTmp = 0; CString strInfo = _T(""); if (pRecTdSpcAttr->GetRecordCount() > 0) { float fVal = 0; if (pRecTdSpcAttr->GetCollect(_T("Spacing")).vt != VT_NULL) { strInfo.Empty(); strInfo.Format(_T("%.2f"), pRecTdSpcAttr->GetCollect(_T("Spacing")).fltVal); arrHead[i++] += strInfo; } //Interval if (pRecTdSpcAttr->GetCollect(_T("PoleInterval")).vt != VT_NULL) { strInfo.Empty(); strInfo.Format(_T("%.2f"), pRecTdSpcAttr->GetCollect(_T("PoleInterval")).fltVal); arrHead[i++] += strInfo; } //DipoleNo strInfo = (pRecTdSpcAttr->GetCollect(_T("DipoleNo")).vt != VT_NULL) ? (LPCTSTR)(_bstr_t)pRecTdSpcAttr->GetCollect(_T("DipoleNo")) : _T(""); arrHead[i++] += strInfo; //RecordMode iTmp = pRecTdSpcAttr->GetCollect(_T("RecordMode")).iVal; if (iTmp > 2 || iTmp < 0) { strInfo.Empty(); if (LANG_ZHCN == g_iUILanguage) { strInfo.Format(_T("查询记录模式值无效,值= %d"), iTmp); AfxMessageBox(strInfo); } else { strInfo.Format(_T("Query recording mode value invalid, value = %d"), iTmp); MessageBoxEx(NULL, strInfo, STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)); } } else { arrHead[i++] += g_chRecMode[iTmp]; } //CurPoleDepoly iTmp = pRecTdSpcAttr->GetCollect(_T("CurPoleDepoly")).iVal; if (iTmp > 1 || iTmp < 0) { strInfo.Empty(); if (LANG_ZHCN == g_iUILanguage) { strInfo.Format(_T("查询当前孔depolyment值无效,值 = %d"), iTmp); AfxMessageBox(strInfo); } else { strInfo.Format(_T("Query current pole depolyment value invalid, value = %d"), iTmp); MessageBoxEx(NULL, strInfo, STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)); } } else { arrHead[i++] += g_chCurPoleDepoly[iTmp]; } //MovingSpeed if (pRecTdSpcAttr->GetCollect(_T("MovingSpeed")).vt != VT_NULL) { fVal = pRecTdSpcAttr->GetCollect(_T("MovingSpeed")).fltVal; strInfo.Empty(); if (fVal < 0) strInfo = _T("Auto"); else strInfo.Format(_T("%.2f m/s"), fVal); arrHead[i++] += strInfo; } //RecordDistance if (pRecTdSpcAttr->GetCollect(_T("RecordDistance")).vt != VT_NULL) { strInfo.Empty(); strInfo.Format(_T("%.2f"), pRecTdSpcAttr->GetCollect(_T("RecordDistance")).fltVal); arrHead[i++] += strInfo; } } else { if (LANG_ZHCN == g_iUILanguage) AfxMessageBox(_T("在数据库不能找到marin 信息")); else MessageBoxEx(NULL, _T("Can not found marin information in database"), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)); } pRecTdSpcAttr->Close(); } szSql.Empty(); szSql.Format(_T("select Clabel from cm where Cname = 'weather' and Lang = %d and Cvalue = %s"), g_iLanguage, pRecTd->GetCollect(_T("weather")).vt == VT_NULL ? _T("-1") : (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("weather"))); pRecCm->Open(szSql.AllocSysString(), _variant_t((IDispatch*)m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText); if ((long)0 != pRecCm->GetRecordCount()) { arrHead[i++] += (((LPCTSTR)(_bstr_t)pRecCm->GetCollect(_T("Clabel")))); } pRecCm->Close(); szSql.Empty(); szSql.Format(_T("select Clabel from cm where Cname = 'WDIR' and Lang = %d and Cvalue = %s"), g_iLanguage, pRecTd->GetCollect(_T("WDIR")).vt == VT_NULL ? _T("-1") : (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("WDIR"))); pRecCm->Open(szSql.AllocSysString(), _variant_t((IDispatch*)m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText); if ((long)0 != pRecCm->GetRecordCount()) { arrHead[i++] += (((LPCTSTR)(_bstr_t)pRecCm->GetCollect(_T("Clabel")))); } pRecCm->Close(); CString strTmp = _T(""); float fTmp = (pRecTd->GetCollect(_T("temperature")).vt == VT_NULL) ? -9999 : (float)pRecTd->GetCollect(_T("temperature")).fltVal; if (fTmp > -9000) { strTmp.Format(_T("%f"), fTmp); } arrHead[i++] += strTmp; arrHead[i++] += (((pRecTd->GetCollect(_T("height")).vt == VT_NULL) ? _T("") : (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("height")))); strTmp.Empty(); fTmp = (pRecTd->GetCollect(_T("humidity")).vt == VT_NULL) ? -9999 : (float)pRecTd->GetCollect(_T("humidity")).fltVal; if (fTmp > -9000) { strTmp.Format(_T("%f"), fTmp); } arrHead[i++] += strTmp; arrHead[i++] += (((LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("Cdate")))); arrHead[i++] += (((LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("Ctime")))); arrHead[i++] += (((pRecTd->GetCollect(_T("Tdate")).vt == VT_NULL) ? _T("") : (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("Tdate")))); arrHead[i++] += (((pRecTd->GetCollect(_T("Ttime")).vt == VT_NULL) ? _T("") : (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("Ttime")))); //这个不用加 szSql.Empty(); szSql.Format(_T("select Clabel from cm where Cname = 'Rdirection' and Lang = %d and Cvalue = %s"), g_iLanguage, pRecTd->GetCollect(_T("Rdirection")).vt == VT_NULL ? _T("-1") : (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("Rdirection"))); pRecCm->Open(szSql.AllocSysString(), _variant_t((IDispatch*)m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText); if ((long)0 != pRecCm->GetRecordCount()) { } pRecCm->Close(); arrHead[i++] += (((pRecTd->GetCollect(_T("OP")).vt == VT_NULL) ? _T("") : (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("OP")))); arrHead[i++] += (((pRecTd->GetCollect(_T("QA")).vt == VT_NULL) ? _T("") : (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("QA")))); } pRecTd->Close(); for (int j = 0; j < arrHead.GetCount(); j++) { arrHead[j] += "\n"; fwrite(arrHead[j], 1, arrHead[j].GetLength(), pFile); } fflush(pFile); return TRUE; } BOOL CRspCETd::SaveTdConToCsvFile(FILE* pFile, CString basename) { _RecordsetPtr pRecConList = NULL; CString szSql = _T(""); CString szRow = _T(""); FILE* pCsvDataFile = fopen(basename + "-Data.csv", "w+"); if (NULL == pCsvDataFile) { CString str = _T(""); if (LANG_ZHCN == g_iUILanguage) { str.Format(_T("无法构建csv应用程序!错误码 %d"), GetLastError()); AfxMessageBox(str); } else { str.Format(_T("Can't build csv application!,err = %d"), GetLastError()); MessageBoxEx(NULL, str, STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)); } return FALSE; } pRecConList.CreateInstance(_uuidof(Recordset)); szSql.Empty(); szSql.Format(_T("select a,b,x,y,N,K,I,V,R0,SP,bUse,R0_LC,M0_LC,POINT_NUM from td1dcon where TEST_FLAG = 1 and TCHID in (select ID from tdchannel where TDID = %u order by TCHID) order by TSN"), m_dwID); try { pRecConList->Open(szSql.AllocSysString(), _variant_t((IDispatch*)m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText); } catch (_com_error e) { hHook = SetWindowsHookEx(WH_CBT, (HOOKPROC)CBTHookProc, AfxGetInstanceHandle(), NULL); AfxMessageBox((LPCTSTR)e.Description()); } int iIndex = (int)0; iIndex = 1; szRow.Empty(); if (pRecConList->GetCollect(_T("POINT_NUM")).iVal >= 0) szRow = _T("Point Num,"); szRow += ((_T("a"))); szRow += ','; szRow += ((_T("b"))); szRow += ','; szRow += ((_T("x"))); szRow += ','; szRow += ((_T("y"))); szRow += ','; szRow += ((_T("Stacking"))); szRow += ','; szRow += ((_T("K"))); szRow += ','; szRow += ((_T("I(mA)"))); szRow += ','; szRow += ((_T("V(mV)"))); szRow += ','; szRow += ((_T("R"))); szRow += ','; szRow += ((_T("R0"))); szRow += ','; szRow += ((_T("SP"))); szRow += ','; szRow += ((_T("R0_RD"))); szRow += "\n"; fwrite(szRow, 1, szRow.GetLength(), pFile); fflush(pFile); fwrite(szRow, 1, szRow.GetLength(), pCsvDataFile); fflush(pCsvDataFile); float fV = 0, fI = 0, fR = 0; CString strText = _T(""); while ((short)0 == pRecConList->adoEOF) { if (pRecConList->GetCollect(_T("bUse")).boolVal != 0)//0为access数据库中的false { iIndex++; szRow.Empty(); if (pRecConList->GetCollect(_T("POINT_NUM")).iVal >= 0) szRow += (((LPCTSTR)(_bstr_t)pRecConList->GetCollect(_T("POINT_NUM")))), szRow += ','; szRow += (((LPCTSTR)(_bstr_t)pRecConList->GetCollect(_T("a")))); szRow += ','; szRow += (((LPCTSTR)(_bstr_t)pRecConList->GetCollect(_T("b")))); szRow += ','; szRow += (((LPCTSTR)(_bstr_t)pRecConList->GetCollect(_T("x")))); szRow += ','; szRow += (((LPCTSTR)(_bstr_t)pRecConList->GetCollect(_T("y")))); szRow += ','; szRow += (((LPCTSTR)(_bstr_t)pRecConList->GetCollect(_T("N")))); szRow += ','; strText.Empty(); strText.Format(_T("%f"), pRecConList->GetCollect(_T("K")).fltVal); szRow += strText; szRow += ','; strText.Empty(); strText.Format(_T("%f"), pRecConList->GetCollect(_T("I")).fltVal); szRow += strText; szRow += ','; strText.Empty(); strText.Format(_T("%f"), pRecConList->GetCollect(_T("V")).fltVal); szRow += strText; szRow += ','; //添加R fV = (float)pRecConList->GetCollect(_T("V")).fltVal; fI = (float)pRecConList->GetCollect(_T("I")).fltVal; fR = (0 == fI) ? 0 : fV / fI; strText.Empty(); strText.Format(_T("%f"), fR); szRow += strText; szRow += ','; strText.Empty(); strText.Format(_T("%f"), pRecConList->GetCollect(_T("R0")).fltVal); szRow += strText; szRow += ','; strText.Empty(); strText.Format(_T("%f"), pRecConList->GetCollect(_T("SP")).fltVal); szRow += strText; szRow += ','; strText.Empty(); strText.Format(_T("%f%%"), pRecConList->GetCollect(_T("R0_LC")).fltVal); szRow += strText; szRow += "\n"; fwrite(szRow, 1, szRow.GetLength(), pFile); fwrite(szRow, 1, szRow.GetLength(), pCsvDataFile); } pRecConList->MoveNext(); } pRecConList->Close(); fflush(pFile); fflush(pCsvDataFile); fclose(pCsvDataFile); return TRUE; } BOOL CRspCETd::ExportResDataToTxt(CString strFileName) { COperTxtFile operTxtFile; if (!operTxtFile.OpenFileforWrite(strFileName)) { return FALSE; } _RecordsetPtr pRecConList = NULL; pRecConList.CreateInstance(_uuidof(Recordset)); CString szSql = _T(""); CStringArray strArrTxt; strArrTxt.RemoveAll(); strArrTxt.Add(_T("a")); strArrTxt.Add(_T("b")); strArrTxt.Add(_T("x")); strArrTxt.Add(_T("y")); strArrTxt.Add(_T("Stacking")); strArrTxt.Add(_T("K")); strArrTxt.Add(_T("V(mV)")); strArrTxt.Add(_T("I(mA)")); strArrTxt.Add(_T("R(Ohm)")); strArrTxt.Add(_T("R0")); strArrTxt.Add(_T("SP")); strArrTxt.Add(_T("R0_RD")); szSql.Empty(); szSql.Format(_T("select a,b,x,y,N,K,I,V,R0,SP,bUse,R0_LC,M0_LC from td1dcon where TCHID in (select ID from tdchannel where TDID = %u order by TCHID) order by TSN"), m_dwID); try { pRecConList->Open(szSql.AllocSysString(), _variant_t((IDispatch*)m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText); } catch (_com_error e) { hHook = SetWindowsHookEx(WH_CBT,(HOOKPROC)CBTHookProc,AfxGetInstanceHandle(),NULL); AfxMessageBox((LPCTSTR)e.Description()); operTxtFile.CloseFile(); return FALSE; } if (!operTxtFile.WriteFileContent(strArrTxt)) { operTxtFile.CloseFile(); return FALSE; } CString strText; float fV = 0, fI = 0, fR = 0; while ((short)0 == pRecConList->adoEOF) { if (pRecConList->GetCollect(_T("bUse")).boolVal != 0)//0为access数据库中的false { strArrTxt.RemoveAll(); strArrTxt.Add((LPCTSTR)(_bstr_t)pRecConList->GetCollect(_T("a"))); strArrTxt.Add((LPCTSTR)(_bstr_t)pRecConList->GetCollect(_T("b"))); strArrTxt.Add((LPCTSTR)(_bstr_t)pRecConList->GetCollect(_T("x"))); strArrTxt.Add((LPCTSTR)(_bstr_t)pRecConList->GetCollect(_T("y"))); strArrTxt.Add((LPCTSTR)(_bstr_t)pRecConList->GetCollect(_T("N"))); strText.Empty(); strText.Format(_T("%f"),pRecConList->GetCollect(_T("K")).fltVal); strArrTxt.Add(strText); strText.Empty(); strText.Format(_T("%f"),pRecConList->GetCollect(_T("V")).fltVal); strArrTxt.Add(strText); strText.Empty(); strText.Format(_T("%f"),pRecConList->GetCollect(_T("I")).fltVal); strArrTxt.Add(strText); //添加R fV = (float)pRecConList->GetCollect(_T("V")).fltVal; fI = (float)pRecConList->GetCollect(_T("I")).fltVal; fR = (0 == fI) ? 0 : fV/fI; strText.Empty(); strText.Format(_T("%f"),fR); strArrTxt.Add(strText); strText.Empty(); strText.Format(_T("%f"),pRecConList->GetCollect(_T("R0")).fltVal); strArrTxt.Add(strText); strText.Empty(); strText.Format(_T("%f"),pRecConList->GetCollect(_T("SP")).fltVal); strArrTxt.Add(strText); strText.Empty(); strText.Format(_T("%f%%"),pRecConList->GetCollect(_T("R0_LC")).fltVal); strArrTxt.Add(strText); if (!operTxtFile.WriteFileContent(strArrTxt)) { operTxtFile.CloseFile(); return FALSE; } } pRecConList->MoveNext(); } pRecConList->Close(); operTxtFile.CloseFile(); return TRUE; } BOOL CRspCETd::SaveTdToResCEFile(CString f_szFileName) { long lRet = VAL_ZERO; int iListIndex = (int)VAL_ZERO; CString szSql = _T(""); CString szCaption = _T(""); UINT uExecCode = (UINT)APP_SUCCESS; CSaveInRes* pSaveInRes = NULL; CString szFilePath = _T(""); CString szFileName = _T(""); CString szFile = _T(""); CStringArray saRecord; CString szTdName = _T(""); CString szTdCN = _T(""); CString szDESN = _T(""); CString szEDistance = _T(""); CString szAr = _T(""); CString szTPAmount = _T(""); CString szTType = _T(""); CString szA = _T(""); CString szB = _T(""); CString szM = _T(""); CString szN = _T(""); CString szR0 = _T(""); CString szDistance = _T(""); CString szElevation = _T(""); DWORD dwChID = (DWORD)VAL_ZERO; _RecordsetPtr pRecTd = NULL; _RecordsetPtr pRecCh = NULL; _RecordsetPtr pRecTdCon = NULL; pRecTd.CreateInstance(_uuidof(Recordset)); pRecCh.CreateInstance(_uuidof(Recordset)); pRecTdCon.CreateInstance(_uuidof(Recordset)); int iAR = 0; szSql.Empty(); szSql.Format(_T("select ID,AR from tdchannel where TDID = %u and CHnumber = 1"), this->m_dwID); pRecCh->Open(szSql.AllocSysString(), _variant_t((IDispatch*)m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText); if ((long)VAL_ZERO != pRecCh->GetRecordCount()) { dwChID = pRecCh->GetCollect(_T("ID")).ulVal; iAR = pRecCh->GetCollect(_T("AR")).iVal; if (17 != iAR && 34 != iAR) //17:4p_ves 34: marine { if (LANG_ZHCN == g_iUILanguage) AfxMessageBox(_T("4极装置和水上测量装置,才支持导出DAT文件!")); else MessageBoxEx(NULL, _T("Only support export 4P-VES and Marine/Water data to dat."), STRING_MESSAGEBOXEX_TITLE, MB_OK, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)); pRecCh->Close(); return false; } szAr = (LPCTSTR)(_bstr_t)pRecCh->GetCollect(_T("AR")); } pRecCh->Close(); if (iAR == 34) { return SaveMarineTdToResCEFile(f_szFileName, dwChID); } szSql.Empty(); szSql.Format(_T("select TDname,TdCN,DESN,Ttype,Edistance,TPamount from td where ID = %u"), this->m_dwID); pRecTd->Open(szSql.AllocSysString(), _variant_t((IDispatch*)m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText); if ((long)VAL_ZERO != pRecTd->GetRecordCount()) { szTdName = (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("TDname")); // szTdCN = (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("TdCN")); szDESN = (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("DESN")); szTType = (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("Ttype")); szEDistance = (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("Edistance")); // szTPAmount = (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("TPamount")); } pRecTd->Close(); szFilePath.Empty(); szFilePath.GetBufferSetLength(256); ::GetCurrentDirectory(szFilePath.GetLength(), szFilePath.GetBuffer(szFilePath.GetLength())); szFilePath.ReleaseBuffer(); szFilePath = szFilePath + _T("\\DAT\\"); szFileName = szTdName + _T(".dat"); szFile = szFilePath + szFileName; pSaveInRes = new CSaveInRes; if (!pSaveInRes->CreateResFile(f_szFileName)) { return FALSE; } szSql.Empty(); szSql.Format(_T("select a,b,R0,bUse from td1dcon where TCHID = %u and bUse <> 0"), dwChID); pRecTdCon->Open(szSql.AllocSysString(), _variant_t((IDispatch*)m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText); ////////////////////////////////////////////////////////////////////////// saRecord.RemoveAll(); saRecord.Add(szTdName); //文件名 saRecord.Add("Schlumberger"); //装置名称 szTPAmount.Empty(); szTPAmount.Format(_T("%d"), pRecTdCon->GetRecordCount()); saRecord.Add(szTPAmount); saRecord.Add("No"); pSaveInRes->AddFileHeader(Res, atoi(szAr.GetBuffer(0)), &saRecord); pSaveInRes->InitCEFileHeader(&saRecord); ////////////////////////////////////////////////////////////////////////// while ((short)VAL_ZERO == pRecTdCon->adoEOF) { if (pRecTdCon->GetCollect(_T("bUse")).boolVal != 0)//0为access数据库中的false { szR0.Empty(); float fR0 = (float)pRecTdCon->GetCollect(_T("R0")).fltVal; szR0.Format(_T("%f"),fR0); szA.Empty(); szA = (LPCTSTR)(_bstr_t)pRecTdCon->GetCollect(_T("a")); szB.Empty(); szB = (LPCTSTR)(_bstr_t)pRecTdCon->GetCollect(_T("b")); saRecord.RemoveAll(); saRecord.Add(szA); saRecord.Add(szB); saRecord.Add(szR0); pSaveInRes->AddDateToFile(&saRecord); } pRecTdCon->MoveNext(); } pRecTdCon->Close(); saRecord.RemoveAll(); saRecord.Add("NO"); pSaveInRes->AddCEModel(&saRecord); pSaveInRes->CloseFile(); return TRUE; } void CRspCETd::SetMarineParams() { long lRet = VAL_ZERO; COpRspCEMarineSettingDlg* pSettingDlg = new COpRspCEMarineSettingDlg(); pSettingDlg->Create(IDD_MARINE_PARAMS_DLG, AfxGetMainWnd()); pSettingDlg->ShowWindow(SW_SHOW); lRet = pSettingDlg->RunModalLoop(MLF_SHOWONIDLE); // 开始非模态窗口模态循环 if (RET_OK == lRet) { int s = 11111111111; } pSettingDlg->DestroyWindow(); delete pSettingDlg; } BOOL CRspCETd::SaveMarineTdToResCEFile(CString f_szFileName, DWORD dwChID) { long lRet = VAL_ZERO; int iListIndex = (int)VAL_ZERO; CString szSql = _T(""); CString szCaption = _T(""); UINT uExecCode = (UINT)APP_SUCCESS; CSaveInRes* pSaveInRes = NULL; CString szFilePath = _T(""); CString szFileName = _T(""); CString szFile = _T(""); CStringArray saRecord; CString szTdName = _T(""); CString szTdCN = _T(""); CString szDESN = _T(""); CString szEDistance = _T(""); CString szAr = _T("34"); CString szTPAmount = _T(""); CString szTType = _T(""); CString szA = _T(""); CString szB = _T(""); CString szM = _T(""); CString szN = _T(""); CString szR0 = _T(""); CString szDistance = _T(""); CString szElevation = _T(""); SetMarineParams(); _RecordsetPtr pRecTd = NULL; _RecordsetPtr pRecTdCon = NULL; pRecTd.CreateInstance(_uuidof(Recordset)); pRecTdCon.CreateInstance(_uuidof(Recordset)); szSql.Empty(); szSql.Format(_T("select TDname,TdCN,DESN,Ttype,Edistance,TPamount from td where ID = %u"), this->m_dwID); pRecTd->Open(szSql.AllocSysString(), _variant_t((IDispatch*)m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText); if ((long)VAL_ZERO != pRecTd->GetRecordCount()) { szTdName = (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("TDname")); // szTdCN = (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("TdCN")); szDESN = (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("DESN")); szTType = (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("Ttype")); szEDistance = (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("Edistance")); // szTPAmount = (LPCTSTR)(_bstr_t)pRecTd->GetCollect(_T("TPamount")); } pRecTd->Close(); szFilePath.Empty(); szFilePath.GetBufferSetLength(256); ::GetCurrentDirectory(szFilePath.GetLength(), szFilePath.GetBuffer(szFilePath.GetLength())); szFilePath.ReleaseBuffer(); szFilePath = szFilePath + _T("\\DAT\\"); szFileName = szTdName + _T(".dat"); szFile = szFilePath + szFileName; pSaveInRes = new CSaveInRes; if (!pSaveInRes->CreateResFile(f_szFileName)) { return FALSE; } szSql.Empty(); szSql.Format(_T("select a,b,R0,bUse from td1dcon where TCHID = %u and bUse <> 0"), dwChID); pRecTdCon->Open(szSql.AllocSysString(), _variant_t((IDispatch*)m_pConnection, true), adOpenStatic, adLockOptimistic, adCmdText); ////////////////////////////////////////////////////////////////////////// saRecord.RemoveAll(); saRecord.Add(szTdName); //文件名 saRecord.Add("Schlumberger"); //装置名称 szTPAmount.Empty(); szTPAmount.Format(_T("%d"), pRecTdCon->GetRecordCount()); saRecord.Add(szTPAmount); saRecord.Add("No"); pSaveInRes->AddFileHeader(Res, atoi(szAr.GetBuffer(0)), &saRecord); pSaveInRes->InitCEFileHeader(&saRecord); ////////////////////////////////////////////////////////////////////////// while ((short)VAL_ZERO == pRecTdCon->adoEOF) { if (pRecTdCon->GetCollect(_T("bUse")).boolVal != 0)//0为access数据库中的false { szR0.Empty(); float fR0 = (float)pRecTdCon->GetCollect(_T("R0")).fltVal; szR0.Format(_T("%f"), fR0); szA.Empty(); szA = (LPCTSTR)(_bstr_t)pRecTdCon->GetCollect(_T("a")); szB.Empty(); szB = (LPCTSTR)(_bstr_t)pRecTdCon->GetCollect(_T("b")); saRecord.RemoveAll(); saRecord.Add(szA); saRecord.Add(szB); saRecord.Add(szR0); pSaveInRes->AddDateToFile(&saRecord); } pRecTdCon->MoveNext(); } pRecTdCon->Close(); saRecord.RemoveAll(); saRecord.Add("NO"); pSaveInRes->AddCEModel(&saRecord); pSaveInRes->CloseFile(); return TRUE; }