Public Class Form1
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")
buat_tabel()
End Sub
Sub cek()
Dim x As String
x = Microsoft.VisualBasic.Left(kode.Text, 2)
If x = "TS" Then
merk.Text = "Toshiba"
ElseIf x = "VG" Then
merk.Text = "V-Gen"
End If
x = Microsoft.VisualBasic.Mid(kode.Text, 3, 3)
If x = "001" Then
nama.Text = "Flasdisk 4GB"
ElseIf x = "002" Then
nama.Text = "Flasdisk 2GB"
End If
If kode.Text = "TS001" Then
harga.Text = 105000
ElseIf kode.Text = "TS002" Then
harga.Text = 75000
End If
If kode.Text = "VG001" Then
harga.Text = 90000
ElseIf kode.Text = "VG002" Then
harga.Text = 6000
End If
End Sub
Sub buat_tabel()
With LV
.Columns.Add("No.pembelian", 85, HorizontalAlignment.Center)
.Columns.Add("Kode Barang", 90, HorizontalAlignment.Center)
.Columns.Add("Nama Barang", 80, HorizontalAlignment.Left)
.Columns.Add("Merk", 70, HorizontalAlignment.Center)
.Columns.Add("Harga", 75, HorizontalAlignment.Center)
.Columns.Add("Jumlah Beli", 90, HorizontalAlignment.Center)
.Columns.Add("Total Harga", 90, HorizontalAlignment.Center)
.View = View.Details
.GridLines = True
.FullRowSelect = True
End With
End Sub
Sub isi_tabel()
Dim lst As New ListViewItem
lst.Text = no.Text
lst.SubItems.Add(kode.Text)
lst.SubItems.Add(nama.Text)
lst.SubItems.Add(merk.Text)
lst.SubItems.Add(harga.Text)
lst.SubItems.Add(jumlah.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
Call cek()
End Sub
Private Sub jumlah_keypress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles jumlah.KeyPress
Dim tombol As Integer = Asc(e.KeyChar)
If tombol = 13 Then
cek()
total.Text = Val(harga.Text) * Val(jumlah.Text)
End If
End Sub
Private Sub btnsimpan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsimpan.Click
isi_tabel()
End Sub
Private Sub btnbersih_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnbersih.Click
no.Text = ""
kode.Text = ""
nama.Text = ""
merk.Text = ""
harga.Text = ""
jumlah.Text = ""
total.Text = ""
no.Focus()
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 btnpilih_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnpilih.Click
LV.Items.Remove(LV.SelectedItems(0))
End Sub
Private Sub btnkeluar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnkeluar.Click
End
End Sub
End Class
Hasil Program
Catatan :
Fungsi Tombol
* Simpan ke ListView : memasukkan data ke dalam tabel
* Bersih : menghapus data
* Hapus Semua Data : menghapus semua data yang ada di tabel
* Hapus Data yang di pilih : menghapus salah satu data yang dipilih pada di tabel
* Keluar Program : keluar dari program
Tidak ada komentar:
Posting Komentar