VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Begin VB.Form frmProductoLista 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Relación de Productos"
   ClientHeight    =   5805
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   9015
   Icon            =   "frmProductoLista.frx":0000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   5805
   ScaleWidth      =   9015
   StartUpPosition =   2  'CenterScreen
   Begin VB.CommandButton cmdEditar 
      Caption         =   "&Ver"
      Height          =   375
      Index           =   3
      Left            =   4125
      TabIndex        =   3
      Top             =   5280
      Width           =   1335
   End
   Begin VB.CommandButton cmdActivar 
      Caption         =   "Ac&tivar"
      Height          =   375
      Left            =   6120
      TabIndex        =   4
      Top             =   5280
      Width           =   1335
   End
   Begin MSComctlLib.ImageList imlUsuario 
      Left            =   5640
      Top             =   5400
      _ExtentX        =   1005
      _ExtentY        =   1005
      BackColor       =   -2147483643
      ImageWidth      =   16
      ImageHeight     =   16
      MaskColor       =   12632256
      _Version        =   393216
      BeginProperty Images {2C247F25-8591-11D1-B16A-00C0F0283628} 
         NumListImages   =   2
         BeginProperty ListImage1 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "frmProductoLista.frx":08CA
            Key             =   ""
         EndProperty
         BeginProperty ListImage2 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "frmProductoLista.frx":0D1C
            Key             =   ""
         EndProperty
      EndProperty
   End
   Begin VB.CommandButton cmdSalir 
      Caption         =   "&Salir"
      Height          =   375
      Left            =   7560
      TabIndex        =   5
      Top             =   5280
      Width           =   1335
   End
   Begin VB.CommandButton cmdEditar 
      Caption         =   "&Borrar"
      Height          =   375
      Index           =   2
      Left            =   2790
      TabIndex        =   2
      Top             =   5280
      Width           =   1335
   End
   Begin VB.CommandButton cmdEditar 
      Caption         =   "&Editar"
      Height          =   375
      Index           =   1
      Left            =   1455
      TabIndex        =   1
      Top             =   5280
      Width           =   1335
   End
   Begin VB.CommandButton cmdEditar 
      Caption         =   "&Nuevo"
      Height          =   375
      Index           =   0
      Left            =   120
      TabIndex        =   0
      Top             =   5280
      Width           =   1335
   End
   Begin MSComctlLib.ListView lvwProducto 
      Height          =   4800
      Left            =   135
      TabIndex        =   6
      Top             =   390
      Width           =   8775
      _ExtentX        =   15478
      _ExtentY        =   8467
      LabelEdit       =   1
      LabelWrap       =   -1  'True
      HideSelection   =   0   'False
      _Version        =   393217
      Icons           =   "imlUsuario"
      SmallIcons      =   "imlUsuario"
      ForeColor       =   -2147483640
      BackColor       =   -2147483643
      BorderStyle     =   1
      Appearance      =   1
      NumItems        =   0
   End
   Begin VB.Label lblLabels 
      Alignment       =   2  'Center
      BorderStyle     =   1  'Fixed Single
      Caption         =   "Productos"
      Height          =   255
      Left            =   120
      TabIndex        =   7
      Top             =   120
      Width           =   8775
   End
End
Attribute VB_Name = "frmProductoLista"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Private Sub Form_Load()

  'Carga el formulario
  
  On Error GoTo LineaError

  Screen.MousePointer = vbHourglass
  
  Call ConfigurarColumnas
  Call LlenarLista
  Call ManejarControles
  
  Screen.MousePointer = vbDefault
  
  Exit Sub
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation
  Screen.MousePointer = vbDefault
  
End Sub

Private Sub ConfigurarColumnas()

  'Configura las columnas de la lista lvwUsuario
  
  On Error GoTo LineaError

  Dim aColumnTitle() As String
  Dim aColumnWidth() As Single
  Dim aColumnAlign() As Integer
  
  ReDim aColumnTitle(6) As String
  ReDim aColumnWidth(6) As Single
  ReDim aColumnAlign(6) As Integer

  aColumnTitle(0) = "Cód."
  aColumnTitle(1) = "Producto"
  aColumnTitle(2) = "Abrev."
  aColumnTitle(3) = "P.Unit."
  aColumnTitle(4) = "Tipo"
  aColumnTitle(5) = "Stock"
  
  aColumnWidth(0) = 0.1
  aColumnWidth(1) = 0.4
  aColumnWidth(2) = 0.15
  aColumnWidth(3) = 0.1
  aColumnWidth(4) = 0.1
  aColumnWidth(5) = 0.05
  
  aColumnAlign(0) = lvwColumnLeft
  aColumnAlign(1) = lvwColumnLeft
  aColumnAlign(2) = lvwColumnLeft
  aColumnAlign(3) = lvwColumnRight
  aColumnAlign(4) = lvwColumnCenter
  aColumnAlign(5) = lvwColumnCenter
    
  Call oListAdmin.InicializarLista(lvwProducto, aColumnTitle, _
                                   aColumnWidth, aColumnAlign, lvwReport)
                                   
  Exit Sub
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation

End Sub

Public Sub LlenarLista()

  'Llena la lista
  
  On Error GoTo LineaError

  Dim sSql As String
  Dim ADORS As ADODB.Recordset
  
  Dim itemX As ListItem
  
  lvwProducto.ListItems.Clear
  
  sSql = " SELECT cProdCode, sProdDesc, sProdDescCrta, nProdPrecUnit, cProdEstd, cProdFlagFicha, cProdFlagCanje, cProdFlagControl" & _
         " FROM Producto where cAlmaCode = '" & kPAR_ALMACEN & "'" & _
         " ORDER BY cProdCode"
  If Not oDBAdmin.EjecutarConsulta(ADOCnn, sSql, ADORS) Then GoTo Salir
  
  Do While Not ADORS.EOF
  
    Set itemX = lvwProducto.ListItems.Add(, , LeerCampo(ADORS!cProdCode))
    itemX.SubItems(1) = LeerCampo(ADORS!sProdDesc)
    itemX.SubItems(2) = LeerCampo(ADORS!sProdDescCrta)
    itemX.SubItems(3) = Format(LeerCampo(ADORS!nProdPrecUnit), "###,###,###,####.00")
            
    If LeerCampo(ADORS!cProdEstd) = 1 Then
      itemX.Icon = 1
      itemX.SmallIcon = 1
    Else
      itemX.Icon = 2
      itemX.SmallIcon = 2
    End If
    
    If LeerCampo(ADORS!cProdFlagFicha) = 1 Then
      itemX.SubItems(4) = "Ficha"
    End If
    
    If LeerCampo(ADORS!cProdFlagCanje) = 1 Then
      itemX.SubItems(4) = "Canje"
    End If
    
    If LeerCampo(ADORS!cProdFlagControl) = 1 Then
      itemX.SubItems(5) = "SI"
    Else
      itemX.SubItems(5) = "NO"
    End If
    
    ADORS.MoveNext
    
  Loop
   
  GoTo Salir
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation
  
Salir:
  Set ADORS = Nothing
         
End Sub

Public Sub ManejarControles()

  'Maneja el uso de los controles
  
  On Error GoTo LineaError

  Call DeshabilitarControl(cmdEditar(kCMD_EDITAR), False)
  Call DeshabilitarControl(cmdEditar(kCMD_BORRAR), False)
  Call DeshabilitarControl(cmdEditar(kCMD_VER), False)
  Call DeshabilitarControl(cmdActivar, False)

  If lvwProducto.ListItems.Count > 0 Then
    
    lvwProducto.SelectedItem.EnsureVisible
    
    If lvwProducto.SelectedItem.SmallIcon = 1 Then
      cmdActivar.Caption = "Desac&tivar"
    Else
      cmdActivar.Caption = "Ac&tivar"
    End If
    
    Call HabilitarControl(cmdEditar(kCMD_EDITAR), False)
    Call HabilitarControl(cmdEditar(kCMD_BORRAR), False)
    Call HabilitarControl(cmdEditar(kCMD_VER), False)
    Call HabilitarControl(cmdActivar, False)
    
  End If
  
  Exit Sub
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation
  
End Sub

Public Sub lvwProducto_Click()

  If lvwProducto.ListItems.Count > 0 Then

    If lvwProducto.SelectedItem.SmallIcon = 1 Then
      cmdActivar.Caption = "Desac&tivar"
    Else
      cmdActivar.Caption = "Ac&tivar"
    End If
    
  End If

End Sub

Private Sub lvwProducto_ColumnClick(ByVal ColumnHeader As MSComctlLib.ColumnHeader)

  'Ordena los registos según la columna seleccionada
  
  On Error GoTo LineaError
  
  Call APISort(lvwProducto, ColumnHeader.Index, gbytLVW_SORT_DEFAULT)
  
  Exit Sub
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation
  
End Sub

Private Sub lvwProducto_DblClick()

  'Invoca al evento Click de cmdEditar
  
  On Error GoTo LineaError
  
  If lvwProducto.ListItems.Count > 0 Then
  
    If cmdEditar(kCMD_EDITAR).Enabled Then
      Call cmdEditar_Click(kCMD_EDITAR)
    Else
      Call cmdEditar_Click(kCMD_VER)
    End If
    
  End If

  Exit Sub
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation
  
End Sub

Private Sub cmdEditar_Click(Index As Integer)

  'Invoca al formulario Usuario
  
  On Error GoTo LineaError
  
  frmProducto.iEditar = Index
  
  frmProducto.Show vbModal
  
  Exit Sub
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation
  
End Sub

Private Sub cmdActivar_Click()

  'Activa o Desactiva a un Usuario

  On Error GoTo LineaError
  
  Dim sSql As String
  Dim sAccion As String
  Dim iActivo As Integer
  
  Screen.MousePointer = vbHourglass
  
  If lvwProducto.SelectedItem.SmallIcon = 1 Then
  
    sAccion = "desactivar"
    iActivo = 0
    
  Else
  
    sAccion = "activar"
    iActivo = 1
  
  End If
  
  If MsgBox("Se procederá a " + sAccion + " a " + lvwProducto.SelectedItem.Text + ". Desea continuar?", vbYesNo + vbQuestion + vbDefaultButton2) = vbYes Then
    
    sSql = "UPDATE Producto SET cProdEstd = $ WHERE cProdCode = $ and cAlmaCode = '$'"
    sSql = VBsprintf(sSql, CStr(iActivo), lvwProducto.SelectedItem.Text, kPAR_ALMACEN)
    
    If oDBAdmin.EjecutarSentencia(ADOCnn, sSql) Then
    
      If iActivo = 1 Then
        lvwProducto.SelectedItem.Icon = 1
        lvwProducto.SelectedItem.SmallIcon = 1
      Else
        lvwProducto.SelectedItem.Icon = 2
        lvwProducto.SelectedItem.SmallIcon = 2
      End If
      
      Call lvwProducto_Click
      
    End If
    
  End If
  
  GoTo Salir
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation
  
Salir:
  Screen.MousePointer = vbDefault

End Sub

Private Sub cmdSalir_Click()

  On Error GoTo LineaError

  Unload Me
  
  Exit Sub
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation

End Sub
