【机房】学生上机状态查看

机房收费系统中的操作者可以查看学生上机状态

窗体界面:

在这里插入图片描述

查询

查询学生上机信息,用到了组合查询,点击阅读:组合查询

显示全部

在这里可以查看所有的上机账户
若是当前没有上机用户,那么就提示当前没有人员上机,并且后面的上机管理直接隐藏不可见。

Private Sub showAll_Click()
    Dim txtSQL As String
    Dim MsgText As String
    Dim mrc As ADODB.Recordset
    
    MSHFlexGrid1.Rows = 1
     
    txtSQL = "select * from online_info"
    Set mrc = ExecuteSQL(txtSQL, MsgText)
    
    
    '添加表头
    With MSHFlexGrid1
        .CellAlignment = 4
        .TextMatrix(0, 0) = "卡号"
        .TextMatrix(0, 1) = "姓名"
        .TextMatrix(0, 2) = "上机日期"
        .TextMatrix(0, 3) = "上机时间"
        .TextMatrix(0, 4) = "机器号"
        .TextMatrix(0, 5) = "选中标记"
    End With
    
    If mrc.EOF = True Then
        MsgBox "当前没有人员上机", 64, "温馨提示"
        computerManagement.Visible = False
    Else
        
        '判断是否移动到数据集对象的最后一条记录
        Do While Not mrc.EOF
        
            With MSHFlexGrid1
            
                .Rows = .Rows + 1
                .CellAlignment = 4
                .TextMatrix(.Rows - 1, 0) = mrc.Fields(0)
                .TextMatrix(.Rows - 1, 1) = mrc.Fields(3)
                .TextMatrix(.Rows - 1, 2) = mrc.Fields(6)
                .TextMatrix(.Rows - 1, 3) = mrc.Fields(7)
                .TextMatrix(.Rows - 1, 4) = mrc.Fields(8)
                mrc.MoveNext
                
            End With
        Loop
        mrc.Close
    End If
End Sub


上机管理

上机管理包括所有同学下机,选中同学下机

进行下机操作的时候,需要先判断是否有正在上机的人员,如果没有上机的人员就没有办法进行下机操作(需要连接数据库).
下机操作还需要判断用户类型,然后计算上机时长、计算费用。


Private Sub allOffLine_Click()
    Rem:连接Online表判断是否有上机的人员
    txtSQL = "select * from Online_info"
    Set mrcOnLine = ExecuteSQL(txtSQL, MsgText)
    
    Do While Not MSHFlexGrid1.Rows = 1
    
    If mrcOnLine.EOF = True Then
        MsgBox "没有人员上机,无法进行下机操作", 64, "温馨提示"
    Else
        
        '查询上机表
        txtSQL = "select * from Online_info where cardno='" & MSHFlexGrid1.TextMatrix(1, 0) & "'"
        Set mrcOnLine = ExecuteSQL(txtSQL, MsgText)
        
        '计算消费时长。运用到了DateDiff函数
        Day = DateDiff("d", mrcOnLine.Fields(6), Date)       '计算上机下机的日期差
        Minute = DateDiff("n", mrcOnLine.Fields(7), Time)        '计算上机下机的同日时间差
        ConsumeTime = 1440 * Val(Day) + Minute             '计算总时间差,分钟为单位

        '查询学生表
        txtSQLStu = "select * from student_Info where cardno='" & MSHFlexGrid1.TextMatrix(1, 0) & "'"
        Set mrcStu = ExecuteSQL(txtSQLStu, MsgtextStu)
        
        '查询基础数据表
        txtSQLBasic = "select * from Basicdata_info"
        Set mrcBasic = ExecuteSQL(txtSQLBasic, MsgtextBasic)
            
            '判断用户类型,扣钱
            If Trim(mrcOnLine.Fields(1)) = "固定用户" Then
                Money = Round((mrcBasic.Fields(0) / 60 * ConsumeTime)) '计算固定用户金额
                Balance = Val(mrcStu.Fields(7)) - Val(Money)
            Else
                Money = Round((mrcBasic.Fields(1) / 60 * ConsumeTime)) '计算固定用户金额
                Balance = Val(mrcStu.Fields(7)) - Val(Money)
               
               '修改student表中的余额
                mrcStu.Fields(7) = Trim(Balance)
                mrcStu.Fields(11) = "未结账"
            End If
             mrcOnLine.Delete
            MSHFlexGrid1.RemoveItem 1    '删除控件中的本行数据
    End If
    Loop
    MsgBox "下机成功", 64, "温馨提示"
    frmMain.lblPeople.Caption = 0
End Sub

选中的同学下机

这个时候不需要判断是否有人员上机了,需要连接数据库查询上机表,计算消费时长,计算费用。
需要注意这些被下机的账户是未结账状态。

Private Sub chooseOffLine_Click()
    Dim m, a As Integer
    
    m = MSHFlexGrid1.Rows - 1
    For a = 1 To m
            
    If MSHFlexGrid1.TextMatrix(m, 5) = "√" Then
                
    '查询上机表
        txtSQL = "select * from Online_info where cardno='" & MSHFlexGrid1.TextMatrix(m, 0) & "'"
        
        Set mrcOnLine = ExecuteSQL(txtSQL, MsgText)
            
            '计算消费时长。运用到了DateDiff函数
            Day = DateDiff("d", mrcOnLine.Fields(6), Date)       '计算上机下机的日期差
            Minute = DateDiff("n", mrcOnLine.Fields(7), Time)        '计算上机下机的同日时间差
            ConsumeTime = 1440 * Val(Day) + Minute             '计算总时间差,分钟为单位
        
            '查询学生表
            txtSQLStu = "select * from student_Info where cardno='" & MSHFlexGrid1.TextMatrix(m, 0) & "'"
            
            Set mrcStu = ExecuteSQL(txtSQLStu, MsgtextStu)
                
                '查询基础数据表
                txtSQLBasic = "select * from Basicdata_info"
                
                Set mrcBasic = ExecuteSQL(txtSQLBasic, MsgtextBasic)
                    
                    '判断用户类型,扣钱
                    If Trim(mrcOnLine.Fields(1)) = "固定用户" Then
                        Money = Round((mrcBasic.Fields(0) / 60 * ConsumeTime)) '计算固定用户金额
                        Balance = Val(mrcStu.Fields(7)) - Val(Money)
                    Else
                        Money = Round((mrcBasic.Fields(1) / 60 * ConsumeTime)) '计算固定用户金额
                        Balance = Val(mrcStu.Fields(7)) - Val(Money)
                       
                       '修改student表中的余额
                        mrcStu.Fields(7) = Trim(Balance)
                        mrcStu.Fields(11) = "未结账"
                    End If
                        MsgBox "下机成功", 64, "温馨提示"
                        mrcOnLine.Delete
                        frmMain.lblPeople.Caption = mrcOnLine.RecordCount  '显示当前上机人数

                        MSHFlexGrid1.RemoveItem m
                        
                    m = m - 1
    Else
    m = m - 1
    End If
Next
End sub 

下机成功之后还需要将上机记录写进line表

Rem:将上机记录写进line表
            txtSQLLine = "select * from line_info where cardno='" & MSHFlexGrid1.TextMatrix(1, 0) & "'"
            Set mrcLine = ExecuteSQL(txtSQLLine, MsgtextLine)
                mrcLine.AddNew
                mrcLine.Fields(1) = mrcOnLine.Fields(0)         '卡号
                mrcLine.Fields(2) = mrcOnLine.Fields(2)      '学号
                mrcLine.Fields(3) = mrcOnLine.Fields(3)      '姓名
                mrcLine.Fields(4) = mrcOnLine.Fields(1)        '系别
                mrcLine.Fields(5) = mrcOnLine.Fields(5)        '性别
                mrcLine.Fields(6) = mrcOnLine.Fields(6)       '上机日期
                mrcLine.Fields(7) = mrcOnLine.Fields(7)        '上机时间
                mrcLine.Fields(8) = Date        '下机日期
                mrcLine.Fields(9) = Time        '下机时间
                mrcLine.Fields(10) = ConsumeTime       '消费时间
                mrcLine.Fields(11) = Money        '消费金额
                mrcLine.Fields(12) = Balance       '余额
                mrcLine.Fields(13) = "正常下机"
                mrcLine.Fields(14) = Trim(VBA.Environ("computername"))
                mrcLine.Update
            

在选中用户的时候有一个标记
选中的账户改变颜色,并且可以跨行选中

Private Sub MSHFlexGrid1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
    
    '获取选中不连续行的权限,及实现多行选中
    Dim col As Integer
    
    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 = vbYellow
        Next col
    End If
End Sub

感谢阅读,欢迎斧正~

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

张_Laura

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值