#Region "Deklarasi"
Dim MyConnection As New AccessData.DatabaseConnection
Dim objConnection As OleDbConnection
Dim objCommand As OleDbCommand
Dim objDataAdapter As OleDbDataAdapter
Dim objdatareader As OleDbDataReader
Dim strSQL As String
Dim objDataSet As New DataSet
Dim objDataTable As New DataTable
Dim f_utama As New f_utama
#End Region
#Region "Sub"
Sub login()
Try
'Mencari data user berdasarkan NIK yang dimasukkan pada txtuser
CekUser()
'tidak boleh mengkosongkan username & password
If txtuser.Text.Trim() = "" And _
txtPassword.Text.Trim() = "" Then
MsgBox("Masukan Username dan Password", MsgBoxStyle.OKOnly, "POS")
txtuser.Focus()
ElseIf txtuser.Text = "" Then
MsgBox("Masukan Username ", MsgBoxStyle.OKOnly, "POS")
txtuser.Focus()
ElseIf txtPassword.Text = "" Then
MsgBox("Masukan password ", MsgBoxStyle.OKOnly, "POS")
txtPassword.Focus()
Else
'jika username dan password tidak kosong, maka program akan mengecek
'apakah data yang dicari tersedia pada objDataTable.
'Jika Tidak (baris data = 0 ) maka akan keluar pesan
'bahwa username tidak ada
If objDataTable.Rows.Count <= 0 Then
MsgBox("Username tidak ada ", MsgBoxStyle.OKOnly, "POS")
txtuser.Focus()
Else
'jika data yang di cari ada, maka program akan mencari password
'berdasarkan username (NIK) yang dimasukkan.
Find_User()
'jika password yang di masukkan salah atau tidak sama
' dengan yang ada pada tabel, maka akan keluar pesan dari program
If Password <> Trim(txtPassword.Text) Then
MsgBox("Password salah!", MsgBoxStyle.OKOnly, "POS")
txtPassword.Focus()
Exit Sub
Else
'Jika benar program akan menampilkan pada form utama
Me.ShowInTaskbar = False
Me.Close()
Me.Dispose()
f_utama.ShowDialog()
txtuser.Text = ""
txtPassword.Text = ""
End If
End If
End If
Catch When Err.Number <> 0
MsgBox("Tidak dapat melakukan proses" _
& vbCrLf & Err.Description)
MyConnection.close()
End Try
End Sub
Sub Find_User()
objCommand = MyConnection.open.CreateCommand
objCommand.CommandText = ("Select Users.NIK,Users.[Password],Karyawan.[FirstName], Users.RoleID" & _
" FROM Karyawan INNER JOIN Users ON Karyawan.NIK = Users.NIK where Users.NIK='" & Trim(txtuser.Text) + "' ")
objdatareader = objCommand.ExecuteReader
objdatareader.Read()
Username = objdatareader.Item("NIK")
Password = objdatareader.Item("Password")
Nama = objdatareader.Item("FirstName")
RoleID = objdatareader.Item("RoleID")
MyConnection.close()
End Sub
Sub CekUser()
objDataTable.Clear()
strSQL = ("SELECT * FROM [Users] WHERE [NIK] = '" & Trim(txtuser.Text) & "' ")
objCommand = New OleDbCommand
objCommand.Connection = MyConnection.open
objCommand.CommandType = CommandType.Text
objCommand.CommandText = strSQL
objDataAdapter = New OleDbDataAdapter(objCommand)
objDataAdapter.Fill(objDataSet, "MDT_user")
objDataTable = objDataSet.Tables("MDT_user")
MyConnection.close()
End Sub
#End Region
Private Sub btnBatal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBatal.Click
Dim mYes_No As String = MsgBox("Apakah anda mau keluar dari program ?", vbYesNo, "POS")
If mYes_No = vbYes Then
End
Else
Exit Sub
End If
End Sub
Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click
login()
End Sub
Private Sub F_Login_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
MyConnection.close()
End Sub
Private Sub txtPassword_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtPassword.KeyUp
If e.KeyCode = Keys.Enter Then
btnLogin.PerformClick()
ElseIf e.KeyCode = Keys.Escape Then
btnBatal.PerformClick()
End If
End Sub