【CSDN】【做了一个VB ATCIVEX组件(DLL),用来进行帐户透支验证操作,请大家帮我看看代码逻辑对不对】
Option Explicit
Private strServerName As String
Private conCheckAccount As Connection
Private rsCheckAccount As Recordset
Public strError As String
Private strSql As String
Private Sub getSQLServerName()
If GetSetting("OnlineBankingDB", "SQL Server Name", "ServerName") = "" Then
strServerName = InputBox("请输入数据库服务器名称")
SaveSetting "OnlineBankingDB", "SQL Server Name", "ServerName", strServerName
Else
strServerName = GetSetting("OnlineBankingDB", "SQL Server Name", "ServerName")
End If
End Sub
Private Sub connectionSQLServer()
Set conCheckAccount = New Connection
Set rsCheckAccount = New Recordset
On Error GoTo errorhandler
Call getSQLServerName
With conCheckAccount
.Provider = "sqloledb"
.ConnectionString = "user id=sa;" & _
"password=;" & _
"data source=" & strServerName & _
";initial catalog=OnlineBankingDB"
.Open
End With
Exit Sub
errorhandler:
MsgBox Err.Number & Err.Source & Err.Description
End Sub
Private Function Credit(strAccountTypeID As String, mCash As Double, mAccountBalance As Double) As Boolean
If rsCheckAccount.State = 1 Then rsCheckAccount.Close
rsCheckAccount.CursorLocation = adUseClient
strSql = "select * from AccountType"
rsCheckAccount.Open strSql, conCheckAccount, adOpenDynamic, adLockOptimistic
If rsCheckAccount.RecordCount > 0 Then
rsCheckAccount.MoveFirst
Do While Not rsCheckAccount.EOF
If rsCheckAccount("cAccountTypeID") = strAccountTypeID Then
If mCash > mAccountBalance Then '
If mCash - mAccountBalance < rsCheckAccount("mMaximumBalance") Then
strError = "警告,你已经进行了帐户透支,本次透支额为:" & CStr(mAccountBalance - mCash) & ",请及时存款"
Credit = True
Exit Do
Else
strError = "警告,帐户透支超过系统上限(" & rsCheckAccount("mMaximumBalance") & "),帐户取款操作被系统终止,请及时存款"
Credit = False
Exit Do
End If
Else
Credit = True
Exit Do
End If
End If
rsCheckAccount.MoveNext
Loop
Else
strError = "帐号非法"
Credit = False
End If
End Function
Public Function validate(strAccountNumber As String, mCash As Double) As Boolean
If strServerName = "" Then
getSQLServerName
End If
Call connectionSQLServer
If rsCheckAccount.State = 1 Then rsCheckAccount.Close
rsCheckAccount.CursorLocation = adUseClient
strSql = "select * from Customer where cAccountNumber ='" & strAccountNumber & "'"
rsCheckAccount.Open strSql, conCheckAccount, adOpenDynamic, adLockOptimistic
If rsCheckAccount.RecordCount > 0 Then
rsCheckAccount.MoveFirst
validate = Credit(rsCheckAccount("cAccountTypeID"), mCash, rsCheckAccount("mAccountBalance"))
Else
strError = "帐号非法"
validate = False
End If
End Function