Sabtu, 05 Januari 2013

Latihan 40a

Deskripsi

1. objek datagridview
ada dua objek ini pada form kali ini

2. objek button
ada 3 objek button pada form kali ini. fungsinya adalah untuk menghapus, mengedit dan menambah data yang ingin ditampilkan pada datagridview

Pembuatan Form
1. buka Microsoft Visual Studio anda
2. bukalah file kumpulan latihan anda
3. pilih menu project lalu klik add windows form
4. drag objek dari toolbox anda. susun hingga menjadi form seperti form pada gambar dibawah ini.


5. masukkan script berikut

Public Class Latihan_40a_46110008
    Dim go As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source =" & Application.StartupPath & "\Datamajemuk.ACCDB")
    Dim dtdetail As New DataTable
    Dim dtmaster As New DataTable
    Dim atur2 As New DataSet
    Dim bsdetail As New BindingSource
    Dim bsmaster As New BindingSource
    Public Sub grabdata()
        'proses pengosongan dan pengisian data tabel
        dtdetail.Rows.Clear()
        dtmaster.Rows.Clear()

        Dim master As New OleDb.OleDbDataAdapter
        master = New OleDb.OleDbDataAdapter("select* from mastertransaksi", go)
        master.Fill(dtmaster)
        master.Dispose()

        Dim detail As New OleDb.OleDbDataAdapter
        detail = New OleDb.OleDbDataAdapter("select* from detailtransaksi", go)
        detail.Fill(dtdetail)
        detail.Dispose()

    End Sub
    Private Sub Latihan_40a_46110008_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        grabdata()
        'memasukkan datatabel ke dalam dataset
        dtmaster.TableName = "idung"
        dtdetail.TableName = "kake"

        dgv1_46110008.DataSource = bsmaster
        dgv2_46110008.DataSource = bsdetail

        atur2.Tables.Add(dtmaster)
        atur2.Tables.Add(dtdetail)

        atur2.Relations.Add(New DataRelation("relasi", atur2.Tables("idung").Columns("notrans"), atur2.Tables("kake").Columns("notrans")))

        'menampilkan datatabel ke dGV dg menggunakan binding
        bsmaster.DataSource = atur2
        bsmaster.DataMember = "idung"
        bsdetail.DataSource = bsmaster
        bsdetail.DataMember = "relasi"
    End Sub

    Private Sub edit46110008_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles edit46110008.Click
        Latihan_40b_46110008.Show()
        Latihan_40b_46110008.ganti46110008.Text = dgv1_46110008.CurrentRow.Cells("notrans").Value
        Latihan_40b_46110008.notr46110008.Text = dgv1_46110008.CurrentRow.Cells("notrans").Value
        Latihan_40b_46110008.tgl46110008.Text = dgv1_46110008.CurrentRow.Cells("tanggaltransaksi").Value
        Latihan_40b_46110008.jt46110008.Text = dgv1_46110008.CurrentRow.Cells("jenistransaksi").Value
        Latihan_40b_46110008.makecolumn()
        Latihan_40b_46110008.botto()
    End Sub

    Private Sub tambah46110008_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tambah46110008.Click
        Latihan_40b_46110008.Show()
        Latihan_40b_46110008.notr46110008.Text = ""
        Latihan_40b_46110008.jt46110008.Text = ""
        Latihan_40b_46110008.ganti46110008.Text = "-"
        Latihan_40b_46110008.makecolumn()
    End Sub

    Private Sub hapus46110008_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles hapus46110008.Click
        If MsgBox("seriously want to delete the record???", MsgBoxStyle.YesNo) = MsgBoxResult.No Then
            Exit Sub
        End If

        Dim bojel As New OleDb.OleDbCommand
        bojel = New OleDb.OleDbCommand("delete* from mastertransaksi where notrans='" & dgv1_46110008.CurrentRow.Cells("notrans").Value & "'", go)
        go.Open()
        bojel.ExecuteNonQuery()
        go.Close()

        bojel = New OleDb.OleDbCommand("delete* from detailtransaksi where notrans='" & dgv1_46110008.CurrentRow.Cells("notrans").Value & "'", go)
        go.Open()
        bojel.ExecuteNonQuery()
        go.Close()

        grabdata()

    End Sub
End Class

Tidak ada komentar:

Posting Komentar