Aplikasi Penjualan Buku Menggunakan Vb.
Net dan Access
Step 2 : Membuat Form Data Buku
A.
Form Data Buku
Tambah kan
form dengan cara klik menu bar Project > AddWindowsForm > Rename Form1.vb
menjadi FormData.vb) langkah-langkahnya seperti pada contoh gambar dibawah ini
:
Lalu rancang lah FormData.vb seperti pada gambar berikut :
Property Setting :
Object
|
Name
|
Text
|
Form 1
|
FormData
|
Data Buku
Komputer
|
Label1
|
Label
1.Text
|
Kode
Buku
|
Label2
|
Label
2.Text
|
Judul
|
Label3
|
Label
3.Text
|
Pengarang
|
Label4
|
Label
4.Text
|
Penerbit
|
Label5
|
Label
5.Text
|
Jumlah
Buku
|
Label6
|
Label
6.Text
|
Jenis
Buku
|
Label7
|
Label
7.Text
|
Harga
|
TextBox
1
|
TextBox
1.Text
|
-
|
TextBox
2
|
TextBox
2.Text
|
-
|
TextBox
3
|
TextBox
3.Text
|
-
|
TextBox
4
|
TextBox
4.Text
|
-
|
TextBox
5
|
TextBox
5.Text
|
-
|
TextBox
6
|
TextBox
6.Text
|
-
|
TextBox
7
|
TextBox
7.Text
|
-
|
TextBox
8
|
TextBox
8.Text
|
-
|
Button
1
|
Button
1
|
&Simpan
|
Button
2
|
Button
2
|
&Ubah
|
Button
3
|
Button
3
|
&Hapus
|
Button
4
|
Button
4
|
&Batal
|
Button
5
|
Button
5
|
&Tutup
|
GroupBox1
|
GroupBox1
|
Deskripsi
|
DataGridView1
|
DataGridView1
|
-
|
Ketikan
koding pada masing-masing object seperti kode berikut :
Imports System.Data.OleDb
Public Class FormData
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 = 60
DataGridView1.Columns(1).Width = 50
DataGridView1.Columns(2).Width = 300
DataGridView1.Columns(3).Width = 100
DataGridView1.Columns(4).Width = 100
DataGridView1.Columns(5).Width = 100
DataGridView1.Columns(6).Width = 100
DataGridView1.Columns(7).Width = 300
DataGridView1.Columns(0).HeaderText = "KODE
BARANG"
DataGridView1.Columns(1).HeaderText = "KODE
JENIS"
DataGridView1.Columns(2).HeaderText = "JUDUL"
DataGridView1.Columns(3).HeaderText = "PENGARANG"
DataGridView1.Columns(4).HeaderText
= "PENERBIT"
DataGridView1.Columns(5).HeaderText = "JUMLAH"
DataGridView1.Columns(6).HeaderText = "HARGA"
DataGridView1.Columns(7).HeaderText = "DESKRIPSI"
End Sub
Private Sub
Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
MyBase.Load
Call Koneksi()
Call TampilJenis()
Call TampilBuku()
Call Kosong()
Call AturGrid()
End Sub
Private Sub
TextBox1_KeyPress(ByVal sender As System.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 System.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 System.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 System.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 System.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,Jumlah,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
Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button5.Click
Me.Close()
End Sub
Private Sub
TextBox4_KeyPress(ByVal sender As System.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
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
TextBox5_KeyPress(ByVal sender As System.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 System.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
TextBox7_KeyPress(ByVal sender As System.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
B.
Tabel Buku
Tambah kan tabel Buku pada database Buku.accdb
yang sudah dibuat pada Step 1 : Aplikasi Penjualan Buku Menggunakan VB. Net& Access.
Struktur Tabel Buku :
Field
|
Type
|
Size
|
Keterangan
|
KodeBuku
|
Text
|
10
|
PK
(Primary Key)
|
KodeJenis
|
Text
|
5
|
FK
(Foreign Key)
|
Judul
|
Text
|
200
|
|
Pengarang
|
Text
|
100
|
|
Penerbit
|
Text
|
100
|
|
Jumlah
|
Number
|
Long Int
|
|
Harga
|
Number
|
Long Int
|
|
Deskripsi
|
Text
|
300
|
0 komentar:
Post a Comment