Public Class frmLoginUserSelect

    Private Sub frmLoginUserSelect_KeyUp(sender As Object, e As KeyEventArgs) Handles Me.KeyUp
        If e.KeyCode = Keys.Return Then
            Login()
        End If
    End Sub

    Private Sub frmLoginUserSelect_Load(sender As Object, e As EventArgs) Handles Me.Load
        Dim Sql = String.Format("SELECT * FROM TBDD_USER WHERE MODULE_RECORD_ORG = 1")
        Dim DT_USER = ClassDatabase.Return_Datatable(Sql)
        Try
            DD_ECMAdmin.TBAD_Users.Clear()

            For Each row As DataRow In DT_USER.Rows
                Dim newUserRow As DD_ECMAdmin.TBAD_UsersRow
                newUserRow = DD_ECMAdmin.TBAD_Users.NewTBAD_UsersRow
                newUserRow.Username = row.Item("USERNAME")
                newUserRow.Surname = row.Item("NAME")
                newUserRow.Prename = row.Item("PRENAME")
                Try
                    newUserRow.Email = row.Item("EMAIL")
                Catch ex As Exception
                    newUserRow.Email = ""
                End Try

                newUserRow.ID = row.Item("GUID")
                DD_ECMAdmin.TBAD_Users.Rows.Add(newUserRow)
                ' chklbxUserForGroup.Items.Add(New MyListBoxItem() With {.Text = row.Item(1), .ExtraData = row.Item(0)})
            Next
        Catch ex As Exception
            MsgBox("Error Load_Users:" & vbNewLine & ex.Message)
        End Try
    End Sub

    Private Sub btnLogin_Click(sender As Object, e As EventArgs) Handles btnLogin.Click
        Login()
    End Sub
    Sub Login()
        Try
            Dim COUNT As Integer
            For Each row As DataRow In DD_ECMAdmin.TBAD_Users.Rows
                If row.Item(0) = CBool(True) Then
                    COUNT += 1
                End If

            Next
            If COUNT = 1 Then
                For Each row As DataRow In DD_ECMAdmin.TBAD_Users.Rows
                    If row.Item(0) = CBool(True) Then
                        Dim User = row.Item("USERNAME")
                        USER_USERNAME = row.Item("USERNAME")
                        USER_PERSONIFIED_TEST = True
                        Me.Close()
                    End If
                Next
            Else
                If COUNT > 0 Then
                    MsgBox("Please choose one User!", MsgBoxStyle.Exclamation)
                Else
                    MsgBox("Please choose only one User!", MsgBoxStyle.Exclamation)
                End If

                Exit Sub
            End If
            For Each row As DataRow In DD_ECMAdmin.TBAD_Users.Rows
                row.Item(0) = CBool(False)
            Next
        Catch ex As Exception
            MsgBox("Error while Login in as special user: " & vbNewLine & ex.Message, MsgBoxStyle.Critical)
        End Try
    End Sub
End Class