📄 saveget.cpp
字号:
// SAVEGET.cpp : implementation file
//
#include "stdafx.h"
#include "BankSystem.h"
#include "SAVEGET.h"
#include "BankSystemDlg.h"
#include "ADOConn.h"
#include <vector>
using namespace std;
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// SAVEGET dialog
SAVEGET::SAVEGET(CWnd* pParent /*=NULL*/)
: CDialog(SAVEGET::IDD, pParent)
{
//{{AFX_DATA_INIT(SAVEGET)
m_money = 0.0f;
flag=0;
//}}AFX_DATA_INIT
}
void SAVEGET::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(SAVEGET)
DDX_Text(pDX, IDC_MONEY, m_money);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(SAVEGET, CDialog)
//{{AFX_MSG_MAP(SAVEGET)
ON_BN_CLICKED(IDC_RADIO1, OnSave)
ON_BN_CLICKED(IDC_RADIO2, OnFetch)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// SAVEGET message handlers
void SAVEGET::OnSave()
{
flag=1;
theApp.transcode="存款";
//GetDlgItem(IDC_STATIC)->SetWindowText("存款金额:");
}
void SAVEGET::OnFetch()
{
flag=2;
theApp.transcode="取款";
//GetDlgItem(IDC_STATIC)->SetWindowText("取款金额:");
}
void SAVEGET::OnOK()
{
this->UpdateData(true);
ADOConn Conn;
Conn.OnInitADOConn();
_RecordsetPtr pRst;
CString sql,opName,randName,Time;
double bla;
_variant_t v;
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(flag==0)
{
AfxMessageBox("请选择操作");
return;
}
switch(flag)
{
case 1:
sql.Format("Update cardInfo set balance=\'%f\' where cardId=\'%s\'",bla+m_money,theApp.CARDID);
break;
case 2:
if(bla<m_money)
{
AfxMessageBox("余额不足");
return;
}
sql.Format("Update cardInfo set balance=\'%f\' where cardId=\'%s\'",bla-m_money,theApp.CARDID);
break;
}
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 + -