forked from boyuanH/Bank
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LoanDlg.cpp
158 lines (142 loc) · 3.12 KB
/
LoanDlg.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
// LoanDlg.cpp : implementation file
//
#include "stdafx.h"
#include "Bank.h"
#include "LoanDlg.h"
#include "ADOConn.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CLoanDlg dialog
CLoanDlg::CLoanDlg(CWnd* pParent /*=NULL*/)
: CDialog(CLoanDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CLoanDlg)
m_BranchName = _T("");
m_CustomerID = _T("");
m_Amount = 0.0;
m_LoanNumber = _T("");
//}}AFX_DATA_INIT
}
void CLoanDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CLoanDlg)
DDX_Text(pDX, IDC_BRANCHNAME, m_BranchName);
DDX_Text(pDX, IDC_CUSTOMERID, m_CustomerID);
DDX_Text(pDX, IDC_AMOUNT, m_Amount);
DDX_Text(pDX, IDC_LOANNUMBER, m_LoanNumber);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CLoanDlg, CDialog)
//{{AFX_MSG_MAP(CLoanDlg)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CLoanDlg message handlers
void CLoanDlg::OnOK()
{
// TODO: Add extra validation here
UpdateData();
if(m_CustomerID==""||m_BranchName==""||m_LoanNumber=="")
{
AfxMessageBox("输入信息不完整,请重新输入");
return;
}
if(!CheckCustomerID())
{
AfxMessageBox("该客户不存在,请先注册");
return;
}
if(!CheckBranch())
{
AfxMessageBox("该银行不存在,请重新输入");
return;
}
if(CheckLoanNumber())
{
AfxMessageBox("该贷款号已经存在,请重新输入");
return;
}
if(m_Amount<=0)
{
AfxMessageBox("输入金额不正确,请重新输入");
return;
}
InsertLoan();
AfxMessageBox("成功为该客户受理贷款!");
CDialog::OnOK();
}
int CLoanDlg::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;
}
}
int CLoanDlg::CheckCustomerID()
{
_bstr_t vSQL;
vSQL="select * from customer where customer_id='"+m_CustomerID+"'";
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;
}
}
int CLoanDlg::CheckLoanNumber()
{
_bstr_t vSQL;
vSQL="select * from loan where loan_number='"+m_LoanNumber+"'";
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 CLoanDlg::InsertLoan()
{
_bstr_t loanSQL;
CString str;
str.Format("%f",m_Amount);
loanSQL="insert into loan(loan_number,customer_id,branch_name,loan_date,\
amount) values('"+m_LoanNumber+"','"+m_CustomerID+"','"+m_BranchName+"',\
convert(varchar,getdate(),120),'"+str+"')";
CADOConn m_ADOConn;
m_ADOConn.OnInitADOConn();
m_ADOConn.ExecuteSQL(loanSQL); //将账号信息插入loan表中
m_ADOConn.ExitConnect();
}