?? servicelist.cpp
字號:
// GWInfo.cpp: implementation of the CGWInfo class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "servicelist.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CServiceInfo::CServiceInfo()
{
m_tmLast=CTime(2004,1,1,1,1,1,-1);
}
CServiceInfo::~CServiceInfo()
{
}
int CServiceInfo::GetServiceInfo(LPSERVICEINFO pInfo)
{
CString szMsg;
CTimeSpan span(CTime::GetCurrentTime()-m_tmLast);
if (span.GetTotalSeconds()>=24*60*60)
{
m_SectKey.Lock();
if (CTimeSpan(CTime::GetCurrentTime()-m_tmLast).GetTotalSeconds()>=24*60*60)
Update(szMsg);
m_SectKey.Unlock();
}
list<SERVICEINFO>::iterator key;
for (key=m_KeyList.begin(); key!=m_KeyList.end(); key++)
{
if ((*key).szGWID.CompareNoCase(pInfo->szGWID)==0 && (*key).nType==pInfo->nType)
{
*pInfo=(*key);
return 0;
}
}
return -1;
}
int CServiceInfo::Reflesh(CString& szMsg)
{
m_SectKey.Lock();
int nRet=Update(szMsg);
m_SectKey.Unlock();
return nRet;
}
int CServiceInfo::Update(CString& szMsg)
{
TCHAR szPath[_MAX_PATH];
LPTSTR pTmp=NULL;
GetModuleFileName(NULL, szPath, _MAX_PATH);
pTmp=strrchr(szPath, '\\');
szPath[pTmp-szPath+1]='\0';
lstrcat(szPath, "TYDZ.udl");
CString szCmd;
szCmd.Format("File Name=%s", szPath);
try
{
_ConnectionPtr pConn;
CoInitialize(NULL);
pConn.CreateInstance(__uuidof(Connection));
pConn->Open(_bstr_t(szCmd), L"", L"", -1);
_CommandPtr pCmd;
pCmd.CreateInstance(__uuidof(Command));
pCmd->ActiveConnection=pConn;
pCmd->CommandText = L"sp_getservicelist";
pCmd->CommandType = adCmdStoredProc;
pCmd->Parameters->Refresh();
_RecordsetPtr pRs=pCmd->Execute(NULL, NULL, adCmdStoredProc);
if (pRs->GetState() != adStateClosed && !pRs->adoEOF)
{
while (!m_KeyList.empty())
m_KeyList.pop_back();
while (!pRs->adoEOF)
{
SERVICEINFO info;
info.szGWID=(LPTSTR)_bstr_t(pRs->GetCollect(L"gwid"));
info.szService=(LPTSTR)_bstr_t(pRs->GetCollect(L"serviceid"));
info.szService2=(LPTSTR)_bstr_t(pRs->GetCollect(L"serviceid2"));
info.szFeeType=(LPTSTR)_bstr_t(pRs->GetCollect(L"ftype"));
info.szFeeCode=(LPTSTR)_bstr_t(pRs->GetCollect(L"fcode"));
info.nType=(long)pRs->GetCollect(L"type");
m_KeyList.push_back(info);
pRs->MoveNext();
}
}
if (pRs->GetState() != adStateClosed)
pRs->Close();
pConn->Close();
pConn.Release();
CoUninitialize();
}
catch (_com_error& e)
{
szMsg.Format("Reflesh the gateways' information error. ERROR=%s", (LPTSTR)e.Description());
return -1;
}
catch (...)
{
szMsg.Format("Reflesh the gateways' information error. ERROR=UNKNOWN ERROR!");
return -2;
}
m_tmLast=CTime::GetCurrentTime();
return 0;
}
/*
int CServiceInfo::UpdateKey(LPGWKEY pKey)
{
POSITION p=NULL;
list<GWKEY>::iterator key;
// for (POSITION pos=m_KeyList.GetHeadPosition(); pos!=NULL; )
for (key=m_KeyList.begin(); key!=m_KeyList.end(); ++key)
{
// p=pos;
// GWKEY key=m_KeyList.GetNext(pos);
if ((*key).szGWID.CompareNoCase(pKey->szGWID)==0 &&
(*key).szKey.CompareNoCase(pKey->szKey)==0)
{
// m_SectKey.Lock();
// m_KeyList.SetAt(p, *pKey);
(*key)=*pKey;
// m_SectKey.Unlock();
return 0;
}
}
// m_SectKey.Lock();
// m_KeyList.AddTail(*pKey);
m_KeyList.push_back(*pKey);
// m_SectKey.Unlock();
return 0;
}*/
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -