Aplikasi Persediaan Barang

 

Sebelum membahas aplikasi persediaan barang, anda harus menyiapkan database dengan cara attach atau restore seperti yang telah dibahas pada bab sebelumnya. Jika anda ingin memulainya dari awal maka ikutilah langkah-langkah yang akan dijelaskan di bawah ini.

7.1 Membuat Database

Untuk membuat database lakukanlah langkah-langkah di bawah ini:

 

1.              Buka sql server

2.              Klik kanan databases > new database

3.              Ketik nama database baru misal DBPersediaan

4.              Klik OK

 

Gambar 7.1 Membuat Database

7.2 Membuat Tabel

Setelah membuat database, lanjutkan dengan membuat beberapa buah tabel yang diperlukan antara lain :

1.              Tabel Barang, Departemen, Supplier dan Tabel User

2.              Tabel Permintaan dan Tabel Detail Permintaan

3.              Tabel Pengeluaran dan Tabel Detail Pengeluaran

4.              Tabel Penerimaan dan Tabel Detail Penerimaan

Struktur masing-masing tabel dapat dilihat pada gambar gambar di bawah ini.

 

 

Gambar 7.2 Tabel Barang

Gambar 7.3 Tabel Departemen

Gambar 7.4 Tabel Supplier

 

Gambar 7.5 Tabel User

Gambar 7.6 Tabel Permintaan

Gambar 7.7 Tabel Detail Permintaan

Gambar 7.8 Tabel Pengeluaran

Gambar 7.9 Tabel Detail Pengeluaran

Gambar 7.10 Tabel Penerimaan

Gambar 7.11 Tabel Detal Penerimaan

7.3 Membuat Project Baru

Setelah dipastikan desain semua tabel dapat terhubung dengan baik, maka segera lanjutkan dengan membuat project baru dengan nama Aplikasi Persediaan Barang.

7.4 Membuat Module Koneksi

Setelah project terbuka, buatlah module dengan cara sebagai berikut:

1.              Klik menu project

2.              Pilih add module

3.              Klik add

4.              Lalu ketik koding berikut ini

Imports System.data.sqlclient

 

Module Module1

Public CONN As sqlConnection

Public DA As sqlDataAdapter

Public DS As DataSet

Public CMD As sqlCommand

Public DR As sqlDataReader

 

Public Sub Koneksi()

Try

String koneksi ke database

CONN = New SqlConnection("data source=user-pc\sqlexpress;initial catalog=dbpersediaan;integrated security=true")

CONN.Open()

Catch ex As Exception

MsgBox(ex.Message)

End

End Try

End Sub

End Module

7.5 Form Login

Gambar 7.12 Form Login

Logika program dalam form login dalam buku semuanya hampir sama. Silakan lihat kembali logika program login pada aplikasi pembayaran SPP atau pemesanan dan pengiriman barang.

Coding :

Imports System.data.sqlclient

 

Public Class MenuLogin

 

Private Sub MenuLogin_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

PictureBox1.Load("kunci3.jpg")

PictureBox1.SizeMode = PictureBoxSizeMode.Zoom

End Sub

 

Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress

If e.KeyChar = Chr(13) Then TextBox2.Focus()

End Sub

 

Private Sub TextBox2_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox2.KeyPress

If e.KeyChar = Chr(13) Then Button1.Focus()

End Sub

 

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Call Koneksi()

CMD = New sqlCommand("select * from tbluser where nama_user='" & TextBox1.Text & "' and pwd_user='" & TextBox2.Text & "'", CONN)

DR = CMD.ExecuteReader

DR.Read()

If Not DR.HasRows Then

MsgBox("Login gagal")

TextBox1.Clear()

TextBox2.Clear()

TextBox1.Focus()

Else

Me.Visible = False

MenuUtama.Show()

MenuUtama.Panel1.Text = DR.Item("kode_User")

MenuUtama.Panel2.Text = DR.Item("nama_User")

MenuUtama.Panel3.Text = DR.Item("status_User")

If MenuUtama.Panel3.Text = "USER" Then

MenuUtama.UserToolStripMenuItem.Enabled = False

End If

End If

 

End Sub

 

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

End

End Sub

End Class

7.6 Form Menu Utama

 

Gambar 7.13 Form Menu Utama

Dalam menu utama terdapat objek PictureBox yang digunakan untuk menampilkan gambar background agar tampilan aplikasi lebih menarik.

7.7 Form User

Dalam hal ini user adalah orang yang melakukan semua proses transaksi, posisinya terletak di gudang.

Logika program dalam form User adalah sebagai berikut :

1.              Ketik kode user, maka program akan mencari kode tersebut ke tabel user

2.              Jika kodenya ditemukan maka akan tampil nama, password dan status di masing-masing textbox

3.              Jika kode user tidak ada maka akan dianggap sebagai data baru

4.              Pada saat button simpan di klik maka, program akan mencari kode tersebut ke dalam tabel user

5.              Jika kodenya tidak ada maka data tersebut akan disimpan sebagai data baru

6.              Jika kode tersebut ada maka data tersebut akan diedit.

Gambar 7.14 Form User

Imports System.data.sqlclient

 

Public Class MasterUser

 

Sub Kosongkan()

TextBox1.Clear()

TextBox2.Clear()

ComboBox1.Text = ""

TextBox3.Clear()

TextBox6.Clear()

TextBox1.Focus()

Call TampilStatus_user()

Call TampilGrid()

End Sub

 

Sub DataBaru()

TextBox2.Clear()

ComboBox1.Text = ""

TextBox3.Clear()

TextBox6.Clear()

TextBox2.Focus()

End Sub

 

Sub Ketemu()

TextBox2.Text = DR.Item("nama_User")

TextBox3.Text = DR.Item("pwd_User")

ComboBox1.Text = DR.Item("Status_user")

TextBox2.Focus()

End Sub

 

Menampilkan tabel user dalam grid

 

Sub TampilGrid()

Call Koneksi()

DA = New SqlDataAdapter("select * from tblUser", CONN)

DS = New DataSet

DA.Fill(DS)

DGV.DataSource = DS.Tables(0)

DGV.ReadOnly = True

End Sub

 

Menampilkan status user dalam combobox1

 

Sub TampilStatus_user()

Call Koneksi()

CMD = New SqlCommand("select distinct Status_user from tblUser", CONN)

DR = CMD.ExecuteReader

ComboBox1.Items.Clear()

Do While DR.Read

ComboBox1.Items.Add(DR.Item("Status_user"))

Loop

End Sub

 

Private Sub MasterUser_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Me.StartPosition = FormStartPosition.CenterScreen

Call Koneksi()

Call Kosongkan()

End Sub

 

Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress

 

Mencari data user, jika ada maka data akan ditampilkan, jika tidak ada maka dianggap data baru

 

If e.KeyChar = Chr(13) Then

Call Koneksi()

CMD = New SqlCommand("select * from tblUser where kode_User='" & TextBox1.Text & "'", CONN)

DR = CMD.ExecuteReader

DR.Read()

If Not DR.HasRows Then

Call DataBaru()

Else

Call Ketemu()

End If

End If

End Sub

 

Private Sub TextBox2_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox2.KeyPress

If e.KeyChar = Chr(13) Then

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

ComboBox1.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

Button1.Focus()

End If

If ((e.KeyChar >= "0" And e.KeyChar <= "9") And e.KeyChar <> vbBack) Then e.Handled = True

End Sub

 

Private Sub TextBox6_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox6.TextChanged

Call Koneksi()

DA = New SqlDataAdapter("select * from tblUser where nama_User like '%" & TextBox6.Text & "%'", CONN)

DS = New DataSet

DA.Fill(DS)

DGV.DataSource = DS.Tables(0)

End Sub

 

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Call Koneksi()

CMD = New SqlCommand("select * from tblUser where kode_User='" & TextBox1.Text & "'", CONN)

DR = CMD.ExecuteReader

DR.Read()

Try

 

Mencari data user, jika tidak ada maka akan disimpan sebagai data baru, jika ada maka akan diedit

 

If Not DR.HasRows Then

Call Koneksi()

Dim simpan As String = "insert into tblUser values ('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & ComboBox1.Text & "')"

CMD = New SqlCommand(simpan, CONN)

CMD.ExecuteNonQuery()

Else

Call Koneksi()

Dim edit As String = "update tblUser set nama_User='" & TextBox2.Text & "',Status_user='" & ComboBox1.Text & "',pwd_User='" & TextBox3.Text & "' where kode_User='" & TextBox1.Text & "'"

CMD = New SqlCommand(edit, CONN)

CMD.ExecuteNonQuery()

End If

Catch ex As Exception

MsgBox(ex.Message)

End Try

Call Kosongkan()

End Sub

 

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

If TextBox1.Text = "" Then

MsgBox("Kode User harus diisi")

TextBox1.Focus()

Exit Sub

End If

 

Call Koneksi()

CMD = New sqlCommand("select distinct kode_user from tblpermintaan where kode_user='" & TextBox1.Text & "'", CONN)

DR = CMD.ExecuteReader

DR.Read()

If DR.HasRows Then

MsgBox("Kode user tidak boleh dihapus karena sudah ada dalam transaksi")

Exit Sub

End If

If MessageBox.Show("yakin akan dihapus..?", "", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.Yes Then

Call Koneksi()

Menghapus data user

Dim hapus As String = "delete from tblUser where kode_User='" & TextBox1.Text & "'"

CMD = New sqlCommand(hapus, CONN)

CMD.ExecuteNonQuery()

Call Kosongkan()

Else

Call Kosongkan()

End If

End Sub

 

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

Call Kosongkan()

End Sub

 

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click

Me.Close()

End Sub

 

Private Sub ComboBox1_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.LostFocus

ComboBox1.Text = UCase(ComboBox1.Text)

End Sub

 

Private Sub DGV_CellMouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DGV.CellMouseClick

On Error Resume Next

TextBox1.Text = DGV.Rows(e.RowIndex).Cells(0).Value

TextBox2.Text = DGV.Rows(e.RowIndex).Cells(1).Value

TextBox3.Text = DGV.Rows(e.RowIndex).Cells(2).Value

ComboBox1.Text = DGV.Rows(e.RowIndex).Cells(3).Value

End Sub

 

End Class

7.8 Form Departemen

Dalam kasus ini departemen berdiri sebagai customer, yaitu entitas yang memerlukan barang-barang untuk keperluan operasional perusahaan.

 

Gambar 7.15 Form Departemen

7.9 Form Barang

Dalam kasus ini data barang tidak menyimpan harga, karena pengolahan data difokuskan pada arus distribusi barang masuk dan keluar.

Gambar 7.16 Form Barang

7.10 Form Supplier

Supplier adalah entitas luar sebagai penyedia barang-barang bagi perusahaan ketika terjadi order barang yang diperlukan.

Gambar 7.17 Form Supplier

7.11 Form Permintaan Barang

Proses transaksi permintaan barang adalah sebagai berikut :

1.              Mengisi nomor permintaan dari departemen atau dari customer

2.              Memilih tanggal permintaan

3.              Memilih departemen atau customer

4.              Mengisi kode barang di kolom kode atau memilihnya dari daftar barang di sebelah kanan

5.              Mengisi jumlah permintaan

6.              Menyimpan data permintaan barang

 

Gambar 7.18 Form Permintaan Barang

Imports System.data.sqlclient

 

Public Class Permintaan

 

Sub Kosongkan()

ComboBox1.Text = ""

Label6.Text = ""

Label7.Text = ""

Label9.Text = ""

Label11.Text = ""

Label12.Text = 0

DGV.Rows.Clear()

Call TampilBarang()

TextBox1.Focus()

End Sub

 

Menampilkan nama barang dalam listbox

 

Sub TampilBarang()

Call Koneksi()

CMD = New SqlCommand("Select * from tblbarang order by 2", CONN)

DR = CMD.ExecuteReader

ListBox1.Items.Clear()

Do While DR.Read

ListBox1.Items.Add(DR.Item("Nama_Barang"))

Loop

End Sub

 

Menampilkan data departemen dalam combobox1

 

Sub Tampildepartemen()

Call Koneksi()

CMD = New SqlCommand("Select * from tbldepartemen", CONN)

DR = CMD.ExecuteReader

ComboBox1.Items.Clear()

Do While DR.Read

ComboBox1.Items.Add(DR.Item("kode_departemen"))

Loop

End Sub

 

Private Sub Permintaan_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Call Koneksi()

Call Kosongkan()

TextBox1.Clear()

Call TampilBarang()

Call Tampildepartemen()

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 DGV.Focus()

End Sub

 

Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged

Mencari nama departemen dari combobox1

 

Call Koneksi()

CMD = New sqlCommand("Select * from tbldepartemen where kode_departemen='" & ComboBox1.Text & "'", CONN)

DR = CMD.ExecuteReader

DR.Read()

If DR.HasRows Then

Label6.Text = DR.Item("nama_departemen")

Label7.Text = DR.Item("pimpinan")

Else

MsgBox("data tidak valid")

End If

End Sub

 

Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress

Mencari nomor permintaan yang sudah dientri sebelumnya

 

If e.KeyChar = Chr(13) Then

Call Koneksi()

CMD = New sqlCommand("Select * from tblpermintaan where no_permintaan='" & TextBox1.Text & "'", CONN)

DR = CMD.ExecuteReader

DR.Read()

If DR.HasRows Then

MsgBox("Nomor ini sudah terdata")

TextBox1.Clear()

Exit Sub

Else

ComboBox1.Focus()

End If

End If

End Sub

 

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

Call Kosongkan()

End Sub

 

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

Me.Close()

End Sub

 

Menghitung banyaknya barang yang diminta

 

Sub HitungBarang()

Dim x As Integer = 0

For baris As Integer = 0 To DGV.RowCount - 1

x = x + DGV.Rows(baris).Cells(5).Value

Label9.Text = x

Next

End Sub

 

Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged

 

Menampilkan data barang ke dalam datagrid dari pilihan dalam listbox1 (sebelah kanan)

 

Label11.Text = ListBox1.Text

Call Koneksi()

CMD = New sqlCommand("select * from tblbarang where nama_barang='" & Label11.Text & "'", CONN)

DR = CMD.ExecuteReader

DR.Read()

Label11.Text = DR.Item("kode_Barang")

Dim row As String() = New String() {Label11.Text}

DGV.Rows.Add(row)

Dim baris As Integer = Val(Label12.Text)

If DR.HasRows Then

On Error Resume Next

DGV.Rows(baris).Cells(1).Value = DR.Item("nama_barang")

DGV.Rows(baris).Cells(2).Value = DR.Item("lokasi")

DGV.Rows(baris).Cells(3).Value = DR.Item("stok")

DGV.CurrentCell = DGV(4, DGV.CurrentCell.RowIndex)

DGV.Focus()

SendKeys.Send("{up}")

Else

MsgBox("Kode barang tidak terdaftar")

End If

Label12.Text = Val(Label12.Text) + 1

Call TampilBarang()

TextBox2.Clear()

End Sub

 

Private Sub TextBox2_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox2.KeyPress

 

Mencari data barang dalam listbox1

 

If e.KeyChar = Chr(13) Then

Call Koneksi()

CMD = New SqlCommand("Select * from tblbarang where nama_barang like '%" & TextBox2.Text & "%' ORDER BY 2", CONN)

DR = CMD.ExecuteReader

ListBox1.Items.Clear()

Do While DR.Read

ListBox1.Items.Add(DR.Item("Nama_Barang"))

Loop

End If

End Sub

 

 

Private Sub DGV_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles DGV.KeyPress

Menghapus baris tertentu dalam transaksi permintaan barang

 

On Error Resume Next

If e.KeyChar = Chr(27) Then

DGV.Rows.RemoveAt(DGV.CurrentCell.RowIndex)

Call HitungBarang()

If DGV.RowCount - 1 = 0 Then

Label12.Text = 0

Else

Label12.Text = Val(Label12.Text) - 1

End If

End If

End Sub

 

Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged

Mencari data barang dalam listbox1

 

Call Koneksi()

CMD = New SqlCommand("Select * from tblbarang WHERE NAMA_BARANG LIKE '%" & TextBox2.Text & "%' order by 2", CONN)

DR = CMD.ExecuteReader

ListBox1.Items.Clear()

Do While DR.Read

ListBox1.Items.Add(DR.Item("Nama_Barang"))

Loop

End Sub

End Class

 

Gambar 7.19 Faktur Permintaan Barang

7.12 Form Pengeluaran Barang

Proses dalam transaksi pengeluaran barang adalah sebagai berikut:

1.              Memilih tanggal pengeluaran

2.              Memilih nomor permintaan

3.              Menyimpan data pengeluaran barang

 

Gambar 7.20 Form Pengeluaran Barang

Imports System.Data.SqlClient

 

Public Class Pengeluaran

 

Membuat nomor pengeluaran otomatis dengan pole KLyyMMdd + nomor urut

 

Sub NomorOtomatis()

Call Koneksi()

CMD = New SqlCommand("select * from tblpengeluaran where No_Pengeluaran in(select max(no_Pengeluaran) from tblpengeluaran)", CONN)

DR = CMD.ExecuteReader

DR.Read()

If Not DR.HasRows Then

TextBox1.Text = "KL" + Format(Now, "yyMMdd") + "01"

Else

If Microsoft.VisualBasic.Mid(DR.Item("no_Pengeluaran"), 3, 6) <> Format(Now, "yyMMdd") Then

TextBox1.Text = "KL" + Format(Now, "yyMMdd") + "01"

Else

TextBox1.Text = Microsoft.VisualBasic.Right(DR.Item("no_pengeluaran"), 8) + 1

TextBox1.Text = "KL" + TextBox1.Text

End If

End If

End Sub

 

Menampilkan nomor permintaan barang dalam combobox

 

Sub TampilPermintaan()

Call Koneksi()

CMD = New SqlCommand("Select * from tblpermintaan WHERE status_permintaan='DALAM PROSES'", CONN)

DR = CMD.ExecuteReader

ComboBox1.Items.Clear()

Do While DR.Read

ComboBox1.Items.Add(DR.Item("no_permintaan"))

Loop

End Sub

 

Sub Kosongkan()

ComboBox1.Text = ""

Label6.Text = ""

Label7.Text = ""

Label9.Text = ""

DGV.Columns.Clear()

TextBox1.Focus()

End Sub

 

Private Sub Pengeluaran_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Call Koneksi()

Call Kosongkan()

TextBox1.Enabled = False

Call NomorOtomatis()

Call TampilPermintaan()

End Sub

 

Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged

Menampilkan nama departemen dan pimpinan berdasarkan nomor permintaan barang

 

Call Koneksi()

CMD = New sqlCommand("Select Nama_departemen,pimpinan from tbldepartemen,tblpermintaan where tbldepartemen.kode_departemen=tblpermintaan.kode_departemen and tblpermintaan.no_permintaan='" & ComboBox1.Text & "'", CONN)

DR = CMD.ExecuteReader

DR.Read()

If DR.HasRows Then

Label6.Text = DR.Item("Nama_departemen")

Label7.Text = DR.Item("Pimpinan")

Else

MsgBox("Nomor permintaan tidak valid")

End If

 

 

Mencari dan menampilkan data permintaan barang kedalam datagrid

 

Call Koneksi()

CMD = New sqlCommand("Select tbldetailpermintaan.kode_barang,tblbarang.nama_barang,tbldetailpermintaan.tersedia,qty_minta,dikirim,status_permintaan from tblbarang,tbldetailpermintaan where tblbarang.kode_barang=tbldetailpermintaan.kode_barang and tbldetailpermintaan.no_permintaan='" & ComboBox1.Text & "'", CONN)

DR = CMD.ExecuteReader

DR.Read()

If DR.HasRows Then

Call Koneksi()

DA = New SqlDataAdapter("Select tbldetailpermintaan.kode_barang as Kode,tblbarang.nama_barang as [Nama Barang],tbldetailpermintaan.Tersedia,qty_minta as [Qty Minta],Dikirim,status_permintaan as Status from tblbarang,tbldetailpermintaan where tblbarang.kode_barang=tbldetailpermintaan.kode_barang and tbldetailpermintaan.no_permintaan='" & ComboBox1.Text & "'", CONN)

DS = New DataSet

DA.Fill(DS)

DGV.DataSource = DS.Tables(0)

Call HitungBarang()

Else

MsgBox("Nomor permintaan tidak valid")

End If

End Sub

 

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

Call Kosongkan()

End Sub

 

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

Me.Close()

End Sub

 

Menghitung banyaknya barang

 

Sub HitungBarang()

Dim x As Integer = 0

For baris As Integer = 0 To DGV.RowCount - 1

x = x + DGV.Rows(baris).Cells(4).Value

Label9.Text = x

Next

End Sub

 

Private Sub DGV_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles DGV.KeyPress

Menghapus baris tertentu dalam datagrid

 

On Error Resume Next

If e.KeyChar = Chr(27) Then

DGV.Rows.RemoveAt(DGV.CurrentCell.RowIndex)

Call HitungBarang()

End If

End Sub

End Class

 

Gambar 7.21 Faktur Pengeluaran Barang

7.13 Form Penerimaan Barang

Proses penerimaan barang dilakukan dengan cara sebagai berikut :

1.              Mengisi nomor nota dari supplier

2.              Memilih tangal penerimaan

3.              Memilih supplier dalam combo

4.              Memilih data barang dalam grid dan mengisi jumlah penerimaannya.

Gambar 7.22 Form Penerimaan Barang

Imports System.data.sqlclient

 

Public Class Penerimaan

 

Sub Kosongkan()

TextBox1.Clear()

ComboBox1.Text = ""

Label6.Text = ""

Label7.Text = ""

Label9.Text = ""

DGV.Columns.Clear()

TextBox1.Focus()

End Sub

 

 

Menampilkan data sipplier dalam combobox1

 

Sub TampilSupplier()

Call Koneksi()

CMD = New SqlCommand("Select * from tblSupplier", CONN)

DR = CMD.ExecuteReader

ComboBox1.Items.Clear()

Do While DR.Read

ComboBox1.Items.Add(DR.Item("kode_Supplier"))

Loop

End Sub

 

Menampilkan data barang dalam grid berupa combo

 

Sub DaftarBarang()

Call Koneksi()

DA = New SqlDataAdapter("Select Nama_Barang from tblbarang", CONN)

DS = New DataSet

DS.Clear()

DA.Fill(DS)

 

Dim cols As New DataGridViewComboBoxColumn

cols.DataSource = DS.Tables(0)

cols.DisplayMember = "Nama_Barang"

DGV.Columns.Add(cols)

cols.HeaderText = "Nama Barang"

cols.Width = 300

cols.MaxDropDownItems = 10

End Sub

 

Sub DataBarang()

Call DaftarBarang()

DGV.Columns.Add("Kode", "Kode Barang")

DGV.Columns.Add("Awal", "Stok Awal")

DGV.Columns.Add("Terima", "Qty Terima")

DGV.Columns.Add("Akhir", "Stok Akhir")

DGV.Columns(1).Visible = False

DGV.Columns(2).ReadOnly = True

DGV.Columns(4).ReadOnly = True

End Sub

 

Private Sub Penerimaan_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Call Koneksi()

Call Kosongkan()

Call TampilSupplier()

Call DataBarang()

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 DGV.Focus()

End Sub

 

Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged

Mencari data supplier

 

Call Koneksi()

CMD = New sqlCommand("Select * from tblSupplier where kode_Supplier='" & ComboBox1.Text & "'", CONN)

DR = CMD.ExecuteReader

DR.Read()

If DR.HasRows Then

Label6.Text = DR.Item("nama_Supplier")

Label7.Text = DR.Item("alamat")

Else

MsgBox("data tidak valid")

End If

End Sub

 

Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress

Mencari nomor penerimaan

 

If e.KeyChar = Chr(13) Then

Call Koneksi()

CMD = New sqlCommand("Select * from tblPenerimaan where no_Penerimaan='" & TextBox1.Text & "'", CONN)

DR = CMD.ExecuteReader

DR.Read()

If DR.HasRows Then

MsgBox("Nomor ini sudah terdata")

TextBox1.Clear()

Else

ComboBox1.Focus()

End If

End If

End Sub

 

 

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

Call Kosongkan()

Call DataBarang()

End Sub

 

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

Me.Close()

End Sub

 

Menghitung jumlah total barang yang diterima

 

Sub HitungBarang()

Dim x As Integer = 0

For baris As Integer = 0 To DGV.RowCount - 1

x = x + DGV.Rows(baris).Cells(3).Value

Label9.Text = x

Next

End Sub

 

 

Private Sub DGV_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles DGV.KeyPress

Menghapus transaksi di baris tertentu

 

On Error Resume Next

If e.KeyChar = Chr(27) Then

DGV.Rows.RemoveAt(DGV.CurrentCell.RowIndex)

Call HitungBarang()

End If

 

End Sub

 

Private Sub TextBox1_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.LostFocus

Call Koneksi()

CMD = New sqlCommand("Select * from tblPenerimaan where no_Penerimaan='" & TextBox1.Text & "'", CONN)

DR = CMD.ExecuteReader

DR.Read()

If DR.HasRows Then

MsgBox("Nomor ini sudah terdata")

TextBox1.Clear()

Else

ComboBox1.Focus()

End If

End Sub

End Class

 

7.14 Laporan Permintaan Barang

Laporan ini terdiri dari laporan harian, laporan periodik, laporan bulanan, laporan per departemen dan laporan per status permintaan.

Gambar 7.23 Form Laporan Permintaan Barang

Gambar 7.24 Laporan Permintaan Bulanan

 

 

Gambar 7.25 Laporan Permintaan Periodik

 

Gambar 7.26 Laporan Permintaan Per Departemen

 

Gambar 7.27 Laporan Permintaan Per Status

 

Imports System.data.sqlclient

 

Public Class LaporanPermintaan

 

Sub departemen()

Call Koneksi()

CMD = New SqlCommand("Select * from tbldepartemen", CONN)

DR = CMD.ExecuteReader

ListBox1.Items.Clear()

Do While DR.Read

ListBox1.Items.Add(DR.Item("nama_departemen"))

Loop

End Sub

 

Sub Status()

Call Koneksi()

CMD = New SqlCommand("Select distinct status_permintaan from tblpermintaan", CONN)

DR = CMD.ExecuteReader

ListBox2.Items.Clear()

Do While DR.Read

ListBox2.Items.Add(DR.Item("status_permintaan"))

Loop

End Sub

 

Private Sub LaporanPermintaan_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Call Koneksi()

Call departemen()

Call Status()

End Sub

 

 

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

 

CRV.SelectionFormula = "{tblpermintaan.tgl_permintaan}= DATE ('" & DTP1.Text & "')"

CRV.ReportSource = "permintaan harian.rpt"

CRV.RefreshReport()

 

End Sub

 

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

CRV.SelectionFormula = "({tblpermintaan.tgl_permintaan}) IN DATE('" & DTP2.Text & "') TO DATE ('" & DTP3.Text & "')"

CRV.ReportSource = "permintaan periodik.rpt"

CRV.RefreshReport()

 

End Sub

 

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

CRV.SelectionFormula = "month({tblpermintaan.tgl_permintaan})=(" & Month(DTP4.Text) & ") and year({tblpermintaan.tgl_permintaan}) =(" & Year(DTP4.Text) & ")"

CRV.ReportSource = "permintaan bulanan.rpt"

CRV.RefreshReport()

 

End Sub

 

Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged

CRV.SelectionFormula = "{tbldepartemen.nama_departemen}='" & ListBox1.Text & "'"

CRV.ReportSource = "permintaan per departemen.rpt"

CRV.RefreshReport()

 

End Sub

 

Private Sub ListBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox2.SelectedIndexChanged

CRV.SelectionFormula = "{tblpermintaan.status_permintaan}='" & ListBox2.Text & "'"

CRV.ReportSource = "permintaan per status.rpt"

CRV.RefreshReport()

 

End Sub

 

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click

CRV.SelectionFormula = "totext({tblpermintaan.tgl_permintaan})='" & DTP5.Text & "'"

CRV.ReportSource = "grafik permintaan.rpt"

CRV.RefreshReport()

 

End Sub

 

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click

CRV.SelectionFormula = "totext({tblpermintaan.tgl_permintaan})>='" & DTP6.Text & "' and totext({tblpermintaan.tgl_permintaan})<='" & DTP7.Text & "'"

CRV.ReportSource = "grafik permintaan.rpt"

CRV.RefreshReport()

 

End Sub

 

Private Sub Button6_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click

CRV.SelectionFormula = "month({tblpermintaan.tgl_permintaan})=(" & Month(DTP8.Text) & ") and year({tblpermintaan.tgl_permintaan}) =(" & Year(DTP8.Text) & ")"

CRV.ReportSource = "grafik permintaan.rpt"

CRV.RefreshReport()

 

End Sub

 

 

Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click

Me.Close()

End Sub

End Class

7.15 Laporan Pengeluaran Barang

Laporan pengeluaran barang terdiri dari laporan harian, mingguan, bulanan, per departemen dan laporan berbentuk grafik.

Gambar 7.28 Form Laporan Pengeluaran Barang

 

Gambar 7.29 Laporan Pengeluaran Per tanggal

Gambar 7.30 Laporan Pengeluaran Periodik

Imports System.data.sqlclient

 

Public Class LaporanPengeluaran

 

Sub departemen()

Call Koneksi()

CMD = New SqlCommand("Select * from tbldepartemen", CONN)

DR = CMD.ExecuteReader

ListBox1.Items.Clear()

Do While DR.Read

ListBox1.Items.Add(DR.Item("nama_departemen"))

Loop

End Sub

 

Private Sub LaporanPengeluaran_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Call Koneksi()

Call departemen()

End Sub

 

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

CRV.SelectionFormula = "totext({tblpengeluaran.tgl_pengeluaran})='" & DTP1.Text & "'"

CRV.ReportSource = "pengeluaran harian.rpt"

CRV.RefreshReport()

End Sub

 

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

CRV.SelectionFormula = "totext({tblpengeluaran.tgl_pengeluaran})>='" & DTP2.Text & "' and totext({tblpengeluaran.tgl_pengeluaran})<='" & DTP3.Text & "'"

CRV.ReportSource = "pengeluaran periodik.rpt"

CRV.RefreshReport()

 

End Sub

 

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

CRV.SelectionFormula = "month({tblpengeluaran.tgl_pengeluaran})=(" & Month(DTP4.Text) & ") and year({tblpengeluaran.tgl_pengeluaran}) =(" & Year(DTP4.Text) & ")" 'OK

CRV.ReportSource = "pengeluaran bulanan.rpt"

CRV.RefreshReport()

 

End Sub

 

Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged

CRV.SelectionFormula = "{tbldepartemen.nama_departemen}='" & ListBox1.Text & "'"

CRV.ReportSource = "pengeluaran per departemen.rpt"

CRV.RefreshReport()

 

End Sub

 

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click

CRV.SelectionFormula = "totext({tblpengeluaran.tgl_pengeluaran})='" & DTP5.Text & "'"

CRV.ReportSource = "grafik pengeluaran.rpt"

CRV.RefreshReport()

 

End Sub

 

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click

CRV.SelectionFormula = "totext({tblpengeluaran.tgl_pengeluaran})>='" & DTP6.Text & "' and totext({tblpengeluaran.tgl_pengeluaran})<='" & DTP7.Text & "'"

CRV.ReportSource = "grafik pengeluaran.rpt"

CRV.RefreshReport()

 

End Sub

 

Private Sub Button6_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click

CRV.SelectionFormula = "month({tblpengeluaran.tgl_pengeluaran})=(" & Month(DTP8.Text) & ") and year({tblpengeluaran.tgl_pengeluaran}) =(" & Year(DTP8.Text) & ")" 'OK

CRV.ReportSource = "grafik pengeluaran.rpt"

CRV.RefreshReport()

 

End Sub

 

Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click

Me.Close()

End Sub

End Class

7.16 Laporan Penerimaan Barang

Laporan penerimaan barang terdiri dari laporan harian, mingguan, bulanan, laporan per supplier dan laporan-laporan berbentuk grafik.

Gambar 7.31 Form Laporan Penerimaan Barang

Gambar 7.32 Laporan Penerimaan Per Tanggal

 

Gambar 7.33 Laporan Penerimaan Per Supplier

Imports System.data.sqlclient

 

 

Public Class LaporanPenerimaan

 

Sub Supplier()

Call Koneksi()

CMD = New SqlCommand("Select * from tblsupplier", CONN)

DR = CMD.ExecuteReader

ListBox1.Items.Clear()

Do While DR.Read

ListBox1.Items.Add(DR.Item("nama_supplier"))

Loop

End Sub

 

 

Private Sub LaporanPenerimaan_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Call Koneksi()

Call Supplier()

End Sub

 

 

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

CRV.SelectionFormula = "totext({tblpenerimaan.tgl_penerimaan})='" & DTP1.Text & "'"

CRV.ReportSource = "penerimaan harian.rpt"

CRV.RefreshReport()

End Sub

 

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

CRV.SelectionFormula = "totext({tblpenerimaan.tgl_penerimaan})>='" & DTP2.Text & "' and totext({tblpenerimaan.tgl_penerimaan})<='" & DTP3.Text & "'"

CRV.ReportSource = "penerimaan periodik.rpt"

CRV.RefreshReport()

End Sub

 

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

CRV.SelectionFormula = "month({tblpenerimaan.tgl_penerimaan})=(" & Month(DTP4.Text) & ") and year({tblpenerimaan.tgl_penerimaan}) =(" & Year(DTP4.Text) & ")"

CRV.ReportSource = "penerimaan bulanan.rpt"

CRV.RefreshReport()

End Sub

 

Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged

CRV.SelectionFormula = "{tblsupplier.nama_supplier}='" & ListBox1.Text & "'"

CRV.ReportSource = "penerimaan per supplier.rpt"

CRV.RefreshReport()

End Sub

 

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click

CRV.SelectionFormula = "totext({tblpenerimaan.tgl_penerimaan})='" & DTP5.Text & "'"

CRV.ReportSource = "grafik penerimaan.rpt"

CRV.RefreshReport()

End Sub

 

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click

 

CRV.SelectionFormula = "totext({tblpenerimaan.tgl_penerimaan})>='" & DTP6.Text & "' and totext({tblpenerimaan.tgl_penerimaan})<='" & DTP7.Text & "'"

CRV.ReportSource = "grafik penerimaan.rpt"

CRV.RefreshReport()

 

End Sub

 

Private Sub Button6_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click

CRV.SelectionFormula = "month({tblpenerimaan.tgl_penerimaan})=(" & Month(DTP8.Text) & ") and year({tblpenerimaan.tgl_penerimaan}) =(" & Year(DTP8.Text) & ")"

CRV.ReportSource = "grafik penerimaan.rpt"

CRV.RefreshReport()

 

End Sub

 

Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click

Me.Close()

End Sub

End Class

 

 

Gambar 7.34 Grafik Permintaan Barang

 

Gambar 7.35 Grafik Pengeluaran Barang

7.17 Laporan Rencana Order Barang

Laporan rencana order barang ini terbentuk berdasarkan permintaan dari beberapa departemen terhadap barang-barang tertentu yang pada saat itu stoknya tidak terpenuhi.

Gambar 7.36 Form Laporan Rencana Order Barang

 

Imports System.data.sqlclient

 

 

Public Class LaporanOrderBarang

 

Sub departemen()

Call Koneksi()

CMD = New SqlCommand("Select * from tbldepartemen", CONN)

DR = CMD.ExecuteReader

ListBox1.Items.Clear()

Do While DR.Read

ListBox1.Items.Add(DR.Item("nama_departemen"))

Loop

End Sub

 

 

Private Sub LaporanOrderBarang_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Call Koneksi()

Call departemen()

End Sub

 

 

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

CRV.SelectionFormula = "totext({tblrencanaorder.tanggal})='" & DTP1.Text & "'"

CRV.ReportSource = "order harian.rpt"

CRV.RefreshReport()

End Sub

 

 

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

CRV.SelectionFormula = "month({tblrencanaorder.tanggal})=(" & Month(DTP4.Text) & ") and year({tblrencanaorder.tanggal}) =(" & Year(DTP4.Text) & ")"

CRV.ReportSource = "order bulanan.rpt"

CRV.RefreshReport()

End Sub

 

Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged

CRV.SelectionFormula = "{tbldepartemen.nama_departemen}='" & ListBox1.Text & "'"

CRV.ReportSource = "order per departemen.rpt"

CRV.RefreshReport()

End Sub

 

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

Me.Close()

End Sub

End Class