充值也很简单,
首先要在student表中查询是否存在该卡号;
若存在,就更新studet表中余额数;
最后还要更新recharge表中的钱数。
如图
Option Explicit
Private Sub cmdOK_Click()
Dim txtSQL As String
Dim txtSQL1 As String
Dim msgText1 As String
Dim msgText As String
Dim mrc As ADODB.Recordset
Dim mrca As ADODB.Recordset
Dim lastmoney As Single '存储上次余额
Dim addmoney As Single '存储增加的钱
Dim sunmoney As Single '存储总和
'检查卡是否为空
If Not Testtxt(txtcardno.Text) Then
MsgBox "请重新输入卡号!", 0 + 48, "提示"
txtcardno.Text = ""
txtcardno.SetFocus
Exit Sub
End If
If Not Testtxt(txtrecharge.Text) Then
MsgBox "请重新输入卡号!", 0 + 48, "提示"
txtrecharge.Text = ""
txtrecharge.SetFocus
Exit Sub
End If
'检查student表的卡号是否存在
txtSQL1 = "select * from student_Info where cardno= '" & txtcardno.Text & "'"
Set mrca = executeSQL(txtSQL1, msgText1)
lastmoney = Val(mrca.Fields(7))
addmoney = Val(txtrecharge.Text)
sunmoney = lastmoney + addmoney
If mrca.EOF Then
MsgBox "此卡不存在或没注册,请重新选择卡号!", 48, "提示"
txtcardno.Text = ""
txtcardno.SetFocus
Exit Sub
End If
txtInfo.Text = "充值卡号:" & Trim(mrca.Fields(0)) & vbCrLf _
& "上次卡内余额:" & lastmoney & vbCrLf _
& "现在卡内余额:" & sunmoney & vbCrLf _
& "充值时间:" & Time & vbCrLf _
& "充值老师:" & UserName
MsgBox "充值成功!", 0 + 48, "提示"
mrca.Fields(7) = sunmoney
mrca.Update
'更新ReCharge_Info信息
txtSQL = "select * from ReCharge_Info where cardno= '" & txtcardno.Text & "'"
Set mrc = executeSQL(txtSQL, msgText)
mrc.AddNew
mrc.Fields(1) = mrca.Fields(1)
mrc.Fields(2) = mrca.Fields(0)
mrc.Fields(3) = Trim(txtrecharge.Text)
mrc.Fields(4) = Format(Date, "yyyy-mm-dd")
mrc.Fields(5) = Format(Time, "hh:mm:ss")
mrc.Fields(6) = mrca.Fields(6)
mrc.Fields(7) = "未结账"
mrc.Update
mrca.Close
mrc.Close
End Sub
Private Sub cmdQuit_Click()
Unload Me
End Sub