• Twitter
  • Facebook
  • Google+
  • Instagram
  • Youtube

Kamis, 22 Desember 2011

Aplikasi pengolahan buku menggunakan vb.net 2008 dengan database access.


Ini adalah salah satu progam pengolahan data buku sederhana yang saya buat menggunakan vb.net 2008 dengan database acces

dan source kodenya :
Public Class frmBarang
    Dim SQL As String
    Dim Proses As New clskoneksi
    Dim tblbuku As DataTable
    Public MyListItem As ListViewItem
    Sub HeaderBuku()
        lstBuku.Columns.Add("NO", 100, HorizontalAlignment.Right)
        lstBuku.Columns.Add("id_buku", 100, HorizontalAlignment.Right)
        lstBuku.Columns.Add("judul_buku", 200, HorizontalAlignment.Center)
        lstBuku.Columns.Add("pengarang", 100, HorizontalAlignment.Left)
        lstBuku.Columns.Add("penerbit", 100, HorizontalAlignment.Left)
        lstBuku.Columns.Add("tahun", 100, HorizontalAlignment.Center)
        lstBuku.Columns.Add("kategori", 100, HorizontalAlignment.Right)
    End Sub
    Sub Tampil()
        Dim i As Integer
        Dim urut As Integer
        Dim jml As Double
        urut = 1
        jml = 0
        Try
            If lstBuku.Items.Count > 0 Then
                lstBuku.Clear()
            End If
            lstBuku.View = View.Details
            Call HeaderBuku()
            If txtCari.Text <> "" Then
                tblbuku = Proses.ExecuteQuery("Select * from [buku] Where judul_buku='" & txtCari.Text & "' order by judul_buku asc")
            Else
                tblbuku = Proses.ExecuteQuery("Select * from [buku] order by judul_buku asc")
            End If
            For i = 0 To tblbuku.Rows.Count - 1
                With tblbuku.Rows(i)
                    MyListItem = lstBuku.Items.Add(urut)
                    MyListItem.SubItems.Add(.Item("id_buku").ToString)
                    MyListItem.SubItems.Add(.Item("judul_buku").ToString)
                    MyListItem.SubItems.Add(.Item("pengarang").ToString)
                    MyListItem.SubItems.Add(.Item("penerbit").ToString)
                    MyListItem.SubItems.Add(.Item("tahun").ToString)
                    MyListItem.SubItems.Add(.Item("kategori").ToString)
                End With
                urut = urut + 1
            Next
        Catch Exp As Exception
            MsgBox("Program error" & vbCrLf & Err.Description)
        End Try
        txtCari.Text = txtCari.Text
    End Sub
    Sub bersih()
        txtKode.Text = ""
        txtJudul.Text = ""
        cboKategori.Text = ""
        txtPenerbit.Text = ""
        txtPengarang.Text = ""
        txtTahun.Text = ""
        txtCari.Text = ""
        Call Tampil()
        NonAktif()
        btnSimpan.Enabled = False
        btnUpdate.Enabled = False
        btnHapus.Enabled = False
        btnBatal.Enabled = False
        btnKeluar.Enabled = True
        txtKode.Enabled = True
        txtKode.Focus()
    End Sub
    Sub Aktif()
        txtKode.Enabled = True
        txtJudul.Enabled = True
        txtPengarang.Enabled = True
        txtPenerbit.Enabled = True
        txtTahun.Enabled = True
        cboKategori.Enabled = True
    End Sub
    Sub NonAktif()
        txtKode.Enabled = False
        txtJudul.Enabled = False
        txtPengarang.Enabled = False
        txtPenerbit.Enabled = False
        txtTahun.Enabled = False
        cboKategori.Enabled = False
    End Sub
    Private Sub txtKode_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtKode.TextChanged
        If Len(txtKode.Text) < 6 Then Exit Sub
        tblbuku = Proses.ExecuteQuery("Select * From [buku] Where id_buku='" & txtKode.Text & "'")
        If tblbuku.Rows.Count > 0 Then
            With tblbuku.Rows(0)
                txtJudul.Text = .Item("judul_buku")
                txtPengarang.Text = .Item("pengarang")
                txtPenerbit.Text = .Item("penerbit")
                txtTahun.Text = .Item("tahun")
                cboKategori.Text = .Item("kategori")
            End With
            Call Aktif()
            txtKode.Enabled = False
            txtJudul.Focus()
            btnSimpan.Enabled = False : btnKeluar.Enabled = True
            btnUpdate.Enabled = True : btnHapus.Enabled = True
            btnBatal.Enabled = True
        Else
            Call Aktif()
            txtKode.Enabled = False
            txtJudul.Focus()
            btnSimpan.Enabled = True
            btnUpdate.Enabled = False : btnHapus.Enabled = False
            btnBatal.Enabled = True
        End If
    End Sub
    Private Sub frmBarang_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        lstBuku.FullRowSelect = True
        Call bersih()
    End Sub
    Private Sub btnSimpan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsimpan.Click
        SQL = "Insert Into [buku] Values ('" & txtKode.Text & "','" & txtJudul.Text & "','" & txtPengarang.Text & "','" & txtPenerbit.Text & "','" & txtTahun.Text & "','" & cboKategori.Text & "')"
        Proses.ExecuteNonQuery(SQL)
        MessageBox.Show("Data Baru telah disimpan..!!", "Penyimpanan Sukses", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Call bersih()
    End Sub
    Private Sub btnKeluar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnkeluar.Click
        Me.Close()
    End Sub
    Private Sub btnHapus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHapus.Click
        SQL = "Delete From [buku] Where id_buku = '" & txtKode.Text & "'"
        Proses.ExecuteNonQuery(SQL)
        MessageBox.Show("Data telah dihapus..!!", "Penghapusan Sukses", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Call bersih()
    End Sub
    Private Sub btnBatal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnbatal.Click
        Call bersih()
        Call NonAktif()
    End Sub
    Private Sub lstBuku_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstBuku.Click
        txtKode.Text = lstBuku.SelectedItems(0).SubItems(1).Text
    End Sub
    Private Sub txtCari_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtCari.TextChanged
        Call Tampil()
    End Sub

    Private Sub btnUpdate_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
        SQL = "Update [buku] Set judul_buku = '" & txtJudul.Text & "',pengarang='" & txtPengarang.Text & "',penerbit='" & txtPenerbit.Text & "',tahun='" & txtTahun.Text & "',kategori='" & cboKategori.Text & "' where id_buku = '" & txtKode.Text & "'"
        Proses.ExecuteNonQuery(SQL)
        MessageBox.Show("Data telah diubah..!!", "Perubahan Data Sukses", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Call bersih()
    End Sub
End Class



Dan ini kode koneksi untuk menjalankannya :
Imports Microsoft.VisualBasic
Imports System.Data.Sql
Public Class ClsKoneksi
    Protected tblUser = New DataTable
    Protected SQL As String
    Protected Cn As OleDb.OleDbConnection
    Protected Cmd As OleDb.OleDbCommand
    Protected Da As OleDb.OleDbDataAdapter
    Protected Ds As DataSet
    Protected Dt As DataTable
    Public Function OpenConn() As Boolean
        Cn = New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=..\db_uas_vbnet.accdb;Persist Security Info=False;")
        Cn.Open()
        If Cn.State <> ConnectionState.Open Then
            Return False
        Else
            Return True
        End If
    End Function
    Public Sub CloseConn()
        If Not IsNothing(Cn) Then
            Cn.Close()
            Cn = Nothing
        End If
    End Sub
    Public Function ExecuteQuery(ByVal Query As String) As DataTable
        If Not OpenConn() Then
            MsgBox("Koneksi Gagal..!!", MsgBoxStyle.Critical, "Access Failed")
            Return Nothing
            Exit Function
        End If

        Cmd = New OleDb.OleDbCommand(Query, Cn)
        Da = New OleDb.OleDbDataAdapter
        Da.SelectCommand = Cmd

        Ds = New Data.DataSet
        Da.Fill(Ds)

        Dt = Ds.Tables(0)

        Return Dt

        Dt = Nothing
        Ds = Nothing
        Da = Nothing
        Cmd = Nothing

        CloseConn()

    End Function
    Public Sub ExecuteNonQuery(ByVal Query As String)
        If Not OpenConn() Then
            MsgBox("Koneksi Gagal..!!", MsgBoxStyle.Critical, "Access Failed..!!")
            Exit Sub
        End If

        Cmd = New OleDb.OleDbCommand
        Cmd.Connection = Cn
        Cmd.CommandType = CommandType.Text
        Cmd.CommandText = Query
        Cmd.ExecuteNonQuery()
        Cmd = Nothing
        CloseConn()
    End Sub
End Class


blog www.deafaroz.blogspot.com BEBAS DI COPY PASTE posting ini di buat untuk memberikan pengetahuan kepada yang belum mengetahuinya,jadi tidak ada larangan untuk tidak mengcopy di blog ini,trimakasih untuk yang udah mau mengcopy di blog ini,sebarkan ilmu semampu anda dengan ikhlas .

3 komentar:

belajarwarawiri mengatakan...

gan ane minta dong aplikasi'y tolong unduh yah ..
kirim link'y ke email saya
asep_guna@ymail.com

belajarwarawiri mengatakan...

gan ane minta dong aplikasi'y tolong unduh yah ..
kirim link'y ke email saya
asep_guna@ymail.com

Faisal Rahmansyah mengatakan...

@belajarwarawiri sudah ada di menu donwload,.
cek disini http://deafaroz.blogspot.com/p/download.html

Contact

Get in touch with me


Adress/Street

12 Street West Victoria 1234 Australia

Phone number

+(12) 3456 789

Website

www.johnsmith.com