Imports System.IO
Imports System.Data
Imports System.Data.SqlClient
Public Class Form_Login
Inherits System.Windows.Forms.Form
#Region "deklarasi"
Dim MyConnection As New DataAcces.DatabaseConnection
Dim f_utama As New MainMenu
Dim objConnection As SqlConnection
Dim objCommand As SqlCommand
Dim objDataAdapter As SqlDataAdapter
Dim objDatareader As SqlDataReader
Dim strSQL As String
Dim objDataSet As New DataSet
Dim objDataTable As New DataTable
Dim mprocess As String
Dim UserName, Password, Level, Msg As String
#End Region
Sub checkUser()
objDataTable.Clear()
' ("Select * from [dbo.TB_user] where [userName]= '" & Trim(txbuser.Text) & "' ")
strSQL = ("SELECT * FROM TB_User where userName = '" & Trim(txbUser.Text) & "' ")
objCommand = New SqlCommand
objCommand.Connection = MyConnection.open
objCommand.CommandType = CommandType.Text
objCommand.CommandText = strSQL
objDataAdapter = New SqlDataAdapter(objCommand)
objDataAdapter.Fill(objDataSet, "MDT_User")
objDataTable = objDataSet.Tables("MDT_User")
MyConnection.close()
End Sub
Sub Find_User()
objCommand = MyConnection.open.CreateCommand
objCommand.CommandText = ("Select userName, password, userLevel FROM TB_User where userName = '" & Trim(txbUser.Text) & "' ")
objDatareader = objCommand.ExecuteReader
objDatareader.Read()
UserName = objDatareader.Item("userName")
Password = objDatareader.Item("password")
Level = objDatareader.Item("userLevel")
MyConnection.close()
End Sub
Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click
checkUser()
If txbUser.Text = "" And txbPass.Text = "" Then
Msg = MsgBox("Masukan UserName dan Password !", MsgBoxStyle.OkOnly, "Pesan")
txbUser.Focus()
ElseIf txbUser.Text = "" Then
Msg = MsgBox("Masukan UserName!", MsgBoxStyle.OkOnly, "Pesan")
txbUser.Focus()
ElseIf txbPass.Text = "" Then
Msg = MsgBox("Masukan Password !", MsgBoxStyle.OkOnly, "Pesan")
txbPass.Focus()
Else
Try
If objDataTable.Rows.Count <= 0 Then
Msg = MsgBox("userName tidak ada!", MsgBoxStyle.OkOnly, "Pesan")
txbUser.Focus()
Else
Find_User()
If Password <> Trim(txbPass.Text) Then
Msg = MsgBox("password salah!", MsgBoxStyle.OkOnly, "Pesan")
txbPass.Focus()
Exit Sub
Else
Me.Hide()
Form_Menu.ShowDialog()
txbUser.Text = ""
txbPass.Text = ""
Me.Close()
End If
End If
Catch ex As Exception
MsgBox("Tidak dapat melakukan proses" & vbCrLf & Err.Description)
End Try
End If
End Sub
Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
Me.Close()
End Sub
Private Sub Login_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'txbUser.Text = "parlin"
'txbPass.Text = "parlin"
'If Not File.Exists("c:\Lokasi.txt") Then
'MsgBox("Please, Crete File Location !")
'LokasiData.Visible = True
' Me.Visible = False
' Enabled_OFF()
'txbUser.Text = "sa"
'txbPass.Text = "mendi"
'End If
End Sub
Sub Enabled_OFF()
txbUser.Enabled = False
txbPass.Enabled = False
btnLogin.Enabled = False
btnCancel.Enabled = False
End Sub
Sub Enabled_ON()
txbUser.Enabled = True
txbPass.Enabled = True
btnLogin.Enabled = True
btnCancel.Enabled = True
End Sub
End Class
Tidak ada komentar:
Posting Komentar