📄 hotelpropertypage1.cpp
字号:
// HotelPropertyPage1.cpp : implementation file
//
#include "stdafx.h"
#include "resource.h"
#include "HotelPropertyPage1.h"
#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif
IMPLEMENT_DYNCREATE(CHotelPropertyPage1, CPropertyPage)
IMPLEMENT_DYNCREATE(CHotelPropertyPage2, CPropertyPage)
/////////////////////////////////////////////////////////////////////////////
// CHotelPropertyPage1 property page
CHotelPropertyPage1::CHotelPropertyPage1() : CPropertyPage(CHotelPropertyPage1::IDD)
{
//{{AFX_DATA_INIT(CHotelPropertyPage1)
m_strLoc = _T("");
m_strNumAvail = _T("");
m_strPrice = _T("");
m_strNumRoom = _T("");
//}}AFX_DATA_INIT
}
CHotelPropertyPage1::~CHotelPropertyPage1()
{
}
void CHotelPropertyPage1::DoDataExchange(CDataExchange* pDX)
{
CPropertyPage::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CHotelPropertyPage1)
DDX_Control(pDX, IDC_LIST_HOTEL_AM, m_listHotelAM);
DDX_Text(pDX, IDC_EDIT_HOTEL_LOC, m_strLoc);
DDX_Text(pDX, IDC_EDIT_HOTEL_NUMAV, m_strNumAvail);
DDX_Text(pDX, IDC_EDIT_HOTEL_PRICE, m_strPrice);
DDX_Text(pDX, IDC_EDIT_HOTEL_NUMR, m_strNumRoom);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CHotelPropertyPage1, CPropertyPage)
//{{AFX_MSG_MAP(CHotelPropertyPage1)
ON_BN_CLICKED(IDC_BTN_HOTELA, OnBtnHotela)
ON_BN_CLICKED(IDC_BTN_HOTEL_M, OnBtnHotelM)
ON_NOTIFY(NM_CLICK, IDC_LIST_HOTEL_AM, OnClickListHotelAm)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CHotelPropertyPage2 property page
CHotelPropertyPage2::CHotelPropertyPage2() : CPropertyPage(CHotelPropertyPage2::IDD)
{
//{{AFX_DATA_INIT(CHotelPropertyPage2)
m_strLoc = _T("");
m_strPrice = _T("");
m_strCustName = _T("");
m_strResLoc = _T("");
m_strResNum = _T("");
//}}AFX_DATA_INIT
}
CHotelPropertyPage2::~CHotelPropertyPage2()
{
}
void CHotelPropertyPage2::DoDataExchange(CDataExchange* pDX)
{
CPropertyPage::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CHotelPropertyPage2)
DDX_Control(pDX, IDC_LIST_HOTEL_QR, m_listHotelQR);
DDX_Text(pDX, IDC_EDIT_HOTELQ_LOC, m_strLoc);
DDX_Text(pDX, IDC_EDIT_HOTELQ_PRICE, m_strPrice);
DDX_Text(pDX, IDC_EDIT_HOTELR_CUSTNAME, m_strCustName);
DDX_Text(pDX, IDC_EDIT_HOTELR_LOC, m_strResLoc);
DDX_Text(pDX, IDC_EDIT_HOTELR_NUMRES, m_strResNum);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CHotelPropertyPage2, CPropertyPage)
//{{AFX_MSG_MAP(CHotelPropertyPage2)
ON_BN_CLICKED(IDC_BTN_HOTEL_RES, OnBtnHotelRes)
ON_BN_CLICKED(IDC_BTN_HOTELQ, OnBtnHotelq)
ON_BN_CLICKED(IDC_RADIO1, OnRadio1)
ON_BN_CLICKED(IDC_RADIO2, OnRadio2)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
void CHotelPropertyPage1::OnBtnHotela()
{
// TODO: Add your control notification handler code here
CString strSQL;
UpdateData();//刷新数据,使编辑框中的值赋给字符串
if( m_strLoc.IsEmpty() )
{
MessageBox("宾馆地点不能为空!");
CWnd::GetDlgItem(IDC_EDIT_HOTEL_LOC)->SetFocus();
return;
}
if( m_strPrice.IsEmpty() )
{
m_strPrice = "0.00";
}
if( m_strNumRoom.IsEmpty() )
{
m_strNumRoom = "0";
}
if( m_strNumAvail.IsEmpty() )
{
m_strNumAvail = "0";
}
strSQL = "insert into HOTELS values \
('" + m_strLoc + "','" + m_strPrice + "','" \
+ m_strNumRoom + "','" + m_strNumAvail + "')";
((CTRSApp*)AfxGetApp())->db.BeginTrans();
try{
((CTRSApp*)AfxGetApp())->db.ExecuteSQL(strSQL);
}
catch(CDBException e)
{
e.ReportError();
((CTRSApp*)AfxGetApp())->db.Rollback();
return;
}
((CTRSApp*)AfxGetApp())->db.CommitTrans();
RefreshData();
}
void CHotelPropertyPage1::OnBtnHotelM()
{
// TODO: Add your control notification handler code here
int i = m_listHotelAM.GetSelectionMark();
CString strSQL;
if( i == -1 )
{
MessageBox("请选择一条记录!");
return;
}
else
{
UpdateData();
strSQL = "update HOTELS set price = " + m_strPrice + ",\
numRooms = " + m_strNumRoom + ",\
numAvail = " + m_strNumAvail + "\
where location = '" + m_strLoc +"'";
}
((CTRSApp*)AfxGetApp())->db.BeginTrans();
try{
((CTRSApp*)AfxGetApp())->db.ExecuteSQL(strSQL);
}
catch(CDBException e)
{
e.ReportError();
((CTRSApp*)AfxGetApp())->db.Rollback();
return;
}
((CTRSApp*)AfxGetApp())->db.CommitTrans();
RefreshData();
}
void CHotelPropertyPage2::OnBtnHotelRes()
{
// TODO: Add your control notification handler code here
UpdateData();
CString strSQL = "select numAvail from HOTELS where location = '" + m_strResLoc + "'";
if(m_strCustName.IsEmpty())
{
MessageBox("客户名不能为空!");
return;
}
if(m_strResLoc.IsEmpty())
{
MessageBox("宾馆地点不能为空!");
return;
}
if(m_strResNum.IsEmpty())
{
MessageBox("预定数量不能为空!");
return;
}
CRecordset rs(&(((CTRSApp*)AfxGetApp())->db));
rs.Open(CRecordset::forwardOnly,strSQL);
CDBVariant numAvail;
if( ! rs.IsEOF() )
{
rs.GetFieldValue("numAvail",numAvail);
if(numAvail.m_lVal - atoi(m_strResNum) >= 0)
{ //更新HOTELS表
strSQL.Format("update HOTELS set numAvail = %d where\
location='" + m_strResLoc+"'",numAvail.m_iVal - atoi(m_strResNum));
((CTRSApp*)AfxGetApp())->db.BeginTrans();
try{
((CTRSApp*)AfxGetApp())->db.ExecuteSQL(strSQL);
}
catch(CDBException e)
{
e.ReportError();
((CTRSApp*)AfxGetApp())->db.Rollback();
return;
}
((CTRSApp*)AfxGetApp())->db.CommitTrans();
//添加RESERVATIONS表
strSQL="insert into RESERVATIONS(custName,resvType)\
values('"+m_strCustName+"',2)";
// MessageBox(strSQL);
((CTRSApp*)AfxGetApp())->db.ExecuteSQL(strSQL);
RefreshData();
}
else
{
MessageBox("没有足够的房间!");
}
}
else
{
MessageBox("没有符合条件的宾馆!");
}
rs.Close();
}
void CHotelPropertyPage2::OnBtnHotelq()
{
// TODO: Add your control notification handler code here
CString strSQL;
int choice = CDialog::GetCheckedRadioButton(IDC_RADIO1,IDC_RADIO2);
UpdateData();
if( choice == IDC_RADIO1 )
{
if(m_strLoc.IsEmpty())
{
MessageBox("地点不能为空!");
return;
}
strSQL = "select * from HOTELS where location ='" + m_strLoc + "'";
}
else if( choice == IDC_RADIO2 )
{
if(m_strPrice.IsEmpty())
{
MessageBox("价格不能为空!");
return;
}
strSQL = "select * from HOTELS where price =" + m_strPrice;
}
else
{
strSQL = "select * from HOTELS";
}
CString location,price,numRooms,numAvail;
m_listHotelQR.DeleteAllItems();
CRecordset rs(&(((CTRSApp*)AfxGetApp())->db));
rs.Open(CRecordset::forwardOnly,strSQL);
int i=0;
while( ! rs.IsEOF() )
{
rs.GetFieldValue("location",location);
m_listHotelQR.InsertItem(i,location);
rs.GetFieldValue("price",price);
m_listHotelQR.SetItemText(i,1,price);
rs.GetFieldValue("numRooms",numRooms);
m_listHotelQR.SetItemText(i,2,numRooms);
rs.GetFieldValue("numAvail",numAvail);
m_listHotelQR.SetItemText(i,3,numAvail);
rs.MoveNext();
i++;
}
rs.Close();
}
BOOL CHotelPropertyPage1::OnInitDialog()
{
CPropertyPage::OnInitDialog();
// TODO: Add extra initialization here
m_listHotelAM.InsertColumn(0,"地点");
m_listHotelAM.InsertColumn(1,"价格");
m_listHotelAM.InsertColumn(2,"房间数");
m_listHotelAM.InsertColumn(3,"剩余房间");
RECT rect;
m_listHotelAM.GetWindowRect(&rect);
int rectWidth = rect.right - rect.left;
m_listHotelAM.SetColumnWidth(0,rectWidth/4);
m_listHotelAM.SetColumnWidth(1,rectWidth/4);
m_listHotelAM.SetColumnWidth(2,rectWidth/4);
m_listHotelAM.SetColumnWidth(3,rectWidth/4);
m_listHotelAM.SetExtendedStyle(LVS_EX_FULLROWSELECT);//单行选中
RefreshData();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
BOOL CHotelPropertyPage2::OnInitDialog()
{
CPropertyPage::OnInitDialog();
// TODO: Add extra initialization here
CWnd::GetDlgItem(IDC_EDIT_HOTELQ_LOC)->EnableWindow(false);
CWnd::GetDlgItem(IDC_EDIT_HOTELQ_PRICE)->EnableWindow(false);
m_listHotelQR.InsertColumn(0,"地点");
m_listHotelQR.InsertColumn(1,"价格");
m_listHotelQR.InsertColumn(2,"房间数");
m_listHotelQR.InsertColumn(3,"剩余房间");
RECT rect;
m_listHotelQR.GetWindowRect(&rect);
int rectWidth = rect.right - rect.left;
m_listHotelQR.SetColumnWidth(0,rectWidth/4);
m_listHotelQR.SetColumnWidth(1,rectWidth/4);
m_listHotelQR.SetColumnWidth(2,rectWidth/4);
m_listHotelQR.SetColumnWidth(3,rectWidth/4);
m_listHotelQR.SetExtendedStyle(LVS_EX_FULLROWSELECT);//单行选中
RefreshData();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CHotelPropertyPage1::OnClickListHotelAm(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
int i = m_listHotelAM.GetSelectionMark();
if( i == -1 )
{
MessageBox("请选择一条记录!");
return;
}
else //选中的记录出现在编辑框中
{
m_listHotelAM.SetHotItem(i);//选中的行高亮
m_strLoc = m_listHotelAM.GetItemText(i,0);
m_strPrice = m_listHotelAM.GetItemText(i,1);
m_strNumRoom = m_listHotelAM.GetItemText(i,2);
m_strNumAvail = m_listHotelAM.GetItemText(i,3);
UpdateData(false);
}
*pResult = 0;
}
void CHotelPropertyPage1::RefreshData()
{
CString location,price,numRooms,numAvail;
m_listHotelAM.DeleteAllItems();
CRecordset rs(&(((CTRSApp*)AfxGetApp())->db));
rs.Open(CRecordset::forwardOnly,"select * from HOTELS");
int i=0;
while( ! rs.IsEOF() )
{
rs.GetFieldValue("location",location);
m_listHotelAM.InsertItem(i,location);
rs.GetFieldValue("price",price);
m_listHotelAM.SetItemText(i,1,price);
rs.GetFieldValue("numRooms",numRooms);
m_listHotelAM.SetItemText(i,2,numRooms);
rs.GetFieldValue("numAvail",numAvail);
m_listHotelAM.SetItemText(i,3,numAvail);
rs.MoveNext();
i++;
}
rs.Close();
}
void CHotelPropertyPage2::RefreshData()
{
CString location,price,numRooms,numAvail;
m_listHotelQR.DeleteAllItems();
CRecordset rs(&(((CTRSApp*)AfxGetApp())->db));
rs.Open(CRecordset::forwardOnly,"select * from HOTELS");
int i=0;
while( ! rs.IsEOF() )
{
rs.GetFieldValue("location",location);
m_listHotelQR.InsertItem(i,location);
rs.GetFieldValue("price",price);
m_listHotelQR.SetItemText(i,1,price);
rs.GetFieldValue("numRooms",numRooms);
m_listHotelQR.SetItemText(i,2,numRooms);
rs.GetFieldValue("numAvail",numAvail);
m_listHotelQR.SetItemText(i,3,numAvail);
rs.MoveNext();
i++;
}
rs.Close();
}
void CHotelPropertyPage2::OnRadio1()
{
// TODO: Add your control notification handler code here
CWnd::GetDlgItem(IDC_EDIT_HOTELQ_LOC)->EnableWindow(true);
CWnd::GetDlgItem(IDC_EDIT_HOTELQ_PRICE)->EnableWindow(false);
}
void CHotelPropertyPage2::OnRadio2()
{
// TODO: Add your control notification handler code here
CWnd::GetDlgItem(IDC_EDIT_HOTELQ_LOC)->EnableWindow(false);
CWnd::GetDlgItem(IDC_EDIT_HOTELQ_PRICE)->EnableWindow(true);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -