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

📄 returndlg.cpp

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

#include "stdafx.h"
#include "Rent.h"
#include "ReturnDlg.h"
#include "connectiondb.h"
#include "rentinfodlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CReturnDlg dialog

CString CReturnDlg::RentName=_T("");
CString CReturnDlg::DVDName=_T("");
CString CReturnDlg::Num=_T("");
CString CReturnDlg::Date=_T("");

CReturnDlg::CReturnDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CReturnDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CReturnDlg)
	m_CheckDVD = FALSE;
	m_CheckID = FALSE;
	m_CheckRent = FALSE;
	m_InDVD = _T("");
	m_InID = _T("");
	m_InRent = _T("");
	m_OutDate = _T("");
	m_OutDVD = _T("");
	m_OutNum = _T("");
	m_OutRent = _T("");
	//}}AFX_DATA_INIT
}

BOOL CReturnDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	m_CheckDVD=FALSE;
	m_CheckID=FALSE;
	m_CheckRent=FALSE;

	m_CInDVD.EnableWindow(FALSE);
	m_CInID.EnableWindow(FALSE);
	m_CInRent.EnableWindow(FALSE);

	return TRUE;

}

void CReturnDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CReturnDlg)
	DDX_Control(pDX, IDC_InRent, m_CInRent);
	DDX_Control(pDX, IDC_InID, m_CInID);
	DDX_Control(pDX, IDC_InDVD, m_CInDVD);
	DDX_Check(pDX, IDC_CHECKDVD, m_CheckDVD);
	DDX_Check(pDX, IDC_CHECKID, m_CheckID);
	DDX_Check(pDX, IDC_CHECKRENT, m_CheckRent);
	DDX_Text(pDX, IDC_InDVD, m_InDVD);
	DDX_Text(pDX, IDC_InID, m_InID);
	DDX_Text(pDX, IDC_InRent, m_InRent);
	DDX_Text(pDX, IDC_OutDate, m_OutDate);
	DDX_Text(pDX, IDC_OutDVD, m_OutDVD);
	DDX_Text(pDX, IDC_OutNum, m_OutNum);
	DDX_Text(pDX, IDC_OutRent, m_OutRent);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CReturnDlg, CDialog)
	//{{AFX_MSG_MAP(CReturnDlg)
	ON_BN_CLICKED(IDC_CHECKID, OnCheckid)
	ON_BN_CLICKED(IDC_CHECKRENT, OnCheckrent)
	ON_BN_CLICKED(IDC_CHECKDVD, OnCheckdvd)
	ON_BN_CLICKED(IDC_BUTTON, OnButton)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

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

void CReturnDlg::OnCheckid() 
{
	// TODO: Add your control notification handler code here
	if(m_CheckID==TRUE)
	{
		m_CheckID=FALSE;
		m_CInID.EnableWindow(FALSE);
	}
	else
	{
		m_CheckID=TRUE;
		m_CInID.EnableWindow(TRUE);
	}
	m_InID.Empty();
	UpdateData(FALSE);
}

void CReturnDlg::OnCheckrent() 
{
	// TODO: Add your control notification handler code here
	if(m_CheckRent==TRUE)
	{
		m_CheckRent=FALSE;
		m_CInRent.EnableWindow(FALSE);
	}
	else
	{
		m_CheckRent=TRUE;
		m_CInRent.EnableWindow(TRUE);
	}
	m_InRent.Empty();
	UpdateData(FALSE);
}

void CReturnDlg::OnCheckdvd() 
{
	// TODO: Add your control notification handler code here

	if(m_CheckDVD==TRUE)
	{
		m_CheckDVD=FALSE;
		m_CInDVD.EnableWindow(FALSE);
	}
	else
	{
		m_CheckDVD=TRUE;
		m_CInDVD.EnableWindow(TRUE);
	}
	m_InDVD.Empty();
	UpdateData(FALSE);
}

void CReturnDlg::OnButton() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
//	CString temp;
//	temp = m_InID;
	CConnectionDB connection;
	pConnection = connection.GetConnectionPtr();

	if(m_CheckID||(m_CheckDVD&&m_CheckRent))
	{	

		CString strSQL;
		if(!m_InID.IsEmpty())
			strSQL.Format("select * from DVDRentInfo where ID = %s",m_InID);
/*		else
		{
			MessageBox("请输入编号!");
			return;
		}*/
		else if(!m_InDVD.IsEmpty()&&!m_InRent.IsEmpty())
			strSQL.Format("select * from DVDRentInfo where Name='%s' and DVDName='%s'"\
																		,m_InRent,m_InDVD);	
		else
		{
			MessageBox("请输入编号或租借人名称和DVD名称!");
			return;
		}
		_RecordsetPtr pRecordset;
		pRecordset.CreateInstance(__uuidof(Recordset));
		_variant_t var;	
		try
		{
			pRecordset->Open(_variant_t(strSQL),pConnection.GetInterfacePtr(),
						adOpenDynamic,adLockOptimistic,adCmdText);
		}
		catch(_com_error *e)
		{
			MessageBox(e->ErrorMessage());
			return;
		}
		if(pRecordset->adoEOF&&pRecordset->BOF)
		{
			MessageBox("没有记录!");
			return;
		}
		try
		{
			var=pRecordset->GetCollect("Name");
			if(var.vt!=VT_NULL)
				m_OutRent=(LPCTSTR)_bstr_t(var);

			var=pRecordset->GetCollect("DVDName");
			if(var.vt!=VT_NULL)
				m_OutDVD=(LPCTSTR)_bstr_t(var);

			var=pRecordset->GetCollect("BNum");
			if(var.vt!=VT_NULL)
				m_OutNum=(LPCTSTR)_bstr_t(var);

			var=pRecordset->GetCollect("BDate");
			if(var.vt!=VT_NULL)
				m_OutDate=(LPCTSTR)_bstr_t(var);

			UpdateData(FALSE);
		}
		catch(_com_error *e)
		{
			MessageBox(e->ErrorMessage());
			return;
		}
	}
	else if(m_CheckDVD&&!m_CheckID&&!m_CheckRent)
	{
		if(m_InDVD.IsEmpty())
		{
			MessageBox("请输入DVD名称!");
			return;
		}
		else
		{
			CRentInfoDlg rentdlg;
			rentdlg.DVDName=m_InDVD;
			if(rentdlg.DoModal()==IDOK)
			{
				m_OutRent=RentName;
				m_OutDVD=DVDName;
				m_OutNum=Num;
				m_OutDate=Date;
				UpdateData(FALSE);
			}
		}
	}
	else if(!m_CheckDVD&&!m_CheckID&&m_CheckRent)
	{
		if(m_InRent.IsEmpty())
		{
			MessageBox("请输入租借人名称!");
			return;
		}
		else
		{
			CRentInfoDlg rentdlg;
			rentdlg.Renter=m_InRent;
			if(rentdlg.DoModal()==IDOK)
			{
				m_OutRent=RentName;
				m_OutDVD=DVDName;
				m_OutNum=Num;
				m_OutDate=Date;
				UpdateData(FALSE);
			}
		}
	}
	else
	{
		MessageBox("请输入租借编号或租借人名称或DVD名称!");
		return;
	}

}

void CReturnDlg::OnOK() 
{
	// TODO: Add extra validation here
	if(m_OutDate.IsEmpty()||m_OutDVD.IsEmpty()||m_OutNum.IsEmpty()||m_OutRent.IsEmpty())
	{
		MessageBox("没有DVD信息!");
		return;
	}
	int num;
	num=atoi(m_OutNum);
	UpdateDVDInfo(m_OutDVD,num);
	UpdateRentInfo(m_OutDVD,m_OutRent);
	
	CDialog::OnOK();
}

void CReturnDlg::UpdateDVDInfo(CString DVDName,int DVDNum)
{
//	int DVDNum;
	CString strSQL;
	strSQL.Format("select * from DVDInfo where DVDName = '%s'",DVDName);
	_RecordsetPtr m_pRecordset;
	m_pRecordset.CreateInstance(__uuidof(Recordset));
	_variant_t var;
	CString strValue;
	int num;
	try
	{
		m_pRecordset->Open(_variant_t(strSQL),pConnection.GetInterfacePtr(),
							adOpenDynamic,adLockOptimistic,adCmdText);
		var=m_pRecordset->GetCollect(_variant_t("DVDNum"));
		if(var.vt!=VT_NULL)
			strValue=(LPCTSTR)_bstr_t(var);
		num=atoi(strValue);
		num+=DVDNum;
		strValue.Format("%d",num);
		m_pRecordset->PutCollect("DVDNum",_variant_t(strValue));
		m_pRecordset->Update();
	}
	catch(_com_error *e)
	{
		MessageBox(e->ErrorMessage());
		return;
	}
	m_pRecordset->Close();
	m_pRecordset=NULL;
}

void CReturnDlg::UpdateRentInfo(CString DVDName,CString RentName)
{
	CString strSQL;
	strSQL.Format("delete * from DVDRentInfo where Name = '%s' and DVDName = '%s'",\
																			RentName,DVDName);
	_variant_t RecordsAffected;
	try
	{
		pConnection->Execute(_bstr_t(strSQL),&RecordsAffected,adCmdText);
	}
	catch(_com_error *e)
	{
		MessageBox(e->ErrorMessage());
	}
}

⌨️ 快捷键说明

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