Public Class Product Public Property ProductID As Integer Public Property ProductCode As String Public Property ProductName As String Public Property Category As String Public Property UnitPrice As Decimal Public Property StockQuantity As Integer Public Property GSTPercentage As DecimalPublic Function AddProduct() As Boolean Try Dim query As String = "INSERT INTO Products (ProductCode, ProductName, Category, UnitPrice, StockQuantity, GSTPercentage) VALUES (@Code, @Name, @Category, @Price, @Stock, @GST)" DBConnection.OpenConnection() Using cmd As New SqlCommand(query, DBConnection.conn) cmd.Parameters.AddWithValue("@Code", ProductCode) cmd.Parameters.AddWithValue("@Name", ProductName) cmd.Parameters.AddWithValue("@Category", Category) cmd.Parameters.AddWithValue("@Price", UnitPrice) cmd.Parameters.AddWithValue("@Stock", StockQuantity) cmd.Parameters.AddWithValue("@GST", GSTPercentage) Return cmd.ExecuteNonQuery() > 0 End Using Catch ex As Exception MessageBox.Show("Error: " & ex.Message) Return False Finally DBConnection.CloseConnection() End Try End Function Public Shared Function GetAllProducts() As DataTable Dim dt As New DataTable() Try Dim query As String = "SELECT ProductID, ProductCode, ProductName, Category, UnitPrice, StockQuantity, GSTPercentage FROM Products" DBConnection.OpenConnection() Using adapter As New SqlDataAdapter(query, DBConnection.conn) adapter.Fill(dt) End Using Catch ex As Exception MessageBox.Show("Error: " & ex.Message) Finally DBConnection.CloseConnection() End Try Return dt End Function
End Class
Imports System.Data.SqlClientPublic Class frmBilling Private dtCart As New DataTable() Private currentInvoiceNumber As String = ""
Private Sub frmBilling_Load(sender As Object, e As EventArgs) Handles MyBase.Load InitializeCartTable() GenerateInvoiceNumber() LoadProducts() LoadCustomers() End Sub Private Sub InitializeCartTable() dtCart.Columns.Add("ProductID", GetType(Integer)) dtCart.Columns.Add("ProductCode", GetType(String)) dtCart.Columns.Add("ProductName", GetType(String)) dtCart.Columns.Add("Quantity", GetType(Integer)) dtCart.Columns.Add("UnitPrice", GetType(Decimal)) dtCart.Columns.Add("GST", GetType(Decimal)) dtCart.Columns.Add("Total", GetType(Decimal)) dgvCart.DataSource = dtCart FormatDataGridView() End Sub Private Sub FormatDataGridView() dgvCart.Columns("ProductID").Visible = False dgvCart.Columns("ProductCode").HeaderText = "Product Code" dgvCart.Columns("ProductName").HeaderText = "Product Name" dgvCart.Columns("Quantity").HeaderText = "Qty" dgvCart.Columns("UnitPrice").HeaderText = "Unit Price" dgvCart.Columns("GST").HeaderText = "GST %" dgvCart.Columns("Total").HeaderText = "Total" dgvCart.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill End Sub Private Sub GenerateInvoiceNumber() currentInvoiceNumber = "INV-" & DateTime.Now.ToString("yyyyMMdd") & "-" & DateTime.Now.ToString("HHmmss") txtInvoiceNo.Text = currentInvoiceNumber End Sub Private Sub LoadProducts() Try Dim dt As DataTable = Product.GetAllProducts() cmbProductName.DataSource = dt cmbProductName.DisplayMember = "ProductName" cmbProductName.ValueMember = "ProductID" cmbProductName.SelectedIndex = -1 Catch ex As Exception MessageBox.Show("Error loading products: " & ex.Message) End Try End Sub Private Sub LoadCustomers() Try Dim query As String = "SELECT CustomerID, CustomerName FROM Customers" DBConnection.OpenConnection() Dim adapter As New SqlDataAdapter(query, DBConnection.conn) Dim dt As New DataTable() adapter.Fill(dt) cmbCustomer.DataSource = dt cmbCustomer.DisplayMember = "CustomerName" cmbCustomer.ValueMember = "CustomerID" DBConnection.CloseConnection() Catch ex As Exception MessageBox.Show("Error loading customers: " & ex.Message) End Try End Sub Private Sub cmbProductName_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cmbProductName.SelectedIndexChanged If cmbProductName.SelectedValue IsNot Nothing Then Try Dim productID As Integer = Convert.ToInt32(cmbProductName.SelectedValue) Dim query As String = "SELECT ProductCode, UnitPrice, GSTPercentage FROM Products WHERE ProductID = @ProductID" DBConnection.OpenConnection() Using cmd As New SqlCommand(query, DBConnection.conn) cmd.Parameters.AddWithValue("@ProductID", productID) Using reader As SqlDataReader = cmd.ExecuteReader() If reader.Read() Then txtProductCode.Text = reader("ProductCode").ToString() txtPrice.Text = reader("UnitPrice").ToString() txtGST.Text = reader("GSTPercentage").ToString() txtQuantity.Text = "1" CalculateTotal() End If End Using End Using DBConnection.CloseConnection() Catch ex As Exception MessageBox.Show("Error: " & ex.Message) End Try End If End Sub Private Sub CalculateTotal() If txtQuantity.Text <> "" And txtPrice.Text <> "" Then Dim quantity As Integer = Integer.Parse(txtQuantity.Text) Dim price As Decimal = Decimal.Parse(txtPrice.Text) Dim gst As Decimal = Decimal.Parse(txtGST.Text) Dim subtotal As Decimal = quantity * price Dim gstAmount As Decimal = subtotal * (gst / 100) Dim total As Decimal = subtotal + gstAmount txtSubtotal.Text = subtotal.ToString("N2") txtGSTAmount.Text = gstAmount.ToString("N2") txtTotal.Text = total.ToString("N2") End If End Sub Private Sub txtQuantity_TextChanged(sender As Object, e As EventArgs) Handles txtQuantity.TextChanged CalculateTotal() End Sub Private Sub btnAddToCart_Click(sender As Object, e As EventArgs) Handles btnAddToCart.Click If cmbProductName.SelectedValue Is Nothing Then MessageBox.Show("Please select a product") Return End If Dim productID As Integer = Convert.ToInt32(cmbProductName.SelectedValue) Dim productCode As String = txtProductCode.Text Dim productName As String = cmbProductName.Text Dim quantity As Integer = Integer.Parse(txtQuantity.Text) Dim unitPrice As Decimal = Decimal.Parse(txtPrice.Text) Dim gst As Decimal = Decimal.Parse(txtGST.Text) Dim total As Decimal = Decimal.Parse(txtTotal.Text) ' Check if product already in cart Dim existingRow As DataRow() = dtCart.Select("ProductID = " & productID) If existingRow.Length > 0 Then existingRow(0)("Quantity") = CInt(existingRow(0)("Quantity")) + quantity existingRow(0)("Total") = CDec(existingRow(0)("Quantity")) * unitPrice Else dtCart.Rows.Add(productID, productCode, productName, quantity, unitPrice, gst, total) End If UpdateGrandTotal() ClearProductFields() End Sub Private Sub UpdateGrandTotal() Dim grandTotal As Decimal = 0 For Each row As DataRow In dtCart.Rows grandTotal += CDec(row("Total")) Next lblGrandTotal.Text = "Grand Total: ₹" & grandTotal.ToString("N2") End Sub Private Sub ClearProductFields() cmbProductName.SelectedIndex = -1 txtProductCode.Clear() txtPrice.Clear() txtGST.Clear() txtQuantity.Clear() txtSubtotal.Clear() txtGSTAmount.Clear() txtTotal.Clear() txtQuantity.Text = "1" End Sub Private Sub btnRemoveFromCart_Click(sender As Object, e As EventArgs) Handles btnRemoveFromCart.Click If dgvCart.CurrentRow IsNot Nothing Then dtCart.Rows.RemoveAt(dgvCart.CurrentRow.Index) UpdateGrandTotal() End If End Sub Private Sub btnSaveInvoice_Click(sender As Object, e As EventArgs) Handles btnSaveInvoice.Click If dtCart.Rows.Count = 0 Then MessageBox.Show("Cart is empty!") Return End If If cmbCustomer.SelectedValue Is Nothing Then MessageBox.Show("Please select a customer") Return End If Try DBConnection.OpenConnection() Dim transaction As SqlTransaction = DBConnection.conn.BeginTransaction() Try ' Calculate totals Dim subtotal As Decimal = 0 Dim totalGST As Decimal = 0 For Each row As DataRow In dtCart.Rows subtotal += CDec(row("Total")) Next Dim totalAmount As Decimal = subtotal ' Insert Invoice Dim invoiceQuery As String = "INSERT INTO Invoices (InvoiceNumber, CustomerID, InvoiceDate, SubTotal, GSTAmount, TotalAmount, PaymentMethod, Status) VALUES (@InvoiceNo, @CustomerID, @Date, @SubTotal, @GST, @Total, @PaymentMethod, 'Completed') SELECT SCOPE_IDENTITY()" Using cmd As New SqlCommand(invoiceQuery, DBConnection.conn, transaction) cmd.Parameters.AddWithValue("@InvoiceNo", txtInvoiceNo.Text) cmd.Parameters.AddWithValue("@CustomerID", Convert.ToInt32(cmbCustomer.SelectedValue)) cmd.Parameters.AddWithValue("@Date", DateTime.Now) cmd.Parameters.AddWithValue("@SubTotal", subtotal) cmd.Parameters.AddWithValue("@GST", totalGST) cmd.Parameters.AddWithValue("@Total", totalAmount) cmd.Parameters.AddWithValue("@PaymentMethod", cmbPaymentMethod.Text) Dim invoiceID As Integer = Convert.ToInt32(cmd.ExecuteScalar()) ' Insert Invoice Items For Each row As DataRow In dtCart.Rows Dim itemQuery As String = "INSERT INTO InvoiceItems (InvoiceID, ProductID, Quantity, UnitPrice, TotalPrice, GSTAmount) VALUES (@InvoiceID, @ProductID, @Quantity, @UnitPrice, @TotalPrice, @GSTAmount)" Using itemCmd As New SqlCommand(itemQuery, DBConnection.conn, transaction) itemCmd.Parameters.AddWithValue("@InvoiceID", invoiceID) itemCmd.Parameters.AddWithValue("@ProductID", row("ProductID")) itemCmd.Parameters.AddWithValue("@Quantity", row("Quantity")) itemCmd.Parameters.AddWithValue("@UnitPrice", row("UnitPrice")) itemCmd.Parameters.AddWithValue("@TotalPrice", row("Total")) itemCmd.Parameters.AddWithValue("@GSTAmount", 0) itemCmd.ExecuteNonQuery() End Using Next End Using transaction.Commit() MessageBox.Show("Invoice saved successfully! Invoice No: " & txtInvoiceNo.Text) ' Print receipt PrintReceipt() ' Reset form ResetForm() Catch ex As Exception transaction.Rollback() MessageBox.Show("Error saving invoice: " & ex.Message) End Try Catch ex As Exception MessageBox.Show("Database error: " & ex.Message) Finally DBConnection.CloseConnection() End Try End Sub Private Sub PrintReceipt() ' Simple print preview Dim printDialog As New PrintDialog() Dim printDocument As New Printing.PrintDocument() AddHandler printDocument.PrintPage, AddressOf PrintDocument_PrintPage printDialog.Document = printDocument If printDialog.ShowDialog() = DialogResult.OK Then printDocument.Print() End If End Sub Private Sub PrintDocument_PrintPage(sender As Object, e As Printing.PrintPageEventArgs) Dim font As New Font("Arial", 10) Dim titleFont As New Font("Arial", 14, FontStyle.Bold) Dim yPos As Single = 50 Dim leftMargin As Single = 50 Dim xPos As Single = leftMargin ' Print Header e.Graphics.DrawString("BILLING SYSTEM", titleFont, Brushes.Black, xPos, yPos) yPos += 30 e.Graphics.DrawString("Invoice No: " & txtInvoiceNo.Text, font, Brushes.Black, xPos, yPos) yPos += 20 e.Graphics.DrawString("Date: " & DateTime.Now.ToString(), font, Brushes.Black, xPos, yPos) yPos += 20 e.Graphics.DrawString("Customer: " & cmbCustomer.Text, font, Brushes.Black, xPos, yPos) yPos += 30 ' Print Column Headers e.Graphics.DrawString("Product", font, Brushes.Black, xPos, yPos) e.Graphics.DrawString("Qty", font, Brushes.Black, xPos + 150, yPos) e.Graphics.DrawString("Price", font, Brushes.Black, xPos + 250, yPos) e.Graphics.DrawString("Total", font, Brushes.Black, xPos + 350, yPos) yPos += 20 e.Graphics.DrawLine(Pens.Black, leftMargin, yPos, 500, yPos) yPos += 10 ' Print Items For Each row As DataRow In dtCart.Rows e.Graphics.DrawString(row("ProductName").ToString(), font, Brushes.Black, xPos, yPos) e.Graphics.DrawString(row("Quantity").ToString(), font, Brushes.Black, xPos + 150, yPos) e.Graphics.DrawString(CDec(row("UnitPrice")).ToString("N2"), font, Brushes.Black, xPos + 250, yPos) e.Graphics.DrawString(CDec(row("Total")).ToString("N2"), font, Brushes.Black, xPos + 350, yPos) yPos += 20 Next yPos += 10 e.Graphics.DrawLine(Pens.Black, leftMargin, yPos, 500, yPos) yPos += 10 e.Graphics.DrawString("Grand Total: " & lblGrandTotal.Text, titleFont, Brushes.Black, xPos, yPos) End Sub Private Sub ResetForm() dtCart.Clear() GenerateInvoiceNumber() UpdateGrandTotal() ClearProductFields() cmbCustomer.SelectedIndex = -1 cmbPaymentMethod.SelectedIndex = -1 End Sub
End Class
Before examining the source code, we must define the scope. A minimum viable product (MVP) for billing software typically includes:
You might be thinking, “Why not start from a blank screen?” vb.net billing software source code
You could, but starting from scratch means reinventing the wheel. You’ll spend weeks just figuring out how to format invoice numbers or calculate tax brackets. By downloading or purchasing VB.NET billing source code, you get an instant MVP (Minimum Viable Product).
Here is what a good source code base gives you out of the box:
Instead of coding the database structure, you start with a working skeleton. Your job shifts from "plumbing" to "customizing." Public Class Product Public Property ProductID As Integer
Most VB.NET billing source code examples use either Microsoft SQL Server Express (free, robust) or MS Access (portable, simple). Below is a normalized schema for a professional system.
In the world of desktop application development, Visual Basic .NET (VB.NET) remains a surprisingly robust and efficient choice for building business applications, particularly billing and invoicing systems. Its rapid application development (RAD) environment, seamless integration with the .NET framework, and ease of database connectivity make it an ideal language for creating point-of-sale (POS) systems, retail billing software, and service invoicing tools.
If you are searching for "VB.NET billing software source code," you are likely looking to do one of three things: build a custom solution for your business, learn how billing logic works under the hood, or modify an open-source project to fit specific needs. End Class
This article will serve as a deep dive into the architecture, features, database design, and actual code structure of a professional billing software built with VB.NET.
When you download or build "VB.NET billing software source code," the Visual Studio solution will look like this: