SlideShare a Scribd company logo
Teknik Informatika Universitas Serambi Mekkah
Modul Dasar Pemrograman III (VB.Net) Hal. 1
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
Field Type Size Keterangan
KodeJenis Text 2 Primary Key (PK)
Jenis Text 50
Nama Tabel : Buku
Field Type Size Keterangan
KodeBuku Text 3 Primary Key (PK)
KodeJenis Text 2 Foreign Key (FK)
Judul Text 100
Pengarang Text 50
Penerbit Text 50
Jumlah Number
Harga Number
Deskripsi Text 200
Nama Tabel : Transaksi
Field Type Size Keterangan
NoFaktur Text 11 Primary Key (PK)
TglFaktur Date/Time
Pukul Date/Time
NamaPembeli Text 50
NoTelp Text 12
Total Number
Dibayar Number
Kembali Number
Item Number
Nama Tabel : DetailTransaksi
Field Type Size Keterangan
NoFaktur Text 11
KodeBuku Text 3
Judul Text 150
Jumlah Number
HargaJual Number
SubTotal Number
Teknik Informatika Universitas Serambi Mekkah
Modul Dasar Pemrograman III (VB.Net) Hal. 2
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 :
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
MenuStrip1
StatusStrip1
GroupBox1
Button
1
Teknik Informatika Universitas Serambi Mekkah
Modul Dasar Pemrograman III (VB.Net) Hal. 3
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
Gambar 3. Rancangan Form Data Jenis Buku
TextBox3
TextBox1
TextBox2
Button1
Button2
Button3
Button4
DataGridView1
Teknik Informatika Universitas Serambi Mekkah
Modul Dasar Pemrograman III (VB.Net) Hal. 4
Gambar 4. Rancangan Form Data Buku
Gambar 5. Rancangan Form Transaksi Penjualan Buku
DataGridView1
TextBox2
TextBox3
TextBox4
TextBox5
TextBox8
TextBox7
TextBox9
Button5
Button4
Button3
Button2
Button1
ComboBox1
TextBox6
TextBox1
TextBox1
TextBox2
TextBox3
TextBox4
TextBox5
Button1
Button2
Button3
TextBox6
Label10
TextBox7
TextBox8
TextBox9
DataGridView1
Button4
Teknik Informatika Universitas Serambi Mekkah
Modul Dasar Pemrograman III (VB.Net) Hal. 5
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
Teknik Informatika Universitas Serambi Mekkah
Modul Dasar Pemrograman III (VB.Net) Hal. 6
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
Teknik Informatika Universitas Serambi Mekkah
Modul Dasar Pemrograman III (VB.Net) Hal. 7
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")
Teknik Informatika Universitas Serambi Mekkah
Modul Dasar Pemrograman III (VB.Net) Hal. 8
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
Teknik Informatika Universitas Serambi Mekkah
Modul Dasar Pemrograman III (VB.Net) Hal. 9
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 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
Teknik Informatika Universitas Serambi Mekkah
Modul Dasar Pemrograman III (VB.Net) Hal. 10
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
Teknik Informatika Universitas Serambi Mekkah
Modul Dasar Pemrograman III (VB.Net) Hal. 11
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
Teknik Informatika Universitas Serambi Mekkah
Modul Dasar Pemrograman III (VB.Net) Hal. 12
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
Teknik Informatika Universitas Serambi Mekkah
Modul Dasar Pemrograman III (VB.Net) Hal. 13
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 = 50
DataGridView1.Columns(1).Width = 300
DataGridView1.Columns(2).Width = 60
DataGridView1.Columns(3).Width = 40
DataGridView1.Columns(4).Width = 80
End Sub
Teknik Informatika Universitas Serambi Mekkah
Modul Dasar Pemrograman III (VB.Net) Hal. 14
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
Teknik Informatika Universitas Serambi Mekkah
Modul Dasar Pemrograman III (VB.Net) Hal. 15
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
Teknik Informatika Universitas Serambi Mekkah
Modul Dasar Pemrograman III (VB.Net) Hal. 16
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
Teknik Informatika Universitas Serambi Mekkah
Modul Dasar Pemrograman III (VB.Net) Hal. 17
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 .......

More Related Content

What's hot

Windows Form - Lec12 (Workshop on C# Programming: Learn to Build)
Windows Form - Lec12 (Workshop on C# Programming: Learn to Build)Windows Form - Lec12 (Workshop on C# Programming: Learn to Build)
Windows Form - Lec12 (Workshop on C# Programming: Learn to Build)
Jannat Ruma
 
Londroid Android Home Screen Widgets
Londroid Android Home Screen WidgetsLondroid Android Home Screen Widgets
Londroid Android Home Screen Widgets
Richard Hyndman
 
Java script frame window
Java script frame windowJava script frame window
Java script frame window
H K
 
Advance JFACE
Advance JFACEAdvance JFACE
Advance JFACE
Rahul Shukla
 
Android session 3
Android session 3Android session 3
Android session 3
Ahesanali Suthar
 
Ajp notes-chapter-01
Ajp notes-chapter-01Ajp notes-chapter-01
Ajp notes-chapter-01
Ankit Dubey
 
SQL express course for begginers
   SQL express course for begginers   SQL express course for begginers
SQL express course for begginers
Dmytro Hvozdov
 
Android session 2
Android session 2Android session 2
Android session 2
Ahesanali Suthar
 
Android session 1
Android session 1Android session 1
Android session 1
Ahesanali Suthar
 
Chapter ii c#(building a user interface)
Chapter ii c#(building a user interface)Chapter ii c#(building a user interface)
Chapter ii c#(building a user interface)
Chhom Karath
 

What's hot (10)

Windows Form - Lec12 (Workshop on C# Programming: Learn to Build)
Windows Form - Lec12 (Workshop on C# Programming: Learn to Build)Windows Form - Lec12 (Workshop on C# Programming: Learn to Build)
Windows Form - Lec12 (Workshop on C# Programming: Learn to Build)
 
Londroid Android Home Screen Widgets
Londroid Android Home Screen WidgetsLondroid Android Home Screen Widgets
Londroid Android Home Screen Widgets
 
Java script frame window
Java script frame windowJava script frame window
Java script frame window
 
Advance JFACE
Advance JFACEAdvance JFACE
Advance JFACE
 
Android session 3
Android session 3Android session 3
Android session 3
 
Ajp notes-chapter-01
Ajp notes-chapter-01Ajp notes-chapter-01
Ajp notes-chapter-01
 
SQL express course for begginers
   SQL express course for begginers   SQL express course for begginers
SQL express course for begginers
 
Android session 2
Android session 2Android session 2
Android session 2
 
Android session 1
Android session 1Android session 1
Android session 1
 
Chapter ii c#(building a user interface)
Chapter ii c#(building a user interface)Chapter ii c#(building a user interface)
Chapter ii c#(building a user interface)
 

Viewers also liked

Makalah Aplikasi Data Penjualan Menggunakan Visual Basic 6.0
Makalah Aplikasi Data Penjualan Menggunakan Visual Basic 6.0Makalah Aplikasi Data Penjualan Menggunakan Visual Basic 6.0
Makalah Aplikasi Data Penjualan Menggunakan Visual Basic 6.0
Marlinda
 
APLIKASI DATA BARANG DAN DATA SUPPLIER MENGGUNAKAN VISUAL BASIC 6.0
APLIKASI DATA BARANG DAN DATA SUPPLIER MENGGUNAKAN VISUAL BASIC 6.0APLIKASI DATA BARANG DAN DATA SUPPLIER MENGGUNAKAN VISUAL BASIC 6.0
APLIKASI DATA BARANG DAN DATA SUPPLIER MENGGUNAKAN VISUAL BASIC 6.0
Marlinda
 
Pengenalan ms word
Pengenalan ms wordPengenalan ms word
Pengenalan ms word
Hendra Nugraha
 
Dasar operasi microsoft word 2007 dan penyuntingan dokumen
Dasar operasi microsoft word 2007 dan penyuntingan dokumenDasar operasi microsoft word 2007 dan penyuntingan dokumen
Dasar operasi microsoft word 2007 dan penyuntingan dokumenKhairul Muttaqin
 
cara-cara untuk pemula ms word 2007
cara-cara untuk pemula ms word 2007 cara-cara untuk pemula ms word 2007
cara-cara untuk pemula ms word 2007
Rico Hidayat
 
REFERENCIAS WORD
REFERENCIAS WORDREFERENCIAS WORD
REFERENCIAS WORD
compuent
 
Pengenalan Microsoft Excel
Pengenalan Microsoft ExcelPengenalan Microsoft Excel
Pengenalan Microsoft Excel
Made Aditya
 
Learning VB.NET Programming Concepts
Learning VB.NET Programming ConceptsLearning VB.NET Programming Concepts
Learning VB.NET Programming Concepts
guest25d6e3
 
Internet, komputer dan windows
Internet, komputer dan windowsInternet, komputer dan windows
Internet, komputer dan windows
Khairul Muttaqin
 
Panduan excel 2007 (1)
Panduan excel 2007 (1)Panduan excel 2007 (1)
Panduan excel 2007 (1)
Yudi Chou
 
100174975 modul-ms-access-2010
100174975 modul-ms-access-2010100174975 modul-ms-access-2010
100174975 modul-ms-access-2010
sutrisno sukarno
 
66645491 modul-dan-panduan-belajar-microsoft-word-2007
66645491 modul-dan-panduan-belajar-microsoft-word-200766645491 modul-dan-panduan-belajar-microsoft-word-2007
66645491 modul-dan-panduan-belajar-microsoft-word-2007
made-deo
 
Asas Ms Excel
Asas Ms ExcelAsas Ms Excel
Asas Ms Excel
Ts Norazah Abdullah
 
Modul microsoft acces 2010
Modul microsoft acces 2010Modul microsoft acces 2010
Modul microsoft acces 2010
Bengkulu University
 
Aplikasi penjualan pulsa
Aplikasi penjualan pulsaAplikasi penjualan pulsa
Aplikasi penjualan pulsa
helvypricilia
 
Latihan access
Latihan accessLatihan access
Latihan access
Odi Sumantri
 
Ms. access 2007 Oleh Yusuf Virmansyah (SMK Sejahtera)
Ms. access 2007 Oleh Yusuf Virmansyah (SMK Sejahtera)Ms. access 2007 Oleh Yusuf Virmansyah (SMK Sejahtera)
Ms. access 2007 Oleh Yusuf Virmansyah (SMK Sejahtera)yusuv
 
MS POWER POINT 2007 BAB1
MS POWER POINT 2007 BAB1MS POWER POINT 2007 BAB1
MS POWER POINT 2007 BAB1
nittoag
 
Belajar power point 2007
Belajar power point 2007 Belajar power point 2007
Belajar power point 2007
basukiwlahar
 
Modul word2007 Komputer Terapan
Modul word2007 Komputer TerapanModul word2007 Komputer Terapan
Modul word2007 Komputer Terapan
Yayan Adrianova Eka Tuah,S.Kom
 

Viewers also liked (20)

Makalah Aplikasi Data Penjualan Menggunakan Visual Basic 6.0
Makalah Aplikasi Data Penjualan Menggunakan Visual Basic 6.0Makalah Aplikasi Data Penjualan Menggunakan Visual Basic 6.0
Makalah Aplikasi Data Penjualan Menggunakan Visual Basic 6.0
 
APLIKASI DATA BARANG DAN DATA SUPPLIER MENGGUNAKAN VISUAL BASIC 6.0
APLIKASI DATA BARANG DAN DATA SUPPLIER MENGGUNAKAN VISUAL BASIC 6.0APLIKASI DATA BARANG DAN DATA SUPPLIER MENGGUNAKAN VISUAL BASIC 6.0
APLIKASI DATA BARANG DAN DATA SUPPLIER MENGGUNAKAN VISUAL BASIC 6.0
 
Pengenalan ms word
Pengenalan ms wordPengenalan ms word
Pengenalan ms word
 
Dasar operasi microsoft word 2007 dan penyuntingan dokumen
Dasar operasi microsoft word 2007 dan penyuntingan dokumenDasar operasi microsoft word 2007 dan penyuntingan dokumen
Dasar operasi microsoft word 2007 dan penyuntingan dokumen
 
cara-cara untuk pemula ms word 2007
cara-cara untuk pemula ms word 2007 cara-cara untuk pemula ms word 2007
cara-cara untuk pemula ms word 2007
 
REFERENCIAS WORD
REFERENCIAS WORDREFERENCIAS WORD
REFERENCIAS WORD
 
Pengenalan Microsoft Excel
Pengenalan Microsoft ExcelPengenalan Microsoft Excel
Pengenalan Microsoft Excel
 
Learning VB.NET Programming Concepts
Learning VB.NET Programming ConceptsLearning VB.NET Programming Concepts
Learning VB.NET Programming Concepts
 
Internet, komputer dan windows
Internet, komputer dan windowsInternet, komputer dan windows
Internet, komputer dan windows
 
Panduan excel 2007 (1)
Panduan excel 2007 (1)Panduan excel 2007 (1)
Panduan excel 2007 (1)
 
100174975 modul-ms-access-2010
100174975 modul-ms-access-2010100174975 modul-ms-access-2010
100174975 modul-ms-access-2010
 
66645491 modul-dan-panduan-belajar-microsoft-word-2007
66645491 modul-dan-panduan-belajar-microsoft-word-200766645491 modul-dan-panduan-belajar-microsoft-word-2007
66645491 modul-dan-panduan-belajar-microsoft-word-2007
 
Asas Ms Excel
Asas Ms ExcelAsas Ms Excel
Asas Ms Excel
 
Modul microsoft acces 2010
Modul microsoft acces 2010Modul microsoft acces 2010
Modul microsoft acces 2010
 
Aplikasi penjualan pulsa
Aplikasi penjualan pulsaAplikasi penjualan pulsa
Aplikasi penjualan pulsa
 
Latihan access
Latihan accessLatihan access
Latihan access
 
Ms. access 2007 Oleh Yusuf Virmansyah (SMK Sejahtera)
Ms. access 2007 Oleh Yusuf Virmansyah (SMK Sejahtera)Ms. access 2007 Oleh Yusuf Virmansyah (SMK Sejahtera)
Ms. access 2007 Oleh Yusuf Virmansyah (SMK Sejahtera)
 
MS POWER POINT 2007 BAB1
MS POWER POINT 2007 BAB1MS POWER POINT 2007 BAB1
MS POWER POINT 2007 BAB1
 
Belajar power point 2007
Belajar power point 2007 Belajar power point 2007
Belajar power point 2007
 
Modul word2007 Komputer Terapan
Modul word2007 Komputer TerapanModul word2007 Komputer Terapan
Modul word2007 Komputer Terapan
 

Similar to Membuat aplikasi penjualan buku sederhana

Inventory management
Inventory managementInventory management
Inventory management
Rajeev Sharan
 
โครงการ 5 บท
โครงการ 5 บทโครงการ 5 บท
โครงการ 5 บท
MareenaHahngeh
 
โครงการ 5 บท
โครงการ 5 บทโครงการ 5 บท
โครงการ 5 บท
MareenaHahngeh
 
Aplikasi rawat-inap-vbnet
Aplikasi rawat-inap-vbnetAplikasi rawat-inap-vbnet
Aplikasi rawat-inap-vbnet
Diaz Alfahrezy
 
Ficha tecnica
Ficha tecnicaFicha tecnica
Ficha tecnica
guest6473b8
 
please code in c#- please note that im a complete beginner- northwind.docx
please code in c#- please note that im a complete beginner-  northwind.docxplease code in c#- please note that im a complete beginner-  northwind.docx
please code in c#- please note that im a complete beginner- northwind.docx
AustinaGRPaigey
 
VB net lab.pdf
VB net lab.pdfVB net lab.pdf
VB net lab.pdf
Prof. Dr. K. Adisesha
 
CRUD VB2010
CRUD VB2010CRUD VB2010
CRUD VB2010
Achmad Sidik
 
Database connectivity with data reader by varun tiwari
Database connectivity with data reader by varun tiwariDatabase connectivity with data reader by varun tiwari
PROGRAMMING USING C#.NET SARASWATHI RAMALINGAM
PROGRAMMING USING C#.NET SARASWATHI RAMALINGAMPROGRAMMING USING C#.NET SARASWATHI RAMALINGAM
PROGRAMMING USING C#.NET SARASWATHI RAMALINGAM
SaraswathiRamalingam
 
Kode vb.net
Kode vb.netKode vb.net
Kode vb.net
Azki Nabidin
 
Kode vb.net
Kode vb.netKode vb.net
Kode vb.net
Azki Nabidin
 
VB Dot net
VB Dot net VB Dot net
VB Dot net
Akber Khowaja
 
Project: Call Center Management
Project: Call Center ManagementProject: Call Center Management
Project: Call Center Management
pritamkumar
 
19.Advanced Visual Basic Lab.pdf
19.Advanced Visual Basic Lab.pdf19.Advanced Visual Basic Lab.pdf
19.Advanced Visual Basic Lab.pdf
virox10x
 
Ditec esoft C# project
Ditec esoft C# project Ditec esoft C# project
Ditec esoft C# project
K.K.T Madhusanka
 
Ditec esoft C# project
Ditec esoft C# projectDitec esoft C# project
Ditec esoft C# project
K.K.T Madhusanka
 
Correction s+ rie_vb
Correction s+ rie_vbCorrection s+ rie_vb
Correction s+ rie_vb
Marwane Lamouri
 
Vb Project ขั้นเทพ
Vb Project ขั้นเทพVb Project ขั้นเทพ
Vb Project ขั้นเทพ
Sinchai Lanon
 
Reservasi hotel
Reservasi hotelReservasi hotel
Reservasi hotel
dian pw
 

Similar to Membuat aplikasi penjualan buku sederhana (20)

Inventory management
Inventory managementInventory management
Inventory management
 
โครงการ 5 บท
โครงการ 5 บทโครงการ 5 บท
โครงการ 5 บท
 
โครงการ 5 บท
โครงการ 5 บทโครงการ 5 บท
โครงการ 5 บท
 
Aplikasi rawat-inap-vbnet
Aplikasi rawat-inap-vbnetAplikasi rawat-inap-vbnet
Aplikasi rawat-inap-vbnet
 
Ficha tecnica
Ficha tecnicaFicha tecnica
Ficha tecnica
 
please code in c#- please note that im a complete beginner- northwind.docx
please code in c#- please note that im a complete beginner-  northwind.docxplease code in c#- please note that im a complete beginner-  northwind.docx
please code in c#- please note that im a complete beginner- northwind.docx
 
VB net lab.pdf
VB net lab.pdfVB net lab.pdf
VB net lab.pdf
 
CRUD VB2010
CRUD VB2010CRUD VB2010
CRUD VB2010
 
Database connectivity with data reader by varun tiwari
Database connectivity with data reader by varun tiwariDatabase connectivity with data reader by varun tiwari
Database connectivity with data reader by varun tiwari
 
PROGRAMMING USING C#.NET SARASWATHI RAMALINGAM
PROGRAMMING USING C#.NET SARASWATHI RAMALINGAMPROGRAMMING USING C#.NET SARASWATHI RAMALINGAM
PROGRAMMING USING C#.NET SARASWATHI RAMALINGAM
 
Kode vb.net
Kode vb.netKode vb.net
Kode vb.net
 
Kode vb.net
Kode vb.netKode vb.net
Kode vb.net
 
VB Dot net
VB Dot net VB Dot net
VB Dot net
 
Project: Call Center Management
Project: Call Center ManagementProject: Call Center Management
Project: Call Center Management
 
19.Advanced Visual Basic Lab.pdf
19.Advanced Visual Basic Lab.pdf19.Advanced Visual Basic Lab.pdf
19.Advanced Visual Basic Lab.pdf
 
Ditec esoft C# project
Ditec esoft C# project Ditec esoft C# project
Ditec esoft C# project
 
Ditec esoft C# project
Ditec esoft C# projectDitec esoft C# project
Ditec esoft C# project
 
Correction s+ rie_vb
Correction s+ rie_vbCorrection s+ rie_vb
Correction s+ rie_vb
 
Vb Project ขั้นเทพ
Vb Project ขั้นเทพVb Project ขั้นเทพ
Vb Project ขั้นเทพ
 
Reservasi hotel
Reservasi hotelReservasi hotel
Reservasi hotel
 

Recently uploaded

HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
panagenda
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
DianaGray10
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
Matthew Sinclair
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
DianaGray10
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
Tomaz Bratanic
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
SOFTTECHHUB
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
Zilliz
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
名前 です男
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
Zilliz
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 
Infrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI modelsInfrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI models
Zilliz
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
Daiki Mogmet Ito
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
DianaGray10
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
shyamraj55
 

Recently uploaded (20)

HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
 
GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 
Infrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI modelsInfrastructure Challenges in Scaling RAG with Custom AI models
Infrastructure Challenges in Scaling RAG with Custom AI models
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
 

Membuat aplikasi penjualan buku sederhana

  • 1. Teknik Informatika Universitas Serambi Mekkah Modul Dasar Pemrograman III (VB.Net) Hal. 1 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 Field Type Size Keterangan KodeJenis Text 2 Primary Key (PK) Jenis Text 50 Nama Tabel : Buku Field Type Size Keterangan KodeBuku Text 3 Primary Key (PK) KodeJenis Text 2 Foreign Key (FK) Judul Text 100 Pengarang Text 50 Penerbit Text 50 Jumlah Number Harga Number Deskripsi Text 200 Nama Tabel : Transaksi Field Type Size Keterangan NoFaktur Text 11 Primary Key (PK) TglFaktur Date/Time Pukul Date/Time NamaPembeli Text 50 NoTelp Text 12 Total Number Dibayar Number Kembali Number Item Number Nama Tabel : DetailTransaksi Field Type Size Keterangan NoFaktur Text 11 KodeBuku Text 3 Judul Text 150 Jumlah Number HargaJual Number SubTotal Number
  • 2. Teknik Informatika Universitas Serambi Mekkah Modul Dasar Pemrograman III (VB.Net) Hal. 2 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 : 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 MenuStrip1 StatusStrip1 GroupBox1 Button 1
  • 3. Teknik Informatika Universitas Serambi Mekkah Modul Dasar Pemrograman III (VB.Net) Hal. 3 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 Gambar 3. Rancangan Form Data Jenis Buku TextBox3 TextBox1 TextBox2 Button1 Button2 Button3 Button4 DataGridView1
  • 4. Teknik Informatika Universitas Serambi Mekkah Modul Dasar Pemrograman III (VB.Net) Hal. 4 Gambar 4. Rancangan Form Data Buku Gambar 5. Rancangan Form Transaksi Penjualan Buku DataGridView1 TextBox2 TextBox3 TextBox4 TextBox5 TextBox8 TextBox7 TextBox9 Button5 Button4 Button3 Button2 Button1 ComboBox1 TextBox6 TextBox1 TextBox1 TextBox2 TextBox3 TextBox4 TextBox5 Button1 Button2 Button3 TextBox6 Label10 TextBox7 TextBox8 TextBox9 DataGridView1 Button4
  • 5. Teknik Informatika Universitas Serambi Mekkah Modul Dasar Pemrograman III (VB.Net) Hal. 5 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
  • 6. Teknik Informatika Universitas Serambi Mekkah Modul Dasar Pemrograman III (VB.Net) Hal. 6 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
  • 7. Teknik Informatika Universitas Serambi Mekkah Modul Dasar Pemrograman III (VB.Net) Hal. 7 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")
  • 8. Teknik Informatika Universitas Serambi Mekkah Modul Dasar Pemrograman III (VB.Net) Hal. 8 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
  • 9. Teknik Informatika Universitas Serambi Mekkah Modul Dasar Pemrograman III (VB.Net) Hal. 9 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 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
  • 10. Teknik Informatika Universitas Serambi Mekkah Modul Dasar Pemrograman III (VB.Net) Hal. 10 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
  • 11. Teknik Informatika Universitas Serambi Mekkah Modul Dasar Pemrograman III (VB.Net) Hal. 11 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
  • 12. Teknik Informatika Universitas Serambi Mekkah Modul Dasar Pemrograman III (VB.Net) Hal. 12 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
  • 13. Teknik Informatika Universitas Serambi Mekkah Modul Dasar Pemrograman III (VB.Net) Hal. 13 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 = 50 DataGridView1.Columns(1).Width = 300 DataGridView1.Columns(2).Width = 60 DataGridView1.Columns(3).Width = 40 DataGridView1.Columns(4).Width = 80 End Sub
  • 14. Teknik Informatika Universitas Serambi Mekkah Modul Dasar Pemrograman III (VB.Net) Hal. 14 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
  • 15. Teknik Informatika Universitas Serambi Mekkah Modul Dasar Pemrograman III (VB.Net) Hal. 15 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
  • 16. Teknik Informatika Universitas Serambi Mekkah Modul Dasar Pemrograman III (VB.Net) Hal. 16 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
  • 17. Teknik Informatika Universitas Serambi Mekkah Modul Dasar Pemrograman III (VB.Net) Hal. 17 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 .......