Upload
ahmad-mustaqim
View
762
Download
2
Embed Size (px)
DESCRIPTION
Citation preview
Ahmad Mustaqim | 12100408Rental_mobil
1
MODUL
Public dbado As New ADODB.Connection
Public rssewa As New ADODB.Recordset
Public rspeminjam As New ADODB.Recordset
Public rsdetail As New ADODB.Recordset
Public Sub koneksi()
If dbado.State = adStateOpen Then
dbado.Close
End If
dbado.ConnectionString = "provider=msdasql.1;persist security info=false;data source=rental_mobil"
dbado.Open
End Sub
LISTING
Sub bersih()
txtsewa.Text = ""
txtkdpeminjam.Text = ""
txtnama_peminjam.Text = ""
cmbtipe.Text = ""
txtharga_sewa.Text = ""
txtlama.Text = ""
txttotal.Text = "0"
End Sub
Sub nonaktif()
txtsewa.Enabled = False
txtkdpeminjam.Enabled = False
txtnama_peminjam.Enabled = False
cmbtipe.Enabled = False
txtharga_sewa.Enabled = False
txtlama.Enabled = False
txttotal.Enabled = False
binputlain.Enabled = False
bsave.Enabled = False
bcancel.Enabled = False
End Sub
Sub aktif()
txtsewa.Enabled = True
txtkdpeminjam.Enabled = True
txtnama_peminjam.Enabled = True
cmbtipe.Enabled = True
txtharga_sewa.Enabled = True
txtlama.Enabled = True
txttotal.Enabled = True
binputlain.Enabled = True
bsave.Enabled = True
bcancel.Enabled = True
End Sub
Sub tabel()
Grid1.ColWidth(0) = 126
Grid1.ColWidth(1) = 900
Ahmad Mustaqim | 12100408Rental_mobil
2
Grid1.ColWidth(2) = 900
Grid1.ColWidth(3) = 900
Grid1.ColWidth(4) = 900
sqltabel = "select*from detail_sewa"
Set rsdetail = dbado.Execute(sqltabel, , adCmdText)
Set Grid1.DataSource = rsdetail
End Sub
Sub no()
Dim sqlno, a, b As String
sqlno = "select * from sewa"
Set rssewa = dbado.Execute(sqlno, , adCmdText)
If rssewa.BOF And rssewa.EOF Then
txtsewa.Text = "W" & Format(Date, "yymm") & "001"
Else
a = 0
rssewa.MoveFirst
Do Until rssewa.EOF
a = a + 1
rssewa.MoveNext
Loop
a = a + 1
b = Len(Str(a))
txtsewa.Text = "W" & Format(Date, "yymm") & Mid$("000", 1, 4 - b) & a
End If
End Sub
Private Sub bcancel_Click()
sqldel = "delete from detail_sewa where no_sewa='" & txtsewa.Text & "'"
Set rsdetail = dbado.Execute(sqldel, , adCmdText)
tabel
nonaktif
bersih
End Sub
Private Sub bclose_Click()
X = MsgBox("yakin mau keluar form?", vbYesNo, "konfirmasi")
If X = vbYes Then
End
End If
End Sub
Private Sub binputlain_Click()
sqlsv = "insert into detail_sewa()values('" & txtsewa.Text & "','" & cmbtipe.Text & "','" & txtlama.Text & "','" & txtharga_sewa.Text & "')"
Set rsdetail = dbado.Execute(sqlsv, , adCmdText)
cmbtipe.Text = ""
txtharga_sewa.Text = ""
txtlama.Text = ""
cmbtipe.SetFocus
tabel
End Sub
Private Sub bnew_Click()
aktif
bersih
no
Ahmad Mustaqim | 12100408Rental_mobil
3
txtkdpeminjam.SetFocus
End Sub
Private Sub bsave_Click()
sqlsave = "insert into sewa()values('" & txtsewa.Text & "','" & lbltanggal.Caption & "','" & txttotal.Text & "','" & txtkdpeminjam.Text & "')"
Set rssewa = dbado.Execute(sqlsave, , adCmdText)
sqlsv = "insert into detail_sewa()values('" & txtsewa.Text & "','" & cmbtipe.Text & "','" & txtlama.Text & "','" & txtharga_sewa.Text & "')"
Set rsdetail = dbado.Execute(sqlsv, , adCmdText)
tabel
nonaktif
bersih
End Sub
Private Sub cmbtipe_Click()
If cmbtipe.ListIndex = 0 Then
ck = "select no_sewa from detail_sewa where no_sewa='" & txtsewa.Text & "' and tipe_mobil='" & cmbtipe.Text & "'"
Set rsdetail = dbado.Execute(ck, , adCmdText)
If rsdetail.BOF And rsdetail.EOF Then
txtharga_sewa.Text = "400000"
txtlama.SetFocus
Else
MsgBox " TIPE '" & cmbtipe.Text & "' SUDAH DIPESAN!"
txtharga_sewa.Text = ""
cmbtipe.SetFocus
End If
Else
If cmbtipe.ListIndex = 1 Then
ck = "select no_sewa from detail_sewa where no_sewa='" & txtsewa.Text & "' and tipe_mobil='" & cmbtipe.Text & "'"
Set rsdetail = dbado.Execute(ck, , adCmdText)
If rsdetail.BOF And rsdetail.EOF Then
txtharga_sewa.Text = "300000"
txtlama.SetFocus
Else
MsgBox " TIPE '" & cmbtipe.Text & "' SUDAH DIPESAN!"
txtharga_sewa.Text = ""
cmbtipe.SetFocus
End If
Else
If cmbtipe.ListIndex = 2 Then
ck = "select no_sewa from detail_sewa where no_sewa='" & txtsewa.Text & "' and tipe_mobil='" & cmbtipe.Text & "'"
Set rsdetail = dbado.Execute(ck, , adCmdText)
If rsdetail.BOF And rsdetail.EOF Then
txtharga_sewa.Text = "500000"
txtlama.SetFocus
Else
MsgBox " TIPE '" & cmbtipe.Text & "' SUDAH DIPESAN!"
txtharga_sewa.Text = ""
cmbtipe.SetFocus
End If
End If
End If
End If
Ahmad Mustaqim | 12100408Rental_mobil
4
End Sub
Private Sub Form_Activate()
nonaktif
lbltanggal.Caption = Format(Date, "yyyy-mm-dd")
tabel
cmbtipe.AddItem ("inova")
cmbtipe.AddItem ("avanza")
cmbtipe.AddItem ("city")
End Sub
Private Sub Form_Load()
koneksi
End Sub
Private Sub txtkdpeminjam_OnEnter()
sqlkd = "select*from peminjam where kd_peminjam='" & txtkdpeminjam.Text & "'"
Set rspeminjam = dbado.Execute(sqlkd, , adCmdText)
If rspeminjam.BOF And rspeminjam.EOF Then
MsgBox "KODE '" & txtkdpeminjam.Text & "' Belum Terdaftar"
txtkdpeminjam.Text = ""
txtkdpeminjam.SetFocus
Else
txtnama_peminjam.Text = rspeminjam!nama
cmbtipe.SetFocus
End If
End Sub
Private Sub txtlama_Change()
txttotal.Text = (Val(txtharga_sewa.Text) * Val(txtlama.Text)) + Val(txttotal.Text)
End Sub