Setelah kita memepelajari program Visual Basic khususnya Visual Basic .Net dari awal atau dari Nol, kita di harapkan sudah memahami fungsi dari semua kontrol yang ada di ToolBox yang kita sudah pelajari di artikel Blog ini.
Kali ini Admin ingin mengadakan sebuah Studi Kasus yang terjadi dalam kehidupan sehari-hari terutama untuk membuat program Aplikasi sederhana untuk usaha UMKM.
Studi Kasus di VB .Net:
Sebuah Cafe Betawi Petir mempunyai cara tersendiri dalam menarik pelanggannya mulai dari menu yang menarik sampai mendapatkan Bonus dan Potongan dengan syarat tertentu.
Menu di pilih melalui RadioButton dengan rincian sebagai berikut :
- Gado-Gado dengan Harga Rp. 20.000
- Nasi Uduk dengan Harga Rp. 15.000
- Soto Betawi dengan Harga Rp. 25.000
Cafe Betawi Petir juga memberikan potongan pembayaran berdasarkan jumlah porsi yang di pesan :
- Jika pesanan Lebih dari 10 (>10), potongan 10%
- Selain itu dapet juga Bonus 1 porsi sesuai barang yang dipesan
- Jika dibawah 10 atau sama dengan 10 (<=10), maka tidak ada Potongan dan Bonus
- Biaya Pajak juga harus ditanggung pembeli sebesar 5% dari Jumlah Total Bayar
- Jumlah yang harus di Bayar =((Total Bayar-Potongan) + Pajak)
Batlah Program berdasarkan ketentuan diatas :
A. Persiapan
Buka program Visual Basic .Net Anda
Pada Form1 tanamkan beberapa kontrol dibawah ini :
- Label
- GroupBox
- TextBox
- Radiobutton
- Button
B. Pengaturan Kontrol
| Kontrol |
Name |
Keterangan |
| GroupBox1 |
GroupBox1 |
Text : Pilihan Menu, Background:ActiveCaption |
| GroupBox2 |
GroupBox2 |
Text:Transaksi Pembelian, Background:ActiveCaption |
| GropuBox3 |
GropuBox3 |
Text:Potongan, Backcolor:silver, Font size:12, Bold |
| GropuBox4 |
GropuBox4 |
Text:Transaksi Pembayaran, Backcolor:silver, Font size:12, Bold |
| RadioButtonl |
RadioButton1 |
Text: Gado-Gado, Font size:12, Bold |
| RadioButton2 |
RadioButton2 |
Text: Nasi Uduk, Font size:12, Bold |
| RadioButton3 |
RadioButton3 |
Text: Soto Betawi, Font size:12, Bold |
| Label1 |
Label1 |
CAFE BETAWI PETIR Font Size:24, Bold |
| Label2 |
Label2 |
Text:Harga/Porsi, Font size:12, Bold |
| Label3 |
Label3 |
Text:Jumlah Porsi, Font size:12, Bold |
| Label4 |
Label4 |
Text:Bayar, Font size:12, Bold |
| Label5 |
Label5 |
Text:Bonus, Font size:12, Bold |
| Label6 |
Label6 |
Text:Potongan, Font size:12, Bold |
| Label7 |
Label7 |
Text:Ppn, Font size:12, Bold |
| Label8 |
Label8 |
Text:Total Bayar, Font size:12, Bold |
| Label9 |
Label9 |
Text:Uang Bayar, Font size:12, Bold |
| Label10 |
Label10 |
Text:Uang Kembali, Font size:12, Bold |
| Label |
LabelHarga |
Text:LabelHarga, AutoSize:False, BorderStyle:FixedSingle,BackColor:control |
| Label |
LabelBayar |
Text:LabelBayar, AutoSize:False, BorderStyle:FixedSingle,BackColor:control |
| Label |
LabelBonus |
Text:LabelBonus, AutoSize:False, BorderStyle:FixedSingle,BackColor:control |
| Label |
LabelPotongan |
Text:LabelPotongan,Font size:12, Bold, AutoSize:False, BorderStyle:Fixedsingle, BackColor:control |
| Label |
LabelPpn |
Text:LabelPpn,Font size:12, Bold, AutoSize:False, BorderStyle:Fixedsingle, BackColor:control |
| Label |
LabelTotalBayar |
Text:LabelTotalBayar,Font size:12, Bold, AutoSize:False, BorderStyle:Fixedsingle, BackColor:control |
| Label |
LabelKembali |
Text:LabelKembali, BorderStyle:Fixedsingle, BackColor:control, Font size:12, Bold |
| TextBox |
TextBoxPorsi |
Text:"", BorderStyle:FixedSingle,BackColor:window |
| TextBox |
TextBoxBayar |
Text:"", BorderStyle:FixedSingle,BackColor:window |
| Button1 |
Button1 |
Text:Clear, Font size:12, Bold |
| Button2 |
Button2 |
Text:Exit, Font size:12, Bold |
C. Desain Form
 |
| Form Penjualan dengan VB .Net |
D. Listing Program (Code)
Buka jendela kode, bersihkan kode yang ada dengan CTRL+A kemudian Del lalu Copy-Paste kode dibawah ini :
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
RadioButton1.Checked = True
RadioButton2.Checked = False
RadioButton3.Checked = False
Call kosong()
End Sub
Private Sub RadioButton1_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton1.CheckedChanged
'Label Harga
LabelHarga.Text = 20000
TextBoxPorsi.Focus()
End Sub
Private Sub RadioButton2_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton2.CheckedChanged
'Label Harga
LabelHarga.Text = 15000
TextBoxPorsi.Focus()
End Sub
Private Sub RadioButton3_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton3.CheckedChanged
'Label Harga
LabelHarga.Text = 25000
TextBoxPorsi.Focus()
End Sub
Sub kosong()
'mengsosongkan TextBox dan Label
LabelBayar.Text = 0
LabelBonus.Text = "-"
LabelPotongan.Text = 0
LabelPpn.Text = 0
LabelTotalBayar.Text = 0
TextBoxBayar.Text = 0
LabelKembali.Text = 0
TextBoxPorsi.Text = 0
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Call kosong()
TextBoxPorsi.Focus()
End Sub
Private Sub Form1_Shown(sender As Object, e As EventArgs) Handles Me.Shown
'Form rata tengah
Me.StartPosition = FormStartPosition.Manual
Me.Left = (Screen.PrimaryScreen.WorkingArea.Width - Me.Width) \ 2
Me.Top = (Screen.PrimaryScreen.WorkingArea.Height - Me.Height) \ 2
TextBoxPorsi.Focus()
End Sub
Private Sub TextBoxPorsi_TextChanged(sender As Object, e As EventArgs) Handles TextBoxPorsi.TextChanged
'input jumalh beli langsung menghitung
Dim harga As Integer
Dim porsi As Integer
Dim bayar As Integer
Integer.TryParse(LabelHarga.Text, harga)
Integer.TryParse(TextBoxPorsi.Text, porsi)
bayar = harga * porsi
LabelBayar.Text = bayar.ToString()
'Di potong PPN 5% dari bayar
Dim ppn As Integer
ppn = (bayar * 5 / 100)
LabelPpn.Text = ppn.ToString("N0")
'Dapat potongan jika pembelian lebih dari 10 porsi
If porsi > 10 Then
Dim potongan As Integer
potongan = (bayar * 10 / 100)
LabelPotongan.Text = potongan.ToString("N0")
'Dapat bonus jika pembelian lebih dari 10 dengan barang terpilih
Dim pilihan As String = ""
If RadioButton1.Checked Then
pilihan = RadioButton1.Text
ElseIf RadioButton2.Checked Then
pilihan = RadioButton2.Text
ElseIf RadioButton3.Checked Then
pilihan = RadioButton3.Text
End If
LabelBonus.Text = "1 Porsi " & pilihan
Else
'Kalau pembelian dibawah 11
LabelBonus.Text = "-"
LabelPotongan.Text = "0"
End If
'Perhitungan Total Bayar
Dim TotalBayar As Integer
TotalBayar = bayar + (ppn - LabelPotongan.Text)
LabelTotalBayar.Text = TotalBayar.ToString("N0")
End Sub
Private Sub TextBoxBayar_TextChanged(sender As Object, e As EventArgs) Handles TextBoxBayar.TextChanged
' format pemisah ribuan saat angka di ketik
Static isFormatting As Boolean = False
If isFormatting Then Exit Sub
isFormatting = True
Dim cash As Decimal
Dim total As Decimal
Dim kembali As Decimal
Decimal.TryParse(TextBoxBayar.Text.Replace(",", ""), cash)
Decimal.TryParse(LabelTotalBayar.Text.Replace(",", ""), total)
' Format ulang textbox
If cash > 0 Then
TextBoxBayar.Text = cash.ToString("N0")
TextBoxBayar.SelectionStart = TextBoxBayar.Text.Length
End If
' Hitung kembalian
kembali = cash - total
If kembali < 0 Then
LabelKembali.Text = "0"
Else
LabelKembali.Text = kembali.ToString("N0")
End If
isFormatting = False
End Sub
Private Sub TextBoxBayar_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TextBoxBayar.KeyPress
'hanya angka yang bisa dimasukan
If Not Char.IsDigit(e.KeyChar) AndAlso Not Char.IsControl(e.KeyChar) Then
e.Handled = True
End If
End Sub
Private Sub TextBoxBayar_Enter(sender As Object, e As EventArgs) Handles TextBoxBayar.Enter
'ketika focus blok teks
TextBoxBayar.SelectAll()
End Sub
Private Sub TextBoxPorsi_KeyDown(sender As Object, e As KeyEventArgs) Handles TextBoxPorsi.KeyDown
'cursor menuju textbayar ketika di tekan Enter setelah pengisisan jumlah beli
If e.KeyCode = Keys.Enter Then
e.SuppressKeyPress = True ' supaya tidak bunyi beep
TextBoxBayar.Focus()
End If
End Sub
Private Sub TextBoxPorsi_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TextBoxPorsi.KeyPress
'hanya angka yang bisa dimasukan
If Not Char.IsDigit(e.KeyChar) AndAlso Not Char.IsControl(e.KeyChar) Then
e.Handled = True
End If
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Me.Close()
End Sub
End Class
Simpan dan jalankan Program
E. Cara Pengoperasian
- Pilih Menu yang diinginkan pada RadioButton
- Harga tampil otomatis saat menu di pilih
- Isi jumlah Porsi yang diinginkan maka secara bersamaan semua akan terhitung otomatis
- Tekan Enter setelah pengisian Jumlah Beli maka cursor akan fokus ke Uang Bayar
- Ketika di Input Uang Bayar, maka Kembalian akan muncul otomatis
F. Penutup
Demikianlah artikel tentang Studi Kaus : Membuat Form Penjualan Untuk Cafe di VB .NET Lengkap Tanpa Error, semoga artikel ini bermanfaat buat kita semua.Amin.
Selamat mencoba semoga berhasil
Post a Comment for "Studi Kasus : Membuat Form Penjualan Untuk Cafe di VB .NET Lengkap Tanpa Error"
Berkomentarlah dengan sopan sesuai tema yang Anda baca.
Jangan menyimpang dari tema