在编辑时保护记录

Securing records when it comes to editing

假设所有文本字段和组合框中都有值。我希望当我点击编辑按钮时,会出现一个弹出窗口 window,在启用文本字段之前需要用户密码。这可能吗?如是? code/syntax 是什么。提前致谢!

是的,有可能,这里我使用 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.UsernameMy.Settings.Password但是首先你需要定义它们在解决方案的属性中,只需转到 Toolbar 中的 Project 选项卡并单击 Properties,然后转到 Settings 选项卡并设置 UsernamePassword 个变量。

希望对您有所帮助:)

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