Senin, 11 Januari 2016

APLIKASI PARKIR MENGGUNAKAN VB.NET


Selamat siang semua sobat blogger.

Hari ini saya mencoba untuk memberikan tutorial pembuatan aplikasi parkir menggunakan bahasa pemrograman vb.net . Disini saya menggunakan IDE Visual Studio 2013. 

Tapi terlebih dahulu yang harus sobat lakukan adalah merancang database yang akan digunakan untuk menampung data yang akan di inputkan dari aplikasi yang akan kita buat nantinya . Oke disini saya akan memberi contekan contoh database yang sudah saya buat untuk aplikasi kita nantinya. 

Sobat bisa melihat contoh gambar dibawah ini.



Setelah selesai merancang database seperti di atas, langkah selanjutny adalah untuk merancang aplikasi yang akan kita buat.

Sobat bisa menggunakan Visual Studio 2008, 2010 dan 2013.
Setelah terbuka klik "new project" kemudian klik "windows form" setelah itu klik oke.

Setelah terbuka mari kita rancang form1 yaitu untuk form login seperti dibawah ini.



Setelah selesai, double klick pada tombol/ button login yang sudah kita buat tadi. Kemudian paste-kan program dibawah ini :
--------------------------------------------------------------------------------------------------------------------------
Imports System.Data.OleDb
Imports System.Data.Odbc
Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        CNN = New OleDbConnection(KONEKSI)
        If CNN.State <> ConnectionState.Closed Then CNN.Close()
        CNN.Open()
        OLECMD = New OleDbCommand("SELECT * From login  WHERE username = '" & TextBox1.Text & _
                                   "' and password = '" & TextBox2.Text & "'", CNN)
        OLERDR = OLECMD.ExecuteReader
        If (OLERDR.Read()) Then
            Form5.Show()
            Me.Hide()
            TextBox1.Text = ""
            TextBox2.Text = ""
            TextBox1.Focus()
        Else
            MsgBox("Username & Password Anda Salah!", MsgBoxStyle.OkOnly, _
                   "Login gagal")
            TextBox1.Text = ""
            TextBox2.Text = ""
            TextBox1.Focus()
        End If
    End Sub

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

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    End Sub
End Class
--------------------------------------------------------------------------------------------------------------------------

Setelah langkah diatas selesai, langkah selanjutnya adalah kita akan merancang menu selanjutnya dari aplikasi kita ini , berikut contoh gambarnya seperti dibawah ini ya sobat :


Setelah selesai merancang copy pastekan code program dibawah ini :
--------------------------------------------------------------------------------------------------------------------------
Imports System.Data.OleDb
Imports System.Data.Odbc
Public Class Form2
    Sub KodeOtomatis()
        CNN = New OleDbConnection(KONEKSI)
        If CNN.State <> ConnectionState.Closed Then CNN.Close()
        CNN.Open()
        OLECMD = New OleDbCommand("select * from Table1 order by [No Antrian] desc", CNN)
        OLERDR = OLECMD.ExecuteReader
        OLERDR.Read()

        If Not OLERDR.HasRows Then
            TextBox2.Text = "000001"
        Else
            TextBox2.Text = Val(Microsoft.VisualBasic.Mid(OLERDR.Item("No Antrian").ToString, 5, 3)) + 1

            If Len(TextBox2.Text) = 1 Then
                TextBox2.Text = "00000" & TextBox2.Text & ""
            ElseIf Len(TextBox2.Text) = 2 Then
                TextBox2.Text = "0000" & TextBox2.Text & ""
            ElseIf Len(TextBox2.Text) = 3 Then
                TextBox2.Text = "000" & TextBox2.Text & ""
            End If
        End If
        TextBox3.Focus()
    End Sub
    Sub bersih()
        TextBox3.Text = ""
        ComboBox1.Text = ""
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If TextBox1.Text = "" Or TextBox2.Text = "" Or TextBox3.Text = "" Or TextBox5.Text = "" Or TextBox5.Text = "" Then
            MsgBox("Isi data dengan benar!!", MsgBoxStyle.Exclamation, "Kesalahan")
            Exit Sub
        End If
        CNN = New OleDbConnection(KONEKSI)
        If CNN.State <> ConnectionState.Closed Then CNN.Close()
        CNN.Open()
        OLECMD = New OleDbCommand("insert into Table1 ([No Antrian],[No Plat Polisi],[Jenis Kendaraan],[Jam Masuk],[Operator],[Tanggal]) values ('" & _
                                  TextBox2.Text & "','" & TextBox3.Text & "','" & ComboBox1.Text & "','" & TextBox5.Text & "','" & TextBox6.Text & "','" & TextBox1.Text & "')", CNN)

        x = OLECMD.ExecuteNonQuery
        If x = 1 Then
            MsgBox("Data berhasil di simpan", MsgBoxStyle.Information, "Informasi")
            Call bersih()
            Call KodeOtomatis()
        Else
            MsgBox("Gagal menyimpan data", MsgBoxStyle.Exclamation, "Kesalahan")
        End If
    End Sub

    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Call KodeOtomatis()
        TextBox5.Text = Format(Now, "HH:mm:ss")
        TextBox1.Text = Format(Now, "dd/MM/yyyy")
        ComboBox1.Items.Clear()
        ComboBox1.Items.Add("Motor")
        ComboBox1.Items.Add("Mobil")
        TextBox5.Text = 1000
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        TextBox5.Text = Format(Now, "HH:mm:ss")
        TextBox1.Text = Format(Now, "dd/MM/yyyy")
    End Sub

    Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
        Form5.Show()
        Me.Hide()
    End Sub

End Class
--------------------------------------------------------------------
Kemudian setelah form2 selesai dan sudah diberikan program, langkah selanjutnya adalah rancang form3 seperti gambar dibawah ini ya  :


lalu pastekan code program dibawah ini :
--------------------------------------------------------------------------------------------------------------------------
Imports System.Data.OleDb
Imports System.Data.Odbc
Public Class Form3
    Sub bersih()
        TextBox1.Text = ""
        TextBox2.Text = ""
        TextBox3.Text = ""
        TextBox4.Text = ""
        TextBox5.Text = ""
        TextBox6.Text = ""
        TextBox7.Text = ""
        TextBox8.Text = ""
        TextBox9.Text = ""
        TextBox10.Text = ""

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        CNN = New OleDbConnection(KONEKSI)
        If CNN.State <> ConnectionState.Closed Then CNN.Close()
        CNN.Open()
        OLECMD = New OleDbCommand("select * from Table1 where [No Antrian] = '" & TextBox2.Text & "'", CNN)
        OLERDR = OLECMD.ExecuteReader
        OLERDR.Read()

        If OLERDR.HasRows Then
            TextBox3.Text = OLERDR("No Plat Polisi")
            TextBox4.Text = OLERDR("Jenis Kendaraan")
            TextBox5.Text = OLERDR("Jam Masuk")
            TextBox1.Text = OLERDR("Tanggal")
            TextBox10.Text = OLERDR("Operator")
            TextBox6.Text = Form5.Label1.Text
            TextBox8.Text = "1000"

        Else
            MsgBox("Data Tidak Ditemukan….!", MsgBoxStyle.Exclamation, "Perhatian")
        End If
    End Sub

    Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        TextBox8.Text = "1000"
        TextBox2.Focus()

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        If TextBox1.Text = "" Then
            MsgBox("Silahkan Cari Data!!", MsgBoxStyle.Exclamation, "Kesalahan")
            Exit Sub
        End If
        Dim detik, menit, jam, second As Integer
        detik = DateDiff(DateInterval.Second, CDate(TextBox5.Text), CDate(TextBox6.Text))
        menit = DateDiff(DateInterval.Minute, CDate(TextBox5.Text), CDate(TextBox6.Text))
        jam = DateDiff(DateInterval.Hour, CDate(TextBox5.Text), CDate(TextBox6.Text))
        jam = detik / 3600
        menit = (detik Mod 3600) / 60
        second = (detik Mod 3600) Mod 60

        TextBox7.Text = jam & ":" & menit & ":" & second
        If jam > 3 Then
            TextBox9.Text = 2000
            If jam > 6 Then
                TextBox9.Text = 3000
            End If
        Else
            TextBox9.Text = 1000
        End If
        Label3.Text = TextBox3.Text
        Label7.Text = TextBox7.Text
        Label9.Text = TextBox9.Text
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        If TextBox2.Text = "" Then
            MsgBox("Isi data dengan benar!!", MsgBoxStyle.Exclamation, "Kesalahan")
            Exit Sub
        End If
        CNN = New OleDbConnection(KONEKSI)
        If CNN.State <> ConnectionState.Closed Then CNN.Close()
        CNN.Open()
        OLECMD = New OleDbCommand("Update Table1 Set [Jam Keluar]='" & TextBox6.Text & "' ,[Lama Parkir]='" & TextBox7.Text & "' ,[Biaya]='" & TextBox9.Text & "' Where [No Antrian]='" & TextBox2.Text & "'", CNN)
        x = OLECMD.ExecuteNonQuery
        If x = 1 Then
            MsgBox("Data berhasil di Simpan", MsgBoxStyle.Information, "Informasi")
            Call bersih()
            TextBox2.Focus()
        Else
            MsgBox("Gagal Menyimpan data", MsgBoxStyle.Exclamation, "Kesalahan")
        End If
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        If TextBox1.Text = "" Or TextBox2.Text = "" Or TextBox3.Text = "" Or TextBox4.Text = "" Or TextBox5.Text = "" Or TextBox6.Text = "" Or TextBox8.Text = "" Or TextBox10.Text = "" Then
            MsgBox("Isi data dengan benar!!", MsgBoxStyle.Exclamation, "Kesalahan")
            Exit Sub
        End If

        If MsgBox("Ingin menghapus data ?", MsgBoxStyle.YesNo, "Konfirmasi") = MsgBoxResult.Yes Then
            CNN = New OleDbConnection(KONEKSI)
            If CNN.State <> ConnectionState.Closed Then CNN.Close()
            CNN.Open()
            OLECMD = New OleDbCommand("Delete from Table1 Where [No Antrian] ='" & TextBox2.Text & "'", CNN)
            x = OLECMD.ExecuteNonQuery
        End If
        If x = 1 Then
            MsgBox("Data berhasil di hapus", MsgBoxStyle.Information, "Informasi")
            Call bersih()
            TextBox2.Focus()
        Else
            MsgBox("Gagal menghapus data", MsgBoxStyle.Exclamation, "Kesalahan")
        End If
    End Sub

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        Form5.Show()
        Me.Hide()
    End Sub

End Class
--------------------------------------------------------------------------------------------------------------------------


Setelah selelsai merancang form3, kita akan merancang form4 . Sobat bisa melihat contoh gambar dibawah ini :

Setelah itu masukan code program seperti dibawah ini :
--------------------------------------------------------------------------------------------------------------------------
Imports System.Data.OleDb
Imports System.Data.Odbc
Public Class Form4
    Sub OpenDB()
        Dim KONEKSI = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Achmad F Faiz\Documents\Visual Studio 2013\Projects\WindowsApplication2\WindowsApplication2\parkir.mdb"
        CNN = New OleDbConnection(KONEKSI)
        If CNN.State <> ConnectionState.Closed Then
            CNN.Open()
        End If
    End Sub
    Sub TampilTable1()
        OLEDA = New OleDbDataAdapter("select * from Table1", CNN)
        DS = New DataSet
        OLEDA.Fill(DS, "Table1")
        DataGridView1.DataSource = DS.Tables("Table1")
    End Sub
    Sub Hitung()
        Dim h As Integer
        h = DataGridView1.Rows.Count - 1
        TextBox2.Text = h
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Call OpenDB()
        Call TampilTable1()
        Call Hitung()
    End Sub

    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
        CNN = New OleDbConnection(KONEKSI)
        If CNN.State <> ConnectionState.Closed Then CNN.Close()
        CNN.Open()
        OLECMD = New OleDbCommand("select * from Table1 where [No Antrian] like'%" & TextBox1.Text & "%'", CNN)
        OLERDR = OLECMD.ExecuteReader
        OLERDR.Read()

        If OLERDR.HasRows Then
            OLEDA = New OleDbDataAdapter("select * from Table1 where [No Antrian] like'%" & TextBox1.Text & "%'", CNN)
            DS = New DataSet
            OLEDA.Fill(DS, "Ketemu")
            DataGridView1.DataSource = DS.Tables("Ketemu")
            DataGridView1.ReadOnly = True
        End If
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Form5.Show()
        Me.Hide()
    End Sub

    Private Sub Form4_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    End Sub
End Class
--------------------------------------------------------------------------------------------------------------------------
Sobat bisa lihat code program yang saya beri warna merah dan saya bold, itu adalah lokasi/directory dimana database yang sobat gunakan untuk aplikasi sobat ini. jadi sobat bisa merubah directory database sobat sesuai dengan komputer sobat ya .

YUP kita sudah berada di langkah terakhir , yaitu kita akan merancang form ke 5 yang akan kita gunakan untuk menu home dari aplikasi kita ini . Sobat bisa melihat dari gambar yang saya tampilkan dibawah ini ya :

kemudian masukan code program dibawah ini :
--------------------------------------------------------------------------------------------------------------------------
Imports System.ArgumentException

Public Class Form5
    Private Sub ParkirMasukToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ParkirMasukToolStripMenuItem.Click
        Form2.Show()
        Me.Hide()
    End Sub

    Private Sub ParkirKeluarToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ParkirKeluarToolStripMenuItem.Click
        Form3.Show()
        Me.Hide()
    End Sub

    Private Sub LihatDataToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LihatDataToolStripMenuItem.Click
        Form4.Show()
        Me.Hide()
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Label1.Text = Format(Now, "HH:mm:ss")
        Label2.Text = Format(Now, "dd/MM/yyyy")
    End Sub

    Private Sub Form5_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Label1.Text = Format(Now, "HH:mm:ss")
        Label2.Text = Format(Now, "dd/MM/yyyy")
    End Sub

    Private Sub KeluarToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles KeluarToolStripMenuItem.Click
        Form1.Show()
        Me.Hide()
    End Sub

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

    End Sub
End Class
--------------------------------------------------------------------------------------------------------------------------

Setelah selesai, kita kembali ke database yang sudah kita buat diatas tadi, buka table admin, dan beri id dan passwordnya seperti gambar dibawah atau terserah sobat mau isi apa id dan passwordnya, tapi disini saya memberi username dan passwordnya adalah "admin" :

Oke selesai, dan selamat mencoba ya sobat :)

Next
This is the most recent post.
Previous
This is the last post.

1 komentar:

  1. gagal bang,tutor tidak lengkap,modul gak ada,cara koneksi gak ada

    BalasHapus