LATIHAN 39 APKOM 4

Public Class Form39_36109010
    Dim dt As New DataTable
    Dim cm As New OleDb.OleDbCommand
    Dim rusna As New ByIskandar.CariKeDataBaseByIskandar
    Dim hma As New OleDb.OleDbConnection("PROVIDER = MICROSOFT.ACE.OLEDB.12.0; DATA SOURCE =" & Application.StartupPath & "/Datamajemuk.ACCDB")

    Private Sub Form39_36109010_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim a As New OleDb.OleDbDataAdapter
        a = New OleDb.OleDbDataAdapter("SELECT BARANG.KODEBARANG, BARANG.NAMABARANG, DETAILTRANSAKSI.UNIT, DETAILTRANSAKSI.HARGA, DETAILTRANSAKSI.UNIT*HARGA AS JUMLAH FROM BARANG INNER JOIN DETAILTRANSAKSI ON BARANG.KODEBARANG = DETAILTRANSAKSI.KODEBARANG WHERE NOTRANS = '" & aa.Text & "'", hma)
        a.Fill(dt)
        a.Dispose()

        Dim dc(1) As DataColumn
        dc(0) = dt.Columns("kodebarang")
        dt.PrimaryKey = dc

        dgv.DataSource = dt
    End Sub

    Private Sub dgv_CellEndEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgv.CellEndEdit
        If dgv.Columns(e.ColumnIndex).Name = "KODEBARANG" Then
            'If dgv.CurrentRow.Cells(0) = "KODEBARANG" Then  (rumus lain)

            'untuk mencari nama barang
            dgv.CurrentRow.Cells("NAMABARANG").Value = ""
            dgv.CurrentRow.Cells("UNIT").Value = 0
            dgv.CurrentRow.Cells("HARGA").Value = 0
            dgv.CurrentRow.Cells("JUMLAH").Value = 0

            rusna.AturPencarianDataBase("barang", "kodebarang", dgv.CurrentRow.Cells("KODEBARANG").Value, 1, hma)
            If rusna.JumlanBaris > 0 Then  '(menampilkan nama barang jika kolom kode barang ditemukan oleh proses di atas
                dgv.CurrentRow.Cells("NAMABARANG").Value = rusna.DataTablenya.Rows(0).Item("NAMABARANG")
            Else
                dgv.CurrentRow.Cells("NAMABARANG").Value = ""
                If Form38_39_40_36109010.ShowDialog = Windows.Forms.DialogResult.OK Then
                    dgv.CurrentRow.Cells("KODEBARANG").Value = Form38_39_40_36109010.dgv.CurrentRow.Cells("KODEBARANG").Value
                    dgv.CurrentRow.Cells("NAMABARANG").Value = Form38_39_40_36109010.dgv.CurrentRow.Cells("NAMABARANG").Value
                End If
            End If

        ElseIf dgv.Columns(e.ColumnIndex).Name = "UNIT" Or dgv.Columns(e.ColumnIndex).Name = "HARGA" Then
            dgv.CurrentRow.Cells("JUMLAH").Value = dgv.CurrentRow.Cells("UNIT").Value * dgv.CurrentRow.Cells("HARGA").Value
            ical()
        End If
    End Sub

    Private Sub ical()
        Dim ical1 As Integer = 0
        For Each ical2 As DataRow In dt.Rows
            ical1 += ical2("JUMLAH")
        Next
        dd.Text = ical1
    End Sub

    Private Sub d_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles d.Click
        If aa.Text.Length = 0 Then
            MsgBox("Isi rong itu No Transaksinya")
            Exit Sub
        End If

        If cc.Text.Length = 0 Then
            MsgBox("Isi rong itu Jenis Transaksinya")
            Exit Sub
        End If

        If dt.Rows.Count = 0 Then
            MsgBox("Isi rong itu datatable k")
            Exit Sub
        End If

        rusna.AturPencarianDataBase("mastertransaksi", "notrans", aa.Text, 1, hma)
        If rusna.JumlanBaris > 0 Then
            MsgBox("Adami notrans seperti itu")
            Exit Sub
        End If

        cm = New OleDb.OleDbCommand("insert into mastertransaksi (notrans, tanggaltransaksi, jenistransaksi) values ('" & aa.Text & "',#" & bb.Value.Month & "/" & bb.Value.Day & "/" & bb.Value.Year & "#,'" & cc.Text & "')", hma)
        hma.Open()
        cm.ExecuteNonQuery()
        hma.Close()

        For Each x As DataRow In dt.Rows
            cm = New OleDb.OleDbCommand("insert into detailtransaksi (notrans, kodebarang, unit, harga) values ('" & aa.Text & "', '" & x("kodebarang") & "', '" & x("unit") & "', '" & x("harga") & "')", hma)
            hma.Open()
            cm.ExecuteNonQuery()
            hma.Close()
        Next

        cm.Dispose()

        aa.Text = ""
        cc.Text = ""
        dd.Text = ""

        dt.Rows.Clear()
        ical()
    End Sub

  
End Class

0 komentar:

Posting Komentar