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

📄 frm_changepassword.vb

📁 基于VBNET编写的图书馆管理系统
💻 VB
字号:
Imports System.Data.OleDb
Public Class frm_ChangePassword
    Inherits System.Windows.Forms.Form
    Dim MyConnection As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Application.StartupPath & "\Library.mdb")
    Dim MyCommand As OleDbCommand
    Dim MyReader As OleDbDataReader
    Dim tempID As String
    Dim tempStatus As String

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    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

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    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 GroupBox1 As System.Windows.Forms.GroupBox
    Friend WithEvents BtnModify As System.Windows.Forms.Button
    Friend WithEvents Button2 As System.Windows.Forms.Button
    Friend WithEvents Button3 As System.Windows.Forms.Button
    Friend WithEvents TxtUserID As System.Windows.Forms.TextBox
    Friend WithEvents TxtOldPass As System.Windows.Forms.TextBox
    Friend WithEvents TxtNewPass As System.Windows.Forms.TextBox
    Friend WithEvents Label4 As System.Windows.Forms.Label
    Friend WithEvents TxtAgain As System.Windows.Forms.TextBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(frm_ChangePassword))
        Me.Label1 = New System.Windows.Forms.Label
        Me.Label2 = New System.Windows.Forms.Label
        Me.Label3 = New System.Windows.Forms.Label
        Me.GroupBox1 = New System.Windows.Forms.GroupBox
        Me.TxtAgain = New System.Windows.Forms.TextBox
        Me.Label4 = New System.Windows.Forms.Label
        Me.TxtNewPass = New System.Windows.Forms.TextBox
        Me.TxtOldPass = New System.Windows.Forms.TextBox
        Me.TxtUserID = New System.Windows.Forms.TextBox
        Me.BtnModify = New System.Windows.Forms.Button
        Me.Button2 = New System.Windows.Forms.Button
        Me.Button3 = New System.Windows.Forms.Button
        Me.GroupBox1.SuspendLayout()
        Me.SuspendLayout()
        '
        'Label1
        '
        Me.Label1.Location = New System.Drawing.Point(52, 26)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(120, 25)
        Me.Label1.TabIndex = 0
        Me.Label1.Text = "用户编号"
        '
        'Label2
        '
        Me.Label2.Location = New System.Drawing.Point(63, 60)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(120, 25)
        Me.Label2.TabIndex = 1
        Me.Label2.Text = "旧密码"
        '
        'Label3
        '
        Me.Label3.Location = New System.Drawing.Point(29, 129)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(120, 25)
        Me.Label3.TabIndex = 2
        Me.Label3.Text = "重新输入密码"
        '
        'GroupBox1
        '
        Me.GroupBox1.Controls.Add(Me.TxtAgain)
        Me.GroupBox1.Controls.Add(Me.Label4)
        Me.GroupBox1.Controls.Add(Me.TxtNewPass)
        Me.GroupBox1.Controls.Add(Me.TxtOldPass)
        Me.GroupBox1.Controls.Add(Me.TxtUserID)
        Me.GroupBox1.Controls.Add(Me.Label1)
        Me.GroupBox1.Controls.Add(Me.Label2)
        Me.GroupBox1.Controls.Add(Me.Label3)
        Me.GroupBox1.Location = New System.Drawing.Point(10, 9)
        Me.GroupBox1.Name = "GroupBox1"
        Me.GroupBox1.Size = New System.Drawing.Size(345, 163)
        Me.GroupBox1.TabIndex = 3
        Me.GroupBox1.TabStop = False
        Me.GroupBox1.Text = "用户信息"
        '
        'TxtAgain
        '
        Me.TxtAgain.Location = New System.Drawing.Point(163, 129)
        Me.TxtAgain.Name = "TxtAgain"
        Me.TxtAgain.Size = New System.Drawing.Size(163, 21)
        Me.TxtAgain.TabIndex = 7
        '
        'Label4
        '
        Me.Label4.Location = New System.Drawing.Point(63, 95)
        Me.Label4.Name = "Label4"
        Me.Label4.Size = New System.Drawing.Size(94, 25)
        Me.Label4.TabIndex = 6
        Me.Label4.Text = "新密码"
        '
        'TxtNewPass
        '
        Me.TxtNewPass.Location = New System.Drawing.Point(163, 95)
        Me.TxtNewPass.Name = "TxtNewPass"
        Me.TxtNewPass.Size = New System.Drawing.Size(163, 21)
        Me.TxtNewPass.TabIndex = 5
        '
        'TxtOldPass
        '
        Me.TxtOldPass.Location = New System.Drawing.Point(163, 60)
        Me.TxtOldPass.Name = "TxtOldPass"
        Me.TxtOldPass.Size = New System.Drawing.Size(163, 21)
        Me.TxtOldPass.TabIndex = 4
        '
        'TxtUserID
        '
        Me.TxtUserID.Location = New System.Drawing.Point(163, 26)
        Me.TxtUserID.Name = "TxtUserID"
        Me.TxtUserID.Size = New System.Drawing.Size(163, 21)
        Me.TxtUserID.TabIndex = 3
        '
        'BtnModify
        '
        Me.BtnModify.Location = New System.Drawing.Point(29, 181)
        Me.BtnModify.Name = "BtnModify"
        Me.BtnModify.Size = New System.Drawing.Size(105, 34)
        Me.BtnModify.TabIndex = 4
        Me.BtnModify.Text = "修改"
        '
        'Button2
        '
        Me.Button2.Location = New System.Drawing.Point(134, 181)
        Me.Button2.Name = "Button2"
        Me.Button2.Size = New System.Drawing.Size(106, 34)
        Me.Button2.TabIndex = 5
        Me.Button2.Text = "重置"
        '
        'Button3
        '
        Me.Button3.Location = New System.Drawing.Point(240, 181)
        Me.Button3.Name = "Button3"
        Me.Button3.Size = New System.Drawing.Size(96, 34)
        Me.Button3.TabIndex = 6
        Me.Button3.Text = "退出"
        '
        'frm_ChangePassword
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
        Me.ClientSize = New System.Drawing.Size(377, 228)
        Me.Controls.Add(Me.Button3)
        Me.Controls.Add(Me.Button2)
        Me.Controls.Add(Me.BtnModify)
        Me.Controls.Add(Me.GroupBox1)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
        Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
        Me.MaximizeBox = False
        Me.MinimizeBox = False
        Me.Name = "frm_ChangePassword"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "修改密码"
        Me.GroupBox1.ResumeLayout(False)
        Me.GroupBox1.PerformLayout()
        Me.ResumeLayout(False)

    End Sub

#End Region
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Me.Close()
    End Sub
    Function clearfields()
        TxtUserID.Text = ""
        TxtNewPass.Text = ""
        TxtOldPass.Text = ""
        TxtAgain.Text = ""
    End Function
    Function checkTextbox(ByVal t As TextBox) As Boolean
        If t.Text = "" Then
            Return (False)
        Else
            Return True
        End If
    End Function
    Function displayMsg(ByVal myMsgText As String)
        MsgBox(myMsgText, MsgBoxStyle.Information, "图书馆管理系统")
    End Function
    Sub updatePassword()
        Dim temp1 As String = TxtNewPass.Text
        Dim temp2 As String = TxtUserID.Text
        MyConnection.Open()
        Try
            MyCommand = New OleDbCommand("UPDATE SystemUsers SET [Password] = '" & temp1 & "' WHERE UserID = '" & temp2 & "'", MyConnection)
            MyCommand.ExecuteNonQuery()
        Catch c As Exception
            MsgBox(c.ToString)
        End Try
        MyConnection.Close()
        MyCommand.Dispose()
    End Sub
    Function checkUserID() As Boolean
        Dim tempID As String
        MyConnection.Open()
        MyCommand = New OleDbCommand("SELECT * FROM SystemUsers WHERE UserID ='" & TxtUserID.Text & "'", MyConnection)
        MyReader = MyCommand.ExecuteReader()
        While MyReader.Read
            tempID = MyReader("UserID")
        End While
        MyConnection.Close()
        MyReader.Close()
        MyCommand.Dispose()
        If tempID = TxtUserID.Text Then
            Return True
        Else
            Return False
        End If
    End Function


    Function checkConfirmPassword() As Boolean
        If TxtNewPass.Text = TxtAgain.Text Then
            Return True
        Else
            If TxtNewPass.Text <> TxtAgain.Text Then
                Return False
            End If
        End If
    End Function
    Function checkpassword() As Boolean
        Dim tempPass As String
        MyConnection.Open()
        MyCommand = New OleDbCommand("SELECT * FROM SystemUsers WHERE UserID ='" & TxtUserID.Text & "'", MyConnection)
        MyReader = MyCommand.ExecuteReader()
        While MyReader.Read
            tempPass = MyReader("Password")
        End While
        MyConnection.Close()
        MyReader.Close()
        MyCommand.Dispose()
        If tempPass = TxtOldPass.Text Then
            Return True
        Else
            Return False
        End If
    End Function
    Private Sub TxtUserID_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TxtUserID.KeyPress
        Dim strChar As String
        strChar = e.KeyChar
        Select Case strChar
            Case ChrW(System.Windows.Forms.Keys.Enter)
                TxtOldPass.Focus()
            Case Else
                '什么也不做
        End Select
    End Sub
    Private Sub TextBox2_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TxtOldPass.KeyPress
        Dim strChar As String
        strChar = e.KeyChar

        Select Case strChar
            Case ChrW(System.Windows.Forms.Keys.Enter)
                TxtNewPass.Focus()
            Case Else
                '什么也不做
        End Select
    End Sub
    Private Sub TextBox3_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TxtNewPass.KeyPress
        Dim strChar As String
        strChar = e.KeyChar

        Select Case strChar
            Case ChrW(System.Windows.Forms.Keys.Enter)
                TxtAgain.Focus()
            Case Else
                '什么也不做
        End Select
    End Sub
    Private Sub TxtAgain_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TxtAgain.KeyPress
        Dim strChar As String
        strChar = e.KeyChar
        Select Case strChar
            Case ChrW(System.Windows.Forms.Keys.Enter)
             
            Case Else
                '什么也不做
        End Select
    End Sub
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        clearfields()
    End Sub
    Private Sub BtnModify_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnModify.Click
        If checkpassword() = False Or checkUserID() = False Then
            displayMsg("密码与用户编号不对应或者用户编号不存在")
            TxtUserID.Focus()
        ElseIf checkConfirmPassword() = False Then
            displayMsg("两次输入的密码不一致,请重新输入")
            Exit Sub
        Else
            If checkpassword() = True And checkUserID() = True Then
                updatePassword()
                displayMsg("你的密码已被更新")
                clearfields()
            End If
        End If
    End Sub



End Class

⌨️ 快捷键说明

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