Latihan Listview Perhitungan Penjualan Barang pada Visual Basic
Desain Form,
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
buattabel()
kodebrg.Items.Add("MS01")
kodebrg.Items.Add("MS02")
kodebrg.Items.Add("MS03")
kodebrg.Items.Add("ID01")
kodebrg.Items.Add("ID02")
kodebrg.Items.Add("ID03")
kodebrg.Items.Add("SP01")
kodebrg.Items.Add("SP02")
kodebrg.Items.Add("SP03")
End Sub
Sub isitabel()
Dim lst As New ListViewItem
lst.Text = kodebrg.Text
lst.SubItems.Add(namabrg.Text)
lst.SubItems.Add(merk.Text)
lst.SubItems.Add(harga.Text)
lst.SubItems.Add(jbeli.Text)
lst.SubItems.Add(diskon.Text)
lst.SubItems.Add(tharga.Text)
LV.Items.Add(lst)
End Sub
Sub buattabel()
LV.Columns.Add("Kode barang", 50, HorizontalAlignment.Center)
LV.Columns.Add("Nama barang", 100, HorizontalAlignment.Left)
LV.Columns.Add("Merk", 80, HorizontalAlignment.Right)
LV.Columns.Add("Harga", 50, HorizontalAlignment.Center)
LV.Columns.Add("Jumlah Beli", 80, HorizontalAlignment.Left)
LV.Columns.Add("Diskon", 80, HorizontalAlignment.Right)
LV.Columns.Add("Total Harga", 80, HorizontalAlignment.Right)
LV.GridLines = True
LV.View = View.Details
LV.FullRowSelect = True
End Sub
Private Sub kodebrg_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles kodebrg.SelectedIndexChanged
Dim x As String
x = Microsoft.VisualBasic.Left(kodebrg.Text, 2)
If x = "MS" Then
merk.Text = "Mie Sedaap!"
ElseIf x = "ID" Then
merk.Text = "Indomie"
ElseIf x = "SP" Then
merk.Text = "Supermie"
End If
Dim k As String
k = Microsoft.VisualBasic.Right(kodebrg.Text, 2)
If k = "01" Then
namabrg.Text = "Rasa Soto"
ElseIf k = "02" Then
namabrg.Text = "Rasa Kari Ayam"
ElseIf k = "03" Then
namabrg.Text = "Rasa Ayam Bawang"
End If
If kodebrg.Text = "MS01" Then
harga.Text = "45000"
ElseIf kodebrg.Text = "MS02" Then
harga.Text = "65000"
ElseIf kodebrg.Text = "MS03" Then
harga.Text = "87000"
ElseIf kodebrg.Text = "ID01" Then
harga.Text = "63000"
ElseIf kodebrg.Text = "ID02" Then
harga.Text = "70000"
ElseIf kodebrg.Text = "ID03" Then
harga.Text = "48000"
ElseIf kodebrg.Text = "SP01" Then
harga.Text = "56000"
ElseIf kodebrg.Text = "SP02" Then
harga.Text = "52000"
ElseIf kodebrg.Text = "SP03" Then
harga.Text = "63000"
End If
End Sub
Private Sub btnhapus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnhapus.Click
LV.Items.Clear()
End Sub
Private Sub btnkeluar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnkeluar.Click
Close()
End Sub
Private Sub btnsimpan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsimpan.Click
isitabel()
kodebrg.Text = ""
namabrg.Text = ""
merk.Text = ""
harga.Text = ""
jbeli.Text = ""
diskon.Text = ""
tharga.Text = ""
End Sub
Private Sub btnproses_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnproses.Click
diskon.Text = 5 / 100 * harga.Text
tharga.Text = harga.Text * jbeli.Text - diskon.Text
End Sub
End Class
Berikut adalah hasilnya
Tidak ada komentar:
Posting Komentar