Minggu, 04 Desember 2011

Latihan 39

Public Class Form39

    Dim I As New OleDb.OleDbConnection("Provider=microsoft.ACE.OLEDB.12.0;data source=" & Application.StartupPath & "\DATAMAJEMUK.accdb")
    Dim CI As New DataTable

    Private Sub Form39_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim Z As New OleDb.OleDbDataAdapter
        Z = New OleDb.OleDbDataAdapter("Select BARANG.KODEBARANG, BARANG.NAMABARANG, DETAILTRANSAKSI.UNIT, DETAILTRANSAKSI.HARGA, DETAILTRANSAKSI.UNIT*DETAILTRANSAKSI.HARGA AS JUMLAH from DETAILTRANSAKSI INNER JOIN BARANG ON DETAILTRANSAKSI.KODEBARANG=BARANG.KODEBARANG WHERE NOTRANS= '" & a.Text & "'", I)
        Z.Fill(CI)
        Z.Dispose()

        Dim dataPrimary(1) As DataColumn
        dataPrimary(0) = CI.Columns("KODEBARANG")
        CI.PrimaryKey = dataPrimary

        DataGridView1.DataSource = CI
    End Sub
    Public Sub TOTALJUMLAH()
        Dim TOT As Double = 0
        For Each x As DataRow In CI.Rows
            TOT = TOT + x("JUMLAH")
        Next
        d.Text = TOT
    End Sub

    Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
        If DataGridView1.Columns(e.ColumnIndex).Name = "KODEBARANG" Then

            DataGridView1.CurrentRow.Cells("NAMABARANG").Value = ""
            DataGridView1.CurrentRow.Cells("UNIT").Value = 0
            DataGridView1.CurrentRow.Cells("HARGA").Value = 0
            DataGridView1.CurrentRow.Cells("JUMLAH").Value = 0

            Dim cari As New ByIskandar.CariKeDataBaseByIskandar
            cari.AturPencarianDataBase("BARANG", "KODEBARANG", DataGridView1.CurrentRow.Cells("KODEBARANG").Value, 1, I)
            If cari.JumlanBaris > 0 Then
                DataGridView1.CurrentRow.Cells("NAMABARANG").Value = cari.DataTablenya.Rows(0).Item("NAMABARANG")
            Else
                DataGridView1.CurrentRow.Cells("KODEBARANG").Value = ""
                If Form383940.ShowDialog = Windows.Forms.DialogResult.OK Then
                    DataGridView1.CurrentRow.Cells("KODEBARANG").Value = Form383940.DataGridView1.CurrentRow.Cells("KODEBARANG").Value
                    DataGridView1.CurrentRow.Cells("NAMABARANG").Value = Form383940.DataGridView1.CurrentRow.Cells("NAMABARANG").Value
                End If
            End If
        ElseIf DataGridView1.Columns(e.ColumnIndex).Name = "UNIT" Or DataGridView1.Columns(e.ColumnIndex).Name = "HARGA" Then
            DataGridView1.CurrentRow.Cells("JUMLAH").Value = DataGridView1.CurrentRow.Cells("UNIT").Value * DataGridView1.CurrentRow.Cells("HARGA").Value

            TOTALJUMLAH()
        End If
    End Sub

    Private Sub ee_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ee.Click
        If a.Text.Length = 0 Then
            MsgBox("No. transaksi sudah ada")
            Exit Sub
        End If

        If c.Text.Length = 0 Then
            MsgBox("Jenis transaksi sudah ada")
            Exit Sub
        End If

        If CI.Rows.Count = 0 Then
            MsgBox("Jumlah baris tidak terisi")
            Exit Sub
        End If

        Dim cari As New ByIskandar.CariKeDataBaseByIskandar
        cari.AturPencarianDataBase("MASTERTRANSAKSI", "NOTRANS", a.Text, 1, I)
        If cari.JumlanBaris > 0 Then
            MsgBox("data tersebut sudah ada")
            Exit Sub
        End If

        Dim CC As New OleDb.OleDbCommand
        CC = New OleDb.OleDbCommand("INSERT INTO MASTERTRANSAKSI (NOTRANS, TANGGALTRANSAKSI, JENISTRANSAKSI) VALUES ('" & a.Text & "', #" & b.Value.Month & "/" & b.Value.Day & "/" & b.Value.Year & "#, '" & c.Text & "')", I)
        I.Open()
        CC.ExecuteNonQuery()
        I.Close()

        For Each X As DataRow In CI.Rows
            CC = New OleDb.OleDbCommand("INSERT INTO DETAILTRANSAKSI (NOTRANS, KODEBARANG, UNIT, HARGA) VALUES ('" & a.Text & "','" & X("KODEBARANG") & "'," & X("UNIT") & ", " & X("HARGA") & ")", I)
            I.Open()
            CC.ExecuteNonQuery()
            I.Close()
            CC.Dispose()
        Next

        a.Text = ""
        b.Text = ""

        CI.Rows.Clear()
    End Sub
End Class

Tidak ada komentar:

Posting Komentar