loanbookdlg.cpp
来自「管理员登录功能;读者借阅模块;读者归还模块;书籍信息模块」· C++ 代码 · 共 172 行
CPP
172 行
// LoanBookDlg.cpp : implementation file
//
#include "stdafx.h"
#include "db.h"
#include "LoanBookDlg.h"
#include <string>
using namespace std;
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CLoanBookDlg dialog
CLoanBookDlg::CLoanBookDlg(CString strBorrowerID, CWnd* pParent /*=NULL*/)
: CDialog(CLoanBookDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CLoanBookDlg)
m_sBorrowerID = strBorrowerID;
m_sItemID = _T("");
//}}AFX_DATA_INIT
CTime tm = CTime::GetCurrentTime();
m_sLoanStartDate.Format ("%d-%d-%d",tm.GetYear(),tm.GetMonth(),tm.GetDay());
tm +=CTimeSpan(30,0,0,0);
m_sLoanEndDate.Format ("%d-%d-%d",tm.GetYear(),tm.GetMonth(),tm.GetDay());
}
void CLoanBookDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CLoanBookDlg)
DDX_Text(pDX, IDC_BORROWID, m_sBorrowerID);
DDX_Text(pDX, IDC_ITEMID, m_sItemID);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CLoanBookDlg, CDialog)
//{{AFX_MSG_MAP(CLoanBookDlg)
ON_BN_CLICKED(IDC_LOAN, OnLoan)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CLoanBookDlg message handlers
void CLoanBookDlg::SetBorrowerID(CString strBorrowerID)
{
m_sBorrowerID=strBorrowerID;
UpdateData(false);
}
BOOL CLoanBookDlg::JudgeItemLoan()
{
_variant_t var;
//设置SELECT语句
CString strSQL;
strSQL.Format( "SELECT * FROM ItemInfo WHERE ItemLoanType=0 AND ItemID = '%s'",m_sItemID);
_bstr_t vSQL =strSQL;
_RecordsetPtr pRecordset;
pRecordset = m_AdoConn.GetRecordSet(vSQL);
BOOL bRet;
if (pRecordset->adoEOF == VARIANT_TRUE) //不存在或已经借出
{
bRet = false;
}
else
{
bRet = true;
}
return bRet;
}
void CLoanBookDlg::OnLoan()
{
UpdateData();
if(!JudgeItemLoan())
{
MessageBox("该书不存在或已经借出");
return ;
}
ModifyData();
InsertData();
}
void CLoanBookDlg::InsertData()
{
_variant_t var;
CString strCount("");
CString strSQL;
strSQL.Format("select max(LoanID) AS MAXLOANID from LoanInfo");
_bstr_t vSQL =strSQL;
_RecordsetPtr m_pRecordset;
m_pRecordset = m_AdoConn.GetRecordSet(vSQL);
if(!m_pRecordset->adoEOF)
{
var = m_pRecordset->GetCollect("MAXLOANID");
}
CString sNextLoanId=(LPCSTR)_bstr_t(var);
int nLoanID=atoi((LPCSTR)_bstr_t(var));
nLoanID+=1;
char buf[10];
itoa(nLoanID,buf,10);
sNextLoanId=buf;
try
{
strSQL.Format ("INSERT INTO LoanInfo(LoanID,BorrowerID,ItemID,LoanStartTime,LoanEndTime,Returned)\
VALUES('%s','%s','%s','%s','%s','%d')",sNextLoanId,m_sBorrowerID,m_sItemID,m_sLoanStartDate,m_sLoanEndDate,0);
_bstr_t vSQL =strSQL;
m_AdoConn.ExecuteSQL(vSQL);
}
catch (_com_error e)
{
CString errormessage;
errormessage.Format("自定义错误信息3:%s",e.ErrorMessage());
AfxMessageBox(errormessage);//显示错误信息
}
}
void CLoanBookDlg::ModifyData()
{
CString strSQL("");
try
{
strSQL.Format("update ItemInfo SET ItemLoanType ='%d' ,ItemReturnTime='%s' WHERE ItemID ='%s'",\
1,m_sLoanEndDate,m_sItemID);
_bstr_t vSQL =strSQL;
m_AdoConn.ExecuteSQL(vSQL);
}
catch (_com_error e)
{
CString errormessage;
errormessage.Format("自定义错误信息3:%s",e.ErrorMessage());
AfxMessageBox(errormessage);///显示错误信息
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?