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

📄 usermanager.vb

📁 图书管理系统 书籍的管理应用 源码可以直接用
💻 VB
字号:
Public Class usermanager
    Inherits System.Windows.Forms.Form

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

    Public Sub New()
        MyBase.New()

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

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

    End Sub

    '窗体重写处置以清理组件列表。
    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 窗体设计器修改此过程。
    '不要使用Code编辑器修改它。
    Friend WithEvents DataGrid1 As System.Windows.Forms.DataGrid
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
    Friend WithEvents Label6 As System.Windows.Forms.Label
    Friend WithEvents Commend As System.Windows.Forms.TextBox
    Friend WithEvents txtName As System.Windows.Forms.TextBox
    Friend WithEvents btnFirst As System.Windows.Forms.Button
    Friend WithEvents btnPre As System.Windows.Forms.Button
    Friend WithEvents btnNext As System.Windows.Forms.Button
    Friend WithEvents btnLast As System.Windows.Forms.Button
    Friend WithEvents btnUpdate As System.Windows.Forms.Button
    Friend WithEvents btnClear As System.Windows.Forms.Button
    Friend WithEvents btnAdd As System.Windows.Forms.Button
    Friend WithEvents btnDelete As System.Windows.Forms.Button
    Friend WithEvents btnExit As System.Windows.Forms.Button
    Friend WithEvents txtPassword As System.Windows.Forms.TextBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.DataGrid1 = New System.Windows.Forms.DataGrid
        Me.Label1 = New System.Windows.Forms.Label
        Me.Label2 = New System.Windows.Forms.Label
        Me.txtName = New System.Windows.Forms.TextBox
        Me.txtPassword = New System.Windows.Forms.TextBox
        Me.btnFirst = New System.Windows.Forms.Button
        Me.btnPre = New System.Windows.Forms.Button
        Me.btnNext = New System.Windows.Forms.Button
        Me.btnLast = New System.Windows.Forms.Button
        Me.btnUpdate = New System.Windows.Forms.Button
        Me.GroupBox1 = New System.Windows.Forms.GroupBox
        Me.Commend = New System.Windows.Forms.TextBox
        Me.Label6 = New System.Windows.Forms.Label
        Me.btnClear = New System.Windows.Forms.Button
        Me.btnAdd = New System.Windows.Forms.Button
        Me.btnDelete = New System.Windows.Forms.Button
        Me.btnExit = New System.Windows.Forms.Button
        CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.GroupBox1.SuspendLayout()
        Me.SuspendLayout()
        '
        'DataGrid1
        '
        Me.DataGrid1.CaptionVisible = False
        Me.DataGrid1.DataMember = ""
        Me.DataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText
        Me.DataGrid1.Location = New System.Drawing.Point(16, 16)
        Me.DataGrid1.Name = "DataGrid1"
        Me.DataGrid1.Size = New System.Drawing.Size(296, 256)
        Me.DataGrid1.TabIndex = 0
        '
        'Label1
        '
        Me.Label1.Location = New System.Drawing.Point(328, 48)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(64, 16)
        Me.Label1.TabIndex = 2
        Me.Label1.Text = "用户名:"
        '
        'Label2
        '
        Me.Label2.Location = New System.Drawing.Point(328, 88)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(48, 16)
        Me.Label2.TabIndex = 3
        Me.Label2.Text = "密码:"
        '
        'txtName
        '
        Me.txtName.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.txtName.Enabled = False
        Me.txtName.Location = New System.Drawing.Point(416, 48)
        Me.txtName.Name = "txtName"
        Me.txtName.Size = New System.Drawing.Size(136, 21)
        Me.txtName.TabIndex = 5
        Me.txtName.Text = ""
        '
        'txtPassword
        '
        Me.txtPassword.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.txtPassword.Location = New System.Drawing.Point(416, 80)
        Me.txtPassword.Name = "txtPassword"
        Me.txtPassword.Size = New System.Drawing.Size(136, 21)
        Me.txtPassword.TabIndex = 6
        Me.txtPassword.Text = ""
        '
        'btnFirst
        '
        Me.btnFirst.Location = New System.Drawing.Point(328, 200)
        Me.btnFirst.Name = "btnFirst"
        Me.btnFirst.Size = New System.Drawing.Size(56, 24)
        Me.btnFirst.TabIndex = 8
        Me.btnFirst.Text = "<<"
        '
        'btnPre
        '
        Me.btnPre.Location = New System.Drawing.Point(384, 200)
        Me.btnPre.Name = "btnPre"
        Me.btnPre.Size = New System.Drawing.Size(56, 24)
        Me.btnPre.TabIndex = 9
        Me.btnPre.Text = "<"
        '
        'btnNext
        '
        Me.btnNext.Location = New System.Drawing.Point(440, 200)
        Me.btnNext.Name = "btnNext"
        Me.btnNext.Size = New System.Drawing.Size(56, 24)
        Me.btnNext.TabIndex = 10
        Me.btnNext.Text = ">"
        '
        'btnLast
        '
        Me.btnLast.Location = New System.Drawing.Point(496, 200)
        Me.btnLast.Name = "btnLast"
        Me.btnLast.Size = New System.Drawing.Size(56, 24)
        Me.btnLast.TabIndex = 11
        Me.btnLast.Text = ">>"
        '
        'btnUpdate
        '
        Me.btnUpdate.Location = New System.Drawing.Point(328, 240)
        Me.btnUpdate.Name = "btnUpdate"
        Me.btnUpdate.Size = New System.Drawing.Size(56, 24)
        Me.btnUpdate.TabIndex = 13
        Me.btnUpdate.Text = "更新"
        '
        'GroupBox1
        '
        Me.GroupBox1.BackColor = System.Drawing.Color.Transparent
        Me.GroupBox1.Controls.Add(Me.Commend)
        Me.GroupBox1.Controls.Add(Me.Label6)
        Me.GroupBox1.Controls.Add(Me.btnClear)
        Me.GroupBox1.Controls.Add(Me.btnAdd)
        Me.GroupBox1.Controls.Add(Me.btnDelete)
        Me.GroupBox1.Controls.Add(Me.btnUpdate)
        Me.GroupBox1.Controls.Add(Me.btnPre)
        Me.GroupBox1.Controls.Add(Me.txtPassword)
        Me.GroupBox1.Controls.Add(Me.btnNext)
        Me.GroupBox1.Controls.Add(Me.Label1)
        Me.GroupBox1.Controls.Add(Me.btnLast)
        Me.GroupBox1.Controls.Add(Me.btnFirst)
        Me.GroupBox1.Controls.Add(Me.Label2)
        Me.GroupBox1.Controls.Add(Me.txtName)
        Me.GroupBox1.Controls.Add(Me.DataGrid1)
        Me.GroupBox1.Location = New System.Drawing.Point(16, 40)
        Me.GroupBox1.Name = "GroupBox1"
        Me.GroupBox1.Size = New System.Drawing.Size(584, 288)
        Me.GroupBox1.TabIndex = 14
        Me.GroupBox1.TabStop = False
        '
        'Commend
        '
        Me.Commend.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.Commend.Location = New System.Drawing.Point(416, 120)
        Me.Commend.Multiline = True
        Me.Commend.Name = "Commend"
        Me.Commend.Size = New System.Drawing.Size(136, 64)
        Me.Commend.TabIndex = 18
        Me.Commend.Text = ""
        '
        'Label6
        '
        Me.Label6.Font = New System.Drawing.Font("宋体", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
        Me.Label6.Location = New System.Drawing.Point(328, 128)
        Me.Label6.Name = "Label6"
        Me.Label6.Size = New System.Drawing.Size(80, 16)
        Me.Label6.TabIndex = 17
        Me.Label6.Text = "用户描述:"
        '
        'btnClear
        '
        Me.btnClear.Location = New System.Drawing.Point(496, 240)
        Me.btnClear.Name = "btnClear"
        Me.btnClear.Size = New System.Drawing.Size(56, 24)
        Me.btnClear.TabIndex = 16
        Me.btnClear.Text = "清空"
        '
        'btnAdd
        '
        Me.btnAdd.Location = New System.Drawing.Point(432, 240)
        Me.btnAdd.Name = "btnAdd"
        Me.btnAdd.Size = New System.Drawing.Size(56, 24)
        Me.btnAdd.TabIndex = 15
        Me.btnAdd.Text = "添加"
        '
        'btnDelete
        '
        Me.btnDelete.Location = New System.Drawing.Point(392, 240)
        Me.btnDelete.Name = "btnDelete"
        Me.btnDelete.Size = New System.Drawing.Size(56, 24)
        Me.btnDelete.TabIndex = 14
        Me.btnDelete.Text = "删除"
        '
        'btnExit
        '
        Me.btnExit.Location = New System.Drawing.Point(512, 8)
        Me.btnExit.Name = "btnExit"
        Me.btnExit.Size = New System.Drawing.Size(88, 24)
        Me.btnExit.TabIndex = 15
        Me.btnExit.Text = "退出"
        '
        'usermanager
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
        Me.BackColor = System.Drawing.Color.LightSteelBlue
        Me.ClientSize = New System.Drawing.Size(616, 341)
        Me.Controls.Add(Me.btnExit)
        Me.Controls.Add(Me.GroupBox1)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
        Me.Name = "usermanager"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "用户管理"
        CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).EndInit()
        Me.GroupBox1.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub

#End Region

    '定义全局变量,用于类内部参数传递
    Dim dtset As New DataSet()
    Dim strcom As String
    Dim intMax As Integer
    '当前显示索引变量
    Dim intCurrent As Integer

    '窗体启动时加载数据
    Private Sub usermanager_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        search()
        txtName.Enabled = False
    End Sub

    '从数据库查询数据
    Sub search()
        strcom = "select * from Operator	"
        dtset = executeSelectQuery(strcom, "users")
        DataGrid1.DataSource = dtset.Tables("users")
        intCurrent = 0
        intMax = dtset.Tables("users").Rows.Count - 1
        display(intCurrent)
    End Sub

    '详细显示其中一条纪录
    Sub display(ByVal index As Integer)
        With dtset.Tables("users").Rows(index)
            txtName.Text = .Item("Name") & ""
            txtPassword.Text = .Item("Password") & ""
            Commend.Text = .Item("Comment") & ""
        End With

    End Sub

    '更新用户信息
    Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
        strcom = "update Operator	 set Password='" + Trim(txtPassword.Text) + "', Comment='" & Commend.Text & "' where Name='" + Trim(txtName.Text) + "'"
        executeNonQuery(strcom)
        search()
    End Sub

    '删除用户信息
    Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
        strcom = "delete from Operator	 where Name='" + Trim(txtName.Text) + "'"
        executeNonQuery(strcom)
        search()
    End Sub

    '添加用户信息
    Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
        If Trim(txtName.Text) = "" Then
            showMsg("请输入操作员信息!", MsgBoxStyle.Information)
            Exit Sub
        End If
        strcom = "insert into Operator	(Name,Password,Comment)values('" + Trim(txtName.Text) + "','" + Trim(txtPassword.Text) + "','" + Commend.Text + "')"
        '执行数据库操作,返回操作成功或失败信息
        If executeNonQuery(strcom) = True Then
            showMsg("添加成功!!!", MsgBoxStyle.Information)
        Else
            showMsg("添加不成功!!!", MsgBoxStyle.Exclamation)
        End If
        txtName.Enabled = False
        txtName.Clear()
        txtPassword.Clear()
        search()
    End Sub

    Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
        '清空
        txtName.Enabled = True
        txtName.Clear()
        txtPassword.Clear()
        Commend.Clear()
    End Sub

    '移动到显示第一个
    Private Sub btnFirst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFirst.Click
        intCurrent = 0
        display(intCurrent)
    End Sub

    '移动到显示前一个
    Private Sub btnPre_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPre.Click
        If intCurrent - 1 >= 0 Then
            intCurrent = intCurrent - 1
        End If
        display(intCurrent)
    End Sub

    '移动到显示后一个
    Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
        If intCurrent + 1 <= intMax Then
            intCurrent = intCurrent + 1
        End If
        display(intCurrent)
    End Sub

    '移动到显示最后一个
    Private Sub btnLast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLast.Click
        intCurrent = intMax
        display(intCurrent)
    End Sub

    '双击时,详细显示此人信息
    Private Sub DataGrid1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGrid1.DoubleClick
        display(DataGrid1.CurrentRowIndex)
    End Sub

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

End Class

⌨️ 快捷键说明

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