-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathAddUserDlg.cpp
167 lines (152 loc) · 4.18 KB
/
AddUserDlg.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
// AddUserDlg.cpp : implementation file
//
#include "stdafx.h"
#include "Bank.h"
#include "AddUserDlg.h"
#include "RegisteDlg.h"
#include "ADOConn.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAddUserDlg dialog
CAddUserDlg::CAddUserDlg(CWnd* pParent /*=NULL*/)
: CDialog(CAddUserDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CAddUserDlg)
m_AccountNum = _T("");
m_Amount = 0.0;
m_CustomerID = _T("");
m_Password = _T("");
m_Password2 = _T("");
m_BranchName = _T("");
//}}AFX_DATA_INIT
}
void CAddUserDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAddUserDlg)
DDX_Text(pDX, IDC_ACCOUNTNUM, m_AccountNum);
DDX_Text(pDX, IDC_AMOUNT, m_Amount);
DDX_Text(pDX, IDC_CUSTOMERID, m_CustomerID);
DDX_Text(pDX, IDC_PASSWORD, m_Password);
DDX_Text(pDX, IDC_PASSWORD2, m_Password2);
DDX_Text(pDX, IDC_BRANCHNAME, m_BranchName);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAddUserDlg, CDialog)
//{{AFX_MSG_MAP(CAddUserDlg)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CAddUserDlg message handlers
void CAddUserDlg::OnOK()
{
// TODO: Add extra validation here
UpdateData();
//检查客户是否存在,判断账号是否重复,密码是否为空,金额是否大于0
CRegisteDlg dlg;
if(dlg.CheckCustomerID(m_CustomerID)==1)//记录不存在
{
AfxMessageBox("该客户不存在,请注册后重新输入");
GetDlgItem(IDC_CUSTOMERID)->SetWindowText("");
GetDlgItem(IDC_ACCOUNTNUM)->SetWindowText("");
GetDlgItem(IDC_BRANCHNAME)->SetWindowText("");
GetDlgItem(IDC_PASSWORD)->SetWindowText("");
GetDlgItem(IDC_PASSWORD2)->SetWindowText("");
GetDlgItem(IDC_AMOUNT)->SetWindowText("");
return;
}
if(CheckAccountNum())
{
AfxMessageBox("该账号已经被注册过,请重新输入");
GetDlgItem(IDC_ACCOUNTNUM)->SetWindowText("");
GetDlgItem(IDC_BRANCHNAME)->SetWindowText("");
GetDlgItem(IDC_PASSWORD)->SetWindowText("");
GetDlgItem(IDC_PASSWORD2)->SetWindowText("");
GetDlgItem(IDC_AMOUNT)->SetWindowText("");
return;
}
if(!CheckBranch())
{
AfxMessageBox("该银行不存在,请重新输入");
GetDlgItem(IDC_BRANCHNAME)->SetWindowText("");
GetDlgItem(IDC_PASSWORD)->SetWindowText("");
GetDlgItem(IDC_PASSWORD2)->SetWindowText("");
GetDlgItem(IDC_AMOUNT)->SetWindowText("");
return;
}
if(m_Password!=m_Password2)
{
AfxMessageBox("两次输入的密码不一致,请重新输入");
GetDlgItem(IDC_PASSWORD)->SetWindowText("");
GetDlgItem(IDC_PASSWORD2)->SetWindowText("");
GetDlgItem(IDC_AMOUNT)->SetWindowText("");
return;
}
if(m_Amount<=0)
{
AfxMessageBox("输入的金额不足,请重新输入");
GetDlgItem(IDC_AMOUNT)->SetWindowText("");
return;
}
InsertAccountNum();
AfxMessageBox("该客户开户成功");
CDialog::OnOK();
}
int CAddUserDlg::CheckAccountNum()
{
_bstr_t vSQL;
vSQL="select * from account where account_number='"+m_AccountNum+"'";
CADOConn m_ADOConn;
_RecordsetPtr m_Recordset;
m_ADOConn.OnInitADOConn();
m_Recordset=m_ADOConn.GetRecordset(vSQL);
if(m_Recordset->adoEOF)//记录集空
{
m_ADOConn.ExitConnect();
return 0;
}
else
{
m_ADOConn.ExitConnect();
return 1;
}
}
void CAddUserDlg::InsertAccountNum()
{
_bstr_t accountSQL,depositorSQL;
CString str;
str.Format("%f",m_Amount);
accountSQL="insert into account(account_number,account_pswd,branch_name,balance)\
values('"+m_AccountNum+"','"+m_Password+"','"+m_BranchName+"','"+str+"')";
depositorSQL="insert into depositor(account_number,customer_id,account_type,access_date,\
amount) values('"+m_AccountNum+"','"+m_CustomerID+"','save',convert(varchar,getdate()\
,120),'"+str+"')";
CADOConn m_ADOConn;
m_ADOConn.OnInitADOConn();
m_ADOConn.ExecuteSQL(accountSQL); //将账号信息插入account表中
m_ADOConn.ExecuteSQL(depositorSQL);//将记录插入depositor表中
m_ADOConn.ExitConnect();
}
int CAddUserDlg::CheckBranch()
{
_bstr_t vSQL;
vSQL="select * from branch where branch_name='"+m_BranchName+"'";
CADOConn m_ADOConn;
_RecordsetPtr m_Recordset;
m_ADOConn.OnInitADOConn();
m_Recordset=m_ADOConn.GetRecordset(vSQL);
if(m_Recordset->adoEOF)//记录集空
{
m_ADOConn.ExitConnect();
return 0;
}
else
{
m_ADOConn.ExitConnect();
return 1;
}
}