miércoles, 15 de mayo de 2024

Mini Software de Recibo con VB .Net 2022 y Excel 365 + Impresion + Codigo Fuente

De la caja de Herramientas agregar PrintDocument1 y PrintPreviewDialog1.

Imports System.Runtime.InteropServices.JavaScript.JSType

Imports Microsoft.Office.Interop

Public Class frmGrid3

    Dim Aplicacion As Excel.Application

    Dim Libro As Excel.Workbook

    Dim hoja As Excel.Worksheet

    Private Sub frmGrid3_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        cargarLibro()

    End Sub

    Private Sub cargarLibro()

        DataGridView1.ColumnCount = 3

        DataGridView1.Columns(0).Name = "Bar Code"

        DataGridView1.Columns(1).Name = "Producto"

        DataGridView1.Columns(2).Name = "Precio"

        DataGridView1.Columns(1).Width = 200

        Try

            Aplicacion = New Excel.Application

            Libro = Aplicacion.Workbooks.Open("C:\Users\miky mouse\OneDrive\ejemplo25.xlsx")

            hoja = Libro.Worksheets(2)

        Catch ex As Exception

            closeL()

            MsgBox("Error " + ex.ToString())

        End Try

    End Sub

    Private Sub closeL()

        Libro.Close()

        Aplicacion.Quit()

    End Sub

Private Sub frmGrid3_Closed(sender As Object, e As EventArgs) Handles MyBase.Closed

        Libro.Close()

        Aplicacion.Quit()

    End Sub

Private Sub TextBox1_KeyDown(sender As Object, e As KeyEventArgs) Handles TextBox1.KeyDown

        Dim bc As String

        Dim dato(3) As String

        Dim cad As String

        Dim j As Integer

        j = 0

        cad = " "

        Dim op As Integer

        op = 0

        If e.KeyCode = 13 Then

            bc = TextBox1.Text

            For j = 2 To 24

                If CLng(bc) = CLng(hoja.Cells(j, 1).Value) Then

                    dato(0) = hoja.Cells(j, 1).value

                    dato(1) = hoja.Cells(j, 2).value

                    dato(2) = hoja.Cells(j, 3).value

                    DataGridView1.Rows.Add(dato)

                    op = 1

                    calTot()

                End If

            Next

            If op = 0 Then

                cad = "No tenemos el Producto "

            End If

            MsgBox(cad + bc)

            TextBox1.Text = " "

        End If

    End Sub

    Private Sub calTot()

        Dim S As Double

        Dim pre As Double

        Dim tax As Double

        Dim tot As Double

        Dim n As Integer

        S = 0.00

        pre = 0.00

        n = DataGridView1.RowCount - 1

        For fila = 0 To n

            pre = CDbl(DataGridView1.Item(2, fila).Value)

            S = S + pre

        Next

        S = Math.Round(S, 2)

        lblSub.Text = S.ToString()

        tax = 0.09 * S

        tax = Math.Round(tax, 2)

        lblTax.Text = tax.ToString()

        tot = S + tax

        tot = Math.Round(tot, 2)

        lblTot.Text = tot.ToString()

    End Sub

Private Sub PrintDocument1_PrintPage(sender As Object, e As Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage

        Dim n As Integer

        Dim fila2 As Single

        Dim fila3 As Single

        Dim f1, f2, f3 As Single

        Dim cad As String

        Dim cad2 As String

        Dim cad3 As String

        Dim cad4 As String

        Dim cad5 As String

        Dim j As Integer

        fila3 = 1

        fila2 = 1

        Try

            n = DataGridView1.RowCount - 1

            e.Graphics.DrawString("MinuvaMarket", New Font("Arial", 16), New SolidBrush(Color.Black), 50, 50)

            For j = 0 To n

                fila3 = 80 + fila2 * 10

                cad = DataGridView1.Item(1, j).Value

                cad2 = DataGridView1.Item(2, j).Value

                e.Graphics.DrawString(cad, New Font("Arial", 13), New SolidBrush(Color.Black), 20, fila3)

                e.Graphics.DrawString(cad2, New Font("Arial", 13), New SolidBrush(Color.Black), 300, fila3)

                fila2 = fila2 + 2

            Next

            cad3 = "Sub Total.." + lblSub.Text

            cad4 = "Tax........" + lblTax.Text

            cad5 = "Total......" + lblTot.Text

            f1 = fila3 + 20

            f2 = fila3 + 40

            f3 = fila3 + 60

            e.Graphics.DrawString(cad3, New Font("Arial", 13), New SolidBrush(Color.Black), 250, f1)

            e.Graphics.DrawString(cad4, New Font("Arial", 13), New SolidBrush(Color.Black), 250, f2)

            e.Graphics.DrawString(cad5, New Font("Arial", 13), New SolidBrush(Color.Black), 250, f3)

        Catch ex As Exception

            closeL()

            MsgBox("Error " + ex.ToString())

        End Try

    End Sub

Private Sub btnPrint_Click(sender As Object, e As EventArgs) Handles btnPrint.Click

        PrintPreviewDialog1.Document = PrintDocument1

        PrintPreviewDialog1.Width = 500

        PrintPreviewDialog1.Height = 600

        PrintPreviewDialog1.Left = 600

        PrintPreviewDialog1.Top = 150

        PrintPreviewDialog1.ShowDialog()

    End Sub

End Class

download Source Code

Para optimizacion del programa comunicarse a minuvasoft10@gmail.com -- Miguel Nunez




No hay comentarios:

Publicar un comentario

Conectar a MySql con Java Netbeans mediante un Formulario

 Tener agregado en libraries el conector mysql. clase coneBD.java package pktForm12; import java.sql.*; import javax.swing.JOptionPane; publ...