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

📄 returndlg.cpp

📁 数据库方面的课程设计
💻 CPP
字号:
// ReturnDlg.cpp : implementation file
//

#include "stdafx.h"
#include "Library.h"
#include "ReturnDlg.h"
#include "punishtypeset.h"
#include "bookinfoset.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_tmBorrow = 0;
	m_tmReturn = 0;
	m_strBookCode = _T("");
	m_strBookName = _T("");
	m_strBookType = _T("");
	m_nOverDays = 0;
	m_strPrice = _T("");
	m_strReaderCode = _T("");
	m_strReaderName = _T("");
	m_fPunish = 0.0f;
	m_fOther = 0.0f;
	m_fTotal = 0.0f;
	//}}AFX_DATA_INIT
}


void CReturnDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CReturnDlg)
	DDX_Control(pDX, IDC_BUTTON_RETURN, m_bntReturn);
	DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER_BORROW, m_tmBorrow);
	DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER_RETURN, m_tmReturn);
	DDX_Text(pDX, IDC_EDIT_BOOKCODE, m_strBookCode);
	DDX_Text(pDX, IDC_EDIT_BOOKNAME, m_strBookName);
	DDX_Text(pDX, IDC_EDIT_BOOKTYPE, m_strBookType);
	DDX_Text(pDX, IDC_EDIT_OVERTIME, m_nOverDays);
	DDX_Text(pDX, IDC_EDIT_PRICE, m_strPrice);
	DDX_Text(pDX, IDC_EDIT_READERCODE, m_strReaderCode);
	DDX_Text(pDX, IDC_EDIT_READERNAME, m_strReaderName);
	DDX_Text(pDX, IDC_EDIT_PUNISH, m_fPunish);
	DDX_Text(pDX, IDC_EDIT_OTHER, m_fOther);
	DDX_Text(pDX, IDC_EDIT_TOTAL, m_fTotal);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CReturnDlg, CDialog)
	//{{AFX_MSG_MAP(CReturnDlg)
	ON_BN_CLICKED(IDC_BUTTON_RETURN, OnButtonReturn)
	ON_BN_CLICKED(IDC_BUTTON_CLEAR, OnButtonClear)
	ON_EN_CHANGE(IDC_EDIT_BOOKCODE, OnChangeEditBookcode)
	ON_EN_CHANGE(IDC_EDIT_OTHER, OnChangeEditOther)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CReturnDlg message handlers

BOOL CReturnDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	m_bntReturn.EnableWindow(FALSE);
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CReturnDlg::OnButtonReturn() 
{
	// TODO: Add your control notification handler code here
	UpdateData();
	CLibraryApp*  ptheApp = (CLibraryApp *) AfxGetApp();
	//修改图书库存信息
	CBookInfoSet rs_book;
	CString strSQL;
	strSQL.Format("select * from bookInfo where code = '%s'",m_strBookCode);
	if(!rs_book.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
	{
		MessageBox("打开数据库失败!","数据库错误",MB_OK);
		return ;
	}
	if(rs_book.GetRecordCount()==0)
	{
		rs_book.Close();
		return;
	}
	rs_book.Edit();
	rs_book.m_isBorrow = FALSE;
	rs_book.m_reader_code = _T("");
	rs_book.Update();
	rs_book.Close();
	//修改借阅信息
	strSQL.Format("select * from borrowInfo where book_code = '%s' and isReturn = False ",m_strBookCode);
	if(!m_BorrowSet.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
	{
		AfxMessageBox("打开数据库失败!");
		return ;
	}
	//判断是否借出
	if(m_BorrowSet.GetRecordCount()!=0)
	{
		m_BorrowSet.Edit();
		m_BorrowSet.m_isReturn = TRUE;
		m_BorrowSet.Update();
	}
	m_BorrowSet.Close();

	//保存还书信息到数据库中
	if(!m_ReturnSet.Open(AFX_DB_USE_DEFAULT_TYPE))
	{
		AfxMessageBox("打开数据库失败!");
		m_bntReturn.EnableWindow(FALSE);
		return ;
	}
	char buffer[20];
	m_ReturnSet.AddNew();
	m_ReturnSet.m_book_code = m_strBookCode;
	m_ReturnSet.m_book_name = m_strBookName;
	m_ReturnSet.m_book_type = m_strBookType;
	m_ReturnSet.m_borrow_date = m_tmBorrow;
	m_ReturnSet.m_operator = ptheApp->m_strOperator;
	gcvt(m_fOther,7,buffer);
	m_ReturnSet.m_other = buffer;
	m_ReturnSet.m_price = m_strPrice;
	gcvt(m_fPunish,7,buffer);
	m_ReturnSet.m_punish = buffer;
	m_ReturnSet.m_reader_code = m_strReaderCode;
	m_ReturnSet.m_reader_name = m_strReaderName;
	m_ReturnSet.m_return_date = CTime::GetCurrentTime();
	gcvt(m_fTotal,7,buffer);
	m_ReturnSet.m_total = buffer;
	m_ReturnSet.Update();
	m_ReturnSet.Close();
	AfxMessageBox("图书归还成功!",MB_ICONINFORMATION );
	//恢复到初始状态
	OnButtonClear();
}

void CReturnDlg::OnButtonClear() 
{
	// TODO: Add your control notification handler code here
	m_tmBorrow = 0;
	m_tmReturn = 0;
	m_strBookCode = _T("");
	m_strBookName = _T("");
	m_strBookType = _T("");
	m_nOverDays = 0;
	m_strPrice = _T("");
	m_strReaderCode = _T("");
	m_strReaderName = _T("");
	m_fPunish = 0.0f;
	m_fOther = 0.0f;
	m_fTotal = 0.0f;
	UpdateData(FALSE);
	//设置按钮状态
	m_bntReturn.EnableWindow(FALSE);	
}

void CReturnDlg::OnChangeEditBookcode() 
{
	// 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();
	CString strSQL;
	strSQL.Format("select * from borrowInfo where book_code = '%s' and isReturn = False ",m_strBookCode);
	//打开记录集
	if(!m_BorrowSet.Open(AFX_DB_USE_DEFAULT_TYPE,strSQL))
	{
		AfxMessageBox("打开数据库失败!");
		m_bntReturn.EnableWindow(FALSE);
		return ;
	}
	//判断是否借出
	if(m_BorrowSet.GetRecordCount()==0)
	{
		m_BorrowSet.Close();
		m_bntReturn.EnableWindow(FALSE);
		return;
	}
	//显示图书基本信息和借阅信息
	m_strBookName = m_BorrowSet.m_book_name;
	m_strBookType = m_BorrowSet.m_book_type;
	m_strPrice   = m_BorrowSet.m_price;
	m_strReaderCode = m_BorrowSet.m_reader_code;
	m_strReaderName = m_BorrowSet.m_reader_name;
	m_tmBorrow = m_BorrowSet.m_borrow_date;
	m_tmReturn = m_BorrowSet.m_return_date;
	CTime  tmCurrent = CTime::GetCurrentTime();
	if(tmCurrent > m_tmReturn)
		m_nOverDays = (int)(tmCurrent - m_tmReturn).GetDays();
	else
		m_nOverDays = 0;
	CPunishTypeSet rs;
	//显示罚款数据
	rs.Open(AFX_DB_USE_DEFAULT_TYPE,"select * from punishtype");
	m_fPunish =(float)( m_nOverDays*(atof(rs.m_money)));
	m_fTotal = m_fOther + m_fPunish;
	m_BorrowSet.Close();
	UpdateData(FALSE);
	//设置按钮状态
	m_bntReturn.EnableWindow();

}

void CReturnDlg::OnChangeEditOther() 
{
	UpdateData();
	m_fTotal = m_fOther + m_fPunish;
	UpdateData(FALSE);
}

⌨️ 快捷键说明

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