Listing Program: Form Data Barang

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 21

LISTING PROGRAM

Form data barang


Imports MySql.Data.MySqlClient
Public Class formbarang
Public from As String
Public halaman As Integer = 1
Dim DBDataset As New DataTable

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

Private Sub btntambah_Click(sender As


Object, e As EventArgs) Handles btntambah.Click
'KODING SIMPAN DATA'
konek()

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

Private Sub btnedit_Click(sender As Object,


e As EventArgs) Handles btnedit.Click
'KODING UBAH DATA'
Call konek()
cmd = New MySqlCommand("UPDATE tb_barang
SET kd_barang = '" & t1.Text & "', nama_barang =
'" & t2.Text & "', harga_jual = '" & t4.Text &
"', stok = '" & t5.Text & "' WHERE kd_barang =
'" & t1.Text & "'", conn)
cmd.ExecuteNonQuery()
Call diskonek()
MessageBox.Show("Data berhasil diubah")
clear()
tampil()
End Sub

Private Sub dgv_CellContentClick(sender As


Object, e As DataGridViewCellEventArgs) Handles
dgv.CellContentClick

End Sub

Private Sub btnhapus_Click(sender As Object,


e As EventArgs) Handles btnhapus.Click
Call konek()

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

Private Sub btnbatal_Click(sender As Object,


e As EventArgs) Handles btnbatal.Click
Me.Close()
menuutama.Show()
End Sub

Private Sub dgv_CellClick(sender As Object,


e As DataGridViewCellEventArgs) Handles
dgv.CellClick
'KODING PANGGIL DATA DIDATAGRIDVIEW KE
TEXTBOX'
t1.Text =
dgv.Rows(e.RowIndex).Cells(0).Value
t2.Text =
dgv.Rows(e.RowIndex).Cells(1).Value
t4.Text =
dgv.Rows(e.RowIndex).Cells(2).Value
t5.Text =
dgv.Rows(e.RowIndex).Cells(3).Value
End Sub
Sub clear()
t1.Clear()
t2.Clear()
t4.Clear()
t5.Clear()
tbcari.Clear()
t1.Focus()

90
Form Pelanggan
Imports MySql.Data.MySqlClient
Public Class formpengguna

Private Sub formpengguna_Load(sender As


Object, e As EventArgs) Handles MyBase.Load

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

Private Sub simpan_Click(sender As Object, e


As EventArgs) Handles simpan.Click
'KODING SIMPAN DATA'
konek()
If RadioButton1.Checked Then
cmd = New MySqlCommand("Insert into
tb_pelanggan
(kd_pelanggan,nama_pelanggan,alamat,no_hp)
values('" & tid.Text & "','" & tnama.Text &
"','" & talamat.Text & "','" & tnohp.Text &
"')", conn)
cmd.ExecuteNonQuery()
MsgBox("Simpan Data Berhasil",
MsgBoxStyle.Information, "Informasi")

93
kosong()
tampil()
diskonek()
End If
End Sub

Private Sub
cbjenis_SelectedIndexChanged(sender As Object, e
As EventArgs)

End Sub

Private Sub gridpengunaan_CellClick(sender


As Object, e As DataGridViewCellEventArgs)
Handles gridpengunaan.CellClick
'KODING PANGGIL DATA DIDATAGRIDVIEW KE
TEXTBOX'
tid.Text =
gridpengunaan.Rows(e.RowIndex).Cells(0).Value
tnama.Text =
gridpengunaan.Rows(e.RowIndex).Cells(1).Value
talamat.Text =
gridpengunaan.Rows(e.RowIndex).Cells(2).Value
tnohp.Text =
gridpengunaan.Rows(e.RowIndex).Cells(3).Value
End Sub
Private Sub Button2_Click(sender As Object,
e As EventArgs) Handles Button2.Click
hapus()
End Sub
Sub hapus()
Dim yesno As String

yesno = MsgBox("Apakah Anda Yakin


Menghapus Data ini?", MsgBoxStyle.YesNo,
"Informasi")

If yesno = DialogResult.Yes Then


konek()

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

Public Class formpenjualan01


Public kd_barang As String
'NOOTOMATIS'
Sub nootomatis()
Call konek()
cmd = New MySqlCommand("select * from
tb_penjualan1 order by no_trans desc", conn)
dr = cmd.ExecuteReader
dr.Read()
If Not dr.HasRows() Then
tnotrans.Text = "R" + "0001"
Else
tnotrans.Text =
Val(Mid(dr.Item("no_trans").ToString, 2, 4)) + 1
If Len(tnotrans.Text) = 1 Then
tnotrans.Text = "R000" &
tnotrans.Text & ""
ElseIf Len(tnotrans.Text) = 2 Then
tnotrans.Text = "R00" &
tnotrans.Text & ""
ElseIf Len(tnotrans.Text) = 3 Then
tnotrans.Text = "R0" &
tnotrans.Text & ""
End If
End If

95
diskonek()
End Sub

Private Sub formpenjualan01_Load(sender As


Object, e As EventArgs) Handles MyBase.Load
tampil()
nootomatis()
tampilComboBox()

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

Private Sub dgvkeranjang_CellClick(sender As


Object, e As DataGridViewCellEventArgs) Handles
dgvkeranjang.CellClick
'KODING PANGGIL DATA DIDATAGRIDVIEW KE
TEXTBOX'
tnotrans.Text =
dgvkeranjang.Rows(e.RowIndex).Cells(0).Value
tnamap.Text =
dgvkeranjang.Rows(e.RowIndex).Cells(1).Value
tbkdbarang.Text =
dgvkeranjang.Rows(e.RowIndex).Cells(2).Value
lblnamabarang.Text =
dgvkeranjang.Rows(e.RowIndex).Cells(3).Value
tbqty.Text =
dgvkeranjang.Rows(e.RowIndex).Cells(4).Value
tbhargajual.Text =
dgvkeranjang.Rows(e.RowIndex).Cells(5).Value

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

Private Sub btnsimpan_Click(sender As


Object, e As EventArgs) Handles btnsimpan.Click

'KODING SIMPAN DATA'


konek()
cmd = New MySqlCommand("Insert into
tb_penjualan1
(no_trans,nama_pelanggan,kd_barang,nama_barang,q
ty,harga_jual,total) values('" & tnotrans.Text &
"','" & tnamap.Text & "','" & tbkdbarang.Text &
"','" & lblnamabarang.Text & "','" & tbqty.Text
& "','" & tbhargajual.Text & "','" &
lbltotalbarang.Text & "')", conn)
cmd.ExecuteNonQuery()
MsgBox("Simpan Data Berhasil",
MsgBoxStyle.Information, "Informasi")
tampil1()
clearinput()
nootomatis()
reset()

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

Private Sub dgv1_CellClick(sender As Object,


e As DataGridViewCellEventArgs) Handles
dgv1.CellClick
'KODING PANGGIL DATA DIDATAGRIDVIEW KE
TEXTBOX'
tbkdbarang.Text =
dgv1.Rows(e.RowIndex).Cells(0).Value
lblnamabarang.Text =
dgv1.Rows(e.RowIndex).Cells(1).Value

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

Private Sub btnhapus_Click(sender As Object,


e As EventArgs) Handles btnhapus.Click
Call konek()
cmd = New MySqlCommand("delete from
tb_penjualan1 WHERE No_trans = '" &
tnotrans.Text & "'", conn)
cmd.ExecuteNonQuery()
Call diskonek()
MessageBox.Show("Data berhasil dihapus")

reset()
tampil1()
cnama.Focus()
End Sub

Private Sub btnbatal_Click(sender As Object,


e As EventArgs) Handles btnbatal.Click
Me.Close()
menuutama.Show()
End Sub

Private Sub GroupBox5_Enter(sender As


Object, e As EventArgs) Handles GroupBox5.Enter

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

Private Sub lbltotal_Click(sender As Object,


e As EventArgs) Handles lbltotal.Click

End Sub

Private Sub btnbarang_Click(sender As


Object, e As EventArgs)

End Sub

Private Sub tidp_KeyPress(sender As Object,


e As KeyPressEventArgs)

End Sub

Private Sub GroupBox1_Enter(sender As


Object, e As EventArgs) Handles GroupBox1.Enter

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

Private Sub Button1_Click(sender As Object,


e As EventArgs)
cetaktransaksi.Show()

End Sub

Private Sub tnotrans_TextChanged(sender As


Object, e As EventArgs) Handles
tnotrans.TextChanged

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

Private Sub dgv1_CellContentClick(sender As


Object, e As DataGridViewCellEventArgs) Handles
dgv1.CellContentClick

End Sub
End Class

105

You might also like