Imports System.Data.SqlClient
Public Class frmAccesscode
    Dim tries As Integer = 3
    Private Sub txtAccess_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtAccess.KeyDown
        If e.KeyCode = Keys.Enter Then
            If tries = 1 Then
                MessageBox.Show("Sorry, you don't have a privilege to access", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
                Me.Close()
                Return
            End If
            cm = New SqlCommand("select * from tblUser where privilege like 'admin' and accesscode like '" & txtAccess.Text & "'", cn)
            dr = cm.ExecuteReader
            dr.Read()
            If dr.HasRows Then
                MessageBox.Show("Access Granted. Welcome boss " + dr.GetValue(3).ToString() + "", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information)
                dr.Close()
                frmCenter.auditTrail(uID, "Access code granted")
                Me.Close()
                frmManagement.ShowDialog()

            Else
                MessageBox.Show("Incorrect access code", "Erorr", MessageBoxButtons.OK, MessageBoxIcon.Error)
                dr.Close()
                frmCenter.auditTrail(uID, "Incorrect access code")
                tries = tries - 1

            End If
            dr.Close()
        End If
    End Sub

    Private Sub frmAccesscode_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        accesscode(uID, logID)
    End Sub

    Public Sub accesscode(ByVal uID As String, ByVal logID As String)
        frmCenter.auditTrail(uID, "Showed access code form")
    End Sub
End Class