Saya akan menjelaskan aplikasi yang saya buat dengan Visual Basic dan Ms.Access. Aplikasi yang saya buat adalah tentang input data inventory untuk sebuah minimarket yang pada postingan sebelumnya telah saya buat, dan kali ini saya lebih mendetailkan aplikasi tersebut agar dapat digunakan dengan efektif.
Beberapa form yang saya buat:
1. Form Login: aplikasi ini hanya dapat diakses oleh karyawan bagian gudang dan manager cabang
2. Form Loading: untuk transisi proses dari Form Login ke Form Inventory
3. Form Inventory: berisi data-data yang berkaitan dengan inventory yang baru saja diinput
4. Form View: untuk melihat data yang terdapat di Ms.Access melalui data grid view
Fungsi yang terdapat dalam apliksi ini adalah:
1. Add: menambahkan data
2. Find: menampilkan data yang ingin kita cari
3. Edit: mengubah data. mengubah disini dikhususkan untuk jumlah barang
4. Delete: menghapus data
5. New: memulai kembali
6. View: melihat kumpulan data yang terdapat dalam database
7. Exit: keluar dari aplikasi
Berikut adalah form-formnya:
Berikut adalah Source Codenya:
1. Form Login
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.OleDb
Public Class Login
Dim koneksi As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\MATERI KULIAH\SMT 3\PB 2\dbpass.accdb"
Dim objekKoneksi As New OleDb.OleDbConnection(koneksi)
Dim xReader As OleDbDataReader
Private Sub btnlogin_Click(sender As Object, e As EventArgs) Handles btnlogin.Click
objekKoneksi.Close()
objekKoneksi.Open()
Dim Cmd As New OleDbCommand("SELECT * FROM Tlogin where Username ='" + username.Text + "'", objekKoneksi)
xReader = Cmd.ExecuteReader
If xReader.HasRows Then
xReader.Read()
username.Text = xReader("Username")
Loading.Show()
Else
MsgBox("Username atau Password salah")
username.Text = ""
password.Text = ""
username.Focus()
End If
xReader.Close()
End Sub
Private Sub Login_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
End Class
2. Form Loading
Public Class Loading
Private Sub Loading_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Timer1.Start()
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
If ProgressBar1.Value < 100 Then
ProgressBar1.Value += 2
Else ProgressBar1.Value = 100
Timer1.Stop()
MessageBox.Show("LOGIN SUKSES! ", "Pemberitahuan", MessageBoxButtons.OK, MessageBoxIcon.Information)
Inventory.Show()
Me.Hide()
End If
End Sub
End Class
3. Form Inventory
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.OleDb
Public Class Inventory
Dim koneksi As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\MATERI KULIAH\SMT 3\PB 2\dbminimarket.accdb"
Dim objekKoneksi As New OleDb.OleDbConnection(koneksi)
Dim xReader As OleDbDataReader
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
objekKoneksi.Close()
objekKoneksi.Open()
Dim tambah As String = "INSERT INTO Tinventory values('" & kodebrg.Text & "','" & namabrg.Text & "','" & jmlhbrg.Text & "','" & DateTimePicker1.Text & "','" & ComboBox1.Text & "','" & pengirim.Text & "')"
Dim oCmd = New OleDbCommand(tambah, objekKoneksi)
oCmd.ExecuteNonQuery()
objekKoneksi.Close()
MsgBox("Sukses!")
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim kode As String = InputBox("Masukan Kode Barang")
If Not Len(kode) = 0 Then
objekKoneksi.Close()
objekKoneksi.Open()
Dim cari As String = "SELECT * FROM Tinventory where KodeBarang='" + kode + "'"
Dim ocmd = New OleDbCommand(cari, objekKoneksi)
xReader = ocmd.ExecuteReader
If xReader.HasRows Then
xReader.Read()
kodebrg.Text = xReader("KodeBarang")
namabrg.Text = xReader("NamaBarang")
jmlhbrg.Text = xReader("JumlahBarang")
DateTimePicker1.Text = xReader("TanggalPenerimaan")
ComboBox1.Text = xReader("Cabang")
pengirim.Text = xReader("NamaPengirimBarang")
'Jika tidak ditemukan tampilkan pesan
Else
MsgBox("Inventory " + kode + " TIDAK ADA")
Exit Sub
End If
xReader.Close()
End If
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
objekKoneksi.Close()
objekKoneksi.Open()
Dim Ubah As String = "update Tinventory set JumlahBarang='" & jmlhbrg.Text & "' where KodeBarang='" & kodebrg.Text & "'"
Dim oCmd = New OleDbCommand(Ubah, objekKoneksi)
oCmd.ExecuteNonQuery()
objekKoneksi.Close()
MsgBox("Sukses")
End Sub
Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
Dim HAPUS As String
HAPUS = MsgBox("Anda Yakin?", vbInformation + vbYesNo, "Konfirmasi")
If HAPUS = vbYes Then
objekKoneksi.Close()
objekKoneksi.Open()
Dim sql As String = "DELETE FROM Tinventory where KodeBarang='" + kodebrg.Text + "'"
Dim Cmd As New OleDbCommand
objekKoneksi.Close()
objekKoneksi.Open()
Cmd.Connection = objekKoneksi
Cmd.CommandText = sql
Cmd.ExecuteNonQuery()
MsgBox("SUKSES")
End If
End Sub
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
Dim pesan As Integer
pesan = MsgBox("Selesai", vbInformation + vbYesNo, "Keluar")
If pesan = vbYes Then
Me.Close()
End If
Me.Close()
End Sub
Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
View.Show()
End Sub
Private Sub DateTimePicker1_ValueChanged(sender As Object, e As EventArgs) Handles DateTimePicker1.ValueChanged
End Sub
Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
End Sub
Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
kodebrg.Text = ""
namabrg.Text = ""
jmlhbrg.Text = ""
ComboBox1.Text = ""
pengirim.Text = ""
kodebrg.Focus()
End Sub
End Class
4. Form View
Public Class View
Private Sub View_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'DbminimarketDataSet11.Tinventory' table. You can move, or remove it, as needed.
Me.TinventoryTableAdapter1.Fill(Me.DbminimarketDataSet11.Tinventory)
'TODO: This line of code loads data into the 'DbminimarketDataSet.Tinventory' table. You can move, or remove it, as needed.
End Sub
End Class
Demikian aplikasi mengenai input data yang saya buat. Mohon maaf bila masih ada kekurangan.
Terima kasiiih