Imports System.Data.Odbc
Public Class frmLogin

    Private Sub frmLogin_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress
        If Asc(e.KeyChar) = Keys.Enter Then
            SendKeys.Send("{tab}")
        End If
    End Sub

    Private Sub frmLogin_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Call Koneksi()
        txtPass.UseSystemPasswordChar = True
    End Sub

    Sub cekPassword()
        On Error Resume Next
        cmd = New OdbcCommand("Select * from tbuser where username='" & txtUser.Text & "' and password=md5('" & txtPass.Text & "')", Conn)
        rd = cmd.ExecuteReader
        rd.Read()
        If rd.HasRows Then
            cLevelUser = rd.Item("level")
            cUserId = rd.Item("user_id")
            Me.Visible = False
            If cLevelUser = "Admin" Then
                frmMenuUtama.Show()
            Else
                frmMenuUser.Show()
            End If

        Else
            MsgBox("Maaf..., Username atau Password Salah", MsgBoxStyle.Critical, "Perhatian...!")
            txtPass.Text = ""
            txtPass.Focus()
            Exit Sub
        End If
    End Sub
    Private Sub btnBatal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Me.Close()
    End Sub

    Private Sub txtPass_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtPass.KeyPress
        If e.KeyChar = Chr(13) Then
            Call cekPassword()
        End If
    End Sub


    Private Sub txtUser_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtUser.KeyPress
       
        If Char.IsLetterOrDigit(e.KeyChar) = False Then
            If e.KeyChar = CChar(ChrW(Keys.Back)) Or _
               e.KeyChar = CChar(ChrW(Keys.Space)) Then
                e.Handled = False
            Else
                e.Handled = True
            End If
        End If
    End Sub

    Private Sub txtUser_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtUser.TextChanged
        txtUser.Text = StripNonAlphaNum(txtUser.Text)
    End Sub

    Private Sub btnOk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOk.Click

        Call cekPassword()
       
    End Sub

   
End Class