机房收费系统之删除和添加用户

        删除和添加用户作为机房收费系统软件的重要部分,在机房收费系统中起着不可忽视的作用。

        删除和添加用户这一版块有三个重要的组成部分:删除数据,更新数据,选择不同的级别显示不同的信息。

第一:选择不同级别显示不同的信息

1、不同的级别所指:管理员,操作员和一般用户

2、不同的信息所指选择管理员或者操作员或者一般用户来显示他们各自的信息

  • 做法:

在实现这一功能时我们要考虑到两个重要的方面,一是正在登陆的用户不能删除,数据库中必须留下一个永久性的用户。因此我们在选择数据的时候我们需要在数据库中留下一个永久性的用户和正在登陆的用户(只限在管理员的部分,因为只有管理员才有删除和添加用户的权限)

Rem:选择不同的用户级别,显示不用的信息
Private Sub comuserlevel_click()

    Dim txtsqluser As String
    Dim msgtextuser As String
    Dim mrcuser As ADODB.Recordset
    
    With MSFlexGrid1
        Call adjustcolwidth(frmdm, MSFlexGrid1, True, 0)
        .Rows = 1
        .TextMatrix(0, 0) = "用户名"
        .TextMatrix(0, 1) = "姓名"
        .TextMatrix(0, 2) = "开户人"
    
        Select Case comuserlevel
        Case "管理员"
                txtsqluser = "select userID,username,head from user_info where level='管理员" & "'" & "and userID<>'yjx" & "'" & "and userID<>'" & frmlogin.txtusername.Text & "'"
                Set mrcuser = executesql(txtsqluser, msgtextuser)
                
                If mrcuser.EOF = True Then
                        MsgBox "无管理员的数据!", vbOKOnly + vbInformation, "温馨提示"
                        Exit Sub
                Else
                        Do While mrcuser.EOF = False
                                .Rows = .Rows + 1
                                .TextMatrix(.Rows - 1, 0) = mrcuser!userid
                                .TextMatrix(.Rows - 1, 1) = mrcuser!username
                                .TextMatrix(.Rows - 1, 2) = mrcuser!head
                                mrcuser.MoveNext
                        Loop
                End If
        Case "操作员"
                txtsqluser = "select userID,username,head from user_info where level='操作员" & "'"
                Set mrcuser = executesql(txtsqluser, msgtextuser)
                
                If mrcuser.EOF = True Then
                        MsgBox "无操作员的数据!", vbOKOnly + vbInformation, "温馨提示"
                        Exit Sub
                Else
                        Do While mrcuser.EOF = False
                                .Rows = .Rows + 1
                                .TextMatrix(.Rows - 1, 0) = mrcuser!userid
                                .TextMatrix(.Rows - 1, 1) = mrcuser!username
                                .TextMatrix(.Rows - 1, 2) = mrcuser!head
                                mrcuser.MoveNext
                        Loop
                End If
        Case "一般用户"
                txtsqluser = "select userID,username,head from user_info where level='一般用户" & "'"
                Set mrcuser = executesql(txtsqluser, msgtextuser)
                
                If mrcuser.EOF = True Then
                        MsgBox "无一般用户的数据!", vbOKOnly + vbInformation, "温馨提示"
                        Exit Sub
                Else
                        Do While mrcuser.EOF = False
                                .Rows = .Rows + 1
                                .TextMatrix(.Rows - 1, 0) = mrcuser!userid
                                .TextMatrix(.Rows - 1, 1) = mrcuser!username
                                .TextMatrix(.Rows - 1, 2) = mrcuser!head
                                mrcuser.MoveNext
                        Loop
                End If
        End Select
    End With
End Sub

第二:更新

          所指将新添加的用户更新到msflexgrid中来,与选择信息的设计步骤相似,在这里就不做介绍了

第三:删除

          所指在删除msflexgrid中的数据的时候数据库中的数据也同样被删除了。

  • 做法
Dim txtsqluser As String
    Dim msgtextuser As String
    Dim mrcuser As ADODB.Recordset
    
    With MSFlexGrid1

            If .Text = "" Then
                    MsgBox "请先查询在进行删除!", vbOKOnly + vbInformation, "温馨提示"
                    comuserlevel.SetFocus
            Else
                    If .RowSel = 0 Then
                            MsgBox "请选择数据!", vbOKOnly + vbInformation, "温馨提示"
                            Exit Sub
                    Else
                            If .RowSel > 0 Then
                                    txtsqluser = "delete from user_info where userID='" & Trim(.TextMatrix(.RowSel, 0)) & "'"
                                    Set mrc = executesql(txtsqluser, msgtextuser)
                                    .RemoveItem .RowSel
                            End If
                    End If
            End If
    End With

猜你喜欢

转载自blog.csdn.net/yang18831636208/article/details/83448704