?? chooseserver.cpp
字號:
// ChooseServer.cpp : implementation file
//
#include "stdafx.h"
#include "qq.h"
#include "ChooseServer.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CChooseServer dialog
CChooseServer::CChooseServer(CWnd* pParent /*=NULL*/)
: CDialog(CChooseServer::IDD, pParent)
{
//{{AFX_DATA_INIT(CChooseServer)
m_PaidType = -1;
//}}AFX_DATA_INIT
m_DefaultSum=0.00f;
bStriked=false;
}
void CChooseServer::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CChooseServer)
DDX_Control(pDX, IDC_EMPLOYER, EmployerCode);
DDX_Control(pDX, IDC_SERVERSUM, Sum);
DDX_Control(pDX, IDC_SERVERREBATE, Rebate);
DDX_Control(pDX, IDC_SERVERPAID, Paid);
DDX_Control(pDX, IDC_SERVERNUM, Num);
DDX_Control(pDX, IDC_SERVERLIST, ServerList);
DDX_Control(pDX, IDC_SERVERBILLLIST, ServerBillList);
DDX_Control(pDX, IDC_HANDCODE, HandCode);
DDX_Control(pDX, IDC_BILLCODEINSERVER, BillCode);
DDX_Radio(pDX, IDC_RADIO1, m_PaidType);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CChooseServer, CDialog)
//{{AFX_MSG_MAP(CChooseServer)
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_UPDATESERVERDATA, OnUpdatedata)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CChooseServer message handlers
BOOL CChooseServer::OnInitDialog()
{//初始化數(shù)據(jù)成員
CDialog::OnInitDialog();
HICON m_hIcon=AfxGetApp()->LoadIcon(IDR_MAINFRAME2);
this->SetIcon(m_hIcon,true);//設(shè)置對話框圖標(biāo)
// TODO: Add extra initialization here
//顯示帳單號碼
CCreateBillCode billcode;
BillCode.SetWindowText(billcode.GenereBillCode());
//顯示服務(wù)項目和價格
if(!m_ServerInfoSet.Open())
{
MessageBox("打開數(shù)據(jù)庫失敗!","數(shù)據(jù)庫錯誤",MB_OK);
return false;
}
m_ServerInfoSet.MoveFirst();//移動到第一條記錄
while (!m_ServerInfoSet.IsEOF())
{
CString strServerName="";
float nServerPrice=0.00f;
strServerName=m_ServerInfoSet.m_ServerName;
nServerPrice=m_ServerInfoSet.m_ServerPrice;
CString str;
str.Format("%6.00f",nServerPrice);
strServerName=strServerName+" "+str;
ServerList.AddString(strServerName);
m_ServerInfoSet.MoveNext();//移動到下一條記錄
}
m_ServerInfoSet.Close();//關(guān)閉數(shù)據(jù)庫
//設(shè)置缺省折扣率
Rebate.SetWindowText("1");
//將錢的總數(shù)設(shè)置為0
Sum.SetWindowText("0");
///Paid無效話
Paid.SetWindowText("0");
Paid.EnableWindow(FALSE);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CChooseServer::OnOK()
{
// TODO: Add extra validation here
/////保存數(shù)據(jù)到數(shù)據(jù)庫中
OnUpdatedata();//自動更新數(shù)據(jù),防止因為忘記更新或者其他的原因產(chǎn)生誤操作
CString strHandCode;
HandCode.GetWindowText(strHandCode);
if(strHandCode=="")
{
MessageBox("請輸入手牌號!","數(shù)據(jù)為空錯誤",MB_OK);
return;
}
/////如果選擇的是"現(xiàn)結(jié)"方式,而已經(jīng)付的金額為<0則提示輸入錯誤
CString strPaidTemp="";
Paid.GetWindowText(strPaidTemp);//得到已經(jīng)付的款
if(bStriked)
{
if(strPaidTemp==""||strPaidTemp=="0")
{
MessageBox("你可能輸入錯誤,客人已經(jīng)付的款應(yīng)該大于0!!","輸入信息錯誤",MB_OK);
return;
}
}
//查找客人數(shù)據(jù)庫中是否存在這個手牌號
if(!m_GuestInfoSet.Open(AFX_DB_USE_DEFAULT_TYPE))
{
AfxMessageBox("打開數(shù)據(jù)庫失敗!");
return;
}
m_GuestInfoSet.MoveFirst();
bool bhas=false;
while(!m_GuestInfoSet.IsEOF())
{
if(m_GuestInfoSet.m_HandCode==strHandCode)
{
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////
bhas=true;//存在這條記錄
break;
}
m_GuestInfoSet.MoveNext();//移動到下一條記錄
}
if(!bhas)
{
MessageBox("你輸入的手牌號不正確!","輸入信息錯誤",MB_OK);
m_GuestInfoSet.Close();//關(guān)閉數(shù)據(jù)庫
return;
}
m_GuestInfoSet.Close();//關(guān)閉數(shù)據(jù)庫
////////查詢完畢
//////////////////////////////////////////////////////////////////////////
/////將數(shù)據(jù)保存到相應(yīng)的數(shù)據(jù)庫中
/////寫B(tài)illInfoSet表
if(!m_BillInfoSet.Open())
{//打開數(shù)據(jù)庫失敗處理異常
MessageBox("打開數(shù)據(jù)庫失敗!","數(shù)據(jù)庫錯誤",MB_OK);
return;
}
/////新增加一條帳單的記錄
m_BillInfoSet.AddNew();
/////數(shù)據(jù)填充
CString strBillCode,strSum,strPaid,strRebate;
BillCode.GetWindowText(strBillCode);
m_BillInfoSet.m_BillCode=strBillCode;//帳單號碼
m_BillInfoSet.m_HandCode=strHandCode;//客人手牌
Sum.GetWindowText(strSum);
char* s=strSum.GetBuffer(strSum.GetLength());
long nSum=atol(s);
m_BillInfoSet.m_Sum=nSum;//應(yīng)付總數(shù)
Paid.GetWindowText(strPaid);
s=strPaid.GetBuffer(strPaid.GetLength());
long nPaid=atol(s);
m_BillInfoSet.m_Paid=nPaid;//實付總數(shù)
Rebate.GetWindowText(strRebate);
m_BillInfoSet.m_Rebate=strRebate;//折扣率there is a bug!!!!
m_BillInfoSet.m_Striked=bStriked;//是否已經(jīng)付款
m_BillInfoSet.Update();//數(shù)據(jù)更新
m_BillInfoSet.Close(); //關(guān)閉數(shù)據(jù)庫
//////////////////////////////////////////////////////////////////////////
// 開始寫B(tài)illContentInfo表,記錄這個帳單的具體消費情況
if(!m_BillContentInfoSet.Open())
{
MessageBox("打開數(shù)據(jù)庫失敗!","數(shù)據(jù)庫錯誤",MB_OK);
return;
}
m_BillContentInfoSet.AddNew();//新增一條記錄
CString strBillContent="";
for(int i=0;i<ServerBillList.GetCount();i++)
{
CString strTemp="";
ServerBillList.GetText(i,strTemp);
strBillContent=strBillContent+strTemp+",";
}
CString strBillcode;
BillCode.GetWindowText(strBillcode);
m_BillContentInfoSet.m_BillCode=strBillcode;
m_BillContentInfoSet.m_BillContent=strBillContent;
m_BillContentInfoSet.Update();//更新數(shù)據(jù)庫,將緩沖區(qū)的數(shù)據(jù)寫入數(shù)據(jù)庫中
m_BillContentInfoSet.Close();//關(guān)閉數(shù)據(jù)庫
CDialog::OnOK();
}
void CChooseServer::OnCancel()
{
// TODO: Add extra cleanup here
CDialog::OnCancel();
}
void CChooseServer::OnAdd()
{
// TODO: Add your control notification handler code here
int nCurSel=ServerList.GetCurSel();
if(nCurSel==-1)
{
MessageBox("請選擇至少一種服務(wù)!","數(shù)據(jù)為空錯誤",MB_OK);
return;
}
CString strServerNum;
Num.GetWindowText(strServerNum);
if(strServerNum==""||strServerNum=="0")
{
MessageBox("數(shù)量至少要為一","數(shù)據(jù)為空錯誤",MB_OK);
return;
}
CString strServerName="";
ServerList.GetText(nCurSel,strServerName);//得到文本
char* s=strServerName.GetBuffer(strServerName.GetLength());
char* str=strtok(s," ");//得到菜的名字
bool bSame=false;
for(int i=0;i<ServerBillList.GetCount();i++)
{
CString strTemp="";
ServerBillList.GetText(i,strTemp);//得到文本
char* temp=strTemp.GetBuffer(strTemp.GetLength());//得到緩沖區(qū)字符
char* bSameText=strtok(temp," ");
if(*bSameText==*str)//找到一個相同的項目
{
bSame=true;
MessageBox("你已經(jīng)選了這個服務(wù)!","選擇錯誤",MB_OK);
return;
}
}
if(!bSame)//若沒有相同的項目則添加新的記錄
{
strServerName=str;//構(gòu)造顯示文本
CString strEmployerCode;//服務(wù)員ID
EmployerCode.GetWindowText(strEmployerCode);
if(strEmployerCode=="")
{//服務(wù)員ID為空
MessageBox("請輸入服務(wù)人員的ID","數(shù)據(jù)為空錯誤",MB_OK);
return;
}
///查詢服務(wù)員表看看是否存在這個服務(wù)員
CString SQLstr="";
bool bHasTheEmployerCode=false;
CString strEmployerName="";
if(!m_EmployerInfoSet.Open())
{
MessageBox("打開數(shù)據(jù)庫失敗!","數(shù)據(jù)庫錯誤",MB_OK);
return;
}
m_EmployerInfoSet.MoveFirst();
while (!m_EmployerInfoSet.IsEOF())
{
if(m_EmployerInfoSet.m_EmployerCode==strEmployerCode)
{
bHasTheEmployerCode=true;
strEmployerName=m_EmployerInfoSet.m_Name;
break;
}
m_EmployerInfoSet.MoveNext();//移動到下一條記錄
}
m_EmployerInfoSet.Close();//關(guān)閉數(shù)據(jù)庫
if(bHasTheEmployerCode)
{
strServerName=strServerName+" "+strServerNum+" "+strEmployerName;
ServerBillList.AddString(strServerName);//添加字符竄
}
else
{
MessageBox("該服務(wù)員的代號不存在!","信息錯誤",MB_OK);
return;
}
}
/////////////////////添加一個項目完成
////////////////////////////////////////////////////////////////////
/*########################計算當(dāng)前應(yīng)付的總款#########################
####################################################################*/
float MoneySum=0;//總錢數(shù)目
for( i=0;i<ServerBillList.GetCount();i++)
{
//取得當(dāng)前文本
CString BillListText="";
ServerBillList.GetText(i,BillListText);//取得文本
//將取得的文本進(jìn)行轉(zhuǎn)換(char*)
char* billlistText=BillListText.GetBuffer(BillListText.GetLength());
char* ServerNameInBillList,*ServerNumInBillList;
//分別取得對應(yīng)的數(shù)據(jù)
ServerNameInBillList=strtok(billlistText," ");//食物名字
ServerNumInBillList=strtok(NULL," "); //食物數(shù)量
//根據(jù)菜單的名字查找相應(yīng)的價錢
CString SQLstr;
SQLstr="select * from ServerInfo where ServerName='";
SQLstr=SQLstr+ServerNameInBillList;
SQLstr=SQLstr+"'";
if(!m_ServerInfoSet.Open(AFX_DB_USE_DEFAULT_TYPE,SQLstr))
{
MessageBox("打開數(shù)據(jù)庫失敗!","數(shù)據(jù)庫錯誤",MB_OK);
return;
}
float nMoney=m_ServerInfoSet.m_ServerPrice;//得到價錢
m_ServerInfoSet.Close();//關(guān)閉數(shù)據(jù)庫
//////////////////////////////////////////////////////////////////////////
///計算總數(shù)
long serverNum=0;
serverNum=atoi(ServerNumInBillList);//食物數(shù)量
MoneySum=MoneySum+nMoney*serverNum;
}
////將計算得到的總數(shù)再乘以折扣率
m_DefaultSum=MoneySum;//設(shè)置缺省的總數(shù)
float rebate=0.00f;
CString strText;
Rebate.UpdateData(true);
Rebate.GetWindowText(strText);
if(strText=="")
{
MessageBox("請輸入折扣率!","數(shù)據(jù)為空錯誤",MB_OK);
return;
}
char* sTemp=strText.GetBuffer(strText.GetLength());
rebate=atof(sTemp);
MoneySum=m_DefaultSum*rebate;//乘以折扣率
CString strSum="";
strSum.Format("%6.00f",MoneySum);
Sum.SetWindowText(strSum);//顯示總數(shù)
//#################################################################
}
void CChooseServer::OnDelete()
{
// TODO: Add your control notification handler code here
int nCount=ServerBillList.GetCount();
if(nCount==0)
{//當(dāng)前記錄為空
MessageBox("當(dāng)前沒有刪除的項目!","數(shù)據(jù)為空錯誤",MB_OK);
Sum.SetWindowText("0");
return;
}
int nCurSel=ServerBillList.GetCurSel();
if(nCurSel==-1)
{//沒有選擇一種菜
MessageBox("你應(yīng)該選擇一種要刪除的服務(wù)項目!","數(shù)據(jù)為空錯誤",MB_OK);
return;
}
else
{
ServerBillList.DeleteString(nCurSel);
}
/////刪除以后從新計算帳總數(shù)
int nNum=ServerBillList.GetCount();
float nMoney=0.00f;
for(int i=0;i<nNum;i++)
{
CString strItemText="";
ServerBillList.GetText(i,strItemText);//得到項目文本
char* str=strItemText.GetBuffer(strItemText.GetLength());
char* strServerName,*strServerNum;
strServerName=strtok(str," ");//得到項目的名字
strServerNum=strtok(NULL," ");//得到服務(wù)項目的數(shù)目
CString SQLstr;
SQLstr="select * from ServerInfo where ServerName='";
SQLstr=SQLstr+strServerName;
SQLstr=SQLstr+"'";
if(!m_ServerInfoSet.Open(AFX_DB_USE_DEFAULT_TYPE,SQLstr))
{
MessageBox("打開數(shù)據(jù)庫失敗!","數(shù)據(jù)庫錯誤",MB_OK);
return;
}
float nPrice=m_ServerInfoSet.m_ServerPrice;//得到價錢
m_ServerInfoSet.Close();//關(guān)閉數(shù)據(jù)庫
//////計算總數(shù)
long nServerNum=atoi(strServerNum);
nMoney=nMoney+nPrice*nServerNum;
}
//顯示更新后的總數(shù)
m_DefaultSum=nMoney;//設(shè)置缺省的總數(shù)
CString strShowText,strReabte;
Rebate.GetWindowText(strReabte);
char* s=strReabte.GetBuffer(strReabte.GetLength());
double n=atof(s);
strShowText.Format("%6.00f",m_DefaultSum*n);
Sum.SetWindowText(strShowText);
}
void CChooseServer::OnRadio()
{
// TODO: Add your control notification handler code here
this->UpdateData(true);
if(m_PaidType==0)
{
bStriked=true;
Paid.EnableWindow(true);
}
if(m_PaidType==1)
{
bStriked=false;
Paid.EnableWindow(false);
}
}
void CChooseServer::OnUpdatedata()
{
// TODO: Add your control notification handler code here
float MoneySum=0.00f;
float rebate=0.00f;
CString strText;
Rebate.GetWindowText(strText);//得到折扣率文本
if(strText=="")
{
MessageBox("請輸入折扣率!","數(shù)據(jù)為空錯誤",MB_OK);
return;
}
char* sRebateTemp=strText.GetBuffer(strText.GetLength());
rebate=atof(sRebateTemp);//轉(zhuǎn)變折扣率
MoneySum=m_DefaultSum*rebate;
CString strSum="";
strSum.Format("%6.00f",MoneySum);
Sum.SetWindowText(strSum);//顯示總數(shù)
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -