?? chooseroom.cpp
字號(hào):
// ChooseRoom.cpp : implementation file
//
#include "stdafx.h"
#include "qq.h"
#include "ChooseRoom.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CChooseRoom dialog
CChooseRoom::CChooseRoom(CWnd* pParent /*=NULL*/)
: CDialog(CChooseRoom::IDD, pParent)
{
//{{AFX_DATA_INIT(CChooseRoom)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void CChooseRoom::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CChooseRoom)
DDX_Control(pDX, IDC_HANDCODE, HandCode);
DDX_Control(pDX, IDC_BILLCODE, BillCode);
DDX_Control(pDX, IDC_ROOMSELNUM, RoomSelNum);
DDX_Control(pDX, IDC_ROOMSUM, RoomSum);
DDX_Control(pDX, IDC_ROOMBILLLIST, RoomBillList);
DDX_Control(pDX, IDC_ROOMCODELIST, RoomCodeList);
DDX_Control(pDX, IDC_ROOMPRICE, RoomPrice);
DDX_Control(pDX, IDC_ROOMTYPE, RoomType);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CChooseRoom, CDialog)
//{{AFX_MSG_MAP(CChooseRoom)
ON_CBN_SELCHANGE(IDC_ROOMTYPE, OnSelchangeRoomtype)
ON_BN_CLICKED(IDC_ADD, OnAdd)
ON_BN_CLICKED(IDC_DELETE, OnDelete)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CChooseRoom message handlers
BOOL CChooseRoom::OnInitDialog()
{
CDialog::OnInitDialog();
HICON m_hIcon=AfxGetApp()->LoadIcon(IDR_MAINFRAME2);
this->SetIcon(m_hIcon,true);//設(shè)置對(duì)話框圖標(biāo)
// TODO: Add extra initialization here
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
RoomType.SetWindowText("標(biāo)準(zhǔn)單人房");
RoomType.AddString("標(biāo)準(zhǔn)單人房");//index==0
RoomType.AddString("標(biāo)準(zhǔn)雙人房");
RoomType.AddString("貴族單人房");
RoomType.AddString("貴族雙人房");//index==3
//////////////////////////////////
//產(chǎn)生帳單號(hào)碼
CCreateBillCode billcode;
BillCode.SetWindowText(billcode.GenereBillCodeForCheckOut());
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CChooseRoom::OnSelchangeRoomtype()
{
// TODO: Add your control notification handler code here
///刪除以前的記錄 this is a bug!!!!
RoomCodeList.ResetContent();//清除所有的項(xiàng)目
CString strComboText;//combobox中的文本
RoomType.GetLBText(RoomType.GetCurSel(),strComboText);//獲得選擇的文本
/////////////////////////////////////////////////////////////////
// 進(jìn)行數(shù)據(jù)庫的查詢
//roomprice fill
CString SQLstr;
SQLstr="SELECT * FROM RoomInfo where RoomType='" ;
SQLstr=SQLstr+strComboText;
SQLstr=SQLstr+"'";
if(!m_RoomInfoSet.Open(AFX_DB_USE_DEFAULT_TYPE,SQLstr))
{//查詢數(shù)據(jù)庫得到數(shù)據(jù)集合
AfxMessageBox("打開數(shù)據(jù)庫失敗!");
return ;
}
CString str;
str.Format("%5.00f",m_RoomInfoSet.m_Price);
RoomPrice.SetWindowText(str);
m_RoomInfoSet.Close(); //關(guān)閉數(shù)據(jù)庫
/////////////////////////////////////////////////////////////
if(!m_RoomInfoSet.Open())
{
MessageBox("打開數(shù)據(jù)庫失敗!","數(shù)據(jù)庫錯(cuò)誤",MB_OK);
return;
}
m_RoomInfoSet.MoveFirst();
while(!m_RoomInfoSet.IsEOF())
{
if(m_RoomInfoSet.m_RoomType==strComboText)
{
if(m_RoomInfoSet.m_RoomStatus=="空")
{
RoomCodeList.AddString(m_RoomInfoSet.m_RoomCode);
}
}
m_RoomInfoSet.MoveNext();
}
m_RoomInfoSet.Close();
////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
int n=RoomCodeList.GetCount();
CString strRoomNum;
strRoomNum.Format("%d",n);
RoomSum.SetWindowText(strRoomNum);//設(shè)置總數(shù)窗口文本
}
void CChooseRoom::OnAdd()
{
// TODO: Add your control notification handler code here
//將roomcode info add to billinfolist
CString strRoomCode;
if(RoomCodeList.GetCount()==0)
{
return;
}
else
{
if(RoomCodeList.GetCurSel()!=-1)
{
RoomCodeList.GetText(RoomCodeList.GetCurSel(),strRoomCode);
}
}
if(RoomCodeList.GetCurSel()==-1)
{
MessageBox("請(qǐng)選擇一個(gè)房間","數(shù)據(jù)為空錯(cuò)誤",MB_OK);
return ;
}
CString BillinfoText=strRoomCode;
int n=RoomBillList.GetCount();
CString strTemp="";
bool bSame=false;
for(int i=0;i<n;i++)
{
RoomBillList.GetText(i,strTemp);
if(strTemp==strRoomCode)
{
MessageBox("你已經(jīng)選擇了這個(gè)房間!","選擇錯(cuò)誤",MB_OK);
bSame=true;
return;
}
}
if(!bSame)
{
RoomBillList.AddString(BillinfoText);
}
////////////////////////////////////////////////////////////////////
//統(tǒng)計(jì)當(dāng)前的帳單數(shù)目
int m=RoomBillList.GetCount();
CString strSelNum;
strSelNum.Format("%d",m);//必須再調(diào)用一次getcount()函數(shù)
RoomSelNum.SetWindowText(strSelNum);
}
void CChooseRoom::OnOK()
{//保存數(shù)據(jù)
// TODO: Add extra validation here
CString strHandCode;
HandCode.GetWindowText(strHandCode);
if(strHandCode=="")
{
MessageBox("請(qǐng)輸入手牌號(hào)!","數(shù)據(jù)為空錯(cuò)誤",MB_OK);
return;
}
CString strSelNum;
RoomSelNum.GetWindowText(strSelNum);
if(strSelNum=="")
{
MessageBox("你至少要選擇一個(gè)房間!","選擇錯(cuò)誤",MB_OK);
return;
}
if(!m_GuestInfoSet.Open(AFX_DB_USE_DEFAULT_TYPE))
{
MessageBox("打開數(shù)據(jù)庫失敗!","數(shù)據(jù)庫錯(cuò)誤",MB_OK);
return;
}
m_GuestInfoSet.MoveFirst();
bool bhas=false;
while(!m_GuestInfoSet.IsEOF())
{
if(m_GuestInfoSet.m_HandCode==strHandCode)
{
//////////////////////////////////////////////////////////////////////////
/// 數(shù)據(jù)填充
m_GuestInfoSet.Edit();//進(jìn)行編輯,寫入到緩沖區(qū)中
m_GuestInfoSet.m_RoomNum=strSelNum;//將當(dāng)前選擇的房間數(shù)目保存到數(shù)據(jù)庫中
CString strShowText="",strtemp="";
int num=RoomBillList.GetCount();
for(int i=0;i<num;i++)
{//調(diào)用RoomBillList.GetDlgITemText(i,strtemp)會(huì)失敗
RoomBillList.GetText(i,strtemp);
strShowText=strShowText+strtemp+",";
}
m_GuestInfoSet.m_RoomCode=strShowText;
m_GuestInfoSet.Update();//更新數(shù)據(jù)
bhas=true;//存在這條記錄
break;
}
m_GuestInfoSet.MoveNext();//移動(dòng)到下一條記錄
}
if(!bhas)
{
MessageBox("你輸入的手牌號(hào)不正確!","輸入信息錯(cuò)誤",MB_OK);
m_GuestInfoSet.Close();//關(guān)閉數(shù)據(jù)庫
return;
}
m_GuestInfoSet.Close();//關(guān)閉數(shù)據(jù)庫
////寫客房信息數(shù)據(jù)庫表
if(!m_RoomInfoSet.Open())
{
MessageBox("打開數(shù)據(jù)庫失敗!","數(shù)據(jù)庫錯(cuò)誤",MB_OK);
return;
}
CString strRoomRestor="";
for(int i=0;i<RoomBillList.GetCount();i++)
{
RoomBillList.GetText(i,strRoomRestor);
m_RoomInfoSet.MoveFirst();
while(!m_RoomInfoSet.IsEOF())
{
if(strRoomRestor==m_RoomInfoSet.m_RoomCode)
{
m_RoomInfoSet.Edit();//edit the DB
m_RoomInfoSet.m_RoomStatus="住人";//改變r(jià)oominfoset的roomstatus
CString SQLStr,strHandCode;
HandCode.GetWindowText(strHandCode);
SQLStr="select * from GuestInfo where HandCode='";
SQLStr=SQLStr+strHandCode;
SQLStr=SQLStr+"'";
if(!m_GuestInfoSet.Open(AFX_DB_USE_DEFAULT_TYPE,SQLStr))
{
MessageBox("打開數(shù)據(jù)庫失敗!","數(shù)據(jù)庫錯(cuò)誤",MB_OK);
return;
}
m_RoomInfoSet.m_PriceType=m_GuestInfoSet.m_IsMember;
m_GuestInfoSet.Close();//關(guān)閉客人信息數(shù)據(jù)庫
m_RoomInfoSet.Update();
}
m_RoomInfoSet.MoveNext();
}
}
m_RoomInfoSet.Close();//關(guān)閉數(shù)據(jù)庫
///將帳單號(hào)碼寫入BillCheckoutInfo表中
if(!m_BillCheckoutInfoSet.Open())
{
MessageBox("打開數(shù)據(jù)庫失敗!","數(shù)據(jù)庫錯(cuò)誤",MB_OK);
return;
}
m_BillCheckoutInfoSet.MoveFirst();//first
while (!m_BillCheckoutInfoSet.IsEOF())
{
if(strHandCode==m_BillCheckoutInfoSet.m_HandCode)
{
m_BillCheckoutInfoSet.Edit();//編輯數(shù)據(jù)庫
CString strBillCode;
BillCode.GetWindowText(strBillCode);//得到賬單號(hào)碼
m_BillCheckoutInfoSet.m_BillCode=strBillCode;
m_BillCheckoutInfoSet.Update();
}
m_BillCheckoutInfoSet.MoveNext();
}
m_BillCheckoutInfoSet.Close();//關(guān)閉數(shù)據(jù)庫
CDialog::OnOK();
}
void CChooseRoom::OnDelete()
{
// TODO: Add your control notification handler code here
int nCurSel=RoomBillList.GetCurSel();
if(nCurSel==-1)
{
MessageBox("請(qǐng)選擇一個(gè)要?jiǎng)h除的房間號(hào)","數(shù)據(jù)為空錯(cuò)誤",MB_OK);
return;
}
RoomBillList.DeleteString(nCurSel);
/////////更新顯示
int m=RoomBillList.GetCount();
CString strSelNum;
strSelNum.Format("%d",m);
RoomSelNum.SetWindowText(strSelNum);
}
void CChooseRoom::OnCancel()
{
// TODO: Add extra cleanup here
CDialog::OnCancel();
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -