Vous êtes sur la page 1sur 4

Imports System.

Data
Imports System.Data.Odbc
Public Class Form6
Dim conn As OdbcConnection
Dim da As OdbcDataAdapter
Dim ds As DataSet
Dim cmd As OdbcCommand
Dim rd As OdbcDataReader
Dim str As String

Sub koneksi()
str =
"Dsn=myodbc;description=myproject;server=localhost;uid=root;database=dbmiexe;port=3
306"
conn = New OdbcConnection(str)
If conn.State = ConnectionState.Closed Then
conn.Open()
End If
End Sub

Sub TampilGrid1()
DataGridView1.Columns.Add("Kode_Buku", "Kode_Buku")
DataGridView1.Columns.Add("Judul_Buku", "Judul_Buku")
DataGridView1.Columns.Add("Jumlah", "Jumlah")
DataGridView1.Columns.Add("Jumlah_Buku", "Jumlah_Buku")
End Sub

Sub TampilGrid2()
DataGridView2.Columns.Add("Kode_Petugas", "Kode_Petugas")
DataGridView2.Columns.Add("Judul_Buku", "Judul_Buku")
DataGridView2.Columns.Add("Jumlah_Buku", "Jumlah_Buku")
DataGridView2.ReadOnly = True
End Sub

Private Sub Form6_Activated(sender As Object, e As EventArgs) Handles


Me.Activated
Call koneksi()
Call otomatis()
LblTanggal.Text = Today
End Sub

Sub TampilKodeAnggota()
cmd = New OdbcCommand("select * FROM Tabel_Mahasiswa", conn)
rd = cmd.ExecuteReader
Do While rd.Read
ComboBox1.Items.Add(rd.Item(0))
Loop
End Sub

Private Sub Form6_Load(sender As Object, e As EventArgs) Handles MyBase.Load


Call koneksi()
Call TampilKodeAnggota()
Call TampilGrid1()
Call HapusMaster()
End Sub

Sub otomatis()
cmd = New OdbcCommand("Select * from Tabel_Pinjam where NoPinjam in (select
max(NoPinjam) from Tabel_Pinjam) order by NoPinjam desc", conn)
Dim urutan As String
Dim hitung As Long
rd = cmd.ExecuteReader
rd.Read()
If Not rd.HasRows Then
urutan = Format(Now, "yyMMdd") + "01"
Else
If Microsoft.VisualBasic.Left(rd.GetString(0), 6) <> Format(Now,
"yyMMdd") Then
urutan = Format(Now, "yyMMdd") + "01"
Else
hitung = rd.GetString(0) + 1
urutan = Format(Now, "yyMMdd") + Microsoft.VisualBasic.Right("00" &
hitung, 2)
End If
End If
LblKdPinjam.Text = urutan
End Sub

Private Sub DataGridView1_CellEndEdit(sender As Object, e As


DataGridViewCellEventArgs) Handles DataGridView1.CellEndEdit
If e.ColumnIndex = 0 Then
Call koneksi()
cmd = New OdbcCommand("select Kode_Buku from
tabel_mahasiswa,tabel_pinjam,tabel_detailpjm where Kode_Buku ='" &
DataGridView1.Rows(e.RowIndex).Cells(0).Value & "' and
tabel_pinjam.NoPinjam=Tabel_detailpjm.NoPinjam and
Tabel_Mahasiswa.NIM=tabel_pinjam.NIM and Tabel_Mahasiswa.NIM='" & ComboBox1.Text &
"' AND tabel_detailpjm.Jumlah_Buku>0", conn)
rd = cmd.ExecuteReader
rd.Read()
If rd.HasRows Then
MsgBox("Buku sedang dipinjam dan belum dikembalikan")
'DGV1.ReadOnly = True
Call HapusBaris()
Exit Sub
End If
Call koneksi()
cmd = New OdbcCommand("Select * from Tabel_Buku where Kode_Buku='" &
DataGridView1.Rows(e.RowIndex).Cells(0).Value & "'", conn)
rd = cmd.ExecuteReader
rd.Read()
If rd.HasRows Then
If rd.Item(5) <= 0 Then
MsgBox("Stok Buku kosong")
Else

DataGridView1.Rows(e.RowIndex).Cells(1).Value =
rd.Item("Judul_Buku")
DataGridView1.Rows(e.RowIndex).Cells(2).Value =
rd.Item("Jumlah")

DataGridView1.Rows(e.RowIndex).Cells(3).Value = 1
Call TotalPinjam()

Call BatasPinjaman()
Exit Sub
End If
Else
MsgBox("Kode Buku tidak teDRaftar")
Exit Sub
End If

End If

If e.ColumnIndex = 3 Then
If DataGridView1.Rows(e.RowIndex).Cells(3).Value =
DataGridView1.Rows(e.RowIndex).Cells(3).Value Then
MsgBox("Stok hanya ada &
DataGridView1.Rows(e.RowIndex).Cells(2).Value & """)
Exit Sub
Else
Call TotalPinjam()
End If

If Val(LblTotalPjm.Text) + Val(LblTelahPjm.Text) >= 4 Then


MsgBox("pinjaman sudah maksimal")
DataGridView1.ReadOnly = True
Button1.Focus()
End If
End If
End Sub

Sub CariData()
ComboBox1.MaxLength = 4
Call koneksi()
cmd = New OdbcCommand("Select * from Tabel_Mahasiswa where NIM='" &
ComboBox1.Text & "'", conn)
rd = cmd.ExecuteReader
rd.Read()
If rd.HasRows Then
LblNamaMhs.Text = rd.Item("Nama")
Call Pinjaman()
If Val(LblTotalPjm.Text) + Val(LblTelahPjm.Text) >= 4 Then
MsgBox("pinjaman sudah maksimal")
DataGridView1.ReadOnly = True
Button1.Focus()
Else
DataGridView1.ReadOnly = False
DataGridView1.Focus()
End If
Else
MsgBox("Nomor anggota tidak teDRaftar")
Call HapusMaster()
ComboBox1.Focus()
Exit Sub
End If
End Sub

Private Sub ComboBox1_KeyPress(sender As Object, e As KeyPressEventArgs)


Handles ComboBox1.KeyPress
If e.KeyChar = Chr(13) Then
Call CariData()
DataGridView1.Focus()
End If
End Sub

Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs)


Handles ComboBox1.SelectedIndexChanged
ComboBox1.MaxLength = 4
Call CariData()
End Sub

End Class

Vous aimerez peut-être aussi