Listing Program: Form Data Barang
Listing Program: Form Data Barang
Listing Program: Form Data Barang
Sub judulgrid()
Dim objAlternatingCellStyle As New
DataGridViewCellStyle()
dgv.AlternatingRowsDefaultCellStyle =
objAlternatingCellStyle
Dim style As DataGridViewCellStyle =
dgv.Columns(0).DefaultCellStyle
dgv.Columns(0).HeaderText = "Kd. Barang"
dgv.Columns(0).Width = 95
dgv.Columns(1).HeaderText = "Nama
Barang"
dgv.Columns(1).AutoSizeMode =
DataGridViewAutoSizeColumnMode.Fill
dgv.Columns(3).HeaderText = "Jenis"
dgv.Columns(3).Width = 90
dgv.Columns(4).HeaderText = "Hrg. Jual"
dgv.Columns(4).Width = 100
dgv.Columns(4).DefaultCellStyle.Format =
"c"
dgv.Columns(5).HeaderText = "Stok"
dgv.Columns(5).Width = 50
objAlternatingCellStyle.BackColor =
Color.AliceBlue
dgv.SelectionMode =
DataGridViewSelectionMode.FullRowSelect
dgv.ReadOnly = True
dgv.AllowUserToAddRows = False
End Sub
Sub isigrid(ByVal page As String)
Call konek()
Dim param As String = "stok"
85
Dim jumlahitem As Integer = 30
Dim index As Integer = jumlahitem *
(page - 1)
Dim query As String = "SELECT
kd_barang,nama_barang,harga_jual " _
& param & " FROM tb_barang tb " _
& "LIMIT " & index & ", " & jumlahitem
If from = "penjualan" Then
param = "stok-(SELECT
COALESCE(SUM(qty),0) FROM tb_penjualan WHERE
kd_barang = tb.kd_barang)"
End If
cmd = New MySqlCommand(query, conn)
cmd.Parameters.AddWithValue("@kd_barang", "%" +
tbcari.Text + "%")
cmd.Parameters.AddWithValue("@nama_barang", "%"
+ tbcari.Text + "%")
dr = cmd.ExecuteReader
If dr.HasRows Then
dt = New DataTable
dt.Load(dr)
dgv.DataSource = dt
dr.Close()
cmd = New MySqlCommand("SELECT
COUNT(*) FROM tb_barang WHERE (kd_barang LIKE
@kd_barang OR nama_barang LIKE @nama_barang)",
conn)
cmd.Parameters.AddWithValue("@kd_barang", "%" +
tbcari.Text + "%")
cmd.Parameters.AddWithValue("@nama_barang", "%"
+ tbcari.Text + "%")
dr = cmd.ExecuteReader
dr.Read()
halaman =
Math.Ceiling(dr.Item(0).ToString / jumlahitem)
dr.Close()
lbltotpage.Text = " / " & halaman
86
Else
dr.Close()
dgv.DataSource = Nothing
tbpage.Text = "1"
lbltotpage.Text = " / 0"
End If
cmd = New MySqlCommand("SELECT COUNT(*)
FROM tb_barang", conn)
dr = cmd.ExecuteReader
dr.Read()
lbltotitem.Text = "Jumlah Item : " &
dr.Item(0).ToString
dr.Close()
End Sub
Sub fgd()
Call konek()
da = New MySqlDataAdapter("select * from
tb_barang where kd_barang LIKE '%" & tbcari.Text
& "%' or nama_barang LIKE '%" & tbcari.Text &
"%'", conn)
ds = New DataSet
da.Fill(ds, "tb_barang")
dgv.DataSource = ds.Tables("tb_barang")
End Sub
Private Sub tbcari_TextChanged(sender As
Object, e As EventArgs) Handles
tbcari.TextChanged
fgd()
End Sub
87
cmd = New MySqlCommand("Insert into
tb_barang
(kd_barang,nama_barang,harga_jual,stok)
values('" & t1.Text & "','" & t2.Text & "','" &
t4.Text & "','" & t5.Text & "')", conn)
cmd.ExecuteNonQuery()
MsgBox("Simpan Data Berhasil",
MsgBoxStyle.Information, "Informasi")
tampil()
clear()
diskonek()
End Sub
Sub tampil()
'KODING TAMPILKAN KE DATAGRIDVIEW'
Call konek()
da = New MySqlDataAdapter("select * from
tb_barang", conn)
ds = New DataSet
da.Fill(ds, "tb_barang")
dgv.DataSource = ds.Tables("tb_barang")
End Sub
Private Function carinama(ByVal namasiswa As
String) As Integer
Try
Dim foundrow As DataGridViewRow = (
From row As DataGridViewRow In
dgv.Rows
Where row.Cells(1).Value =
namasiswa
Select row
).First
If foundrow IsNot Nothing Then
Return (foundrow.Index)
Else
Return -1
End If
Catch ex As Exception
Return -1
End Try
End Function
88
Private Sub formbarang_Load(sender As
Object, e As EventArgs) Handles MyBase.Load
tampil()
tbcari.Visible = False
lbltotitem.Visible = False
btnfirst.Visible = False
btnprev.Visible = False
tbpage.Visible = False
lbltotpage.Visible = False
btnnext.Visible = False
btnlast.Visible = False
End Sub
End Sub
89
cmd = New MySqlCommand("delete from
tb_barang WHERE kd_barang = '" & t1.Text & "'",
conn)
cmd.ExecuteNonQuery()
Call diskonek()
MessageBox.Show("Data berhasil dihapus")
tampil()
clear()
End Sub
90
Form Pelanggan
Imports MySql.Data.MySqlClient
Public Class formpengguna
tampil()
gridpengunaan.Columns(0).HeaderText =
"kode"
gridpengunaan.Columns(1).HeaderText =
"Nama"
gridpengunaan.Columns(2).HeaderText =
"Alamat"
gridpengunaan.Columns(3).HeaderText =
"No.Hp"
End Sub
Sub nootomatis()
Call konek()
cmd = New MySqlCommand("select * from
tb_pelanggan order by kd_pelanggan desc", conn)
dr = cmd.ExecuteReader
dr.Read()
If Not dr.HasRows() Then
tid.Text = "P" + "0001"
Else
tid.Text =
Val(Mid(dr.Item("kd_pelanggan").ToString, 2, 4))
+ 1
If Len(tid.Text) = 1 Then
91
tid.Text = "P000" & tid.Text &
""
ElseIf Len(tid.Text) = 2 Then
tid.Text = "P00" & tid.Text & ""
ElseIf Len(tid.Text) = 3 Then
tid.Text = "P0" & tid.Text & ""
End If
End If
diskonek()
End Sub
'NOOTOMATIS'
Sub nootomatis1()
Call konek()
cmd = New MySqlCommand("select * from
tb_pelanggan order by kd_pelanggan desc", conn)
dr = cmd.ExecuteReader
dr.Read()
If Not dr.HasRows() Then
tid.Text = "R" + "0001"
Else
tid.Text =
Val(Mid(dr.Item("kd_pelanggan").ToString, 2, 4))
+ 1
If Len(tid.Text) = 1 Then
tid.Text = "R000" & tid.Text &
""
ElseIf Len(tid.Text) = 2 Then
tid.Text = "R00" & tid.Text & ""
ElseIf Len(tid.Text) = 3 Then
tid.Text = "R0" & tid.Text & ""
End If
End If
diskonek()
End Sub
Sub kosong()
tid.Text = ""
talamat.Text = ""
tnama.Text = ""
tnohp.Text = ""
cbjenis.Text = ""
92
id.Clear()
End Sub
Sub tampil()
konek()
da = New
MySql.Data.MySqlClient.MySqlDataAdapter("select
* from tb_pelanggan", conn)
ds = New DataSet
ds.Clear()
da.Fill(ds, "tb_pelanggan")
gridpengunaan.DataSource =
ds.Tables("tb_pelanggan")
diskonek()
End Sub
Sub tampil1()
konek()
da = New
MySql.Data.MySqlClient.MySqlDataAdapter("select
* from tb_pelanggan1", conn)
ds = New DataSet
ds.Clear()
da.Fill(ds, "tb_pelanggan1")
gridpengunaan.DataSource =
ds.Tables("tb_pelanggan1")
diskonek()
End Sub
93
kosong()
tampil()
diskonek()
End If
End Sub
Private Sub
cbjenis_SelectedIndexChanged(sender As Object, e
As EventArgs)
End Sub
94
cmd = New MySqlCommand("Delete From
tb_pelanggan Where kd_pelanggan='" & tid.Text &
"'", conn)
cmd.ExecuteNonQuery()
MsgBox("Hapus Data Sukses",
MsgBoxStyle.Information, "Sukses")
kosong()
diskonek()
tampil()
tampil1()
End If
End Sub
Form Penjualan
Imports MySql.Data.MySqlClient
95
diskonek()
End Sub
End Sub
Sub tampil()
'KODING TAMPILKAN KE DATAGRIDVIEW'
Call konek()
da = New MySqlDataAdapter("select * from
tb_barang", conn)
ds = New DataSet
da.Fill(ds, "tb_barang")
dgv1.DataSource = ds.Tables("tb_barang")
cnama.Focus()
End Sub
96
lbltotalbarang.Text =
dgvkeranjang.Rows(e.RowIndex).Cells(6).Value
End Sub
Sub tampil1()
'KODING TAMPILKAN KE DATAGRIDVIEW'
Call konek()
da = New MySqlDataAdapter("select * from
tb_penjualan1", conn)
ds = New DataSet
da.Fill(ds, "tb_penjualan1")
dgvkeranjang.DataSource =
ds.Tables("tb_penjualan1")
End Sub
diskonek()
End Sub
97
Private Sub btninput_Click(sender As Object,
e As EventArgs) Handles btninput.Click
Dim tot As Integer
tot = tbqty.Text * tbhargajual.Text
lbltotalbarang.Text = tot
lbltotal.Text = (tot)
End Sub
Sub inputkeranjang()
If kd_barang = "" Then
MsgBox("Input dahulu item barang!",
16, "Perhatian")
Else
If Val(tbqty.Text) <= 0 Then
MsgBox("Masukkan Qty!", 16,
"Perhatian")
Else
cmd = New MySqlCommand("SELECT
stok-(SELECT COALESCE(SUM(qty),0) FROM
tb_penjualan1 where kd_barang = '" & kd_barang &
"') AS stok" _
& " FROM tb_barang
WHERE kd_barang = '" & kd_barang & "'", conn)
dr = cmd.ExecuteReader
dr.Read()
Dim stok As Integer =
dr.Item("stok").ToString
dr.Close()
If Val(tbqty.Text) > stok Then
MsgBox("Stok tidak cukup!",
16, "Informasi")
Else
cmd = New
MySqlCommand("SELECT no FROM tb_penjualan1 where
kd_barang = '" & kd_barang & "'", conn)
dr = cmd.ExecuteReader
dr.Read()
If dr.HasRows Then
Dim update As String =
"UPDATE tb_penjualan1 SET qty = qty + " &
Val(tbqty.Text) & ", harga_jual = " &
tbhargajual.Text _
98
&
", total = qty * harga_jual WHERE no = " &
dr.Item("no").ToString
dr.Close()
Query(update)
Else
dr.Close()
Dim query As String =
"INSERT INTO tb_penjualan1 (kd_barang,
nama_barang, qty, ambil, harga_jual, total)" _
& "VALUES
(@kd_barang, @nama_barang, @qty, @ambil,
@harga_jual, @total)"
QueryKeranjang(query,
kd_barang.ToUpper, lblnamabarang.Text,
tbqty.Text, "", tbhargajual.Text,
Val(tbqty.Text) * Val(tbhargajual.Text))
End If
kd_barang = ""
isikeranjang()
cnama.Focus()
clearinput()
End If
End If
End If
End Sub
Sub isikeranjang()
Dim query As String = "SELECT * FROM
tb_penjualan1"
Dim da As New MySqlDataAdapter(query,
conn)
Dim ds As New DataSet()
If da.Fill(ds) Then
dgvkeranjang.DataSource =
ds.Tables(0)
dgvkeranjang.Refresh()
Else
dgvkeranjang.DataSource = Nothing
End If
99
If dgvkeranjang.RowCount > 0 Then
judulgrid()
End If
hitungtotal()
End Sub
Sub judulgrid()
Dim objAlternatingCellStyle As New
DataGridViewCellStyle()
dgvkeranjang.AlternatingRowsDefaultCellStyle =
objAlternatingCellStyle
Dim style As DataGridViewCellStyle =
dgvkeranjang.Columns(0).DefaultCellStyle
dgvkeranjang.Columns(0).Visible = False
dgvkeranjang.Columns(1).HeaderText =
"Kd. Barang"
dgvkeranjang.Columns(1).Width = 150
dgvkeranjang.Columns(2).HeaderText =
"Nama Barang"
dgvkeranjang.Columns(2).AutoSizeMode =
DataGridViewAutoSizeColumnMode.Fill
dgvkeranjang.Columns(3).HeaderText =
"Qty"
dgvkeranjang.Columns(3).Width = 100
dgvkeranjang.Columns(4).HeaderText =
"Ambil"
dgvkeranjang.Columns(4).Width = 100
dgvkeranjang.Columns(5).Visible = False
dgvkeranjang.Columns(6).HeaderText =
"Hrg. Jual"
dgvkeranjang.Columns(6).Width = 150
dgvkeranjang.Columns(6).DefaultCellStyle.Format
= "c"
dgvkeranjang.Columns(7).HeaderText =
"Total"
dgvkeranjang.Columns(7).Width = 150
dgvkeranjang.Columns(7).DefaultCellStyle.Format
= "c"
100
objAlternatingCellStyle.BackColor =
Color.AliceBlue
dgvkeranjang.SelectionMode =
DataGridViewSelectionMode.FullRowSelect
dgvkeranjang.ReadOnly = True
dgvkeranjang.AllowUserToAddRows = False
End Sub
Sub hitungtotal()
Dim hitung As Integer
For i = 0 To dgvkeranjang.RowCount - 1
hitung +=
dgvkeranjang.Rows(i).Cells(8).Value
Next
lbltotal.Text = FormatCurrency(hitung)
End Sub
Sub clearinput()
tbkdbarang.Clear()
lblnamabarang.Text = ""
tbqty.Clear()
tbhargajual.Clear()
lbltotalbarang.Text = (0)
cnama.Text = "Pilih Kode"
tnamap.Clear()
End Sub
Sub reset()
lbltotal.Text = (0)
clearinput()
tampil1()
End Sub
101
tbhargajual.Text =
dgv1.Rows(e.RowIndex).Cells(2).Value
tbqty.Focus()
End Sub
Sub hitung()
Dim total = Aggregate row As
DataGridViewRow In dgvkeranjang.Rows _
Into
Sum(Convert.ToDouble(row.Cells(6).Value))
lbltotalbarang.Text = "Rp. " +
Format(total, "###,###.00")
End Sub
reset()
tampil1()
cnama.Focus()
End Sub
End Sub
102
Private Sub
ComboBox1_SelectedIndexChanged(sender As Object,
e As EventArgs)
End Sub
Private Sub
dgvkeranjang_CellContentClick(sender As Object,
e As DataGridViewCellEventArgs) Handles
dgvkeranjang.CellContentClick
End Sub
End Sub
End Sub
End Sub
End Sub
Sub tampilComboBox()
konek()
Dim str As String
str = "select kd_pelanggan from
tb_pelanggan"
cmd = New MySqlCommand(str, conn)
dr = cmd.ExecuteReader
If dr.HasRows Then
Do While dr.Read
103
cnama.Items.Add(dr("kd_pelanggan"))
Loop
Else
End If
End Sub
'CETAK'
Sub cetak()
End Sub
End Sub
End Sub
Sub tampilnama()
konek()
cmd = New MySqlCommand("select
kd_pelanggan, nama_pelanggan from tb_pelanggan
where kd_pelanggan='" & cnama.Text & "'", conn)
dr = cmd.ExecuteReader
dr.Read()
If dr.HasRows Then
tnamap.Text =
dr.Item("nama_pelanggan")
Else
End If
End Sub
104
Private Sub
cnama_SelectedIndexChanged(sender As Object, e
As EventArgs) Handles cnama.SelectedIndexChanged
tampilnama()
End Sub
End Sub
End Class
105