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

本文详细解析了一个用于管理用户的界面代码,包括用户级别的选择、用户信息的显示、添加和删除用户的逻辑实现。代码中使用了ADODB.Recordset进行数据库操作,展示了如何通过下拉菜单选择用户级别,并根据选择显示相应的用户信息,以及实现用户添加和删除的功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

这个窗体比较简单,以下是代码展示:

添加和删除用户:

Private Sub cboUserLevel_Click()
    Dim txtsql As String
    Dim msgtext As String
    Dim mrc As ADODB.Recordset
    
    
    txtsql = "select * from user_info where level= '" & Trim(cboUserLevel.Text) & "'"
    Set mrc = ExecuteSQL(txtsql, msgtext)
    
    If mrc.EOF Then
        MsgBox "没有内容!", 0, "温馨提示"
    Else
        With MSHFlexGrid1
        .Rows = 1
        .CellAlignment = 4
        .ColAlignment = 4
        .TextMatrix(0, 0) = "用户名"
        .TextMatrix(0, 1) = "姓名"
        .TextMatrix(0, 2) = "开户人"
    End With
        
        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(2)
            .TextMatrix(.Rows - 1, 2) = mrc.fields(3)
        mrc.MoveNext
    
    End With
        Loop
        mrc.Close
    
    End If
    
End Sub
Private Sub cmdAdd_Click()
    Me.Hide
    Adduser.Show
End Sub
Private Sub cmdBack_Click()
    Me.Hide
End Sub

Private Sub cmdDelete_Click()
    Dim txtsql As String
    Dim msgtext As String
    Dim mrc As ADODB.Recordset
    MSHFlexGrid1.SelectionMode = flexSelectionByRow '单机的时候选择整行

    MSHFlexGrid1.FocusRect = flexFocusNone '在当前单元的周围画一个焦点框
    MSHFlexGrid1.HighLight = flexHighlightWithFocus '该值决定了所选定的单元是否突出显示

    With MSHFlexGrid1
        If .RowSel = 0 Then
            MsgBox "请选择数据!", 0 + 48, "提示"
            Exit Sub
        Else
            If .RowSel > 0 Then
              If Trim(MSHFlexGrid1.TextMatrix(.RowSel, 0)) = UserName Then
                    MsgBox "该用户正在登陆,不能删除!", 0 + 48, "温馨提示"
                    Exit Sub
                Else
                
                txtsql = "delete from user_info where userid= '" & Trim(MSHFlexGrid1.TextMatrix(.RowSel, 0)) & "'"
                Set mrc = ExecuteSQL(txtsql, msgtext)
                
                MSHFlexGrid1.RemoveItem MSHFlexGrid1.Row
              
                    End If
                End If
            End If
        
    End With

End Sub

Private Sub Form_Load()
cboUserLevel.AddItem "一般用户"
cboUserLevel.AddItem "操作员"
cboUserLevel.AddItem "管理员"
End Sub

添加用户窗体:

Private Sub cmdDelete_Click()
        txtUser.Text = ""
        txtPassword.Text = ""
        cboUserLevel.Text = ""
        txtName.Text = ""
        Text4.Text = ""
End Sub

Private Sub cmdOk_Click()
    Dim txtsql As String
    Dim msgtext As String
    Dim mrc As ADODB.Recordset
    
    txtsql = "select * from user_info"
    Set mrc = ExecuteSQL(txtsql, msgtext)
    
    If Trim(txtUser.Text) = "" Then
        MsgBox "请填写用户名", 0 + 48, "温馨提示"
    Else
        If Trim(txtName.Text) = "" Then
            MsgBox "请填写姓名", 0 + 48, "温馨提示"
        Else
            If Trim(txtPassword.Text) = "" Then
                MsgBox "请输入密码", 0 + 48, "温馨提示"
            End If
        End If
    End If
    
    If Trim(Text4.Text) <> Trim(txtPassword.Text) Then
        MsgBox "密码不一致,请重新输入", 0 + 48, "温馨提示"
        Exit Sub
        Text4.SetFocus
        Text4.Text = ""
    End If
    If mrc.EOF = True Then
        MsgBox "有相同记录,请重新输入!", 0 + 48, "提示"
        txtUser.SetFocus
        txtUser.Text = ""
        txtPassword.Text = ""
        cboUserLevel.Text = ""
        txtName.Text = ""
        Text4.Text = ""
        mrc.Close
    End If
    
    If Trim(txtUser.Text) = mrc.fields(0) Then
        MsgBox "已经有相同用户了,不能添加重复用户", 0 + 46, "提示"
        txtUser.Text = ""
        txtUser.SetFocus
        Exit Sub
    Else
    mrc.AddNew
    mrc.fields(0) = Trim(txtUser.Text)
    mrc.fields(1) = Trim(txtPassword.Text)
    mrc.fields(2) = Trim(cboUserLevel.Text)
    mrc.fields(3) = Trim(txtName.Text)
    mrc.fields(4) = "开户人"
    mrc.Update
    mrc.Close
    MsgBox "添加用户成功", 0 + 48, "提示"
    Unload Me
End If

End Sub

Private Sub Form_Load()
cboUserLevel.AddItem "一般用户"
cboUserLevel.AddItem "操作员"
cboUserLevel.AddItem "管理员"

End Sub



Private Sub txtUser_KeyPress(KeyAscii As Integer)
 Dim ctemp As String
    ctemp = "#$%^&*"   '禁止输入的字符
    If InStr(1, ctemp, Chr(KeyAscii)) <> 0 Then
        KeyAscii = 0
    End If

End Sub
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值