You are on page 1of 18

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=perpus")
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='peminjam'",
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 ulasan_buku", conn)
ds = New DataSet
da.Fill(ds)
home.DGV_ulasan.DataSource = ds.Tables(0)
home.DGV_ulasan.ReadOnly = True
End Sub

Sub tampil_koleksi_pribadi()
cmd = New OdbcCommand("select * from koleksi_pribadi inner join buku on
koleksi_pribadi.id_buku = buku.id_buku where id_user='" & home.Panel1.Text & "'",
conn)
dr = cmd.ExecuteReader
home.ListBox1.Items.Clear()
Do While dr.Read
home.ListBox1.Items.Add(dr.Item("id_buku") & Space(2) &
dr.Item("judul"))
Loop
End Sub

End Module

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 id_user, nama_lengkap, status, email,
alamat, no_telepon from user", conn)
ds = New DataSet
da.Fill(ds)
DGV.DataSource = ds.Tables(0)
DGV.ReadOnly = True
DGV.Columns("id_user").Width = 100
DGV.Columns("nama_lengkap").Width = 120
DGV.Columns("status").Width = 95
DGV.Columns("email").Width = 100
DGV.Columns("alamat").Width = 100
DGV.Columns("no_telepon").Width = 100
End Sub

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

Sub panggilData()
On Error Resume Next
TextBox2.Text = dr("nama_lengkap")
TextBox3.Text = dr("password")
ComboBox1.Text = dr("status")
TextBox4.Text = dr("email")
TextBox5.Text = dr("no_telepon")
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 id_user, nama_lengkap, status, email,
alamat, no_telepon from user where id_user like '%" & TextBox7.Text & "%' or
nama_lengkap like '%" & TextBox7.Text & "%' or email like '%" & TextBox7.Text & "%'
or alamat like '%" & TextBox7.Text & "%' or status like '%" & TextBox7.Text & "%'
or no_telepon 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
TextBox4.Text = "" Or TextBox5.Text = "" Or TextBox6.Text = "" Or ComboBox1.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 & "', '" & TextBox6.Text & "', '" & TextBox5.Text & "')"
cmd = New OdbcCommand(simpan, conn)
cmd.ExecuteNonQuery()
MsgBox("Data Berhasil Ditambahkan!!", MsgBoxStyle.Information,
"Informasi")
Else
Dim edit As String = "update user set nama_lengkap='" &
TextBox2.Text & "', password='" & TextBox3.Text & "', status='" & ComboBox1.Text &
"', email='" & TextBox4.Text & "', alamat='" & TextBox6.Text & "', no_telepon='" &
TextBox5.Text & "' where id_user='" & 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 id_user='" &
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

HOME

Imports System.Data.Odbc

Public Class home

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


System.EventArgs) Handles MyBase.Load
Call tampilGrid_Buku()
Call tampilGrid_Member()
Call tampilGrid_Ulasan()

End Sub

'kodingan sub

'kodingan TabControl

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


System.EventArgs) Handles TextBox1.TextChanged
da = New OdbcDataAdapter("select * from buku where id_buku like'%" &
TextBox1.Text & "%' or judul like '%" & TextBox1.Text & "%' or penerbit like '%" &
TextBox1.Text & "%' or penulis like '%" & TextBox1.Text & "%'", conn)
ds = New DataSet
da.Fill(ds)
DGV_buku.DataSource = ds.Tables(0)
DGV_buku.ReadOnly = True
End Sub

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


System.EventArgs)
da = New OdbcDataAdapter("select * from user where status='peminjam' and
nama_lengkap like '%" & TextBox2.Text & "%'", conn)
ds = New DataSet
da.Fill(ds)
DGV_member.DataSource = ds.Tables(0)
DGV_member.ReadOnly = True
End Sub

'kodingan button

'master

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


System.EventArgs) Handles btn_user.Click
user.Show()
End Sub

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


System.EventArgs) Handles btn_buku.Click
buku.Show()
End Sub

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


System.EventArgs) Handles btn_kategori.Click
kategori.Show()
End Sub

'laporan

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


System.EventArgs) Handles laporan_peminjaman.Click

End Sub
Private Sub btn_laporan_buku_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btn_laporan_buku.Click
laporan_buku.Show()
End Sub

'umum

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


System.EventArgs) Handles btn_peminjaman.Click
peminjaman.Show()
End Sub

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


System.EventArgs) Handles btn_pengembalian.Click
pengembalian.Show()
End Sub

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


System.EventArgs) Handles btn_cari_buku.Click
cari_buku.Show()
End Sub

'keluar

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


System.EventArgs) Handles btn_logout.Click
If MessageBox.Show("apakah anda yakin ingin logout", "WARNING",
MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.Yes Then
Me.Close()
login.Show()
End If
End Sub

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


System.EventArgs) Handles btn_exit.Click
End
'If MessageBox.Show("apakah anda yakin ingin keluar", "WARNING",
MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.Yes Then
' Me.Close()
'End If
End Sub

End Class

PEMINJAMAN

Imports System.Data.Odbc

Public Class peminjaman

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


System.EventArgs) Handles MyBase.Load
Call hapus() 'agar saat halaman menload belum ada data
Call idPeminjaman() 'untuk mengenerate id_peminjaman secara otomatis
Call ubahTanggal() 'untuk mengubah tanggal peminjaman dan jatuh tempo

End Sub
'kodingan sub

Sub idPeminjaman()
Call koneksi()
cmd = New OdbcCommand("select id_peminjaman from peminjaman order by
id_peminjaman desc", conn)
dr = cmd.ExecuteReader
dr.Read()
If Not dr.HasRows Then
TextBox1.Text = Format(Today, "yyMMdd") + "001"
Else
If Microsoft.VisualBasic.Left(dr("id_peminjaman"), 6) = Format(Today,
"yyMMdd") Then
TextBox1.Text = dr("id_peminjaman") + 1
Else
TextBox1.Text = Format(Today, "yyMMdd") + "001"
End If
End If
End Sub

Sub hapus()
TextBox2.Clear()
TextBox3.Clear()
TextBox4.Clear()
TextBox7.Clear()
TextBox8.Clear()
PictureBox1.Image = Nothing
ListBox1.Items.Clear()
End Sub

Sub hapusBuku()
TextBox2.Clear()
TextBox3.Clear()
TextBox4.Clear()
PictureBox1.Image = Nothing
End Sub

Sub tampilRiwayat()
Call koneksi()
cmd = New OdbcCommand("SELECT id_peminjaman, judul, tanggal_peminjaman,
status_peminjaman FROM peminjaman inner join buku on peminjaman.id_buku =
buku.id_buku where id_user='" & TextBox7.Text & "'", conn)
dr = cmd.ExecuteReader
ListBox1.Items.Clear()
If dr.HasRows Then
Do While dr.Read
ListBox1.Items.Add(dr("id_peminjaman") & Space(3) & dr("judul") &
Space(3) & dr("tanggal_peminjaman") & Space(3) & dr("status_peminjaman"))
Loop
Else
ListBox1.Items.Add("Tidak ada riwayat buku yang dipinjam")
End If
End Sub

Sub ubahTanggal()
Dim hariIni As DateTime = DateTime.Now
TextBox5.Text = Format(hariIni, "yyyy-MM-dd")
Dim TujuhHari As DateTime = hariIni.AddDays(7)
TextBox6.Text = Format(TujuhHari, "yyyy-MM-dd")
End Sub

Sub panggilBuku()
Call koneksi()
cmd = New OdbcCommand("select * from buku where id_buku='" & TextBox2.Text
& "'", conn)
dr = cmd.ExecuteReader
dr.Read()

If dr.HasRows Then
TextBox3.Text = dr("judul")
TextBox4.Text = dr("ketersediaan_buku")

On Error Resume Next


PictureBox1.Load(dr("gambar"))
PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
Else
MsgBox("Buku tidak ditemukan", MsgBoxStyle.Information, "informasi")
Call hapusBuku()
End If
End Sub

Sub panggilAnggota()
Call koneksi()
cmd = New OdbcCommand("select * from user where status='peminjam' and
id_user='" & TextBox7.Text & "'", conn)
dr = cmd.ExecuteReader
dr.Read()
End Sub

Sub cekPeminjaman()
Call koneksi()
cmd = New OdbcCommand("select count(id_peminjaman) as hitungPeminjaman from
peminjaman where id_user='" & TextBox7.Text & "' and status_peminjaman='dipinjam'",
conn)
dr = cmd.ExecuteReader
dr.Read()
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 = 9

If e.KeyChar = Chr(13) Then


Call panggilBuku()
e.Handled = True
End If
End Sub

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


System.Windows.Forms.KeyPressEventArgs) Handles TextBox7.KeyPress
TextBox7.MaxLength = 9

If e.KeyChar = Chr(13) Then


Call panggilAnggota()
e.Handled = True

If dr.HasRows Then
TextBox8.Text = dr("nama_lengkap")
Call tampilRiwayat()
Else
MsgBox("Anggota tidak ditemukan", MsgBoxStyle.Information,
"Informasi")
TextBox7.Clear()
TextBox8.Clear()
End If
End If
End Sub

'kodinngan button

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


System.EventArgs) Handles btn_simpan.Click
If TextBox1.Text = "" Or TextBox2.Text = "" Or TextBox3.Text = "" Or
TextBox4.Text = "" Or TextBox5.Text = "" Or TextBox6.Text = "" Or TextBox7.Text =
"" Or TextBox8.Text = "" Then
MsgBox("Harap isi semua data!!", MsgBoxStyle.Information, "Informasi")
Exit Sub
End If

If TextBox4.Text = "Tidak Tersedia" Then


MsgBox("Buku tidak tersedia, Silahkan memilih buku yang lain",
MsgBoxStyle.Information, "Informasi")
Call hapusBuku()
Exit Sub
End If

Call cekPeminjaman()
If dr("hitungPeminjaman") > 3 Then
MsgBox("Anggota sudah meminjam 3 buku", MsgBoxStyle.Information,
"Informasi")
Call hapus()
Exit Sub
End If

Call koneksi()

Dim simpan As String = "insert into peminjaman values('" & TextBox1.Text &
"', '" & TextBox7.Text & "', '" & TextBox2.Text & "', '" & TextBox5.Text & "', '" &
TextBox6.Text & "', '', 'dipinjam', 'Belum Dikembalikan', '', '', '')"
cmd = New OdbcCommand(simpan, conn)
cmd.ExecuteNonQuery()

Dim UbahKetersediaan As String = "update buku set ketersediaan_buku='Tidak


Tersedia' where id_buku='" & TextBox2.Text & "'"
cmd = New OdbcCommand(UbahKetersediaan, conn)
cmd.ExecuteNonQuery()

MsgBox("Data berhasil ditambahkan", MsgBoxStyle.Information, "Informasi")


Call hapusBuku()
Call idPeminjaman()
Call tampilRiwayat()
End Sub

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


System.EventArgs) Handles btn_cari_buku.Click
list_buku.Show()
list_buku.btn_lihat.Visible = False
list_buku.btn_pinjam.Visible = True
End Sub

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


System.EventArgs) Handles btn_cari_anggota.Click
list_anggota.Show()
End Sub

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


System.EventArgs) Handles btn_batal.Click
Call hapus()
End Sub

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


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

'kodingan listbox

Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal


e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
Call koneksi()
cmd = New OdbcCommand("select * from peminjaman inner join buku on
peminjaman.id_buku = buku.id_buku where id_peminjaman='" &
Microsoft.VisualBasic.Left(ListBox1.Text, 9) & "'", conn)
dr = cmd.ExecuteReader
dr.Read()
If dr.HasRows Then
TextBox2.Text = dr("id_buku")
TextBox3.Text = dr("judul")
TextBox4.Text = dr("ketersediaan_buku")

On Error Resume Next


PictureBox1.Load(dr("gambar"))
PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
End If
End Sub
End Class

PENGEMBALIAN

Imports System.Data.Odbc

Public Class pengembalian

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


System.EventArgs) Handles MyBase.Load
TextBox3.Text = Format(Today, "yyyy-MM-dd")

Call hapus()
End Sub

'kodingan variabel

Dim DendaTerlambat As Integer = 0


Dim DendaKondisi As Integer = 0
Dim TotalDenda As Integer = 0

Dim jatuhTempo As Date


Dim kondisiBuku As String

'kodingan sub

Sub hapus()
TextBox2.Clear()
TextBox4.Clear()
TextBox5.Clear()
TextBox6.Clear()
TextBox7.Clear()
TextBox8.Clear()

ComboBox1.Text = ""
ComboBox2.Text = ""

ComboBox2.Enabled = False
TextBox7.ReadOnly = True

PictureBox1.Image = Nothing
End Sub

Sub hitungKeterlambatan()
Dim tanggalKembali As Date = TextBox3.Text
Dim denda As Integer = 5000

If tanggalKembali <= jatuhTempo Then


TextBox5.Text = "Tepat Waktu"

DendaTerlambat = 0

Call hitungDenda()
Else
Dim selisihHari As Integer = (tanggalKembali - jatuhTempo).Days
TextBox5.Text = "Terlambat " & selisihHari & " Hari"

DendaTerlambat = denda * selisihHari

Call hitungDenda()
End If
End Sub

Sub hitungDenda()
TotalDenda = DendaTerlambat + DendaKondisi
TextBox6.Text = TotalDenda
End Sub

Sub panggilPeminjaman()
Call koneksi()
cmd = New OdbcCommand("select * from user where id_user='" & TextBox1.Text
& "' and status='peminjam'", conn)
dr = cmd.ExecuteReader
dr.Read()

If Not dr.HasRows Then


MsgBox("Kode anggota tidak ditemukan!!", MsgBoxStyle.Information,
"Informasi")
Exit Sub
Else
cmd = New OdbcCommand("select * from peminjaman where id_user='" &
TextBox1.Text & "' and status_peminjaman='dipinjam'", conn)
dr = cmd.ExecuteReader
ComboBox1.Items.Clear()
ComboBox1.Text = ""

If dr.HasRows Then
Do While dr.Read()
ComboBox1.Items.Add(dr("id_peminjaman"))
Loop
ComboBox1.Enabled = True
ComboBox1.Focus()
Else
ComboBox1.Text = "Anggota tidak meminjam buku apapun"
ComboBox1.Enabled = False
End If
End If
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 = 9

If e.KeyChar = Chr(13) Then


Call panggilPeminjaman()
e.Handled = True
End If
End Sub

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


System.Windows.Forms.KeyPressEventArgs) Handles TextBox7.KeyPress
TextBox7.MaxLength = 15

If e.KeyChar = Chr(13) Then


e.Handled = True
Dim kembali As String = TextBox7.Text - TextBox6.Text

If kembali >= 0 Then


TextBox8.Text = kembali
Else
MsgBox("Pembayaran Kurang", MsgBoxStyle.Information, "Informasi")
End If

End If
End Sub

'kodingan combobox
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
Call koneksi()
cmd = New OdbcCommand("select * from peminjaman inner join buku on
peminjaman.id_buku = buku.id_buku where id_peminjaman='" & ComboBox1.Text & "'",
conn)
dr = cmd.ExecuteReader
dr.Read()

If dr.HasRows Then
jatuhTempo = dr("jatuh_tempo")

TextBox2.Text = dr("id_buku")
TextBox4.Text = Format(jatuhTempo, "yyyy-MM-dd")
PictureBox1.Load(dr("gambar"))
PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage

Call hitungKeterlambatan()

ComboBox2.Enabled = True
End If
End Sub

Private Sub ComboBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal


e As System.EventArgs) Handles ComboBox2.SelectedIndexChanged
Call koneksi()
cmd = New OdbcCommand("select harga from buku where id_buku='" &
TextBox2.Text & "'", conn)
dr = cmd.ExecuteReader
dr.Read()

Dim hargaBuku As Integer = dr("harga")

If ComboBox2.Text = "Baik" Then


kondisiBuku = "Baik"
DendaKondisi = 0
Call hitungDenda()
ElseIf ComboBox2.Text = "Rusak < 25%" Then
kondisiBuku = "Rusak"
DendaKondisi = hargaBuku * 25 / 100
Call hitungDenda()
ElseIf ComboBox2.Text = "Rusak < 50%" Then
kondisiBuku = "Rusak"
DendaKondisi = hargaBuku * 50 / 100
Call hitungDenda()
ElseIf ComboBox2.Text = "Rusak < 75%" Then
kondisiBuku = "Rusak"
DendaKondisi = hargaBuku
Call hitungDenda()
ElseIf ComboBox2.Text = "Hilang" Then
kondisiBuku = "Hilang"
DendaKondisi = hargaBuku
Call hitungDenda()
Else
MsgBox("Kondisi tidak valid!!", MsgBoxStyle.Information, "Informasi")
End If

TextBox7.Clear()
TextBox8.Clear()
TextBox7.ReadOnly = False

End Sub

'kodingan button

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


System.EventArgs) Handles btn_cari.Click
list_anggota.Show()
End Sub

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


System.EventArgs) Handles btn_simpan.Click
If TextBox1.Text = "" Or ComboBox1.Text = "" Or ComboBox2.Text = "" Or
TextBox7.Text = "" Or TextBox8.Text = "" Then
MsgBox("Harap isi semua data", MsgBoxStyle.Information, "Informasi")

Else

Dim updatePeminjaman As String = "update peminjaman set


tanggal_pengembalian='" & Format(Today, "yyyy-MM-dd") & "',
status_peminjaman='dikembalikan', kondisi_buku='" & kondisiBuku & "', denda='" &
TextBox6.Text & "', dibayar='" & TextBox7.Text & "', kembali='" & TextBox8.Text &
"' where id_peminjaman='" & ComboBox1.Text & "'"
cmd = New OdbcCommand(updatePeminjaman, conn)
cmd.ExecuteNonQuery()

If Not kondisiBuku = "Hilang" Then


Dim updateBuku As String = "update buku set
ketersediaan_buku='Tersedia' where id_buku='" & TextBox2.Text & "'"
cmd = New OdbcCommand(updateBuku, conn)
cmd.ExecuteNonQuery()
End If

MsgBox("Buku berhasil dikembalikan", MsgBoxStyle.Information,


"Informasi")
Call hapus()
Call panggilPeminjaman()
End If
End Sub

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


System.EventArgs) Handles btn_batal.Click
Call hapus()

End Sub

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


System.EventArgs) Handles btn_tutup.Click
Me.Close()
End Sub
End Class

KATEGORI

Imports System.Data.Odbc

Public Class kategori


Private Sub kategori_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Call tampil_grid()

End Sub

'kodingan sub

Sub hapus()
TextBox2.Clear()
End Sub

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

Sub panggilData()
TextBox2.Text = dr("nama_kategori")
End Sub

Sub tampil_grid()
Call koneksi()
da = New OdbcDataAdapter("select * from kategori_buku", 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


TextBox2.Focus()
e.Handled = True
Call panggilKode()
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


Button1.Focus()
e.Handled = True
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 = "" Then
MsgBox("Harap isi semua data!!", MsgBoxStyle.Information, "Informasi")
End If

Call panggilKode()

If Not dr.HasRows Then


Dim simpan As String = "insert into kategori_buku values('" &
TextBox1.Text & "', '" & TextBox2.Text & "')"
cmd = New OdbcCommand(simpan, conn)
cmd.ExecuteNonQuery()
MsgBox("Data berhasil disimpan!!", MsgBoxStyle.Information,
"Informasi")
Else
Dim edit As String = "update kategori_buku set nama_kategori='" &
TextBox2.Text & "' where id_kategori='" & TextBox1.Text & "'"
cmd = New OdbcCommand(edit, conn)
cmd.ExecuteNonQuery()
MsgBox("Data berhasil diedit!!", MsgBoxStyle.Information, "Informasi")
End If
Call tampil_grid()
Call hapus()
TextBox1.Clear()
TextBox1.Focus()
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 = "" Then
MsgBox("Harap isi semua data!!", MsgBoxStyle.Information, "Informasi")
End If

If MessageBox.Show("apakah yakin data akan dihapus", "Warning",


MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.Yes Then
Dim hapus As String = "delete from kategori_buku where id_kategori='" &
TextBox1.Text & "'"
cmd = New OdbcCommand(hapus, conn)
cmd.ExecuteNonQuery()
MsgBox("Data berhasil dihapus", MsgBoxStyle.Information, "Informasi")
End If
Call hapus()
Call tampil_grid()
TextBox1.Clear()
TextBox1.Focus()

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
End Class

You might also like