一、逻辑流程图
二、代码分享
Dim txtSQL As String
Dim txtSQL1 As String
Dim txtSQL2 As String
Dim MsgText As String
Dim mrc As adodb.Recordset '连接BD表
Dim mrc1 As adodb.Recordset '连接student表
Dim mrc2 As adodb.Recordset '连接Recharge表
Dim cash1 As Integer
Dim cash2 As Integer
Private Sub cmdExit_Click()
Unload Me
End Sub
Private Sub cmdOK_Click()
'判断是否输入卡号
If Not Testtxt(txtCardno.Text) Then
MsgBox "请输入卡号!", 48, "提示"
txtCardno.SetFocus
Exit Sub
End If
If Not IsNumeric(Trim(txtCardno.Text)) Then
MsgBox "卡号请输入数字!", 48, "提示"
txtCardno.Text = ""
txtCardno.SetFocus
Exit Sub
End If
'判断是否输入充值金额
If Not Testtxt(txtRecharge.Text) Then
MsgBox "请输入充值金额!", 48, "提示"
txtRecharge.SetFocus
Exit Sub
End If
'判断金额是否为数字
If Not IsNumeric(Trim(txtRecharge.Text)) Then
MsgBox "充值金额请输入数字!", 48, "提示"
txtRecharge.Text = ""
txtRecharge.SetFocus
Exit Sub
End If
'判断充值金额是否小于基础表最低金额
txtSQL = "select*from BasicData_Info"
Set mrc = ExecuteSQL(txtSQL, MsgText)
'充值金额与最低金额比较
If Val(txtRecharge.Text) < mrc.Fields(5) Then
MsgBox "充值金额不得小于最低金额,请重新输入!", 48, "提示"
txtRecharge.Text = ""
txtRecharge.SetFocus
Exit Sub
End If
'连接student表判断卡号是否存在
txtSQL1 = "select*from student_Info where cardno='" & Trim(txtCardno.Text) & "'"
Set mrc1 = ExecuteSQL(txtSQL1, MsgText)
If mrc1.EOF = True Then
MsgBox "该卡号不存在或者被停用,请重新输入!", 48, "提示"
txtCardno.Text = ""
txtCardno.SetFocus
Exit Sub
Else
cash1 = mrc1.Fields(7)
'更新recharge表
txtSQL2 = "select*from Recharge_Info"
Set mrc2 = ExecuteSQL(txtSQL2, MsgText)
mrc2.AddNew
mrc2.Fields(1) = mrc1.Fields(1)
mrc2.Fields(2) = mrc1.Fields(0)
mrc2.Fields(3) = Trim(txtRecharge.Text)
mrc2.Fields(4) = Date
mrc2.Fields(5) = Time
mrc2.Fields(6) = mrc1.Fields(9)
mrc2.Fields(7) = mrc1.Fields(10)
mrc2.Update
'将总金额更新到student表
cash2 = cash1 + Val(txtRecharge.Text)
mrc1.Fields(7) = cash2
mrc1.Update
'在txtnote中显示充值信息
txtNote.Text = "充值卡号:" & txtCardno.Text & vbCrLf & _
"原金额:" & cash1 & vbCrLf & _
"充值金额:" & txtRecharge.Text & vbCrLf & _
"现有金额:" & cash2 & vbCrLf & _
"充值日期:" & Date & vbCrLf & _
"充值时间:" & Time & vbCrLf & _
"充值教师:" & UserName
mrc.Close
mrc1.Close
mrc2.Close
MsgBox "充值成功!", 48, "提示"
txtCardno.Text = ""
txtRecharge.Text = ""
txtNote.Text = ""
End If
End Sub
代码仓库
vbCr=Chr(13) 回车符
vbLf=Chr(10) 换行符
vbCrLf=Chr(13) & Chr(10) 回车+换行符
例如vbcrlf使用方法:
response.write("hello!world!")输出为: hello!world! response.write("hello!"&vbcrlf&"world!")输出为: hello! world!