Selasa, 06 Desember 2011

Latihan 40b

Public Class Form40B
    Dim I As New OleDb.OleDbConnection("Provider=microsoft.ACE.OLEDB.12.0;data source=" & Application.StartupPath & "\DATAMAJEMUK.accdb")
    Dim DATA As New DataTable
    Public Sub catherine()
        Dim X As New OleDb.OleDbDataAdapter
        X = 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)
        DATA.Rows.Clear()
        X.Fill(DATA)

    End Sub

    Private Sub Form40B_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim dataPrimary(1) As DataColumn
        dataPrimary(0) = DATA.Columns("NOTRANS")
        DATA.PrimaryKey = dataPrimary

        DataGridView1.DataSource = DATA

        TOTALJUMLAH()

    End Sub
    Public Sub TOTALJUMLAH()
        Dim TOT As Double = 0
        For Each x As DataRow In DATA.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)
        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
        End If

        TOTALJUMLAH()

    End Sub
    Private Sub SIMPAN_TAMBAH()
        If a.Text.Length = 0 Then
            MsgBox("Maaf, Nomor transaksi harus diisi dulu")
            Exit Sub
        End If

        If c.Text.Length = 0 Then
            MsgBox("Maaf, Jenis transaksi harus diisi dulu")
            Exit Sub
        End If

        If DATA.Rows.Count() = 0 Then
            MsgBox("Maaf, Proses tidak dapat dilanjutkan")
            Exit Sub
        End If

        If NO1.Text <> a.Text Then
            Dim cari As New ByIskandar.CariKeDataBaseByIskandar
            cari.AturPencarianDataBase("MASTERTRANSAKSI", "NOTRANS", a.Text, 1, I)
            If cari.JumlanBaris > 0 Then
                MsgBox("Nomor transaksi sudah ada")
                Exit Sub
            End If
        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 DATA.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

        NO1.Text = "-"
        a.Text = ""
        c.Text = ""

        DATA.Rows.Clear()

        TOTALJUMLAH()
        Form40a.cate()

    End Sub
    Private Sub Simpan_Edit()
        If a.Text.Length = 0 Then
            MsgBox("Maaf, Nomor transaksi harus diisi dulu")
            Exit Sub
        End If

        If b.Text.Length = 0 Then
            MsgBox("Maaf, Jenis transaksi harus diisi dulu")
            Exit Sub
        End If

        If DATA.Rows.Count() = 0 Then
            MsgBox("Maaf, Proses tidak dapat dilanjutkan")
            Exit Sub
        End If

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

        Dim CC As New OleDb.OleDbCommand
        CC = New OleDb.OleDbCommand("DELETE * FROM MASTERTRANSAKSI WHERE NOTRANS= '" & a.Text & "'", I)
        I.Open()
        CC.ExecuteNonQuery()
        I.Close()

        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()

        CC = New OleDb.OleDbCommand("DELETE * FROM DETAILTRANSAKSI WHERE NOTRANS= '" & a.Text & "'", I)
        I.Open()
        CC.ExecuteNonQuery()
        I.Close()

        For Each XX As DataRow In DATA.Rows

            CC = New OleDb.OleDbCommand("INSERT INTO DETAILTRANSAKSI (NOTRANS, KODEBARANG, UNIT, HARGA) VALUES ('" & a.Text & "', '" & XX("KODEBARANG") & "', " & XX("UNIT") & ", " & XX("HARGA") & ")", I)
            I.Open()
            CC.ExecuteNonQuery()
            I.Close()
            CC.Dispose()
        Next

        NO1.Text = "-"
        a.Text = ""
        c.Text = ""

        DATA.Rows.Clear()

        TOTALJUMLAH()
        Form40a.cate()
    End Sub

    Private Sub ee_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        If NO1.Text = "-" Then
            SIMPAN_TAMBAH()
        Else
            Simpan_Edit()
        End If
    End Sub
End Class

Tidak ada komentar:

Posting Komentar