Di MENU UTAMA biasanya ada :
1. admin hak aksesnya sebagai Supervisor
2. user hak aksesnya ada pembatasnya
Langkah-langkahnya :
1. buat tabel login
Kita buat Data Percobaan :
Kita buat Form Login
Beri nama : textbox nya : txtuser, txtpass, cbakses
Karena ini menggunakan DataBase MYSQL
Kita buat Modul dan Koneksi ke DataBase MySQL
Syarat : Anda sudah Install Xampp dan Connection Mysql NET versi 6.5.4 dan VB.net(VB-2010)
kita buat Koneksi ke MYSQL biasa pojok kanan atas Klik Kanan > Add Reference sampai
pilih Browse cari di c:\Program files\Mysql\Mysql Connector Net 6.5.4
lalu blok semua - OK
Kemudian buat Modulnya buat Coding konek nya
lalu buat Codingnya
Imports MySql.Data.MySqlClient
Imports System.Data
Module modulku
Public cmd As New MySqlCommand
Public dadapter As New MySqlDataAdapter
Public datardr As MySqlDataReader
Public strSql As String
Dim serv As String = "Server=localhost;"
Dim dbase As String = "Database=toko;"
Dim uid As String = "uid=root;"
Dim pwd As String = "pwd=;"
Dim ConString = serv & dbase & uid & pwd
Public db As New MySqlConnection(ConString)
Public Sub konek()
Try
tutupDB()
db.Open()
MsgBox("Koneksi DataBase berhasil dilakukan")
Catch ex As MySqlException
MsgBox(ex.Message)
MsgBox("Koneksi tidak berhasil dilakukan")
End Try
End Sub
Public Sub tutupDB()
If db.State = ConnectionState.Open Then
db.Close()
End If
End Sub
End Module
Kemudian buat Form2 sebagai Form Utama ( Menu Utama )
Kemudian Coding untuk Form1 ( Login )
Imports MySql.Data.MySqlClient
Public Class Form1
Private Sub TampilData()
Dim da As New MySqlDataAdapter("select USERNAME,PASSWORD,HAKAKSES from tbl_login", db)
'Dim da As New MySqlDataAdapter("select * from tbl_login", db)
Dim dt As New DataTable
da.Fill(dt)
dgv.DataSource = dt
'Dim query As String = "SELECT * FROM CUSTOMER"
' Dim da As New MySqlDataAdapter(query, db)
' Dim ds As New DataSet()
'If da.Fill(ds) Then
'dgv.DataSource = ds.Tables(0)
'End If
End Sub
Private Sub CekData()
konek()
Try
strSql = "SELECT * FROM tbl_login where trim(username) ='" & Trim(txtuser.Text) & "' AND Password='" & Trim(txtpass.Text) & "'"
cmd.CommandText = strSql
cmd.Connection = db
dadapter.SelectCommand = cmd
datardr = cmd.ExecuteReader
If datardr.HasRows Then
datardr.Read()
' MessageBox.Show("Kombinasi Username ,Password dan Hak Akses Benar", "Konfirmasi", MessageBoxButtons.OK, MessageBoxIcon.Error)
cbakses.Text = datardr("hakakses")
If cbakses.Text = "admin" Then
'Jika Hak akses adalah admin
Form2.Show() 'Tampilkan Form2
Me.Hide()
Else 'Jika Hak Akses bukan admin (user)
Form2.DataMahasiswaToolStripMenuItem.Enabled = False 'disable submenu data mahasiswa di form 2
Form2.DataDosenToolStripMenuItem.Enabled = False 'disable submenu data dosen di form 2
Form2.Show() 'Tampilkan Form2
Me.Hide()
End If
Else
'Munculkan messagebox pesan salah
MessageBox.Show("Kombinasi Username ,Password dan Hak Akses Salah", "Konfirmasi", MessageBoxButtons.OK, MessageBoxIcon.Error)
txtuser.Focus()
End If
' datardr.Close()
' cmd.Dispose()
' db.Close()
Catch ex As Exception
End Try
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
konek()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
TampilData()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
CekData()
End Sub
End Class
Kemudian Jalankan (Debug)
Kita coba pakai nama abu sebagai user
Lalu klik OK hasilnya
Kita input dengan admin sebagai admin
Hasilnya :
1. admin hak aksesnya sebagai Supervisor
2. user hak aksesnya ada pembatasnya
Langkah-langkahnya :
1. buat tabel login
Kita buat Data Percobaan :
Kita buat Form Login
Beri nama : textbox nya : txtuser, txtpass, cbakses
Karena ini menggunakan DataBase MYSQL
Kita buat Modul dan Koneksi ke DataBase MySQL
Syarat : Anda sudah Install Xampp dan Connection Mysql NET versi 6.5.4 dan VB.net(VB-2010)
kita buat Koneksi ke MYSQL biasa pojok kanan atas Klik Kanan > Add Reference sampai
pilih Browse cari di c:\Program files\Mysql\Mysql Connector Net 6.5.4
lalu blok semua - OK
Kemudian buat Modulnya buat Coding konek nya
lalu buat Codingnya
Imports MySql.Data.MySqlClient
Imports System.Data
Module modulku
Public cmd As New MySqlCommand
Public dadapter As New MySqlDataAdapter
Public datardr As MySqlDataReader
Public strSql As String
Dim serv As String = "Server=localhost;"
Dim dbase As String = "Database=toko;"
Dim uid As String = "uid=root;"
Dim pwd As String = "pwd=;"
Dim ConString = serv & dbase & uid & pwd
Public db As New MySqlConnection(ConString)
Public Sub konek()
Try
tutupDB()
db.Open()
MsgBox("Koneksi DataBase berhasil dilakukan")
Catch ex As MySqlException
MsgBox(ex.Message)
MsgBox("Koneksi tidak berhasil dilakukan")
End Try
End Sub
Public Sub tutupDB()
If db.State = ConnectionState.Open Then
db.Close()
End If
End Sub
End Module
Kemudian buat Form2 sebagai Form Utama ( Menu Utama )
Kemudian Coding untuk Form1 ( Login )
Imports MySql.Data.MySqlClient
Public Class Form1
Private Sub TampilData()
Dim da As New MySqlDataAdapter("select USERNAME,PASSWORD,HAKAKSES from tbl_login", db)
'Dim da As New MySqlDataAdapter("select * from tbl_login", db)
Dim dt As New DataTable
da.Fill(dt)
dgv.DataSource = dt
'Dim query As String = "SELECT * FROM CUSTOMER"
' Dim da As New MySqlDataAdapter(query, db)
' Dim ds As New DataSet()
'If da.Fill(ds) Then
'dgv.DataSource = ds.Tables(0)
'End If
End Sub
Private Sub CekData()
konek()
Try
strSql = "SELECT * FROM tbl_login where trim(username) ='" & Trim(txtuser.Text) & "' AND Password='" & Trim(txtpass.Text) & "'"
cmd.CommandText = strSql
cmd.Connection = db
dadapter.SelectCommand = cmd
datardr = cmd.ExecuteReader
If datardr.HasRows Then
datardr.Read()
' MessageBox.Show("Kombinasi Username ,Password dan Hak Akses Benar", "Konfirmasi", MessageBoxButtons.OK, MessageBoxIcon.Error)
cbakses.Text = datardr("hakakses")
If cbakses.Text = "admin" Then
'Jika Hak akses adalah admin
Form2.Show() 'Tampilkan Form2
Me.Hide()
Else 'Jika Hak Akses bukan admin (user)
Form2.DataMahasiswaToolStripMenuItem.Enabled = False 'disable submenu data mahasiswa di form 2
Form2.DataDosenToolStripMenuItem.Enabled = False 'disable submenu data dosen di form 2
Form2.Show() 'Tampilkan Form2
Me.Hide()
End If
Else
'Munculkan messagebox pesan salah
MessageBox.Show("Kombinasi Username ,Password dan Hak Akses Salah", "Konfirmasi", MessageBoxButtons.OK, MessageBoxIcon.Error)
txtuser.Focus()
End If
' datardr.Close()
' cmd.Dispose()
' db.Close()
Catch ex As Exception
End Try
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
konek()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
TampilData()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
CekData()
End Sub
End Class
Kemudian Jalankan (Debug)
Kita coba pakai nama abu sebagai user
Lalu klik OK hasilnya
Kita input dengan admin sebagai admin
Hasilnya :
Tidak ada komentar:
Posting Komentar