📄 rentinfodlg.cpp
字号:
// RentInfoDlg.cpp : implementation file
//
#include "stdafx.h"
#include "Rent.h"
#include "RentInfoDlg.h"
#include "connectiondb.h"
#include "returndlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CRentInfoDlg dialog
CRentInfoDlg::CRentInfoDlg(CWnd* pParent /*=NULL*/)
: CDialog(CRentInfoDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CRentInfoDlg)
// NOTE: the ClassWizard will add member initialization here
Renter=_T("");
DVDName=_T("");
//}}AFX_DATA_INIT
}
void CRentInfoDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CRentInfoDlg)
DDX_Control(pDX, IDC_LISTRENT, m_RentInfoList);
//}}AFX_DATA_MAP
}
BOOL CRentInfoDlg::OnInitDialog()
{
CDialog::OnInitDialog();
m_RentInfoList.InsertColumn(0,"ID",LVCFMT_LEFT,30,-1);
m_RentInfoList.InsertColumn(1,"租借人",LVCFMT_LEFT,80,-1);
m_RentInfoList.InsertColumn(2,"DVD名",LVCFMT_LEFT,150,-1);
m_RentInfoList.InsertColumn(3,"租借数量",LVCFMT_LEFT,90,-1);
m_RentInfoList.InsertColumn(4,"租借日期",LVCFMT_LEFT,100,-1);
m_RentInfoList.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
// if(DVDName.IsEmpty()&&Renter.IsEmpty())
OninitRentInfoList();
return TRUE;
}
BEGIN_MESSAGE_MAP(CRentInfoDlg, CDialog)
//{{AFX_MSG_MAP(CRentInfoDlg)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CRentInfoDlg message handlers
void CRentInfoDlg::OninitRentInfoList()
{
m_RentInfoList.DeleteAllItems();
UpdateData(TRUE);
_RecordsetPtr recordset;
CConnectionDB *connectiondb=new CConnectionDB();
pConnection=connectiondb->GetConnectionPtr();
recordset.CreateInstance(__uuidof(Recordset));
_variant_t var;
CString strSQL;
CString strValue;
if(!DVDName.IsEmpty())
strSQL.Format("select * from DVDRentInfo where DVDName='%s'",DVDName);
else if(!Renter.IsEmpty())
strSQL.Format("select * from DVDRentInfo where Name='%s'",Renter);
else
strSQL="select * from DVDRentInfo";
int ItemNum=0;
try
{
recordset->Open(_variant_t(strSQL),pConnection.GetInterfacePtr(),
adOpenDynamic,adLockOptimistic,adCmdText);
}
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
return;
}
if(recordset->adoEOF&&recordset->BOF)
{
MessageBox("没有记录!");
CDialog::OnOK();
}
try
{
while(!recordset->adoEOF)
{
var=recordset->GetCollect("ID");
if(var.vt!=VT_NULL)
strValue=(LPCSTR)_bstr_t(var);
m_RentInfoList.InsertItem(ItemNum,strValue);
var=recordset->GetCollect("Name");
if(var.vt!=VT_NULL)
strValue=(LPCSTR)_bstr_t(var);
m_RentInfoList.SetItemText(ItemNum,1,strValue);
var=recordset->GetCollect("DVDName");
if(var.vt!=VT_NULL)
strValue=(LPCSTR)_bstr_t(var);
m_RentInfoList.SetItemText(ItemNum,2,strValue);
var=recordset->GetCollect("BNum");
if(var.vt!=VT_NULL)
strValue=(LPCSTR)_bstr_t(var);
m_RentInfoList.SetItemText(ItemNum,3,strValue);
var=recordset->GetCollect("BDate");
if(var.vt!=VT_NULL)
strValue=(LPCSTR)_bstr_t(var);
m_RentInfoList.SetItemText(ItemNum,4,strValue);
recordset->MoveNext();
ItemNum++;
}
}
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
return;
}
recordset->Close();
recordset=NULL;
delete connectiondb;
}
void CRentInfoDlg::OnItList()
{
/* CConnectionDB connection;
pConnection=connection.GetConnectionPtr();
CString strSQL;
if(!DVDName.IsEmpty())
strSQL.Format("select * from DVDRentInfo where DVDName='%s'",DVDName);
if(!Renter.IsEmpty())
strSQL.Format("select * from DVDRentInfo where DVDName='%s'",Renter);
_RecordsetPtr pRecordset;
pRecordset.CreateInstance(__uuidof(Recordset));
try
{
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;
}
else
{
CReturnDlg renturndlg;
_variant_t var;
try
{
var=pRecordset->GetCollect("Name");
if(var.vt!=VT_NULL)
renturndlg.m_OutRent=(LPCTSTR)_bstr_t(var);
var=pRecordset->GetCollect("DVDName");
if(var.vt!=VT_NULL)
renturndlg.m_OutDVD=(LPCTSTR)_bstr_t(var);
var=pRecordset->GetCollect("BNum");
if(var.vt!=VT_NULL)
renturndlg.m_OutNum=(LPCTSTR)_bstr_t(var);
var=pRecordset->GetCollect("BDate");
if(var.vt!=VT_NULL)
renturndlg.m_OutDate=(LPCTSTR)_bstr_t(var);
*/
}
void CRentInfoDlg::OnOK()
{
// TODO: Add extra validation here
if(!DVDName.IsEmpty()||!Renter.IsEmpty())
{
int sel;
sel=m_RentInfoList.GetSelectionMark();
if(sel<0)
{
MessageBox("请选择DVD!");
return;
}
else
{
HWND hWnd = ::FindWindow(NULL,"还碟信息");
CReturnDlg returndlg;
CReturnDlg::FindWindow("CReturnDlg","还碟信息");
returndlg.RentName=m_RentInfoList.GetItemText(sel,1);
returndlg.DVDName=m_RentInfoList.GetItemText(sel,2);
returndlg.Num=m_RentInfoList.GetItemText(sel,3);
returndlg.Date=m_RentInfoList.GetItemText(sel,4);
UpdateData(FALSE);
}
}
CDialog::OnOK();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -