Private Sub frostudown_Click()
Dim txt As Boolean '用来记录是否选中
Dim mrca As ADODB.Recordset '用来存储OnLine_info 的sql语句
Dim txtSQLa As String '用来接收返回的结果
Dim mrc2 As ADODB.Recordset '用来更新Line_info 的sql语句
Dim txtSQL2 As String '用来接收更新Line_info返回的结果
Dim mrconline As ADODB.Recordset '用来计算上机时间
Dim txtSQLonline As String
Dim mrcc As ADODB.Recordset '用来存储BasicData_Info 的sql语句
Dim txtSQLc As String '用来接收BasicData_Info返回的结果
Dim Rate As String '记录固定用户每小时费用
Dim tmpRate As String '记录临时用户每小时费用
Dim listTime As String '记录最小时间
Dim ConMoney As String '上机花费
Dim Cash As String '用来记录余额
Dim usertype As String '记录用户类型
Dim mrcb As ADODB.Recordset
Dim txtSQLb As String
Dim mrcd As ADODB.Recordset '用来更新line_info表存储记录
Dim txtSQLd As String '用来删除上机表的结果
Dim onlineMsgText As String '接受信息
m = MSHFlexGrid1.Rows - 1 '定义m变量为检索次数
For a = 1 To m '循环次数
If MSHFlexGrid1.TextMatrix(m, 5) = "√" And MSHFlexGrid1.TextMatrix(m, 0) <> "卡号" Then '检索有√标识的行
txtSQLc = "exec proc_BasicData_select"
Set mrcc = ExecuteSQL(txtSQLc, MsgText) '将设定的基本数据赋值给变量
Rate = mrcc.Fields(0)
tmpRate = mrcc.Fields(1)
listTime = mrcc.Fields(3)
mrcc.Close
txtSQLb = "exec proc_sutdentinfo_select @cardno = '" & MSHFlexGrid1.TextMatrix(m, 0) & "'"
Set mrcb = ExecuteSQL(txtSQLb, MsgText)
usertype = Trim(mrcb.Fields(10)) '将用户类型记录
Cash = Trim(mrcb.Fields(9)) '记录消费前账户余额
txtSQLonline = "exec proc_OnLine_info @cardno = '" & MSHFlexGrid1.TextMatrix(m, 0) & "'" '使用查询将所需要更新字段进行更新
Set mrconline = ExecuteSQL(txtSQLonline, MsgText)
consumtime = DateDiff("n", mrconline.Fields(9), Now) '计算消费时间,这里比较的数据库中的日期和时间在一起
If consumtime > listTime Then '如果上机时间大于设置的最小时间
If usertype = "固定用户" Then
ConMoney = Int((Rate * consumtime) / 60 + 1)
Else
ConMoney = Int((tmpRate * consumtime) / 60 + 1)
End If
balance = Cash - ConMoney '计算下机后的余额
Else
ConMoney = 0
balance = Cash
End If
mrcb.Fields(9) = Trim(Cash) '将余额更新到学生表
mrcb.Update
mrcb.Close
txtSQL2 = "exec proc_deplane @cardno = '" & MSHFlexGrid1.TextMatrix(m, 0) & "'" '使用查询将所需要更新字段进行更新
Set mrc2 = ExecuteSQL(txtSQL2, MsgText)
mrc2.Fields(0) = Date
mrc2.Fields(1) = Time
mrc2.Fields(2) = Trim(consumtime) '上机时间
mrc2.Fields(3) = Trim(ConMoney) '上机花费
mrc2.Fields(4) = "正常下机"
mrc2.Update
mrc2.Close
txtSQLd = "delete OnLine_Info where cardno = '" & MSHFlexGrid1.TextMatrix(m, 0) & "'" '上机成功后将上机表的信息删除
Set mrcd = ExecuteSQL(txtSQLd, onlineMsgText)
MSHFlexGrid1.RemoveItem 2
m = m - 1
txt = True
Else
m = m - 1
End If
Next
If txt = True Then
MsgBox "下机成功", vbOKCancel + vbExclamation, "提示"
Else
MsgBox "您未进行选择,或选择有误", vbOKCancel + vbExclamation, "提示"
End If
txt = False
End Sub
Private Sub MSHFlexGrid1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
Dim col As Integer '选中相应行时,在选中行的第6列显示√
If MSHFlexGrid1.TextMatrix(MSHFlexGrid1.Row, 5) = "√" Then
MSHFlexGrid1.TextMatrix(MSHFlexGrid1.Row, 5) = "" '恢复颜色
For col = 0 To MSHFlexGrid1.Cols - 1
MSHFlexGrid1.col = col
MSHFlexGrid1.CellBackColor = vbWhite
Next col
Else
MSHFlexGrid1.TextMatrix(MSHFlexGrid1.Row, 5) = "√" '改变颜色
For col = 0 To MSHFlexGrid1.Cols - 1
MSHFlexGrid1.col = col
MSHFlexGrid1.CellBackColor = &HFFFF00
Next col
End If
If MSHFlexGrid1.TextMatrix(MSHFlexGrid1.Row, 5) = "√" Then '如果有选中的则可以用
frostudown.Enabled = True
Else
frostudown.Enabled = False
End If
End Sub
使用するマシンを選択する方法は、クリックする列にマークを付けて選択し、そのカード番号を条件としてデータベースを変更することです。すべてのデバイスと大差ありません。要点は1つです。ディレクトリの最初の行を選択できません。適切な方法が見つからないため、指定されたセルをカード番号として直接判断します。機能も正常に実現されています。