Вы находитесь на странице: 1из 13

LAMPIRAN

Koneksi ke database
Public con As ADODB.Connection
Public rsanggota As New ADODB.Recordset
Public rspenerbit As New ADODB.Recordset
Public rsbuku As New ADODB.Recordset
Public rsmajalah As New ADODB.Recordset
Public rskunjungan As New ADODB.Recordset
Public Sub ConnectDatabase()
Set con = New ADODB.Connection
con.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path &
"\pustaka.mdb;Persist Security Info=False"
con.CursorLocation = adUseClient
End Sub
Public Sub NotConnectDatabase()
con.Close
End Sub

Login
Dim counter As Integer
Dim ms As Byte
Private Sub cmdcancel_Click()
txtuser.Text = ""
txtpassword.Text = ""
txtuser.SetFocus
End Sub
Private Sub cmdexit_Click()
Unload Me
End Sub
Private Sub cmdlogin_Click()
If txtuser.Text = "Administrator" And txtpassword.Text = "Library" Then
Frmlogin.Hide
MDIForm1.mnlogin.Visible = False
MDIForm1.mnentri.Visible = True
MDIForm1.mntransaksi.Visible = True
MDIForm1.mninformasi.Visible = True
MDIForm1.mnkatalog.Visible = True
MDIForm1.mnkeluar.Visible = True
Else
If txtuser.Text = "User" And txtpassword.Text = "Duri" Then

Frmlogin.Hide
MDIForm1.mnlogin.Visible = False
MDIForm1.mnkatalog.Visible = True
MDIForm1.mnkeluar.Visible = True
counter = counter + 1
If counter = 3 Then
ms = MsgBox("Anda Tidak Bisa Log In Lagi !!!", vbOKOnly +
vbInformation)
Unload Me
counter = 0
Else
ms = MsgBox("Anda Salah Menginputkan Username dan password !!!",
vbOKOnly + vbInformation)
txtuser.Text = ""
txtpassword.Text = ""
End If
End If
End If
End Sub
Private Sub Form_Activate()
txtuser.SetFocus
End Sub
Private Sub txtuser_KeyPress(KeyAscii As Integer)
If KeyAscii <> 13 Then Exit Sub
txtpassword.SetFocus
End Sub
Private Sub txtpassword_KeyPress(KeyAscii As Integer)
If KeyAscii <> 13 Then Exit Sub
cmdlogin.SetFocus
End Sub
Private Sub Form_Load()
Move (Screen.Width - Width) / 2, (Screen.Height - Height) / 2
End Sub
Input data
Dim ms As Byte
Private Sub cmdcancel_Click()
ms = MsgBox("Yakin ingin membatalkan ?", vbYesNo + vbInformation, "Pesan
Cancel")
If ms = vbYes Then
bersih

End If
End Sub
Private Sub cmddelete_Click()
ms = MsgBox("Apakah Data Akan Dihapus ?", vbYesNo + vbInformation, "Pesan
Delete")
If ms = vbYes Then
rsanggota.Delete
rsanggota.MoveNext
End If
bersih
End Sub
Private Sub cmdexit_Click()
Unload Me
End Sub
Private Sub cmdfirst_Click()
rsanggota.MoveFirst
If rsanggota.BOF And rsanggota.RecordCount > 0 Then
rsanggota.MoveFirst
Exit Sub
End If
End Sub

Private Sub cmdkeluar_Click()


Unload Me
End Sub
Private Sub cmdlast_Click()
rsanggota.MoveLast
If rsanggota.EOF Then
rsanggota.MoveLast
Exit Sub
End If
End Sub
Private Sub cmdnext_Click()
rsanggota.MoveNext
If rsanggota.EOF Then
rsanggota.MoveLast
Exit Sub
End If
End Sub

Private Sub cmdpreview_Click()


ConnectDatabase
Set rsanggota = New ADODB.Recordset
rsanggota.CursorLocation = adUseClient
rsanggota.Open "select * from anggota", con, adOpenDynamic, adLockOptimistic
Set DataGrid1.DataSource = rsanggota
total_angg.Text = rsanggota.RecordCount
End Sub
Private Sub cmdprevious_Click()
rsanggota.MovePrevious
If rsanggota.BOF And rsanggota.RecordCount > 0 Then
rsanggota.MoveFirst
Exit Sub
End If
End Sub
Private Sub cmdsave_Click()
With rsanggota
ms = MsgBox("Apakah Data Akan Disimpan ?", vbYesNo + vbInformation, "Pesan
Save")
If ms = vbYes Then
.AddNew
.Fields(0) = txtno_angg.Text
.Fields(1) = txtnm_angg.Text
.Fields(2) = txtalamat.Text
.Fields(3) = txttelepon.Text
.Fields(4) = txttgl_lahir.Text
.Fields(5) = txtbadge.Text
.Fields(6) = tgl_masuk.Value
.Update
End If
End With
bersih
End Sub
Private Sub cmdupdate_Click()
With rsanggota
ms = MsgBox("Apakah Data Akan Diubah ?", vbYesNo + vbInformation, "Pesan
Update")
If ms = vbYes Then
.Update
.Fields(0) = txtno_angg.Text
.Fields(1) = txtnm_angg.Text
.Fields(2) = txtalamat.Text
.Fields(3) = txttelepon.Text

.Fields(4) = txttgl_lahir.Text
.Fields(5) = txtbadge.Text
.Fields(6) = tgl_masuk.Value
.UpdateBatch
End If
End With
bersih
End Sub
Private Sub Form_Activate()
txtno_angg.SetFocus
End Sub
Private Sub Form_Load()
Move (Screen.Width - Width) / 2, (Screen.Height - Height) / 2
ConnectDatabase
Set rsanggota = New ADODB.Recordset
rsanggota.CursorLocation = adUseClient
rsanggota.Open "select * from anggota", con, adOpenDynamic, adLockOptimistic
Set DataGrid1.DataSource = rsanggota
total_angg.Text = rsanggota.RecordCount
tgl_masuk.Value = Now
End Sub
Private Sub bersih()
txtno_angg.Text = ""
txtnm_angg.Text = ""
txtalamat.Text = ""
txttelepon.Text = ""
txttgl_lahir.Text = ""
txtbadge.Text = ""
tgl_masuk.Value = Now
txtno_angg.SetFocus
End Sub

Private Sub Form_Unload(Cancel As Integer)


NotConnectDatabase
End Sub
Private Sub Picture2_Click()
End Sub
Private Sub txtno_angg_KeyPress(KeyAscii As Integer)
If KeyAscii <> 13 Then Exit Sub

txtnm_angg.SetFocus
End Sub

Private Sub txtnm_angg_KeyPress(KeyAscii As Integer)


If KeyAscii <> 13 Then Exit Sub
txtalamat.SetFocus
End Sub
Private Sub txtalamat_KeyPress(KeyAscii As Integer)
If KeyAscii <> 13 Then Exit Sub
txttelepon.SetFocus
End Sub
Private Sub txttelepon_KeyPress(KeyAscii As Integer)
If KeyAscii <> 13 Then Exit Sub
txttgl_lahir.SetFocus
End Sub
Private Sub txttgl_lahir_KeyPress(KeyAscii As Integer)
If KeyAscii <> 13 Then Exit Sub
txtbadge.SetFocus
End Sub
Private Sub txtbadge_KeyPress(KeyAscii As Integer)
If KeyAscii <> 13 Then Exit Sub
cmdsave.SetFocus
End Sub

Private Sub txtno_angg_Change()


On Error Resume Next
If Len(txtno_angg.Text) < 4 Then
Exit Sub
End If
With rsanggota
.Filter = "No_Angg = '" & txtno_angg.Text & "'"
txtnm_angg.Text = .Fields(1)
txtalamat.Text = .Fields(2)
txttelepon.Text = .Fields(3)
txttgl_lahir.Text = .Fields(4)
txtbadge.Text = .Fields(5)
tgl_masuk.Value = .Fields(6)
End With
End Sub

Input data buku


Dim ms As Byte
Private Sub cmdcancel_Click()
ms = MsgBox("Yakin ingin membatalkan ?", vbYesNo + vbInformation, "Pesan
Cancel")
If ms = vbYes Then
bersih
End If
End Sub
Private Sub cmddelete_Click()
ms = MsgBox("Apakah Data Akan Dihapus ?", vbYesNo + vbInformation, "Pesan
Delete")
If ms = vbYes Then
rsbuku.Delete
rsbuku.MoveNext
End If
bersih
End Sub
Private Sub cmdexit_Click()
Unload Me
End Sub
Private Sub cmdfirst_Click()
rsbuku.MoveFirst
If rsbuku.BOF And rsbuku.RecordCount > 0 Then
rsbuku.MoveFirst
Exit Sub
End If
End Sub
Private Sub cmdkeluar_Click()
Unload Me
End Sub
Private Sub cmdlast_Click()
rsbuku.MoveLast
If rsbuku.EOF Then
rsbuku.MoveLast
Exit Sub
End If
End Sub
Private Sub cmdnext_Click()

rsbuku.MoveNext
If rsbuku.EOF Then
rsbuku.MoveLast
Exit Sub
End If
End Sub
Private Sub cmdprevious_Click()
rsbuku.MovePrevious
If rsbuku.BOF And rsbuku.RecordCount > 0 Then
rsbuku.MoveFirst
Exit Sub
End If
End Sub

Private Sub cmdpreview_Click()


ConnectDatabase
Set rsbuku = New ADODB.Recordset
rsbuku.CursorLocation = adUseClient
rsbuku.Open "select * from buku", con, adOpenDynamic, adLockOptimistic
Set DataGrid1.DataSource = rsbuku
total_buku.Text = rsbuku.RecordCount
End Sub
Private Sub cmdsave_Click()
With rsbuku
ms = MsgBox("Apakah Data Akan Disimpan ?", vbYesNo + vbInformation, "Pesan
Save")
If ms = vbYes Then
.AddNew
.Fields(0) = txtkd_buku.Text
.Fields(1) = txtjdl_buku.Text
.Fields(2) = txtpengarang.Text
.Fields(3) = txtedisi.Text
.Fields(4) = txtjumlah.Text
.Fields(5) = txtkd_penerbit.Text
.Fields(6) = txtno_katalog.Text
.Update
End If
End With
bersih
End Sub

Private Sub cmdupdate_Click()

With rsbuku
ms = MsgBox("Apakah Data Akan Diubah ?", vbYesNo + vbInformation, "Pesan
Update")
If ms = vbYes Then
.Update
.Fields(0) = txtkd_buku.Text
.Fields(1) = txtjdl_buku.Text
.Fields(2) = txtpengarang.Text
.Fields(3) = txtedisi.Text
.Fields(4) = txtjumlah.Text
.Fields(5) = txtkd_penerbit.Text
.Fields(6) = txtno_katalog.Text
.UpdateBatch
End If
End With
bersih
End Sub
Private Sub dgkd_penerbit_DblClick()
txtkd_penerbit.Text = rspenerbit!kd_penerbit
dgkd_penerbit.Visible = False
txtno_katalog.SetFocus
End Sub
Private Sub DataGrid1_Click()
End Sub
Private Sub Form_Activate()
txtkd_buku.SetFocus
End Sub
Private Sub Form_Load()
Move (Screen.Width - Width) / 2, (Screen.Height - Height) / 2
ConnectDatabase
Set rsbuku = New ADODB.Recordset
rsbuku.CursorLocation = adUseClient
rsbuku.Open "select * from buku", con, adOpenDynamic, adLockOptimistic
Set DataGrid1.DataSource = rsbuku
total_buku.Text = rsbuku.RecordCount
Set rspenerbit = New ADODB.Recordset
rspenerbit.CursorLocation = adUseClient
rspenerbit.Open "select kd_penerbit, nm_penerbit from penerbit", con,
adOpenDynamic, adLockOptimistic
Set DataGrid2.DataSource = rspenerbit
DataGrid2.Visible = False

End Sub
Private Sub bersih()
txtkd_buku.Text = ""
txtjdl_buku.Text = ""
txtpengarang.Text = ""
txtedisi.Text = ""
txtjumlah.Text = ""
txtkd_penerbit.Text = ""
txtno_katalog.Text = ""
txtkd_buku.SetFocus
End Sub
Private Sub txtjumlah_KeyPress(KeyAscii As Integer)
If KeyAscii <> 13 Then Exit Sub
txtkd_penerbit.SetFocus
End Sub
Private Sub txtkd_penerbit_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Set rspenerbit = con.Execute("select * from penerbit where kd_penerbit like '" &
txtkd_penerbit.Text & "%'")
With rspenerbit
If Not (.BOF And .EOF) Then
Set DataGrid2.DataSource = rspenerbit
DataGrid2.Visible = True
End If
End With
End If
End Sub
Private Sub txtkd_penerbit_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyDown Then
DataGrid2.SetFocus
End If
End Sub
Private Sub DataGrid2_KeyPress(KeyAscii As Integer)
txtkd_penerbit.Text = DataGrid2.Columns.Item(0).Text
DataGrid2.Visible = False
rspenerbit.Close
DataGrid2.Visible = False
txtno_katalog.SetFocus
End Sub
Private Sub txtkd_buku_Change()

On Error Resume Next


If Len(txtkd_buku.Text) < 4 Then
Exit Sub
End If
With rsbuku
.Filter = "Kd_Buku = '" & txtkd_buku.Text & "'"
txtkd_buku.Text = .Fields(0)
txtjdl_buku.Text = .Fields(1)
txtpengarang.Text = .Fields(2)
txtedisi.Text = .Fields(3)
txtjumlah.Text = .Fields(4)
txtkd_penerbit.Text = .Fields(5)
txtno_katalog.Text = .Fields(6)
End With
End Sub

Private Sub txtkd_buku_KeyPress(KeyAscii As Integer)


If KeyAscii <> 13 Then Exit Sub
txtjdl_buku.SetFocus
End Sub
Private Sub txtjdl_buku_KeyPress(KeyAscii As Integer)
If KeyAscii <> 13 Then Exit Sub
txtpengarang.SetFocus
End Sub
Private Sub txtno_katalog_KeyPress(KeyAscii As Integer)
If KeyAscii <> 13 Then Exit Sub
cmdsave.SetFocus
End Sub
Private Sub txtpengarang_KeyPress(KeyAscii As Integer)
If KeyAscii <> 13 Then Exit Sub
txtedisi.SetFocus
End Sub
Private Sub txtedisi_KeyPress(KeyAscii As Integer)
If KeyAscii <> 13 Then Exit Sub
txtjumlah.SetFocus
End Sub

Peminjaman Buku
Private Sub cmdexit_Click()
Unload Me
End Sub
Private Sub cmdpreview_Click()
Dim rs1 As ADODB.Recordset
Dim rs2 As ADODB.Recordset
ConnectDatabase
con.Execute ("delete * from Tmp2") Set rs1 = con.Execute("select
Pinjam_Buku.No_Angg,Anggota.Nm_Angg,Pinjam_Buku.Kd_Buku,Buku.Jdl_Buku
,Pinjam_Buku.Tgl_Pinjam,Pinjam_Buku.Tgl_Hrs_Kembali from
Pinjam_Buku,Buku,Anggota where Pinjam_Buku.No_Angg = '" & Text1.Text & "'
and Pinjam_Buku.No_Angg = Anggota.No_Angg and Pinjam_Buku.Kd_Buku =
Buku.Kd_Buku and isnull(Pinjam_Buku.Tgl_Kembali) = True")
'Set rs1 = con.Execute("select No_Angg,Kd_Buku,Tgl_Pinjam,Tgl_Hrs_Kembali
from Pinjam_Buku where Kd_Angg = '" & Text1.Text & "'") ' and
Pinjam_Buku.Kd_Angg = Anggota.Kd_Angg and Pinjam_Buku.Kd_Buku =
Buku.Kd_Buku")
Set rs2 = con.Execute("select
Pinjam_Majalah.No_Angg,Anggota.Nm_Angg,Pinjam_Majalah.Kd_Majalah,Majala
h.Nm_Majalah,Pinjam_Majalah.Tgl_Pinjam,Pinjam_Majalah.Tgl_Hrs_Kembali from
Pinjam_Majalah,Majalah,Anggota where Pinjam_Majalah.No_Angg = '" &
Text1.Text & "' and Pinjam_Majalah.No_Angg = Anggota.No_Angg and
Pinjam_Majalah.Kd_Majalah = Majalah.Kd_Majalah and
isnull(Pinjam_Majalah.Tgl_Kembali) = True")
If Not rs1.EOF Then
rs1.MoveFirst
While Not rs1.EOF
con.Execute ("insert into Tmp2 values('" & rs1(0) & "','" & rs1(1) & "','" &
rs1(2) & "','" & rs1(3) & "','" & Format(rs1(4), "dd/MM/yyyy") & "','" &
Format(rs1(5), "dd/MM/yyyy") & "')")
rs1.MoveNext
Wend
End If
If Not rs2.EOF Then
rs2.MoveFirst
While Not rs2.EOF
con.Execute ("insert into Tmp2 values('" & rs2(0) & "','" & rs2(1) & "','" &
rs2(2) & "','" & rs2(3) & "','" & Format(rs2(4), "dd/MM/yyyy") & "','" &
Format(rs2(5), "dd/MM/yyyy") & "')")
rs2.MoveNext
Wend
End If

cr1.DataFiles(0) = App.Path & "\pustaka.mdb" cr1.ReportFileName =


App.Path & "\rptPinjaman.rpt" cr1.ReplaceSelectionFormula
"{Tmp2.Kd_A} = '" & Text1.Text & "'" cr1.Formulas(1) = "librarian
= '" & Text2.Text & "'"
cr1.WindowState = crptMaximized
cr1.WindowShowRefreshBtn = True
cr1.RetrieveDataFiles
cr1.Action = 1
cr1.Reset
End Sub
Private Sub Form_Activate()
Text1.SetFocus
End Sub
Private Sub Form_Load()
Move (Screen.Width - Width) / 2, (Screen.Height - Height) / 2
End Sub
Private Sub Form_Unload(Cancel As Integer)
NotConnectDatabase
End Sub
Private Sub Label3_Click()
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii <> 13 Then Exit Sub
Text2.SetFocus
End Sub
Private Sub Text2_KeyPress(KeyAscii As Integer)
If KeyAscii <> 13 Then Exit Sub
cmdpreview.SetFocus
End Sub

Вам также может понравиться