Imports System.Data.OleDb
//kode di atas
digunakan untuk mengimport library OleDb sebagai library database Ms.Access
Public Class FormPenjualan
Private NomOt As String
= ""
Sub TampilGrid()
da = New OleDbDataAdapter("select * from tbPenjualan", conn)
ds = New DataSet
ds.Clear()
da.Fill(ds, "tbPenjualan")
dgv.DataSource = ds.Tables("tbPenjualan")
dgv.ReadOnly = True
End Sub
//kode di atas
digunakan untuk menampilkan data dari database ke datagridview
Private Sub nomorpenjualan()
Koneksi()
Try
cmd = New OleDbCommand("SELECT TOP 1 right(no_penjualan,3) + 1 as nomor
FROM tbPenjualan ORDER BY no_penjualan DESC ", conn)
rd = cmd.ExecuteReader
If rd.Read Then
Select Case rd!nomor
Case Is <= 9
NomOt = "P-" & "00" & rd!nomor
Case Is <= 99
NomOt = "P-" & "0" & rd!nomor
End Select
Else
'tabel
kosong
NomOt = "P-" & "001"
End If
lblNoPenjualan.Text
= NomOt
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
//kode di atas
digunakan untuk membuat no penjualan secara otomatis
Private Sub FormPenjualan_Load(ByVal sender As
System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Call Koneksi()
Call TampilGrid()
Call nomorpenjualan()
End Sub
//kode di atas
digunakan untuk menampilkan form dengan kondisi-kondisi yang telah dibuat
pada class-class
Private Sub txtCari_KeyPress(ByVal sender As
Object, ByVal
e As System.Windows.Forms.KeyPressEventArgs) Handles txtCari.KeyPress
If e.KeyChar
= Chr(13) Then
cmd = New OleDbCommand("select * from tbPenjualan where nama_brg like '%" & txtCari.Text
& "%' or harga_brg like '%"
& txtCari.Text & "%'
or no_penjualan like '%" & txtCari.Text
& "%'", conn)
rd = cmd.ExecuteReader
rd.Read()
If rd.HasRows
Then
da = New OleDbDataAdapter("select * from tbPenjualan where nama_brg like '%" & txtCari.Text
& "%' or harga_brg like '%"
& txtCari.Text & "%'
or no_penjualan like '%" & txtCari.Text
& "%'", conn)
ds = New DataSet
da.Fill(ds,
"ketemu")
dgv.DataSource
= ds.Tables("ketemu")
dgv.ReadOnly
= True
lblNoPenjualan.Text
= rd.Item(0)
txtNama.Text
= rd.Item(1)
txtHarga.Text
= rd.Item(2)
txtJumlah.Text
= rd.Item(3)
lblTotalHarga.Text
= rd.Item(4)
Else
MsgBox("data tidak ditemukan")
End If
End If
End Sub
//kode di atas
digunakan untuk mencari data
Private Sub txtJumlah_TextChanged(ByVal sender As
Object, ByVal
e As System.EventArgs) Handles
txtJumlah.TextChanged
lblTotalHarga.Text = Val(txtHarga.Text)
* Val(txtJumlah.Text)
End Sub
//kode di atas
digunakan untuk menghitung total harga
Private Sub btnSimpan_Click(ByVal sender As
System.Object, ByVal e As
System.EventArgs) Handles btnSimpan.Click
cmd = New OleDbCommand("INSERT INTO tbPenjualan VALUES ('"
& NomOt & "','"
& txtNama.Text & "','"
& txtHarga.Text & "','"
& txtJumlah.Text & "','"
& lblTotalHarga.Text & "')",
conn)
cmd.ExecuteNonQuery()
MsgBox("Berhasil Menyimpan Data !", MsgBoxStyle.Information)
Call TampilGrid()
End Sub
//kode di atas
digunakan untuk menyimpan data
Private Sub btnHapus_Click(ByVal sender As
System.Object, ByVal e As
System.EventArgs) Handles btnHapus.Click
cmd = New OleDbCommand("DELETE FROM tbPenjualan WHERE No_Penjualan =
'" & lblNoPenjualan.Text & "'", conn)
cmd.ExecuteNonQuery()
MsgBox("Berhasil Menghapus Data !", MsgBoxStyle.Information)
Call TampilGrid()
End Sub
//kode di atas
digunakan untuk menghapus data
Private Sub btnUbah_Click(ByVal sender As
System.Object, ByVal e As
System.EventArgs) Handles btnUbah.Click
cmd = New OleDbCommand("UPDATE tbPenjualan SET nama_brg = '"
& txtNama.Text & "',
harga_brg = '" & txtHarga.Text & "', jumlah_brg = '" & txtJumlah.Text
& "', total_harga = '"
& lblTotalHarga.Text & "'
WHERE no_penjualan = '" & lblNoPenjualan.Text
& "'", conn)
cmd.ExecuteNonQuery()
MsgBox("Berhasil Mengubah Data !", MsgBoxStyle.Information)
Call TampilGrid()
End Sub
//kode di atas
digunakan untuk mengubah data
Private Sub btnClear_Click(ByVal sender As
System.Object, ByVal e As
System.EventArgs) Handles btnClear.Click
lblNoPenjualan.Text = NomOt
txtNama.Text = ""
txtHarga.Text = ""
txtJumlah.Text = ""
lblTotalHarga.Text = ""
End Sub
//kode di atas
digunakan untuk membatalkan penginputan
End Class
|
Comments
Post a Comment