Membuat Aplikasi Penjualan Buku Sederhana dengan VB.NET 2008
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 |
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 AsSystem.Object, ByVal e As System.EventArgs) HandlesDataJenisBukuToolStripMenuItem.Click
Form2.Show()
End Sub
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 4. Rancangan Form Data Buku
Gambar 5. Rancangan Transaksi Penjualan Buku
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 Jenis Buku setelah dijalankan
Gambar 6. Hasil 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
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 AsSystem.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 AsSystem.Windows.Forms.DataGridViewCellEventArgs) HandlesDataGridView1.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 AsSystem.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 AsSystem.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 AsSystem.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 AsSystem.EventArgs) Handles Button4.Click
Call Kosong()
End Sub
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e AsSystem.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 AsSystem.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 Data Buku setelah dijalankan
Gambar 7. Hasil 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 = 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 AsSystem.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 AsSystem.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 AsSystem.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 AsSystem.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 AsSystem.Windows.Forms.DataGridViewCellEventArgs) HandlesDataGridView1.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 AsSystem.EventArgs) Handles Button1.Click
If TextBox1.Text = "" Or ComboBox1.Text = "" Or TextBox2.Text = "" OrTextBox3.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 AsSystem.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 AsSystem.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 AsSystem.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 AsSystem.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 AsSystem.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 AsSystem.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 AsSystem.EventArgs) Handles Button5.Click
Me.Close()
End Sub
Private Sub TextBox9_TextChanged(ByVal sender As System.Object, ByVal e AsSystem.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 AsSystem.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 Transaksi Penjualan Buku Komputer setelah dijalankan
Gambar 8. 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
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 AsSystem.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 AsSystem.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 AsSystem.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 AsSystem.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
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles Button2.Click
Call Kosong()
DataGridView1.Columns.Clear()
Call KolomBaru()
DataGridView1.Focus()
End Sub
Private Sub DataGridView1_EditingControlShowing(ByVal sender As Object, ByVale 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 AsKeyPressEventArgs)
If DataGridView1.CurrentCell.ColumnIndex = 3 Then
If ((Asc(ex.KeyChar) < 48 Or Asc(ex.KeyChar) > 57) AndAsc(ex.KeyChar) <> 8) Then
ex.Handled = True
End If
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles Button1.Click
If TextBox1.Text = "" Or TextBox2.Text = "" Or TextBox3.Text = "" OrTextBox4.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 AsSystem.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 AsSystem.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 AsSystem.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 AsSystem.EventArgs) Handles Button4.Click
Form3.ShowDialog()
End Sub
End Class
Update Contact :
No Wa/Telepon (puat) : 085267792168
No Wa/Telepon (fajar) : 085369237896
Email : Fajarudinsidik@gmail.com
No Wa/Telepon (puat) : 085267792168
No Wa/Telepon (fajar) : 085369237896
Email: Fajarudinsidik@gmail.com
atau Kirimkan Private messanger melalui email dengan klik tombol order dibawah ini :