VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MsComCtl.ocx"
Object = "{86CF1D34-0C5F-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSComCt2.ocx"
Begin VB.Form frmPremioTicketLista 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Premios (Ticket)"
   ClientHeight    =   8280
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   10785
   Icon            =   "frmPremioTicketLista.frx":0000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   ScaleHeight     =   8280
   ScaleWidth      =   10785
   StartUpPosition =   2  'CenterScreen
   Begin VB.CommandButton cmdAjustar 
      Caption         =   "Realizar A&juste"
      Height          =   375
      Left            =   9240
      TabIndex        =   15
      Top             =   7200
      Width           =   1335
   End
   Begin VB.CommandButton cmdBuscar 
      Caption         =   "B&uscar"
      Default         =   -1  'True
      Height          =   375
      Left            =   9240
      TabIndex        =   12
      Top             =   5760
      Width           =   1335
   End
   Begin VB.CommandButton cmdSalir 
      Caption         =   "&Salir"
      Height          =   375
      Left            =   9240
      TabIndex        =   16
      Top             =   7680
      Width           =   1335
   End
   Begin VB.CommandButton cmdExtornar 
      Caption         =   "E&xtornar"
      Height          =   375
      Left            =   9240
      TabIndex        =   14
      Top             =   6720
      Width           =   1335
   End
   Begin VB.CommandButton cmdIngresar 
      Caption         =   "&Ingresar"
      Height          =   375
      Left            =   9240
      TabIndex        =   13
      Top             =   6240
      Width           =   1335
   End
   Begin VB.CommandButton cmdActivar 
      Caption         =   "Ac&tivar"
      Height          =   375
      Left            =   9240
      TabIndex        =   8
      Top             =   3960
      Width           =   1335
   End
   Begin VB.CommandButton cmdMarcar 
      Caption         =   "&Marcar Todo"
      Height          =   375
      Left            =   9240
      TabIndex        =   7
      Top             =   3480
      Width           =   1335
   End
   Begin VB.CommandButton cmdEditar 
      Caption         =   "&Borrar"
      Height          =   375
      Index           =   2
      Left            =   9240
      TabIndex        =   5
      Top             =   2280
      Width           =   1335
   End
   Begin VB.CommandButton cmdEditar 
      Caption         =   "&Editar"
      Height          =   375
      Index           =   1
      Left            =   9240
      TabIndex        =   4
      Top             =   1800
      Width           =   1335
   End
   Begin VB.CommandButton cmdEditar 
      Caption         =   "&Nuevo"
      Height          =   375
      Index           =   0
      Left            =   9240
      TabIndex        =   3
      Top             =   1320
      Width           =   1335
   End
   Begin VB.CommandButton cmdEditar 
      Caption         =   "&Ver"
      Height          =   375
      Index           =   3
      Left            =   9240
      TabIndex        =   6
      Top             =   2760
      Width           =   1335
   End
   Begin VB.Frame Frame1 
      Caption         =   "Ver "
      Height          =   1095
      Left            =   9240
      TabIndex        =   18
      Top             =   120
      Width           =   1335
      Begin VB.OptionButton optActivos 
         Caption         =   "Inactivos"
         Height          =   255
         Index           =   0
         Left            =   240
         TabIndex        =   1
         Top             =   240
         Width           =   975
      End
      Begin VB.OptionButton optActivos 
         Caption         =   "Activos"
         Height          =   255
         Index           =   1
         Left            =   240
         TabIndex        =   2
         Top             =   600
         Width           =   975
      End
   End
   Begin MSComctlLib.ListView lvwPremioTicket 
      Height          =   3975
      Left            =   120
      TabIndex        =   0
      Top             =   360
      Width           =   8895
      _ExtentX        =   15690
      _ExtentY        =   7011
      LabelEdit       =   1
      LabelWrap       =   -1  'True
      HideSelection   =   0   'False
      _Version        =   393217
      Icons           =   "imlPremioTicket"
      SmallIcons      =   "imlPremioTicket"
      ForeColor       =   -2147483640
      BackColor       =   -2147483643
      BorderStyle     =   1
      Appearance      =   1
      NumItems        =   0
   End
   Begin MSComctlLib.ListView lvwIngresoPremioTicket 
      Height          =   3375
      Left            =   120
      TabIndex        =   9
      Top             =   4680
      Width           =   8895
      _ExtentX        =   15690
      _ExtentY        =   5953
      LabelEdit       =   1
      LabelWrap       =   -1  'True
      HideSelection   =   0   'False
      _Version        =   393217
      Icons           =   "imlPremioTicket"
      SmallIcons      =   "imlPremioTicket"
      ForeColor       =   -2147483640
      BackColor       =   -2147483643
      BorderStyle     =   1
      Appearance      =   1
      NumItems        =   0
   End
   Begin MSComCtl2.DTPicker dtpFInicio 
      Height          =   315
      Left            =   9240
      TabIndex        =   10
      Top             =   4680
      Width           =   1215
      _ExtentX        =   2143
      _ExtentY        =   556
      _Version        =   393216
      CalendarForeColor=   -2147483640
      CalendarTitleBackColor=   -2147483645
      CalendarTitleForeColor=   -2147483629
      CalendarTrailingForeColor=   -2147483645
      CustomFormat    =   "dd/MM/yyyy"
      Format          =   23658499
      CurrentDate     =   37042
   End
   Begin MSComCtl2.DTPicker dtpFFin 
      Height          =   315
      Left            =   9240
      TabIndex        =   11
      Top             =   5280
      Width           =   1215
      _ExtentX        =   2143
      _ExtentY        =   556
      _Version        =   393216
      CalendarForeColor=   -2147483640
      CalendarTitleBackColor=   -2147483645
      CalendarTitleForeColor=   -2147483629
      CalendarTrailingForeColor=   -2147483645
      CustomFormat    =   "dd/MM/yyyy"
      Format          =   23658499
      CurrentDate     =   37042
   End
   Begin MSComctlLib.ImageList imlPremioTicket 
      Left            =   0
      Top             =   0
      _ExtentX        =   1005
      _ExtentY        =   1005
      BackColor       =   -2147483643
      ImageWidth      =   16
      ImageHeight     =   16
      MaskColor       =   12632256
      _Version        =   393216
      BeginProperty Images {2C247F25-8591-11D1-B16A-00C0F0283628} 
         NumListImages   =   3
         BeginProperty ListImage1 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "frmPremioTicketLista.frx":0442
            Key             =   ""
         EndProperty
         BeginProperty ListImage2 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "frmPremioTicketLista.frx":0894
            Key             =   ""
         EndProperty
         BeginProperty ListImage3 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "frmPremioTicketLista.frx":0CE6
            Key             =   ""
         EndProperty
      EndProperty
   End
   Begin VB.Label lblLabels 
      Caption         =   "Al"
      Height          =   375
      Index           =   3
      Left            =   9240
      TabIndex        =   21
      Top             =   5040
      Width           =   495
   End
   Begin VB.Label lblLabels 
      Caption         =   "Del"
      Height          =   375
      Index           =   2
      Left            =   9240
      TabIndex        =   20
      Top             =   4440
      Width           =   495
   End
   Begin VB.Label lblLabels 
      Alignment       =   2  'Center
      BorderStyle     =   1  'Fixed Single
      Caption         =   "Ingresos"
      Height          =   255
      Index           =   1
      Left            =   120
      TabIndex        =   19
      Top             =   4440
      Width           =   8895
   End
   Begin VB.Label lblLabels 
      Alignment       =   2  'Center
      BorderStyle     =   1  'Fixed Single
      Caption         =   "Premios"
      Height          =   255
      Index           =   0
      Left            =   120
      TabIndex        =   17
      Top             =   120
      Width           =   8895
   End
End
Attribute VB_Name = "frmPremioTicketLista"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Dim iItem As Integer

Public bTodoFlag As Boolean
Public dFInicio As Date
Public dFFin As Date

Private Sub Form_Activate()

  On Error GoTo LineaError
  
  'Form Actual
  psForm = kFORM_PREMIO_TICKET_LISTA
  
  Exit Sub
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation
  
End Sub

Private Sub Form_Load()

  'Carga el formulario
  
  On Error GoTo LineaError

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

Private Sub ConfigurarColumnas()

  'Configura las columnas de las listas lvwPremioTicket y lvwIngresoPremioTicket
  
  On Error GoTo LineaError

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

  aColumnTitle(0) = "Descripción"
  aColumnTitle(1) = "Stock"
  aColumnTitle(2) = "Tickets"
  
  aColumnWidth(0) = 0.55
  aColumnWidth(1) = 0.2
  aColumnWidth(2) = 0.2
  
  aColumnAlign(0) = lvwColumnLeft
  aColumnAlign(1) = lvwColumnRight
  aColumnAlign(2) = lvwColumnRight
  
  lvwPremioTicket.CheckBoxes = True
    
  Call oListAdmin.InicializarLista(lvwPremioTicket, aColumnTitle, _
                                   aColumnWidth, aColumnAlign, lvwReport)
                                   
  ReDim aColumnTitle(5) As String
  ReDim aColumnWidth(5) As Single
  ReDim aColumnAlign(5) As Integer

  aColumnTitle(0) = "Fecha Ingreso"
  aColumnTitle(1) = "Cantidad"
  aColumnTitle(2) = "Usuario"
  aColumnTitle(3) = "Fecha Extorno"
  aColumnTitle(4) = "Usuario Extorno"
  
  aColumnWidth(0) = 0.2
  aColumnWidth(1) = 0.15
  aColumnWidth(2) = 0.2
  aColumnWidth(3) = 0.2
  aColumnWidth(4) = 0.2
  
  aColumnAlign(0) = lvwColumnLeft
  aColumnAlign(1) = lvwColumnRight
  aColumnAlign(2) = lvwColumnLeft
  aColumnAlign(3) = lvwColumnLeft
  aColumnAlign(4) = lvwColumnLeft
    
  Call oListAdmin.InicializarLista(lvwIngresoPremioTicket, aColumnTitle, _
                                   aColumnWidth, aColumnAlign, lvwReport)
                                   
  Exit Sub
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation

End Sub

Private Sub InicializarForm()

  'Inicializa el Form
  
  On Error GoTo LineaError

  iItem = 0
  
  dtpFInicio.Value = Date - 15
  dtpFFin.Value = Date
  
  optActivos(kSI).Value = True
  
  Exit Sub
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation
  
End Sub

Public Sub LlenarListaPremioTicket()

  'Llena la lista PremioTicket
  
  On Error GoTo LineaError

  Dim sSQL As String
  Dim ADORS As ADODB.Recordset
  
  Dim itemX As ListItem
  
  lvwPremioTicket.ListItems.Clear
  cmdMarcar.Caption = "&Marcar Todo"
  
  sSQL = "SELECT * " + _
         "FROM Premio_Ticket " + _
         "WHERE cPremActi = $ Order by sPremDesc"
  sSQL = VBsprintf(sSQL, IIf(optActivos(kSI).Value, kSI, kNO))
  If Not oDBAdmin.EjecutarConsulta(ADOCnn, sSQL, ADORS) Then GoTo Salir
  
  Do While Not ADORS.EOF
  
    Set itemX = lvwPremioTicket.ListItems.Add(, "k" + LeerCampo(ADORS!cPremCode), LeerCampo(ADORS!sPremDesc))
    itemX.SubItems(1) = LeerCampo(ADORS!nPremStoc)
    itemX.SubItems(2) = LeerCampo(ADORS!nTickCant)
    
    If LeerCampo(ADORS!cPremActi) = kSI Then
      itemX.Icon = 1
      itemX.SmallIcon = 1
    Else
      itemX.Icon = 2
      itemX.SmallIcon = 2
    End If
  
    ADORS.MoveNext
    
  Loop
  
  GoTo Salir
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation
  
Salir:
  Set ADORS = Nothing
         
End Sub

Public Sub LlenarListaIngresoPremioTicket()

  'Llena la lista IngresoPremioTicket
  
  On Error GoTo LineaError

  Dim sSQL As String
  Dim ADORS As ADODB.Recordset
  
  Dim itemX As ListItem
  
  sSQL = "SELECT * " + _
         "FROM Ingreso_Premio_Ticket " + _
         "WHERE cPremCode = $ AND " + _
         "FORMAT(dIngrDate, 'yyyy/mm/dd') >= '$' AND " + _
         "FORMAT(dIngrDate, 'yyyy/mm/dd') <= '$' " + _
         "Order by dIngrDate DESC"
  sSQL = VBsprintf(sSQL, Mid(lvwPremioTicket.SelectedItem.Key, 2), _
         Format(dtpFInicio.Value, "yyyy/mm/dd"), _
         Format(dtpFFin.Value, "yyyy/mm/dd"))
  If Not oDBAdmin.EjecutarConsulta(ADOCnn, sSQL, ADORS) Then GoTo Salir

  Do While Not ADORS.EOF
  
    Set itemX = lvwIngresoPremioTicket.ListItems.Add(, "k" + LeerCampo(ADORS!cIngrCode), Format(LeerCampo(ADORS!dIngrDate), "dd/mm/yyyy hh:mm"))
    itemX.SubItems(1) = Format(LeerCampo(ADORS!nIngrCant), "##,##0")
    itemX.SubItems(2) = LeerCampo(ADORS!sUserDesc)
    
    If LeerCampo(ADORS!dExtoDate) = "" Then
    
      If LeerCampo(ADORS!cAjusFlag) <> CStr(kSI) Then
        
        itemX.Icon = 1
        itemX.SmallIcon = 1
        
      Else
      
        itemX.Icon = 3
        itemX.SmallIcon = 3
      
      End If
        
    Else
      itemX.SubItems(3) = Format(LeerCampo(ADORS!dExtoDate), "dd/mm/yyyy hh:mm")
      itemX.SubItems(4) = LeerCampo(ADORS!sUseEDesc)
      itemX.Icon = 2
      itemX.SmallIcon = 2
    End If
  
    ADORS.MoveNext
    
  Loop
  
  lblLabels(1).Caption = "Ingresos   -   " + lvwPremioTicket.SelectedItem.Text + "   -   Del " + Format(dtpFInicio.Value, "dd/mm/yyyy") + " Al " + Format(dtpFFin.Value, "dd/mm/yyyy")
  dFInicio = dtpFInicio.Value
  dFFin = dtpFFin.Value
  
  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_NUEVO), False)
  Call DeshabilitarControl(cmdEditar(kCMD_EDITAR), False)
  Call DeshabilitarControl(cmdEditar(kCMD_BORRAR), False)
  Call DeshabilitarControl(cmdEditar(kCMD_VER), False)
  Call DeshabilitarControl(cmdMarcar, False)
  Call DeshabilitarControl(cmdActivar, False)
  
  Call DeshabilitarControl(cmdBuscar, False)
  Call DeshabilitarControl(cmdIngresar, False)
  Call DeshabilitarControl(cmdExtornar, False)
  Call DeshabilitarControl(cmdAjustar, False)
  
  Call DeshabilitarControl(dtpFInicio, False)
  Call DeshabilitarControl(dtpFFin, False)
  
  If piPerfil_Codigo = kPERFIL_ADMINISTRADOR Or piPerfil_Codigo = kPERFIL_SUPERVISOR Then
    Call HabilitarControl(cmdEditar(kCMD_NUEVO), False)
  End If

  If lvwPremioTicket.ListItems.Count > 0 Then
    
    lvwPremioTicket.SelectedItem.EnsureVisible
    
    If optActivos(kSI).Value Then
      cmdActivar.Caption = "Desac&tivar"
    Else
      cmdActivar.Caption = "Ac&tivar"
    End If
    
    If piPerfil_Codigo = kPERFIL_ADMINISTRADOR Or piPerfil_Codigo = kPERFIL_SUPERVISOR Then
    
      Call HabilitarControl(cmdEditar(kCMD_EDITAR), False)
      Call HabilitarControl(cmdEditar(kCMD_BORRAR), False)
      Call HabilitarControl(cmdEditar(kCMD_VER), False)
      Call HabilitarControl(cmdMarcar, False)
      Call HabilitarControl(cmdActivar, False)
      
      Call HabilitarControl(cmdBuscar, False)
      Call HabilitarControl(cmdIngresar, False)
      
      If lvwIngresoPremioTicket.ListItems.Count > 0 Then
        Call HabilitarControl(cmdExtornar, False)
        Call HabilitarControl(cmdAjustar, False)
      End If
      
      Call HabilitarControl(dtpFInicio, False)
      Call HabilitarControl(dtpFFin, False)
      
    End If
    
  End If
  
  Exit Sub
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation
  
End Sub

Private Sub optActivos_Click(Index As Integer)

  'Invoca a las funciones que llenaran las listas

  On Error GoTo LineaError

  Call LlenarListaPremioTicket
  Call cmdBuscar_Click
  
  Exit Sub
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation

End Sub

Public Sub lvwPremioTicket_Click()

  'Invoca al click del botón buscar
  
  On Error GoTo LineaError
  
  Call cmdBuscar_Click
  
  Exit Sub
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation

End Sub

Private Sub lvwPremioTicket_ColumnClick(ByVal ColumnHeader As MSComctlLib.ColumnHeader)

  'Ordenar Según la columna seleccionada
  
  On Error GoTo LineaError

  If ColumnHeader.Index = 2 Or ColumnHeader.Index = 3 Then
  
    Call APISort(lvwPremioTicket, ColumnHeader.Index, _
                 gbytLVW_SORT_VALUE)
                 
  Else
  
    Call APISort(lvwPremioTicket, ColumnHeader.Index, _
                 gbytLVW_SORT_DEFAULT)
                 
  End If
  
  Exit Sub
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation
  
End Sub

Private Sub lvwPremioTicket_DblClick()

  'Invoca al evento Click de cmdEditar
  
  On Error GoTo LineaError
  
  If lvwPremioTicket.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 lvwPremioTicket_ItemCheck(ByVal Item As MSComctlLib.ListItem)

  'caption de cmdMarcar

  On Error GoTo LineaError

  If Item.Checked Then
    iItem = iItem + 1
  Else
    iItem = iItem - 1
  End If
  
  If iItem = lvwPremioTicket.ListItems.Count Then
    cmdMarcar.Caption = "Des&marc. Todo"
  ElseIf iItem = 0 Then
    cmdMarcar.Caption = "&Marcar Todo"
  End If
  
  Item.Selected = True
  
  Exit Sub
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation

End Sub

Private Sub lvwIngresoPremioTicket_ColumnClick(ByVal ColumnHeader As MSComctlLib.ColumnHeader)

  'Ordenar Según la columna seleccionada
  
  On Error GoTo LineaError
  
  If ColumnHeader.Index = 1 Or ColumnHeader.Index = 4 Then
  
    Call APISort(lvwIngresoPremioTicket, ColumnHeader.Index, _
                 gbytLVW_SORT_DATE)

  ElseIf ColumnHeader.Index = 2 Then
  
    Call APISort(lvwIngresoPremioTicket, ColumnHeader.Index, _
                 gbytLVW_SORT_VALUE)
                 
  Else
  
    Call APISort(lvwIngresoPremioTicket, ColumnHeader.Index, _
                 gbytLVW_SORT_DEFAULT)
                 
  End If
  
  Exit Sub
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation
  
End Sub


Private Sub cmdMarcar_Click()

  'Marcar/Desmarcar
  
  On Error GoTo LineaError

  Dim i As Integer

  Screen.MousePointer = vbHourglass
  
  If cmdMarcar.Caption = "&Marcar Todo" Then
  
    For i = 1 To lvwPremioTicket.ListItems.Count
      lvwPremioTicket.ListItems(i).Checked = True
    Next
    
    cmdMarcar.Caption = "Des&marc. Todo"
      
  Else
  
    For i = 1 To lvwPremioTicket.ListItems.Count
      lvwPremioTicket.ListItems(i).Checked = False
    Next
    
    cmdMarcar.Caption = "&Marcar Todo"
  
  End If
    
  Screen.MousePointer = vbDefault
   
  Exit Sub
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation
  Screen.MousePointer = vbDefault
  
End Sub

Private Sub cmdActivar_Click()

  'Activa/Desactiva Registros

  On Error GoTo LineaError

  Dim sSQL As String
  Dim i As Integer
  Dim iCant As Integer

  Screen.MousePointer = vbHourglass
  
  i = 1
  iCant = lvwPremioTicket.ListItems.Count
  
  If MsgBox("Se va a proceder a " + IIf(optActivos(kSI).Value, "desactivar", "activar") + " a los registros seleccionados. Confirma acción?", vbYesNo + vbQuestion + vbDefaultButton2) = vbNo Then GoTo Salir
  
  Do While i <= iCant
  
    If lvwPremioTicket.ListItems(i).Checked Then
    
      sSQL = "UPDATE Premio_Ticket SET cPremActi = $ " + _
             "WHERE cPremCode = $"
      sSQL = VBsprintf(sSQL, IIf(optActivos(kSI).Value, kNO, kSI), _
             Mid(lvwPremioTicket.ListItems(i).Key, 2))
               
      If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
        
      lvwPremioTicket.ListItems.Remove (lvwPremioTicket.ListItems(i).Index)
        
      iCant = lvwPremioTicket.ListItems.Count
      i = i - 1
      
    End If
    
    i = i + 1
  
  Loop
  
  Call cmdBuscar_Click
  
  GoTo Salir
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation
  
Salir:
  Screen.MousePointer = vbDefault

End Sub

Private Sub cmdEditar_Click(Index As Integer)

  'Invoca al formulario Premio_Ticket
  
  On Error GoTo LineaError
  
  Dim sSQL As String
  Dim ADORS As ADODB.Recordset
  
  bTodoFlag = True
  
  If Index = kCMD_EDITAR Or Index = kCMD_BORRAR Then

    sSQL = "SELECT cPremCode FROM Canje_Ticket WHERE cPremCode = $"
    sSQL = VBsprintf(sSQL, Mid(lvwPremioTicket.SelectedItem.Key, 2))
    If Not oDBAdmin.EjecutarConsulta(ADOCnn, sSQL, ADORS) Then GoTo Salir

    If Not ADORS.EOF And Index = kCMD_BORRAR Then
      MsgBox "No se puede borrar Premio. El premio registra transacciones", vbOKOnly + vbInformation
      Exit Sub
    End If

    If Not ADORS.EOF And Index = kCMD_EDITAR Then
      bTodoFlag = False
    End If
    
    Set ADORS = Nothing
    
  End If

  frmPremioTicket.iEditar = Index

  frmPremioTicket.Show vbModal
    
  GoTo Salir
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation
  
Salir:
  Set ADORS = Nothing
  
End Sub

Public Sub cmdBuscar_Click()

  'Buscar Ingresos según rango de fecha
  
  On Error GoTo LineaError

  lblLabels(1).Caption = "Ingresos"
  lvwIngresoPremioTicket.ListItems.Clear

  If lvwPremioTicket.ListItems.Count > 0 Then

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

End Sub

Private Sub cmdIngresar_Click()

  'Ingresar Cantidad (Stock)
  
  On Error GoTo LineaError
  
  frmIngresoPremioTicket.Show vbModal
  
  Exit Sub
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation
  
End Sub

Private Sub cmdExtornar_Click()

  'Extornar Ingreso
  
  On Error GoTo LineaError
  
  Dim sSQL As String
  Dim sPremio As String
  
  Dim itemX As ListItem
  Dim bConnFlag As Boolean
  
  Dim lStock As Long
  Dim lCantidad As Long
  
  Screen.MousePointer = vbHourglass
  
  If lvwIngresoPremioTicket.SelectedItem.SmallIcon = 2 Then
    MsgBox "Ingreso ya ha sido extornado", vbOKOnly + vbInformation
    GoTo Salir
  ElseIf lvwIngresoPremioTicket.SelectedItem.SmallIcon = 3 Then
    MsgBox "Los ajustes no pueden ser extornados", vbOKOnly + vbInformation
    GoTo Salir
  End If
  
  lStock = CLng(lvwPremioTicket.SelectedItem.SubItems(1))
  lCantidad = CLng(lvwIngresoPremioTicket.SelectedItem.SubItems(1))
  
  If lStock < lCantidad Then
    MsgBox "No se puede ejecutar el proceso. Stock actual menor a la cantidad a extornar.", vbOKOnly + vbInformation
    GoTo Salir
  End If
  
  If MsgBox("Se extornará ingreso seleccionado (Fecha: " + lvwIngresoPremioTicket.SelectedItem.Text + " - Cantidad: " + lvwIngresoPremioTicket.SelectedItem.SubItems(1) + "). Confirma Acción?", _
  vbQuestion + vbYesNo + vbDefaultButton2) = vbNo Then GoTo Salir
  
  sPremio = Mid(lvwPremioTicket.SelectedItem.Key, 2)
  
  ADOCnn.BeginTrans
  bConnFlag = True
  
  sSQL = "UPDATE Ingreso_Premio_Ticket SET dExtoDate = '$', sUseEDesc = '$' " + _
         "WHERE cPremCode = $ AND cIngrCode = $"
  sSQL = VBsprintf(sSQL, Format(Now, "yyyy/mm/dd hh:mm"), psUsuario_Descripcion, sPremio, _
         Mid(lvwIngresoPremioTicket.SelectedItem.Key, 2))
         
  If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo LineaError1
  
  sSQL = "UPDATE Premio_Ticket SET nPremStoc = nPremStoc - $ " + _
         "WHERE cPremCode = $"
  sSQL = VBsprintf(sSQL, Format(lvwIngresoPremioTicket.SelectedItem.SubItems(1), "####0"), _
         sPremio)

  If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo LineaError1
  
  ADOCnn.CommitTrans
  bConnFlag = False
  
  lvwPremioTicket.SelectedItem.SubItems(1) = Format(lStock - lCantidad, "##,##0")
  
  Set itemX = lvwIngresoPremioTicket.SelectedItem
  
  itemX.SubItems(3) = Format(Now, "dd/mm/yyyy hh:mm")
  itemX.SubItems(4) = psUsuario_Descripcion
  itemX.Icon = 2
  itemX.SmallIcon = 2
  
  GoTo Salir
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation
  
LineaError1:
  If bConnFlag Then ADOCnn.RollbackTrans
  
Salir:
  Screen.MousePointer = vbDefault
  
End Sub

Private Sub cmdAjustar_Click()

  'Invoca al formulario Ajuste
  
  frmAjuste.Show vbModal
  
  Exit Sub
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation

End Sub

Private Sub CmdSalir_Click()

  'Descargar Form

  On Error GoTo LineaError

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

End Sub



