'************************************************************************************************************************
' File: PMACSlogin.vb
' Programmer: Ting Chan
' Date: May 31, 2005
'
' Description:
' This form is the login window for MARS PMACS
' Allows the user to enter a user name and password then check to see whether or not
' they match a console or remote client profile
'
' Revision History:
'
'************************************************************************************************************************
Public Class PMACSlogin
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()
        'This call is required by the Windows Form Designer.
        InitializeComponent()

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents txtUserName As System.Windows.Forms.TextBox
    Friend WithEvents txtPassword As System.Windows.Forms.TextBox
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents btnOK As System.Windows.Forms.Button
    Friend WithEvents btnCancel As System.Windows.Forms.Button
    Friend WithEvents ProgressBar1 As System.Windows.Forms.ProgressBar
    Friend WithEvents Panel1 As System.Windows.Forms.Panel
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.Label1 = New System.Windows.Forms.Label
        Me.txtUserName = New System.Windows.Forms.TextBox
        Me.txtPassword = New System.Windows.Forms.TextBox
        Me.Label2 = New System.Windows.Forms.Label
        Me.btnOK = New System.Windows.Forms.Button
        Me.btnCancel = New System.Windows.Forms.Button
        Me.ProgressBar1 = New System.Windows.Forms.ProgressBar
        Me.Panel1 = New System.Windows.Forms.Panel
        Me.Panel1.SuspendLayout()
        Me.SuspendLayout()
        '
        'Label1
        '
        Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label1.Location = New System.Drawing.Point(104, 16)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(120, 32)
        Me.Label1.TabIndex = 0
        Me.Label1.Text = "User Name"
        '
        'txtUserName
        '
        Me.txtUserName.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.txtUserName.Location = New System.Drawing.Point(232, 16)
        Me.txtUserName.Name = "txtUserName"
        Me.txtUserName.Size = New System.Drawing.Size(160, 29)
        Me.txtUserName.TabIndex = 1
        Me.txtUserName.Text = ""
        '
        'txtPassword
        '
        Me.txtPassword.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.txtPassword.Location = New System.Drawing.Point(232, 56)
        Me.txtPassword.Name = "txtPassword"
        Me.txtPassword.PasswordChar = Microsoft.VisualBasic.ChrW(42)
        Me.txtPassword.Size = New System.Drawing.Size(160, 29)
        Me.txtPassword.TabIndex = 3
        Me.txtPassword.Text = ""
        '
        'Label2
        '
        Me.Label2.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label2.Location = New System.Drawing.Point(104, 56)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(120, 32)
        Me.Label2.TabIndex = 2
        Me.Label2.Text = "Password"
        '
        'btnOK
        '
        Me.btnOK.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.btnOK.Location = New System.Drawing.Point(120, 112)
        Me.btnOK.Name = "btnOK"
        Me.btnOK.Size = New System.Drawing.Size(80, 24)
        Me.btnOK.TabIndex = 4
        Me.btnOK.Text = "OK"
        '
        'btnCancel
        '
        Me.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.btnCancel.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.btnCancel.Location = New System.Drawing.Point(296, 112)
        Me.btnCancel.Name = "btnCancel"
        Me.btnCancel.Size = New System.Drawing.Size(80, 24)
        Me.btnCancel.TabIndex = 5
        Me.btnCancel.Text = "Cancel"
        '
        'ProgressBar1
        '
        Me.ProgressBar1.Location = New System.Drawing.Point(8, 8)
        Me.ProgressBar1.Name = "ProgressBar1"
        Me.ProgressBar1.Size = New System.Drawing.Size(440, 32)
        Me.ProgressBar1.TabIndex = 6
        '
        'Panel1
        '
        Me.Panel1.BackColor = System.Drawing.Color.Black
        Me.Panel1.Controls.Add(Me.ProgressBar1)
        Me.Panel1.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Panel1.Location = New System.Drawing.Point(16, 152)
        Me.Panel1.Name = "Panel1"
        Me.Panel1.Size = New System.Drawing.Size(456, 48)
        Me.Panel1.TabIndex = 8
        Me.Panel1.Visible = False
        '
        'PMACSlogin
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(8, 19)
        Me.ClientSize = New System.Drawing.Size(488, 214)
        Me.Controls.Add(Me.btnCancel)
        Me.Controls.Add(Me.btnOK)
        Me.Controls.Add(Me.txtPassword)
        Me.Controls.Add(Me.txtUserName)
        Me.Controls.Add(Me.Label2)
        Me.Controls.Add(Me.Label1)
        Me.Controls.Add(Me.Panel1)
        Me.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.MaximizeBox = False
        Me.MinimizeBox = False
        Me.Name = "PMACSlogin"
        Me.Text = "PMACS Login"
        Me.Panel1.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub

#End Region

#Region "User clicks OK button"
    '****************************************************************************
    'The user clicks OK to confirm the user name and password
    'check the user name and password to see whether what kind of user is he or she
    'If the user name and password does not match neither a console or client, 
    'prompt the user to re-enter the name and password
    '****************************************************************************
    Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
        Dim tstart As Double
        ' Make sure the user entered something.
        If txtUserName.Text.Length = 0 Then
            MsgBox("You must enter a user name", MsgBoxStyle.Exclamation)
            txtUserName.Focus()
        ElseIf txtPassword.Text.Length = 0 Then
            MsgBox("You must enter a password", MsgBoxStyle.Exclamation)
            txtPassword.Focus()
        ElseIf PasswordValidation(txtUserName.Text, txtPassword.Text) = 0 Then
            'username and/or password is invalid
            MsgBox("User name/password invalid", MsgBoxStyle.Exclamation)
            txtUserName.Focus()
        ElseIf PasswordValidation(txtUserName.Text, txtPassword.Text) = 1 Then
            'display a login timer
            Panel1.Visible = True
            tstart = Microsoft.VisualBasic.Timer
            While Microsoft.VisualBasic.Timer - tstart < 5
                ProgressBar1.Value = (Microsoft.VisualBasic.Timer - tstart) * 20
            End While
            ' The user name/password is Console.
            DialogResult = DialogResult.OK
        ElseIf PasswordValidation(txtUserName.Text, txtPassword.Text) = 2 Then
            'display a login timer
            Panel1.Visible = True
            tstart = Microsoft.VisualBasic.Timer
            While Microsoft.VisualBasic.Timer - tstart < 5
                ProgressBar1.Value = (Microsoft.VisualBasic.Timer - tstart) * 20
            End While
            ' The user name/password is Remote Client.
            DialogResult = DialogResult.OK
        End If
    End Sub
#End Region

#Region "User clicks Cancel button"
    '*******************************************************************
    'User click cancel to cancel the login process
    'exit the user name validation process
    '*******************************************************************
    Private Sub btnCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        DialogResult = DialogResult.Cancel
    End Sub
#End Region

#Region "User Name/Password Validation"
    '**************************************************************************
    ' Use the user name and password enter by the user and check whether they 
    ' match a console or remote client profile
    '**************************************************************************
    ' Put real validation here.
    Private Function PasswordValidation(ByVal user_name As String, ByVal password As String) As Integer
        Dim i As Integer

        'user enters the correct username  and password for Console
        If user_name = "console" And password = "mars" Then
            LoginType = 1
        ElseIf user_name = "remote" And password = "mars" Then
            'User enters the correct username and password for Remote Client
            LoginType = 2
        Else
            'username and/or password is invalid
            LoginType = 0
        End If
        Return LoginType
    End Function
#End Region

End Class
