You are on page 1of 7

'=============================================================================== =====================' '====================================== Kelompok_III =========================== =====================' '================================== PUSTAKA SEBARIS KODE ======================= =====================' '=============================== Copyright 2013@

AkiL.Nert ===================== =====================' '=============================================================================== =====================' Imports System.Data.SqlClient Imports System.Data.Sql Public Class AddPinjaman Sub bersih() jdl1.Text = "" jdl2.Text = "" jdl3.Text = "" jdl4.Text = "" txtBuku1.Text = "" txtBuku2.Text = "" txtBuku3.Text = "" txtBuku4.Text = "" txtNoAnggota.Text = "" jdl1.Text = "JUDUL" jdl2.Text = "JUDUL" jdl3.Text = "JUDUL" jdl4.Text = "JUDUL" txtTotPinjam.Text = "" lblNamaAnggt.Text = "NAMA ANGGOTA" GB1.Visible = False GB2.Visible = False GB3.Visible = False GB4.Visible = False txtTotPinjam.Items(3).Enabled = False txtTotPinjam.Items(2).Enabled = False txtTotPinjam.Items(1).Enabled = False txtTotPinjam.Items(0).Enabled = False End Sub Sub refreshGV() sqlda = New SqlDataAdapter("SELECT TblPinjam.NoPinjaman, TblPinjam.TglPi njaman, TblPinjam.NoAnggota, TblAnggota.NamaAnggota, TblPinjam.NoBuku, TblPinjam .JdlBuku FROM TblAnggota INNER JOIN TblPinjam ON TblAnggota.NoAnggota = TblPinja m.NoAnggota INNER JOIN TblBuku ON TblPinjam.NoBuku = TblBuku.NoBuku WHERE (TblPi njam.Status = 'PINJAM')", conn) sqlds.Clear() sqlda.Fill(sqlds, "TblPinjam") sqldt = sqlds.Tables("TblPinjam") GV.DataSource = sqldt GV.Columns(0).HeaderText = "NO PINJAM" GV.Columns(0).Width = 100 GV.Columns(1).HeaderText = "TANGGAL PINJAM" GV.Columns(1).Width = 100 GV.Columns(2).HeaderText = "NO ANGGOTA" GV.Columns(2).Width = 100 GV.Columns(3).HeaderText = "NAMA ANGGOTA" GV.Columns(3).Width = 170 GV.Columns(4).HeaderText = "NO BUKU" GV.Columns(4).Width = 100

GV.Columns(5).HeaderText = "JUDUL BUKU" GV.Columns(5).Width = 250 End Sub Sub cariAnggota() Try conn.Open() sqlcmd = New SqlCommand("select * from TblAnggota where NoAnggota='" + txtNoAnggota.Text + "'", conn) sqldr = sqlcmd.ExecuteReader If sqldr.Read Then lblNamaAnggt.Text = sqldr(1).ToString() txtTotPinjam.Enabled = True Else MessageBox.Show("DATA TIDAK ADA", "PUSTAKA SEBARIS KODE @ AkiL", MessageBoxButtons.OK, MessageBoxIcon.Information) lblNamaAnggt.Text = "NAMA ANGGOTA" End If Catch ex As Exception MessageBox.Show("TERJADI KESALAHAN (ERROR #001) " & ex.Message, "PUS TAKA SEBARIS KODE @ AkiL", MessageBoxButtons.OK, MessageBoxIcon.Error) Finally conn.Close() End Try End Sub Sub JmlPnjm() Try conn.Open() Dim dtpinjam As New DataTable Dim dapinjam As New SqlDataAdapter("select * from TblPinjam where (N oAnggota='" + txtNoAnggota.Text + "') and (TblPinjam.Status = 'PINJAM')", conn) dtpinjam.Clear() dapinjam.Fill(dtpinjam) Dim jml As String jml = dtpinjam.Rows.Count If jml = 0 Then txtTotPinjam.Items(3).Enabled = True txtTotPinjam.Items(2).Enabled = True txtTotPinjam.Items(1).Enabled = True txtTotPinjam.Items(0).Enabled = True ElseIf jml = 1 Then MessageBox.Show(lblNamaAnggt.Text & ", Hanya bisa pinjam 3", "PU STAKA SEBARIS KODE @ AkiL", MessageBoxButtons.OK, MessageBoxIcon.Information) txtTotPinjam.Items(3).Enabled = False txtTotPinjam.Items(2).Enabled = True txtTotPinjam.Items(1).Enabled = True txtTotPinjam.Items(0).Enabled = True ElseIf jml = 2 Then MessageBox.Show(lblNamaAnggt.Text & ", Hanya bisa pinjam 2", "PU STAKA SEBARIS KODE @ AkiL", MessageBoxButtons.OK, MessageBoxIcon.Information) txtTotPinjam.Items(3).Enabled = False txtTotPinjam.Items(2).Enabled = False txtTotPinjam.Items(1).Enabled = True txtTotPinjam.Items(0).Enabled = True ElseIf jml = 3 Then MessageBox.Show(lblNamaAnggt.Text & ", Hanya bisa pinjam 1", "PU STAKA SEBARIS KODE @ AkiL", MessageBoxButtons.OK, MessageBoxIcon.Information) txtTotPinjam.Items(3).Enabled = False txtTotPinjam.Items(2).Enabled = False txtTotPinjam.Items(1).Enabled = False txtTotPinjam.Items(0).Enabled = True

ElseIf jml = 4 Then MessageBox.Show(lblNamaAnggt.Text & ", SUDAH TIDAK BISA PiNJAM", "PUSTAKA SEBARIS KODE @ AkiL", MessageBoxButtons.OK, MessageBoxIcon.Information ) txtTotPinjam.Enabled = False End If Catch ex As Exception MessageBox.Show("TERJADI KESALAHAN (ERROR #001)" & ex.Message, "PUST AKA SEBARIS KODE @ AkiL", MessageBoxButtons.OK, MessageBoxIcon.Error) Finally conn.Close() End Try End Sub Private Function NoFak() As String Dim strjum As String Dim strfak As String If conn.State = 1 Then conn.Close() Dim str As String = "select count(*) AS Expr2, NoPinjaman AS Expr1 FROM TblPinjam group by NoPinjaman" conn.Open() sqlcmd = New SqlCommand(str, conn) sqlcmd.ExecuteNonQuery() Dim baca As SqlDataReader = sqlcmd.ExecuteReader(CommandBehavior.CloseCo nnection) Do While baca.Read strjum = (baca(0)) strfak = (baca(1)) Loop conn.Close() If strjum = "" Then NoFak = "AK000001" Else Dim ST As String ST = strfak Dim n As Integer n = Mid(ST, 3, Len(strfak)) n = n + 1 Dim no As String no = n If Len(no) = 1 Then NoFak = "AK00000" & no ElseIf Len(no) = 2 Then NoFak = "AK0000" & no ElseIf Len(no) = 3 Then NoFak = "AK000" & no ElseIf Len(no) = 4 Then NoFak = "AK00" & no ElseIf Len(no) = 5 Then NoFak = "AK0" & no End If End If End Function '===================================================================' '========================= BATAS PROCEDURE =========================' '======================= PUSTAKA SEBARIS KODE ======================' '================= Copyright Kelompok III @ AkiL ===================' '==================================================================='

Private Sub AddPinjaman_Load(ByVal sender As System.Object, ByVal e As Syste m.EventArgs) Handles MyBase.Load bersih() koneksi() refreshGV() lblNoPinjam.Text = NoFak() End Sub Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.Eve ntArgs) Handles Timer1.Tick 'format 12 jam -->> lblJam.Text = Format(Now, "hh:mm:ss tt") lblJam.Text = Format(Now, "H:mm:ss") lblTanggal.Text = Format(Now, "dddd, dd MMMM yyyy") 'lblTanggal.Text = Format(DateAdd("d", 7, Now), "dddd, dd - MM - yyyy") End Sub Private Sub txtTotPinjam_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtTotPinjam.KeyPress If Asc(e.KeyChar) = Keys.Enter Then txtTotPinjam.Text = "" End If End Sub Private Sub btnTutup_Click(ByVal sender As System.Object, ByVal e As System. EventArgs) Handles btnTutup.Click Me.Close() End Sub Private Sub txtNoAnggota_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtNoAnggota.KeyPress If Asc(e.KeyChar) = Keys.Enter Then cariAnggota() JmlPnjm() End If End Sub Private Sub btnBersih_Click(ByVal sender As System.Object, ByVal e As System .EventArgs) Handles btnBersih.Click bersih() End Sub Private Sub txtTotPinjam_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As Telerik.WinControls.UI.Data.PositionChangedEventArgs) Handles txtTot Pinjam.SelectedIndexChanged If txtTotPinjam.Text = "1" Then GB1.Visible = True GB2.Visible = False GB3.Visible = False GB4.Visible = False ElseIf txtTotPinjam.Text = "2" Then GB1.Visible = True GB2.Visible = True GB3.Visible = False GB4.Visible = False ElseIf txtTotPinjam.Text = "3" Then GB1.Visible = True GB2.Visible = True GB3.Visible = True GB4.Visible = False ElseIf txtTotPinjam.Text = "4" Then GB1.Visible = True GB2.Visible = True GB3.Visible = True GB4.Visible = True End If

End Sub Private Sub txtBuku1_KeyPress(ByVal sender As System.Object, ByVal e As Syst em.Windows.Forms.KeyPressEventArgs) Handles txtBuku1.KeyPress If Asc(e.KeyChar) = Keys.Enter Then Try conn.Open() sqlcmd = New SqlCommand("select * from TblBuku where NoBuku='" + txtBuku1.Text + "'", conn) sqldr = sqlcmd.ExecuteReader If sqldr.Read Then jdl1.Text = sqldr(2).ToString() Else MessageBox.Show("DATA TIDAK ADA", "PUSTAKA SEBARIS KODE @ Ak iL", MessageBoxButtons.OK, MessageBoxIcon.Information) jdl1.Text = "JUDUL" End If Catch ex As Exception MessageBox.Show("TERJADI KESALAHAN (ERROR #001) " & ex.Message, "PUSTAKA SEBARIS KODE @ AkiL", MessageBoxButtons.OK, MessageBoxIcon.Error) Finally conn.Close() End Try End If End Sub Private Sub txtBuku2_KeyPress(ByVal sender As System.Object, ByVal e As Syst em.Windows.Forms.KeyPressEventArgs) Handles txtBuku2.KeyPress If Asc(e.KeyChar) = Keys.Enter Then Try conn.Open() sqlcmd = New SqlCommand("select * from TblBuku where NoBuku='" + txtBuku2.Text + "'", conn) sqldr = sqlcmd.ExecuteReader If sqldr.Read Then jdl2.Text = sqldr(2).ToString() Else MessageBox.Show("DATA TIDAK ADA", "PUSTAKA SEBARIS KODE @ Ak iL", MessageBoxButtons.OK, MessageBoxIcon.Information) jdl2.Text = "JUDUL" End If Catch ex As Exception MessageBox.Show("TERJADI KESALAHAN (ERROR #001) " & ex.Message, "PUSTAKA SEBARIS KODE @ AkiL", MessageBoxButtons.OK, MessageBoxIcon.Error) Finally conn.Close() End Try End If End Sub Private Sub txtBuku3_KeyPress(ByVal sender As System.Object, ByVal e As Syst em.Windows.Forms.KeyPressEventArgs) Handles txtBuku3.KeyPress If Asc(e.KeyChar) = Keys.Enter Then Try conn.Open() sqlcmd = New SqlCommand("select * from TblBuku where NoBuku='" + txtBuku3.Text + "'", conn) sqldr = sqlcmd.ExecuteReader If sqldr.Read Then jdl3.Text = sqldr(2).ToString() Else

MessageBox.Show("DATA TIDAK ADA", "PUSTAKA SEBARIS KODE @ Ak iL", MessageBoxButtons.OK, MessageBoxIcon.Information) jdl3.Text = "JUDUL" End If Catch ex As Exception MessageBox.Show("TERJADI KESALAHAN (ERROR #001) " & ex.Message, "PUSTAKA SEBARIS KODE @ AkiL", MessageBoxButtons.OK, MessageBoxIcon.Error) Finally conn.Close() End Try End If End Sub Private Sub txtBuku4_KeyPress(ByVal sender As System.Object, ByVal e As Syst em.Windows.Forms.KeyPressEventArgs) Handles txtBuku4.KeyPress If Asc(e.KeyChar) = Keys.Enter Then Try conn.Open() sqlcmd = New SqlCommand("select * from TblBuku where NoBuku='" + txtBuku4.Text + "'", conn) sqldr = sqlcmd.ExecuteReader If sqldr.Read Then jdl4.Text = sqldr(2).ToString() Else MessageBox.Show("DATA TIDAK ADA", "PUSTAKA SEBARIS KODE @ Ak iL", MessageBoxButtons.OK, MessageBoxIcon.Information) jdl4.Text = "JUDUL" End If Catch ex As Exception MessageBox.Show("TERJADI KESALAHAN (ERROR #001) " & ex.Message, "PUSTAKA SEBARIS KODE @ AkiL", MessageBoxButtons.OK, MessageBoxIcon.Error) Finally conn.Close() End Try End If End Sub Private Sub btnSimpan_Click(ByVal sender As System.Object, ByVal e As System .EventArgs) Handles btnSimpan.Click Dim x As Integer Dim st(3) As Integer Dim w As New TextBox Dim list As New ArrayList list.Add(txtBuku1.Text) list.Add(txtBuku2.Text) list.Add(txtBuku3.Text) list.Add(txtBuku4.Text) Dim judul As New ArrayList judul.Add(jdl1.Text) judul.Add(jdl2.Text) judul.Add(jdl3.Text) judul.Add(jdl4.Text) Dim Tanggal As String Tanggal = Format(Now, "dddd, dd - MMMMM - yyyy") Try For x = 0 To 3 If txtNoAnggota.Text <> "" And txtTotPinjam.Text <> "" Then If (list(x) <> "") And (judul(x) <> "JUDUL") Then conn.Open() sqlcmd = New SqlCommand("select * from TblBuku where NoB

uku ='" + list(x) + "'", conn) sqldr = sqlcmd.ExecuteReader If sqldr.Read Then st(x) = Convert.ToInt32(sqldr(5).ToString()) conn.Close() If st(x) > 0 Then st(x) = st(x) - 1 w.Text = st(x) conn.Open() sqlcmd = New SqlCommand("UPDATE TblBuku set Stoc k='" + w.Text + "' where NoBuku='" + list(x) + "'", conn) sqlcmd.ExecuteNonQuery() sqlcmd = New SqlCommand("insert into TblPinjam v alues('" + lblNoPinjam.Text + "','" + txtNoAnggota.Text + "','" + Tanggal + "',' " + list(x) + "','" + judul(x) + "','" + Tanggal + "','" & "PINJAM" & "')", conn ) sqlcmd.ExecuteNonQuery() lblNoPinjam.Text = NoFak() conn.Close() MessageBox.Show("NO BUKU " & list(x) & " TERSIMP AN", "PUSTAKA SEBARIS KODE @ AkiL", MessageBoxButtons.OK, MessageBoxIcon.Informa tion) Else MessageBox.Show("NO BUKU " & list(x) & " KEHABIS AN STOCK", "PUSTAKA SEBARIS KODE @ AkiL", MessageBoxButtons.OK, MessageBoxIcon.I nformation) End If End If End If Else MessageBox.Show("LENGKAPI TERLEBIH DAHULU", "PUSTAKA SEBARIS KODE @ AkiL", MessageBoxButtons.OK, MessageBoxIcon.Information) End If Next refreshGV() lblNoPinjam.Text = NoFak() bersih() Catch ex As Exception MessageBox.Show("TERJADI KESALAHAN (ERROR #002) " & ex.Message, "PUS TAKA SEBARIS KODE @ AkiL", MessageBoxButtons.OK, MessageBoxIcon.Error) End Try End Sub Private Sub btnCr_Click(ByVal sender As System.Object, ByVal e As System.Eve ntArgs) Handles btnCr.Click cariAnggota() JmlPnjm() End Sub End Class

You might also like