E › TIPS BLOG

Tutorial membuat aplikasi cetak faktur sederhana dengan VB NET

 IT Dadakan-, Pada kesempatan kali ini admin akan membagikan Tutorial membuat Aplikasi Cetak Faktur Sederhana dengan VB NET ,pastikan kalian sudah menginstal Visual Studio ,kalau punya admin versi 2010 Ultimate.

Langsung saja kalian buka Visual Studio Kalian ,lalu klik new project -> beri nama sesuka kalian contoh : Latihan Cetak Faktur.Setelah itu buat 3 Form dengan nama masing-masing : FormMain,FormLogo,PrinterForm.

Buat desain FormMain seperti gambar berikut ini :

Tutorial membuat aplikasi cetak faktur sederhana dengan VB NET
sumber : Doc Pribadi

Lalu masukkan code berikut didalam FormMain :


Public Class FormMain

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        PictureBox1.ImageLocation = My.Settings.logo
        'PictureBox2.BackgroundImage = code128(txtbarcode.Tex, "B")
        'Panel1.Height = dgvproduct.Height + 220

        gridsetings()

        dgvrecipt.Columns(0).Name = "Name"
        dgvrecipt.Columns(1).Name = "Qty"
        dgvrecipt.Columns(2).Name = "Price"

        dgvrecipt.Columns(0).Width = 50
        dgvrecipt.Columns(1).Width = 15
        dgvrecipt.Columns(2).Width = 50
    End Sub

    Private Sub gridsetings()

        dgvrecipt.ScrollBars = ScrollBars.None
        dgvrecipt.RowHeadersVisible = False
        dgvrecipt.ColumnCount = 3
        dgvrecipt.Columns(2).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight

        dgvrecipt.CellBorderStyle = DataGridViewCellBorderStyle.None


    End Sub

    Private Sub calc()
        Try

            Dim total As Integer = 0
            For index As Integer = 0 To dgvrecipt.Rows.Count - 1
                total += Convert.ToDouble(dgvrecipt.Rows(index).Cells(2).Value.ToString)
            Next
            Labeltotal.Text = total.ToString
        Catch ex As Exception

        End Try
    End Sub

    Private Sub ResizeDGV()
        dgvrecipt.Height = dgvrecipt.ColumnHeadersHeight + dgvrecipt.Rows.Cast(Of DataGridViewRow).Sum(Function(r) r.Height)
        Panel1.Height = dgvrecipt.Height + 250
        dgvrecipt.ClearSelection()
    End Sub

    Private Sub btnadd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnadd.Click
        total()
        Dim rNum As Integer = dgvproduct.Rows.Add

        dgvproduct.Rows.Item(rNum).Cells(0).Value = txtname.Text
        dgvproduct.Rows.Item(rNum).Cells(1).Value = txtqty.Text
        dgvproduct.Rows.Item(rNum).Cells(2).Value = Labeltotalprice.Text

        Dim rNum2 As Integer = dgvrecipt.Rows.Add

        dgvrecipt.Rows.Item(rNum2).Cells(0).Value = txtname.Text
        dgvrecipt.Rows.Item(rNum2).Cells(1).Value = txtqty.Text
        dgvrecipt.Rows.Item(rNum2).Cells(2).Value = Labeltotalprice.Text

        gridsetings()
        calc()


        txtname.Clear()
        txtqty.Clear()
        txtprice.Clear()

        txtname.Focus()

    End Sub

    Sub total()
        Labeltotalprice.Text = Val(txtqty.Text) * Val(txtprice.Text)
    End Sub

    Private Sub dgvrecipt_RowsAdded(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowsAddedEventArgs) Handles dgvrecipt.RowsAdded
        ResizeDGV()
    End Sub

    Private Sub dgvrecipt_RowsRemoved(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowsRemovedEventArgs) Handles dgvrecipt.RowsRemoved
        ResizeDGV()
    End Sub

    Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
        Dim bm As New Bitmap(Me.Panel1.Width, Me.Panel1.Height)
        Panel1.DrawToBitmap(bm, New Rectangle(0, 0, Me.Panel1.Width, Me.Panel1.Height))

        e.Graphics.DrawImage(bm, 0, 0)

        Dim aPS As New PageSetupDialog

        aPS.Document = PrintDocument1

    End Sub

    Private Sub btnprint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnprint.Click
        PrintDocument1.PrinterSettings.PrinterName = My.Settings.printer

        PrintDocument1.Print()

        dgvproduct.Rows.Clear()
        dgvrecipt.Rows.Clear()

        calc()
    End Sub

    Private Sub PrinterToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrinterToolStripMenuItem.Click
        printerForm.Show()
    End Sub

    Private Sub LogoToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LogoToolStripMenuItem.Click
        FormLogo.Show()
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        dgvproduct.Rows.Clear()
        dgvrecipt.Rows.Clear()
        Labeltotal.Text = ""
        Labeltotalprice.Text = ""
    End Sub

End Class


Buat desain FormLogo seperti gambar berikut ini :

Tutorial membuat aplikasi cetak faktur sederhana dengan VB NET
sumber : Doc Pribadi

Lalu masukkan code berikut didalam FormLogo :


Public Class FormLogo

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim openfile As New SaveFileDialog

        openfile.ShowDialog()

        TextBox1.Text = openfile.FileName
        PictureBox1.ImageLocation = openfile.FileName
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        My.Settings.logo = TextBox1.Text
        My.Settings.Save()

        FormMain.PictureBox1.ImageLocation = My.Settings.logo
        Me.Close()
    End Sub

    Private Sub FormLogo_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        PictureBox1.ImageLocation = My.Settings.logo

    End Sub
End Class


Buat desain PrinterForm seperti gambar berikut ini :

Tutorial membuat aplikasi cetak faktur sederhana dengan VB NET
sumber : Doc Pribadi

Lalu masukkan code berikut didalam PrinterForm :


Public Class printerForm

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If PrintDialog1.ShowDialog = Windows.Forms.DialogResult.Cancel Then
            Exit Sub
        End If

        TextBox1.Text = PrintDialog1.PrinterSettings.PrinterName

    End Sub

    Private Sub printerForm_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        Try
            My.Settings.printer = TextBox1.Text

            My.Settings.Save()
            Me.Close()
        Catch ex As Exception

        End Try
        

    End Sub

    Private Sub printerForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        TextBox1.Text = My.Settings.printer

    End Sub
End Class


Terakhir Save Project kalian ,dan coba RUN project kalian .


Nah cukup sekian Tutorial membuat aplikasi cetak faktur sederhana dengan VB NET ,jika ada problem dalam pembuatan silahkan komen dibawah.

Kalian juga bisa mendownload Source Codenya Disini

IT Dadakan Febi Arifin ,mulai mengenal dunia IT sejak SMP , suka sekali Ngoding walau bikin pusing wkwk.

Berlangganan update artikel terbaru via email:

Buka Komentar

0 Response to "Tutorial membuat aplikasi cetak faktur sederhana dengan VB NET"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel