www.pudn.com > hotel2003.rar > 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()  
{//初始化数据成员 
	CDialog::OnInitDialog(); 
	HICON m_hIcon=AfxGetApp()->LoadIcon(IDR_MAINFRAME2); 
	this->SetIcon(m_hIcon,true);//设置对话框图标 
	// TODO: Add extra initialization here 
	//显示帐单号码 
    CCreateBillCode billcode; 
	BillCode.SetWindowText(billcode.GenereBillCode()); 
	//显示服务项目和价格 
    if(!m_ServerInfoSet.Open()) 
	{ 
		MessageBox("打开数据库失败!","数据库错误",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();//关闭数据库 
	//设置缺省折扣率 
	Rebate.SetWindowText("1"); 
	//将钱的总数设置为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 
	/////保存数据到数据库中 
    OnUpdatedata();//自动更新数据,防止因为忘记更新或者其他的原因产生误操作 
	CString strHandCode; 
	HandCode.GetWindowText(strHandCode); 
    if(strHandCode=="") 
	{ 
		MessageBox("请输入手牌号!","数据为空错误",MB_OK); 
		return; 
	} 
	/////如果选择的是"现结"方式,而已经付的金额为<0则提示输入错误 
	CString strPaidTemp=""; 
	Paid.GetWindowText(strPaidTemp);//得到已经付的款 
	if(bStriked) 
	{ 
		if(strPaidTemp==""||strPaidTemp=="0") 
		{ 
			MessageBox("你可能输入错误,客人已经付的款应该大于0!!","输入信息错误",MB_OK); 
			return; 
		} 
	} 
	//查找客人数据库中是否存在这个手牌号 
	if(!m_GuestInfoSet.Open(AFX_DB_USE_DEFAULT_TYPE)) 
	{ 
		AfxMessageBox("打开数据库失败!"); 
		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();//关闭数据库  
		return; 
	} 
	m_GuestInfoSet.Close();//关闭数据库  
	////////查询完毕 
	////////////////////////////////////////////////////////////////////////// 
	/////将数据保存到相应的数据库中 
	/////写BillInfoSet表 
	if(!m_BillInfoSet.Open()) 
	{//打开数据库失败处理异常 
		MessageBox("打开数据库失败!","数据库错误",MB_OK); 
		return; 
	} 
	/////新增加一条帐单的记录 
	m_BillInfoSet.AddNew(); 
	/////数据填充 
	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;//应付总数 
	Paid.GetWindowText(strPaid); 
	s=strPaid.GetBuffer(strPaid.GetLength()); 
	long nPaid=atol(s); 
	m_BillInfoSet.m_Paid=nPaid;//实付总数 
	Rebate.GetWindowText(strRebate); 
	m_BillInfoSet.m_Rebate=strRebate;//折扣率there is a bug!!!! 
	m_BillInfoSet.m_Striked=bStriked;//是否已经付款 
	m_BillInfoSet.Update();//数据更新 
	m_BillInfoSet.Close(); //关闭数据库 
	////////////////////////////////////////////////////////////////////////// 
	//      开始写BillContentInfo表,记录这个帐单的具体消费情况 
	if(!m_BillContentInfoSet.Open()) 
	{ 
		MessageBox("打开数据库失败!","数据库错误",MB_OK); 
		return; 
	} 
	m_BillContentInfoSet.AddNew();//新增一条记录 
	CString strBillContent=""; 
	for(int i=0;iUpdateData(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("请输入折扣率!","数据为空错误",MB_OK); 
		return; 
	} 
	char* sRebateTemp=strText.GetBuffer(strText.GetLength()); 
	rebate=atof(sRebateTemp);//转变折扣率 
	MoneySum=m_DefaultSum*rebate; 
	CString strSum=""; 
	strSum.Format("%6.00f",MoneySum); 
	Sum.SetWindowText(strSum);//显示总数 
}