|
|
|||||||||||
Vb.net Billing Software Source Code Apr 2026Private 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 Sub btnPrint_Click(sender As Object, e As EventArgs) Handles btnPrint.Click PrintDocument1.Print() End Sub Private Sub ResetBill() txtCustomerName.Clear() txtMobile.Clear() txtGSTIN.Clear() dgvItems.Rows.Clear() nudQuantity.Value = 1 lblSubtotal.Text = "0.00" lblTax.Text = "0.00" lblDiscount.Text = "0.00" lblGrandTotal.Text = "0.00" currentBillID = -1 btnPrint.Enabled = False End Sub End Class Imports System.Drawing.Printing Public Class frmPrintPreview Private billID As Integer Private billData As DataTable Private itemsData As DataTable MessageBox.Show("Bill saved successfully! Bill No: " & billID) currentBillID = billID btnPrint.Enabled = True End Sub vb.net billing software source code 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 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 frmBilling_Load(sender As Object, e As EventArgs) Handles MyBase.Load LoadProductsIntoCombo() ResetBill() End Sub Private Sub SaveBillItem(billID As Integer Public Sub New(billID As Integer) InitializeComponent() Me.billID = billID LoadBillData() End Sub ' Save Bill Header Dim billID As Integer = SaveBillHeader(custID, CDec(lblSubtotal.Text), CDec(lblTax.Text), CDec(lblDiscount.Text), CDec(lblGrandTotal.Text)) Private Sub LoadProductsIntoCombo() Dim query As String = "SELECT ProductID, ProductName FROM Products" Using conn As New OleDbConnection(connString) Dim da As New OleDbDataAdapter(query, conn) Dim dt As New DataTable() da.Fill(dt) cboProduct.DataSource = dt cboProduct.DisplayMember = "ProductName" cboProduct.ValueMember = "ProductID" End Using End Sub productID As Integer Private Sub btnAddItem_Click(sender As Object, e As EventArgs) Handles btnAddItem.Click If cboProduct.SelectedValue Is Nothing Then Exit Sub Dim productID As Integer = CInt(cboProduct.SelectedValue) Dim productName As String = cboProduct.Text Dim qty As Integer = CInt(nudQuantity.Value) Dim price As Decimal = GetProductPrice(productID) Dim total As Decimal = price * qty Private Sub btnNewBill_Click(sender As Object, e As EventArgs) Handles btnNewBill.Click ResetBill() End Sub ' Save Bill Items For Each row As DataGridViewRow In dgvItems.Rows If Not row.IsNewRow Then SaveBillItem(billID, CInt(row.Cells("colProductID").Value), CInt(row.Cells("colQty").Value), CDec(row.Cells("colPrice").Value), CDec(row.Cells("colTotal").Value)) End If Next CustomerID (AutoNumber, PK) Name (Text) Mobile (Text) GSTIN (Text) 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 |