Aplikasi Penjualan Toko Game “Gamindo”
Saya menggunakan aplikasi dari
VB.NET 12 yang saya gunakan sebagai fasilitas membangun aplikasi ini, dan
fasilitas penyimpan tambahan yaitu File CSV (sebagai penyimpan data transaksi)
Sebuah penjualan/transaksi membutuhkan
fasilitas untuk menghitung, mencatat,
dan mencetak struk. Disinilah Saya akan menjelaskan aplikasi dari Aplikasi
Penjualan Toko Game “Gamindo” ini.
1. Dibutuhkan Login yang desainnya seperti ini :
Coding Form_Login:
Public Class Form_Login
Dim objKelasAdmin As New Class_Admin
Private Sub LinkLabel1_LinkClicked(sender As Object, e As LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked
Password.Show()
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If txtUsername.Text = "admin" And txtPassword.Text = Password.TextBox2.Text Then
objKelasAdmin.TampilFormMDI()
objKelasAdmin.TutupFormPassword()
Me.Hide()
MsgBox("Welcome", MessageBoxButtons.OK + MessageBoxIcon.Information,
"Konfirmasi")
Else
objKelasAdmin.PasswordSalah()
txtPassword.Text = ""
txtUsername.Text = ""
End If
End Sub
Private Sub Form_Login_Load(sender As Object, e As EventArgs) Handles MyBase.Load
txtPassword.PasswordChar = "•"
End Sub
End Class
2. Apa bila kita mengklik LinkLabel1 maka akan muncul Form Password, desainnya seperti ini:
Setelah itu,
apabila kita klik Copy, Username dan Password secara otomatis ter-copy ke Form
Login.
Coding Password:
Public Class Password
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Form_Login.txtUsername.Text =
TextBox1.Text
Form_Login.txtPassword.Text =
TextBox2.Text
MsgBox("Berhasil
Di Copy !", MessageBoxButtons.OK + MessageBoxIcon.Information,
"Konfirmasi")
End Sub
End Class
3. Lalu Muncul MDI_Form Seperti ini:
Apabila kita mengklik MenuStrip
Tersebut akan terjadi seperti ini
Shopping = Membuka Form_Penjualan
View = Muncul 4 SubMenu yaitu Cascade, Horizontally, Vertically, dan Arrange Icon
Exit = untuk keluar/end
View = Muncul 4 SubMenu yaitu Cascade, Horizontally, Vertically, dan Arrange Icon
Exit = untuk keluar/end
Coding MDI_Form:
Public Class MDI_Form
Private Sub
PenjualanToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles PenjualanToolStripMenuItem.Click
Dim frmPenjualan As New Form_Penjualan
frmPenjualan.MdiParent = Me
frmPenjualan.Show()
frmPenjualan.txtItemName.Focus()
End Sub
Private Sub ExitToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles
ExitToolStripMenuItem.Click
End
End Sub
Private Sub HorizontalToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles
HorizontalToolStripMenuItem.Click
Me.LayoutMdi(MdiLayout.TileHorizontal)
End Sub
Private Sub CascadeToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles
CascadeToolStripMenuItem.Click
Me.LayoutMdi(MdiLayout.Cascade)
End Sub
Private Sub VerticalToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles
VerticalToolStripMenuItem.Click
Me.LayoutMdi(MdiLayout.TileVertical)
End Sub
Private Sub ArrangeIconToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles
ArrangeIconToolStripMenuItem.Click
Me.LayoutMdi(MdiLayout.ArrangeIcons)
End Sub
Private Sub MDI_Form_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
End Class
4. Jika kita mengklik Shopping akan muncul Form_Penjualan Seperti ini:
Disitu kita
dapat melakukan:
·
Browse Data CSV
·
Menginput Nama Barang dan Kuantitas yang
diinginkan, serta muncul Total
·
Shopping = Memasukan Textbox Nama item, Qty,
Item Code, Price, dan Total ke DataGridView1
·
Payment = Mencetak Struk pembayaran ke PDF
(Sehingga dapat di print)
·
Refresh, menghapus textbox Input
·
Delete, Menghapus data di DataGridView1
·
Save To CSV, Melakukan Save ke CSV setelah data
dimasukkan
·
Save to Text, Melakukan Cetakan Pembelian ke
NotePad/.Text (Sehingga dapat di print)
·
Find, Dapat mencari kata yang diinginkan di
DataGridView1
·
Quit, Keluar dari Form_Penjualan
Coding Form_Penjualan: (Lumayan Panjang)
Public Class Form_Penjualan
Dim objKelasAdmin As New Class_Admin
Dim tinggi As Double = 0
Dim Kode_Barcode() As String = {"2001", "2002", "2003", "2004", "3001", "4001", "5001", "6001", "7001", "8001"}
Dim Nama_Barang() As String = {"ps1", "ps2", "ps3", "ps4", "gameboy", "stick", "kaset", "hdmi", "hardisk", "tv"}
Dim Judul_Kolom() As String = {"Nama Brang", "Kode Barang", "Harga", "Kuantitas", "Total"}
Dim tbl_csv As New DataTable
Dim data() As String
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
txtItemName.Focus()
Tanggal.Text = DateAndTime.Now
For i As Integer = 0 To 4
tbl_csv.Columns.Add(Judul_Kolom(i))
Next
For a As Integer = 0 To 9
ItemCode.Items.Add(Kode_Barcode(a))
Next
End Sub
Private Sub TextBox4_TextChanged(sender As Object, e As EventArgs) Handles
txtQuantity.TextChanged
If Not Len(txtQuantity.Text) = 0 Then
txtTotal.Text =
Val(Val(txtPrice.Text) * Val(txtQuantity.Text))
ElseIf txtQuantity.Text = "" Then
txtTotal.Text = ""
End If
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
ItemCode.Text = ""
txtItemName.Text = ""
txtPrice.Text = ""
txtQuantity.Text = ""
txtTotal.Text = ""
txtItemName.Focus()
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
If txtItemName.Text = "" Or txtPrice.Text = "" Or txtQuantity.Text = "" Or txtTotal.Text = "" Or ItemCode.Text = "" Then
MessageBox.Show("Isikan Data dengan Lengkap !", "Konfirmasi", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Exit Sub
End If
If TextBox1.Text = "" Then
MessageBox.Show("Pilih File CSV !", "Konfirmasi",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Exit Sub
End If
If IO.File.Exists(TextBox1.Text) = False Then
MessageBox.Show("Path/File not found !", "Konfirmasi", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Exit Sub
End If
Dim Var5 As String
Dim Var4 As String
Dim Var3 As String
Dim Var2 As String
Dim Var1 As String
Dim noFile As Short
noFile = FreeFile()
FileOpen(noFile, TextBox1.Text,
OpenMode.Append)
Var1 = txtItemName.Text
Var2 = ItemCode.Text
Var3 = txtPrice.Text
Var4 = txtQuantity.Text
Var5 = txtTotal.Text
WriteLine(1, Var1, Var2, Var3, Var4,
Var5)
FileClose(1)
'load
data ke datatable
Dim tbl_csv As New DataTable
Dim data() As String
Dim separator As String = ","
Using csv As New IO.StreamReader(TextBox1.Text)
data = Split(csv.ReadLine(),
separator)
tbl_csv.Columns.Add("Nama Brang")
tbl_csv.Columns.Add("Kode Barang")
tbl_csv.Columns.Add("Harga")
tbl_csv.Columns.Add("Kuantitas")
tbl_csv.Columns.Add("Total")
tbl_csv.Rows.Add(data)
Do While csv.EndOfStream = False
data = Split(csv.ReadLine(),
separator)
tbl_csv.Rows.Add(data)
Loop
End Using
DataGridView1.DataSource = Nothing
DataGridView1.Columns.Clear()
DataGridView1.DataSource = tbl_csv
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Me.Close()
End Sub
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
If TextBox1.Text = "" Then
MessageBox.Show("Pilih File CSV !", "Konfirmasi",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Exit Sub
End If
If IO.File.Exists(TextBox1.Text) = False Then
MessageBox.Show("Path/File not found !", "Konfirmasi", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Exit Sub
End If
tinggi = 0
With PrintDocument1
.PrinterSettings.DefaultPageSettings.Landscape
= False
.Print()
End With
End Sub
Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
Using opn As New OpenFileDialog
With opn
.Filter = "CSV|*.csv|All Files|*.*"
.Multiselect = False
If .ShowDialog = Windows.Forms.DialogResult.Cancel Then Exit Sub
TextBox1.Text = .FileName
End With
End Using
End Sub
Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
If TextBox1.Text = "" Then
MessageBox.Show("Pilih File CSV !", "Konfirmasi",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Exit Sub
End If
If IO.File.Exists(TextBox1.Text) = False Then
MessageBox.Show("Path/File not found !", "Konfirmasi", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Exit Sub
End If
Dim separator As String = ","
'load
data ke datatable
Using csv As New IO.StreamReader(TextBox1.Text)
data = Split(csv.ReadLine(),
separator)
tbl_csv.Rows.Add(data)
'add
data
Do While csv.EndOfStream = False
data = Split(csv.ReadLine(),
separator)
tbl_csv.Rows.Add(data)
Loop
End Using
DataGridView1.DataSource = Nothing
DataGridView1.Columns.Clear()
DataGridView1.DataSource = tbl_csv
End Sub
Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
If IO.File.Exists(DataGridView1.DataSource) = False Then
MessageBox.Show("Import Data !", "Konfirmasi",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Exit Sub
End If
If TextBox1.Text = "" Then
MessageBox.Show("Pilih File CSV !", "Konfirmasi",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Exit Sub
End If
If txtItemName.Text = "" Or txtPrice.Text = "" Or txtQuantity.Text = "" Or txtTotal.Text = "" Or ItemCode.Text = "" Then
MessageBox.Show("Isikan Data dengan Lengkap !", "Konfirmasi", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Exit Sub
End If
'save
gridview to csv
Dim fileName As String = ""
Using sve As New SaveFileDialog
With sve
.Filter = "CSV|*.csv|All Files|*.*"
If .ShowDialog = Windows.Forms.DialogResult.Cancel Then Exit Sub
fileName = .FileName
End With
End Using
Dim data As String = ""
Dim separator As String = ","
Using txt As New IO.StreamWriter(fileName, False)
Dim table_source As New DataTable
table_source = TryCast(DataGridView1.DataSource,
DataTable)
For Each row As DataRow In table_source.Rows
Try
txt.WriteLine(Join(row.ItemArray, separator))
Catch ex As Exception
End Try
Next
MessageBox.Show("Data Saved To : " +
fileName, "Konfirmasi", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Using
End Sub
Private Sub PrintDocument1_PrintPage(sender As Object, e As Printing.PrintPageEventArgs)
Handles
PrintDocument1.PrintPage
tinggi += 10
e.Graphics.DrawString("GAMINDO - TOKO GAME", New Drawing.Font("verdana", 8), Brushes.Black, 2, tinggi)
tinggi += 10
e.Graphics.DrawString("Jalan. Margonda Raya, Depok", New Drawing.Font("verdana", 8), Brushes.Black, 2, tinggi)
tinggi += 10
e.Graphics.DrawString("0821-3300-9696", New Drawing.Font("verdana", 8),
Brushes.Black, 2, tinggi)
tinggi += 10
e.Graphics.DrawString("--------------------------------------------------------------------", New Drawing.Font("verdana", 8), Brushes.Black, 2, tinggi)
For row As Integer = 0 To DataGridView1.Rows.Count - 2
tinggi += 10
e.Graphics.DrawString(DataGridView1.Rows(row).Cells(0).Value.ToString +
vbTab + DataGridView1.Rows(row).Cells(1).Value.ToString + vbTab +
DataGridView1.Rows(row).Cells(2).Value.ToString + vbTab + DataGridView1.Rows(row).Cells(3).Value.ToString
+ vbTab + DataGridView1.Rows(row).Cells(4).Value.ToString, New Drawing.Font("verdana", 8),
Brushes.Black, 2, tinggi)
Next
tinggi += 10
e.Graphics.DrawString("--------------------------------------------------------------------", New Drawing.Font("verdana", 8), Brushes.Black, 2, tinggi)
tinggi += 10
e.Graphics.DrawString(DateAndTime.Now, New Drawing.Font("verdana", 8),
Brushes.Black, 2, tinggi)
tinggi += 10
e.Graphics.DrawString("Terimakasih Atas Kunjungan Anda, Semoga Datang
Kembali", New Drawing.Font("verdana", 8),
Brushes.Black, 2, tinggi)
End Sub
Private Sub TextBox6_TextChanged(sender As Object, e As EventArgs) Handles
TextBox6.TextChanged
Dim xloop1 As Integer
Dim sPola As String
Dim sbuka As String
Dim SBetul As Boolean
sPola = TextBox6.Text + "*"
For xloop1 = 1 To DataGridView1.RowCount - 1
sbuka = DataGridView1.Rows(xloop1 -
1).Cells(0).Value
SBetul = UCase(sbuka) Like UCase(sPola)
If SBetul = True Then
DataGridView1.CurrentCell =
DataGridView1.Item(0, xloop1 - 1)
Exit
Sub
End If
Next
End Sub
Private Sub Button9_Click(sender As Object, e As EventArgs) Handles Button9.Click
If TextBox1.Text = "" Then
MessageBox.Show("Pilih File CSV !", "Konfirmasi",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Exit Sub
End If
If IO.File.Exists(TextBox1.Text) = False Then
MessageBox.Show("Path/File not found !", "Konfirmasi", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Exit Sub
End If
If DataGridView1.CurrentRow.Index <>
DataGridView1.NewRowIndex Then
DataGridView1.Rows.RemoveAt(DataGridView1.CurrentRow.Index)
ElseIf DataGridView1.CurrentRow.Index = 0 Then
MsgBox("Data Belum Diinput")
Else
MsgBox("Pilih Baris yang ingin Dihapus")
End If
End Sub
Private Sub txtItemName_TextChanged(sender As Object, e As EventArgs) Handles
txtItemName.TextChanged
If txtItemName.Text = "" Then
ItemCode.Text = ""
txtPrice.Text = ""
txtQuantity.Text = ""
txtTotal.Text = ""
ElseIf txtItemName.Text = "ps1" Then
ItemCode.Text = Kode_Barcode(0)
txtPrice.Text = "1000000"
ElseIf txtItemName.Text = "ps2" Then
ItemCode.Text = Kode_Barcode(1)
txtPrice.Text = "2000000"
ElseIf txtItemName.Text = "ps3" Then
ItemCode.Text = Kode_Barcode(2)
txtPrice.Text = "3000000"
ElseIf txtItemName.Text = "ps4" Then
ItemCode.Text = Kode_Barcode(3)
txtPrice.Text = "6000000"
ElseIf txtItemName.Text = "gameboy" Then
ItemCode.Text = Kode_Barcode(4)
txtPrice.Text = "500000"
ElseIf txtItemName.Text = "stick" Then
ItemCode.Text = Kode_Barcode(5)
txtPrice.Text = "250000"
ElseIf txtItemName.Text = "kaset" Then
ItemCode.Text = Kode_Barcode(6)
txtPrice.Text = "200000"
ElseIf txtItemName.Text = "hdmi" Then
ItemCode.Text = Kode_Barcode(7)
txtPrice.Text = "450000"
ElseIf txtItemName.Text = "hardisk" Then
ItemCode.Text = Kode_Barcode(8)
txtPrice.Text = "600000"
ElseIf txtItemName.Text = "tv" Then
ItemCode.Text = Kode_Barcode(9)
txtPrice.Text = "4000000"
End If
End Sub
Private Sub ItemCode_SelectedIndexChanged(sender As Object, e As EventArgs) Handles
ItemCode.SelectedIndexChanged
Dim x As String
x = ItemCode.Text
Select Case x
Case 2001
txtItemName.Text =
Nama_Barang(0)
txtPrice.Text = "1000000"
Case 2002
txtItemName.Text =
Nama_Barang(1)
txtPrice.Text = "2000000"
Case 2003
txtItemName.Text = Nama_Barang(2)
txtPrice.Text = "3000000"
Case 2004
txtItemName.Text =
Nama_Barang(3)
txtPrice.Text = "6000000"
Case 2005
txtItemName.Text = Nama_Barang(4)
txtPrice.Text = "500000"
Case 2006
txtItemName.Text =
Nama_Barang(5)
txtPrice.Text = "250000"
Case 2007
txtItemName.Text =
Nama_Barang(6)
txtPrice.Text = "200000"
Case 2008
txtItemName.Text =
Nama_Barang(7)
txtPrice.Text = "450000"
Case 2009
txtItemName.Text =
Nama_Barang(8)
txtPrice.Text = "600000"
Case 2010
txtItemName.Text =
Nama_Barang(9)
txtPrice.Text = "4000000"
End Select
End Sub
Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click
If IO.File.Exists(DataGridView1.DataSource) = False Then
MessageBox.Show("Import Data !", "Konfirmasi",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Exit Sub
End If
If txtItemName.Text = "" Or txtPrice.Text = "" Or txtQuantity.Text = "" Or txtTotal.Text = "" Or ItemCode.Text = "" Then
MessageBox.Show("Isikan Data dengan Lengkap !", "Konfirmasi", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Exit Sub
End If
Dim Var5 As String
Dim Var4 As String
Dim Var3 As String
Dim Var2 As String
Dim Var1 As String
Dim noFile As Short
noFile = FreeFile()
Var1 = txtItemName.Text
Var2 = ItemCode.Text
Var3 = txtPrice.Text
Var4 = txtQuantity.Text
Var5 = txtTotal.Text
SaveFileDialog1.Filter = "Text Files|*.txt|All Files |*."
SaveFileDialog1.ShowDialog()
FileOpen(noFile,
SaveFileDialog1.FileName, OpenMode.Output)
PrintLine(noFile, "GAMINDO - TOKO GAME" & vbCrLf & "Jalan.
Margonda Raya, Depok" & vbCrLf & "0821-8888-9696"
& vbCrLf & vbCrLf & "Nama
Barang" & vbTab & vbTab
& ": " & Var1 & vbCrLf & "Kode Barang" &
vbTab & vbTab & ": " & Var2 & vbCrLf & "Harga Barang"
& vbTab & vbTab & ": " & Var3 & vbCrLf & "Kuantitas" &
vbTab & vbTab & ": " & Var4 & vbCrLf & "Total" &
vbTab & vbTab & vbTab & ":
" & Var5 & vbCrLf & vbCrLf
& "Terimakasih atas Transaksinya,
Semoga Datang Kembali")
FileClose()
MessageBox.Show("Data Saved To : " +
SaveFileDialog1.FileName, "Konfirmasi", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Sub
End Class
5. Saya juga membuat Class untuk admin, seperti ini Coding Class_Admin:
Public Class Class_Admin
Public Sub TampilPassword()
Password.Show()
End Sub
Public Sub TutupFormPassword()
Password.Hide()
End Sub
Public Sub KlikPrint()
MsgBox("Data
sukses diprint, Terimakasih")
End Sub
Public Sub PasswordSalah()
MsgBox("Harap
Masukan Password Dengan Benar", MsgBoxStyle.OkOnly + MsgBoxStyle.Exclamation, "Perhatian")
End Sub
Public Sub TampilFormMDI()
MDI_Form.Show()
End Sub
Public Sub TampilLogin()
Form_Login.Show()
End Sub
Public Sub TutupFormMDI()
MDI_Form.Hide()
End Sub
End Class
Untuk
Mempermudah melihat codingnya File download nya dapat dicoba langsung DISINI
Sekian
Aplikasi Dari saya, Terimakasih atas partisipasinya.