?? checkout.cpp
字號:
/*
//更新找錢窗口的數據
*/
OnChangeCheckoutPaid();
break;
}
else
{
StartTime.SetWindowText("");
Times.SetWindowText("0");
Sum.SetWindowText("0");
}
m_BillCheckoutInfoSet.MoveNext();//移動到下一條記錄
}
m_BillCheckoutInfoSet.Close();//關閉數據庫
/*###################### END ############################*/
}
void CCheckOut::OnEditchangeCheckoutHandcode()
{
// TODO: Add your control notification handler code here
//清除前面的記錄,重新進行計算
CString strHandCode="";
HandCode.GetWindowText(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);
/*
//更新找錢窗口的數據
*/
OnChangeCheckoutPaid();
break;
}
else
{
StartTime.SetWindowText("");
Times.SetWindowText("0");
Sum.SetWindowText("0");
}
m_BillCheckoutInfoSet.MoveNext();//移動到下一條記錄
}
m_BillCheckoutInfoSet.Close();//關閉數據庫
/*###################### END ############################*/
}
void CCheckOut::OnChangeCheckoutPaid()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
CString strSum,strPaid;
Sum.GetWindowText(strSum);
Paid.GetWindowText(strPaid);
long nSum=0,nPaid=0,nSub=0;
char* sSum,*sPaid;
sSum=strSum.GetBuffer(strSum.GetLength());
sPaid=strPaid.GetBuffer(strPaid.GetLength());
nSum=atol(sSum);
nPaid=atol(sPaid);
nSub=nPaid-nSum;
CString strSub;
strSub.Format("%ld",nSub);
SubMoney.SetWindowText(strSub);
}
void CCheckOut::OnOK()
{
// TODO: Add extra validation here
/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
保存數據到數據庫中
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/
CString strEndTime,strSum,strHandCode;
HandCode.GetWindowText(strHandCode);//手牌號碼
CurTime.GetWindowText(strEndTime);//得到當前時間,也就是結束時間
Sum.GetWindowText(strSum);
///////將結束實際寫到數據庫中
if(!m_BillCheckoutInfoSet.Open())
{
MessageBox("打開數據庫失敗!","數據庫錯誤",MB_OK);
return;
}
m_BillCheckoutInfoSet.MoveFirst();
while (!m_BillCheckoutInfoSet.IsEOF())
{
if(strHandCode==m_BillCheckoutInfoSet.m_HandCode)
{
if(!m_BillCheckoutInfoSet.m_Sum.IsEmpty())
{//已經寫了這個記錄
MessageBox("該客戶已經結帳了!","結帳錯誤",MB_OK);
m_BillCheckoutInfoSet.Close();//關閉數據庫停止查找
return;
}
else
{
CTime tm(year,month,day,hour,minute,second);
m_BillCheckoutInfoSet.Edit();
m_BillCheckoutInfoSet.m_EndTime=tm;
m_BillCheckoutInfoSet.m_Sum=strSum;
m_BillCheckoutInfoSet.Update();
}
}
m_BillCheckoutInfoSet.MoveNext();
}
m_BillCheckoutInfoSet.Close();
InitDate();//初始化數組
CDialog::OnOK();
}
void CCheckOut::InitDate()
{
for(int i=0;i<100;i++)
{
STRINGS[i]="";
}
}
void CCheckOut::OnCancel()
{
// TODO: Add extra cleanup here
CDialog::OnCancel();
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -