?? addrentinfo.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 + -