' Connection string for MS Access (change path accordingly) Dim connString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\BillingDB.accdb" Dim currentBillID As Integer = -1
Private Sub LoadBillData() ' Fetch Bill Header and Items using billID from DB ' (Implement using OleDbDataAdapter) ' Then bind to PrintDocument End Sub
BillID (AutoNumber, PK) BillDate (Date/Time) CustomerID (Number) Subtotal (Currency) TaxAmount (Currency) DiscountAmount (Currency) GrandTotal (Currency)
Private Sub SaveBillItem(billID As Integer, productID As Integer, qty As Integer, price As Decimal, total As Decimal) Dim query As String = "INSERT INTO BillItems (BillID, ProductID, Quantity, Price, Total) VALUES (@bid, @pid, @qty, @price, @total)" Using conn As New OleDbConnection(connString) Dim cmd As New OleDbCommand(query, conn) cmd.Parameters.AddWithValue("@bid", billID) cmd.Parameters.AddWithValue("@pid", productID) cmd.Parameters.AddWithValue("@qty", qty) cmd.Parameters.AddWithValue("@price", price) cmd.Parameters.AddWithValue("@total", total) conn.Open() cmd.ExecuteNonQuery() End Using End Sub
Private Function SaveCustomer(name As String, mobile As String, gstin As String) As Integer Dim query As String = "INSERT INTO Customers (Name, Mobile, GSTIN) VALUES (@name, @mob, @gst); SELECT SCOPE_IDENTITY()" Using conn As New OleDbConnection(connString) Dim cmd As New OleDbCommand(query, conn) cmd.Parameters.AddWithValue("@name", name) cmd.Parameters.AddWithValue("@mob", mobile) cmd.Parameters.AddWithValue("@gst", gstin) conn.Open() Return CInt(cmd.ExecuteScalar()) End Using End Function
CustomerID (AutoNumber, PK) Name (Text) Mobile (Text) GSTIN (Text)
Private Sub CalculateTotals() Dim subtotal As Decimal = 0 For Each row As DataGridViewRow In dgvItems.Rows If Not row.IsNewRow Then subtotal += CDec(row.Cells("colTotal").Value) End If Next
Private Sub btnSaveBill_Click(sender As Object, e As EventArgs) Handles btnSaveBill.Click If dgvItems.Rows.Count = 0 Then MessageBox.Show("Add at least one item.") Return End If
Private Sub PrintDocument1_PrintPage(sender As Object, e As PrintPageEventArgs) Handles PrintDocument1.PrintPage Dim font As New Font("Arial", 10) Dim y As Single = e.MarginBounds.Top
ItemID (AutoNumber, PK) BillID (Number) ProductID (Number) Quantity (Number) Price (Currency) Total (Currency) Note : This is a working minimal example. Add error handling, data validation, and DB connection string as needed. 1. Main Form – frmBilling.vb Imports System.Data.OleDb Public Class frmBilling
lblSubtotal.Text = subtotal.ToString("N2") lblTax.Text = taxAmount.ToString("N2") lblDiscount.Text = discount.ToString("N2") lblGrandTotal.Text = grandTotal.ToString("N2") End Sub
' Connection string for MS Access (change path accordingly) Dim connString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\BillingDB.accdb" Dim currentBillID As Integer = -1
Private Sub LoadBillData() ' Fetch Bill Header and Items using billID from DB ' (Implement using OleDbDataAdapter) ' Then bind to PrintDocument End Sub
BillID (AutoNumber, PK) BillDate (Date/Time) CustomerID (Number) Subtotal (Currency) TaxAmount (Currency) DiscountAmount (Currency) GrandTotal (Currency) vb.net billing software source code
Private Sub SaveBillItem(billID As Integer, productID As Integer, qty As Integer, price As Decimal, total As Decimal) Dim query As String = "INSERT INTO BillItems (BillID, ProductID, Quantity, Price, Total) VALUES (@bid, @pid, @qty, @price, @total)" Using conn As New OleDbConnection(connString) Dim cmd As New OleDbCommand(query, conn) cmd.Parameters.AddWithValue("@bid", billID) cmd.Parameters.AddWithValue("@pid", productID) cmd.Parameters.AddWithValue("@qty", qty) cmd.Parameters.AddWithValue("@price", price) cmd.Parameters.AddWithValue("@total", total) conn.Open() cmd.ExecuteNonQuery() End Using End Sub
Private Function SaveCustomer(name As String, mobile As String, gstin As String) As Integer Dim query As String = "INSERT INTO Customers (Name, Mobile, GSTIN) VALUES (@name, @mob, @gst); SELECT SCOPE_IDENTITY()" Using conn As New OleDbConnection(connString) Dim cmd As New OleDbCommand(query, conn) cmd.Parameters.AddWithValue("@name", name) cmd.Parameters.AddWithValue("@mob", mobile) cmd.Parameters.AddWithValue("@gst", gstin) conn.Open() Return CInt(cmd.ExecuteScalar()) End Using End Function ' Connection string for MS Access (change path
CustomerID (AutoNumber, PK) Name (Text) Mobile (Text) GSTIN (Text)
Private Sub CalculateTotals() Dim subtotal As Decimal = 0 For Each row As DataGridViewRow In dgvItems.Rows If Not row.IsNewRow Then subtotal += CDec(row.Cells("colTotal").Value) End If Next Main Form – frmBilling
Private Sub btnSaveBill_Click(sender As Object, e As EventArgs) Handles btnSaveBill.Click If dgvItems.Rows.Count = 0 Then MessageBox.Show("Add at least one item.") Return End If
Private Sub PrintDocument1_PrintPage(sender As Object, e As PrintPageEventArgs) Handles PrintDocument1.PrintPage Dim font As New Font("Arial", 10) Dim y As Single = e.MarginBounds.Top
ItemID (AutoNumber, PK) BillID (Number) ProductID (Number) Quantity (Number) Price (Currency) Total (Currency) Note : This is a working minimal example. Add error handling, data validation, and DB connection string as needed. 1. Main Form – frmBilling.vb Imports System.Data.OleDb Public Class frmBilling
lblSubtotal.Text = subtotal.ToString("N2") lblTax.Text = taxAmount.ToString("N2") lblDiscount.Text = discount.ToString("N2") lblGrandTotal.Text = grandTotal.ToString("N2") End Sub