📄 admin_addadmin.vb
字号:
Imports System.Data
'引入数据库操作类命名空间
Imports System.Data.OleDb
'引入ADO.NET操作命名空间
Public Class win_addadmin
Inherits System.Windows.Forms.Form
Dim sqlstr As String 'SQL语句标记
Dim objDS As DataSet '数据在内存中的缓存
#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 GroupBox1 As System.Windows.Forms.GroupBox
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 tbnewname As System.Windows.Forms.TextBox
Friend WithEvents tbnewpassword As System.Windows.Forms.TextBox
Friend WithEvents tbConfirmpw As System.Windows.Forms.TextBox
Friend WithEvents btOK As System.Windows.Forms.Button
Friend WithEvents btreset As System.Windows.Forms.Button
Friend WithEvents btcancel As System.Windows.Forms.Button
Friend WithEvents Label4 As System.Windows.Forms.Label
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(win_addadmin))
Me.GroupBox1 = New System.Windows.Forms.GroupBox
Me.Label4 = New System.Windows.Forms.Label
Me.btcancel = New System.Windows.Forms.Button
Me.btreset = New System.Windows.Forms.Button
Me.btOK = New System.Windows.Forms.Button
Me.tbConfirmpw = New System.Windows.Forms.TextBox
Me.tbnewpassword = New System.Windows.Forms.TextBox
Me.tbnewname = New System.Windows.Forms.TextBox
Me.Label3 = New System.Windows.Forms.Label
Me.Label2 = New System.Windows.Forms.Label
Me.Label1 = New System.Windows.Forms.Label
Me.GroupBox1.SuspendLayout()
Me.SuspendLayout()
'
'GroupBox1
'
Me.GroupBox1.Controls.Add(Me.Label4)
Me.GroupBox1.Controls.Add(Me.btcancel)
Me.GroupBox1.Controls.Add(Me.btreset)
Me.GroupBox1.Controls.Add(Me.btOK)
Me.GroupBox1.Controls.Add(Me.tbConfirmpw)
Me.GroupBox1.Controls.Add(Me.tbnewpassword)
Me.GroupBox1.Controls.Add(Me.tbnewname)
Me.GroupBox1.Controls.Add(Me.Label3)
Me.GroupBox1.Controls.Add(Me.Label2)
Me.GroupBox1.Controls.Add(Me.Label1)
Me.GroupBox1.ForeColor = System.Drawing.SystemColors.ControlDark
Me.GroupBox1.Location = New System.Drawing.Point(4, 2)
Me.GroupBox1.Name = "GroupBox1"
Me.GroupBox1.Size = New System.Drawing.Size(280, 152)
Me.GroupBox1.TabIndex = 0
Me.GroupBox1.TabStop = False
Me.GroupBox1.Text = "添加管理员"
'
'Label4
'
Me.Label4.Location = New System.Drawing.Point(48, 96)
Me.Label4.Name = "Label4"
Me.Label4.Size = New System.Drawing.Size(200, 16)
Me.Label4.TabIndex = 9
Me.Label4.Text = "系统自动过滤 ' "" + & | 字符"
Me.Label4.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
Me.Label4.UseMnemonic = False
'
'btcancel
'
Me.btcancel.DialogResult = System.Windows.Forms.DialogResult.Cancel
Me.btcancel.ForeColor = System.Drawing.SystemColors.ControlText
Me.btcancel.Location = New System.Drawing.Point(184, 120)
Me.btcancel.Name = "btcancel"
Me.btcancel.Size = New System.Drawing.Size(56, 24)
Me.btcancel.TabIndex = 6
Me.btcancel.Text = "关闭"
'
'btreset
'
Me.btreset.ForeColor = System.Drawing.SystemColors.ControlText
Me.btreset.Location = New System.Drawing.Point(112, 120)
Me.btreset.Name = "btreset"
Me.btreset.Size = New System.Drawing.Size(56, 24)
Me.btreset.TabIndex = 5
Me.btreset.Text = "重置"
'
'btOK
'
Me.btOK.ForeColor = System.Drawing.SystemColors.ControlText
Me.btOK.Location = New System.Drawing.Point(40, 120)
Me.btOK.Name = "btOK"
Me.btOK.Size = New System.Drawing.Size(56, 24)
Me.btOK.TabIndex = 4
Me.btOK.Text = "确定"
'
'tbConfirmpw
'
Me.tbConfirmpw.Location = New System.Drawing.Point(136, 72)
Me.tbConfirmpw.MaxLength = 10
Me.tbConfirmpw.Name = "tbConfirmpw"
Me.tbConfirmpw.PasswordChar = Microsoft.VisualBasic.ChrW(42)
Me.tbConfirmpw.Size = New System.Drawing.Size(88, 21)
Me.tbConfirmpw.TabIndex = 3
Me.tbConfirmpw.Text = ""
'
'tbnewpassword
'
Me.tbnewpassword.Location = New System.Drawing.Point(136, 48)
Me.tbnewpassword.MaxLength = 10
Me.tbnewpassword.Name = "tbnewpassword"
Me.tbnewpassword.PasswordChar = Microsoft.VisualBasic.ChrW(42)
Me.tbnewpassword.Size = New System.Drawing.Size(88, 21)
Me.tbnewpassword.TabIndex = 2
Me.tbnewpassword.Text = ""
'
'tbnewname
'
Me.tbnewname.Location = New System.Drawing.Point(136, 16)
Me.tbnewname.MaxLength = 10
Me.tbnewname.Name = "tbnewname"
Me.tbnewname.Size = New System.Drawing.Size(88, 21)
Me.tbnewname.TabIndex = 1
Me.tbnewname.Text = ""
'
'Label3
'
Me.Label3.ForeColor = System.Drawing.SystemColors.ControlText
Me.Label3.Location = New System.Drawing.Point(64, 72)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(72, 24)
Me.Label3.TabIndex = 2
Me.Label3.Text = "确定密码:"
Me.Label3.TextAlign = System.Drawing.ContentAlignment.MiddleRight
'
'Label2
'
Me.Label2.ForeColor = System.Drawing.SystemColors.ControlText
Me.Label2.Location = New System.Drawing.Point(64, 48)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(72, 24)
Me.Label2.TabIndex = 1
Me.Label2.Text = "新密码:"
Me.Label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight
'
'Label1
'
Me.Label1.ForeColor = System.Drawing.SystemColors.ControlText
Me.Label1.Location = New System.Drawing.Point(64, 16)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(72, 24)
Me.Label1.TabIndex = 0
Me.Label1.Text = "登陆帐号:"
Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight
'
'win_addadmin
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.CancelButton = Me.btcancel
Me.ClientSize = New System.Drawing.Size(288, 157)
Me.Controls.Add(Me.GroupBox1)
Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
Me.MaximizeBox = False
Me.MaximumSize = New System.Drawing.Size(296, 184)
Me.MinimumSize = New System.Drawing.Size(296, 184)
Me.Name = "win_addadmin"
Me.ShowInTaskbar = False
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "图书馆管理系统--添加管理员"
Me.GroupBox1.ResumeLayout(False)
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub btreset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btreset.Click
tbnewname.Text = ""
tbnewpassword.Text = ""
tbConfirmpw.Text = ""
End Sub
Private Sub btcancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btcancel.Click
Close()
End Sub
Private Sub btOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btOK.Click
Dim canupdate As Boolean = True, newname As String, newpassword As String, confirmpw As String
newname = filter(Trim(tbnewname.Text).ToString)
newpassword = filter(Trim(tbnewpassword.Text).ToString)
confirmpw = filter(Trim(tbConfirmpw.Text).ToString)
If newname = "" Then
MessageBox.Show("管理员新帐号不能有空!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Information)
tbnewname.Focus()
canupdate = False
ElseIf newpassword = "" Then
MessageBox.Show("管理员新密码不能有空!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Information)
tbnewpassword.Focus()
canupdate = False
ElseIf confirmpw = "" Then
MessageBox.Show("管理员确定密码不能有空!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Information)
tbConfirmpw.Focus()
canupdate = False
ElseIf newpassword <> confirmpw Then
MessageBox.Show("两密码不一致!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Information)
tbnewpassword.Focus()
canupdate = False
End If
sqlstr = "select * from admininfo where adminname = '" & newname & "'" '判断新输入的帐号是否存在
objDS = GetData(sqlstr)
If objDS.Tables(0).Rows.Count > 0 Then '帐号已经存在
MessageBox.Show("管理员帐号已存在!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Information)
tbnewname.Focus()
tbnewname.Text = ""
canupdate = False
End If
If canupdate Then '没有错误
Try
sqlstr = "insert into admininfo(adminname,lpassword) values('" & newname & "','" & newpassword & "')"
objDS = GetData(sqlstr)
Me.Close()
MessageBox.Show("添加管理员成功", "数据更新成功", MessageBoxButtons.OK, MessageBoxIcon.Information)
Catch
MsgBox("更新数据库错误。", MsgBoxStyle.Information + MsgBoxStyle.OKOnly, "错误")
End Try
End If
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -