bcheck.cpp

来自「图书管理系统,主要功能有图书的借还,增加,查询等」· C++ 代码 · 共 171 行

CPP
171
字号
// bcheck.cpp : implementation file
//

#include "stdafx.h"
#include "图书管理系统.h"
#include "bcheck.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern CMyApp theApp;
/////////////////////////////////////////////////////////////////////////////
// Cbcheck dialog


Cbcheck::Cbcheck(CWnd* pParent /*=NULL*/)
	: CDialog(Cbcheck::IDD, pParent)
{
	//{{AFX_DATA_INIT(Cbcheck)
	m_id = _T("");
	m_age = _T("");
	m_name = _T("");
	//}}AFX_DATA_INIT
}


void Cbcheck::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(Cbcheck)
	DDX_Control(pDX, IDC_LIST1, m_list);
	DDX_Text(pDX, IDC_ID, m_id);
	DDX_Text(pDX, IDC_UAGE, m_age);
	DDX_Text(pDX, IDC_UNAME, m_name);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(Cbcheck, CDialog)
	//{{AFX_MSG_MAP(Cbcheck)
	ON_BN_CLICKED(IDC_CHECK, OnCheck)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// Cbcheck message handlers

void Cbcheck::OnCheck() 
{		
	UpdateData();
	if(m_id.IsEmpty())
	{
		MessageBox("请输入要查询的读者编号");
		GetDlgItem(IDC_ID)->SetFocus();
		m_id="";
		UpdateData(FALSE);
		return;
	}
	if(m_id.Compare(check))
	{
		MessageBox("您不能查询别人的纪录");
		GetDlgItem(IDC_ID)->SetFocus();
		m_id="";
		UpdateData(FALSE);
		return;
	}
	sql.Format("select readername,readerage from reader where readernumber='%s'",m_id);
	connect();
	if(!m_pRecordset->adoEOF)
	{
		var=m_pRecordset->GetCollect("readername");
		if(var.vt!=VT_NULL)
			m_name=(LPCSTR)_bstr_t(var);
		var=m_pRecordset->GetCollect("readerage");
		if(var.vt!=VT_NULL)
			m_age=(LPCSTR)_bstr_t(var);
	}
	UpdateData(FALSE);
	m_pRecordset->Close();
	m_pRecordset=NULL;
	sql.Format("select * from book where have='%s' and people='%s' order by bookid desc","已借出",m_id);
	connect();
	while(!m_pRecordset->adoEOF)
	{
		m_list.InsertItem(0,"");
		var=m_pRecordset->GetCollect("bookid");
		if(var.vt!=VT_NULL)
			m_list.SetItemText(0,0,_bstr_t(var));
		var=m_pRecordset->GetCollect("booktype");
		if(var.vt!=VT_NULL)
			m_list.SetItemText(0,1,_bstr_t(var));
		var=m_pRecordset->GetCollect("bookname");
		if(var.vt!=VT_NULL)
			m_list.SetItemText(0,2,_bstr_t(var));
		var=m_pRecordset->GetCollect("author");
		if(var.vt!=VT_NULL)
			m_list.SetItemText(0,3,_bstr_t(var));
		var=m_pRecordset->GetCollect("publisher");
		if(var.vt!=VT_NULL)
			m_list.SetItemText(0,4,_bstr_t(var));
		m_pRecordset->MoveNext();
	}
	m_pRecordset->Close();
	m_pRecordset=NULL;
		
}

BOOL Cbcheck::OnInitDialog() 
{
	CDialog::OnInitDialog();
	m_list.SetExtendedStyle(LVS_EX_FLATSB
		|LVS_EX_FULLROWSELECT
		|LVS_EX_HEADERDRAGDROP
		|LVS_EX_ONECLICKACTIVATE
		|LVS_EX_GRIDLINES);
	m_list.InsertColumn(0,"图书编号",LVCFMT_CENTER,100,0);
	m_list.InsertColumn(1,"图书类别",LVCFMT_CENTER,100,1);
	m_list.InsertColumn(2,"图书名称",LVCFMT_CENTER,250,2);
	m_list.InsertColumn(3,"作者",LVCFMT_CENTER,100,3);
	m_list.InsertColumn(4,"出版社",LVCFMT_CENTER,200,4);
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void Cbcheck::connect()
{
	m_pRecordset.CreateInstance(__uuidof(Recordset));
	try
	{
		m_pRecordset->Open(sql.AllocSysString(),
							theApp.m_pConnection.GetInterfacePtr(),	
							adOpenDynamic,
							adLockOptimistic,
							adCmdText);
	}
	catch(_com_error *e)
	{
		AfxMessageBox(e->ErrorMessage());
	}
}

void Cbcheck::read()
{
	connect();
	m_list.DeleteAllItems();
	while(!m_pRecordset->adoEOF)
	{
		m_list.InsertItem(0,"");
		var=m_pRecordset->GetCollect("bookid");
		if(var.vt!=VT_NULL)
			m_list.SetItemText(0,0,_bstr_t(var));
		var=m_pRecordset->GetCollect("booktype");
		if(var.vt!=VT_NULL)
			m_list.SetItemText(0,1,_bstr_t(var));
		var=m_pRecordset->GetCollect("bookname");
		if(var.vt!=VT_NULL)
			m_list.SetItemText(0,2,_bstr_t(var));
		var=m_pRecordset->GetCollect("author");
		if(var.vt!=VT_NULL)
			m_list.SetItemText(0,3,_bstr_t(var));
		var=m_pRecordset->GetCollect("publisher");
		if(var.vt!=VT_NULL)
			m_list.SetItemText(0,4,_bstr_t(var));
	}
	m_pRecordset->Close();
	m_pRecordset=NULL;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?