Imports System.ComponentModel
Public Class frmLogIn
    Private Sub frmLogIn_Load(sender As Object, e As EventArgs) Handles Me.Load
        InitializeDatabaseConnection()
        sqlSTR = "SELECT   USER_ID, User_Name  FROM   ApplicationUser  ORDER BY User_Name"
        ExecuteSQLQuery(sqlSTR)
        If Not sqlDT.Rows.Count > 0 Then
            ExecuteSQLQuery(" INSERT INTO  ApplicationUser (Full_Name, Fathers_Name, User_Name, Password, Email, UserType) VALUES " &
                            " ('Your name here', 'Father name', 'admin', '12345', 'example@yourmail.com', 'Admin') ")
        End If
        FillDataComboBox(sqlSTR, "USER_ID", "User_Name", cmbUsers)
        If My.Settings.APP_REMEMBER = True Then
            cmbUsers.SelectedValue = My.Settings.LOGGED_USER_ID
            txtPassword.Text = My.Settings.LOGGED_USER_PASSWORD
            chkRememberMe.Checked = My.Settings.APP_REMEMBER
        End If
    End Sub
    Private Sub btnLogin_Click(sender As Object, e As EventArgs) Handles btnLogin.Click


        ExecuteSQLQuery("SELECT * FROM ApplicationUser WHERE USER_ID='" & num_fltr(cmbUsers.SelectedValue) & "' AND Password ='" & str_repl(txtPassword.Text) & "' ")
        If sqlDT.Rows.Count > 0 Then
            xUser_ID = sqlDT.Rows(0)("USER_ID")
            xUserName = sqlDT.Rows(0)("User_Name")


            If sqlDT.Rows(0)("UserType") = "Manager" Then
                frmMDIParent.Show()
                With frmMDIParent
                    .BarStaticItem1.Caption = "test"
                End With
                'With frmMDIParent1
                '    .OptionsToolStripMenuItem.Enabled = False
                '    .AttendanceCardToolStripMenuItem.Enabled = False
                '    .FingerprintToolStripMenuItem.Enabled = False
                '    .EmployeeListToolStripMenuItem.Enabled = False
                '    .CompanyDetailsToolStripMenuItem.Enabled = False
                '    .ShiftManagementToolStripMenuItem.Enabled = False
                '    .DepartmentInformationToolStripMenuItem.Enabled = False
                '    .DesignationToolStripMenuItem.Enabled = False
                '    .btnShift.Enabled = False
                '    .btnCompany.Enabled = False
                '    .Show()
                'End With
            ElseIf sqlDT.Rows(0)("UserType") = "Admin" Then
                frmMDIParent.Show()
                My.Settings.userlevel = "Admin"
                My.Settings.Save()
                'With frmMDIParent
                '.BarStaticItem1.Caption = "Admin"
                '.OptionsToolStripMenuItem.Enabled = True
                '.AttendanceCardToolStripMenuItem.Enabled = True
                '.FingerprintToolStripMenuItem.Enabled = True
                '.EmployeeListToolStripMenuItem.Enabled = True
                '.CompanyDetailsToolStripMenuItem.Enabled = True
                '.ShiftManagementToolStripMenuItem.Enabled = True
                '.DepartmentInformationToolStripMenuItem.Enabled = True
                '.DesignationToolStripMenuItem.Enabled = True
                '.btnShift.Enabled = True
                '.btnCompany.Enabled = True
                '.Show()
                ' End With
            ElseIf sqlDT.Rows(0)("UserType") = "User" Then
                frmMDIParent.Show()
                With frmMDIParent
                    .BarStaticItem2.Caption = sqlDT.Rows(0)("EMPLOYEE_ID")
                End With
            End If

            Me.Visible = False
        Else
            MsgBox("You have no permission to use this system, for further details please contact to your top managment system.", MsgBoxStyle.Information, "Warning.")
            xcountx = xcountx + 1
            If xcountx >= 3 Then
                MsgBox("You have reach the maximum time of login !!", MsgBoxStyle.Critical, "Error.")
                End
            End If
            Exit Sub
        End If
        If chkRememberMe.Checked = True Then
            My.Settings.LOGGED_USER_ID = cmbUsers.SelectedValue
            My.Settings.LOGGED_USER_PASSWORD = txtPassword.Text
            My.Settings.APP_REMEMBER = chkRememberMe.Checked
            My.Settings.Save()
        Else
            My.Settings.LOGGED_USER_ID = Nothing
            My.Settings.LOGGED_USER_PASSWORD = Nothing
            My.Settings.APP_REMEMBER = False
            My.Settings.Save()
        End If
    End Sub
    Private Sub frmLogIn_Closing(sender As Object, e As CancelEventArgs) Handles Me.Closing
        frmManagement.Show()

    End Sub
    Private Sub btnClose_Click(sender As Object, e As EventArgs) Handles btnClose.Click
        Me.Close()
    End Sub
End Class