?? roomdestine.cpp
字號:
// RoomDestine.cpp : implementation file
//
#include "stdafx.h"
#include "qq.h"
#include "RoomDestine.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CRoomDestine dialog
CRoomDestine::CRoomDestine(CWnd* pParent /*=NULL*/)
: CDialog(CRoomDestine::IDD, pParent)
{
//{{AFX_DATA_INIT(CRoomDestine)
m_DestineCerityType = 0;
m_SexType = 0;
//}}AFX_DATA_INIT
nDestineRoomSum=0;
}
void CRoomDestine::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CRoomDestine)
DDX_Control(pDX, IDC_ROOMDESTINE_BILLCODE, m_BillCode);
DDX_Control(pDX, IDC_ROOMDES_CERTIFYCODE, CerifyCode);
DDX_Control(pDX, IDC_ROOMNUM, m_DestineRoomSum);
DDX_Control(pDX, IDC_ROOMDESTINE_TYPE, m_RoomType);
DDX_Control(pDX, IDC_ROOMDESTINE_TIME, m_DestineTime);
DDX_Control(pDX, IDC_ROOMDESTINE_ROOMCODE, m_RoomCodeList);
DDX_Control(pDX, IDC_ROOMDESTINE_PRICE, m_RoomPrice);
DDX_Control(pDX, IDC_ROOMDESTINE_NAME, m_DestinerName);
DDX_Control(pDX, IDC_ROOMDESTINE_MONEY, m_DestineMoney);
DDX_Control(pDX, IDC_ROOMDESTINE_DESTINEBILL, m_DestineBill);
DDX_Radio(pDX, IDC_RADIO1, m_DestineCerityType);
DDX_Radio(pDX, IDC_RADIO4, m_SexType);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CRoomDestine, CDialog)
//{{AFX_MSG_MAP(CRoomDestine)
ON_CBN_SELCHANGE(IDC_ROOMDESTINE_TYPE, OnSelchangeRoomdestineType)
ON_BN_CLICKED(IDC_ADD, OnAdd)
ON_BN_CLICKED(IDC_DELETE, OnDelete)
ON_BN_CLICKED(IDC_RADIO1, OnRadio)
ON_BN_CLICKED(IDC_RADIO2, OnRadio)
ON_BN_CLICKED(IDC_RADIO3, OnRadio)
ON_BN_CLICKED(IDC_RADIO4, OnRadio)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CRoomDestine message handlers
BOOL CRoomDestine::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
m_RoomType.SetWindowText("標準單人房");
m_RoomType.AddString("標準單人房");//index==0
m_RoomType.AddString("標準雙人房");
m_RoomType.AddString("貴族單人房");
m_RoomType.AddString("貴族雙人房");//index==3
//產生帳單號碼
CCreateBillCode billcode;
m_BillCode.SetWindowText(billcode.GenereBillCode());
//////////////////////////////////////////////////////////////////////////
CTime time=CTime::GetCurrentTime();//構造時間對象
CTime tm(time);
int year,month,day,hour,minute,second;
year=tm.GetYear();
month=tm.GetMonth();
day=tm.GetDay();
hour=tm.GetHour();
minute=tm.GetMinute();
second=tm.GetSecond();
CString strYear,strMonth,strDay,strHour,strMinute,strSecond;
strYear.Format("%d",year);
strMonth.Format("%d",month);
strDay.Format("%d",day);
strHour.Format("%d",hour);
strMinute.Format("%d",minute);
strSecond.Format("%d",second);
CString strShowText;
strShowText=strYear+"-"+strMonth+"-"+strDay;
strShowText=strShowText+" "+strHour+":"+strMinute+":"+strSecond;
m_DestineTime.SetWindowText(strShowText);
//設置預定額為0
m_DestineMoney.SetWindowText("0");
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CRoomDestine::OnSelchangeRoomdestineType()
{
// TODO: Add your control notification handler code here
m_RoomCodeList.ResetContent();//清除所有的項目
CString strComboText;//combobox中的文本
m_RoomType.GetLBText(m_RoomType.GetCurSel(),strComboText);//獲得選擇的文本
/////////////////////////////////////////////////////////////////
// 進行數據庫的查詢
//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))
{//查詢數據庫得到數據集合
AfxMessageBox("打開數據庫失敗!");
return ;
}
CString str;
str.Format("%5.00f",m_RoomInfoSet.m_Price);
m_RoomPrice.SetWindowText(str);
m_RoomInfoSet.Close(); //關閉數據庫
/////////////////////////////////////////////////////////////
if(!m_RoomInfoSet.Open())
{
MessageBox("打開數據庫失敗!","數據庫錯誤",MB_OK);
return;
}
m_RoomInfoSet.MoveFirst();
while(!m_RoomInfoSet.IsEOF())
{
if(m_RoomInfoSet.m_RoomType==strComboText)
{
if(m_RoomInfoSet.m_RoomStatus=="空")
{
m_RoomCodeList.AddString(m_RoomInfoSet.m_RoomCode);
}
}
m_RoomInfoSet.MoveNext();
}
m_RoomInfoSet.Close();
////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
}
void CRoomDestine::OnAdd()
{
// TODO: Add your control notification handler code here
CString strRoomCode;
if(m_RoomCodeList.GetCount()==0)
{
return;
}
else
{
if(m_RoomCodeList.GetCurSel()!=-1)
{
m_RoomCodeList.GetText(m_RoomCodeList.GetCurSel(),strRoomCode);
}
}
if(m_RoomCodeList.GetCurSel()==-1)
{
MessageBox("你至少要選擇一項!","選擇項為空",MB_OK);
return;
}
if(m_RoomCodeList.GetCurSel()!=-1)
{
int n=m_DestineBill.GetCount();
CString strTemp=" ";
bool bSame=false;
if(n!=0)
{
for(int i=0;i<n;i++)
{
m_DestineBill.GetText(i,strTemp);
char* s=strTemp.GetBuffer(strTemp.GetLength());//there is a bug!
char* str=strtok(s," ");
str=strtok(NULL," ");
strTemp=str;
if(strTemp==strRoomCode)
{
MessageBox("你已經添加了這個房間!","選擇錯誤",MB_OK);
bSame=true;
return;
}
}
}
CString BillinfoText;
if(!bSame)
{
m_RoomType.GetWindowText(BillinfoText);
BillinfoText=BillinfoText+" "+strRoomCode;
m_DestineBill.AddString(BillinfoText);
nDestineRoomSum++;
CString strSum;
strSum.Format("%d",nDestineRoomSum);
m_DestineRoomSum.SetWindowText(strSum);
}
}
////////////////////////////////////////////////////////////////////
}
void CRoomDestine::OnDelete()
{
// TODO: Add your control notification handler code here
int nCurSel=m_DestineBill.GetCurSel();
if(nCurSel==-1)
{
MessageBox("請選擇一個要刪除的房間號","數據為空錯誤",MB_OK);
return;
}
m_DestineBill.DeleteString(nCurSel);
/////////更新顯示
nDestineRoomSum--;
CString strSum;
strSum.Format("%d",nDestineRoomSum);
m_DestineRoomSum.SetWindowText(strSum);
}
void CRoomDestine::OnOK()
{// [7/1/2003-11:21]
// TODO: Add extra validation here
/*
* 將下面的一些代碼放在OnOK()函數中是為了放在寫入到數據庫中時,證件類型或者
性別為空的情況的發生
若在OnRaido()函數中寫入這些代碼,如果使用者沒有點擊Radio按鈕的話,就不會進行
賦值的操作,從而導致寫入到數據庫中的為空
*/
UpdateData(TRUE);//狀態更新
if(m_DestineCerityType==0)
{
m_CerityTypeName="身份證";
}
if(m_DestineCerityType==1)
{
m_CerityTypeName="軍人證";
}
if(m_DestineCerityType==2)
{
m_CerityTypeName="學生證";
}
if(m_SexType==0)
{
m_DestinerSexType="男";
}
if(m_SexType==1)
{
m_DestinerSexType="女";
}
/*
* 先進行檢查,看是否有些項目為空
*/
CString strDestinerName,strDestinerMoney,strCerityCode,strBillCode,strDestinetime;
m_DestinerName.GetWindowText(strDestinerName);
m_DestineMoney.GetWindowText(strDestinerMoney);
CerifyCode.GetWindowText(strCerityCode);
m_BillCode.GetWindowText(strBillCode);
m_DestineTime.GetWindowText(strDestinetime);
if(atof(strDestinerMoney)<0)
{
MessageBox("必須要繳納預定金","預定金錯誤",MB_OK);
return;
}
if(m_DestineBill.GetCount()==0)
{
MessageBox("帳單為空","錯誤",MB_OK);
return;
}
if(strDestinerName==""||strDestinerMoney==""||strCerityCode=="")
{
MessageBox("請填寫完整","為空錯誤",MB_OK);
return;
}
////保存數據到數據庫中
if(!m_DestineRoomSet.Open())
{
MessageBox("數據庫打開失敗!","數據庫錯誤",MB_OK);
return;
}
bool bHadSameRecordSet=false;//是否已經有了這條記錄
m_DestineRoomSet.MoveFirst();
while (!m_DestineRoomSet.IsEOF())
{
if(strCerityCode==m_DestineRoomSet.m_CeritifyCode)
{
bHadSameRecordSet=true;
break;
}
m_DestineRoomSet.MoveNext();
}
m_DestineRoomSet.Close();//數據庫關閉
if(bHadSameRecordSet)
{
MessageBox("該客人已經預定了房間!","錯誤",MB_OK);
return;
}
else
{
//寫入到數據庫的表中
if(!m_DestineRoomSet.Open())
{
MessageBox("數據庫打開失敗!","數據庫錯誤",MB_OK);
return;
}
m_DestineRoomSet.AddNew();//添加一條新的記錄
m_DestineRoomSet.m_BillCode=strBillCode;//帳單號碼
m_DestineRoomSet.m_CeritifyCode=strCerityCode;
m_DestineRoomSet.m_Certificate=m_CerityTypeName;
m_DestineRoomSet.m_DestineMoney=strDestinerMoney;
m_DestineRoomSet.m_DestinerName=strDestinerName;
m_DestineRoomSet.m_DestinerSex=m_DestinerSexType;
m_DestineRoomSet.m_DestineTime=strDestinetime;
//寫入預定了哪些房間
CString strRoomCodes,strTemp;
for(int i=0;i<m_DestineBill.GetCount();i++)
{
m_DestineBill.GetText(i,strTemp);
char* s=strTemp.GetBuffer(strTemp.GetLength());//there is a bug!
char* str=strtok(s," ");
str=strtok(NULL," ");
strRoomCodes=strRoomCodes+str+",";
}
m_DestineRoomSet.m_DestineRoomCode=strRoomCodes;
m_DestineRoomSet.Update();//更新記錄
m_DestineRoomSet.Close();//關閉數據庫,寫入了一條新的記錄
//改寫CRoomInfoSet表中的信息
//將預定的房間的狀態改為“預定”
for(i=0;i<m_DestineBill.GetCount();i++)
{
CString strRoomCode;
m_DestineBill.GetText(i,strTemp);
char* s=strTemp.GetBuffer(strTemp.GetLength());//there is a bug!
char* str=strtok(s," ");
str=strtok(NULL," ");
strRoomCode=str;
if(!m_RoomInfoSet.Open())
{
MessageBox("數據庫打開失敗!","數據庫錯誤",MB_OK);
return;
}
m_RoomInfoSet.MoveFirst();
while (!m_RoomInfoSet.IsEOF())
{
if(strRoomCode==m_RoomInfoSet.m_RoomCode)
{
m_RoomInfoSet.Edit();
m_RoomInfoSet.m_RoomStatus="預定";
m_RoomInfoSet.Update();
}
m_RoomInfoSet.MoveNext();
}
m_RoomInfoSet.Close();
}
}
CDialog::OnOK();
}
void CRoomDestine::OnRadio()
{
// TODO: Add your control notification handler code here
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -