Source Code aplikasi:
Imports System.Data.OleDbImports word = Microsoft.Office.Interop.WordPublic Class Form1Public koneksi As OleDbConnection = NothingPublic command As OleDbCommand = NothingPublic reader As OleDbDataAdapter = NothingFunction Connect()If Not koneksi Is Nothing Thenkoneksi.Close()End Ifkoneksi.Open()Return koneksiEnd FunctionFunction Closedd()koneksi.Close()Return koneksiEnd FunctionPrivate Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.LoadIf Not koneksi Is Nothing Then koneksi.Close()Dim koneksiString As StringkoneksiString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=E:\02. PERPUSTAKAAN\Kuliah\Semester 5\Visual Programming\aplikasiPenjualanSederhanan\db_penjualan.accdb"Trykoneksi = New OleDbConnection(koneksiString)koneksi.Open()Me.Text = "Form Penjualan Barang"koneksi.Close()Catch ex As ExceptionMessageBox.Show("Koneksi Error : " + ex.Message)End TryrefreshCombo()End SubPrivate Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.ClickConnect()If (Val(tTotal.Text) > 0) ThenTryDim dt As New DataTableDim query = "select * from tb_penjualan where noFaktur='" & tNoFaktur.Text & "'"reader = New OleDbDataAdapter(query, koneksi)reader.Fill(dt)If dt.Rows.Count = 0 Thencommand = 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.ExecuteNonQueryIf hasil > 0 ThenMessageBox.Show("Transaksi berhasil diproses", "Transaksi Faktur", MessageBoxButtons.OK, MessageBoxIcon.Information)kosongkan()refreshCombo()End IfElseMessageBox.Show("Transaksi gagal diproses, no faktur sudah terdaftar", "Transaksi Faktur", MessageBoxButtons.OK, MessageBoxIcon.Error)End IfCatch ex As ExceptionEnd TryEnd IfEnd SubPrivate Sub tKodeBarang_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles tKodeBarang.KeyPressIf Asc(e.KeyChar) = 13 ThenCall ambilDataBarang()End IfEnd SubSub ambilDataBarang()TryDim dt As New DataTableDim query = "select * from tb_barang where kodeBarang='" & tKodeBarang.Text & "'"reader = New OleDbDataAdapter(query, koneksi)reader.Fill(dt)If dt.Rows.Count > 0 ThentNamaBarang.Text = dt.Rows(0).Item("namaBarang").ToStringtHargaSatuan.Text = dt.Rows(0).Item("hargaBarang").ToStringEnd IfCatch ex As ExceptionEnd TrytQty.Focus()End SubPrivate Sub tQty_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles tQty.KeyUptTotal.Text = Val(tQty.Text) * Val(tHargaSatuan.Text)End SubPrivate Sub kosongkan()tNoFaktur.Text = ""tKodeBarang.Text = ""tNamaBarang.Text = ""tHargaSatuan.Text = ""tQty.Text = ""tTotal.Text = ""tNoFaktur.Focus()End SubPrivate Sub refreshCombo()TryDim dt As New DataTableDim query = "select * from tb_penjualan"reader = New OleDbDataAdapter(query, koneksi)reader.Fill(dt)comboNoFaktur.Items.Clear()If dt.Rows.Count > 0 ThenFor i = 0 To dt.Rows.CountcomboNoFaktur.Items.Add(dt.Rows(i).Item("noFaktur").ToString)NextEnd IfCatch ex As ExceptionEnd TryEnd SubPrivate Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.ClickTryDim dt As New DataTableDim 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.ApplicationDim myWordDoc As New word.DocumentDim hasil As New IntegermyWordDoc = 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 = TruemyWordApp.PrintPreview = TruemyWordDoc.SaveAs2("E:\02. PERPUSTAKAAN\Kuliah\Semester 5\Visual Programming\aplikasiPenjualanSederhanan\" & tNoFaktur.Text & ".docx")'myWordApp.Quit()End IfCatch ex As ExceptionEnd TryEnd SubEnd Class
Screenshot Aplikasi:
Gambar Ketika Transaksi |
kak,kalau pembelian lebih dari 1 terus tampilan dbikin kolom bisa gak ya?
ReplyDeletemakasih kak infonya
ReplyDeletebaca juga :
Dompet wanita
Tas Ransel wanita
Tas Selempang Wanita