📄 returndlg.cpp
字号:
// ReturnDlg.cpp : implementation file
//
#include "stdafx.h"
#include "library.h"
#include "ReturnDlg.h"
#include "BookSet.h"
#include "PunishSet1.h"
#include "ReaderSet.h"
#include "BorrrowSet.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CReturnDlg dialog
CReturnDlg::CReturnDlg(CWnd* pParent /*=NULL*/)
: CDialog(CReturnDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CReturnDlg)
m_bookid = _T("");
m_price = _T("");
m_bookname = _T("");
m_name = _T("");
m_overday = 0;
m_punish_cost = _T("");
m_readerid = _T("");
m_tmBorrow = 0;
m_tmReturn = 0;
m_wouldreturn = 0;
//}}AFX_DATA_INIT
}
void CReturnDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CReturnDlg)
DDX_Text(pDX, IDC_BOOK_ID, m_bookid);
DDX_Text(pDX, IDC_BOOK_PRICE, m_price);
DDX_Text(pDX, IDC_BOOK_NAME, m_bookname);
DDX_Text(pDX, IDC_NAME, m_name);
DDX_Text(pDX, IDC_OVERDAY, m_overday);
DDX_Text(pDX, IDC_PUNISH_COST, m_punish_cost);
DDX_Text(pDX, IDC_READER_ID, m_readerid);
DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER_BORROW, m_tmBorrow);
DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER_RETURN, m_tmReturn);
DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER_WOULD_RETURN, m_wouldreturn);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CReturnDlg, CDialog)
//{{AFX_MSG_MAP(CReturnDlg)
ON_EN_CHANGE(IDC_BOOK_ID, OnChangeBookId)
ON_BN_CLICKED(IDOK2, OnClear)
ON_BN_CLICKED(IDOK, OnReturn)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CReturnDlg message handlers
void CReturnDlg::OnChangeBookId()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
UpdateData(TRUE);
CBorrrowSet borrowSet;
CString strsql;
strsql.Format("select * from Borrow where BookID='%s'",m_bookid);
if(!borrowSet.Open(AFX_DB_USE_DEFAULT_TYPE,strsql))
{
AfxMessageBox("连接数据库错误");
return;
}
int bookNum = borrowSet.GetRecordCount();
if(0 == bookNum)
{
borrowSet.Close();
return;
}
m_bookname = borrowSet.m_BookName;
m_price = borrowSet.m_Price;
m_readerid = borrowSet.m_CardID;
m_name = borrowSet.m_Name;
m_tmBorrow = borrowSet.m_BorrowData;
m_wouldreturn = borrowSet.m_ReturnData;
m_tmReturn = CTime::GetCurrentTime();
if(m_tmReturn > borrowSet.m_ReturnData)
{
if(m_tmReturn - m_wouldreturn > 0)
m_overday = (int)(m_tmReturn - m_wouldreturn).GetDays();
}
CPunishSet punishSet;
strsql.Format("select * from Punish ");
if(!punishSet.Open(AFX_DB_USE_DEFAULT_TYPE,strsql))
{
AfxMessageBox("连接数据库错误");
return;
}
double money = atof(punishSet.m_Money);
m_punish_cost.Format("%f",m_overday * money);
UpdateData(false);
borrowSet.Close();
}
void CReturnDlg::OnClear()
{
// TODO: Add your control notification handler code here
m_tmBorrow = 0;
m_tmReturn = 0;
m_wouldreturn = 0;
m_bookid = _T("");
m_bookname = _T("");
m_overday = 0;
m_price = _T("");
m_readerid = _T("");
m_name = _T("");
m_punish_cost = _T("");
UpdateData(FALSE);
}
void CReturnDlg::OnReturn()
{
// TODO: Add your control notification handler code here
////修改图书是否可借
UpdateData();
CString strsql;
CBookSet bookSet;
strsql.Format("select * from Book where BookID = '%s'",m_bookid);
if(!bookSet.Open(AFX_DB_USE_DEFAULT_TYPE,strsql))
{
AfxMessageBox("连接数据库错误");
return;
}
if(0 == bookSet.GetRecordCount())
{
bookSet.Close();
return;
}
bookSet.Edit();
bookSet.m_IsBorrow = FALSE;
bookSet.Update();
bookSet.Close();
//////////////////////////////////////////////////////////////////////////
///修改借阅数量
CReaderSet readerSet;
strsql.Format("select * from Reader where CardID='%s'",m_readerid);
if(!readerSet.Open(AFX_DB_USE_DEFAULT_TYPE,strsql))
{
AfxMessageBox("数据库连接错误");
return;
}
readerSet.Edit();
readerSet.m_BorrowNum--;
readerSet.Update();
readerSet.Close();
////修改图书是否归还信息
strsql.Format("select * from Borrow where BookID = '%s' and CardID='%s'",m_bookid,m_readerid);
CBorrrowSet borrowSet;
if(!borrowSet.Open(AFX_DB_USE_DEFAULT_TYPE,strsql))
{
AfxMessageBox("数据库连接错误");
return;
}
if(0 == borrowSet.GetRecordCount())
{
borrowSet.Close();
return;
}
/* borrowSet.Edit();
borrowSet.m_IsReturn = TRUE;
*/
borrowSet.Delete();
borrowSet.Close();
////保存还书记录到数据库
strsql.Format("select * from ReturnTable where BookID = '%s' and BorrowData = '%s'",m_bookid,m_tmBorrow);
if(!m_returnSet.Open(AFX_DB_USE_DEFAULT_TYPE,strsql))
{
AfxMessageBox("连接数据库错误");
return;
}
if(0 != m_returnSet.GetRecordCount())
{
m_returnSet.Close();
return;
}
CString tt;
m_returnSet.AddNew();
m_returnSet.m_BookID = m_bookid;
m_returnSet.m_BookName = m_bookname;
m_returnSet.m_CardID = m_readerid;
m_returnSet.m_Name = m_name;
m_returnSet.m_Price = m_price;
m_returnSet.m_Punish_Cost = m_punish_cost;
m_returnSet.m_BorrowData = m_tmBorrow;
m_returnSet.m_RealReturnData= m_tmReturn;
m_returnSet.m_ReturnData = m_wouldreturn;
if(m_returnSet.CanUpdate())
{
m_returnSet.Update();
m_returnSet.Close();
AfxMessageBox("图书归还成功");
}
OnClear();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -