📄 frm_changeadmpass.vb
字号:
Imports System.Data.OleDb
Public Class frm_ChangeAdmPass
Dim myConnection As New OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0; Data source=D:\library.mdb")
Dim myCommand As OleDbCommand
Dim myReader As OleDbDataReader
Private Sub frm_ChangeAdmPass_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
admNotxt.Focus()
End Sub
Private Sub oldpasstxt_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles oldPasstxt.KeyPress
If e.KeyChar = ChrW(System.Windows.Forms.Keys.Enter) Then
checkValidAdm()
End If
End Sub
Sub checkValidAdm()
Dim admNo As String = ""
Dim password As String = ""
myConnection.Open()
myCommand = New OleDbCommand("select * from Administrator where AdmNo = '" & admNotxt.Text & _
"'", myConnection)
myReader = myCommand.ExecuteReader()
While myReader.Read
admNo = myReader("AdmNo")
password = myReader("Password")
End While
myConnection.Close()
myReader.Close()
myCommand.Dispose()
If admNo = "" Then
MsgBox("Invalid Administrator ID!")
admNotxt.Clear()
oldPasstxt.Clear()
admNotxt.Focus()
Else
If password = oldPasstxt.Text Then
newPasstxt.Focus()
Else
MsgBox("Invalid Administrator Password!")
oldPasstxt.Focus()
oldPasstxt.SelectAll()
End If
End If
End Sub
Private Sub newpasstxt_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles newPasstxt.KeyPress
If e.KeyChar = ChrW(System.Windows.Forms.Keys.Enter) Then
If newPasstxt.Text = "" Then
MsgBox("password can not be empty!")
newPasstxt.Focus()
Else
againtxt.Focus()
End If
End If
End Sub
Private Sub okbt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles okbt.Click
If checkPasswordSame() Then
changePassword()
Else
MsgBox("The 2nd input new password is not as same as the 1st one!")
againtxt.Focus()
againtxt.SelectAll()
End If
End Sub
Function checkPasswordSame() As Boolean
Dim firstStr As String = newPasstxt.Text
Dim secondStr As String = againtxt.Text
If firstStr.Equals(secondStr) Then
Return True
Else
Return False
End If
End Function
Sub changePassword()
myConnection.Open()
myCommand = New OleDbCommand("Update Administrator set [Password]='" & newPasstxt.Text & _
"' where admNo='" & admNotxt.Text & "'", myConnection)
myCommand.ExecuteNonQuery()
MsgBox("Change password success!")
myConnection.Close()
myCommand.Dispose()
End Sub
Private Sub exitbt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles exitbt.Click
Me.Close()
End Sub
Private Sub resetbt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles resetbt.Click
admNotxt.Clear()
oldPasstxt.Clear()
newPasstxt.Clear()
againtxt.Clear()
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -