假设所有文本字段和组合框中都有值。我希望当我点击编辑按钮时,会出现一个弹出窗口,在启用文本字段之前需要用户密码..这可能吗?如是?什么是代码/语法。提前谢谢!
答案 0 :(得分:0)
是的,有可能,我在这里使用Mike
作为用户名,Mike124
作为密码,以下是执行该操作的代码:
'Here is the click event when the user clicks on the edit button
Private Sub EditBUT_Click(sender As Object, e As EventArgs) Handles EditBUT.Click
RecheckUsername: Dim UserNameInput As String = InputBox("Please enter your username :")
If UserNameInput = "Mike" And UserNameInput <> "" Then
ReheckPassword: Dim PasswordInput As String = InputBox("Please enter your password :")
If PasswordInput = "Mike124" And PasswordInput <> "" Then
'Enable the all the fields here because the username and the password are correct
Else
'The password is wrong
MsgBox("Please check your password and try again")
GoTo ReheckPassword
End If
Else
'The username is wrong
MsgBox("Please check your username and try again")
GoTo RecheckUsername
End If
End Sub
如果您想要一种存储用户名和密码的方法,可以使用My.Settings.Username
和My.Settings.Password
,但首先,您需要在您的属性中定义它们解决方案,只需转到Project
中的Toolbar
标签,然后点击Properties
,然后转到Settings
标签,设置Username
和{{ 1}}变量。
希望能帮助您满足您的需求:)
答案 1 :(得分:0)
Private Sub ACCOUNT_RECHECK()
Dim UserNameInput As String = InputBox("Please Enter your Username:")
Dim PasswordInput As String = InputBox("Please Enter your Password:")
Try
dbconnect.Open()
qInsert = "Select * from tblAdmin where Admin_UName='" & UserNameInput & "' and Admin_Password='" & PasswordInput & "'"
dbcommand = New OleDbCommand(qInsert, dbconnect)
dbcommand.ExecuteNonQuery()
Dim dr = dbcommand.ExecuteReader
If dr.Read = True Then
AccountType1 = dr("Admin_Type")
AccessGranted1 = True
dbconnect.Close()
Else
AccessGranted1 = False
End If
dbconnect.Close()
Catch ex As Exception
MsgBox(Err.Description)
End Try
End Sub
Private Sub btnEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEdit.Click
ACCOUNT_RECHECK()
If AccountType1 = False Then
MsgBox("INVALID! YOU'RE NOT ALLOWED TO MODIFY THIS DATA!", MsgBoxStyle.Exclamation)
End If
If AccessGranted1 = True Then
MsgBox("ACCESS GRANTED!", MsgBoxStyle.Information)
If AccountType1 = 1 Then
TAGA_ENABLE()
TAGA_ENABLEB()
ElseIf AccountType1 = 2 Then
MsgBox("Sorry, your access role is only for viewing! Kindly ask the Admin to change your role to modify this data", MsgBoxStyle.Information)
End If
End If
End Sub