Visual Basic.NET - ¿Como hacer un sistema de ventas en VB.net 2010?

 
Vista:
Imágen de perfil de Cristopher Alexis
Val: 37
Ha mantenido su posición en Visual Basic.NET (en relación al último mes)
Gráfica de Visual Basic.NET

¿Como hacer un sistema de ventas en VB.net 2010?

Publicado por Cristopher Alexis (12 intervenciones) el 04/12/2020 22:14:50
Hola buen dia colegas como estan espero que se encuentren muy bien.
bueno les comento, necesito ayuda con un proyecto en el cual necesito implementar un sistema de ventas como el que les muestro acontinuación.
este es eleventa un software de punto de venta del que me estoy guiando, y deseo que mi programa aumente la cantidad cada vez que se ingrese un producto que ya esta en la lista :(

Primera imagen es la de eleventa
Captura-de-pantalla-31

Pero el problema es este que al momento de querer agregar mas de un producto a la lista me sucede esto!:->

Segunda imagen es mi programa, se llama venta plus
Captura-de-pantalla-32

Este es el codi que estpy usando, agradeceria que me ayudaran y me dijeran en que puedo mejorar :)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
Public CodigoBarra As String
    Public DescripcionProducto As String
    Public PrecioVenta As Double
    Public Cantidad As Double
    Public Importe As Double
    Public Total As Double
    Public TotalProd As Double
 
Private Sub btnAgregarP_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAgregarP.Click
        AgregarAVenta(txtCodigoBarras.Text)
        Total = Format(Sumar("Column5", dgvDetalleVenta), "c2")
        TotalProd = Sumar("Column4", dgvDetalleVenta)
 
        lbTotal.Text = Total
        lbTotalProductos.Text = "Total de productos:" & " " & TotalProd
 
        txtCodigoBarras.Text = ""
        txtCodigoBarras.Focus()
    End Sub
 
    Public Sub AgregarAVenta(ByVal Producto As String)
        'If dgvDetalleVenta.RowCount > 0 Then
 
        'End If
        Select Case lstGiro.Text
            Case "Carpinteria"
                VentaCarpinteria(Producto)
                If dgvDetalleVenta.RowCount = 0 Then
                    dgvDetalleVenta.Rows.Add(CodigoBarra, DescripcionProducto, PrecioVenta, Cantidad, Importe)
                ElseIf dgvDetalleVenta.RowCount > 0 Then
                    For i As Integer = 0 To dgvDetalleVenta.RowCount - 1 Step +1
                        If dgvDetalleVenta.Rows(i).Cells(0).Value = txtCodigoBarras.Text Then
                            dgvDetalleVenta.Rows(i).Cells(3).Value = dgvDetalleVenta.Rows(i).Cells(3).Value + 1
                            dgvDetalleVenta.Rows(i).Cells(4).Value = dgvDetalleVenta.Rows(i).Cells(3).Value * dgvDetalleVenta.Rows(i).Cells(2).Value
                            Exit For
                        Else
                            dgvDetalleVenta.Rows.Add(CodigoBarra, DescripcionProducto, PrecioVenta, Cantidad, Importe)
                            Exit For
                        End If
                    Next
                End If
 
        End Select
    End Sub
 
    Public Sub VentaCarpinteria(ByVal Prduct)
        Dim SQL As String = "select Referencia,Nombre,Precioalpublico from Tbl_ProductosCarpinteria where Referencia = '" & Prduct & "'"
        comando.CommandType = CommandType.Text
        comando.CommandText = SQL
        comando.Connection = conexion_
 
        If txtCodigoBarras.Text <> "" Then
            Try
                Lector = comando.ExecuteReader()
                If Lector.HasRows() Then
                    While Lector.Read()
                        CodigoBarra = Lector(0).ToString
                        DescripcionProducto = Lector(1).ToString
                        PrecioVenta = Lector(2).ToString
                        Cantidad = 1
                        Importe = Cantidad * PrecioVenta
                    End While
                End If
                Lector.Close()
 
            Catch ex As Exception
                MsgBox(ex.ToString)
            End Try
        End If
    End Sub
Agradezco infinitamente su ayuda sin mas me despido esperando gracias.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
sin imagen de perfil
Val: 11
Ha aumentado su posición en 15 puestos en Visual Basic.NET (en relación al último mes)
Gráfica de Visual Basic.NET

¿Como hacer un sistema de ventas en VB.net 2010?

Publicado por RONALD (2 intervenciones) el 04/12/2020 22:59:22
Hola buena tarde, el problema se debe a que estas agregando una nueva fila al mismo tiempo en que estas realizando el recorrido del DataGrid, primero deberias recorrer el DataGrid y colocar una variable que te evalue si existe o no existe ese codigo de barras en el Grid y posteriormente en base al resultado que tenga esa variable decides si agregas una nueva fila al grid o actualizas una fila ya existente. Seria algo asi:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
Dim VarAux1=0
Dim FilaNumero=0
 
Case "Carpinteria"
    VentaCarpinteria(Producto)
    If dgvDetalleVenta.RowCount = 0 Then
        dgvDetalleVenta.Rows.Add(CodigoBarra, DescripcionProducto, PrecioVenta, Cantidad, Importe)
    ElseIf dgvDetalleVenta.RowCount > 0 Then
        For i As Integer = 0 To dgvDetalleVenta.RowCount - 1 Step +1
            If dgvDetalleVenta.Rows(i).Cells(0).Value = txtCodigoBarras.Text Then
                VarAux1 = 1
                FilaNumero = i
                Exit For
            End If
        Next
 
        if VarAux1=0 then
               dgvDetalleVenta.Rows.Add(CodigoBarra, DescripcionProducto, PrecioVenta, Cantidad, Importe)
        else
                dgvDetalleVenta.Rows(FilaNumero).Cells(3).Value = dgvDetalleVenta.Rows(i).Cells(3).Value + 1
                dgvDetalleVenta.Rows(FilaNumero).Cells(4).Value = dgvDetalleVenta.Rows(i).Cells(3).Value * dgvDetalleVenta.Rows(i).Cells(2).Value
        end if
 
    End If
 
End Select


Esa seria mas o menos la idea verifica la sintaxis y la logica porque estoy escribiendo el codigo sin pasarlo por ningun editor para VB.
Espero que te sea util.

Saludos
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
1
Comentar
Imágen de perfil de Cristopher Alexis
Val: 37
Ha mantenido su posición en Visual Basic.NET (en relación al último mes)
Gráfica de Visual Basic.NET

¿Como hacer un sistema de ventas en VB.net 2010?

Publicado por Cristopher Alexis (12 intervenciones) el 05/12/2020 06:52:03
Wooou amigo muchas gracias, Sr. Ronald

Esta respuesta me soluciono en absoluto mi problema agradezco su tiempo y gentilesa.
espero que tenga un excelente dia y nuevamente le agradezco, me salvo. estare compartiendo la beta de mi proyecto

Dejo aqui el codigo ya mejorado por si puedo ayudar a algun colega más:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
Public Sub AgregarAVenta(ByVal Producto As String)
    Dim VarAux1 As Integer = 0
    Dim FilaNumero As Integer = 0
    Select Case lstGiro.Text
        Case "Carpinteria"
            SwichVenta(Producto)
            If dgvDetalleVenta.RowCount = 0 Then
                dgvDetalleVenta.Rows.Add(CodigoBarra, DescripcionProducto, PrecioVenta, Cantidad, Importe, Stock)
                dgvDetalleVenta.Rows(FilaNumero).Cells(5).Value = Stock - 1
            ElseIf dgvDetalleVenta.RowCount > 0 Then
                For i As Integer = 0 To dgvDetalleVenta.RowCount - 1 Step +1
                    If dgvDetalleVenta.Rows(i).Cells(0).Value = txtCodigoBarras.Text Then
                        VarAux1 = 1
                        FilaNumero = i
                        Exit For
                    End If
                Next
                If VarAux1 = 0 Then
                    dgvDetalleVenta.Rows.Add(CodigoBarra, DescripcionProducto, PrecioVenta, Cantidad, Importe, Stock)
                    dgvDetalleVenta.Rows(FilaNumero).Cells(5).Value = Stock - 1
                ElseIf VarAux1 = 1 Then
                    If dgvDetalleVenta.Rows(FilaNumero).Cells(5).Value > 0 Then
                        dgvDetalleVenta.Rows(FilaNumero).Cells(3).Value = dgvDetalleVenta.Rows(FilaNumero).Cells(3).Value + 1
                        dgvDetalleVenta.Rows(FilaNumero).Cells(4).Value = dgvDetalleVenta.Rows(FilaNumero).Cells(3).Value * dgvDetalleVenta.Rows(FilaNumero).Cells(2).Value
                        dgvDetalleVenta.Rows(FilaNumero).Cells(5).Value = dgvDetalleVenta.Rows(FilaNumero).Cells(5).Value - 1
                    Else
                        MsgBox("O_o Ojo O_o" + vbNewLine + "¡No cuentas con stock disponible para esta operación!" + vbNewLine + "Renueva", MsgBoxStyle.Exclamation)
                    End If
                End If
            End If
        Case "Aluminio"
 
    End Select
End Sub
 
Public Sub SwichVenta(ByVal Prduct)
    Select Case lstGiro.Text
        Case "Carpinteria"
            Dim SQL As String = "select Referencia,Nombre,Precioalpublico,StockDisponible from Tbl_ProductosCarpinteria where Referencia = '" & Prduct & "'"
            comando.CommandType = CommandType.Text
            comando.CommandText = SQL
            comando.Connection = conexion_
 
            If txtCodigoBarras.Text <> "" Then
                Try
                    Lector = comando.ExecuteReader()
                    If Lector.HasRows() Then
                        While Lector.Read()
                            CodigoBarra = Lector(0).ToString
                            DescripcionProducto = Lector(1).ToString
                            PrecioVenta = Lector(2).ToString
                            Stock = Lector(3).ToString
                            Cantidad = 1
                            Importe = Cantidad * PrecioVenta
                        End While
                    End If
                    Lector.Close()
                Catch ex As Exception
                    MsgBox(ex.ToString)
                End Try
            End If
        Case "Aluminio"
            Dim SQL As String = "select Referencia,Nombre,Precioalpublico,StockDisponible from Tbl_ProductosCarpinteria where Referencia = '" & Prduct & "'"
            comando.CommandType = CommandType.Text
            comando.CommandText = SQL
            comando.Connection = conexion_
 
            If txtCodigoBarras.Text <> "" Then
                Try
                    Lector = comando.ExecuteReader()
                    If Lector.HasRows() Then
                        While Lector.Read()
                            CodigoBarra = Lector(0).ToString
                            DescripcionProducto = Lector(1).ToString
                            PrecioVenta = Lector(2).ToString
                            Stock = Lector(3).ToString
                            Cantidad = 1
                            Importe = Cantidad * PrecioVenta
                        End While
                    End If
                    Lector.Close()
                Catch ex As Exception
                    MsgBox(ex.ToString)
                End Try
            End If
    End Select
 
End Sub

Nuevamente muchas gracias
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar