Login window of computer room charging system (setting of login level)

The first step when the computer room charging system is running is to log in. Today, let's talk about the login window

1, Process sorting of login form:

2, Error set:

Logic error

There is nothing wrong with the syntax and operation of this form, but there are some problems in the logic. At the beginning, I forgot the permission settings of different levels of login. The code listed in setting permission login is skipped directly, no running

Bad code:

    If mrc.Fields(2) = "General user" Then            'Judge user level
        frmmain.admin.Enabled = False            'Freeze the corresponding menu bar
        frmmain.operator.Enabled = False
    End If
    
    If mrc.Fields(2)= "Operator" Then
        frmmain.admin.Enabled = False
    End If

After debugging for many times, we found the problem because there are many spaces in the value of mrc.fields(2). If the conditions are not satisfied, we will jump all the time. Later, we added the Trim function and it was OK^_^

Correct code:

    If Trim(mrc.Fields(2)) = "General user" Then      'Judge user level
        frmmain.admin.Enabled = False            'Freeze the corresponding menu bar
        frmmain.operator.Enabled = False
    End If
    
    If Trim(mrc.Fields(2)) = "Operator" Then
        frmmain.admin.Enabled = False
    End If

3, Query set:

① , how to judge whether the text box content is empty?

Testtxt function

② How to determine whether there is the user in the database?

mrc.EOF    mrc.BOF

③ How to judge the number of password input times?

Define a miCount variable, and add 1 for each run

4, Code snippet:

① . judge whether the text box is empty

Public Function testtxt(txt As String) As Boolean
    If Trim(txt) = "" Then
        testtxt = False
    Else
        testtxt = True
    End If

End Function

② . judge whether the database has the user

     If mrc.EOF Then                                      'adopt EOF,BOF To determine whether there is the user
        MsgBox "There is no such user, please re-enter the user name", vbOKOnly, "reminder:"
        txtuserID.Text = ""                               'Clear user name text box contents
        txtuserID.SetFocus
    Else
        If Trim(mrc.Fields(1)) = Trim(txtPWD.Text) Then   'If the input password is equal to the database password
            
        Me.Hide
        ......

③ How to judge the input times

            If miCount = 1 Then
                MsgBox "You have two more chances!", vbOKOnly, "Reminder"
                txtPWD.Text = ""
                txtPWD.SetFocus
                Exit Sub
            End If
            
            If miCount = 2 Then
                MsgBox "You have another chance!", vbOKOnly, "Reminder:"
                txtPWD.Text = ""
                txtPWD.SetFocus
                Exit Sub
            End If
            
            If miCount = 3 Then
                MsgBox "You have entered too many times, the program will close soon!", vbOKOnly, "reminder:"
                End
            End If

④ How to determine the login user level

    If Trim(mrc.Fields(2)) = "General user" Then      'Judge user level
        frmmain.admin.Enabled = False            'Freeze the corresponding menu bar
        frmmain.operator.Enabled = False
    End If
    
    If Trim(mrc.Fields(2)) = "Operator" Then
        frmmain.admin.Enabled = False
    End If

This login form has been simply completed. The above codes are for ensuring the operation of the code, and do not include the details of the optimization part. Next station

 

 

 

 

Keywords: Database

Added by remote2 on Wed, 01 Jan 2020 14:34:43 +0200