Baiklah, kali ini saya ingin berbagi sedikit bagaimana cara memuat form login. Pada system login ini user harus memilih type user. Apakah type login Admin, Atau apakah Kasir. Baiklah, rancangan Formnya sebagai berikut.
Query untuk Databasenya
create Database Dblogin
create table Tblogin (typeuser char(50),
Usernama char (50),
password char (50)primary key))
Untuk Button LOGIN Isikan kode dibawah Ini
Dim Sql, username, password, tipe As String
Dim cmd As SqlCommand
Dim rdr As SqlDataReader
username = TextBox1.Text
password = TextBox2.Text
tipe = ComboBox1.SelectedItem
Sql = "select * from Tblogin where username='" + username + "'and password='" + password + "'and tipe='" + tipe + "'"
cmd = New SqlCommand(Sql, koneksi)
rdr = cmd.ExecuteReader()
If rdr.HasRows = True And ComboBox1.SelectedItem = "ADMINISTRATOR" Then TERMINATOR.Show()
Button1.Enabled = True
Me.Hide()
ElseIf rdr.HasRows = True And ComboBox1.SelectedItem = "KASIR" Then
KARYAWAN.Show()
Button1.Enabled = False
Me.Hide()
Else MessageBox.Show("Password Atau Username Salah", "PESAN", MessageBoxButtons.OK, MessageBoxIcon.Error)
Button1.Show()
Button1.Enabled = True
End If
TextBox1.Clear()
TextBox2.Clear()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ComboBox1.Items.Add("ADMINISTRATOR")
ComboBox1.Items.Add("KASIR")
Dim strKoneksi As String
strKoneksi = "Data Source=SIHALOHO-PC\SQLEXPRESS;Initial Catalog=Dblogin;Integrated Security=True"
koneksi = New SqlConnection(strKoneksi)
Try Catch ex As Exception MessageBox.Show("Acces Denield")
End Try
ComboBox1.SelectedIndex = 0
End Sub
Full code
Imports System.Data.Sql
Imports System.Data.SqlClient
Public Class Form1
Dim koneksi As SqlConnection
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ComboBox1.Items.Add("ADMINISTRATOR")
ComboBox1.Items.Add("KASIR")
Dim strKoneksi As String strKoneksi = "Data Source=SIHALOHO-PC\SQLEXPRESS;Initial Catalog=Dblogin;Integrated Security=True"
koneksi = New SqlConnection(strKoneksi)
Try Catch ex As Exception MessageBox.Show("Acces Denield")
End Try
ComboBox1.SelectedIndex = 0
End sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Sql, username, password, tipe As String
Dim cmd As SqlCommand
Dim rdr As SqlDataReader
username = TextBox1.Text
password = TextBox2.Text
tipe = ComboBox1.SelectedItem
Sql = "select * from Tblogin where username='" + username + "'and password='" + password + "'and tipe='" + tipe + "'"
cmd = New SqlCommand(Sql, koneksi)
rdr = cmd.ExecuteReader()
If rdr.HasRows = True And ComboBox1.SelectedItem = "ADMINISTRATOR" Then TERMINATOR.Show()
Button1.Enabled = True
Me.Hide()
ElseIf rdr.HasRows = True And ComboBox1.SelectedItem = "KASIR" Then
KARYAWAN.Show()
Button1.Enabled = False
Me.Hide()
Else MessageBox.Show("Password Atau Username Salah", "PESAN", MessageBoxButtons.OK, MessageBoxIcon.Error)
Button1.Show()
Button1.Enabled = True
End If
TextBox1.Clear()
TextBox2.Clear()
End Sub
End Class

Komentar
Posting Komentar