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

📄 returnbookdlg.cpp

📁 图书馆管理系统是典型的信息管理系统(MIS),其开发主要包括后台数据库的建立和维护以及前端应用程序的开发两个方面。对于前者要求建立起数据一致性和完整性强.数据安全性好的库。而对于后者则要求应用程序功能
💻 CPP
字号:
// ReturnBookDlg.cpp : implementation file
//

#include "stdafx.h"
#include "librarym.h"
#include "ReturnBookDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CReturnBookDlg dialog


CReturnBookDlg::CReturnBookDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CReturnBookDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CReturnBookDlg)
	m_ReturnReaderID = _T("");
	m_ReturnBookID = _T("");
	//}}AFX_DATA_INIT
}


void CReturnBookDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CReturnBookDlg)
	DDX_Text(pDX, IDC_EDIT_RETURNREADERID, m_ReturnReaderID);
	DDX_Text(pDX, IDC_EDIT_RETURNBOOKID, m_ReturnBookID);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CReturnBookDlg, CDialog)
	//{{AFX_MSG_MAP(CReturnBookDlg)
	ON_BN_CLICKED(IDC_BUTTON_CANCEL, OnButtonCancel)
	ON_BN_CLICKED(IDC_BUTTON_RETURN, OnButtonReturn)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CReturnBookDlg message handlers


BOOL CReturnBookDlg::OnInitDialog()
{
	CDialog::OnInitDialog();
	//初始化数据库连接
	HRESULT result;
	try
	{
		//实例化连接对象
		result=m_pConnection.CreateInstance(_uuidof(Connection));
		if(SUCCEEDED(result))
		{
			//设置连接属性为UDL文件
			m_pConnection->ConnectionString="File Name=LIBRARYM.udl";
			//设置等待连接打开的时间为20s
			m_pConnection->ConnectionTimeout=20;
			result=m_pConnection->Open("","","",adConnectUnspecified);

			if(FAILED(result))
			{
				AfxMessageBox("open failed");
				return TRUE;
			}
		}
		else
		{
			AfxMessageBox("createinstance of connection failed!");
			return TRUE;
		}
	}
	catch(_com_error e)
	{
		//输出异常信息
		_bstr_t bstrSource(e.Source());
		_bstr_t bstrDescription(e.Description());
		AfxMessageBox(bstrSource+bstrDescription);
		return TRUE;
	}
	return TRUE;
}

void CReturnBookDlg::OnButtonCancel() 
{
	CDialog::OnCancel();
}

void CReturnBookDlg::OnButtonReturn() 
{
	UpdateData(TRUE);
	CString strSql="delete from BorrowRelation where ";
	CString addsql="select * from BookInfo where ";
	CString temp;
	CString temp1;

	if(m_ReturnBookID.IsEmpty())
	{
		AfxMessageBox("book ID can't ne empty!",MB_OK);
		return;
	}
	temp.Format("BookID='%s'",m_ReturnBookID);
	temp1.Format("BookID='%s'",m_ReturnBookID);
	strSql+=temp;
	addsql+=temp1;
	temp="";

	if(m_ReturnReaderID.IsEmpty())
	{
		AfxMessageBox("Reader ID can't ne empty!",MB_OK);
		return;
	}
	temp.Format("and ReaderID='%s'",m_ReturnReaderID);
	strSql+=temp;

	_RecordsetPtr pset;
	pset.CreateInstance(_uuidof(Recordset));

	int curItem=0;
	_variant_t var;
	CString addvalue;           //还书后库存+1
	try
	{
		pset->Open(_variant_t(strSql),m_pConnection.GetInterfacePtr(),
			adOpenDynamic,adLockOptimistic,adCmdText);

		pset->Open(_variant_t(addsql),m_pConnection.GetInterfacePtr(),
			adOpenDynamic,adLockOptimistic,adCmdText);

		var=pset->GetCollect("Available");
		addvalue=(LPCSTR)_bstr_t(var);
		//把字符转化为整型
		int add=atoi(addvalue);
		add++;  //库存里增加一本刚还的书
		addvalue.Format("%d",add);
		//把数据放回表BookInfo里,更新保存
		pset->PutCollect("Available",_variant_t(addvalue));
		pset->Update();
	}
	catch(_com_error *e)
	{
		AfxMessageBox(e->ErrorMessage());
		return;
	}
	pset->Close();
	pset=NULL;
	return;
}

⌨️ 快捷键说明

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