- Form (Name : frmKasir, Text = Kosongkan)
- TextBox: (txtKodeBarang, txtNamaBarang, txtHargaJual, txtJumlahJual, txtSubTotal, txtUangBayar, txtUang Kembali)
- Label : (Default, Sesuaikan dengan TextBox, txtGrandTotal, lblTotal)
- Button : (Name : btnTambah)
- DataGridView: (Name : dgvPenjualan)
2. Tambahkan Kode Berikut:
Sub txtKodeBarang, ganti event menjadi KeyPress
- Private Sub txtKodeBarang_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtKodeBarang.KeyPress
- If e.KeyChar = Chr(13) Then
- If txtKodeBarang.Text = "MR01" Then
- txtNamaBarang.Text = "MotherBoard PC"
- txtHargaJual.Text = 300000
- ElseIf txtKodeBarang.Text = "KR01" Then
- txtNamaBarang.Text = "Keyboard"
- txtHargaJual.Text = 45000
- ElseIf txtKodeBarang.Text = "LD01" Then
- txtNamaBarang.Text = "LCD"
- txtHargaJual.Text = 120000
- End If
- End If
- End Sub
Sub txtJumlahJual, ganti event menjadi KeyPress
Sub btnTambah:
- Private Sub txtJumlahJual_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtJumlahJual.KeyPress
- If e.KeyChar = Chr(13) Then
- txtSubTotal.Text = Val(txtHargaJual.Text) * Val(txtJumlahJual.Text)
- End If
- End Sub
Sub btnTambah:
- Private Sub btnTambah_Click(sender As Object, e As EventArgs) Handles btnTambah.Click
- dgvPenjualan.RowCount = dgvPenjualan.RowCount + 1
- dgvPenjualan(0, dgvPenjualan.RowCount - 2).Value = txtKodeBarang.Text
- dgvPenjualan(1, dgvPenjualan.RowCount - 2).Value = txtNamaBarang.Text
- dgvPenjualan(2, dgvPenjualan.RowCount - 2).Value = txtHargaJual.Text
- dgvPenjualan(3, dgvPenjualan.RowCount - 2).Value = txtJumlahJual.Text
- dgvPenjualan(4, dgvPenjualan.RowCount - 2).Value = txtSubTotal.Text
- If dgvPenjualan.RowCount > 1 Then
- Dim totalharga As Integer = 0
- For index As Integer = 0 To dgvPenjualan.RowCount - 1
- totalharga += Convert.ToInt32(dgvPenjualan.Rows(index).Cells(4).Value)
- Next
- txtGrandTotal.Text = Val(txtGrandTotal.Text) + totalharga
- End If
- End Sub
Sub txtUangBayar, ganti event menjadi KeyPress
- Private Sub txtUangBayar_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtUangBayar.KeyPress
- If e.KeyChar = Chr(13) Then
- txtUangKembali.Text = Val(txtUangBayar.Text) - Val(txtGrandTotal.Text)
- End If
- End Sub
Tidak ada komentar:
Posting Komentar