📄 qikan.cpp
字号:
// qikan.cpp: implementation of the Cqikan class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "QKDJ.h"
#include "qikan.h"
#include "ADOConn.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
Cqikan::Cqikan()
{
m_fuben=0;
m_jiahao="";
m_kanhao="";
m_name="";
m_qici="";
m_roomid="";
m_issn="";
}
Cqikan::~Cqikan()
{
}
void Cqikan::sql_insert()
{
// 连接数据库
ADOConn m_AdoConn;
m_AdoConn.OnInitDBConnect();
// 设置INSERT语句
_bstr_t vSQL;
CString temp;
temp.Format("%d",m_fuben);
vSQL="insert into qikan(jiahao,kanhao,name,issn,qici,roomid,fuben) values";
vSQL=vSQL+"('"+m_jiahao+"','"+m_kanhao+"','"+m_name+"','"+m_issn+"','"+m_qici+"'";
vSQL=vSQL+",'"+m_roomid+"',"+temp+")";
m_AdoConn.ExecuteSQL(vSQL); // 执行INSERT语句
m_AdoConn.ExitConnect(); // 断开与数据库的连接
AfxMessageBox("插入语句执行成功!");
}
// 判断是否存在指定的刊号
int Cqikan::HaveKanhao(CString ckanhao)
{
try
{
long IRscent=0;
_RecordsetPtr m_pRecordset;
// 连接数据库
ADOConn m_AdoConn;
_bstr_t bSQL;
bSQL="select * from qikan where kanhao='"+ckanhao+"'";
// 执行SELECT语句
m_pRecordset=m_AdoConn.GetRecordSet(bSQL);
// 如果adoEOF属性为真,表示存在相同的刊号,返回1,否则返回-1
if(m_pRecordset->adoEOF)
return -1;
else
return 1;
// 断开与数据库的连接
m_AdoConn.ExitConnect();
}
catch(_com_error e)
{
AfxMessageBox(e.Description());
}
return -1;
}
void Cqikan::GetInfo(CString ckanhao)
{
// 连接数据库
ADOConn m_AdoConn;
// 设置SELECT语句
_bstr_t vSQL;
vSQL="select * from qikan where kanhao='"+ckanhao+"'";
// 执行SELECT语句
_RecordsetPtr m_pRecordset;
m_pRecordset=m_AdoConn.GetRecordSet(vSQL);
// 返回各列的值
if(m_pRecordset->adoEOF)
Cqikan();
else
{
m_fuben=atoi((LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("fuben"));
m_jiahao=(LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("jiahao");
m_kanhao=ckanhao;
m_name=(LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("name");
m_issn=(LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("issn");
m_qici=(LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("qici");
m_roomid=(LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("roomid");
if(0==m_jiahao.GetLength())
m_jiahao="";
if(0==m_kanhao.GetLength())
m_kanhao="";
if(0==m_name.GetLength())
m_name="";
if(0==m_issn.GetLength())
m_issn="";
if(0==m_qici.GetLength())
m_qici="";
if(0==m_roomid.GetLength())
m_roomid="";
int len;
len=60-m_qici.GetLength();
for(int i=1;i<=len;i++)
{
m_qici += "0";
}
}
// 断开与数据库的连接
m_AdoConn.ExitConnect();
}
void Cqikan::sql_update()
{
// 连接数据库
ADOConn m_AdoConn;
m_AdoConn.OnInitDBConnect();
// 设置UPDATE语句
_bstr_t vSQL;
CString temp;
temp.Format("%d",m_fuben);
vSQL="update qikan set jiahao='"+m_jiahao+"',name='"+m_name+"',qici='"+m_qici+"'";
vSQL=vSQL+",issn='"+m_issn+"',roomid='"+m_roomid+"',fuben="+temp+" where kanhao='"+m_kanhao+"'";
m_AdoConn.ExecuteSQL(vSQL); // 执行
m_AdoConn.ExitConnect(); // 断开与数据库的连接
AfxMessageBox("更新语句执行成功!");
}
void Cqikan::sql_delete(CString ckanhao)
{
// 连接数据库
ADOConn m_AdoConn;
m_AdoConn.OnInitDBConnect();
// 设置DELETE语句
_bstr_t vSQL;
vSQL="delete from qikan where kanhao='"+ckanhao+"'";
m_AdoConn.ExecuteSQL(vSQL); // 执行
m_AdoConn.ExitConnect(); // 断开与数据库的连接
AfxMessageBox("删除语句执行成功!");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -