Selasa, 10 Januari 2012

Script Visual Basic Apkomp 4 PNUP -FORM39-


Public Class Form39_36109006
    Dim HARUN As New OleDb.OleDbConnection("provider=microsoft.ace.oledb.12.0;data source= " & Application.StartupPath & "\DATAMAJEMUK.accdb")
    Dim DT As New DataTable
    Dim CARI As New ByIskandar.CariKeDataBaseByIskandar
    Private Sub Latihan39_36109006_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        DT.Columns.Add(New DataColumn("KODEBARANG", GetType(String)))
        DT.Columns.Add(New DataColumn("NAMABARANG", GetType(String)))
        DT.Columns.Add(New DataColumn("UNIT", GetType(Double)))
        DT.Columns.Add(New DataColumn("HARGA", GetType(Integer)))
        DT.Columns.Add(New DataColumn("JUMLAH", GetType(Double)))
        DGV_36109006.DataSource = DT

        Dim DC(1) As DataColumn
        DC(0) = DT.Columns("KODEBARANG")
        DT.PrimaryKey = DC

        DT.Columns("UNIT").DefaultValue = 0
        DT.Columns("HARGA").DefaultValue = 0
        DT.Columns("JUMLAH").DefaultValue = 0

    End Sub
    Private Sub Muhharun()
        Dim Manis1 As Integer
        For Each Manis2 As DataGridViewRow In DGV_36109006.Rows
            Manis1 = Manis1 + Manis2.Cells("JUMLAH").Value
        Next
        TO_36109006.Text = Manis1

    End Sub

    Private Sub DataGridView1_CellEndEdit(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DGV_36109006.CellEndEdit
        If e.ColumnIndex = 0 Then

            CARI.AturPencarianDataBase("BARANG", "kodebarang", DGV_36109006.CurrentRow.Cells("kodebarang").Value, 1, HARUN)
            If CARI.JumlanBaris > 0 Then
                DGV_36109006.CurrentRow.Cells("KODEBARANG").Value = CARI.DataTablenya.Rows(0).Item("KODEBARANG")
                DGV_36109006.CurrentRow.Cells("NAMABARANG").Value = CARI.DataTablenya.Rows(0).Item("NamaBarang")
            Else
                MsgBox("kode barang tidak tersedia")
                If Form383940_36109006.ShowDialog = Windows.Forms.DialogResult.OK Then
                    DGV_36109006.CurrentRow.Cells("KODEBARANG").Value = Form383940_36109006.dgv_36109006.CurrentRow.Cells("KodeBarang").Value
                    DGV_36109006.CurrentRow.Cells("NAMABARANG").Value = Form383940_36109006.dgv_36109006.CurrentRow.Cells("namabarang").Value
                    DGV_36109006.CurrentRow.Cells("HARGA").Value = Form383940_36109006.dgv_36109006.CurrentRow.Cells("HARGAJUAL").Value
                Else
                    DGV_36109006.CurrentRow.Cells("KODEBARANG").Value = ""
                    DGV_36109006.CurrentRow.Cells("NAMABARANG").Value = ""
                End If
            End If
        End If
        If e.ColumnIndex = 2 Or e.ColumnIndex = 3 Then
            DGV_36109006.CurrentRow.Cells("JUMLAH").Value = DGV_36109006.CurrentRow.Cells("UNIT").Value * DGV_36109006.CurrentRow.Cells("HARGA").Value

        End If

        Muhharun()
    End Sub
    Private Sub Simpan_36109006_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Simpan_36109006.Click
        If NT_36109006.Text.Length = 0 Then
            MsgBox("no transaksi belum terisi")
            Exit Sub
        End If


        If JT_36109006.Text.Length = 0 Then
            MsgBox("jenis transaksi belum terisi")
            Exit Sub
        End If

        If DT.Rows.Count = 0 Then
            MsgBox("data tidak tersedia")
        End If

        CARI.AturPencarianDataBase("mastertransaksi", "notrans", NT_36109006.Text, 1, HARUN)

        If CARI.JumlanBaris > 0 Then
            MsgBox("kode sudah ada")
            Exit Sub
        End If

        Dim COM As New OleDb.OleDbCommand
        COM = New OleDb.OleDbCommand("insert into mastertransaksi (notrans, tanggaltransaksi, jenistransaksi) values ('" & NT_36109006.Text & "',#" & T_36109006.Value.Month & "/" & T_36109006.Value.Day & "/" & T_36109006.Value.Year & "#,'" & JT_36109006.Text & "')", HARUN)

        HARUN.Open()
        COM.ExecuteNonQuery()
        HARUN.Close()

        For Each r As DataRow In DT.Rows

            COM = New OleDb.OleDbCommand("insert into detailtransaksi (notrans, kodebarang, unit, harga ) values ('" & NT_36109006.Text & "','" & r("kodebarang") & "'," & r("unit") & "," & r("harga") & ")", HARUN)
            HARUN.Open()
            COM.ExecuteNonQuery()
            HARUN.Close()

            COM.Dispose()

        Next

        NT_36109006.Text = ""
        JT_36109006.Text = ""
        TO_36109006.Text = ""

        DT.Rows.Clear()
        Muhharun()

    End Sub


End Class


0 komentar:

Posting Komentar

Diberdayakan oleh Blogger.

BTricks