📄 teldbaccess.cpp
字号:
// TelDBAccess.cpp: implementation of the TelDBAccess class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "TelDBAccess.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
TelDBAccess::TelDBAccess()
{
}
TelDBAccess::~TelDBAccess()
{
}
/*
int TelDBAccess::startbr()
{
int intReturnCode=0;
if(!m_fConnected){
m_strErrMsg="***错误:数据库尚未连接";
return -1;
}
HRESULT hr;
_bstr_t source=m_strSource;
_bstr_t query=m_strSQL;
try{
hr=m_pRst->Open(query,source,adOpenDynamic,adLockOptimistic,adCmdText);
}
catch(_com_error e){
m_strErrMsg.Format("***错误:打开记录集出错:%s",e.ErrorMessage());
return -1;
}
intReturnCode=bindvalue();
if(intReturnCode<0)m_strErrMsg="***错误:获取表栏位值出错";
return intReturnCode;
}
int TelDBAccess::readnext()
{
int intReturnCode=0;
if(!m_fConnected){
m_strErrMsg="***错误:数据库尚未连接";
return -1;
}
try{
m_pRst->MoveNext();
}
catch(_com_error e){
m_strErrMsg.Format("***错误:记录集读取次笔出错:%s",e.ErrorMessage());
return -1;
}
intReturnCode=bindvalue();
if(intReturnCode<0)m_strErrMsg="***错误:获取表栏位值出错";
return intReturnCode;
}
int TelDBAccess::endbr()
{
if(!m_fConnected)return -1;
m_pRst->Close();
return 0;
}
int TelDBAccess::insertrec()
{
int intReturnCode=0;
if(!m_fConnected){
m_strErrMsg="***错误:数据库尚未连接";
return -1;
}
HRESULT hr;
try{
hr=m_pRst->AddNew();
intReturnCode=setvalue();
if(intReturnCode<0){
m_strErrMsg="***错误:设置表栏位值出错";
return intReturnCode;
}
hr=m_pRst->Update();
}
catch(_com_error e){
m_strErrMsg.Format("***错误:新增记录出错:%s",e.ErrorMessage());
return -1;
}
return 0;
}
int TelDBAccess::updaterec()
{
int intReturnCode=0;
HRESULT hr;
if(!m_fConnected){
m_strErrMsg="***错误:数据库尚未连接";
return -1;
}
if(m_pRst->EndOfFile){
m_strErrMsg=" 警告:记录集到尾";
return 1;
}
try{
intReturnCode=setvalue();
if(intReturnCode<0){
m_strErrMsg="***错误:设置表栏位值出错";
return intReturnCode;
}
hr=m_pRst->Update();
}
catch(_com_error e){
m_strErrMsg.Format("***错误:更新数据出错%s",e.ErrorMessage());
return -1;
}
return 0;
}
int TelDBAccess::deleterec()
{
int intReturnCode=0;
HRESULT hr;
if(!m_fConnected){
m_strErrMsg="***错误:数据库尚未连接";
return -1;
}
if(m_pRst->EndOfFile){
m_strErrMsg=" 警告:记录集到尾";
return 1;
}
try{
hr=m_pRst->Delete(adAffectCurrent);
}
catch(_com_error e){
m_strErrMsg.Format("***错误:删除数据出错:%s",e.ErrorMessage());
return -1;
}
return 0;
}
*/
int TelDBAccess::setvalue()
{
VARIANT varValue;
CString strValue;
try{
varValue.vt=VT_BSTR;
varValue.bstrVal=(_bstr_t)m_strStation;
m_pRst->PutCollect("Station",&varValue);
varValue.vt=VT_BSTR;
varValue.bstrVal=(_bstr_t)m_strTelText;
m_pRst->PutCollect("TelText",&varValue);
varValue.vt=VT_BSTR;
varValue.bstrVal=(_bstr_t)m_strOneTime;
m_pRst->PutCollect("Onetime",&varValue);
varValue.vt=VT_I2;
varValue.iVal=m_intDataSource;
m_pRst->PutCollect("DataSource1",&varValue);
varValue.vt=VT_I1;
varValue.bVal=m_bitDepartFlag;
m_pRst->PutCollect("Depart_flag",&varValue);
}
catch(_com_error e){
return -1;
}
return 0;
}
int TelDBAccess::bindvalue()
{
if(m_pRst->EndOfFile)return 1;
VARIANT varValue;
CString strValue;
try{
varValue = m_pRst->GetCollect("Telegram_id");
if(varValue.vt != VT_NULL)m_intTelID=varValue.iVal;
varValue = m_pRst->GetCollect("Station");
if(varValue.vt != VT_NULL)m_strStation=(LPCSTR)_bstr_t(varValue);
varValue = m_pRst->GetCollect("Station1");
if(varValue.vt != VT_NULL)m_strStation1=(LPCSTR)_bstr_t(varValue);
varValue = m_pRst->GetCollect("Teltext");
if(varValue.vt != VT_NULL)m_strTelText=(LPCSTR)_bstr_t(varValue);
varValue = m_pRst->GetCollect("Onetime");
if(varValue.vt != VT_NULL)m_strOneTime=(LPCSTR)_bstr_t(varValue);
varValue = m_pRst->GetCollect("DataSource1");
if(varValue.vt != VT_NULL)m_intDataSource=varValue.iVal;
varValue = m_pRst->GetCollect("Depart_flag");
if(varValue.vt != VT_NULL)m_bitDepartFlag=varValue.bVal;
varValue = m_pRst->GetCollect("Fullname");
if(varValue.vt != VT_NULL)m_strFullName=(LPCSTR)_bstr_t(varValue);
}
catch(_com_error e){
return -1;
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -