Sabtu, 28 Januari 2012

Jawaban Soal 2 (Fince Tinus Waruwu)

Kasus : Quiz No 2 Halaman 33

Listing Program :

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")

        Dim i As Integer
        For i = 1 To 20
            no.Items.Add(i)
        Next

        Call buattabel()
End Sub

Private Sub kode_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles kode.SelectedIndexChanged
        Dim x, y As String
        x = Microsoft.VisualBasic.Left(kode.Text, 2)
        y = Microsoft.VisualBasic.Right(kode.Text, 3)
        Select Case x
            Case "TS" : merk.Text = "Thosiba"
                Select Case y
                    Case "001" : Me.nama.Text = "Flashdisk 4GB" : Me.harga.Text = 105000
                    Case "002" : Me.nama.Text = "Flashdisk 2GB" : Me.harga.Text = 72000
                End Select
            Case "VG" : merk.Text = "V-Gen"
                Select Case y
                    Case "001" : Me.nama.Text = "Flashdisk 4GB" : Me.harga.Text = 90000
                    Case "002" : Me.nama.Text = "Flashdisk 2GB" : Me.harga.Text = 60000
                End Select
        End Select
    End Sub

Private Sub jumlah_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles jumlah.KeyPress
        If Asc(e.KeyChar) = 13 Then
            total.Text = harga.Text * jumlah.Text
        End If
    End Sub

Sub buattabel()
        lv.View = View.Details
        lv.GridLines = True
        lv.FullRowSelect = True
        lv.Columns.Add("No Pembelian", 80)
        lv.Columns.Add("Kode", 100)
        lv.Columns.Add("Nama", 120)
        lv.Columns.Add("Merk", 100)
        lv.Columns.Add("Harga", 100)
        lv.Columns.Add("Jumlah", 100)
        lv.Columns.Add("Total", 100)
End Sub


Sub IsiTabel()
        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 simpan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles simpan.Click
        Call IsiTabel()
End Sub

Private Sub keluar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles keluar.Click
        Dim i As MsgBoxResult
        i = MsgBox("Apa anda ingin keluar?", MsgBoxStyle.Information + MsgBoxStyle.YesNo, "Perhatian")
        If i = MsgBoxResult.Yes Then
            Close()
        End If
End Sub

Private Sub bersih_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bersih.Click
        Call berish(Me)
End Sub

Sub berish(ByVal F As Form)
        Dim X As Object
        For Each X In F.Controls
            If TypeOf X Is TextBox Then X.Text = ""
            If TypeOf X Is ComboBox Then X.Text = ""
        Next
End Sub

Private Sub hapus_data_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles hapus_data.Click
        lv.Items.Remove(lv.SelectedItems(0))
End Sub

    Private Sub hapus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles hapus.Click
        lv.Items.Clear()
    End Sub
End Class


Hasil Program