Delicious Digg Facebook Favorites More Stumbleupon Twitter
Blog seputar hobby

Sunday, January 26, 2014

Posted by Maulana yusuf 5:57 AM
1 comment

Desain Form Aplikasi:


Source Code aplikasi:

Imports System.Data.OleDb
Imports word = Microsoft.Office.Interop.Word

Public Class Form1
    Public koneksi As OleDbConnection = Nothing
    Public command As OleDbCommand = Nothing
    Public reader As OleDbDataAdapter = Nothing
    Function Connect()
        If Not koneksi Is Nothing Then
            koneksi.Close()
        End If
        koneksi.Open()
        Return koneksi
    End Function
    Function Closedd()
        koneksi.Close()
        Return koneksi
    End Function

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If Not koneksi Is Nothing Then koneksi.Close()

        Dim koneksiString As String

        koneksiString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=E:\02. PERPUSTAKAAN\Kuliah\Semester 5\Visual Programming\aplikasiPenjualanSederhanan\db_penjualan.accdb"

        Try
            koneksi = New OleDbConnection(koneksiString)
            koneksi.Open()
            Me.Text = "Form Penjualan Barang"
            koneksi.Close()
        Catch ex As Exception
            MessageBox.Show("Koneksi Error : " + ex.Message)
        End Try

        refreshCombo()

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Connect()
        If (Val(tTotal.Text) > 0) Then
             Try
                Dim dt As New DataTable
                Dim query = "select * from tb_penjualan where noFaktur='" & tNoFaktur.Text & "'"
                reader = New OleDbDataAdapter(query, koneksi)
                reader.Fill(dt)

                If dt.Rows.Count = 0 Then
                    command = New OleDbCommand("INSERT INTO tb_penjualan(noFaktur,kodeBarang,QTY,total)values('" & tNoFaktur.Text & "','" & tKodeBarang.Text & "','" & tQty.Text & "','" & tTotal.Text & "')", koneksi)
                    Dim hasil As Integer = command.ExecuteNonQuery
                    If hasil > 0 Then
                        MessageBox.Show("Transaksi berhasil diproses", "Transaksi Faktur", MessageBoxButtons.OK, MessageBoxIcon.Information)
                        kosongkan()
                        refreshCombo()
                    End If
                Else
                    MessageBox.Show("Transaksi gagal diproses, no faktur sudah terdaftar", "Transaksi Faktur", MessageBoxButtons.OK, MessageBoxIcon.Error)
                End If
            Catch ex As Exception

            End Try

        End If
    End Sub

    Private Sub tKodeBarang_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles tKodeBarang.KeyPress
        If Asc(e.KeyChar) = 13 Then
            Call ambilDataBarang()
        End If
    End Sub

    Sub ambilDataBarang()
        Try
            Dim dt As New DataTable
            Dim query = "select * from tb_barang where kodeBarang='" & tKodeBarang.Text & "'"
            reader = New OleDbDataAdapter(query, koneksi)
            reader.Fill(dt)

            If dt.Rows.Count > 0 Then
                tNamaBarang.Text = dt.Rows(0).Item("namaBarang").ToString
                tHargaSatuan.Text = dt.Rows(0).Item("hargaBarang").ToString
            End If
        Catch ex As Exception

        End Try

        tQty.Focus()
    End Sub

    Private Sub tQty_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles tQty.KeyUp
        tTotal.Text = Val(tQty.Text) * Val(tHargaSatuan.Text)
    End Sub

    Private Sub kosongkan()
        tNoFaktur.Text = ""
        tKodeBarang.Text = ""
        tNamaBarang.Text = ""
        tHargaSatuan.Text = ""
        tQty.Text = ""
        tTotal.Text = ""
        tNoFaktur.Focus()
    End Sub

    Private Sub refreshCombo()
        Try
            Dim dt As New DataTable
            Dim query = "select * from tb_penjualan"
            reader = New OleDbDataAdapter(query, koneksi)
            reader.Fill(dt)

            comboNoFaktur.Items.Clear()
            If dt.Rows.Count > 0 Then
                For i = 0 To dt.Rows.Count
                    comboNoFaktur.Items.Add(dt.Rows(i).Item("noFaktur").ToString)
                Next
            End If
        Catch ex As Exception

        End Try
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Try
            Dim dt As New DataTable
            Dim query = "select * from qw_penjualan where noFaktur='" & comboNoFaktur.Text & "'"
            reader = New OleDbDataAdapter(query, koneksi)
            reader.Fill(dt)

            If dt.Rows.Count > 0 Then
                ' MsgBox(dt.Rows(0).Item("noFaktur").ToString)
                Dim myWordApp As New word.Application
                Dim myWordDoc As New word.Document
                Dim hasil As New Integer
                myWordDoc = myWordApp.Documents.Open("E:\02. PERPUSTAKAAN\Kuliah\Semester 5\Visual Programming\aplikasiPenjualanSederhanan\faktur.docx")

                myWordDoc.Bookmarks("noFaktur").Select()
                myWordApp.Selection.TypeText(dt.Rows(0).Item("noFaktur").ToString)

                myWordDoc.Bookmarks("kodeBarang").Select()
                myWordApp.Selection.TypeText(dt.Rows(0).Item("kodeBarang").ToString)

                myWordDoc.Bookmarks("namaBarang").Select()
                myWordApp.Selection.TypeText(dt.Rows(0).Item("namaBarang").ToString)


                myWordDoc.Bookmarks("hargaBarang").Select()
                myWordApp.Selection.TypeText(dt.Rows(0).Item("hargaBarang").ToString)


                myWordDoc.Bookmarks("QTY").Select()
                myWordApp.Selection.TypeText(dt.Rows(0).Item("QTY").ToString)

                myWordDoc.Bookmarks("total").Select()
                myWordApp.Selection.TypeText(dt.Rows(0).Item("total").ToString)

                myWordApp.Visible = True
                myWordApp.PrintPreview = True
                myWordDoc.SaveAs2("E:\02. PERPUSTAKAAN\Kuliah\Semester 5\Visual Programming\aplikasiPenjualanSederhanan\" & tNoFaktur.Text & ".docx")
                'myWordApp.Quit()
            End If
        Catch ex As Exception

        End Try
    End Sub
End Class

Screenshot Aplikasi:
Gambar Ketika Transaksi







1 comment:

  1. kak,kalau pembelian lebih dari 1 terus tampilan dbikin kolom bisa gak ya?

    ReplyDelete

Search

Our Sponsors