Pertama kita buat design VB.Net seperti yang dibawah ini :
Kedua masukan koding vb.net seperti yang dibawah ini :
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
kodebarang.Items.Add("TS001")
kodebarang.Items.Add("TS002")
kodebarang.Items.Add("VG001")
kodebarang.Items.Add("VG002")
Call buattable()
End Sub
Sub buattable()
Lv.Columns.Add("No Pembelian", 100, HorizontalAlignment.Center)
Lv.Columns.Add("Kode Barang", 90, HorizontalAlignment.Center)
Lv.Columns.Add("Nama Barang", 100, HorizontalAlignment.Center)
Lv.Columns.Add("Merk", 70, HorizontalAlignment.Center)
Lv.Columns.Add("Harga", 70, HorizontalAlignment.Center)
Lv.Columns.Add("Jumlah Beli", 90, HorizontalAlignment.Center)
Lv.Columns.Add("Total Harga", 100, HorizontalAlignment.Center)
Lv.View = View.Details
Lv.GridLines = True
Lv.FullRowSelect = True
End Sub
Sub isitable()
Dim x As New ListViewItem
x.Text = nopembelian.Text
x.SubItems.Add(kodebarang.Text)
x.SubItems.Add(namabarang.Text)
x.SubItems.Add(merk.Text)
x.SubItems.Add(harga.Text)
x.SubItems.Add(jumlahbeli.Text)
x.SubItems.Add(totalharga.Text)
Lv.Items.Add(x)
End Sub
Private Sub kodebarang_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles kodebarang.SelectedIndexChanged
Dim x As String
x = Mid(kodebarang.Text, 1, 2)
Select Case x
Case "TS"
merk.Text = "Toshiba"
Case "TS"
merk.Text = "Toshiba"
Case "VG"
merk.Text = "V-Gen"
Case "VG"
merk.Text = "V-Gen"
End Select
x = Mid(kodebarang.Text, 3, 3)
Select Case x
Case "001"
namabarang.Text = "Flashdisk 4 GB"
Case "002"
namabarang.Text = "Flashdisk 2GB"
Case "001"
namabarang.Text = "Flashdisk 4GB"
Case "002"
namabarang.Text = "Flashdisk 2GB"
End Select
If kodebarang.Text = "TS001" Then
harga.Text = 105000
ElseIf kodebarang.Text = "TS002" Then
harga.Text = 75000
ElseIf kodebarang.Text = "VG001" Then
harga.Text = 90000
ElseIf kodebarang.Text = "VG002" Then
harga.Text = 65000
End If
End Sub
Private Sub jumlahbeli_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles jumlahbeli.KeyPress
If Asc(e.KeyChar) = 13 Then
totalharga.Text = Val(harga.Text) * jumlahbeli.Text
End If
End Sub
Private Sub Bersih_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bersih.Click
nopembelian.Text = ""
kodebarang.Text = ""
namabarang.Text = ""
merk.Text = ""
harga.Text = ""
jumlahbeli.Text = ""
totalharga.Text = ""
End Sub
Private Sub Simpanlistview_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Simpanlistview.Click
Call isitable()
End Sub
Private Sub hapussemua_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles hapussemua.Click
Lv.Items.Clear()
End Sub
Private Sub hapusdatapilih_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles hapusdatapilih.Click
Lv.Items.Remove(Lv.SelectedItems(0))
End Sub
Private Sub keluar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles keluar.Click
Me.Close()
End Sub
End Class
Setelah selesai membuat koding nya , jalankan program vb.net nya , maka akan tampil seperti ini :
0 comments:
Post a Comment