Sabtu, 07 Maret 2015

Membuat Aplikasi Input Data Mahasiswa

Penjelasan :
Aplikasi ini bertujuan untuk menyimpan data mengenai mahasiswa dalam satu universitas / perguruan tinggi.

Screen Shoot :


Source Code :
Script Form1.vb
Imports System.Data.OleDb
Public Class Form1
    Dim kon As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\data_mahasiswa.accdb")
    Dim xReader As OleDbDataReader

Sub kosong()
        txtNim.Text = ""
        txtNama.Text = ""
        rbl.Checked = False
        rbp.Checked = False
        cbSmt.Text = ""
        txtTA.Text = ""
End Sub

Sub hidup()
        txtNim.Enabled = True
        txtNama.Enabled = True
        rbl.Checked = True
        rbp.Checked = True
        cbSmt.Enabled = True
        cbSmt.SelectedItem = 1
        txtTA.Enabled = True
        btnSimpan.Enabled = True
        btnEdit.Enabled = True
        btnHapus.Enabled = True
End Sub

Sub mati()
        txtNim.Enabled = False
        txtNama.Enabled = False
        rbl.Checked = False
        rbp.Checked = False
        cbSmt.Enabled = False
        txtTA.Enabled = False
        btnSimpan.Enabled = False
        btnEdit.Enabled = False
        btnHapus.Enabled = False
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'Data_mahasiswaDataSet1.tabel_mahasiswa' table. You can move, or remove it, as needed.
        Me.Tabel_mahasiswaTableAdapter1.Fill(Me.Data_mahasiswaDataSet1.tabel_mahasiswa)
        kon.Close()
        kon.Open()
        cbSmt.Items.Add("Satu")
        cbSmt.Items.Add("Dua")
        cbSmt.Items.Add("Tiga")
        cbSmt.Items.Add("Empat")
        cbSmt.Items.Add("Lima")
        cbSmt.Items.Add("Enam")
        cbSmt.Items.Add("Tujuh")
        cbSmt.Items.Add("Delapan")
        mati()
        btnTambah.Focus()
End Sub

Private Sub btnTambah_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTambah.Click
        hidup()
        txtNim.Focus()
End Sub

Private Sub btnSimpan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSimpan.Click
        If txtNim.Text = "" And txtNama.Text = "" And txtTA.Text = "" Then
            MsgBox("Masih ada Data yang kosong", MsgBoxStyle.Information, "Informasi")
        Else
            Dim jk As String = ""
            If rbl.Checked Then
                jk = "Laki-Laki"
            Else
                jk = "Perempuan"
            End If

            kon.Close()
            kon.Open()
            Dim sql As String = "INSERT INTO tabel_mahasiswa (NIM, Nama, Jenis_Kelamin, Semester, Tahun_Angkatan) VALUES ('" & txtNim.Text & "', '" & txtNama.Text & "', '" & jk & "', '" & cbSmt.Text & "', '" & txtTA.Text & "')"
            Dim eks = New OleDbCommand(sql, kon)
            eks.ExecuteNonQuery()
            kon.Close()
            MsgBox("Data Berhasil Disimpan", MsgBoxStyle.Information, "Informasi")
        End If
End Sub

Private Sub btnEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEdit.Click
        Dim jk As String = ""
        If rbl.Checked Then
            jk = "Laki-Laki"
        Else
            jk = "Perempuan"
        End If

        kon.Close()
        kon.Open()
        Dim sql As String = "UPDATE tabel_mahasiswa SET Nama = '" & txtNama.Text & "', Jenis_Kelamin = '" & jk & "', Semester = '" & cbSmt.SelectedItem & "', Tahun_Angkatan = '" & txtTA.Text & "'"
        Dim eks = New OleDbCommand(sql, kon)
        eks.ExecuteNonQuery()
        kon.Close()
        MsgBox("Data Berhasil Diubah", MsgBoxStyle.Information, "Informasi")
End Sub

Private Sub btnHapus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHapus.Click
        kon.Close()
        kon.Open()
        Dim sql As String = "DELETE FROM tabel_mahasiswa WHERE NIM='" & txtNim.Text & "'"
        Dim eks = New OleDbCommand(sql, kon)
        eks.ExecuteNonQuery()
        kon.Close()

        MsgBox("Data Berhasil Dihapus", MsgBoxStyle.Information, "Informasi")
        btnEdit.Enabled = False
        btnHapus.Enabled = False
End Sub
End Class