forked from boyuanH/Bank
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LoginDlg.cpp
310 lines (286 loc) · 7.05 KB
/
LoginDlg.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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
// LoginDlg.cpp : implementation file
//
#include "stdafx.h"
#include "Bank.h"
#include "LoginDlg.h"
#include "ADOConn.h"
#include "BankDlg.h"
#include "LoginDlg.h"
#include "RegisteDlg.h"
#include "EmployeeDlg.h"
#include "MangerDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CLoginDlg dialog
extern CString g_CustomerID;
extern int g_UserType;
CLoginDlg::CLoginDlg(CWnd* pParent /*=NULL*/)
: CDialog(CLoginDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CLoginDlg)
m_Password = _T("");
m_UserType = -1;
m_UserID = _T("");
//}}AFX_DATA_INIT
m_iLoginCount=0;
}
void CLoginDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CLoginDlg)
DDX_Text(pDX, IDC_PASSWORD, m_Password);
DDX_Radio(pDX, IDC_RADIO_CUSTOMER, m_UserType);
DDX_Text(pDX, IDC_USERID, m_UserID);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CLoginDlg, CDialog)
//{{AFX_MSG_MAP(CLoginDlg)
ON_BN_CLICKED(IDC_RADIO_CUSTOMER, OnRadioCustomer)
ON_BN_CLICKED(IDC_RADIO_EMPLOYEE, OnRadioEmployee)
ON_BN_CLICKED(IDC_BUTTON_REGIST, OnButtonRegist)
ON_BN_CLICKED(IDC_RADIO1, OnRadio1)
ON_WM_PAINT()
ON_WM_CTLCOLOR()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CLoginDlg message handlers
void CLoginDlg::OnOK()
{
// TODO: Add extra validation here
BOOL bLogOn=FALSE;
UpdateData(true);
if(m_UserID=="")
{
MessageBox("请输入账号!");
return;
}
if(m_Password=="")
{
MessageBox("请输入密码!");
return;
}
CADOConn m_ADOConn;
m_ADOConn.OnInitADOConn(); //打开数据库连接
_RecordsetPtr m_pRecordset;//定义记录集指针
CString strPswd;
_variant_t theValue; //取得相关属性值
if(m_UserType==1)//银行雇员登录
{
_bstr_t empSQL="Select * from employee where employee_id='"+m_UserID+"'";
m_pRecordset=m_ADOConn.GetRecordset(empSQL);
if(m_pRecordset->adoEOF) //入股记录集是空的
{
MessageBox("账号不存在");
return;
}
theValue=m_pRecordset->GetCollect("employee_pswd");
if(theValue.vt!=VT_NULL)
strPswd=(char *)_bstr_t(theValue);
if(strPswd==m_Password)
{
bLogOn=TRUE;
CBankApp* App=(CBankApp*)AfxGetApp();
}
if(bLogOn)
{
g_CustomerID=m_UserID;
g_UserType=m_UserType; //用户类型
EndDialog(IDOK);//登录成功,关闭对话框
CEmployeeDlg dlg;
dlg.DoModal();
}
else
{
m_iLoginCount++;
if(m_iLoginCount>=3)
{
MessageBox("用户信息不正确,输入错误密码超过三次,无法登录!");
this->EndDialog(0);
}
else
{
MessageBox("密码不正确,请重新输入!");
GetDlgItem(IDC_PASSWORD)->SetWindowText("");
return;
}
}
}
else if(m_UserType==0) //普通用户登录
{
_bstr_t custSQL="Select * from account where account_number='"+m_UserID+"'";
m_pRecordset=m_ADOConn.GetRecordset(custSQL);
if(m_pRecordset->adoEOF) //入股记录集是空的
{
MessageBox("该客户账号不存在");
return;
}
theValue=m_pRecordset->GetCollect("account_pswd");
if(theValue.vt!=VT_NULL)
strPswd=(char *)_bstr_t(theValue);
if(strPswd==m_Password)
{
bLogOn=TRUE;
CBankApp* App=(CBankApp*)AfxGetApp();
}
if(bLogOn)
{
g_CustomerID=m_UserID;
g_UserType=m_UserType;//用户类型
EndDialog(IDOK);//登录成功,关闭对话框
CBankDlg dlg;
dlg.DoModal();
}
else
{
m_iLoginCount++;
if(m_iLoginCount>=3)
{
MessageBox("用户信息不正确,输入错误密码超过三次,无法登录!");
this->EndDialog(0);
}
else
{
MessageBox("密码不正确,请重新输入!");
GetDlgItem(IDC_PASSWORD)->SetWindowText("");
return;
}
}
}
else //经理登录
{
_bstr_t manaSQL="Select * from manager where manager_id='"+m_UserID+"'";
m_pRecordset=m_ADOConn.GetRecordset(manaSQL);
if(m_pRecordset->adoEOF) //入股记录集是空的
{
MessageBox("账号不存在");
return;
}
theValue=m_pRecordset->GetCollect("manager_pswd");
if(theValue.vt!=VT_NULL)
strPswd=(char *)_bstr_t(theValue);
if(strPswd==m_Password)
{
bLogOn=TRUE;
CBankApp* App=(CBankApp*)AfxGetApp();
}
if(bLogOn)
{
g_CustomerID=m_UserID;
g_UserType=m_UserType;//用户类型
EndDialog(IDOK);//登录成功,关闭对话框
CMangerDlg dlg;
dlg.DoModal();
}
else
{
m_iLoginCount++;
if(m_iLoginCount>=3)
{
MessageBox("用户信息不正确,输入错误密码超过三次,无法登录!");
this->EndDialog(0);
}
else
{
MessageBox("密码不正确,请重新输入!");
GetDlgItem(IDC_PASSWORD)->SetWindowText("");
return;
}
}
}
m_ADOConn.ExitConnect();//断开数据源连接
CDialog::OnOK();
}
void CLoginDlg::OnRadioCustomer()
{
// TODO: Add your control notification handler code here
m_UserType=0;
}
void CLoginDlg::OnRadioEmployee()
{
// TODO: Add your control notification handler code here
m_UserType=1;
}
BOOL CLoginDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
m_btn.SubclassDlgItem(IDC_BUTTON_REGIST,this);
m_btn.SetIcon(IDI_ICON1);
m_btn.SetFlat(FALSE);
m_btn.SetAlign(CButtonST::ST_ALIGN_VERT);
m_btn.SetTooltipText(_T("This is a tooltip.\r\nMultiline!"));
CheckDlgButton(IDC_RADIO_CUSTOMER,BST_CHECKED);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CLoginDlg::OnButtonRegist()
{
// TODO: Add your control notification handler code here
CRegisteDlg rdlg;
rdlg.DoModal();
}
void CLoginDlg::OnCancel()
{
// TODO: Add extra cleanup here
if(MessageBox("确实要退出系统吗?","退出提示",MB_YESNO|MB_ICONQUESTION)==IDYES)
CDialog::OnCancel();
}
void CLoginDlg::OnRadio1()
{
// TODO: Add your control notification handler code here
m_UserType=2;
}
void CLoginDlg::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
CRect rect;
GetClientRect(&rect);
CDC dcMem;
dcMem.CreateCompatibleDC(&dc);
CBitmap bmpBackground;
bmpBackground.LoadBitmap(IDB_BITMAP1);
//IDB_BITMAP是你自己的图对应的ID
BITMAP bitmap;
bmpBackground.GetBitmap(&bitmap);
CBitmap *pbmpOld=dcMem.SelectObject(&bmpBackground);
dc.StretchBlt(0,0,rect.Width(),rect.Height(),&dcMem,0,0,\
bitmap.bmWidth,bitmap.bmHeight,SRCCOPY);
// Do not call CDialog::OnPaint() for painting messages
}
HBRUSH CLoginDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
if(pWnd->GetDlgCtrlID()==IDC_MAINSTATIC)
{
CFont font;
font.CreatePointFont(300,"宋体");
pDC->SelectObject(&font);
pDC->SetTextColor(RGB(255,255,0));
pDC->SetBkMode(TRANSPARENT);
return (HBRUSH)GetStockObject(HOLLOW_BRUSH);
}
if(pWnd->GetDlgCtrlID()==IDC_NAME)
{
CFont font;
font.CreatePointFont(100,"仿宋");
pDC->SelectObject(&font);
pDC->SetBkMode(TRANSPARENT);
pDC->SetTextColor(RGB(255,25,25));
pDC->SetBkColor(RGB(155,155,155));
return (HBRUSH)::GetStockObject(NULL_BRUSH);
}
if(nCtlColor == CTLCOLOR_STATIC)
{
pDC->SetTextColor(RGB(255,255,0));
pDC->SetBkMode(TRANSPARENT);
return (HBRUSH)::GetStockObject(NULL_BRUSH);
}
return hbr;
}