Selesaikanlah Kasus Berikut :
Kasus Latihan Listview Perhitungan Penjualan Barang
Berikut Jawaban Program :
Gambar 0.1 Desain awal
program
Coding program:
Public Class Form1
Sub
buattabel()
lv.Columns.Add("No
Pembelian", 80, HorizontalAlignment.Center)
lv.Columns.Add("Kode
Barang", 180, HorizontalAlignment.Center)
lv.Columns.Add("Nama
Barang", 180, HorizontalAlignment.Center)
lv.Columns.Add("Merk",
80, HorizontalAlignment.Center)
lv.Columns.Add("Harga",
80, HorizontalAlignment.Center)
lv.Columns.Add("Jumlah
Beli", 80, HorizontalAlignment.Center)
lv.Columns.Add("Total
Harga", 80, HorizontalAlignment.Center)
lv.View = View.Details
lv.GridLines = True
lv.FullRowSelect = True
End Sub
Sub
isitabel()
Dim lst
As New
ListViewItem
lst.Text = kode.Text
lst.SubItems.Add(no.Text)
lst.SubItems.Add(nama.Text)
lst.SubItems.Add(merk.Text)
lst.SubItems.Add(harga.Text)
lst.SubItems.Add(jlh.Text)
lst.SubItems.Add(total.Text)
lv.Items.Add(lst)
End Sub
Private Sub kode_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles
kode.SelectedIndexChanged
Dim x As String
x =
Microsoft.VisualBasic.Left(kode.Text, 2)
Select Case x
Case
"TS" : merk.Text = "Toshiba"
Case
"VG" : merk.Text = "V-Gen"
End Select
Dim y As String
y =
Microsoft.VisualBasic.Right(kode.Text, 3)
Select Case y
Case
"001" : nama.Text = "flashdisk 4 GB"
Case "002" : nama.Text = "flashdisk 2 GB"
End Select
If x = "TS" And
y = "001" Then
harga.Text = "105000"
ElseIf
x = "TS" And
y = "002" Then
harga.Text = "75000"
ElseIf
x = "VG" And
y = "001" Then
harga.Text = "90000"
ElseIf
x = "VG" And
y = "002" Then
harga.Text = "60000"
Else
harga.Text = "0"
End If
End Sub
Private Sub Form1_Load(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
kode.Items.Add("TS001")
kode.Items.Add("TS002")
kode.Items.Add("VG001")
kode.Items.Add("VG002")
buattabel()
End Sub
Private Sub Button5_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles btnkeluar.Click
End
End Sub
Private Sub Button2_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles btnbersih.Click
kode.Text = ""
nama.Text = ""
nama.Text = ""
harga.Text = ""
merk.Text = ""
jlh.Text = ""
total.Text = ""
End Sub
Private Sub Button1_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles btnsimpan.Click
isitabel()
End Sub
Private Sub Button4_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles
btnhapusdatadipilih.Click
lv.Items.Remove(lv.SelectedItems(0))
End Sub
Private Sub Button3_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles
btnhapussemuadata.Click
lv.Items.Clear()
End Sub
Private Sub total_TextChanged(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles total.TextChanged
total.Text = Val(harga.Text) *
Val(jlh.Text)
End Sub
Private Sub jlh_KeyPress(ByVal
sender As Object,
ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles
jlh.KeyPress
Dim x2 As Integer =
Asc(e.KeyChar)
If x2 =
13 Then
total.Text = Val(harga.Text) * Val(jlh.Text)
End If
End Sub
Private Sub jlh_TextChanged(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles jlh.TextChanged
End Sub
End Class
Dan inilah hasil dari
program :
Gambar 0.1 Desain hasil akhir dari program
Selamat Pemrograman VB Net
0 komentar:
Posting Komentar