📄 query.cpp
字号:
// Query.cpp : 实现文件
//
#include "stdafx.h"
#include "MyZone.h"
#include "Query.h"
#include ".\query.h"
// CQuery 对话框
IMPLEMENT_DYNAMIC(CQuery, CPropertyPage)
CQuery::CQuery()
: CPropertyPage(CQuery::IDD)
, m_Qname(_T(""))
{
}
CQuery::~CQuery()
{
}
void CQuery::DoDataExchange(CDataExchange* pDX)
{
CPropertyPage::DoDataExchange(pDX);
DDX_Control(pDX, IDC_LIST1, m_List);
DDX_Text(pDX, IDC_EDIT1, m_Qname);
}
BEGIN_MESSAGE_MAP(CQuery, CPropertyPage)
ON_BN_CLICKED(IDC_BUTTON1, OnBnClickedButton1)
END_MESSAGE_MAP()
// CQuery 消息处理程序
void CQuery::OnBnClickedButton1()
{
// TODO: 在此添加控件通知处理程序代码
//theApp.m_pRecordsetbook->Close();
UpdateData(TRUE);
CString str;
_variant_t var;
CString strisbn,strbookname,strauthor,strpublish;
str.Format ("SELECT * FROM Book where Book_Name = '%s'",m_Qname );
try
{
theApp.m_pRecordsetbook1->Open((LPCTSTR)str,
theApp.m_pConnection.GetInterfacePtr(),
adOpenDynamic,
adLockOptimistic,
adCmdText);
}
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
}
if(theApp.m_pRecordsetbook1->adoEOF)
{
MessageBox("对不起,没有找到你要查找的信息!");
theApp.m_pRecordsetbook1->Close();
return;
}
else
{
// 清空列表框
m_List.ResetContent();
strisbn=strbookname=strauthor=strpublish="";
try
{
theApp.m_pRecordsetbook1->MoveFirst();
// 读入库中各字段并加入列表框中
while(!theApp.m_pRecordsetbook1->adoEOF)
{
var = theApp.m_pRecordsetbook1->GetCollect("ISBN");//collect收集、聚焦
if(var.vt != VT_NULL)
strisbn = (LPCSTR)_bstr_t(var);
var = theApp.m_pRecordsetbook1->GetCollect("Book_Name");
if(var.vt != VT_NULL)
strbookname = (LPCSTR)_bstr_t(var);
var = theApp.m_pRecordsetbook1->GetCollect("Author");
if(var.vt != VT_NULL)
strauthor = (LPCSTR)_bstr_t(var);
var = theApp.m_pRecordsetbook1->GetCollect("Publish");
if(var.vt != VT_NULL)
strpublish = (LPCSTR)_bstr_t(var);
m_List.AddString( strisbn + " --> "+strbookname + " --> "+strauthor + " --> "+strpublish);
theApp.m_pRecordsetbook1->MoveNext();
}
if(theApp.m_pRecordsetbook1->State)
theApp.m_pRecordsetbook1->Close();
}
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
}
}
}
//void CQuery::OnReadAccess1(void)
//{
// UpdateData(TRUE);
// _variant_t var;
// CString strisbn,strbookname,strauthor,strpublish;
//
// // 清空列表框
// m_List.ResetContent();
// strisbn=strbookname=strauthor=strpublish="";
//
// try
// {
// if( !theApp.m_pRecordsetbook->BOF )
// {
// theApp.m_pRecordsetbook->MoveFirst();
// }
// else
// {
// AfxMessageBox("没有您要找的书!");
// return;
// }
//
// // 读入库中各字段并加入列表框中
// while(!theApp.m_pRecordsetbook->adoEOF)
// {
// var = theApp.m_pRecordsetbook->GetCollect("ISBN");//collect收集、聚焦
// if(var.vt != VT_NULL)
// strisbn = (LPCSTR)_bstr_t(var);
// var = theApp.m_pRecordsetbook->GetCollect("Book_Name");
// if(var.vt != VT_NULL)
// strbookname = (LPCSTR)_bstr_t(var);
// var = theApp.m_pRecordsetbook->GetCollect("Author");
// if(var.vt != VT_NULL)
// strauthor = (LPCSTR)_bstr_t(var);
// var = theApp.m_pRecordsetbook->GetCollect("Publish");
// if(var.vt != VT_NULL)
// strpublish = (LPCSTR)_bstr_t(var);
//
// m_List.AddString( strisbn + " --> "+strbookname + " --> "+strauthor + " --> "+strpublish);
//
// theApp.m_pRecordsetbook->MoveNext();
// }
// //if(theApp.m_pRecordsetbook->State)
// // theApp.m_pRecordsetbook->Close();
// }
// catch(_com_error *e)
// {
// AfxMessageBox(e->ErrorMessage());
// }
//}
//BOOL CQuery::DestroyWindow()
//{
// // TODO: 在此添加专用代码和/或调用基类
// theApp.m_pRecordsetbook->Close();
// theApp.m_pRecordsetbook = NULL;
//
// return CPropertyPage::DestroyWindow();
//}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -