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

📄 addrentinfo.cpp

📁 影碟出租系统 利用mfc编程 与数据库连接
💻 CPP
字号:
// AddRentInfo.cpp : implementation file
//

#include "stdafx.h"
#include "Rent.h"
#include "AddRentInfo.h"
#include "Connectiondb.h"

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

/////////////////////////////////////////////////////////////////////////////
// CAddRentInfo dialog


CAddRentInfo::CAddRentInfo(CWnd* pParent /*=NULL*/)
	: CDialog(CAddRentInfo::IDD, pParent)
{
	//{{AFX_DATA_INIT(CAddRentInfo)
	m_DVDName = _T("");
	m_RenterName = _T("");
	m_RentNum = '1';
	//}}AFX_DATA_INIT
}


void CAddRentInfo::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAddRentInfo)
	DDX_Control(pDX, IDC_EDIT_DVDNAME, m_CDVDName);
	DDX_Control(pDX, IDC_DATETIMEPICKER, m_RentDate);
	DDX_Text(pDX, IDC_EDIT_DVDNAME, m_DVDName);
	DDX_Text(pDX, IDC_EDIT_PNAME, m_RenterName);
	DDX_Text(pDX, IDC_EDIT_RENTNUM, m_RentNum);
	//}}AFX_DATA_MAP
}

BOOL CAddRentInfo::OnInitDialog()
{
	CDialog::OnInitDialog();
	
	if(!m_DVDName.IsEmpty())
		m_CDVDName.EnableWindow(FALSE);
	return TRUE;

}

BEGIN_MESSAGE_MAP(CAddRentInfo, CDialog)
	//{{AFX_MSG_MAP(CAddRentInfo)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CAddRentInfo message handlers

void CAddRentInfo::OnOK() 
{
	// TODO: Add extra validation here
	UpdateData(TRUE);
	CString strDate;
	GetDlgItem(IDC_DATETIMEPICKER)->GetWindowText(strDate);
	CConnectionDB *connection=new CConnectionDB();
	m_pConnection=connection->GetConnectionPtr();
	_RecordsetPtr pRentRecordset;
	pRentRecordset.CreateInstance(__uuidof(Recordset));
	HRESULT hr;
	if(m_DVDName.IsEmpty()||m_RenterName.IsEmpty())
	{
		MessageBox("请输入完整的资料!");
		return;
	}
	CString strtemp;
	strtemp.Format("DVD:%s\n租借人:%s\n数量:%s\n日期:%s",m_DVDName,m_RenterName,m_RentNum,strDate);
	try
	{
		hr=pRentRecordset->Open(_variant_t("DVDRentInfo"),m_pConnection.GetInterfacePtr(),
						adOpenDynamic,adLockOptimistic,adCmdTable);
		if(SUCCEEDED(hr))
		{
			if(MessageBox(strtemp,"提示",MB_OKCANCEL)==IDOK)
			{
				pRentRecordset->AddNew();
				pRentRecordset->PutCollect("DVDName",_variant_t(m_DVDName));
				pRentRecordset->PutCollect("Name",_variant_t(m_RenterName));
				pRentRecordset->PutCollect("BNum",_variant_t(m_RentNum));
				pRentRecordset->PutCollect("BDate",_variant_t(strDate));
				pRentRecordset->Update();
			}
		}
		else
		{
			AfxMessageBox("open error");
			return;
		}
	}
	catch(_com_error *e)
	{
		AfxMessageBox(e->ErrorMessage());
		return;
	}
	pRentRecordset->Close();
	pRentRecordset=NULL;
	delete connection;
	int dvdNum=atoi(m_RentNum);
	CString dvdName=m_DVDName;
	MinusDVDNum(dvdName,dvdNum);
	
	CDialog::OnOK();
}

void CAddRentInfo::MinusDVDNum(CString DVDName,int DVDNum)
{
	_RecordsetPtr pDVDRecordset;
	pDVDRecordset.CreateInstance(__uuidof(Recordset));
	CString strSQL;
	strSQL.Format("select DVDNum from DVDInfo where DVDName='%s'",DVDName);
	_variant_t var;
	CString strValue;
	int num;
	HRESULT hr;
	try
	{
		hr=pDVDRecordset->Open(_variant_t(strSQL),m_pConnection.GetInterfacePtr(),
							adOpenDynamic,adLockOptimistic,adCmdText);
		if(SUCCEEDED(hr))
		{
			var=pDVDRecordset->GetCollect("DVDNum");
			if(var.vt!=VT_NULL)
				strValue=(LPCSTR)_bstr_t(var);
			num=atoi(strValue);
			num-=DVDNum;
			strValue.Format("%d",num);
			pDVDRecordset->PutCollect("DVDNum",_variant_t(strValue));
			pDVDRecordset->Update();
		}
		else
		{
			MessageBox("error");
			return;
		}
	}
	catch(_com_error *e)
	{
		AfxMessageBox(e->ErrorMessage());
		return;
	}
	pDVDRecordset->Close();
	pDVDRecordset=NULL;
}

⌨️ 快捷键说明

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