机房收费学生上机状态查看

  
显示全部代码:

'显示全部信息代码
Private Sub ShowAll_Click()
    
    Dim msgtext As String
    Dim txtsql As String
    Dim mrc As ADODB.Recordset
    
    MSFlexGrid1.SelectionMode = flexSelectionByRow     '单击的时候选择的是整行
    MSFlexGrid1.FocusRect = flexFocusNone               '在当前单元的周围画一个焦点框
    MSFlexGrid1.HighLight = flexHighlightWithFocus      '该值决定了所选定的单元是否突出显示

        
    txtsql = "select * from OnLine_Info" '查看数据库以得到所有上机同学的表
    Set mrc = ExecuteSQL(txtsql, msgtext)
       
    If mrc.EOF = True Then '判断数据库是否为空
        MsgBox "学生上机记录为空!", vbOKOnly, "温馨提示"
        ShowAll.Enabled = False
    Else
        ShowAll.Enabled = True
    End If
        
        With MSFlexGrid1 '添加表头
            .Rows = 1
            .CellAlignment = 4
            .TextMatrix(0, 0) = "卡号"
            .TextMatrix(0, 1) = "姓名"
            .TextMatrix(0, 2) = "上机日期"
            .TextMatrix(0, 3) = "上机时间"
            .TextMatrix(0, 4) = "机房号"
            '将数据库的值赋给表格
            Do While Not mrc.EOF
                .Rows = .Rows + 1
                .CellAlignment = 4
                .TextMatrix(.Rows - 1, 0) = Trim(mrc.Fields(0)) & ""
                .TextMatrix(.Rows - 1, 1) = Trim(mrc.Fields(3))
                .TextMatrix(.Rows - 1, 2) = Trim(mrc.Fields(6))
                .TextMatrix(.Rows - 1, 3) = Trim(mrc.Fields(7))
                .TextMatrix(.Rows - 1, 4) = Trim(mrc.Fields(8))
                mrc.MoveNext
            Loop
        End With
        mrc.Close
        MSFlexGrid1.CellAlignment = 4
End Sub片

  
所有学生下线:

'所有学生下线代码
Private Sub AllOffLine_Click()
        
        Dim msgtext As String
        Dim txtsql As String
        Dim mrc As ADODB.Recordset
        
        txtsql = "delete from online_Info"
        Set mrc = ExecuteSQL(txtsql, msgtext)
        '将查询内容显示在表格控件中
        
        With MSFlexGrid1
        .Rows = 2 '两行
        .CellAlignment = 4  '单元格内容居中,居中对齐
        .TextMatrix(0, 0) = "卡号"
        .TextMatrix(0, 1) = "学号"
        .TextMatrix(0, 2) = "姓名"
        .TextMatrix(0, 3) = "上机日期"
        .TextMatrix(0, 4) = "上机时间"
        .TextMatrix(0, 5) = "电脑号"
        End With
        MsgBox "所有同学已下机,控件内容将全部清空!", vbOKOnly + vbExclamation, "提示"
        MSFlexGrid1.Clear '清空部件内容
        AllOffLine.Enabled = False '所有学生下线按钮不可用
End Sub

  
选中学生下线:

'选中学生下线代码
Private Sub ChooseOffLine_Click()
    
    Dim msgtext As String
    Dim txtsql As String
    Dim mrc As ADODB.Recordset
    
    MSFlexGrid1.SelectionMode = flexSelectionByRow     '单击的时候选择的是整行
    MSFlexGrid1.FocusRect = flexFocusNone               '在当前单元的周围画一个焦点框
    MSFlexGrid1.HighLight = flexHighlightWithFocus      '该值决定了所选定的单元是否突出显示
 
 
    With MSFlexGrid1
        
        If .RowSel = 0 Then   '选中行为第一行
            MsgBox "请选择数据!", vbOKOnly, "提示"
            Exit Sub
        End If
        
            If .RowSel >= 1 Then
            txtsql = "select * from OnLine_Info where cardno='" & Trim(.TextMatrix(.RowSel, 0)) & "'"
            Set mrc = ExecuteSQL(txtsql, msgtext)
                If mrc.EOF = True Then
                   MsgBox "无上线人数!"
                   Exit Sub
                Else
                    .RemoveItem .RowSel
                    mrc.Delete
                End If
            End If
      End With
      mrc.Update
End Sub

     在做这个窗体时突然出现了一个实时错误“30015”,最后同过设置界面中MSFlexGrid1控件属性得已解决。

在这里插入图片描述
  给下图MSFlexGrid1控件固定行设置成0就行了。
在这里插入图片描述


如有问题欢迎留言区评论。。。

发布了53 篇原创文章 · 获赞 6 · 访问量 3349

猜你喜欢

转载自blog.csdn.net/weixin_44031029/article/details/102845014