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

📄 ucadduser.vb

📁 <Visual Basic 数据库开发实例精粹(第二版)>一书首先介绍了Visual Basic(简称VB)开发的技巧和重点技术
💻 VB
字号:
Public Class ucAddUser
    Inherits System.Windows.Forms.UserControl

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

    Public Sub New()
        MyBase.New()

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

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

    End Sub

    'UserControl 重写 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 窗体设计器修改此过程。
    '不要使用代码编辑器修改它。
  Public WithEvents _fr_1 As System.Windows.Forms.GroupBox
  Friend WithEvents txtTrueName As System.Windows.Forms.TextBox
  Friend WithEvents labTrueName As System.Windows.Forms.Label
  Public WithEvents txtAccount As System.Windows.Forms.TextBox
  Public WithEvents txtConfirmPwd As System.Windows.Forms.TextBox
  Public WithEvents cmdAdd As System.Windows.Forms.Button
  Public WithEvents _lbl_2 As System.Windows.Forms.Label
  Public WithEvents _lbl_4 As System.Windows.Forms.Label
  Public WithEvents _lbl_5 As System.Windows.Forms.Label
  Friend WithEvents Label1 As System.Windows.Forms.Label
  Public WithEvents txtPwd As System.Windows.Forms.TextBox
  Friend WithEvents cboRole As System.Windows.Forms.ComboBox
  <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
    Me._fr_1 = New System.Windows.Forms.GroupBox
    Me.cboRole = New System.Windows.Forms.ComboBox
    Me.Label1 = New System.Windows.Forms.Label
    Me.txtTrueName = New System.Windows.Forms.TextBox
    Me.labTrueName = New System.Windows.Forms.Label
    Me.txtAccount = New System.Windows.Forms.TextBox
    Me.txtPwd = New System.Windows.Forms.TextBox
    Me.txtConfirmPwd = New System.Windows.Forms.TextBox
    Me.cmdAdd = New System.Windows.Forms.Button
    Me._lbl_2 = New System.Windows.Forms.Label
    Me._lbl_4 = New System.Windows.Forms.Label
    Me._lbl_5 = New System.Windows.Forms.Label
    Me._fr_1.SuspendLayout()
    Me.SuspendLayout()
    '
    '_fr_1
    '
    Me._fr_1.BackColor = System.Drawing.SystemColors.Window
    Me._fr_1.Controls.Add(Me.cboRole)
    Me._fr_1.Controls.Add(Me.Label1)
    Me._fr_1.Controls.Add(Me.txtTrueName)
    Me._fr_1.Controls.Add(Me.labTrueName)
    Me._fr_1.Controls.Add(Me.txtAccount)
    Me._fr_1.Controls.Add(Me.txtPwd)
    Me._fr_1.Controls.Add(Me.txtConfirmPwd)
    Me._fr_1.Controls.Add(Me.cmdAdd)
    Me._fr_1.Controls.Add(Me._lbl_2)
    Me._fr_1.Controls.Add(Me._lbl_4)
    Me._fr_1.Controls.Add(Me._lbl_5)
    Me._fr_1.ForeColor = System.Drawing.SystemColors.ControlText
    Me._fr_1.Location = New System.Drawing.Point(38, 23)
    Me._fr_1.Name = "_fr_1"
    Me._fr_1.RightToLeft = System.Windows.Forms.RightToLeft.No
    Me._fr_1.Size = New System.Drawing.Size(300, 246)
    Me._fr_1.TabIndex = 22
    Me._fr_1.TabStop = False
    Me._fr_1.Text = "添加用户"
    '
    'cboRole
    '
    Me.cboRole.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
    Me.cboRole.Location = New System.Drawing.Point(72, 149)
    Me.cboRole.Name = "cboRole"
    Me.cboRole.Size = New System.Drawing.Size(203, 20)
    Me.cboRole.TabIndex = 45
    '
    'Label1
    '
    Me.Label1.AutoSize = True
    Me.Label1.BackColor = System.Drawing.Color.Transparent
    Me.Label1.Location = New System.Drawing.Point(13, 151)
    Me.Label1.Name = "Label1"
    Me.Label1.Size = New System.Drawing.Size(54, 17)
    Me.Label1.TabIndex = 28
    Me.Label1.Text = "所属部门"
    '
    'txtTrueName
    '
    Me.txtTrueName.Location = New System.Drawing.Point(73, 63)
    Me.txtTrueName.Name = "txtTrueName"
    Me.txtTrueName.Size = New System.Drawing.Size(203, 21)
    Me.txtTrueName.TabIndex = 26
    Me.txtTrueName.Text = ""
    '
    'labTrueName
    '
    Me.labTrueName.AutoSize = True
    Me.labTrueName.BackColor = System.Drawing.Color.Transparent
    Me.labTrueName.Location = New System.Drawing.Point(15, 65)
    Me.labTrueName.Name = "labTrueName"
    Me.labTrueName.Size = New System.Drawing.Size(54, 17)
    Me.labTrueName.TabIndex = 25
    Me.labTrueName.Text = "真实姓名"
    '
    'txtAccount
    '
    Me.txtAccount.AcceptsReturn = True
    Me.txtAccount.AutoSize = False
    Me.txtAccount.BackColor = System.Drawing.SystemColors.Window
    Me.txtAccount.Cursor = System.Windows.Forms.Cursors.IBeam
    Me.txtAccount.ForeColor = System.Drawing.SystemColors.WindowText
    Me.txtAccount.Location = New System.Drawing.Point(73, 37)
    Me.txtAccount.MaxLength = 10
    Me.txtAccount.Name = "txtAccount"
    Me.txtAccount.RightToLeft = System.Windows.Forms.RightToLeft.No
    Me.txtAccount.Size = New System.Drawing.Size(203, 19)
    Me.txtAccount.TabIndex = 0
    Me.txtAccount.Text = ""
    '
    'txtPwd
    '
    Me.txtPwd.AcceptsReturn = True
    Me.txtPwd.AutoSize = False
    Me.txtPwd.BackColor = System.Drawing.SystemColors.Window
    Me.txtPwd.Cursor = System.Windows.Forms.Cursors.IBeam
    Me.txtPwd.ForeColor = System.Drawing.SystemColors.WindowText
    Me.txtPwd.Location = New System.Drawing.Point(72, 92)
    Me.txtPwd.MaxLength = 15
    Me.txtPwd.Name = "txtPwd"
    Me.txtPwd.PasswordChar = Microsoft.VisualBasic.ChrW(42)
    Me.txtPwd.RightToLeft = System.Windows.Forms.RightToLeft.No
    Me.txtPwd.Size = New System.Drawing.Size(203, 20)
    Me.txtPwd.TabIndex = 2
    Me.txtPwd.Text = ""
    '
    'txtConfirmPwd
    '
    Me.txtConfirmPwd.AcceptsReturn = True
    Me.txtConfirmPwd.AutoSize = False
    Me.txtConfirmPwd.BackColor = System.Drawing.SystemColors.Window
    Me.txtConfirmPwd.Cursor = System.Windows.Forms.Cursors.IBeam
    Me.txtConfirmPwd.ForeColor = System.Drawing.SystemColors.WindowText
    Me.txtConfirmPwd.Location = New System.Drawing.Point(72, 118)
    Me.txtConfirmPwd.MaxLength = 15
    Me.txtConfirmPwd.Name = "txtConfirmPwd"
    Me.txtConfirmPwd.PasswordChar = Microsoft.VisualBasic.ChrW(42)
    Me.txtConfirmPwd.RightToLeft = System.Windows.Forms.RightToLeft.No
    Me.txtConfirmPwd.Size = New System.Drawing.Size(203, 20)
    Me.txtConfirmPwd.TabIndex = 3
    Me.txtConfirmPwd.Text = ""
    '
    'cmdAdd
    '
    Me.cmdAdd.BackColor = System.Drawing.SystemColors.Control
    Me.cmdAdd.Cursor = System.Windows.Forms.Cursors.Default
    Me.cmdAdd.ForeColor = System.Drawing.SystemColors.ControlText
    Me.cmdAdd.Location = New System.Drawing.Point(152, 188)
    Me.cmdAdd.Name = "cmdAdd"
    Me.cmdAdd.RightToLeft = System.Windows.Forms.RightToLeft.No
    Me.cmdAdd.Size = New System.Drawing.Size(102, 24)
    Me.cmdAdd.TabIndex = 4
    Me.cmdAdd.Text = "添加(&M)"
    '
    '_lbl_2
    '
    Me._lbl_2.AutoSize = True
    Me._lbl_2.BackColor = System.Drawing.Color.Transparent
    Me._lbl_2.Cursor = System.Windows.Forms.Cursors.Default
    Me._lbl_2.ForeColor = System.Drawing.SystemColors.ControlText
    Me._lbl_2.Location = New System.Drawing.Point(14, 39)
    Me._lbl_2.Name = "_lbl_2"
    Me._lbl_2.RightToLeft = System.Windows.Forms.RightToLeft.No
    Me._lbl_2.Size = New System.Drawing.Size(42, 17)
    Me._lbl_2.TabIndex = 24
    Me._lbl_2.Text = "用户名"
    '
    '_lbl_4
    '
    Me._lbl_4.AutoSize = True
    Me._lbl_4.BackColor = System.Drawing.Color.Transparent
    Me._lbl_4.Cursor = System.Windows.Forms.Cursors.Default
    Me._lbl_4.ForeColor = System.Drawing.SystemColors.ControlText
    Me._lbl_4.Location = New System.Drawing.Point(13, 96)
    Me._lbl_4.Name = "_lbl_4"
    Me._lbl_4.RightToLeft = System.Windows.Forms.RightToLeft.No
    Me._lbl_4.Size = New System.Drawing.Size(29, 17)
    Me._lbl_4.TabIndex = 22
    Me._lbl_4.Text = "密码"
    '
    '_lbl_5
    '
    Me._lbl_5.AutoSize = True
    Me._lbl_5.BackColor = System.Drawing.Color.Transparent
    Me._lbl_5.Cursor = System.Windows.Forms.Cursors.Default
    Me._lbl_5.ForeColor = System.Drawing.SystemColors.ControlText
    Me._lbl_5.Location = New System.Drawing.Point(13, 122)
    Me._lbl_5.Name = "_lbl_5"
    Me._lbl_5.RightToLeft = System.Windows.Forms.RightToLeft.No
    Me._lbl_5.Size = New System.Drawing.Size(29, 17)
    Me._lbl_5.TabIndex = 21
    Me._lbl_5.Text = "确认"
    '
    'ucAddUser
    '
    Me.BackColor = System.Drawing.SystemColors.Window
    Me.Controls.Add(Me._fr_1)
    Me.Name = "ucAddUser"
    Me.Size = New System.Drawing.Size(376, 300)
    Me._fr_1.ResumeLayout(False)
    Me.ResumeLayout(False)

  End Sub

#End Region

  Private Sub ucAddUser_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    'mdlTreeView.TypesToTreeView(tcboClientType.TreeDropDown, False)
    Dim roleObj As New clientMgrBusiness.Role
    Dim ErrMsg As String
    Dim Ary As New ArrayList
    ErrMsg = roleObj.GetAllRoles(Ary)
    If ErrMsg <> "" Then
      MsgBox(ErrMsg, MsgBoxStyle.Critical + MsgBoxStyle.OKOnly)
      Return
    End If
    cboRole.DataSource = Ary
    cboRole.DisplayMember = "RoleName"
    cboRole.ValueMember = "RoleId"

  End Sub

  Private Sub cmdAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAdd.Click
    '进行简单验证
    If txtTrueName.Text = "" Then
      MsgBox("请添写用户名", MsgBoxStyle.Critical + MsgBoxStyle.OKOnly)
      Exit Sub
    End If
    If txtAccount.Text = "" Or _
      txtTrueName.Text = "" Or _
      txtPwd.Text = "" Or _
      txtConfirmPwd.Text = "" Then
      MsgBox("请将信息填写完整", MsgBoxStyle.Critical + MsgBoxStyle.OKOnly)
      Exit Sub
    End If
    If Me.cboRole.SelectedIndex < 0 Then
      MsgBox("请选择用户角色", MsgBoxStyle.Critical + MsgBoxStyle.OKOnly)
      Exit Sub
    End If
    If Me.txtPwd.Text <> Me.txtConfirmPwd.Text Then
      MsgBox("两次密码输入不正确", MsgBoxStyle.Critical + MsgBoxStyle.OKOnly)
      Exit Sub
    End If

    Dim ErrMsg As String
    Dim userObj As New clientMgrBusiness.User
    Dim dmUser As New clientMgrBusiness.UserDataModel
    dmUser.m_szUserAccount = txtAccount.Text
    dmUser.m_szTrueName = txtTrueName.Text
    dmUser.m_szUserPwd = txtPwd.Text
    dmUser.m_iRoleID = cboRole.SelectedValue
    '填加用户真实姓名
    ErrMsg = userObj.AddUser(dmUser)
    '如果出错,弹出出错信息
    If ErrMsg <> "" Then
      MsgBox(ErrMsg, MsgBoxStyle.Critical + MsgBoxStyle.OKOnly)
    Else
      MsgBox("填加成功!", MsgBoxStyle.Information + MsgBoxStyle.OKOnly)
      txtAccount.Text = ""
      txtTrueName.Text = ""
      txtPwd.Text = ""
      txtConfirmPwd.Text = ""
    End If

  End Sub

End Class

⌨️ 快捷键说明

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