?? moneypay.cpp
字號:
// MoneyPay.cpp : implementation file
//
#include "stdafx.h"
#include "qq.h"
#include "MoneyPay.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#include <winuser.h>
/////////////////////////////////////////////////////////////////////////////
// CMoneyPay dialog
CMoneyPay::CMoneyPay(CWnd* pParent /*=NULL*/)
: CDialog(CMoneyPay::IDD, pParent)
{
//{{AFX_DATA_INIT(CMoneyPay)
m_nMoneyType = 1;
//}}AFX_DATA_INIT
bMoneyInSQL=false;
}
void CMoneyPay::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMoneyPay)
DDX_Control(pDX, IDC_SUBMONEY, SubMoney);
DDX_Control(pDX, IDC_PAYSUMMONEY, Sum);
DDX_Control(pDX, IDC_PAIDNUMMONEY, Paid);
DDX_Control(pDX, IDC_BILLCODEPAYMONEY, BillCode);
DDX_Radio(pDX, IDC_RADIO1, m_nMoneyType);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMoneyPay, CDialog)
//{{AFX_MSG_MAP(CMoneyPay)
ON_EN_CHANGE(IDC_BILLCODEPAYMONEY, OnBillcodeChange)
ON_EN_CHANGE(IDC_PAIDNUMMONEY, OnChangePaidmoney)
ON_BN_CLICKED(IDC_RADIO1, OnRadio)
ON_BN_CLICKED(IDC_RADIO2, OnRadio)
ON_WM_CREATE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMoneyPay message handlers
BOOL CMoneyPay::OnInitDialog()
{
CDialog::OnInitDialog();
HICON m_hIcon=AfxGetApp()->LoadIcon(IDR_MAINFRAME2);
this->SetIcon(m_hIcon,true);//設置對話框圖標
// TODO: Add extra initialization here
Sum.SetWindowText("0");
Paid.SetWindowText("0");
SubMoney.SetWindowText("0");
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CMoneyPay::OnBillcodeChange()
{
// 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 strBillCode="";
BillCode.GetWindowText(strBillCode);//獲得帳單文本
if(!m_BillInfoSet.Open())
{
MessageBox("打開數據庫失敗!","數據庫錯誤",MB_OK);
return;
}
bool bhas=false;
m_BillInfoSet.MoveFirst();//移動到第一條記錄
while (!m_BillInfoSet.IsEOF())
{
if(m_BillInfoSet.m_BillCode==strBillCode)
{//在數據庫中找到要付款的帳單號
bhas=true;
long nShouldMoney=0;
nShouldMoney=m_BillInfoSet.m_Sum-m_BillInfoSet.m_Paid;
if(nShouldMoney<=0)
{
MessageBox("你已經支付了這個帳單!","付款錯誤",MB_OK);
BillCode.SetWindowText("");
break;
}
else
{
CString strMoney;
strMoney.Format("%ld",nShouldMoney);
Sum.SetWindowText(strMoney);
break;
}
}
m_BillInfoSet.MoveNext();//移動到下一條記錄
}
m_BillInfoSet.Close();//關閉數據庫
if(!bhas)
{
Sum.SetWindowText("0");
return;
}
}
void CMoneyPay::OnChangePaidmoney()
{
// 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 strPaidMoney="",strSumMoney="";
Paid.GetWindowText(strPaidMoney);//得到當前的輸入文本
Sum.GetWindowText(strSumMoney); //得到當前要支付的總數
char* sPaid=strPaidMoney.GetBuffer(strPaidMoney.GetLength());
char* sSum=strSumMoney.GetBuffer(strSumMoney.GetLength());
long nSubMoney=0,nPaidMoney=0,nSumMoney=0;
nPaidMoney=atol(sPaid);
nSumMoney=atol(sSum);
nSubMoney=nPaidMoney-nSumMoney;
CString strSubMoney;
strSubMoney.Format("%ld",nSubMoney);
SubMoney.SetWindowText(strSubMoney);//計算剩余的錢
}
void CMoneyPay::OnOK()
{
// TODO: Add extra validation here
//保存記錄到數據庫中
CString strBillCode;
BillCode.GetWindowText(strBillCode);//得到當前的帳單號碼
CString strSubMoney;
SubMoney.GetWindowText(strSubMoney);
char* s=strSubMoney.GetBuffer(strSubMoney.GetLength());
long nmoney=atol(s);
if(!bMoneyInSQL)
{//如果不將剩下的錢存入到酒店中
if(nmoney>=0)
{
CString SQLstr;
SQLstr="select * from BillInfo where BillCode='";
SQLstr=SQLstr+strBillCode;
SQLstr=SQLstr+"'";
if(!m_BillInfoSet.Open(AFX_DB_USE_DEFAULT_TYPE,SQLstr))
{
MessageBox("打開數據庫失敗!","數據庫錯誤",MB_OK);
return;
}
m_BillInfoSet.Edit();//編輯數據庫
m_BillInfoSet.m_Paid=m_BillInfoSet.m_Sum;
m_BillInfoSet.m_Striked=true;
m_BillInfoSet.Update();//更新
m_BillInfoSet.Close();//關閉數據庫
}
else
{
CString SQLstr;
SQLstr="select * from BillInfo where BillCode='";
SQLstr=SQLstr+strBillCode;
SQLstr=SQLstr+"'";
if(!m_BillInfoSet.Open(AFX_DB_USE_DEFAULT_TYPE,SQLstr))
{
MessageBox("打開數據庫失敗!","數據庫錯誤",MB_OK);
return;
}
m_BillInfoSet.Edit();//編輯數據庫
m_BillInfoSet.m_Paid=m_BillInfoSet.m_Sum+nmoney;
m_BillInfoSet.m_Striked=true;
m_BillInfoSet.Update();//更新
m_BillInfoSet.Close();//關閉數據庫
}
}
else
{
CString SQLstr;
SQLstr="select * from BillInfo where BillCode='";
SQLstr=SQLstr+strBillCode;
SQLstr=SQLstr+"'";
if(!m_BillInfoSet.Open(AFX_DB_USE_DEFAULT_TYPE,SQLstr))
{
MessageBox("打開數據庫失敗!","數據庫錯誤",MB_OK);
return;
}
m_BillInfoSet.Edit();//編輯數據庫
m_BillInfoSet.m_Paid=m_BillInfoSet.m_Sum+nmoney;
m_BillInfoSet.m_Striked=true;
m_BillInfoSet.Update();//更新
m_BillInfoSet.Close();//關閉數據庫
}
CDialog::OnOK();
}
void CMoneyPay::OnRadio()
{
// TODO: Add your control notification handler code here
this->UpdateData(true);//更新數據
CString strSubMoney;
SubMoney.GetWindowText(strSubMoney);
char* s=strSubMoney.GetBuffer(strSubMoney.GetLength());
bool bBigZero=false;
long nmoney=atol(s);//得到余額的情況
if(nmoney>=0)
{
bBigZero=true;
}
else
{
bBigZero=false;
}
if(m_nMoneyType==0)
{//選擇的是"是"
if(bBigZero)
{
bMoneyInSQL=true;
}
else
{
bMoneyInSQL=false;
MessageBox("對不起,你沒有足夠的錢存入酒店!","存入錯誤",MB_OK);
}
}
if(m_nMoneyType==1)
{
bMoneyInSQL=false;
}
}
void CMoneyPay::OnCancel()
{
// TODO: Add extra cleanup here
CDialog::OnCancel();
}
int CMoneyPay::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CDialog::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
// AnimateWindow(GetSafeHwnd(),1000,AW_CENTER);
return 0;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -