做每个窗体之前最重要的是屡清思路,缕清思路的最好的方法就是画流程图,画流程图前要考虑做的窗体需要哪几个表。退卡中,要判断卡号是否存在肯定就用到了student表,退卡,肯定就用到了本身的退卡表,卡号需要判断是否上机,这时就用到了on_line正在上机表,如果在上机,就要先下机在退卡。
流程图:
代码如下:
Private Sub cmdOK_Click()
Dim txtsql As String
Dim msgtext As String
Dim mrc As ADODB.Recordset
Dim mrc1 As ADODB.Recordset
Dim mrc2 As ADODB.Recordset
Dim a, b, c, d, e As String
'判断卡号是否为空
If Trim(txtCardno.Text) = "" Then
MsgBox "卡号为空,请重新输入", vbExclamation, "警告"
txtCardno.SetFocus
Exit Sub
Else
'判断卡号是否为数字
If not IsNumeric(txtCardno.Text) Then
MsgBox "卡号不是数字,请重新输入!", vbExclamation, "警告"
txtCardno.Text = ""
txtCardno.SetFocus
End If
End If
'新建查询
txtsql = "select * from student_Info where cardno = '" & Trim(txtCardno.Text) & "'"
Set mrc = ExecuteSQL(txtsql, msgtext)
'判断卡号是否存在
If mrc.EOF = True Then
MsgBox "该卡号不存在,请重新输入!", vbExclamation, "警告"
txtCardno.Text = ""
txtCardno.SetFocus
End If
'判断卡号是否已经退卡
'新建查询
txtsql = "select * from OnLine_Info where cardno=' " & Trim(txtCardno.Text) & "' "
Set mrc1 = ExecuteSQL(txtsql, msgtext)
If mrc1.EOF = False Then
MsgBox "该卡没有下机,请下机后退卡!", vbExclamation, "警告"
txtCardno.Text = ""
txtCardno.SetFocus
End If
txtsql = "select * from CancelCard_Info"
Set mrc2 = ExecuteSQL(txtsql, msgtext)
'把学生表赋值给退卡表
with mrc2
mrc2.AddNew
mrc2.Fields(0) = Trim(mrc.Fields(1))
mrc2.Fields(1) = Trim(mrc.Fields(0))
mrc2.Fields(2) = Trim(mrc.Fields(7))
mrc2.Fields(3) = Date
mrc2.Fields(4) = Time
mrc2.Fields(5) = mrc.Fields(9)
mrc2.Fields(6) = mrc.Fields(11)
mrc.Fields(10) = "不使用"
mrc.Update '更新学生表
mrc2.Update '更新退卡表
end with
a = Val(mrc2.Fields(1)) '卡号
b = Val(mrc2.Fields(2)) '应退金额
c = Val(mrc2.Fields(3)) '退卡日期
d = Val(mrc2.Fields(4)) '退卡时间
e = Val(mrc2.Fields(5)) '操作员
Text3 = "退卡卡号:" & a & vbCrLf & "应退金额:" & b & vbCrLf & "退卡日期:" & c & vbCrLf & "退卡时间:" & Format(Now(), "HH:mm:ss") '获取当前时间
txtblackcash.Text = b '显示退卡金额
MsgBox "退卡成功!", vbOKOnly + vbExclamation, "警告"
代码部分写的不是很完善,后期会继续完善。