Parte 19 – Ventana de Inventario en Visual Basic 6

Siguiente con esta lección trabajamos la ventana de inventario en Visual Basic 6, la cual nos muestra el listado de productos de nuestro inventario.

En este vídeo se termina de organizar la ventana de Productos y se inicia con la ventana de Inventario, para la ventana de productos nos faltaba inicializar los campos de formulario poner los campos que llevan texto a vació y lo datos de valor a cero.

Y en la ventana de Inventario se trabajo el LlenarProductosGrid que es para listar los productos del Inventario dependiendo del Filtro que se use.

Ventana de Producto

Sub IniciarTextos()
    
    txtCodigoPro = ""
    txtNombrePro.Text = ""
    txtNombreCort.Text = ""
    txtEstante.Text = "-"
    txtExistencia.Text = "0"
    txtExistMinima.Text = "0"
    
    txtPrecioCosto.Text = 0
    txtImpuesto.Text = 0
    txtPrecioCImp.Text = 0
    
    txtProcV1.Text = "0"
    txtProcV2.Text = "0"
    txtProcV3.Text = "0"
    txtProcVMinim.Text = "0"
    
    txtPrecioV1.Text = "0"
    txtPrecioV2.Text = "0"
    txtPrecioV3.Text = "0"
    txtPrecioVMinim.Text = "0"
    
    txtUtilidadP1.Text = "0"
    txtUtilidadP2.Text = "0"
    txtUtilidadP3.Text = "0"
    txtUtilidadP4.Text = "0"
    
End Sub

En el evento Load del formulario y en el Sub Procedimiento Guardado.

Private Sub Form_Load()
    CodigoProducto = 0
    Call LimpiarTextos
    Call LlenarProveedores
    Call LlenarCategorias
End Sub
Sub GuardarProducto()
    If txtCodigoPro.Text = "" Then
       MsgBox "Debe llenar el Campo Código", vbExclamation, "Error"
       Exit Sub
    End If
    If txtNombrePro.Text = "" Then
       MsgBox "Debe llenar el Campo Nombre del Producto", vbExclamation, "Error"
       Exit Sub
    End If
    If txtNombreCort.Text = "" Then
       MsgBox "Debe llenar el Campo Nombre Corto", vbExclamation, "Error"
       Exit Sub
    End If
    If txtEstante.Text = "" Then
       MsgBox "Debe llenar el Campo Estante", vbExclamation, "Error"
       Exit Sub
    End If
    
    If txtPrecioCosto.Text = "" Then
       MsgBox "Debe llenar el Campo Precio Costo", vbExclamation, "Error"
       Exit Sub
    End If
    If txtPrecioV1.Text = "" Then
       MsgBox "Debe llenar el Campo Precio Venta 1", vbExclamation, "Error"
       Exit Sub
    End If
    If txtImpuesto.Text = "" Then
       MsgBox "Debe llenar el Campo Impuesto", vbExclamation, "Error"
       Exit Sub
    End If
    
    
    If CodigoProveedor = 0 Then
        IdProducto = UltimoIdTabla("tblProductos", "IdProducto")
        CodCategoria = cmbCategorias.ItemData(cmbCategorias.ListIndex + 1)
        CodProv = cmdProveedor.ItemData(cmdProveedor.ListIndex + 1)
        Sql = "Insert Into tblProductos (IdProducto, CodigoPro, NombrePro, NombreCortoPro,EstantePro, ExistPro, ExistMinPro, PCostoPro,PVenta1Pro, PVenta2Pro, PVenta3Pro, PMinimoPro, IdCategoria, IdProveedor) Values (" & IdProducto & ",'" & txtCodigoPro & "','" & txtNombrePro & "','" & txtNombreCort & "','" & txtEstante & "','" & txtExistencia & "','" & txtExistMinima & "','" & txtPrecioCosto & "','" & txtPrecioV1 & "','" & txtPrecioV2 & "','" & txtPrecioV3 & "', '" & txtPrecioVMinim & "', " & CodCategoria & ", " & CodProv & ") "
    Else
        'Sql = "Update tblProductos SET NombreEmpresaPro = '" & txtNombreEmpresa & "',NitEmpresaPro = '" & txtNit & "',NombrePro = '" & txtNombreContacto & "',TelefonoPro = '" & txtTelefono & "',DireccionPro = '" & txtDireccion & "',EmailPro = '" & txtEmail & "' Where tblProveedores = " & CodigoProveedor
    End If
    ConexionADO.Execute Sql
    MsgBox "Producto Guardado", vbInformation, "Guardar"
    Call LimpiarTextos
    txtCodigoPro.SetFocus
End Sub

Ventana de Inventario en Visual Basic 6

El Procedimiento de Llenar Grid es el siguiente:

Sub LlenarProductosGrid()
    Dim Sql As String
    Dim Filtro As String
    Dim Ordenar As String
    Dim Columnas As Integer
    Dim Op, Ord As Integer
    
    Op = cmdTipoBusqueda.ListIndex
    Filtro = ""
    
    Select Case Op
        Case 0:
            Filtro = " tblProductos.NombrePro Like '%" & txtFiltro & "%'"
        Case 1:
            Filtro = " tblProductos.CodigoPro Like '%" & txtFiltro & "%'"
        Case 2:
            Filtro = " tblCategorias.NombreCategoria Like '%" & txtFiltro & "%'"
        Case 3:
            Filtro = " tblProveedores.NombreEmpresaPro Like '%" & txtFiltro & "%'"
        Case 4:
            Filtro = " tblProductos.PVenta1Pro >= " & txtFiltro
        Case 5:
            Filtro = " tblProductos.PVenta1Pro <= " & txtFiltro
    End Select
    
    Ord = cmdOrdenarpor.ListIndex
    
    Select Case Ord
        Case 0:
            Ordenar = " tblProductos.NombrePro ASC "
        Case 1:
            Ordenar = " tblProductos.CodigoPro ASC "
   End Select
        
    
    Sql = "SELECT tblProductos.IdProducto, tblProductos.CodigoPro, tblProductos.NombrePro, tblProductos.ExistPro, tblProductos.ExistMinPro, Format(tblProductos.PCostoPro,'currency'), Format(tblProductos.PVenta1Pro,'currency'), Format(tblProductos.PVenta2Pro,'currency'), Format(tblProductos.PVenta3Pro,'currency'), Format(tblProductos.PMinimoPro,'currency'), tblCategorias.NombreCategoria, tblProveedores.NombreEmpresaPro " _
        & " FROM (tblProductos INNER JOIN tblCategorias ON tblProductos.IdCategoria = tblCategorias.Idcategoria) INNER JOIN tblProveedores ON tblProductos.IdProveedor = tblProveedores.IdProveedor WHERE " & Filtro & " order by " & Ordenar
        
   Columnas = 12
   
   Call LlenarGrid(msGrid, Sql, Columnas)
   
    msGrid.ColWidth(0) = 0
    msGrid.ColWidth(1) = 0
    msGrid.ColWidth(2) = 1800
    msGrid.ColWidth(3) = 4000
    msGrid.ColWidth(4) = 1100
    msGrid.ColWidth(5) = 1100
    msGrid.ColWidth(6) = 1500
    msGrid.ColWidth(7) = 1500
    msGrid.ColWidth(8) = 1500
    msGrid.ColWidth(9) = 1500
    msGrid.ColWidth(10) = 2000
    msGrid.ColWidth(11) = 2000
    msGrid.ColWidth(12) = 4000
   
    msGrid.TextMatrix(0, 2) = "Código"
    msGrid.TextMatrix(0, 3) = "Nombre Producto"
    msGrid.TextMatrix(0, 4) = "Exist"
    msGrid.TextMatrix(0, 5) = "Exis. Min"
    msGrid.TextMatrix(0, 6) = "P. Costo"
    msGrid.TextMatrix(0, 7) = "P. Venta 1"
    msGrid.TextMatrix(0, 8) = "P. Venta 2"
    msGrid.TextMatrix(0, 9) = "P. Venta 3"
    msGrid.TextMatrix(0, 10) = "P. Mínima"
    msGrid.TextMatrix(0, 11) = "Categoría"
    msGrid.TextMatrix(0, 12) = "Proveedor"
    
    msGrid.ColAlignment(4) = flexAlignCenterCenter
    msGrid.ColAlignment(5) = flexAlignCenterCenter
    
    SumTotal = 0
    For Fila = 1 To msGrid.Rows - 1
        Exist = msGrid.TextMatrix(Fila, 4)
        PrecioCost = CCur(msGrid.TextMatrix(Fila, 6))
        SumaTotal = SumaTotal + (Exist * PrecioCost)
    Next Fila
    
    txtTotalLista.Text = Format(SumaTotal, "currency")
End Sub

Eventos

Private Sub cmdCerrar_Click()
    Unload Me
End Sub

Private Sub cmdNuevo_Click()
    frmProducto.Show
End Sub

Private Sub Form_Load()
    cmdTipoBusqueda.ListIndex = 0
    cmdOrdenarpor.ListIndex = 0
    Call LlenarProductosGrid
End Sub

Private Sub txtFiltro_KeyUp(KeyCode As Integer, Shift As Integer)
    If KeyCode = 13 Then
       Call LlenarProductosGrid
    End If
End Sub

Siguiente Lección  Curso Software de Ventas Parte 20, Borrar y Exportar Productos

Total Page Visits: 5262 - Today Page Visits: 1

Deja una respuesta