📄 管理员管理.vb
字号:
Imports System.Data
Imports System.Data.OleDb
Public Class 管理员管理
Inherits System.Windows.Forms.Form
#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 MainMenu1 As System.Windows.Forms.MainMenu
Friend WithEvents MenuItem1 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem2 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem3 As System.Windows.Forms.MenuItem
Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
Friend WithEvents Button2 As System.Windows.Forms.Button
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents GroupBox2 As System.Windows.Forms.GroupBox
Friend WithEvents DataGrid1 As System.Windows.Forms.DataGrid
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.MainMenu1 = New System.Windows.Forms.MainMenu
Me.MenuItem1 = New System.Windows.Forms.MenuItem
Me.MenuItem2 = New System.Windows.Forms.MenuItem
Me.MenuItem3 = New System.Windows.Forms.MenuItem
Me.GroupBox1 = New System.Windows.Forms.GroupBox
Me.Button2 = New System.Windows.Forms.Button
Me.Button1 = New System.Windows.Forms.Button
Me.TextBox2 = New System.Windows.Forms.TextBox
Me.Label2 = New System.Windows.Forms.Label
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.Label1 = New System.Windows.Forms.Label
Me.GroupBox2 = New System.Windows.Forms.GroupBox
Me.DataGrid1 = New System.Windows.Forms.DataGrid
Me.GroupBox1.SuspendLayout()
Me.GroupBox2.SuspendLayout()
CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'MainMenu1
'
Me.MainMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem1, Me.MenuItem3})
'
'MenuItem1
'
Me.MenuItem1.Index = 0
Me.MenuItem1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem2})
Me.MenuItem1.Text = "文件(&F)"
'
'MenuItem2
'
Me.MenuItem2.Index = 0
Me.MenuItem2.Text = "退出(&X)"
'
'MenuItem3
'
Me.MenuItem3.Index = 1
Me.MenuItem3.Shortcut = System.Windows.Forms.Shortcut.F1
Me.MenuItem3.Text = "帮助(&H)"
'
'GroupBox1
'
Me.GroupBox1.Controls.Add(Me.Button2)
Me.GroupBox1.Controls.Add(Me.Button1)
Me.GroupBox1.Controls.Add(Me.TextBox2)
Me.GroupBox1.Controls.Add(Me.Label2)
Me.GroupBox1.Controls.Add(Me.TextBox1)
Me.GroupBox1.Controls.Add(Me.Label1)
Me.GroupBox1.Location = New System.Drawing.Point(8, 0)
Me.GroupBox1.Name = "GroupBox1"
Me.GroupBox1.Size = New System.Drawing.Size(120, 144)
Me.GroupBox1.TabIndex = 1
Me.GroupBox1.TabStop = False
'
'Button2
'
Me.Button2.Location = New System.Drawing.Point(32, 112)
Me.Button2.Name = "Button2"
Me.Button2.TabIndex = 5
Me.Button2.Text = "更改"
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(32, 88)
Me.Button1.Name = "Button1"
Me.Button1.TabIndex = 4
Me.Button1.Text = "添加"
'
'TextBox2
'
Me.TextBox2.Location = New System.Drawing.Point(8, 64)
Me.TextBox2.Name = "TextBox2"
Me.TextBox2.PasswordChar = Microsoft.VisualBasic.ChrW(42)
Me.TextBox2.TabIndex = 3
Me.TextBox2.Text = ""
'
'Label2
'
Me.Label2.Location = New System.Drawing.Point(8, 48)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(53, 16)
Me.Label2.TabIndex = 2
Me.Label2.Text = "密码"
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(8, 24)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.TabIndex = 1
Me.TextBox1.Text = ""
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(8, 8)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(48, 16)
Me.Label1.TabIndex = 0
Me.Label1.Text = "用户名"
'
'GroupBox2
'
Me.GroupBox2.Controls.Add(Me.DataGrid1)
Me.GroupBox2.Location = New System.Drawing.Point(128, 0)
Me.GroupBox2.Name = "GroupBox2"
Me.GroupBox2.Size = New System.Drawing.Size(152, 144)
Me.GroupBox2.TabIndex = 2
Me.GroupBox2.TabStop = False
'
'DataGrid1
'
Me.DataGrid1.DataMember = ""
Me.DataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText
Me.DataGrid1.Location = New System.Drawing.Point(8, 16)
Me.DataGrid1.Name = "DataGrid1"
Me.DataGrid1.Size = New System.Drawing.Size(136, 120)
Me.DataGrid1.TabIndex = 0
'
'管理员管理
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.ClientSize = New System.Drawing.Size(280, 145)
Me.Controls.Add(Me.GroupBox2)
Me.Controls.Add(Me.GroupBox1)
Me.MaximizeBox = False
Me.Menu = Me.MainMenu1
Me.Name = "管理员管理"
Me.Text = "管理员管理"
Me.GroupBox1.ResumeLayout(False)
Me.GroupBox2.ResumeLayout(False)
CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem2.Click
Me.Close()
End Sub
Dim cmd As New OleDbCommand
Dim cmda As New OleDbCommand("select * from 管理员表", myconn)
Dim da As OleDbDataAdapter = New OleDbDataAdapter(cmda)
Dim dsa As DataSet = New DataSet
Sub db()
dsa.Clear()
da.Fill(dsa)
DataGrid1.DataSource = dsa.Tables(0)
myconn.Close()
End Sub
Private Sub 用户管理_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
db()
Catch ex As Exception
End Try
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
Dim strsql As String
strsql = "insert into 管理员表(用户名,密码) values('" & TextBox1.Text & "','" & TextBox2.Text & "')"
myconn.Open()
cmd = New OleDbCommand
cmd.Connection = myconn
cmd.CommandText() = strsql
cmd.ExecuteNonQuery()
myconn.Close()
db()
Catch ex As Exception
End Try
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Try
Dim strsql As String
strsql = "update 管理员表 set 密码='" & TextBox2.Text & "' where 用户名='" & TextBox1.Text & "' "
myconn.Open()
cmd = New OleDbCommand
cmd.Connection = myconn
cmd.CommandText() = strsql
cmd.ExecuteNonQuery()
myconn.Close()
db()
TextBox1.Enabled = True
Button1.Enabled = True
Catch ex As Exception
End Try
End Sub
Private Sub MenuItem3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem3.Click
Process.Start(Application.StartupPath & ("\3.txt"))
End Sub
Private Sub DataGrid1_CurrentCellChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGrid1.CurrentCellChanged
Try
Dim yongh As String
yongh = DataGrid1.Item(DataGrid1.CurrentCell.RowNumber, 0)
MsgBox(yongh)
Dim yonghcmda As New OleDbCommand("select * from 管理员表 where 用户名='" & yongh & "'", myconn)
Dim yonghda As OleDbDataAdapter = New OleDbDataAdapter(yonghcmda)
Dim yonghdsa As DataSet = New DataSet
yonghdsa.Clear()
yonghda.Fill(yonghdsa)
TextBox1.Text = yonghdsa.Tables(0).Rows(0)("用户名")
TextBox2.Text = yonghdsa.Tables(0).Rows(0)("密码")
TextBox1.Enabled = False
Button1.Enabled = False
Catch ex As Exception
End Try
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -