机房收费系统中查看学生上机状态 ,其功能就是查看 正在上机的学生,并将他们下机,下机方式有两种,一种是 全部下机, 另一种是选中下机, 其中选中下机 实现较为困难一点。 因为选中下机 一次 就要更新一次。 会出现一些莫名其妙的问题。
全部下机代码部分
'MSHFlexGrid1内数据循环删除
Do While Not MSHFlexGrid1.Rows = 1
otxtSQL = "select * from Online_Info where cardno='" & MSHFlexGrid1.TextMatrix(1, 0) & "'"
Set omrc = ExecuteSQL(otxtSQL, oMsgText)
stxtSQL = "select * from student_Info where cardno='" & MSHFlexGrid1.TextMatrix(1, 0) & "'"
Set Smrc = ExecuteSQL(stxtSQL, sMsgText)
On Error GoTo 1
consumetime = DateDiff("n", omrc.Fields(7), Time) '计算消费时长
If Trim(Smrc.Fields(1)) = "固定用户" Then '根据用户类型计算出消费金额
consume = consumetime / 2 '固定用户除以2元每分钟
Else
consume = consumetime / 3 '临时用户除以3元每分钟
End If
'更新student_Info 数据,用户余额更新
i = Trim(Smrc.Fields(7)) - consume
updatestxtSQL = "update student_Info set cash=" & i & " where cardno='" & MSHFlexGrid1.TextMatrix(1, 0) & "'"
Set updatesmrc = ExecuteSQL(updatestxtSQL, updatesMsgText)
'更新line_Info数据,添加下机记录
ltxtSQL = "select * from Line_Info "
Set lmrc = ExecuteSQL(ltxtSQL, lMsgText)
lmrc.AddNew
lmrc.Fields(1) = Trim(MSHFlexGrid1.TextMatrix(1, 0))
lmrc.Fields(2) = Trim(Smrc.Fields(1))
lmrc.Fields(3) = Trim(Smrc.Fields(2))
lmrc.Fields(4) = Trim(Smrc.Fields(4))
lmrc.Fields(5) = Trim(Smrc.Fields(3))
lmrc.Fields(6) = Trim(omrc.Fields(6))
lmrc.Fields(7) = Trim(omrc.Fields(7))
lmrc.Fields(8) = Format(Now(), "yyyy-MM-dd")
lmrc.Fields(9) = Format(Now(), "HH:mm:ss")
lmrc.Fields(10) = consumetime
lmrc.Fields(11) = consume
lmrc.Fields(12) = i
lmrc.Fields(13) = "正常下机"
lmrc.Fields(14) = Trim(StrCPN)
lmrc.Update
'更新online_Info数据,删除上机数据
deleotxtSQL = "delete from Online_Info where cardno='" & MSHFlexGrid1.TextMatrix(1, 0) & "'"
Set deleomrc = ExecuteSQL(deleotxtSQL, deleoMsgText)
MSHFlexGrid1.RemoveItem 1 '删除myflexgrid本行数据
Loop
1:
If Error = 3021 Then
End If
选中下机 :
On Error GoTo dateerr
With MSHFlexGrid1
'记录选中下机的卡号,在最后一行加了一个勾,将这些记录的所有的卡号信息全部存到数组sz中!
i = 0
For j = 1 To .Rows - 1
If .TextMatrix(j, 10) = "√" Then
sz(i) = .TextMatrix(j, 0) '存的是卡号
xh(i) = Val(j)
i = i + 1
End If
Next j
For z = 0 To i '数组是从0开始的
'更新了表online_info与表line info中的信息
txtsql = "select * from basicdata_info"
Set mrc3 = ExecuteSQL(txtsql, Msgtext)
txtsql = "select * from student_Info where cardno='" & Trim(sz(z)) & "'" & "and status='使用" & "'"
Set mrc4 = ExecuteSQL(txtsql, Msgtext)
txtsql = "select * from Online_Info where cardno='" & Trim(sz(z)) & "'"
Set mrc1 = ExecuteSQL(txtsql, Msgtext)
'计算消费时间
' consumetime = DateDiff("n", Trim(mrc1!Date), Now)
If Trim(mrc4!Type) = "固定用户" Then
consume = Trim(consumetime) / 2
Else
consume = Trim(consumetime) / 3
End If
'计算余额 (上机时候的余额显示减去消费金额)
txtCash = Val(mrc4!cash) - Val(consume)
If Val(Trim(txtCash)) < 0 Then
MsgBox "余额不足,不能下机,请充值后下机", , "提示"
Exit Sub
End If
'更新数据到line_info表
txtsql = "select * from line_Info where cardno='" & sz(z) & "'" & "and ontime='" & mrc1.Fields(7) & "'"
Set mrc2 = ExecuteSQL(txtsql, Msgtext)
mrc2.Fields(8) = Format(Now(), "yyyy-MM-dd")
mrc2.Fields(9) = Format(Now(), "HH:mm:ss")
mrc2.Fields(10) = Trim(consumetime)
mrc2.Fields(11) = Trim(consume)
mrc2.Fields(12) = Trim(txtCash)
mrc2.Fields(13) = "正常下机"
mrc2.Fields(14) = "Jeff"
mrc2.Update
MSHFlexGrid1.RemoveItem xh(s)
'更新表online_info
txtsql = "delete online_info where cardno='" & sz(z) & "'"
Set mrc = ExecuteSQL(txtsql, Msgtext)
Next z
dateerr:
If Err = 3021 Or Err = 13 Then
End If
End With