⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 borrow.cpp

📁 图书管理系统,主要功能有图书的借还,增加,查询等
💻 CPP
字号:
// borrow.cpp : implementation file
//

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

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


Cborrow::Cborrow(CWnd* pParent /*=NULL*/)
	: CDialog(Cborrow::IDD, pParent)
{
	//{{AFX_DATA_INIT(Cborrow)
	m_bid = _T("");
	m_uid = _T("");
	//}}AFX_DATA_INIT
}


void Cborrow::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(Cborrow)
	DDX_Text(pDX, IDC_bnumber, m_bid);
	DDX_Text(pDX, IDC_unumber, m_uid);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(Cborrow, CDialog)
	//{{AFX_MSG_MAP(Cborrow)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// Cborrow message handlers

void Cborrow::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 Cborrow::OnOK() 
{
	UpdateData();
	if(m_uid.IsEmpty())
	{
		MessageBox("请输入读者编号");
		GetDlgItem(IDC_unumber)->SetFocus();
		m_uid="";
		UpdateData(FALSE);
		return;
	}
	if(m_uid.Compare(check))
	{
		MessageBox("您不能使用其他读者的编号");
		GetDlgItem(IDC_unumber)->SetFocus();
		m_uid="";
		m_bid="";
		UpdateData(FALSE);
		return;
	}
	sql.Format("select totle from reader where readernumber='%s'",m_uid);
	connect();
	var=m_pRecordset->GetCollect("totle");
	if(var.vt!=VT_NULL)
		temp=(LPCSTR)_bstr_t(var);
	totle=atoi(temp);
	if(totle>=3)
	{
		MessageBox("您所借图书的数量已达到上限,不能再借");
		GetDlgItem(IDC_unumber)->SetFocus();
		m_uid="";
		m_bid="";
		UpdateData(FALSE);
		return;
	}
	totle+=1;
	temp.Format("%d",totle);
	m_pRecordset->Close();
	m_pRecordset=NULL;
	if(m_bid.IsEmpty())
	{
		MessageBox("请输入图书编号");
		GetDlgItem(IDC_bnumber)->SetFocus();
		m_bid="";
		UpdateData(FALSE);
		return;
	}
	sql.Format("select have from book where bookid='%s'",m_bid);
	connect();
	if(!m_pRecordset->adoEOF)
	{
		var=m_pRecordset->GetCollect("have");
		if(var.vt!=VT_NULL)
			record=(LPCSTR)_bstr_t(var);
	}
	else
	{
		MessageBox("输入的图书编号不存在,请重新输入");
		GetDlgItem(IDC_bnumber)->SetFocus();
		m_bid="";
		UpdateData(FALSE);
		return;
	}
	m_pRecordset->Close();
	m_pRecordset=NULL;
	if(!record.Compare("已借出"))
	{
		MessageBox("此图书已借出,请重新选择");
		GetDlgItem(IDC_bnumber)->SetFocus();
		m_bid="";
		UpdateData(FALSE);
		return;
	}
	try
	{
		sql.Format("update book set have='%s',people='%s' where bookid='%s'","已借出",m_uid,m_bid);
		connect();
		sql.Format("update reader set totle='%s' where readernumber='%s'",temp,m_uid);
		connect();
	}
	catch(_com_error *e)
		{
			AfxMessageBox(e->ErrorMessage());
		}
		MessageBox("借阅成功");
		OnCancel();
}

⌨️ 快捷键说明

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