Saturday, January 17, 2015

How to Create a Visual Basic Laundry Application

Assalmualaikum agan-agan: D

Before we make loundry application provide dirty cloth: v: v hehehehe

Sorry gan kidding .. coffee + cigarettes kamsudnya ...


Immediately wrote the first we create a database

1. Run apache and Mysql on xampp
2. create a database with the name laundering clothes
  

3. create customer and transaction tables
4. create customer form
coding di form pelanggan 
Private Sub Command1_Click()
If Text1 = "" Or Text2 = "" Or Text3 = "" Or Text4 = "" Or Text5 = "" Then
MsgBox "Data Belum Lengkap"
If Text1.Text = "" Then
Text1.SetFocus
ElseIf Text2.Text = "" Then
Text2.SetFocus
ElseIf Text3.Text = "" Then
Text3.SetFocus
ElseIf Text4.Text = "" Then
Text4.SetFocus
ElseIf Text5.Text = "" Then
Text5.SetFocus
End If
Else
Dim sqlsave, tanggal As String
lahir = Format(DTPicker1.Value, "YYYY-MM-DD")
sqlsave = "insert into pelanggan values  ('" & Text1 & "','" & Text2 & "','" & Text3 & "','" & Text4 & "','" & Text5 & "','" & tanggal & "')"
conn.Execute sqlsave
Form_Load
End If
End Sub

Private Sub Command2_Click()
If Text1 = "" Or Text2 = "" Or Text3 = "" Or Text4 = "" Or Text5 = "" Then
MsgBox "Data Belum Lengkap"
If Text1.Text = "" Then
Text1.SetFocus
ElseIf Text2.Text = "" Then
Text2.SetFocus
ElseIf Text3.Text = "" Then
Text3.SetFocus
ElseIf Text4.Text = "" Then
Text4.SetFocus
ElseIf Text5.Text = "" Then
Text5.SetFocus
End If
Else
Dim sqlupdate, tanggal As String
lahir = Format(DTPicker1.Value, "YYYY-MM-DD")
sqlupdate = "update pelanggan set nama_pelanggan='" & Text2 & "', alamat='" & Text3 & "', nomor_hp ='" & Text4 & "', jenis_pelanggan='" & Text5 & "', tanggal_aktif='" & tanggal & "' where kode_pelanggan='" & Text1 & "'"
conn.Execute sqlupdate
Form_Load
End If
End Sub
Private Sub Command3_Click()
pesan = MsgBox("Yakin akan Dihapus", vbOKCancel, "KOnfirmasi Hapus Data")
If pesan = vbOK Then
Dim sqldelete As String
sqldelete = "delete from pelanggan where kode_pelanggan ='" & Text1 & "'"
conn.Execute sqldelete
MsgBox "Data Berhasil Dihapus ", vbOKOnly, "Konfirmasi Hapus"
Form_Load
Else
Form_Load
Text1.SetFocus
End If
End Sub
Private Sub Form_Activate()
Call opendb
End Sub
Private Sub Form_Load()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""

End Sub

Function cari()
Call opendb
rspelanggan.Open "select * from pelanggan where kode_pelanggan ='" & Text1 & "'", conn

End Function

Private Sub Text1_KeyPress(KeyAscii As Integer)
  If KeyAscii = 13 Then
Call cari
If Not rspelanggan.EOF Then
    tampilkandata
    MsgBox "kode pelanggan sudah ada ", vbOKOnly, "konfirmasi"
    Text2.SetFocus
Else
    Text2.SetFocus
End If
End If
End Sub

Private Sub tampilkandata()
With rspelanggan
If Not rspelanggan.EOF Then
Text2 = rspelanggan!nama_pelanggan
Text3 = rspelanggan!alamat_pelanggan
Text4 = rspelanggan!nomor_hp
Text5 = rspelanggan!jenis_pelanggan
End If
End With
End Sub
Private Sub Text2_Click()
Call cari
If Not rspelanggan.EOF Then
    tampilkandata
    MsgBox "kode pelanggan sudah ada ", vbOKOnly, "konfirmasi"
    Text2.SetFocus
Else
    Text2.SetFocus
End If
End Sub


5. buat form transaksi

 coding form transaksi disedot aja gan :D
Private Sub Combo2_Change()
Dim jenis, harga As Integer
jenis = Combo2
If jenis = "cucin+setrika" Then
harga = 10000 * Text2
ElseIf jenis = "setrika" Then
harga = 4000 * Text2
Text2.Text = harga
End If
End Sub

Private Sub Command1_Click()
If Text1 = "" Or Combo1 = "" Or Combo2 = "" Or Text2 = "" Or Text3 = "" Or Text4 = "" Or Text5 = "" Then
MsgBox "Data Belum Lengkap"
If Text1.Text = "" Then
Text1.SetFocus
ElseIf Combo1.Text = "" Then
Combo1.SetFocus
ElseIf Text3.Text = "" Then
Text3.SetFocus
ElseIf Text4.Text = "" Then
Text4.SetFocus
ElseIf Text5.Text = "" Then
Text5.SetFocus
End If
Else
Dim sqlsave, tanggal As String
tanggal = Format(DTPicker1.Value, "YYYY-MM-DD")
sqlsave = "insert into transaksi_pencucian values ('" & Text1 & "','" & tanggal & "','" & Combo1 & "','" & Combo2 & "','" & Text2 & "','" & Text3 & "','" & Text4 & "','" & Text5 & "')"
conn.Execute sqlsave
CrystalReport1.SelectionFormula = "Totext({transaksi_pencucian.no_faktur})='" & Text1 & "'"
CrystalReport1.ReportFileName = App.Path & "\Report1.rpt"
CrystalReport1.WindowState = crptMaximized
CrystalReport1.WindowShowRefreshBtn = True
CrystalReport1.RetrieveDataFiles
CrystalReport1.Action = 1
Call kosong
End If
End Sub



Private Sub Command2_Click()
Form_Load
End Sub

Private Sub Command3_Click()
MsgBox "yaqin anda ingin keluar", vbOKOnly, "konfirmasi keluar"
Unload Me
End Sub

Private Sub Command4_Click()
CrystalReport1.SelectionFormula = "Totext({transaksi_pencucian.no_faktur})='" & Text1 & "'"
CrystalReport1.ReportFileName = App.Path & "\Report1.rpt"
CrystalReport1.WindowState = crptMaximized
CrystalReport1.WindowShowRefreshBtn = True
CrystalReport1.RetrieveDataFiles
CrystalReport1.Action = 1
End Sub

Private Sub Form_Activate()
Call opendb
End Sub

Private Sub Form_Load()
Text1.Text = ""
Combo2.Clear
Combo2.AddItem "cucin+setrika"
Combo2.AddItem "setrika"
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""

Call opendb
rspelanggan.Open "Select Distinct kode_pelanggan From pelanggan order By 1", conn
rspelanggan.Requery
Do Until rspelanggan.EOF
    Combo1.AddItem rspelanggan!kode_pelanggan
    rspelanggan.MoveNext
Loop
conn.Close


End Sub


Private Sub kosong()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
End Sub





Private Sub Text4_Click()
Dim jumlah, diskon As Integer
jumlah = Text3.Text
If jumlah >= 3 Then
diskon = Val(jumlah / 3) * 0.05
Text4.Text = diskon
End If
End Sub



Private Sub Text5_Click()
Dim diskon As Double
diskon = Text2.Text * Text4.Text
Text5.Text = Val(Text2.Text) - diskon
End Sub

6. Buat Module untuk variabel koneksi ke database
 7. koneksikan dengan mysql odbc
8. lalu jalankan... semoga berhasil



No comments:

Post a Comment