📄 readerquery.cpp
字号:
// ReaderQuery.cpp : implementation file
//
#include "stdafx.h"
#include "Library.h"
#include "ReaderQuery.h"
#include "_recordset.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
///////////////////////////////////////////////////////////////////////////
// CReaderQuery dialog
CReaderQuery::CReaderQuery(CWnd* pParent /*=NULL*/)
: CDialog(CReaderQuery::IDD, pParent)
{
//{{AFX_DATA_INIT(CReaderQuery)
m_EditQuery = _T("");
m_Aut = _T("");
m_CDate = _T("");
m_CNum = 0;
m_Name = _T("");
m_No = _T("");
m_PDate = _T("");
m_Pre = _T("");
m_Status = _T("");
m_About = _T("");
//}}AFX_DATA_INIT
}
void CReaderQuery::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CReaderQuery)
DDX_Control(pDX, IDC_COMBO2, m_Combo2);
DDX_Control(pDX, IDC_COMBO1, m_Combo);
DDX_Text(pDX, IDC_EDIT_QUERY, m_EditQuery);
DDX_Control(pDX, IDC_ADODC1, m_ado);
DDX_Control(pDX, IDC_DATAGRID1, m_datagrid);
DDX_Text(pDX, IDC_EDIT_AUT, m_Aut);
DDX_Text(pDX, IDC_EDIT_CDATE, m_CDate);
DDX_Text(pDX, IDC_EDIT_CNUM, m_CNum);
DDX_Text(pDX, IDC_EDIT_NAME, m_Name);
DDX_Text(pDX, IDC_EDIT_NO, m_No);
DDX_Text(pDX, IDC_EDIT_PDATE, m_PDate);
DDX_Text(pDX, IDC_EDIT_PRE, m_Pre);
DDX_Text(pDX, IDC_EDIT_STATUS, m_Status);
DDX_Text(pDX, IDC_EDITABOUT, m_About);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CReaderQuery, CDialog)
//{{AFX_MSG_MAP(CReaderQuery)
ON_BN_CLICKED(IDC_BTN_QUERY, OnBtnQuery)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CReaderQuery message handlers
BOOL CReaderQuery::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
((CButton *)GetDlgItem(IDC_RADIO6))->SetCheck(TRUE);//选上
m_Combo.SetCurSel(1);
//m_datagrid.SetRefDataSource(NULL);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CReaderQuery::OnBtnQuery()
{
// TODO: Add your control notification handler code here
UpdateData(true);
int index;
CString strCom,vSQL;
vSQL = "Select BNo As 书号, BName As 书名, Type As 类型,Status As 状态,Author As 作者,Press As 出版社 ";
vSQL += " From Book Where ";
if (((CButton *)GetDlgItem(IDC_RADIO6))->GetCheck() == 1)
{
strCom = m_EditQuery + "%";
}
else
{
strCom = "%" + m_EditQuery + "%";
}
index = m_Combo.GetCurSel();
switch (index)
{
case 0:
vSQL = vSQL + "BNo like '" +strCom + "'";
break;
case 1:
vSQL = vSQL + "BName like '" +strCom + "'";
break;
case 2:
if (m_EditQuery == "1")
strCom = "社会科学";
else if (m_EditQuery == "2")
strCom = "自然科学";
else if (m_EditQuery == "3")
strCom = "艺术类";
else if (m_EditQuery == "4")
strCom = "综合类";
else
strCom = "";
vSQL = vSQL + "Type='" +strCom + "'";
break;
case 3:
vSQL = vSQL + "Author like '" +strCom + "'";
break;
case 4:
vSQL = vSQL + "Press like '" +strCom + "'";
break;
}
m_ado.SetRecordSource(vSQL); //刷新ADO Data控件的记录源
m_ado.Refresh();
int i = (int)m_datagrid.GetApproxCount();
strCom.Format("命中项为: %d",i);
GetDlgItem(IDC_NUM)->SetWindowText(strCom);
RefreshData();
UpdateData(false);
}
void CReaderQuery::RefreshData()
{
if (m_ado.GetRecordset().GetEof()==1)
{
MessageBox("没有找到你所要的记录!请重来!");
return;
}
book.GetData(m_datagrid.GetItem(0));
m_No = book.GetNo();
m_Name = book.GetName();
m_Status = book.GetStatus();
m_Aut = book.GetAuthor();
m_PDate = book.GetPublicDate();
m_CDate = book.GetComeInDate();
m_About = book.GetAbout();
m_Pre = book.GetPress();
m_CNum = book.GetCopyNum();
CString type;
type = book.GetType();
if(type == "社会科学")
{
m_Combo2.SetCurSel(0);
}
else if (type == "自然科学")
{
m_Combo2.SetCurSel(1);
}
else if (type == "艺术类")
{
m_Combo2.SetCurSel(2);
}
else
m_Combo2.SetCurSel(3);
}
BEGIN_EVENTSINK_MAP(CReaderQuery, CDialog)
//{{AFX_EVENTSINK_MAP(CReaderQuery)
ON_EVENT(CReaderQuery, IDC_DATAGRID1, 218 /* RowColChange */, OnRowColChangeDatagrid1, VTS_PVARIANT VTS_I2)
//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()
void CReaderQuery::OnRowColChangeDatagrid1(VARIANT FAR* LastRow, short LastCol)
{
// TODO: Add your control notification handler code here
RefreshData();
UpdateData(false);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -