📄 lend.cpp
字号:
// lend.cpp : implementation file
//
#include "stdafx.h"
#include "图书管理系统.h"
#include "lend.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern CMyApp theApp;
/////////////////////////////////////////////////////////////////////////////
// Clend dialog
Clend::Clend(CWnd* pParent /*=NULL*/)
: CDialog(Clend::IDD, pParent)
{
//{{AFX_DATA_INIT(Clend)
m_bid = _T("");
m_uid = _T("");
//}}AFX_DATA_INIT
}
void Clend::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(Clend)
DDX_Text(pDX, IDC_bnumber, m_bid);
DDX_Text(pDX, IDC_unumber, m_uid);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(Clend, CDialog)
//{{AFX_MSG_MAP(Clend)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// Clend message handlers
void Clend::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 Clend::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;
}
if(m_bid.IsEmpty())
{
MessageBox("请输入图书编号");
GetDlgItem(IDC_bnumber)->SetFocus();
m_bid="";
UpdateData(FALSE);
return;
}
sql.Format("select have from book where bookid='%s' and people='%s'",m_bid,m_uid);
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_bid);
connect();
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);
totle-=1;
temp.Format("%d",totle);
m_pRecordset->Close();
m_pRecordset=NULL;
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 + -