大家好,又见面了,我是你们的朋友全栈君。
具体思路如图
代码如下:
'判断卡号是否为空
If Not Testtxt(txtCardno.Text) Then
MsgBox "请输入卡号!", vbOKOnly + vbExclamation, "提示"
txtCardno.SetFocus
Exit Sub
End If
'新建查询
strSQL = "select status,studentNo,Cash,UserID,Ischeck from student_Info where cardno = '" & txtCardno.Text & "'"
Set mrc = ExecuteSQL(strSQL, msgText)
studentNo = Trim(mrc.Fields(1))
Cash = mrc.Fields(2)
UserID = mrc.Fields(3)
Ischeck = mrc.Fields(4)
'判断是否注册
If mrc.EOF Then
MsgBox "没有该卡号!", vbOKOnly + vbExclamation, "提示"
txtCardno.SetFocus
txtCardno.Text = ""
Exit Sub
'判断是否退卡
ElseIf Trim(mrc.Fields(0)) = Trim("不使用") Then
MsgBox "此卡已退卡!", 48, "提示"
txtCardno.SetFocus
txtCardno.Text = ""
Exit Sub
Else
'判断是否正在上机
strSQL = "select * from Online_Info where cardno= '" & txtCardno.Text & "'"
Set mrcO = ExecuteSQL(strSQL, msgText)
If Not mrcO.EOF Then
MsgBox "此卡正在上机,请先下机再退卡!", 48, "提示"
txtCardno.SetFocus
txtCardno.Text = ""
Exit Sub
End If
'更新student_Info表
strSQL = "update student_Info set status = '" & "不使用" & "'" & "where cardno = '" & txtCardno.Text & "'"
Set mrc2 = ExecuteSQL(strSQL, msgText)
strSQL = "update student_Info set cash= '" & Val(0) & "'" & "where cardno = '" & txtCardno.Text & "'"
Set mrcS = ExecuteSQL(strSQL, msgText)
'把数据插入到CancelCard_Info表
strSQL = "select * from CancelCard_Info"
Set mrcC = ExecuteSQL(strSQL, msgText)
mrcC.AddNew
mrcC.Fields(0) = studentNo
mrcC.Fields(1) = txtCardno.Text
mrcC.Fields(2) = Cash
mrcC.Fields(3) = Date
mrcC.Fields(4) = Time
mrcC.Fields(5) = UserID
mrcC.Fields(6) = Ischeck
mrcC.Update
mrcC.Close
txtReturnAmount.Text = Cash
txtMessage.Text = "退款卡号:" & txtCardno.Text & vbCrLf & vbCrLf & _
"应退款金额:" & Cash & vbCrLf & vbCrLf & _
"退款日期:" & CancelDate & vbCrLf & vbCrLf & _
"退款时间:" & CancelTime & vbCrLf & vbCrLf & _
"办理退卡老师:" & UserID
MsgBox "退卡成功!", vbOKOnly + vbExclamation, "提示"
End If
最后在往CancelCard_Info表中插入数据是,也可以使用 insert 语句
strSQL = "insert into CancelCard_Info values('" & studentNo & "','" & txtCardno.Text & "','" & Cash & "','" & Date & _
"','" & Time & "','" & UserID & "','" & Ischeck & "')"
Call ExecuteSQL(strSQL, msgText)
两种方法实现的功能是一样的,但是我们因为敲学生的问题,一开始都比较习惯用select语句,但是insert语句用起来也挺简单的。
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/105790.html原文链接:https://javaforall.cn
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有