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

📄 borrow.cpp

📁 本程序是在学习期间编制的图书馆管理系统
💻 CPP
字号:
// Borrow.cpp : 实现文件
//

#include "stdafx.h"
#include "MyZone.h"
#include "Borrow.h"
#include ".\borrow.h"


// CBorrow 对话框

IMPLEMENT_DYNAMIC(CBorrow, CPropertyPage)
CBorrow::CBorrow()
	: CPropertyPage(CBorrow::IDD)
	, m_Bisbn(_T(""))
	, m_Bdate(COleDateTime::GetCurrentTime())
{
}

CBorrow::~CBorrow()
{
}

void CBorrow::DoDataExchange(CDataExchange* pDX)
{
	CPropertyPage::DoDataExchange(pDX);
	DDX_Text(pDX, IDC_EDIT1, m_Bisbn);
	DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER1, m_Bdate);
}


BEGIN_MESSAGE_MAP(CBorrow, CPropertyPage)
	ON_BN_CLICKED(IDC_BUTTON1, OnBnClickedButton1)
END_MESSAGE_MAP()


// CBorrow 消息处理程序


BOOL CBorrow::OnInitDialog()
{
	CPropertyPage::OnInitDialog();

	// TODO:  在此添加额外的初始化
	try
	{
		theApp.m_pRecordsetborrow->Open(_variant_t("SELECT * FROM Borrow"),                
							theApp.m_pConnection.GetInterfacePtr(),	 
							adOpenDynamic,
							adLockOptimistic,
							adCmdText);

	}
	catch(_com_error *e)
	{
		AfxMessageBox(e->ErrorMessage());
	}

	return TRUE;  // return TRUE unless you set the focus to a control
	// 异常: OCX 属性页应返回 FALSE
}



void CBorrow::OnBnClickedButton1()
{
	// TODO: 在此添加控件通知处理程序代码
	UpdateData(TRUE);
	CString str,str1,str2;
	COleDateTime m_bbb;
	int i;
	SetDlgItemText(IDC_EDIT3,theApp.m_Auserid);
	if( m_Bisbn == ""|| theApp.m_Auserid == "")
	{
		AfxMessageBox("用户名,ISBN和借书日期不能为空!");
	}
	else
	{
	try
	{
		theApp.m_pRecordsetbook->Open(_variant_t("select Left_Num from Book where ISBN =\'"+m_Bisbn+"\'"),
		theApp.m_pConnection.GetInterfacePtr(),
		adOpenDynamic,adLockOptimistic,adCmdText);
	
	if(!theApp.m_pRecordsetbook->adoEOF)
	{
		str = theApp.m_pRecordsetbook->GetCollect("Left_Num");
		i = atoi(str);
		if(i>0)
		{
			i=i-1;
			str1.Format("%d",i);
			theApp.m_pRecordsetbook->PutCollect("Left_Num", _variant_t(str1));
			theApp.m_pRecordsetbook->Update();
		}
		else
		{
			theApp.m_pRecordsetbook->Close();
			AfxMessageBox("没有图书剩余,您不能借此书!"); 
		}
	}
	else
	{
		theApp.m_pRecordsetbook->Close();
		AfxMessageBox("没有此书,请重新输入!"); 
	}
	}
	catch(_com_error e){
	CString errormessage;
	errormessage.Format("数据库图书表项操作失败!\n%s",e.Description());
	MessageBox(e.Description());
	}




	try
	{
		theApp.m_pRecordset->Open(_variant_t("select BLeft from Reader where SID =\'"+theApp.m_Auserid+"\'"),
		theApp.m_pConnection.GetInterfacePtr(),
		adOpenDynamic,adLockOptimistic,adCmdText);
	
	if(!theApp.m_pRecordset->adoEOF)
	{
		CString str4,str5;
		str4 = theApp.m_pRecordset->GetCollect("BLeft");
		i = atoi(str4);
		if(i>0)
		{
			i=i-1;
			str5.Format("%d",i);
			theApp.m_pRecordset->PutCollect("BLeft", _variant_t(str5));
			theApp.m_pRecordset->Update();
			theApp.m_pRecordset->Close();
		}
		else
		{
			theApp.m_pRecordset->Close();
			AfxMessageBox("您的借书量已达上限,您不能借此书!"); 
		}
	}
	else
	{
		theApp.m_pRecordset->Close();
		AfxMessageBox("没有此书,请重新输入!"); 
	}
	}
	catch(_com_error e){
	CString errormessage;
	errormessage.Format("数据库图书表项操作失败!\n%s",e.Description());
	MessageBox(e.Description());
	}




	try
	{	
		theApp.m_pRecordsetborrow->AddNew();
		theApp.m_pRecordsetborrow->PutCollect("ISBN", _variant_t(m_Bisbn));

		
		str2.Format("%d-%d-%d",m_Bdate.GetYear(),m_Bdate.GetMonth(),m_Bdate.GetDay());
		theApp.m_pRecordsetborrow->PutCollect("Borrow_Date", _variant_t(str2));


		theApp.m_pRecordsetborrow->PutCollect("SID",_variant_t(theApp.m_Auserid));
		theApp.m_pRecordsetborrow->Update();
		AfxMessageBox("借书成功!");
		theApp.m_pRecordsetborrow->Close();		
	}
	catch(_com_error e){
	CString errormessage;
	errormessage.Format("数据库借书表项操作失败!\r\n%s",e.Description());
	MessageBox(e.Description());
	}
	}
}

⌨️ 快捷键说明

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