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

📄 formuser.vb

📁 人事管理系统(VB.NET2005+SQL Server2005)
💻 VB
字号:
Imports System
Imports System.Data
Imports CommonDB
Imports CommonSystem

Public Class FormUser
    Inherits System.Windows.Forms.Form

    Private oUser As User

#Region " Windows 窗体设计器生成的代码 "

    Public Sub New()
        MyBase.New()

        '该调用是 Windows 窗体设计器所必需的。
        InitializeComponent()

        '在 InitializeComponent() 调用之后添加任何初始化

    End Sub

    '窗体重写 dispose 以清理组件列表。
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Windows 窗体设计器所必需的
    Private components As System.ComponentModel.IContainer

    '注意: 以下过程是 Windows 窗体设计器所必需的
    '可以使用 Windows 窗体设计器修改此过程。
    '不要使用代码编辑器修改它。
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents Label4 As System.Windows.Forms.Label
    Friend WithEvents Panel1 As System.Windows.Forms.Panel
    Friend WithEvents Panel2 As System.Windows.Forms.Panel
    Friend WithEvents btnExit As System.Windows.Forms.Button
    Friend WithEvents btnCancel As System.Windows.Forms.Button
    Friend WithEvents btnReset As System.Windows.Forms.Button
    Friend WithEvents btnUpdate As System.Windows.Forms.Button
    Friend WithEvents txtPassword As System.Windows.Forms.TextBox
    Friend WithEvents txtPassword2 As System.Windows.Forms.TextBox
    Friend WithEvents cmbUserName As System.Windows.Forms.ComboBox
    Friend WithEvents cmbRole As System.Windows.Forms.ComboBox
    Friend WithEvents Label5 As System.Windows.Forms.Label
    Friend WithEvents cmbOperation As System.Windows.Forms.ComboBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.Label1 = New System.Windows.Forms.Label
        Me.Label2 = New System.Windows.Forms.Label
        Me.Label3 = New System.Windows.Forms.Label
        Me.Label4 = New System.Windows.Forms.Label
        Me.Panel1 = New System.Windows.Forms.Panel
        Me.cmbRole = New System.Windows.Forms.ComboBox
        Me.cmbUserName = New System.Windows.Forms.ComboBox
        Me.txtPassword2 = New System.Windows.Forms.TextBox
        Me.txtPassword = New System.Windows.Forms.TextBox
        Me.Label5 = New System.Windows.Forms.Label
        Me.cmbOperation = New System.Windows.Forms.ComboBox
        Me.Panel2 = New System.Windows.Forms.Panel
        Me.btnExit = New System.Windows.Forms.Button
        Me.btnCancel = New System.Windows.Forms.Button
        Me.btnReset = New System.Windows.Forms.Button
        Me.btnUpdate = New System.Windows.Forms.Button
        Me.Panel1.SuspendLayout()
        Me.Panel2.SuspendLayout()
        Me.SuspendLayout()
        '
        'Label1
        '
        Me.Label1.Location = New System.Drawing.Point(40, 72)
        Me.Label1.Name = "Label1"
        Me.Label1.TabIndex = 0
        Me.Label1.Text = "用户名"
        '
        'Label2
        '
        Me.Label2.Location = New System.Drawing.Point(40, 104)
        Me.Label2.Name = "Label2"
        Me.Label2.TabIndex = 1
        Me.Label2.Text = "用户角色"
        '
        'Label3
        '
        Me.Label3.Location = New System.Drawing.Point(40, 136)
        Me.Label3.Name = "Label3"
        Me.Label3.TabIndex = 2
        Me.Label3.Text = "密码"
        '
        'Label4
        '
        Me.Label4.Location = New System.Drawing.Point(40, 168)
        Me.Label4.Name = "Label4"
        Me.Label4.TabIndex = 3
        Me.Label4.Text = "密码确认"
        '
        'Panel1
        '
        Me.Panel1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.Panel1.Controls.Add(Me.cmbRole)
        Me.Panel1.Controls.Add(Me.cmbUserName)
        Me.Panel1.Controls.Add(Me.txtPassword2)
        Me.Panel1.Controls.Add(Me.txtPassword)
        Me.Panel1.Controls.Add(Me.Label3)
        Me.Panel1.Controls.Add(Me.Label2)
        Me.Panel1.Controls.Add(Me.Label1)
        Me.Panel1.Controls.Add(Me.Label4)
        Me.Panel1.Controls.Add(Me.Label5)
        Me.Panel1.Controls.Add(Me.cmbOperation)
        Me.Panel1.Location = New System.Drawing.Point(40, 8)
        Me.Panel1.Name = "Panel1"
        Me.Panel1.Size = New System.Drawing.Size(392, 224)
        Me.Panel1.TabIndex = 4
        '
        'cmbRole
        '
        Me.cmbRole.Location = New System.Drawing.Point(144, 104)
        Me.cmbRole.Name = "cmbRole"
        Me.cmbRole.Size = New System.Drawing.Size(200, 20)
        Me.cmbRole.TabIndex = 9
        '
        'cmbUserName
        '
        Me.cmbUserName.Location = New System.Drawing.Point(144, 72)
        Me.cmbUserName.Name = "cmbUserName"
        Me.cmbUserName.Size = New System.Drawing.Size(200, 20)
        Me.cmbUserName.TabIndex = 8
        '
        'txtPassword2
        '
        Me.txtPassword2.Location = New System.Drawing.Point(144, 168)
        Me.txtPassword2.Name = "txtPassword2"
        Me.txtPassword2.PasswordChar = Microsoft.VisualBasic.ChrW(42)
        Me.txtPassword2.Size = New System.Drawing.Size(200, 21)
        Me.txtPassword2.TabIndex = 7
        Me.txtPassword2.Text = ""
        '
        'txtPassword
        '
        Me.txtPassword.Location = New System.Drawing.Point(144, 136)
        Me.txtPassword.Name = "txtPassword"
        Me.txtPassword.PasswordChar = Microsoft.VisualBasic.ChrW(42)
        Me.txtPassword.Size = New System.Drawing.Size(200, 21)
        Me.txtPassword.TabIndex = 6
        Me.txtPassword.Text = ""
        '
        'Label5
        '
        Me.Label5.Location = New System.Drawing.Point(40, 40)
        Me.Label5.Name = "Label5"
        Me.Label5.TabIndex = 0
        Me.Label5.Text = "操作"
        '
        'cmbOperation
        '
        Me.cmbOperation.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
        Me.cmbOperation.Items.AddRange(New Object() {"请选择一种操作", "增加用户", "修改用户", "删除用户"})
        Me.cmbOperation.Location = New System.Drawing.Point(144, 40)
        Me.cmbOperation.Name = "cmbOperation"
        Me.cmbOperation.Size = New System.Drawing.Size(200, 20)
        Me.cmbOperation.TabIndex = 8
        '
        'Panel2
        '
        Me.Panel2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.Panel2.Controls.Add(Me.btnExit)
        Me.Panel2.Controls.Add(Me.btnCancel)
        Me.Panel2.Controls.Add(Me.btnReset)
        Me.Panel2.Controls.Add(Me.btnUpdate)
        Me.Panel2.Location = New System.Drawing.Point(40, 256)
        Me.Panel2.Name = "Panel2"
        Me.Panel2.Size = New System.Drawing.Size(392, 40)
        Me.Panel2.TabIndex = 5
        '
        'btnExit
        '
        Me.btnExit.Location = New System.Drawing.Point(299, 9)
        Me.btnExit.Name = "btnExit"
        Me.btnExit.TabIndex = 11
        Me.btnExit.Text = "退  出"
        '
        'btnCancel
        '
        Me.btnCancel.Enabled = False
        Me.btnCancel.Location = New System.Drawing.Point(115, 9)
        Me.btnCancel.Name = "btnCancel"
        Me.btnCancel.TabIndex = 10
        Me.btnCancel.Text = "取  消"
        '
        'btnReset
        '
        Me.btnReset.Location = New System.Drawing.Point(203, 9)
        Me.btnReset.Name = "btnReset"
        Me.btnReset.TabIndex = 9
        Me.btnReset.Text = "重  置"
        '
        'btnUpdate
        '
        Me.btnUpdate.Enabled = False
        Me.btnUpdate.Location = New System.Drawing.Point(19, 9)
        Me.btnUpdate.Name = "btnUpdate"
        Me.btnUpdate.TabIndex = 8
        Me.btnUpdate.Text = "更  新"
        '
        'FormUser
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
        Me.ClientSize = New System.Drawing.Size(472, 334)
        Me.Controls.Add(Me.Panel2)
        Me.Controls.Add(Me.Panel1)
        Me.Name = "FormUser"
        Me.Text = "用户管理"
        Me.Panel1.ResumeLayout(False)
        Me.Panel2.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub InitialData()
        'Initial cmbOperation
        cmbOperation.SelectedIndex = 0

        'Initial cmbUserName
        cmbUserName.DataSource = Nothing
        cmbUserName.Items.Clear()
        cmbUserName.DataSource = DbBase.DataInterface().Execute4DS("select id,name from user_info").Tables(0).DefaultView
        cmbUserName.DisplayMember = "name"
        cmbUserName.ValueMember = "id"
        cmbUserName.Text = "请选择用户或输入新用户名"
        cmbUserName.DropDownStyle = ComboBoxStyle.DropDown

        'Initial cmbRole
        cmbRole.DataSource = Nothing
        cmbRole.Items.Clear()
        cmbRole.DataSource = DbBase.DataInterface().Execute4DS("select id,role from user_level").Tables(0).DefaultView
        cmbRole.DisplayMember = "role"
        cmbRole.ValueMember = "id"
        'cmbRole.Text = "请选择用户角色"

        'Clear Password
        txtPassword.Text = ""
        txtPassword2.Text = ""
    End Sub

    Private Sub FormUser_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        InitialData()
    End Sub

    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
        Me.Close()
    End Sub

    Private Sub btnReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReset.Click
        InitialData()
    End Sub

    Private Sub cmbOperation_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles cmbOperation.SelectedIndexChanged
        Select Case cmbOperation.SelectedIndex
            Case 0
                EndEdit()
                InitialData()
                Exit Sub
            Case 1
                cmbUserName.DropDownStyle = ComboBoxStyle.Simple
                cmbUserName.Text = ""
                oUser = New User
            Case Else
                cmbUserName.DropDownStyle = ComboBoxStyle.DropDownList
        End Select
        BeginEdit()
    End Sub

    Private Sub cmbUserName_SelectedIndexChanged(ByVal send As Object, ByVal e As EventArgs) Handles cmbUserName.SelectedIndexChanged
        If cmbUserName.SelectedIndex >= 0 Then
            Try
                oUser = New User(cmbUserName.Text)
                cmbRole.Text = oUser.Role
                txtPassword.Text = oUser.Password
                txtPassword2.Text = oUser.Password
            Catch ex As Exception
                If ex.Message = "Can't find the user when Construct User!" Then
                    oUser = New User
                Else
                    Throw New Exception(ex.Message)
                End If
            End Try
        End If
    End Sub

    Private Sub BeginEdit()
        btnUpdate.Enabled = True
        btnCancel.Enabled = True
    End Sub

    Private Sub EndEdit()
        btnUpdate.Enabled = False
        btnCancel.Enabled = False
    End Sub

    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        cmbOperation.SelectedIndex = 0
    End Sub

    Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
        oUser.Name = cmbUserName.Text
        oUser.Role = cmbRole.Text
        oUser.Password = txtPassword.Text

        Select Case cmbOperation.SelectedIndex
            Case 1
                oUser.Add()
            Case 2
                oUser.Update()
            Case 3
                oUser.Delete()
            Case Else
                '
        End Select
        InitialData()
    End Sub
End Class

⌨️ 快捷键说明

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