📄 move.cpp
字号:
// MOVE.cpp : implementation file
//
#include "stdafx.h"
#include "BankSystem.h"
#include "MOVE.h"
#include "ADOConn.h"
#include "BankSystemDlg.h"
#include <vector>
using namespace std;
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// MOVE dialog
MOVE::MOVE(CWnd* pParent /*=NULL*/)
: CDialog(MOVE::IDD, pParent)
{
//{{AFX_DATA_INIT(MOVE)
m_toID = _T("");
m_tomoney = 0.0f;
//}}AFX_DATA_INIT
}
void MOVE::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(MOVE)
DDX_Text(pDX, IDC_TOCARDID, m_toID);
DDX_Text(pDX, IDC_TOMONEY, m_tomoney);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(MOVE, CDialog)
//{{AFX_MSG_MAP(MOVE)
ON_BN_CLICKED(IDC_NEXT, OnNext)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// MOVE message handlers
void MOVE::OnNext()
{
this->UpdateData(true);
ADOConn Conn;
Conn.OnInitADOConn();
_RecordsetPtr pRst;
_bstr_t sql;
_variant_t v;
if(m_toID==theApp.CARDID)
{
AfxMessageBox("给自己转帐没意思");
return;
}
sql="select * from cardInfo,userInfo where cardId='"+m_toID+"'"+"and cardInfo.cardOwer=userInfo.userID";
pRst=Conn.GetRecordset(sql);
if(pRst->adoEOF)
{
AfxMessageBox("无此卡");
return;
}
else
{
v=pRst->GetCollect("userName");
cardName=v.bstrVal;
//MessageBox(cardName);
v=pRst->GetCollect("cardId");
cardID=v.bstrVal;
v=pRst->GetCollect("balance");
toM=v.dblVal+m_tomoney;
GetDlgItem(IDC_NEXT)->ShowWindow(SW_HIDE);
TOmoney.Format("%f",m_tomoney);
str="转给:"+cardName+"\n";
str+="金额:"+TOmoney+"\n";
//str+="他的余额:"+cardMoney;
GetDlgItem(IDC_BALANCE)->SetWindowText(str);
}
sql="select *from cardInfo where cardId='"+theApp.CARDID+"'";//本卡
pRst=Conn.GetRecordset(sql);
if(pRst->adoEOF)
AfxMessageBox("error");
else
{
v=pRst->GetCollect("balance");
localmoney=v.dblVal-m_tomoney;
}
if(localmoney<0)
{
AfxMessageBox("你的卡上余额不足!");
return;
}
theApp.transmoney.Format("%f",m_tomoney);
GetDlgItem(IDOK)->ShowWindow(!SW_HIDE);
}
void MOVE::OnOK()
{
this->UpdateData(true);
ADOConn Conn;
Conn.OnInitADOConn();
_RecordsetPtr pRst;
_variant_t v;
CString sql,opName,randName;
sql.Format("Update cardInfo set cardInfo.balance=\'%f\' where cardId=\'%s\'",toM,m_toID);
Conn.Execute((_bstr_t)sql);
sql.Format("Update cardInfo set balance=\'%f\'where cardId=\'%s\'",localmoney,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();
//AfxMessageBox(Time);
theApp.transcode="转帐";
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);
AfxMessageBox("转帐成功!");
CDialog::OnOK();
}
BOOL MOVE::OnInitDialog()
{
CDialog::OnInitDialog();
GetDlgItem(IDOK)->ShowWindow(SW_HIDE);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -