?? checkout.cpp
字號:
// CheckOut.cpp : implementation file
//
#include "stdafx.h"
#include "qq.h"
#include "CheckOut.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CCheckOut dialog
int CCheckOut::year=0;
int CCheckOut::month=0;
int CCheckOut::day=0;
int CCheckOut::hour=0;
int CCheckOut::minute=0;
int CCheckOut::second=0;
CString CCheckOut::STRINGS[100]={""};
CCheckOut::CCheckOut(CWnd* pParent /*=NULL*/)
: CDialog(CCheckOut::IDD, pParent)
{
//{{AFX_DATA_INIT(CCheckOut)
//}}AFX_DATA_INIT
}
void CCheckOut::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCheckOut)
DDX_Control(pDX, IDC_CHECKOUT_BILLCODE, BillCode);
DDX_Control(pDX, IDC_CHECKOUT_HANDCODE, HandCode);
DDX_Control(pDX, IDC_CHECKOUT_CURTIME, CurTime);
DDX_Control(pDX, IDC_CHECKOUT_TIMES, Times);
DDX_Control(pDX, IDC_CHECKOUT_SUM, Sum);
DDX_Control(pDX, IDC_CHECKOUT_SUBMONEY, SubMoney);
DDX_Control(pDX, IDC_CHECKOUT_STARTTIME, StartTime);
DDX_Control(pDX, IDC_CHECKOUT_PAID, Paid);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CCheckOut, CDialog)
//{{AFX_MSG_MAP(CCheckOut)
ON_CBN_EDITCHANGE(IDC_CHECKOUT_HANDCODE, OnEditchangeCheckoutHandcode)
ON_EN_CHANGE(IDC_CHECKOUT_PAID, OnChangeCheckoutPaid)
ON_CBN_SELCHANGE(IDC_CHECKOUT_HANDCODE, OnSelchangeCheckoutHandcode)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCheckOut message handlers
BOOL CCheckOut::OnInitDialog()
{
CDialog::OnInitDialog();
HICON m_hIcon=AfxGetApp()->LoadIcon(IDR_MAINFRAME2);
this->SetIcon(m_hIcon,true);//設置對話框圖標
// TODO: Add extra initialization here
///安裝匹配字符串
InitDate();//初始化數組
m_acCombo.Init(GetDlgItem(IDC_CHECKOUT_HANDCODE));
if(!m_GuestInfoSet.Open(AFX_DB_USE_DEFAULT_TYPE))
{
MessageBox("查詢數據庫失敗或者數據庫沒有連接!",
"數據庫錯誤",
MB_OK
);
return false;
}
m_GuestInfoSet.MoveFirst();//move to the first record
int i=0;
while(!m_GuestInfoSet.IsEOF())
{
STRINGS[i]=m_GuestInfoSet.m_HandCode;
m_GuestInfoSet.MoveNext();
i++;
}
m_GuestInfoSet.Close();//關閉數據庫
for (int j=0; (!STRINGS[j].IsEmpty()); j++)
{
m_acCombo.GetStringList().Add(STRINGS[j].GetBuffer(STRINGS[j].GetLength()));
}
//產生帳單號碼
CCreateBillCode billcode;
BillCode.SetWindowText(billcode.GenereBillCodeForCheckOut());
Sum.SetWindowText("0");
Paid.SetWindowText("0");
SubMoney.SetWindowText("0");
Times.SetWindowText("0");
//設置當前時間
CTime time=CTime::GetCurrentTime();//構造時間對象
CTime tm(time);
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;
CurTime.SetWindowText(strShowText);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CCheckOut::OnSelchangeCheckoutHandcode()
{
// TODO: Add your control notification handler code here
Sum.SetWindowText("0");
Paid.SetWindowText("0");
SubMoney.SetWindowText("0");
CString strHandCode="";
HandCode.GetLBText(HandCode.GetCurSel(),strHandCode);
//到數據庫中查找是否存在這個記錄
int Startyear=0; //得到年份
int Startmonth=0;
int Startday=0;
int Starthour=0;
int Startmini=0;
int Startsecond=0;
float nRoomPrice=0.00f;//房間的價格(total)
//////////////////////////////////////////////////////////////////////////
/*############### 顯示開始入住時間的查詢過程 ##################*/
if(!m_BillCheckoutInfoSet.Open())
{
MessageBox("打開數據庫失敗!","數據庫錯誤",MB_OK);
return;
}
m_BillCheckoutInfoSet.MoveFirst();//移動到第一條記錄
while (!m_BillCheckoutInfoSet.IsEOF())
{
if(strHandCode==m_BillCheckoutInfoSet.m_HandCode)
{//找到了這個手牌號碼,將這個記錄中的開始時間寫道對話框中
CTime strTime=m_BillCheckoutInfoSet.m_StartTime;
CString strTimeShow,strYear,strMonth,strDay,strHour,strMinute,strSecond;
Startyear=strTime.GetYear(); //得到年份
Startmonth=strTime.GetMonth();
Startday=strTime.GetDay();
Starthour=strTime.GetHour();
Startmini=strTime.GetMinute();
Startsecond=strTime.GetSecond();
strYear.Format("%d",Startyear);//格式化年份
strMonth.Format("%d",Startmonth);
strDay.Format("%d",Startday);
strHour.Format("%d",Starthour);
strMinute.Format("%d",Startmini);
strSecond.Format("%d",Startsecond);//格式化秒
strTimeShow=strYear+"-"+strMonth+"-"+strDay+" "+strHour
+":"+strMinute+":"+strSecond;
StartTime.SetWindowText(strTimeShow);
/////////////////////////////////////////////////////////////////
//計算入住的總時間
CString strStartTime,strEndTime;
long nHours=0,nMinutes=0;
StartTime.GetWindowText(strStartTime); //得到開始入住的時間
CurTime.GetWindowText(strEndTime);//得到當前的時間
if(strStartTime=="")
{
Times.SetWindowText("");
}
int dYears=0,dMonths=0,dDays=0,dMinutes=0,dHours=0,dSeconds=0;
dYears=year-Startyear;//得到年份的差值
dMonths=month-Startmonth;
dDays=day-Startday;
dHours=hour-Starthour;
dMinutes=minute-Startmini;
dSeconds=second-Startsecond;
//計算總的時間差
nHours=dYears*365*24+dMonths*30*24+dDays*24+dHours;
nMinutes=dMinutes+(int)dSeconds/60;
if(nMinutes<0)
{
nHours=nHours-1;
nMinutes=nMinutes+60;
}
CString strHours,strMinutes;
strHours.Format("%d",nHours);
strMinutes.Format("%d",nMinutes);
CString strTimes;
strTimes=strHours+":"+strMinutes;
Times.SetWindowText(strTimes);
/* 通過手牌號碼查找房間的號碼 */
if(!m_GuestInfoSet.Open())
{
MessageBox("打開數據庫失敗!","數據庫錯誤",MB_OK);
return;
}
m_GuestInfoSet.MoveFirst();//移動到第一條記錄
while (!m_GuestInfoSet.IsEOF())
{
if(strHandCode==m_GuestInfoSet.m_HandCode)
{//查找到相應的手牌號碼
CString strRoomCode;
strRoomCode=m_GuestInfoSet.m_RoomCode;//得到房間號碼
char* s=strRoomCode.GetBuffer(strRoomCode.GetLength());
char* strTokText=strtok(s,",");
/* 通過查找得到的房間號碼查看房間的價格 */
while(strTokText!=NULL)
{
CString strRoomCodeTok=strTokText;//得到房間號碼
if(!m_RoomInfoSet.Open())
{//打開房間表
MessageBox("打開數據庫失敗!","數據庫錯誤",MB_OK);
return;
}
m_RoomInfoSet.MoveFirst();//移動第一條記錄
while(!m_RoomInfoSet.IsEOF())
{
if(m_RoomInfoSet.m_RoomCode==strRoomCode)
{//找到了房間查看房間的價格
//將當前查找到的房間價格加入到總和中
nRoomPrice=nRoomPrice+m_RoomInfoSet.m_Price;
}
m_RoomInfoSet.MoveNext();//移動到下一條記錄
}
m_RoomInfoSet.Close();//查詢完畢關閉數據庫
//得到下一個房間號碼
strTokText=strtok(NULL,",");
}
}
m_GuestInfoSet.MoveNext();//移動到客人的下一條記錄
}
m_GuestInfoSet.Close();//關閉客人信息表
/////////計算住房間的費用
////計算方法為:房間費用=房間的價格*住的時間
float nRoomTotalPrice=0.00f;
/*
計算客人住房所用的總費用
*/
nRoomTotalPrice=(float)(nHours+(float)nMinutes/60)*nRoomPrice;
/* @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ */
/*
開始計算客人在酒店期間各種消費總數目
*/
/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
通過查找帳單來計算總的消費費用
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/
long nSumInCast=0;//消費的總費用
if(!m_BillInfoSet.Open())
{
MessageBox("打開數據庫失敗!","數據庫錯誤",MB_OK);
return;
}
m_BillInfoSet.MoveFirst();//first
while (!m_BillInfoSet.IsEOF())
{
if(strHandCode==m_BillInfoSet.m_HandCode)
{
nSumInCast=nSumInCast+m_BillInfoSet.m_Sum-m_BillInfoSet.m_Paid;
}
m_BillInfoSet.MoveNext();//移動到下一條記錄
}
m_BillInfoSet.Close();//關閉數據庫
/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
計算客人總的費用包括房間的錢和消費的錢
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/
CString strSum;
strSum.Format("%6.00f",nSumInCast+nRoomTotalPrice);
Sum.SetWindowText(strSum);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -