?? checkrentinfo.cpp
字號:
// CheckRentInfo.cpp : implementation file
//
#include "stdafx.h"
#include "Rent.h"
#include "CheckRentInfo.h"
#include "Connectiondb.h"
#include "rentinfodlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CCheckRentInfo dialog
CCheckRentInfo::CCheckRentInfo(CWnd* pParent /*=NULL*/)
: CDialog(CCheckRentInfo::IDD, pParent)
{
//{{AFX_DATA_INIT(CCheckRentInfo)
m_Renter = _T("");
m_CheckDate = FALSE;
//}}AFX_DATA_INIT
}
void CCheckRentInfo::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCheckRentInfo)
DDX_Control(pDX, IDC_DATETIMEPICKER1, m_Date);
DDX_Control(pDX, IDC_COMBOLIST, m_ComboList);
DDX_Control(pDX, IDC_LIST_RENT, m_RentList);
DDX_Text(pDX, IDC_EDIT_RENTER, m_Renter);
DDX_Check(pDX, IDC_CHECKDATE, m_CheckDate);
//}}AFX_DATA_MAP
}
BOOL CCheckRentInfo::OnInitDialog()
{
CDialog::OnInitDialog();
m_RentList.InsertColumn(0,"ID",LVCFMT_LEFT,50,-1);
m_RentList.InsertColumn(1,"租借人",LVCFMT_LEFT,80,-1);
m_RentList.InsertColumn(2,"DVD名",LVCFMT_LEFT,150,-1);
m_RentList.InsertColumn(3,"租借數量",LVCFMT_LEFT,90,-1);
m_RentList.InsertColumn(4,"租借日期",LVCFMT_LEFT,100,-1);
m_RentList.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
m_CheckDate=FALSE;
m_Date.EnableWindow(FALSE);
// 初始化組合框
CConnectionDB connection;
pConnection=connection.GetConnectionPtr();
_RecordsetPtr pRecordset;
pRecordset.CreateInstance(__uuidof(Recordset));
CString strSQL;
CString strValue;
strSQL="select DVDName from DVDInfo";
_variant_t var;
try
{
pRecordset->Open(_variant_t(strSQL),pConnection.GetInterfacePtr(),
adOpenDynamic,adLockOptimistic,adCmdText);
}
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
return TRUE;
}
m_ComboList.AddString("");
try
{
while(!pRecordset->adoEOF)
{
var=pRecordset->GetCollect("DVDNAME");
if(var.vt!=VT_NULL)
strValue=(LPCSTR)_bstr_t(var);
m_ComboList.AddString(strValue);
pRecordset->MoveNext();
}
pRecordset->Close();
pRecordset=NULL;
}
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
return TRUE;
}
return TRUE;
}
BEGIN_MESSAGE_MAP(CCheckRentInfo, CDialog)
//{{AFX_MSG_MAP(CCheckRentInfo)
ON_BN_CLICKED(IDC_CHECKDATE, OnCheckdate)
ON_BN_CLICKED(IDC_CHENK_RENT, OnChenkRent)
ON_BN_CLICKED(IDC_LISTALLRENT, OnListallrent)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCheckRentInfo message handlers
void CCheckRentInfo::OnCheckdate()
{
// TODO: Add your control notification handler code here
if(m_CheckDate==FALSE)
{
m_CheckDate=TRUE;
m_Date.EnableWindow(TRUE);
}
else
{
m_CheckDate=FALSE;
m_Date.EnableWindow(FALSE);
}
}
void CCheckRentInfo::OnChenkRent()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
if(m_RentList.GetItemCount()>0)
{
m_RentList.DeleteAllItems();
UpdateData(FALSE);
}
if(pConnection==NULL)
{
CConnectionDB connection;
pConnection=connection.GetConnectionPtr();
}
_RecordsetPtr pRecordset;
pRecordset.CreateInstance(__uuidof(Recordset));
CString strDate,strDVD;
CString strSQL,temp;
m_ComboList.GetWindowText(strDVD);
//如果日期,DVD名和租借人的值全部為空,則查找所有的信息
//否則根據條件進行查找
if((!m_CheckDate)&&(strDVD.IsEmpty())&&(m_Renter.IsEmpty()))
strSQL="select * from DVDRentInfo";
else
strSQL="select * from DVDRentInfo where ";
if(m_CheckDate)
{
m_Date.GetWindowText(strDate);
temp.Format("BDate = '%s'",strDate);
strSQL+=temp;
}
if(!m_Renter.IsEmpty())
{
if(m_CheckDate)
temp.Format(" and Name = '%s'",m_Renter);
else
temp.Format("Name = '%s'",m_Renter);
strSQL+=temp;
}
if(!strDVD.IsEmpty())
{
if((!m_CheckDate)&&(m_Renter.IsEmpty()))
temp.Format("DVDName = '%s'",strDVD);
else
temp.Format(" and DVDName = '%s'",strDVD);
strSQL+=temp;
}
_variant_t var;
CString strValue;
HRESULT hr;
int ItemNum=0;
try
{
hr=pRecordset->Open(_variant_t(strSQL),pConnection.GetInterfacePtr(),
adOpenDynamic,adLockOptimistic,adCmdText);
}
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
return;
}
if((pRecordset->adoEOF)&&(pRecordset->BOF))
{
MessageBox("沒有記錄!");
return;
}
try
{
while(!pRecordset->adoEOF)
{
var=pRecordset->GetCollect("ID");
if(var.vt!=VT_NULL)
strValue=(LPCSTR)_bstr_t(var);
m_RentList.InsertItem(ItemNum,strValue);
var=pRecordset->GetCollect("Name");
if(var.vt!=VT_NULL)
strValue=(LPCSTR)_bstr_t(var);
m_RentList.SetItemText(ItemNum,1,strValue);
var=pRecordset->GetCollect("DVDName");
if(var.vt!=VT_NULL)
strValue=(LPCSTR)_bstr_t(var);
m_RentList.SetItemText(ItemNum,2,strValue);
var=pRecordset->GetCollect("BNum");
if(var.vt!=VT_NULL)
strValue=(LPCSTR)_bstr_t(var);
m_RentList.SetItemText(ItemNum,3,strValue);
var=pRecordset->GetCollect("BDate");
if(var.vt!=VT_NULL)
strValue=(LPCSTR)_bstr_t(var);
m_RentList.SetItemText(ItemNum,4,strValue);
pRecordset->MoveNext();
ItemNum++;
}
}
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
pRecordset->Close();
pRecordset=NULL;
return;
}
}
void CCheckRentInfo::OnListallrent()
{
// TODO: Add your control notification handler code here
CRentInfoDlg dlg;
dlg.DoModal();
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -