Anda di halaman 1dari 18

Teknik Informatika Universitas Serambi Mekkah

Membuat Aplikasi Penjualan Buku Sederhana


Langkah-langkah dalam membuat aplikasi adalah sebagai berikut :
1. Buat project baru dengan nama Aplikasi Penjualan lalu simpan pada Local
Disc di PC atau Laptop
Anda.
2. Buatlah database dengan nama JualBuku.accdb lalu simpan kedalam folder
Aplikasi Penjualan >
bin > debug kemudian rancanglah struktur tabel seperti berikut ini :
Nama Tabel : Jenis
Fiel
Type
d
KodeJenis
Text
Jenis
Text
Nama Tabel : Buku
Fiel
Type
d
KodeBuku
Text
KodeJenis
Text
Judul
Text
Pengarang
Text
Penerbit
Text
Jumlah
Number
Harga
Number
Deskripsi
Text
Nama Tabel : Transaksi
Fiel
Type
d
NoFaktur
Text
TglFaktur
Date/Tim
e
Pukul
Date/Tim
e
NamaPembeli Text
NoTelp
Text
Total
Number
Dibayar
Number
Kembali
Number
Item
Number

Size
Keterangan
2
Primary Key (PK)
50

Size
Keterangan
3
Primary Key (PK)
2
Foreign Key (FK)
100
50
50

200

Size
Keterangan
11
Primary Key (PK)

50
12

Nama Tabel : DetailTransaksi


Fiel
Type
Size
d
NoFaktur
Text
11
KodeBuku
Text
3
Judul
Text
150
Jumlah
Number
HargaJual
Number
SubTotal
Number

Modul Dasar Pemrograman III (VB.Net)

Keterangan

Hal. 1

Teknik Informatika Universitas Serambi Mekkah

Entity Relationship Diagram (ERD) Aplikasi Penjualan Buku Komputer

Gambar 1.
Rancangan ERD
Rancanglah Form Menu, Form Jenis Buku, dan Form Data Buku, Form
Transaksi Penjualan Buku seperti gambar berikut :

MenuStrip1
GroupBox1

Button

StatusStrip1

Gambar 2. Menu Aplikasi Penjualan Buku Komputer


Tulislah koding menunya sebagai berikut :
Public Class Form1
Private Sub DataJenisBukuToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles DataJenisBukuToolStripMenuItem.Click
Form2.Show()
End Sub

Modul Dasar Pemrograman III (VB.Net)

Hal. 2

Teknik Informatika Universitas Serambi Mekkah

Private Sub DataBukuToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles DataBukuToolStripMenuItem.Click
Form3.Show()
End Sub
Private Sub KeluarToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles KeluarToolStripMenuItem.Click
If MessageBox.Show("Yakin akan menutup aplikasi ini..?", "", MessageBoxButtons.YesNo)
= Windows.Forms.DialogResult.Yes Then
End
End If
End Sub
End Class

Button
1

TextBox
1

Button
2

TextBox
2

Button3
TextBox
3

Button
4

DataGridView1

Gambar 3. Rancangan Form Data Jenis Buku

Modul Dasar Pemrograman III (VB.Net)

Hal. 3

TextBo
x1

ComboBox1

TextBo
x2
TextBo
x3

TextBox8

TextBo
x4

TextBox7

TextBo
x5

Button5

TextBo
x6

Button4
Button3

TextBo
x9
DataGridVie
w1

Button2

Button1

Gambar 4. Rancangan Form


Data Buku

TextBox2
TextBo
x1

TextBox
3

TextBo
x4
TextBo
x5

Button4

DataGridView1
Label10
1
Button

Button
2

TextBox9
TextBox6
TextBox7

Button
3

Gambar 5. Rancangan Form Transaksi


Penjualan Buku

TextBox8

Tambahkan sebuah module kemudian tulislah koding dibawah ini :


Imports System.Data.OleDb
Module Module1
Public Conn As OleDbConnection
Public da As OleDbDataAdapter
Public ds As DataSet
Public cmd As OleDbCommand
Public rd As OleDbDataReader
Public Str As String
Public Sub Koneksi()
Str = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & Application.StartupPath &
"\JualBuku.accdb"
Conn = New OleDbConnection(Str)
If Conn.State = ConnectionState.Closed Then
Conn.Open()
End If
End Sub
End Module

Hasil Form2 (Jenis Buku) setelah dijalankan

Gambar 6. Hasil Form2 (Jenis Buku)


Kodingnya sebagai berikut :
Imports System.Data.OleDb
Public Class Form2
Sub Kosong()
TextBox1.Clear()
TextBox2.Clear()
TextBox1.Focus()
End Sub
Sub Isi()
TextBox2.Clear()
TextBox2.Focus()
End Sub

Sub TampilJenis()
da = New OleDbDataAdapter("Select * From Jenis", Conn)
ds = New DataSet
ds.Clear()
da.Fill(ds, "Jenis")
DataGridView1.DataSource = ds.Tables("Jenis")
DataGridView1.Refresh()
End Sub
Sub AturGrid()
DataGridView1.Columns(0).Width = 60
DataGridView1.Columns(1).Width = 200
DataGridView1.Columns(0).HeaderText = "KODE JENIS"
DataGridView1.Columns(1).HeaderText = "NAMA JENIS"
End Sub
Private Sub Form2_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles
Me.Load
Call Koneksi()
Call TampilJenis()
Call Kosong()
Call AturGrid()
End Sub
Private Sub TextBox2_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles TextBox2.KeyPress
TextBox2.MaxLength = 50
If e.KeyChar = Chr(13) Then
TextBox2.Text = UCase(TextBox2.Text)
End If
End Sub
Private Sub DataGridView1_CellContentClick(ByVal sender As Object, ByVal e As
System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
Dim i As Integer
i = Me.DataGridView1.CurrentRow.Index
With DataGridView1.Rows.Item(i)
Me.TextBox1.Text = .Cells(0).Value
Me.TextBox2.Text = .Cells(1).Value
End With
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button1.Click
If TextBox1.Text = "" Or TextBox2.Text = "" Then
MsgBox("Data belum lengkap..!")
TextBox1.Focus()
Exit Sub
Else
cmd = New OleDbCommand("Select * From Jenis where KodeJenis='" & TextBox1.Text &
"'", Conn)
rd = cmd.ExecuteReader
rd.Read()
If Not rd.HasRows Then
Dim Simpan As String = "insert into Jenis(KodeJenis,Jenis)values " & _
"('" & TextBox1.Text & "','" & TextBox2.Text & "')"
cmd = New OleDbCommand(Simpan, Conn)
cmd.ExecuteNonQuery()
MsgBox("Simpan data sukses...!", MsgBoxStyle.Information, "Perhatian")
End If
Call TampilJenis()
Call Kosong()
TextBox1.Focus()
End If
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Button2.Click
If TextBox1.Text = "" Then
MsgBox("Kode Jenis belum diisi")
TextBox1.Focus()
Exit Sub
Else
Dim Ubah As String = "Update Jenis set " & _
"Jenis='" & TextBox2.Text & "' " & _
"where KodeJenis='" & TextBox1.Text & "'"
cmd = New OleDbCommand(Ubah, Conn)
cmd.ExecuteNonQuery()
MsgBox("Ubah data sukses..!", MsgBoxStyle.Information, "Perhatian")
Call TampilJenis()
Call Kosong()
TextBox1.Focus()
End If
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button3.Click
If TextBox1.Text = "" Then
MsgBox("Kode Buku belum diisi")
TextBox1.Focus()
Exit Sub
Else
If MessageBox.Show("Yakin akan menghapus Data Jenis " & TextBox1.Text & " ?", "",
MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.Yes Then
cmd = New OleDbCommand("Delete * From Jenis where KodeJenis='" & TextBox1.Text
& "'", Conn)
cmd.ExecuteNonQuery()
Call Kosong()
Call TampilJenis()
Else
Call Kosong()
End If
End If
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button4.Click
Call Kosong()
End Sub
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
TextBox1.MaxLength = 2
If e.KeyChar = Chr(13) Then
cmd = New OleDbCommand("Select * From Jenis where KodeJenis='" & TextBox1.Text &
"'", Conn)
rd = cmd.ExecuteReader
rd.Read()
If rd.HasRows = True Then
TextBox2.Text = rd.Item(1)
TextBox2.Focus()
Else
Call Isi()
TextBox2.Focus()
End If
End If
End Sub
Private Sub TextBox3_TextChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles TextBox3.TextChanged
cmd = New OleDbCommand("Select * From Jenis where KodeJenis like '%" & TextBox3.Text &
"%'", Conn)
rd = cmd.ExecuteReader
rd.Read()
If rd.HasRows Then
da = New OleDbDataAdapter("Select * From Jenis where KodeJenis like '%" &
TextBox3.Text & "%'", Conn) ds =
New DataSet
da.Fill(ds, "Dapat")
DataGridView1.DataSource = ds.Tables("Dapat")

DataGridView1.ReadOnly = True
Else
MsgBox("Data tidak ditemukan")
End If
End Sub
End Class

Hasil Form3 (Data Buku) setelah dijalankan

Gambar 7. Hasil Form3 (Data Buku)


Kodingnya sebagai berikut :
Imports System.Data.OleDb
Public Class Form3
Sub Kosong()
TextBox1.Clear()
ComboBox1.Text = ""
TextBox2.Clear()
TextBox3.Clear()
TextBox4.Clear()
TextBox5.Clear()
TextBox6.Clear()
TextBox7.Clear()
TextBox8.Clear()
TextBox1.Focus()
End Sub
Sub Isi()
ComboBox1.Text = ""
TextBox2.Clear()
TextBox3.Clear()
TextBox4.Clear()
TextBox5.Clear()
TextBox6.Clear()
TextBox7.Clear()
ComboBox1.Focus()
End Sub

Sub TampilBuku()
da = New OleDbDataAdapter("Select * From Buku", Conn)
ds = New DataSet
ds.Clear()
da.Fill(ds, "Buku")
DataGridView1.DataSource = ds.Tables("Buku")
DataGridView1.Refresh()
End Sub
Sub TampilJenis()
cmd = New OleDbCommand("Select KodeJenis From Jenis", Conn)
rd = cmd.ExecuteReader
Do While rd.Read
ComboBox1.Items.Add(rd.Item(0))
Loop
End Sub
Sub AturGrid()
DataGridView1.Columns(0).Width
DataGridView1.Columns(1).Width
DataGridView1.Columns(2).Width
DataGridView1.Columns(3).Width
DataGridView1.Columns(4).Width
DataGridView1.Columns(5).Width
DataGridView1.Columns(6).Width
DataGridView1.Columns(7).Width

=
=
=
=
=
=
=
=

60
50
300
100
100
100
100
300

DataGridView1.Columns(0).HeaderText
DataGridView1.Columns(1).HeaderText
DataGridView1.Columns(2).HeaderText
DataGridView1.Columns(3).HeaderText
DataGridView1.Columns(4).HeaderText
DataGridView1.Columns(5).HeaderText
DataGridView1.Columns(6).HeaderText
DataGridView1.Columns(7).HeaderText
End Sub

=
=
=
=
=
=
=
=

"KODE BARANG"
"KODE JENIS"
"JUDUL"
"PENGARANG"
"PENERBIT"
"JUMLAH"
"HARGA"
"DESKRIPSI"

Private Sub Form2_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles


Me.Load
Call Koneksi()
Call TampilJenis()
Call TampilBuku()
Call Kosong()
Call AturGrid()
End Sub
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
TextBox1.MaxLength = 3
If e.KeyChar = Chr(13) Then
cmd = New OleDbCommand("Select * From Buku where KodeBuku='" & TextBox1.Text &
"'", Conn)
rd = cmd.ExecuteReader
rd.Read()
If rd.HasRows = True Then
ComboBox1.Text = rd.Item(1)
TextBox2.Text = rd.Item(2)
TextBox3.Text = rd.Item(3)
TextBox4.Text = rd.Item(4)
TextBox5.Text = rd.Item(5)
TextBox6.Text = rd.Item(6)
TextBox7.Text = rd.Item(7)
TextBox2.Focus()
Else
Call Isi()
ComboBox1.Focus()
End If
End If
End Sub

Private Sub TextBox2_KeyPress(ByVal sender As Object, ByVal e As


System.Windows.Forms.KeyPressEventArgs) Handles TextBox2.KeyPress
TextBox2.MaxLength = 50
If e.KeyChar = Chr(13) Then
TextBox2.Text = UCase(TextBox2.Text)
TextBox3.Focus()
End If
End Sub
Private Sub TextBox3_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles TextBox3.KeyPress
If e.KeyChar = Chr(13) Then
TextBox3.Text = UCase(TextBox3.Text)
TextBox4.Focus()
End If
End Sub
Private Sub ComboBox1_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles ComboBox1.KeyPress
If e.KeyChar = Chr(13) Then TextBox2.Focus()
End Sub
Private Sub DataGridView1_CellContentClick(ByVal sender As Object, ByVal e As
System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
Dim i As Integer
i = Me.DataGridView1.CurrentRow.Index
With DataGridView1.Rows.Item(i)
Me.TextBox1.Text = .Cells(0).Value
Me.ComboBox1.Text = .Cells(1).Value
Me.TextBox2.Text = .Cells(2).Value
Me.TextBox3.Text = .Cells(3).Value
Me.TextBox4.Text = .Cells(4).Value
Me.TextBox5.Text = .Cells(5).Value
Me.TextBox6.Text = .Cells(6).Value
Me.TextBox7.Text = .Cells(7).Value
End With
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button1.Click
If TextBox1.Text = "" Or ComboBox1.Text = "" Or TextBox2.Text = "" Or TextBox3.Text =
"" Or TextBox4.Text = "" Or TextBox5.Text = "" Or TextBox6.Text = "" Then
MsgBox("Data belum lengkap..!")
TextBox1.Focus()
Exit Sub
Else
cmd = New OleDbCommand("Select * From Buku where KodeBuku='" & TextBox1.Text &
"'", Conn)
rd = cmd.ExecuteReader
rd.Read()
If Not rd.HasRows Then
Dim Simpan As String = "insert into
Buku(KodeBuku,KodeJenis,Judul,Pengarang,Penerbit,JumlahBuku,Harga,Deskripsi)values " & _
"('" & TextBox1.Text & "','" & ComboBox1.Text & "','" & TextBox2.Text & "','"
& TextBox3.Text & "','" & TextBox4.Text & "','" & TextBox5.Text & "','" & TextBox6.Text &
"','" & TextBox7.Text & "')"
cmd = New OleDbCommand(Simpan, Conn)
cmd.ExecuteNonQuery()
MsgBox("Simpan data sukses...!", MsgBoxStyle.Information, "Perhatian")
End If
Call TampilBuku()
Call Kosong()
TextBox1.Focus()
End If
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles


Button2.Click
If TextBox1.Text = "" Then
MsgBox("Kode Buku belum diisi")
TextBox1.Focus()
Exit Sub
Else
Dim Ubah As String = "Update Buku set " & _
"KodeJenis='" & ComboBox1.Text & "'," & _
"Judul='" & TextBox2.Text & "'," & _
"Pengarang='" & TextBox3.Text & "'," & _
"Penerbit='" & TextBox4.Text & "'," & _
"JumlahBuku='" & TextBox5.Text & "'," & _
"Harga='" & TextBox6.Text & "'," & _
"Deskripsi='" & TextBox7.Text & "' " & _
"where KodeBuku='" & TextBox1.Text & "'"
cmd = New OleDbCommand(Ubah, Conn)
cmd.ExecuteNonQuery()
MsgBox("Ubah data sukses..!", MsgBoxStyle.Information, "Perhatian")
Call TampilBuku()
Call Kosong()
TextBox1.Focus()
End If
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button3.Click
If TextBox1.Text = "" Then
MsgBox("Kode Buku belum diisi")
TextBox1.Focus()
Exit Sub
Else
If MessageBox.Show("Yakin akan menghapus Data Buku " & TextBox1.Text & " ?", "",
MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.Yes Then
cmd = New OleDbCommand("Delete * From Buku where KodeBuku='" & TextBox1.Text &
"'", Conn)
cmd.ExecuteNonQuery()
Call Kosong()
Call TampilBuku()
Else
Call Kosong()
End If
End If
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button4.Click
Call Kosong()
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles ComboBox1.SelectedIndexChanged
cmd = New OleDbCommand("Select * From Jenis where KodeJenis='" & ComboBox1.Text & "'",
Conn)
rd = cmd.ExecuteReader
rd.Read()
If rd.HasRows = True Then
TextBox8.Text = rd.Item(1)
Else
MsgBox("Kode jenis ini tidak terdaftar")
End If
End Sub
Private Sub TextBox4_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles TextBox4.KeyPress
If e.KeyChar = Chr(13) Then
TextBox4.Text = UCase(TextBox4.Text)
TextBox5.Focus()
End If
End Sub

Private Sub TextBox5_KeyPress(ByVal sender As Object, ByVal e As


System.Windows.Forms.KeyPressEventArgs) Handles TextBox5.KeyPress
If e.KeyChar = Chr(13) Then TextBox6.Focus()
End Sub
Private Sub TextBox6_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles TextBox6.KeyPress
If e.KeyChar = Chr(13) Then
TextBox6.Text = UCase(TextBox6.Text)
TextBox7.Focus()
End If
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button5.Click
Me.Close()
End Sub
Private Sub TextBox9_TextChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles TextBox9.TextChanged
cmd = New OleDbCommand("Select * From Buku where Judul like '%" & TextBox9.Text &
"%'", Conn)
rd = cmd.ExecuteReader
rd.Read()
If rd.HasRows Then
da = New OleDbDataAdapter("Select * From Buku where Judul like '%" & TextBox9.Text
& "%'", Conn)
ds = New DataSet
da.Fill(ds, "Dapat")
DataGridView1.DataSource = ds.Tables("Dapat")
DataGridView1.ReadOnly = True
Else
MsgBox("Data tidak ditemukan")
End If
End Sub
Private Sub TextBox7_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles TextBox7.KeyPress
TextBox6.MaxLength = 225
If e.KeyChar = Chr(13) Then
TextBox7.Text = UCase(TextBox7.Text)
Button1.Focus()
End If
End Sub
End Class

Hasil Form4 (Transaksi Penjualan Buku Komputer) setelah dijalankan

Gambar 8. Hasil Form4 (Transaksi Penjualan)


Kodingnya sebagai berikut :
Imports System.Data.OleDb
Public Class Form4
Sub Kosong()
TextBox4.Clear()
TextBox5.Clear()
TextBox6.Clear()
TextBox7.Clear()
TextBox8.Clear()
TextBox4.Focus()
End Sub
Sub TidakAktif()
TextBox1.Enabled = False
TextBox2.Enabled = False
TextBox3.Enabled = False
End Sub
Sub KolomBaru()
DataGridView1.Columns.Add("Kode", "KODE BUKU")
DataGridView1.Columns.Add("Nama", "NAMA BUKU")
DataGridView1.Columns.Add("Harga", "HARGA")
DataGridView1.Columns.Add("Jumlah", "QTY")
DataGridView1.Columns.Add("Total", "SUB TOTAL")
Call LebarKolom()
End Sub
Sub LebarKolom()
DataGridView1.Columns(0).Width
DataGridView1.Columns(1).Width
DataGridView1.Columns(2).Width
DataGridView1.Columns(3).Width
DataGridView1.Columns(4).Width
End Sub

=
=
=
=
=

50
300
60
40
80

Private Sub Otomatis()


cmd = New OleDbCommand("Select * from Transaksi where NoFaktur in (select
max(NoFaktur) from Transaksi) order by NoFaktur desc", Conn)
Dim urutan As String
Dim hitung As Long
rd = cmd.ExecuteReader
rd.Read()
If Not rd.HasRows Then
urutan = "TR" + Format(Now, "yyMMdd") + "001"
Else
If Microsoft.VisualBasic.Mid(rd.GetString(0), 3, 6) <> Format(Now, "yyMMdd") Then
urutan = "TR" + Format(Now, "yyMMdd") + "001"
Else
hitung = Microsoft.VisualBasic.Right(rd.GetString(0), 2) + 1
urutan = "TR" + Format(Now, "yyMMdd") + Microsoft.VisualBasic.Right("000" &
hitung, 3)
End If
End If
TextBox1.Text = urutan
End Sub
Sub TampilBuku()
cmd = New OleDbCommand("Select KodeBuku From Buku", Conn)
rd = cmd.ExecuteReader
End Sub
Private Sub Form4_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles
Me.Activated
Call Otomatis()
TextBox2.Text = Today
TextBox3.Text = TimeOfDay
End Sub
Private Sub Form4_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles
Me.Load
Call Koneksi()
Call KolomBaru()
Call Kosong()
Call TidakAktif()
Call TampilBuku()
End Sub
Sub TotalItem()
Dim HitungItem As Integer = 0
For I As Integer = 0 To DataGridView1.Rows.Count - 1
HitungItem = HitungItem + Val(DataGridView1.Rows(I).Cells(3).Value)
TextBox9.Text = HitungItem
Next
End Sub
Sub TotalHarga()
Dim HitungHarga As Integer = 0
For I As Integer = 0 To DataGridView1.Rows.Count - 1
HitungHarga = HitungHarga + Val(DataGridView1.Rows(I).Cells(4).Value)
TextBox6.Text = HitungHarga
Label10.Text = HitungHarga
Next
End Sub
Sub HapusBaris()
On Error Resume Next
Dim Baris As Integer = DataGridView1.CurrentCell.RowIndex
DataGridView1.Rows(baris).Cells(0).Value = ""
Chr(30)
End Sub
Private Sub DataGridView1_KeyDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyEventArgs)
If e.KeyCode = Keys.Up Then
DataGridView1.CurrentCell = DataGridView1.Rows(0).Cells(3)
End If
End Sub

Private Sub DataGridView1_KeyPress(ByVal sender As Object, ByVal e As


System.Windows.Forms.KeyPressEventArgs)
On Error Resume Next
If e.KeyChar = Chr(27) Then
DataGridView1.Rows.RemoveAt(DataGridView1.CurrentCell.RowIndex)
Call TotalItem()
Call TotalHarga()
TextBox7.Clear()
TextBox8.Text = ""
End If
End Sub
Private Sub TextBox7_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles TextBox7.KeyPress
If e.KeyChar = Chr(13) Then
If Val(TextBox7.Text) < Val(TextBox6.Text) Then
MsgBox("Pembayaran kurang")
TextBox8.Text = ""
TextBox7.Focus()
Exit Sub
ElseIf Val(TextBox7.Text) = Val(TextBox6.Text) Then
TextBox8.Text = 0
Button2.Focus()
Else
TextBox8.Text = Val(TextBox7.Text) - Val(TextBox6.Text)
Button2.Focus()
End If
End If
If Not ((e.KeyChar >= "0" And e.KeyChar <= "9") Or e.KeyChar = vbBack) Then
e.Handled() = True
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button2.Click
Call Kosong()
DataGridView1.Columns.Clear()
Call KolomBaru()
DataGridView1.Focus()
End Sub
Private Sub DataGridView1_EditingControlShowing(ByVal sender As Object, ByVal e As
System.Windows.Forms.DataGridViewEditingControlShowingEventArgs)
If e.Control.GetType.ToString() =
"System.Windows.Forms.DataGridViewTextBoxEditingControl" Then
Dim c As DataGridViewTextBoxEditingControl = CType(e.Control,
DataGridViewTextBoxEditingControl)
RemoveHandler c.KeyPress, AddressOf GridViewTextBox_KeyPress
AddHandler c.KeyPress, AddressOf GridViewTextBox_KeyPress
End If
End Sub
Private Sub GridViewTextBox_KeyPress(ByVal sender As Object, ByVal ex As
KeyPressEventArgs)
If DataGridView1.CurrentCell.ColumnIndex = 3 Then
If ((Asc(ex.KeyChar) < 48 Or Asc(ex.KeyChar) > 57) And Asc(ex.KeyChar) <> 8) Then
ex.Handled = True
End If
End If
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles


Button1.Click
If TextBox1.Text = "" Or TextBox2.Text = "" Or TextBox3.Text = "" Or TextBox4.Text =
"" Or TextBox5.Text = "" Or TextBox6.Text = "" Or TextBox7.Text = "" Or TextBox8.Text = ""
Then
MsgBox("Data belum lengkap, tidak ada transaksi atau pembayaran masih kosong")
Exit Sub
End If
'Simpan ke tabel Transaksi
Dim SimpanTransaksi As String = "Insert into
Transaksi(NoFaktur,TglFaktur,Pukul,NamaPembeli,NoTelp,Total,Dibayar,Kembali,Item) values " & _
"('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" &
TextBox4.Text & "','" & TextBox5.Text & "','" & TextBox6.Text & "','" & TextBox7.Text & "','"
& TextBox8.Text & "','" & TextBox9.Text & "')"
cmd = New OleDbCommand(SimpanTransaksi, Conn)
cmd.ExecuteNonQuery()
For baris As Integer = 0 To DataGridView1.Rows.Count - 2
'Simpan ke tabel DetailTransaksi
Dim SimpanDetailTransaksi As String = "Insert into DetailTransaksi
(NoFaktur,KodeBuku,Judul,HargaJual,Jumlah,SubTotal) values " & _
"('" & TextBox1.Text & "','" & DataGridView1.Rows(baris).Cells(0).Value & "','" &
DataGridView1.Rows(baris).Cells(1).Value & "','" & DataGridView1.Rows(baris).Cells(2).Value &
"','" & DataGridView1.Rows(baris).Cells(3).Value & "','" &
DataGridView1.Rows(baris).Cells(4).Value & "')"
cmd = New OleDbCommand(SimpanDetailTransaksi, Conn)
cmd.ExecuteNonQuery()
'Kurangi stok Buku
cmd = New OleDbCommand("select * from Buku where KodeBuku='" &
DataGridView1.Rows(baris).Cells(0).Value & "'", Conn)
rd = cmd.ExecuteReader
rd.Read()
If rd.HasRows Then
Dim KurangiStok As String = "update Buku set JumlahBuku= '" & rd.Item(5) DataGridView1.Rows(baris).Cells(3).Value & "' where KodeBuku='" &
DataGridView1.Rows(baris).Cells(0).Value & "'"
cmd = New OleDbCommand(KurangiStok, Conn)
cmd.ExecuteNonQuery()
End If
Next baris
DataGridView1.Columns.Clear()
Call KolomBaru()
Call Otomatis()
Call Kosong()
End Sub
Sub kena(ByVal myGrid As DataGrid)
myGrid.CurrentCell = New DataGridCell(1, 1)
End Sub

Private Sub DataGridView1_CellEndEdit1(ByVal sender As Object, ByVal e As


System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellEndEdit
If e.ColumnIndex = 0 Then
cmd = New OleDbCommand("select * from Buku where KodeBuku='" &
DataGridView1.Rows(e.RowIndex).Cells(0).Value & "'", Conn)
rd = cmd.ExecuteReader
rd.Read()
If rd.HasRows Then
DataGridView1.Rows(e.RowIndex).Cells(1).Value = rd.Item(2)
DataGridView1.Rows(e.RowIndex).Cells(2).Value = rd.Item(6)
DataGridView1.Rows(e.RowIndex).Cells(3).Value = 1
DataGridView1.Rows(e.RowIndex).Cells(4).Value =
DataGridView1.Rows(e.RowIndex).Cells(2).Value * DataGridView1.Rows(e.RowIndex).Cells(3).Value
Call TotalItem()
Call TotalHarga()
Else
MsgBox("Kode buku tidak terdaftar")
End If
End If
If e.ColumnIndex = 3 Then
cmd = New OleDbCommand("select * from Buku where KodeBuku='" &
DataGridView1.Rows(e.RowIndex).Cells(0).Value & "'", Conn)
rd = cmd.ExecuteReader
rd.Read()
If rd.HasRows Then
If DataGridView1.Rows(e.RowIndex).Cells(3).Value > rd.Item(5) Then
MsgBox("Stok Buku hanya ada " & rd.Item(5) & "")
DataGridView1.Rows(e.RowIndex).Cells(3).Value = 1
DataGridView1.Rows(e.RowIndex).Cells(4).Value =
DataGridView1.Rows(e.RowIndex).Cells(2).Value * DataGridView1.Rows(e.RowIndex).Cells(3).Value
Call TotalItem()
Call TotalHarga()
Else
DataGridView1.Rows(e.RowIndex).Cells(4).Value =
DataGridView1.Rows(e.RowIndex).Cells(2).Value * DataGridView1.Rows(e.RowIndex).Cells(3).Value
Call TotalItem()
Call TotalHarga()
End If
End If
DataGridView1.CurrentCell = DataGridView1.Rows(0).Cells(0)
End If
End Sub
Private Sub TextBox4_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles TextBox4.KeyPress
If e.KeyChar = Chr(13) Then
TextBox4.Text = UCase(TextBox4.Text)
TextBox5.Focus()
End If
End Sub
Private Sub TextBox5_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles TextBox5.KeyPress
If e.KeyChar = Chr(13) Then
TextBox5.Text = UCase(TextBox5.Text)
DataGridView1.Focus()
End If
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button4.Click
Form3.ShowDialog()
End Sub
End Class

Besambung ke Laporan
Transaksi .......