📄 exchange.cpp
字号:
// EXChange.cpp : implementation file
//
#include "stdafx.h"
#include "BankSystem.h"
#include "EXChange.h"
#include "ADOConn.h"
#include <vector>
using namespace std;
#include "BankSystemDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// EXChange dialog
EXChange::EXChange(CWnd* pParent /*=NULL*/)
: CDialog(EXChange::IDD, pParent)
{
//{{AFX_DATA_INIT(EXChange)
m_money = 0.0f;
//}}AFX_DATA_INIT
}
void EXChange::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(EXChange)
DDX_Control(pDX, IDC_COMBO1, m_select);
DDX_Text(pDX, IDC_EDIT1, m_money);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(EXChange, CDialog)
//{{AFX_MSG_MAP(EXChange)
ON_BN_CLICKED(IDC_NEXT, OnNext)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// EXChange message handlers
BOOL EXChange::OnInitDialog()
{
CDialog::OnInitDialog();
GetDlgItem(IDOK)->ShowWindow(SW_HIDE);
ADOConn Conn;
Conn.OnInitADOConn();
_RecordsetPtr pRst;
_variant_t v;
sql.Format("select * from cardInfo ");
pRst=Conn.GetRecordset((_bstr_t)sql);
if(pRst->adoEOF)
AfxMessageBox("error");
else
{
v=pRst->GetCollect("curType");
curtype=v.bstrVal;
}
GetDlgItem(IDC_BI)->SetWindowText(curtype);
sql.Format("select *from MoneyOP");
pRst=Conn.Execute((_bstr_t)sql);
while(!pRst->adoEOF)
{
v=pRst->GetCollect("MoneyName");
moneyname=v.bstrVal;
m_select.AddString(moneyname);
pRst->MoveNext();
}
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void EXChange::OnNext()
{
this->UpdateData(true);
ADOConn Conn;
Conn.OnInitADOConn();
_variant_t v;
_RecordsetPtr pRst;
CString sql,opName,randName,Time;
CString selectName,money,money1;
int iPos=m_select.GetCurSel();
if(iPos!=-1)
m_select.GetLBText(iPos,selectName);
else
{
AfxMessageBox("选择币种");
return;
}
sql.Format("select *from MoneyOP where MoneyName=\'%s\'",curtype);
pRst=Conn.GetRecordset((_bstr_t)sql);
if(pRst->adoEOF)
AfxMessageBox("error");
else
{
v=pRst->GetCollect("currency");
a1=v.dblVal;
}
sql.Format("select *from MoneyOP where MoneyName=\'%s\'",selectName);
pRst=Conn.GetRecordset((_bstr_t)sql);
if(pRst->adoEOF)
AfxMessageBox("error");
else
{
v=pRst->GetCollect("currency");
a2=v.dblVal;
}
money.Format("%f",m_money);
money1.Format("%f",(a1/a2)*m_money);
str="用"+money+curtype+"\n";
str+="兑换成"+money1+selectName+"\n";
GetDlgItem(IDC_INFO)->SetWindowText(str);
GetDlgItem(IDC_NEXT)->ShowWindow(SW_HIDE);
GetDlgItem(IDOK)->ShowWindow(!SW_HIDE);
}
void EXChange::OnOK()
{
ADOConn Conn;
Conn.OnInitADOConn();
_variant_t v;
_RecordsetPtr pRst;
double bla;
CString sql,opName,randName,Time;
sql.Format("select *from cardInfo where cardId=\'%s\'",theApp.CARDID);
pRst=Conn.GetRecordset((_bstr_t)sql);
if(pRst->adoEOF)
AfxMessageBox("error");
else
{
v=pRst->GetCollect("balance");
bla=v.dblVal;
}
if(bla<m_money)
{
AfxMessageBox("余额不足");
return;
}
sql.Format("Update cardInfo set balance=\'%f\' where cardId=\'%s\'",bla-m_money,theApp.CARDID);
Conn.Execute((_bstr_t)sql);
if(theApp.flag=="银行")
{
sql.Format("select * from operator,cardInfo,userInfo where cardInfo.cardId=\'%s\'and cardInfo.cardOwer=userInfo.userID and userInfo.bankId=Operator.BankId",theApp.CARDID);
try
{
pRst= Conn.Execute((_bstr_t)sql);
}
catch(_com_error &e)
{
AfxMessageBox(e.Description());
}
vector<CString>ID;
while(!pRst->adoEOF)
{
v=pRst->GetCollect("opId");
opName=v.bstrVal;
ID.push_back(opName);
pRst->MoveNext();
}
srand((unsigned)time(NULL));
int x = rand()%(ID.size());
randName=ID.at(x);
}
Time=Conn.GetCurrTime();
theApp.transmoney.Format("%f",m_money);
sql.Format("insert into transInfo(transCode,cardId,transMoney,transDate,transPlace,opId) values(\'%s\',\'%s\',\'%s\',\'%s\',\'%s\',\'%s\')",\
theApp.transcode,theApp.CARDID,theApp.transmoney,Time,theApp.flag,randName);
Conn.Execute((_bstr_t)sql);
MessageBox("成功");
CDialog::OnOK();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -