Vb.net Billing Software Source Code Review

Let's explore the most critical parts of the source code.

The final piece is printing. Using the PrintDocument component from the toolbox:

Private Sub PrintInvoice()
    Dim printDoc As New Printing.PrintDocument()
    AddHandler printDoc.PrintPage, AddressOf PrintPageHandler
    Dim printDialog1 As New PrintDialog()
    printDialog1.Document = printDoc
    If printDialog1.ShowDialog() = DialogResult.OK Then
        printDoc.Print()
    End If
End Sub

Private Sub PrintPageHandler(sender As Object, e As Printing.PrintPageEventArgs) Dim yPos As Single = e.MarginBounds.Top Dim leftMargin As Single = e.MarginBounds.Left Dim font As New Font("Arial", 12) Dim largeFont As New Font("Arial", 16, FontStyle.Bold)

'Header
e.Graphics.DrawString("ABC Electronics", largeFont, Brushes.Black, leftMargin, yPos)
yPos += 30
e.Graphics.DrawString("Invoice #: " & lblInvoiceNo.Text, font, Brushes.Black, leftMargin, yPos)
yPos += 20
e.Graphics.DrawString("Date: " & DateTime.Now.ToShortDateString(), font, Brushes.Black, leftMargin, yPos)
yPos += 30
e.Graphics.DrawString("Items:", font, Brushes.Black, leftMargin, yPos)
yPos += 20
'Loop through DataGridView rows and print them
For Each row As DataGridViewRow In dgvCart.Rows
    Dim line As String = row.Cells("ProductName").Value & " x " & row.Cells("Quantity").Value & " = " & row.Cells("Total").Value
    e.Graphics.DrawString(line, font, Brushes.Black, leftMargin, yPos)
    yPos += 20
Next
'Total
yPos += 20
e.Graphics.DrawString("Grand Total: " & lblGrandTotal.Text, New Font("Arial", 14, FontStyle.Bold), Brushes.Black, leftMargin, yPos)

End Sub

Before diving into the source code, let’s address the "why." Many developers assume C# is the only path on .NET, but VB.NET offers unique advantages for desktop billing applications:


Public Class frmProducts
    Private Sub frmProducts_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        LoadProducts()
    End Sub
Private Sub LoadProducts()
    Try
        Dim dt As DataTable = Product.GetAllProducts()
        dgvProducts.DataSource = dt
        dgvProducts.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill
    Catch ex As Exception
        MessageBox.Show("Error loading products: " & ex.Message)
    End Try
End Sub
Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click
    If ValidateFields() Then
        Dim product As New Product()
        product.ProductCode = txtProductCode.Text
        product.ProductName = txtProductName.Text
        product.Category = txtCategory.Text
        product.UnitPrice = Decimal.Parse(txtPrice.Text)
        product.StockQuantity = Integer.Parse(txtStock.Text)
        product.GSTPercentage = Decimal.Parse(txtGST.Text)
If product.AddProduct() Then
            MessageBox.Show("Product added successfully!")
            ClearFields()
            LoadProducts()
        End If
    End If
End Sub
Private Function ValidateFields() As Boolean
    If String.IsNullOrWhiteSpace(txtProductCode.Text) Then
        MessageBox.Show("Product code is required")
        Return False
    End If
    If String.IsNullOrWhiteSpace(txtProductName.Text) Then
        MessageBox.Show("Product name is required")
        Return False
    End If
    If Not Decimal.TryParse(txtPrice.Text, Nothing) Then
        MessageBox.Show("Invalid price")
        Return False
    End If
    Return True
End Function
Private Sub ClearFields()
    txtProductCode.Clear()
    txtProductName.Clear()
    txtCategory.Clear()
    txtPrice.Clear()
    txtStock.Clear()
    txtGST.Clear()
End Sub

End Class

Imports System.Data.SqlClient

Public Class DBConnection Private Shared connectionString As String = "Data Source=localhost;Initial Catalog=BillingSystem;Integrated Security=True" Public Shared conn As SqlConnection = New SqlConnection(connectionString) vb.net billing software source code

Public Shared Function GetConnection() As SqlConnection
    Return conn
End Function
Public Shared Sub OpenConnection()
    If conn.State = ConnectionState.Closed Then
        conn.Open()
    End If
End Sub
Public Shared Sub CloseConnection()
    If conn.State = ConnectionState.Open Then
        conn.Close()
    End If
End Sub

End Class

Yes, for internal business tools and standalone billing apps.
Modern alternatives include C# WPF, .NET MAUI, or web-based systems, but VB.NET wins for:

The source code patterns above are production-ready but must be extended with: Let's explore the most critical parts of the source code

If you need the complete source code (all forms, full database script, and reports) for a specific use case (retail shop, restaurant, pharmacy), let me know – I can provide a detailed GitHub-ready structure with all files.

I'll provide you with a comprehensive guide and source code for a basic billing software system in VB.NET with SQL Server database.

While classic WinForms is stable, you can modernize your billing app:

Example – Export invoice to PDF using QuestPDF: End Sub

Using document As New Document(Of InvoiceData)(...)
    document.GeneratePdfAndShow()
End Using

Before examining the source code, we must define the scope. A minimum viable product (MVP) for billing software typically includes: