Pinjam Default

download Pinjam Default

If you can't read please download the document

description

Source code pinjam.vb

Transcript of Pinjam Default

Imports System.Data.OleDbPublic Class Form_Peminjaman Sub bersih() txKdAnggota.Text = "" txNama.Text = "" txNoItem.Text = "" txkdBuku.Text = "" txJudul.Text = "" txKdPinjam.Text = "" txtglhrskembali.Text = "" End Sub Sub kode_pinjam() Call conn() cmd = New OleDbCommand("select * from pinjam where kd_pinjam in(select max(kd_pinjam)from pinjam) order by kd_pinjam desc", koneksi) Dim urutan As String Dim hitung As Long rd = cmd.ExecuteReader rd.Read() If rd.HasRows Then hitung = Strings.Right(rd("kd_pinjam"), 3) + 1 urutan = Strings.Right("001" & hitung, 3) Else urutan = "001" End If rd.Close() txKdPinjam.Text() = urutan End Sub Sub pinjaman() tabel = New Data.OleDb.OleDbDataAdapter("select pinjam.kd_pinjam, pinjam.no_item, item.kd_buku, buku.judul, pinjam.tgl_pinjam, pinjam.tgl_hrs_kembali from pinjam, buku, anggota, item where pinjam.kd_anggota= anggota.kd_anggota and pinjam.no_item=item.no_item and item.kd_buku=buku.kd_buku and pinjam.kd_pinjam not in (select kd_pinjam from kembali) and anggota.kd_anggota= '" & txKdAnggota.Text & "'", koneksi) ds = New DataSet ds.Clear() tabel.Fill(ds, "Detail") grdpinjam.DataSource = ds.Tables("Detail") txjmlpinjam.Text = grdpinjam.Rows.Count - 1 'aturkolom() grdpinjam.ReadOnly = True End Sub Sub sedangdipinjam() Call conn() cmd = New OleDbCommand("select pinjam.no_item from anggota, item, buku, pinjam where pinjam.no_item='" & txNoItem.Text & "' and pinjam.kd_pinjam and anggota.kd_anggota=pinjam.kd_anggota and anggota.kd_anggota='" & txKdAnggota.Text & "' and pinjam.no_item and pinjam.kd_pinjam not in(select kd_pinjam from kembali)", koneksi) rd = cmd.ExecuteReader rd.Read() If rd.HasRows Then MsgBox("Buku sedang anda pinjam dan belum dikembalikan !") txNoItem.Text = "" txJudul.Text = "" txkdBuku.Text = "" txNoItem.Focus() Exit Sub End If cmd = New OleDbCommand("select pinjam.no_item from item, buku, pinjam where pinjam.no_item='" & txNoItem.Text & "' and pinjam.kd_pinjam not in (select kd_pinjam from kembali)", koneksi) rd = cmd.ExecuteReader rd.Read() If rd.HasRows Then MsgBox("Buku sedang dalam peminjaman dan belum dikembalikan !") txNoItem.Text = "" txJudul.Text = "" txkdBuku.Text = "" txNoItem.Focus() Exit Sub End If End Sub Private Sub txKdAnggota_TextChanged(sender As Object, e As EventArgs) Handles txKdAnggota.TextChanged Call conn() cmd = New OleDbCommand("select * from anggota where kd_anggota = '" & txKdAnggota.Text & "'", koneksi) rd = cmd.ExecuteReader Do While rd.Read() txNama.Text = rd.Item("nama_anggota") Call pinjaman() txNoItem.Enabled = True Loop End Sub Private Sub txNoItem_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txNoItem.KeyPress If e.KeyChar = Chr(13) Then Call conn() cmd = New OleDbCommand("select buku.judul, item.kd_buku from item, buku where buku.kd_buku=item.kd_buku and item.no_item = '" & txNoItem.Text & "'", koneksi) rd = cmd.ExecuteReader rd.Read() If Not rd.HasRows Then MsgBox("No Item tidak ada !") Else txJudul.Text = rd.Item("judul") txkdBuku.Text = rd.Item("kd_buku") Call sedangdipinjam() btSimpan.Focus() Dim tgl As DateTime tgl = CDate(Today) tgl = DateAdd(DateInterval.Day, 7, tgl) txtglhrskembali.Text = "" & tgl & "" End If End If End Sub Private Sub Form_Peminjaman_Load(sender As Object, e As EventArgs) Handles MyBase.Load kode_pinjam() 'datapeminjaman() txtglpinjam.Text = Today End Sub Private Sub btSimpan_Click(sender As Object, e As EventArgs) Handles btSimpan.Click If Val(txjmlpinjam.Text) + Val(TextBox1.Text) > 2 Then MsgBox("Pinjaman sudah maksimal") Exit Sub End If Dim simpan As String = "insert into pinjam(kd_pinjam,kd_anggota,no_item,tgl_pinjam,tgl_hrs_kembali)values('" & txKdPinjam.Text & _ "','" & txKdAnggota.Text & "','" & txNoItem.Text & "','" & txtglpinjam.Text & "','" & txtglhrskembali.Text & "')" cmd = New OleDbCommand(simpan, koneksi) cmd.ExecuteNonQuery() MsgBox("Data berhasil disimpan", MsgBoxStyle.OkOnly, "Simpan") Call pinjaman() 'Call bersih() End SubEnd Class