上机部分,是属于比较难理解的一块, 其中不免会出现问题,耐心解决。 向身边的巨人 寻求帮助。
一 流程图。
二 注意部分
1.判断卡号是否注册,退卡,余额是否大于最小上机金额时,用到了student 表。
2.判断是否上机时,用到了Online表。
3.除了卡号的文本框以外,其他的文本框都不可输入
4.显示信息时将上机前的余额提出来,用于下机时计算余额
三 代码
Private Sub cmdOnLine_Click()
Dim mrc As ADODB.Recordset '连接student表中的
Dim txtSQL As String
Dim Msgtext As String
Dim mrcc As ADODB.Recordset '连接online表中的
Dim SQL As String
Dim Text As String
Dim mrccc As ADODB.Recordset '连接line表
'检查余额是否够(student表)
txtSQL = "select * from student_Info where cardno = '" & txtCardNo.Text & "'"
Set mrc = ExecuteSQL(txtSQL, Msgtext)
If mrc.EOF Then
MsgBox "没有这个卡号,请重新输入!", vbOKOnly + vbExclamation, "警告"
txtCardNo.Text = ""
mrc.Close
txtCardNo.SetFocus
Else
If Trim(mrc.Fields(10)) = "不使用" Then
MsgBox "没有此卡号"
Else
If Trim(Val(mrc.Fields(7))) <= 0 Then
MsgBox "余额不足,请充值"
txtCardNo.Text = ""
txtName.Text = ""
txtSex.Text = ""
txtSID.Text = ""
txtDept.Text = ""
txtType.Text = ""
txtOffDate.Text = ""
txtOnTime.Text = ""
txtOnDate.Text = ""
txtOffTime.Text = ""
txtCTime.Text = ""
txtCMoney.Text = ""
Else
'点击上机,下机时间和日期,消费时间和金额框中数据清空
txtOnDate.Text = ""
txtOnTime.Text = ""
txtCTime.Text = ""
txtCMoney.Text = ""
'检查上机是否重复
SQL = "select * from OnLine_Info where cardno = '" & txtCardNo.Text & "'"
Set mrcc = ExecuteSQL(SQL, Text)
If mrcc.EOF Then
'从student表中向各个文本框中添加上机的数据
mrc.Update
txtSID.Text = mrc.Fields(1)
txtName.Text = mrc.Fields(2)
txtSex.Text = mrc.Fields(3)
txtDept.Text = mrc.Fields(4)
txtBaLance.Text = mrc.Fields(7)
txtType.Text = mrc.Fields(14)
mrc.Close
'mrcc:on Line 如果没有查到数据,那么创建一个新行,添加各个数据
mrcc.AddNew
mrcc.Fields(0) = Trim(txtCardNo.Text)
mrcc.Fields(1) = txtType.Text
mrcc.Fields(2) = txtCardNo.Text
mrcc.Fields(3) = txtName.Text
mrcc.Fields(4) = txtDept.Text
mrcc.Fields(5) = txtSex.Text
mrcc.Fields(6) = Date
mrcc.Fields(7) = Time
mrcc.Fields(8) = "DEER"
startime = Now '获得系统时间
txtOnDate.Text = Format(startime, "yyyy/mm/dd")
txtOnTime.Text = Format(startime, "hh:mm:ss") '使用格式函数显示格式
mrcc.Update
'刷新line表中的数据
txtSQL = "select * from Line_Info where cardno = '" & txtCardNo.Text & "'"
Set mrccc = ExecuteSQL(txtSQL, Msgtext)
mrccc.AddNew
mrccc.Fields(1) = Trim(txtCardNo.Text)
mrccc.Fields(13) = "正常下机"
mrccc.Fields(2) = txtCardNo.Text
mrccc.Fields(3) = txtName.Text
mrccc.Fields(4) = txtDept.Text
mrccc.Fields(5) = txtSex.Text
mrccc.Fields(6) = Date
mrccc.Fields(7) = Time
mrccc.Fields(14) = "tzk"
mrccc.Update
MsgBox "上机成功", vbOKOnly + vbExclamation, "登陆成功"
Else
MsgBox "此用户正在上机"
End If
End If
End If
End If
End Sub