0% found this document useful (0 votes)
63 views12 pages

Ujikom

The document contains code for a library management system that handles user registration and login. It includes modules for database connectivity and displaying data grids. The register class handles the registration form, validating input, generating user IDs, and inserting new user data into the database. The login class handles the login form, validating credentials against the user table, and loading the home form upon successful login.

Uploaded by

sayidalgifary3
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
63 views12 pages

Ujikom

The document contains code for a library management system that handles user registration and login. It includes modules for database connectivity and displaying data grids. The register class handles the registration form, validating input, generating user IDs, and inserting new user data into the database. The login class handles the login form, validating credentials against the user table, and loading the home form upon successful login.

Uploaded by

sayidalgifary3
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Module

Imports System.Data.Odbc
Module Module1
Public conn As OdbcConnection
Public ds As DataSet
Public cmd As OdbcCommand
Public da As OdbcDataAdapter
Public dr As OdbcDataReader

Public Sub koneksi()


conn = New OdbcConnection("Dsn=perpus2")
conn.Open()
End Sub

Sub tampilGrid_Buku()
Call koneksi()
da = New OdbcDataAdapter("select * from buku", conn)
ds = New DataSet
da.Fill(ds)
home.DGV_buku.Datasource = ds.Tables(0)
home.DGV_buku.ReadOnly = True
End Sub

Sub tampilGrid_member()
Call koneksi()
da = New OdbcDataAdapter("select * from user where
status='peminjaman'", conn)
ds = New DataSet
da.Fill(ds)
home.DGV_member.Datasource = ds.Tables(0)
home.DGV_member.ReadOnly = True
End Sub

Sub tampilGrid_ulasan()
Call koneksi()
da = New OdbcDataAdapter("select * from ulasanbuku", conn)
ds = New DataSet
da.Fill(ds)
home.DGV_ulasan.Datasource = ds.Tables(0)
home.DGV_ulasan.ReadOnly = True
End Sub
End Module
Register

Imports System.Data.Odbc

Public Class register

Private Sub register_Load(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles MyBase.Load
lbltanggal.Text = Today

TextBox1.Enabled = False
TextBox2.Focus()

Call idUser()
End Sub

'kodingan sub

Sub idUser()
Call koneksi()
cmd = New OdbcCommand("select UserID from user where
status='peminjam' order by UserID desc", conn)
dr = cmd.ExecuteReader
dr.Read()
If Not dr.HasRows Then
TextBox1.Text = Format(Today, "yyMMdd") + "001"
Else
If Microsoft.VisualBasic.Left(dr("UserID"), 6) = Format(Today,
"yyMMdd") Then
TextBox1.Text = dr("UserID") + 1
Else
TextBox1.Text = Format(Today, "yyMMdd") + "001"
End If
End If
End Sub

Sub hapus()
TextBox1.Clear()
TextBox2.Clear()
TextBox3.Clear()
TextBox4.Clear()
TextBox5.Clear()
TextBox6.Clear()
End Sub

Sub cekEmail()
Call koneksi()
cmd = New OdbcCommand("select * from user where status='peminjam'
and email='" & TextBox4.Text & "' or NamaLengkap='" & TextBox2.Text & "'",
conn)
dr = cmd.ExecuteReader
dr.Read()
End Sub

'kodingan jam
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
lbljam.Text = TimeOfDay
End Sub

'kodingan checkbox

Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object,


ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
If CheckBox1.Checked Then
TextBox3.PasswordChar = ""
Else
TextBox3.PasswordChar = "*"
End If
End Sub

'kodingan button

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click
If TextBox1.Text = "" Or TextBox2.Text = "" Or TextBox3.Text = ""
Or TextBox4.Text = "" Or TextBox5.Text = "" Then
MsgBox("Harap isi semua data!!", MsgBoxStyle.Information,
"Informasi")
Else

Call cekEmail()
If dr.HasRows Then
MsgBox("Email atau Nama telah terdaftar!!",
MsgBoxStyle.Information, "Informasi")
Else
Dim simpan As String = "insert into user values('" &
TextBox1.Text & "', '" & TextBox2.Text & "', '" & TextBox3.Text & "',
'peminjam', '" & TextBox4.Text & "', '" & TextBox5.Text & "', '" &
TextBox6.Text & "')"
cmd = New OdbcCommand(simpan, conn)
cmd.ExecuteNonQuery()

MsgBox("Daftar Berhasil!!", MsgBoxStyle.Information,


"Informasi")
login.Show()
Me.Hide()
Call hapus()
Call idUser()
End If
End If
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button2.Click
End
End Sub

'kodingan textbox

Private Sub TextBox2_KeyPress(ByVal sender As System.Object, ByVal e As


System.Windows.Forms.KeyPressEventArgs) Handles TextBox2.KeyPress
TextBox2.MaxLength = 50

If e.KeyChar = Chr(13) Then


TextBox3.Focus()
e.Handled = True
End If
End Sub

Private Sub TextBox3_KeyPress(ByVal sender As System.Object, ByVal e As


System.Windows.Forms.KeyPressEventArgs) Handles TextBox3.KeyPress
TextBox3.MaxLength = 50

If e.KeyChar = Chr(13) Then


TextBox4.Focus()
e.Handled = True
End If
End Sub

Private Sub TextBox4_KeyPress(ByVal sender As System.Object, ByVal e As


System.Windows.Forms.KeyPressEventArgs) Handles TextBox4.KeyPress
TextBox4.MaxLength = 50

If e.KeyChar = Chr(13) Then


TextBox5.Focus()
e.Handled = True
End If
End Sub

Private Sub TextBox5_KeyPress(ByVal sender As System.Object, ByVal e As


System.Windows.Forms.KeyPressEventArgs) Handles TextBox5.KeyPress
TextBox5.MaxLength = 50

If e.KeyChar = Chr(13) Then


TextBox5.Focus()
e.Handled = True
End If
End Sub

Private Sub TextBox6_KeyPress(ByVal sender As System.Object, ByVal e As


System.Windows.Forms.KeyPressEventArgs) Handles TextBox6.KeyPress
TextBox6.MaxLength = 50

If e.KeyChar = Chr(13) Then


Button1.Focus()
e.Handled = True
End If
End Sub

'kodingan Login

Private Sub Label3_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Label3.Click
login.Show()
Me.Hide()
End Sub

Private Sub ComboBox1_SelectedIndexChanged_1(ByVal sender As


System.Object, ByVal e As System.EventArgs) Handles
ComboBox1.SelectedIndexChanged
Button1.Focus()

End Sub
End Class
Yang di gunakan

- GrupBox
- Label
- lbltanggal, lbljm
- TextBox 1-6 yang 1 tidak ada codingan
- Combobox1 untuk status (opsional)
- Button simpan dan exit
- Label untuk Sudah Memiliki Akun ?
- Label untuk Login sekarang di sebelah nyaaa

Login
Imports System.Data.Odbc
Public Class login

Private Sub GroupBox1_Enter(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles GroupBox1.Enter
lbltanggal.Text = Today
End Sub
'kodingan veriabel

Dim dicoba As String

'kodingan sub

Sub hapus()
TextBox1.Clear()
TextBox1.Focus()
TextBox2.Clear()
ComboBox1.Text = "peminjam"
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Me.Close()
End Sub

'kodingan checkbox
Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
If CheckBox1.Checked Then
TextBox2.PasswordChar = ""
Else
TextBox2.PasswordChar = ""
End If
End Sub

'kodingan jam
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
lbljam.Text = TimeOfDay
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
ComboBox1.SelectedIndexChanged
Button1.Focus()
End Sub

'kodingan button

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click
If TextBox1.Text = "" Or TextBox2.Text = "" Or ComboBox1.Text = ""
Then
MsgBox("Harap isi semua data!!", MsgBoxStyle.Information,
"Informasi")
Else
Call koneksi()

cmd = New OdbcCommand("select * from user where UserID='" &


TextBox1.Text & "' and password='" & TextBox2.Text & "' and status='" &
ComboBox1.Text & "'", conn)
dr = cmd.ExecuteReader
dr.Read()

If Not dr.HasRows Then


cmd = New OdbcCommand("select * from user where email='" &
TextBox1.Text & "' and password='" & TextBox2.Text & "' and status='" &
ComboBox1.Text & "'", conn)
dr = cmd.ExecuteReader
dr.Read()

If Not dr.HasRows Then


dicoba = dicoba + 1
MsgBox("Login Gagal")
TextBox2.Focus()
If dicoba > 2 Then
Call hapus()
MsgBox("Percobaan Login Telah Gagal Lebih Dari 3
Kali, Silahkan Coba Lagi", MsgBoxStyle.Critical, "Peringatan")
End
End If
Exit Sub
End If
End If

Me.Visible = False
home.Show()
Call hapus()
home.Label4.Text = Format("Nama : " & dr("NamaLengkap"))
home.Label5.Text = Format("Status : " & dr("status"))

home.Panel1.Text = dr("UserID")
home.Panel2.Text = dr("NamaLengkap")
home.Panel3.Text = dr("status")

If home.Panel3.Text = "admin" Then


'admin (Tidak Bisa Peminjaman/Pengembalian)
'home.GroupBox8.Visible = False

ElseIf home.Panel3.Text = "petugas" Then


'Petugas (Tidak Bisa Registrasi dan
Peminjaman/Pengembalian)
home.GroupBox6.Visible = False
home.btn_user.Visible = False
home.GroupBox5.Width = 167

ElseIf home.Panel3.Text = "peminjam" Then


'Tidak Bisa Laporan
home.GroupBox7.Visible = False
home.GroupBox5.Visible = False

'Hapus TabPage

home.TabControl1.TabPages.Remove(home.TabControl1.TabPages(0))
End If
Call hapus()
End If
End Sub

'codingan register
Private Sub Label12_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Label12.Click
register.Show()
Me.Hide()
End Sub
End Class

User

Imports System.Data.Odbc
Public Class user

Private Sub user_Load(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles MyBase.Load
Call tampilGrid()
End Sub

'kodingan sub
Sub tampilGrid()
Call koneksi()
da = New OdbcDataAdapter("select UserID, NamaLengkap, status,
email, alamat, no_telpon from user", conn)
ds = New DataSet
da.Fill(ds)
DGV.DataSource = ds.Tables(0)
DGV.ReadOnly = True
DGV.Columns("UserID").Width = 100
DGV.Columns("NamaLengkap").Width = 120
DGV.Columns("status").Width = 95
DGV.Columns("email").Width = 100
DGV.Columns("alamat").Width = 100
DGV.Columns("no_telpon").Width = 100
End Sub

Sub panggilKode()
Call koneksi()
cmd = New OdbcCommand("select * from user where UserID='" &
TextBox1.Text & "'", conn)
dr = cmd.ExecuteReader
dr.Read()
End Sub

Sub panggilData()
On Error Resume Next
TextBox2.Text = dr("NamaLengkap")
TextBox3.Text = dr("password")
ComboBox1.Text = dr("status")
TextBox4.Text = dr("email")
TextBox5.Text = dr("no_telpon")
TextBox6.Text = dr("alamat")
End Sub

Sub hapus()
TextBox2.Clear()
TextBox3.Clear()
ComboBox1.Text = ""
TextBox4.Clear()
TextBox5.Clear()
TextBox6.Clear()
End Sub

Sub caridata()
Call koneksi()
da = New OdbcDataAdapter("select UserID, NamaLengkap, status,
email, alamat, no_telpon from user where UserID like '%" & TextBox7.Text &
"%' or NamaLengkap like '%" & TextBox7.Text & "%' or email like '%" &
TextBox7.Text & "%' or alamat like '%" & TextBox7.Text & "%' or status like
'%" & TextBox7.Text & "%' or no_telpon like '%" & TextBox7.Text & "%'",
conn)
ds = New DataSet
da.Fill(ds)
DGV.DataSource = ds.Tables(0)
DGV.ReadOnly = True

End Sub

'kodingan textbox

Private Sub TextBox1_KeyPress(ByVal sender As System.Object, ByVal e As


System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
TextBox1.MaxLength = 20

If e.KeyChar = Chr(13) Then


Call panggilKode()
TextBox2.Focus()
e.Handled = True

If dr.HasRows Then
Call panggilData()
Else
Call hapus()
End If
End If
End Sub

Private Sub TextBox2_KeyPress(ByVal sender As System.Object, ByVal e As


System.Windows.Forms.KeyPressEventArgs) Handles TextBox2.KeyPress
TextBox2.MaxLength = 20

If e.KeyChar = Chr(13) Then


TextBox3.Focus()
e.Handled = True
End If
End Sub

Private Sub TextBox3_KeyPress(ByVal sender As System.Object, ByVal e As


System.Windows.Forms.KeyPressEventArgs) Handles TextBox3.KeyPress
TextBox3.MaxLength = 20

If e.KeyChar = Chr(13) Then


ComboBox1.Focus()
e.Handled = True
End If
End Sub

Private Sub TextBox4_KeyPress(ByVal sender As System.Object, ByVal e As


System.Windows.Forms.KeyPressEventArgs) Handles TextBox4.KeyPress
TextBox4.MaxLength = 20

If e.KeyChar = Chr(13) Then


TextBox5.Focus()
e.Handled = True
End If
End Sub

Private Sub TextBox5_KeyPress(ByVal sender As System.Object, ByVal e As


System.Windows.Forms.KeyPressEventArgs) Handles TextBox5.KeyPress
TextBox5.MaxLength = 20

If e.KeyChar = Chr(13) Then


TextBox6.Focus()
e.Handled = True
End If
End Sub

Private Sub TextBox6_KeyPress(ByVal sender As System.Object, ByVal e As


System.Windows.Forms.KeyPressEventArgs) Handles TextBox6.KeyPress
TextBox6.MaxLength = 20

If e.KeyChar = Chr(13) Then


Button1.Focus()
e.Handled = True
End If
End Sub

'kodingan combobox

Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As


System.Object, ByVal e As System.EventArgs) Handles
ComboBox1.SelectedIndexChanged
TextBox4.Focus()
End Sub

'kodingan button

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click
If TextBox1.Text = "" Or TextBox2.Text = "" Or TextBox3.Text = ""
Or ComboBox1.Text = "" Or TextBox4.Text = "" Or TextBox5.Text = "" Or
TextBox6.Text = "" Then
MsgBox("Harap isi semua data!!", MsgBoxStyle.Information,
"Informasi")
Else

Call panggilKode()

If Not dr.HasRows Then


Dim simpan As String = "insert into user values('" &
TextBox1.Text & "', '" & TextBox2.Text & "', '" & TextBox3.Text & "', '" &
ComboBox1.Text & "', '" & TextBox4.Text & "', '" & TextBox5.Text & "', '" &
TextBox6.Text & "')"
cmd = New OdbcCommand(simpan, conn)
cmd.ExecuteNonQuery()
MsgBox("Data Berhasil Ditambahkan!!",
MsgBoxStyle.Information, "Informasi")
Else
Dim edit As String = "update user set NamaLengkap='" &
TextBox2.Text & "', password='" & TextBox3.Text & "', status='" &
ComboBox1.Text & "', email='" & TextBox4.Text & "', alamat='" &
TextBox6.Text & "', no_telpon='" & TextBox5.Text & "' where UserID='" &
TextBox1.Text & "'"
cmd = New OdbcCommand(edit, conn)
cmd.ExecuteNonQuery()
MsgBox("Data Berhasil Diedit!!", MsgBoxStyle.Information,
"Informasi")
End If
Call hapus()
Call tampilGrid()
'Call TampilMember()
TextBox1.Clear()
TextBox1.Focus()
End If
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button2.Click
If TextBox1.Text = "" Or TextBox2.Text = "" Or TextBox3.Text = ""
Or TextBox4.Text = "" Or TextBox5.Text = "" Or TextBox6.Text = "" Or
ComboBox1.Text = "" Then
MsgBox("Harap isi semua data!!", MsgBoxStyle.Information,
"Informasi")
Else
If MessageBox.Show("Yakin data ingin dihapus?", "WARNING",
MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.Yes Then
Dim edit As String = "delete from user where UserID='" &
TextBox1.Text & "'"
cmd = New OdbcCommand(edit, conn)
cmd.ExecuteNonQuery()
MsgBox("Data Berhasil Dihapus!!", MsgBoxStyle.Information,
"Informasi")
End If
Call hapus()
Call tampilGrid()
'Call TampilMember()
TextBox1.Clear()
TextBox1.Focus()
End If
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button3.Click
Call hapus()
TextBox1.Clear()
TextBox1.Focus()
End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button4.Click
Me.Close()
End Sub

'caridata

Private Sub TextBox7_TextChanged(ByVal sender As System.Object, ByVal e


As System.EventArgs) Handles TextBox7.TextChanged
Call caridata()
End Sub
End Class

You might also like