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

📄 admin_changeadminname.vb

📁 图书馆管理系统,是数据库的课程设计,报告里面包含了需求分析数据字典概念结构设计逻辑结构设计数据库物理设计数据库实施
💻 VB
字号:
Imports System.Data
'引入数据库操作类命名空间
Imports System.Data.OleDb
'引入ADO.NET操作命名空间

Public Class win_chadminname
    Inherits System.Windows.Forms.Form
    Dim login As New library2.win_login
    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 btcancel As System.Windows.Forms.Button
    Friend WithEvents btreset As System.Windows.Forms.Button
    Friend WithEvents btOK As System.Windows.Forms.Button
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents tbConfirmname As System.Windows.Forms.TextBox
    Friend WithEvents tbnewname As System.Windows.Forms.TextBox
    Friend WithEvents tbname As System.Windows.Forms.TextBox
    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_chadminname))
        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.tbConfirmname = New System.Windows.Forms.TextBox
        Me.tbnewname = New System.Windows.Forms.TextBox
        Me.tbname = 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.tbConfirmname)
        Me.GroupBox1.Controls.Add(Me.tbnewname)
        Me.GroupBox1.Controls.Add(Me.tbname)
        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(56, 96)
        Me.Label4.Name = "Label4"
        Me.Label4.Size = New System.Drawing.Size(192, 16)
        Me.Label4.TabIndex = 18
        Me.Label4.Text = "系统自动过滤 ' "" + & | 字符"
        Me.Label4.TextAlign = System.Drawing.ContentAlignment.TopCenter
        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 = "确定"
        '
        'tbConfirmname
        '
        Me.tbConfirmname.Location = New System.Drawing.Point(132, 72)
        Me.tbConfirmname.MaxLength = 10
        Me.tbConfirmname.Name = "tbConfirmname"
        Me.tbConfirmname.Size = New System.Drawing.Size(88, 21)
        Me.tbConfirmname.TabIndex = 3
        Me.tbConfirmname.Text = ""
        '
        'tbnewname
        '
        Me.tbnewname.Location = New System.Drawing.Point(132, 48)
        Me.tbnewname.MaxLength = 10
        Me.tbnewname.Name = "tbnewname"
        Me.tbnewname.Size = New System.Drawing.Size(88, 21)
        Me.tbnewname.TabIndex = 2
        Me.tbnewname.Text = ""
        '
        'tbname
        '
        Me.tbname.Location = New System.Drawing.Point(132, 16)
        Me.tbname.MaxLength = 10
        Me.tbname.Name = "tbname"
        Me.tbname.Size = New System.Drawing.Size(88, 21)
        Me.tbname.TabIndex = 1
        Me.tbname.Text = ""
        '
        'Label3
        '
        Me.Label3.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Label3.Location = New System.Drawing.Point(60, 72)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(72, 24)
        Me.Label3.TabIndex = 11
        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(60, 48)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(72, 24)
        Me.Label2.TabIndex = 10
        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(60, 16)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(72, 24)
        Me.Label1.TabIndex = 9
        Me.Label1.Text = "登陆帐号:"
        Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'win_chadminname
        '
        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_chadminname"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "图书馆管理系统--修改管理员帐号"
        Me.GroupBox1.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub btcancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btcancel.Click
        Close()
    End Sub

    Private Sub btreset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btreset.Click
        tbname.Text = ""
        tbnewname.Text = ""
        tbConfirmname.Text = ""
    End Sub

    Private Sub btOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btOK.Click
        Dim canupdate As Boolean = True, adminname As String, newname As String, confirmname As String
        adminname = filter(Trim(tbname.Text).ToString)
        newname = filter(Trim(tbnewname.Text).ToString)
        confirmname = filter(Trim(tbConfirmname.Text).ToString)
        If adminname = "" Then
            MessageBox.Show("管理员帐号不能有空!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Information)
            tbname.Focus()
            canupdate = False
        ElseIf newname = "" Then
            MessageBox.Show("管理员新帐号不能有空!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Information)
            tbnewname.Focus()
            canupdate = False
        ElseIf confirmname = "" Then
            MessageBox.Show("管理员确定帐号不能有空!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Information)
            tbConfirmname.Focus()
            canupdate = False
        ElseIf newname <> confirmname Then
            MessageBox.Show("两帐号不一致!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Information)
            tbnewname.Focus()
            canupdate = False
        End If

        Try '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''检测输入的帐号与管理员帐号是否一致
            sqlstr = "select * from admininfo where id=" & login.loginid & ""
            objDS = GetData(sqlstr)
            If adminname <> objDS.Tables(0).Rows(0)("adminname").ToString Then '检测输入的帐号与管理员帐号是否一致
                MsgBox("帐号错误。", MsgBoxStyle.Information + MsgBoxStyle.OKOnly, "错误")
                tbname.Focus()
                tbname.Text = ""
                canupdate = False
                'Else
                'canupdate = True'''''''''''''''输入的与读取的相一致''''''默认canupdate为true
            End If
        Catch
            MsgBox("数据错误。", MsgBoxStyle.Information + MsgBoxStyle.OKOnly, "错误")
        End Try

        Try ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''判断新输入的帐号是否存在
            sqlstr = "select * from admininfo where adminname = '" & newname & "'" '判断新输入的帐号是否存在
            objDS = GetData(sqlstr)
            If objDS.Tables(0).Rows.Count > 0 Then '''''''''''''''''''''''''''''''''帐号已经存在
                tbnewname.Text = ""
                tbConfirmname.Text = ""
                MessageBox.Show("管理员帐号已存在!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Information)
                tbnewname.Focus()
                canupdate = False
            End If
        Catch
            MsgBox("数据错误。", MsgBoxStyle.Information + MsgBoxStyle.OKOnly, "错误")
        End Try

        If canupdate Then ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''没有错误
            Try
                sqlstr = "update admininfo set adminname='" & newname & "' where adminname='" & adminname & "'"
                objDS = GetData(sqlstr)
                Me.Close()
                MessageBox.Show("管理员名更新成功" & ControlChars.CrLf & "新管理员名:" & newname, "数据更新成功", 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 + -