Sabtu, 14 Januari 2017

Aplikasi Administrator Pendaftaran Turnament Futsal

Assalammualaikum pada postingan kali ini gue bakal bikin program di Visual Studio dan program ini akan terhubung ke database (Ms.Access), Program ini tentang aplikasi untuk administrator "Pendaftaran Turnament Futsal", Aplikasi ini hanya bisa di gunakan oleh admin saja. Cukup penjelasan dan basa-basinya kita langsung saja ke pembuataannya oke.

Pertama kalian harus membuat beberapa form disini gue membuat 3 form dan yg akan terhubung dengan database ada 1 form, oke pertama buat form seperti ini :


Form Pertama


Form Kedua


Form Ketiga


Oke desain sudah selesai sekarang kita buat databasenya dahulu, Disini gue akan buat satu database :

 


Selesah itu pilih data sheet view lalu isikan database tadi seperti ini :



 Gimana ? Susah ? Belom pusing kan ? Belom lah ya source codenya kan belom hehe, Lanjutin ya desain sudah, database sudah, sekarang kita ke source code deh. source code yg gue kasih bakal ngurut kaya desain form diatas, Oke nih Source codenya :
Form Pertama :
Public Class Form1

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        form2.Show()
        Me.Hide()
    End Sub

    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        Dim x = MsgBox("Are You Sure?", MsgBoxStyle.YesNo + MsgBoxStyle.Question, "Confirmation")
        If x = vbYes Then
            Me.Close()
            form2.Close()
            Form10.Close()
            'End
        End If
    End Sub
End Class
Form Kedua :

Public Class form2
    Dim id, pw
    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Form1.Show()
        Me.Close()
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        id = TextBox1.Text = "admin"
        pw = TextBox2.Text = "123456"
        If id = True And pw = True Then
            Form10.Show()
            Me.Close()
        Else
            id = False Or pw = False
            MessageBox.Show("ID ATAU PASSWORD YANG ANDA MASUKAN SALAH !!", "Warning", MessageBoxButtons.OK)
            TextBox1.Focus()
            TextBox1.Clear()
            TextBox2.Clear()
        End If
    End Sub
End Class


Form Ketiga :

Imports System.Data.OleDb
Public Class Form10
    Dim simpan As String

    Private Sub jalankansql(ByVal sQl As String)
        konek()
        Dim objcmd As New OleDb.OleDbCommand
        Try
            objcmd.Connection = conn
            objcmd.CommandType = CommandType.Text
            objcmd.CommandText = sQl
            objcmd.ExecuteNonQuery()
            objcmd.Dispose()
            MessageBox.Show("Data Berhasil Disimpan", " ", MessageBoxButtons.OK)
        Catch ex As Exception
            MessageBox.Show("Tidak Bisa Menyimpan Data ke Database", " ", MessageBoxButtons.OK)
        End Try
    End Sub

    Private Sub ShowData()
        konek()
        Dim str As String = "Select Nomor_Pendaftar as [Nomor Pendaftar], Nama_Team as [Nama Team], Nama_Coach as [Nama Coach] from nyusaindahlu ORDER By Nomor_Pendaftar"
        DA = New OleDb.OleDbDataAdapter(str, conn)
        DS = New DataSet
        DS.Clear()
        DA.Fill(DS, "nyusaindahlu")
        DataGridView1.DataSource = DS.Tables("nyusaindahlu")
        DA.Dispose()
        DS.Dispose()
        conn.Close()
    End Sub

    Public Sub clear()
        TextBox1.Text = ""
        TextBox2.Text = ""
        TextBox3.Text = ""
        ShowData()
    End Sub

    Private Sub isiTextBox()
        Dim i As Integer
        i = DataGridView1.CurrentRow.Index
        TextBox1.Text = DataGridView1.Item(0, i).Value
        TextBox2.Text = DataGridView1.Item(1, i).Value
        TextBox3.Text = DataGridView1.Item(2, i).Value
    End Sub

    Private Sub Form10_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        ShowData()
        konek()
        isiTextBox()
        clear()
    End Sub


    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Me.Close()
        form2.Show()
    End Sub

    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        conn.Close()
        conn.Open()
        If TextBox2.Text = "" Or TextBox3.Text = "" Then
            MessageBox.Show("Data Belum Lengkap", " ", MessageBoxButtons.OK)
            Exit Sub
        End If

        simpan = "INSERT INTO nyusaindahlu (Nama_Team, Nama_Coach) VALUES ('" & TextBox2.Text & "','" & TextBox3.Text & "') "
        jalankansql(simpan)
        ShowData()
        clear()
        Exit Sub
    End Sub

    Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
        Dim hapussql As String
        Dim pesan
        pesan = MsgBox("Apakah Anda Yakin Akan Menghapus Nomor_Pendaftar " + TextBox1.Text + " ? ", vbExclamation + vbYesNo, "Attention!")
        If pesan = vbNo Then Exit Sub
        hapussql = "DELETE FROM nyusaindahlu WHERE Nomor_Pendaftar = " & TextBox1.Text & ""
        jalankansql(hapussql)
        Me.Cursor = Cursors.WaitCursor
        clear()
        ShowData()
        Me.Cursor = Cursors.Default
    End Sub

    Private Sub DataGridView1_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
        isiTextBox()
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Dim x As String = TextBox1.Text
        conn.Close()
        conn.Open()

        CMD = New OleDbCommand("SELECT * FROM nyusaindahlu where Nomor_Pendaftar like '%" + x + "%'", conn)
        RD = CMD.ExecuteReader
        RD.Read()
        If RD.HasRows Then
            DA = New OleDbDataAdapter("select * from nyusaindahlu where Nomor_Pendaftar like '%" + x + "%'", conn)
            DS = New DataSet
            DA.Fill(DS, "Ketemu")
            DataGridView1.DataSource = DS.Tables("Ketemu")
            DataGridView1.ReadOnly = True
            TextBox1.Text = ""
            TextBox1.Focus()
        Else
            TextBox1.Text = "Data Tidak Ada"
            TextBox1.Text = ""
            TextBox1.Focus()
        End If
        RD.Close()
    End Sub
End Class


Pusing ngga ? Pasti pusing tapi gapapa wajar efek sampingnya itu hehe, Desain sudah, database sudah, source code sudah, eh tar dulu masih ada dua langkah tambahan lagi nih tapi tenang sebentar lagi selesai ko dua langkah tambahan ini juga ngga terlalu ribet jadi jangan nyerah dulu hehehe. Oke langkah pertama adalah menambahkan module di program visual studio kalian, caranya ? nih gue kasih caranya :





Nah selanjutnya isikan Sourcode seperti dibawah ini : 

Imports System.Data.OleDb
Imports System.Data
Module Module1
    Public conn As OleDbConnection
    Public CMD As OleDbCommand
    Public DS As New DataSet
    Public DA As OleDbDataAdapter
    Public RD As OleDbDataReader
    Public lokasidb As String

    Public Sub konek()
        lokasidb = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & AppPath() & "\UAS.accdb"
        'lokasidb = AppPath() & "\UAS.accdb"
        conn = New OleDbConnection(lokasidb)
        If conn.State = ConnectionState.Closed Then
            conn.Open()
        End If
    End Sub

    Public Function AppPath() As String
        Return System.AppDomain.CurrentDomain.BaseDirectory()
    End Function
End Module



Yeeeeeee selesai juga, nih hasil RUN nya yaa braaadeeeer :




Tidak ada komentar:

Posting Komentar