📄 adminborrow.cpp
字号:
// AdminBorrow.cpp : implementation file
//
#include "stdafx.h"
#include "library.h"
#include "AdminBorrow.h"
#include "Reader.h"
#include "Book.h"
#include "Borrow.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAdminBorrow dialog
CAdminBorrow::CAdminBorrow(CWnd* pParent /*=NULL*/)
: CDialog(CAdminBorrow::IDD, pParent)
{
//{{AFX_DATA_INIT(CAdminBorrow)
m_EBNo = _T("");
m_ERNo = _T("");
//}}AFX_DATA_INIT
}
void CAdminBorrow::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAdminBorrow)
DDX_Control(pDX, IDC_DATAGRID1, m_DataGrid);
DDX_Text(pDX, IDC_EDIT_BNO, m_EBNo);
DDX_Text(pDX, IDC_EDIT_RNO, m_ERNo);
DDX_Control(pDX, IDC_ADODC1, m_Adodc);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAdminBorrow, CDialog)
//{{AFX_MSG_MAP(CAdminBorrow)
ON_BN_CLICKED(IDC_BTN_RNO, OnBtnRno)
ON_BN_CLICKED(IDC_BTN_BNO, OnBtnBno)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CAdminBorrow message handlers
BOOL CAdminBorrow::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
GetDlgItem(IDC_EDIT_BNO)->EnableWindow(false);
GetDlgItem(IDC_BTN_BNO)->EnableWindow(false);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CAdminBorrow::OnBtnRno()
{
// TODO: Add your control notification handler code here
UpdateData(true);
if (m_ERNo=="")
{
MessageBox("请输入要借书读者的ID号","借书", MB_OK|MB_ICONEXCLAMATION);
return;
}
borrower.GetData(m_ERNo);
if (borrower.GetNo()=="")
{
MessageBox("没有这位读者,请确认输入ID是否正确! ","读者ID不正确", MB_OK|MB_ICONEXCLAMATION);
return;
}
CString vSQL;
vSQL = "select Book.BNo As 书号, Book.BName As 书名, Author As 作者, BrTime As 借出时间,MsTime AS 该还时间 ";
vSQL += "From Book,Borrow ";
vSQL += "where Book.BNo=Borrow.BNo and Borrow.RNo='";
vSQL = vSQL + borrower.GetNo() + "' And RtTime=''";
m_Adodc.SetRecordSource(vSQL);
m_Adodc.Refresh();
long i = borrower.GetBrNum();
vSQL.Format("ID号:%s 姓名:%s 目前已借%d 本",borrower.GetNo(),borrower.GetName(), i);
GetDlgItem(IDC_INFO)->SetWindowText(vSQL);
vSQL = borrower.GetType();
if (vSQL=="学生")
{
if (borrower.GetBrNum()==8)
{
MessageBox("该读者已达到最大借阅数,不能再借书!");
GetDlgItem(IDC_EDIT_BNO)->EnableWindow(false);
GetDlgItem(IDC_BTN_BNO)->EnableWindow(false);
}
else
{
GetDlgItem(IDC_EDIT_BNO)->EnableWindow(true);
GetDlgItem(IDC_BTN_BNO)->EnableWindow(true);
}
}
else if(vSQL=="教师")
{
if (borrower.GetBrNum()==12)
{
MessageBox("该读者已达到最大借阅数,不能再借书!");
GetDlgItem(IDC_EDIT_BNO)->EnableWindow(false);
GetDlgItem(IDC_BTN_BNO)->EnableWindow(false);
}
else
{
GetDlgItem(IDC_EDIT_BNO)->EnableWindow(true);
GetDlgItem(IDC_BTN_BNO)->EnableWindow(true);
}
}
else
{
if (borrower.GetBrNum()==5)
{
MessageBox("该读者已达到最大借阅数,不能再借书!");
GetDlgItem(IDC_EDIT_BNO)->EnableWindow(false);
GetDlgItem(IDC_BTN_BNO)->EnableWindow(false);
}
else
{
GetDlgItem(IDC_EDIT_BNO)->EnableWindow(true);
GetDlgItem(IDC_BTN_BNO)->EnableWindow(true);
}
}
//m_DataGrid.SetRefDataSource(NULL);
}
void CAdminBorrow::OnBtnBno()
{
// TODO: Add your control notification handler code here
UpdateData(true);
if (m_EBNo=="")
{
MessageBox("请输入要借图书的ID号","借书", MB_OK|MB_ICONEXCLAMATION);
return;
}
CBook book;
book.GetData(m_EBNo);
if (book.GetNo()=="")
{
MessageBox("没有这本书,请确认输入ID是否正确! ","图书ID不正确", MB_OK|MB_ICONEXCLAMATION);
return;
}
if (book.GetStatus() == "已借")
{
MessageBox("此书已经被借,请借另一本!","此书已被借", MB_OK|MB_ICONEXCLAMATION);
return;
}
int iType;
if (borrower.GetType() == "学生")
iType = 28;
else if (borrower.GetType() == "教师")
iType = 60;
else
iType = 60;
CString sTime1,sTime2;
CTime t1,t2;
CTimeSpan ts(iType,0,0,0);
t1=CTime::GetCurrentTime();
t2=t1+ts;
sTime1.Format("%d-%02d-%02d",t1.GetYear(),t1.GetMonth(),t1.GetDay()); //借出时间
sTime2.Format("%d-%02d-%02d",t2.GetYear(),t2.GetMonth(),t2.GetDay()); //该还时间
CBorrow bw;
bw.SQL_Insert(book.GetNo(),borrower.GetNo(),sTime1,sTime2);
book.SQL_UpdateStatus("已借");
borrower.SetBrNum(borrower.GetBrNum()+1);
borrower.SetTotalNum(borrower.GetTotalNum()+1);
borrower.SQL_Update(borrower.GetNo());
//m_DataGrid.SetRefDataSource(NULL);
CString vSQL;
vSQL = "select Book.BNo As 书号, Book.BName As 书名, Author As 作者, BrTime As 借出时间,MsTime AS 该还时间 ";
vSQL += "From Book,Borrow ";
vSQL += "where Book.BNo=Borrow.BNo and Borrow.RNo='";
vSQL = vSQL + borrower.GetNo() + "'";
vSQL = vSQL + "and RtTime=''";
m_Adodc.SetRecordSource(vSQL);
m_Adodc.Refresh();
vSQL.Format("ID号:%s 姓名:%s 目前已借%d 本",borrower.GetNo(),borrower.GetName(), borrower.GetBrNum());
GetDlgItem(IDC_INFO)->SetWindowText(vSQL);
vSQL = borrower.GetType();
if (vSQL=="学生")
{
if (borrower.GetBrNum()==8)
{
MessageBox("该读者已达到最大借阅数,不能再借书!");
GetDlgItem(IDC_EDIT_BNO)->EnableWindow(false);
GetDlgItem(IDC_BTN_BNO)->EnableWindow(false);
}
}
else if(vSQL=="教师")
{
if (borrower.GetBrNum()==12)
{
MessageBox("该读者已达到最大借阅数,不能再借书!");
GetDlgItem(IDC_EDIT_BNO)->EnableWindow(false);
GetDlgItem(IDC_BTN_BNO)->EnableWindow(false);
}
}
else
{
if (borrower.GetBrNum()==5)
{
MessageBox("该读者已达到最大借阅数,不能再借书!");
GetDlgItem(IDC_EDIT_BNO)->EnableWindow(false);
GetDlgItem(IDC_BTN_BNO)->EnableWindow(false);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -