⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 user.frm

📁 进销存管理系统是基于用户的数据库管理系统
💻 FRM
字号:
VERSION 5.00
Begin VB.Form frmUser 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "用户管理"
   ClientHeight    =   3450
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   3390
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MDIChild        =   -1  'True
   MinButton       =   0   'False
   ScaleHeight     =   3450
   ScaleWidth      =   3390
   Begin VB.CommandButton cmdClose 
      Caption         =   "关闭"
      Height          =   375
      Left            =   1800
      TabIndex        =   8
      Top             =   2760
      Width           =   1335
   End
   Begin VB.CommandButton cmdChangeType 
      Caption         =   "更改用户类型"
      Height          =   375
      Left            =   1800
      TabIndex        =   7
      Top             =   2190
      Width           =   1335
   End
   Begin VB.CommandButton cmdAddUser 
      Caption         =   "添加用户"
      Height          =   375
      Left            =   1800
      TabIndex        =   6
      Top             =   480
      Width           =   1335
   End
   Begin VB.CommandButton cmdDeleteUser 
      Caption         =   "删除用户"
      Height          =   375
      Left            =   1800
      TabIndex        =   5
      Top             =   1050
      Width           =   1335
   End
   Begin VB.CommandButton cmdChangePwd 
      Caption         =   "改变密码"
      Height          =   375
      Left            =   1800
      TabIndex        =   4
      Top             =   1620
      Width           =   1335
   End
   Begin VB.ComboBox cboUserType 
      Height          =   300
      Left            =   240
      Style           =   2  'Dropdown List
      TabIndex        =   1
      Top             =   480
      Width           =   1335
   End
   Begin VB.ListBox lstUser 
      Height          =   2040
      Left            =   240
      TabIndex        =   0
      Top             =   1200
      Width           =   1335
   End
   Begin VB.Label lblUserList 
      AutoSize        =   -1  'True
      Caption         =   "用户列表:"
      Height          =   180
      Left            =   240
      TabIndex        =   3
      Top             =   960
      Width           =   810
   End
   Begin VB.Label lblUserType 
      AutoSize        =   -1  'True
      Caption         =   "用户类型:"
      Height          =   180
      Left            =   240
      TabIndex        =   2
      Top             =   240
      Width           =   810
   End
End
Attribute VB_Name = "frmUser"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Private Sub cboUserType_Click()
    On Error GoTo errHandler
    
    lstUser.Clear
    
    Dim str As String
    Select Case cboUserType.ListIndex
        Case 0, 1, 2, 3:
            str = "select * from userlist where 用户类型=" & cboUserType.ListIndex
        Case Else:
            str = "select * from userlist"
    End Select
    
    Dim rs As New ADODB.Recordset
    rs.Open str, gConn, adOpenStatic
    While Not rs.EOF
        lstUser.AddItem rs("用户名"), 0
        lstUser.ItemData(0) = rs("用户类型")
        rs.MoveNext
    Wend
    rs.Close
  
    Exit Sub
    
errHandler:
    MsgBox Err.Description, vbCritical, "错误"
End Sub

Private Sub cmdAddUser_Click()
    On Error GoTo errHandler

    Dim strUser As String
    Dim strPwd As String
    Dim nType As Integer
    
    '取得用户名
getUser:
    strUser = InputBox("请输入所要新建的用户的名称:", "用户名")
    If strUser = "" Then Exit Sub
    
    Dim rs As New ADODB.Recordset
    rs.Open "select * from userlist where 用户名='" & strUser & "'", gConn, adOpenStatic
    If Not rs.EOF Then
        MsgBox "该用户名已经存在!", vbCritical, "用户名重复"
        GoTo getUser
    End If
    rs.Close
    
    '取得用户密码
getPwd:
    frmPassword.Show vbModal
    strPwd = frmPassword.txtPwd(0).Text
    Unload frmPassword
    If strPwd = "" Then
        MsgBox "必须输入密码!", vbCritical, "需要密码"
        GoTo getPwd
    End If
            
    '取得用户类型
getType:
    frmUserType.Show vbModal
    nType = frmUserType.mnUserType
    Unload frmUserType
    If nType < 0 Then
        MsgBox "必须选择用户类型!", vbCritical, "选择用户类型"
        GoTo getType
    End If
    
    gConn.Execute "insert into userlist(用户名,用户密码,用户类型) values('" & strUser & "','" & strPwd & "'," & nType & ")"
    
    Exit Sub
    
errHandler:
    MsgBox Err.Description, vbCritical, "错误"
End Sub

Private Sub cmdChangePwd_Click()
    On Error GoTo errHandler
    
    If lstUser.Text = "" Then Exit Sub

    frmPassword.Show vbModal
    If frmPassword.txtPwd(0).Text <> "" Then
        gConn.Execute "update userlist set 用户密码='" & frmPassword.txtPwd(0).Text & "' where 用户名='" & lstUser.Text & "'"
    End If
    Unload frmPassword
    
    Exit Sub
    
errHandler:
    MsgBox Err.Description, vbCritical, "错误"
End Sub

Private Sub cmdClose_Click()
    Unload Me
End Sub

Private Sub cmdDeleteUser_Click()
    On Error GoTo errHandler
    
    If lstUser.Text = "" Then Exit Sub
    If lstUser.Text = gsUserName Then
        MsgBox "不能删除当前记录!", vbCritical, "删除用户错误"
        Exit Sub
    End If
    
    gConn.Execute "delete from userlist where 用户名='" & lstUser.Text & "'"
    '从列表框中移去所删除的用户
    lstUser.RemoveItem lstUser.ListIndex
    
    Exit Sub
    
errHandler:
    MsgBox Err.Description, vbCritical, "错误"
End Sub

Private Sub cmdChangeType_Click()
    On Error GoTo errHandler
    
    If lstUser.Text = "" Then Exit Sub
    
    Load frmUserType
    frmUserType.optUserType(lstUser.ItemData(lstUser.ListIndex)).Value = True
    frmUserType.Show vbModal
    If frmUserType.mnUserType >= 0 Then
        gConn.Execute "update userlist set 用户类型=" & frmUserType.mnUserType & " where 用户名='" & lstUser.Text & "'"
    End If
    Unload frmUserType
    
    Exit Sub
    
errHandler:
    MsgBox Err.Description, vbCritical, "错误"
End Sub

Private Sub Form_Load()
    cboUserType.AddItem "管理人员", 0
    cboUserType.AddItem "仓管人员", 1
    cboUserType.AddItem "销售人员", 2
    cboUserType.AddItem "进货人员", 3
    cboUserType.AddItem "所有人员", 4
    
    cboUserType.ListIndex = 4
End Sub

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -