Kamis, 05 Januari 2012

Public Class Form38

    Dim cimi As New DataTable
    Dim ismi As New OleDb.OleDbCommand
    Dim sri As New ByIskandar.CariKeDataBaseByIskandar
    Dim conect As New OleDb.OleDbConnection("provider = microsoft.ace.oledb.12.0;data source=" & Application.StartupPath & "\datamajemuk.accdb;Jet OLEDB:Database Password=cimi")
    Private Sub Form38_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim ismisriwahyuni As New OleDb.OleDbDataAdapter
        ismisriwahyuni = 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 ='" & NT46109023.Text & "'", conect)
        cimi.Rows.Clear()
        ismisriwahyuni.Fill(cimi)
        ismisriwahyuni.Dispose()

        Dim dpc(1) As DataColumn
        dpc(0) = cimi.Columns("kodebarang")
        cimi.PrimaryKey = dpc

        DATA46109023.DataSource = cimi
    End Sub

    Private Sub cim()
        Dim cim1 As Integer = 0
        For Each cim2 As DataRow In cimi.Rows
            cim1 += cim2("JUMLAH")
        Next
        TOT46109023.Text = cim1
    End Sub

    Private Sub UN46109023_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UN46109023.TextChanged, HR46109023.TextChanged
        JM46109023.Text = Val(UN46109023.Text) * Val(HR46109023.Text)
    End Sub

    Private Sub KB46109023_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles KB46109023.TextChanged
        NB46109023.Text = ""
        HR46109023.Text = ""
        UN46109023.Text = ""
    End Sub

    Private Sub KB46109023_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles KB46109023.Leave
        If KB46109023.Text.Length = 0 Then
            Exit Sub
        End If
        sri.AturPencarianDataBase("barang", "kodebarang", KB46109023.Text, 1, conect)
        If sri.JumlanBaris > 0 Then
            KB46109023.Text = sri.DataTablenya.Rows(0).Item("KODEBARANG")
            NB46109023.Text = sri.DataTablenya.Rows(0).Item("NAMABARANG")
        Else
            MsgBox("Kode barang seperti itu tidak ada..")
            If Form383940_46109023.ShowDialog = Windows.Forms.DialogResult.OK Then
                KB46109023.Text = Form383940_46109023.DATA46109023.CurrentRow.Cells("kodebarang").Value
                NB46109023.Text = Form383940_46109023.DATA46109023.CurrentRow.Cells("namabarang").Value
            Else
                KB46109023.Text = ""
            End If
        End If
    End Sub


    Private Sub TM46109023_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TM46109023.Click
        If KB46109023.Text.Length = 0 Then
            MsgBox("Isi Kode Barang")
            Exit Sub
        End If

        If Val(UN46109023.Text) = 0 Then
            MsgBox("Isi Unit Barang")
            Exit Sub
        End If

        If Val(HR46109023.Text) = 0 Then
            MsgBox("Isi Harga Barang")
            Exit Sub
        End If

        Dim cimot As DataRow
        cimot = cimi.Rows.Find(KB46109023.Text)
        If cimot Is Nothing Then
            cimot = cimi.NewRow
            cimot("KODEBARANG") = KB46109023.Text
            cimot("NAMABARANG") = NB46109023.Text
            cimot("UNIT") = Val(UN46109023.Text)
            cimot("HARGA") = Val(HR46109023.Text)
            cimot("JUMLAH") = Val(JM46109023.Text)

            cimi.Rows.Add(cimot)

            KB46109023.Text = ""
            UN46109023.Text = ""
            HR46109023.Text = ""

        Else
            MsgBox("Kode barang itu sudah ada, mohon ganti dengan kode barang yang lain...")
        End If
        cim()
    End Sub

    Private Sub S46109023_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles S46109023.Click
        If NT46109023.Text.Length = 0 Then
            MsgBox("Isi No Transaksi")
            Exit Sub
        End If

        If JT46109023.Text.Length = 0 Then
            MsgBox("isi Jenis Transaksi")
            Exit Sub
        End If

        If cimi.Rows.Count = 0 Then
            MsgBox("Isi datatable")
            Exit Sub
        End If

        sri.AturPencarianDataBase("mastertransaksi", "notrans", NT46109023.Text, 1, conect)
        If sri.JumlanBaris > 0 Then
            MsgBox("No Trans sudah ada")
            Exit Sub
        End If

        ismi = New OleDb.OleDbCommand("insert into mastertransaksi (notrans, tanggaltransaksi, jenistransaksi) values ('" & NT46109023.Text & "',#" & T46109023.Value.Month & "/" & T46109023.Value.Day & "/" & T46109023.Value.Year & "#,'" & JT46109023.Text & "')", conect)
        conect.Open()
        ismi.ExecuteNonQuery()
        conect.Close()

        For Each x As DataRow In cimi.Rows
            ismi = New OleDb.OleDbCommand("insert into detailtransaksi (notrans, kodebarang, unit, harga) values ('" & NT46109023.Text & "','" & x("kodebarang") & "','" & x("unit") & "','" & x("harga") & "')", conect)
            conect.Open()
            ismi.ExecuteNonQuery()
            conect.Close()
        Next
        ismi.Dispose()

        NT46109023.Text = ""
        JT46109023.Text = ""

        cimi.Rows.Clear()
        cim()
    End Sub
End Class

Tidak ada komentar:

Posting Komentar