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 frmCanjeLista 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Canjes Realizados"
   ClientHeight    =   8280
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   10785
   Icon            =   "frmCanjeLista.frx":0000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   ScaleHeight     =   8280
   ScaleWidth      =   10785
   StartUpPosition =   2  'CenterScreen
   Begin VB.CommandButton cmdCliente 
      Caption         =   "&Ver Cliente"
      Height          =   375
      Left            =   7920
      TabIndex        =   19
      Top             =   7800
      Width           =   1335
   End
   Begin VB.CommandButton cmdExtornar 
      Caption         =   "Ext&ornar"
      Height          =   375
      Index           =   1
      Left            =   120
      TabIndex        =   8
      Top             =   7800
      Width           =   1335
   End
   Begin VB.CommandButton cmdExtornar 
      Caption         =   "E&xtornar"
      Height          =   375
      Index           =   0
      Left            =   120
      TabIndex        =   6
      Top             =   4320
      Width           =   1335
   End
   Begin VB.CommandButton cmdSalir 
      Caption         =   "&Salir"
      Height          =   375
      Left            =   9360
      TabIndex        =   16
      Top             =   7800
      Width           =   1335
   End
   Begin VB.Frame fraCanjeLista 
      Height          =   735
      Index           =   0
      Left            =   5760
      TabIndex        =   11
      Top             =   360
      Width           =   4935
      Begin VB.Label lblLabels 
         Caption         =   "Puntos:"
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   9.75
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   375
         Index           =   2
         Left            =   120
         TabIndex        =   15
         Top             =   240
         Width           =   855
      End
      Begin VB.Label lblPuntos 
         Alignment       =   1  'Right Justify
         Caption         =   "Puntos"
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   9.75
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   375
         Left            =   960
         TabIndex        =   14
         Top             =   240
         Width           =   1215
      End
      Begin VB.Label lblLabels 
         Caption         =   "Tickets:"
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   9.75
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   375
         Index           =   3
         Left            =   2520
         TabIndex        =   13
         Top             =   240
         Width           =   855
      End
      Begin VB.Label lblTickets 
         Alignment       =   1  'Right Justify
         Caption         =   "Tickets"
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   9.75
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   375
         Left            =   3360
         TabIndex        =   12
         Top             =   240
         Width           =   1335
      End
   End
   Begin VB.Frame fraCanjeLista 
      Height          =   735
      Index           =   2
      Left            =   120
      TabIndex        =   10
      Top             =   360
      Width           =   5535
      Begin VB.CommandButton cmdBuscar 
         Caption         =   "B&uscar"
         Default         =   -1  'True
         Height          =   375
         Left            =   3960
         TabIndex        =   4
         Top             =   240
         Width           =   1335
      End
      Begin MSComCtl2.DTPicker dtpFInicio 
         Height          =   315
         Left            =   840
         TabIndex        =   1
         Top             =   240
         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            =   2640
         TabIndex        =   3
         Top             =   240
         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 VB.Label lblLabels 
         Caption         =   "Del"
         Height          =   375
         Index           =   0
         Left            =   240
         TabIndex        =   0
         Top             =   240
         Width           =   495
      End
      Begin VB.Label lblLabels 
         Caption         =   "Al"
         Height          =   375
         Index           =   1
         Left            =   2280
         TabIndex        =   2
         Top             =   240
         Width           =   495
      End
   End
   Begin MSComctlLib.ListView lvwCanjePunto 
      Height          =   2625
      Left            =   120
      TabIndex        =   5
      Top             =   1560
      Width           =   10455
      _ExtentX        =   18441
      _ExtentY        =   4630
      LabelEdit       =   1
      LabelWrap       =   -1  'True
      HideSelection   =   0   'False
      _Version        =   393217
      Icons           =   "imlCanje"
      SmallIcons      =   "imlCanje"
      ForeColor       =   -2147483640
      BackColor       =   -2147483643
      BorderStyle     =   1
      Appearance      =   1
      NumItems        =   0
   End
   Begin MSComctlLib.ListView lvwCanjeTicket 
      Height          =   2625
      Left            =   120
      TabIndex        =   7
      Top             =   5040
      Width           =   10455
      _ExtentX        =   18441
      _ExtentY        =   4630
      LabelEdit       =   1
      LabelWrap       =   -1  'True
      HideSelection   =   0   'False
      _Version        =   393217
      Icons           =   "imlCanje"
      SmallIcons      =   "imlCanje"
      ForeColor       =   -2147483640
      BackColor       =   -2147483643
      BorderStyle     =   1
      Appearance      =   1
      NumItems        =   0
   End
   Begin MSComctlLib.ImageList imlCanje 
      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   =   2
         BeginProperty ListImage1 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "frmCanjeLista.frx":0442
            Key             =   ""
         EndProperty
         BeginProperty ListImage2 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "frmCanjeLista.frx":0894
            Key             =   ""
         EndProperty
      EndProperty
   End
   Begin VB.Label lblLabels 
      Alignment       =   2  'Center
      BorderStyle     =   1  'Fixed Single
      Caption         =   "Canje Tickets"
      Height          =   255
      Index           =   5
      Left            =   120
      TabIndex        =   18
      Top             =   4800
      Width           =   10455
   End
   Begin VB.Label lblLabels 
      Alignment       =   2  'Center
      BorderStyle     =   1  'Fixed Single
      Caption         =   "Canje  Puntos"
      Height          =   255
      Index           =   4
      Left            =   120
      TabIndex        =   17
      Top             =   1320
      Width           =   10455
   End
   Begin VB.Label lblCliente 
      Alignment       =   2  'Center
      Caption         =   "Cliente"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   9.75
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   120
      TabIndex        =   9
      Top             =   120
      Width           =   10575
   End
End
Attribute VB_Name = "frmCanjeLista"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Dim sCliente As String

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()

  On Error GoTo LineaError

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

  aColumnTitle(0) = "Fecha Canje"
  aColumnTitle(1) = "Tarjeta"
  aColumnTitle(2) = "Premio"
  aColumnTitle(3) = "Cantidad"
  aColumnTitle(4) = "Puntos Canj."
  aColumnTitle(5) = "Usuario"
  aColumnTitle(6) = "Fecha Extorno"
  aColumnTitle(7) = "Usuario Extorno"
  
  aColumnWidth(0) = 0.13
  aColumnWidth(1) = 0.09
  aColumnWidth(2) = 0.2
  aColumnWidth(3) = 0.09
  aColumnWidth(4) = 0.09
  aColumnWidth(5) = 0.12
  aColumnWidth(6) = 0.12
  aColumnWidth(7) = 0.12
    
  aColumnAlign(0) = lvwColumnLeft
  aColumnAlign(1) = lvwColumnLeft
  aColumnAlign(2) = lvwColumnLeft
  aColumnAlign(3) = lvwColumnRight
  aColumnAlign(4) = lvwColumnRight
  aColumnAlign(5) = lvwColumnLeft
  aColumnAlign(6) = lvwColumnLeft
  aColumnAlign(7) = lvwColumnLeft
    
  Call oListAdmin.InicializarLista(lvwCanjePunto, aColumnTitle, _
                                   aColumnWidth, aColumnAlign, lvwReport)
                                   
  ReDim aColumnTitle(8) As String
  ReDim aColumnWidth(8) As Single
  ReDim aColumnAlign(8) As Integer

  aColumnTitle(0) = "Fecha Canje"
  aColumnTitle(1) = "Tarjeta"
  aColumnTitle(2) = "Premio"
  aColumnTitle(3) = "Cantidad"
  aColumnTitle(4) = "Tickets Canj."
  aColumnTitle(5) = "Usuario"
  aColumnTitle(6) = "Fecha Extorno"
  aColumnTitle(7) = "Usuario Extorno"
  
  aColumnWidth(0) = 0.13
  aColumnWidth(1) = 0.09
  aColumnWidth(2) = 0.2
  aColumnWidth(3) = 0.09
  aColumnWidth(4) = 0.09
  aColumnWidth(5) = 0.12
  aColumnWidth(6) = 0.12
  aColumnWidth(7) = 0.12
    
  aColumnAlign(0) = lvwColumnLeft
  aColumnAlign(1) = lvwColumnLeft
  aColumnAlign(2) = lvwColumnLeft
  aColumnAlign(3) = lvwColumnRight
  aColumnAlign(4) = lvwColumnRight
  aColumnAlign(5) = lvwColumnLeft
  aColumnAlign(6) = lvwColumnLeft
  aColumnAlign(7) = lvwColumnLeft
    
  Call oListAdmin.InicializarLista(lvwCanjeTicket, aColumnTitle, _
                                   aColumnWidth, aColumnAlign, lvwReport)
                                   
  Exit Sub
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation

End Sub

Private Sub InicializarForm()

  'Inicializa el Form
  
  On Error GoTo LineaError
  
  dtpFInicio.Value = Date - 15
  dtpFFin.Value = Date
  
  TraerDataCliente
  Call cmdBuscar_Click
  
  Exit Sub
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation
  
End Sub

Private Sub TraerDataCliente()

  'Traer Data del Cliente seleccionado
  
  On Error GoTo LineaError
  
  sCliente = Mid(frmPrincipal.lvwCliente.SelectedItem.Key, 2)
     
  lblCliente.Caption = frmCanje.txtApellidos.Text + " " + frmCanje.txtNombres.Text + " - Tarjeta Activa: " + frmPrincipal.lvwCliente.SelectedItem.SubItems(2)
  lblPuntos.Caption = frmCanje.lblPuntos.Caption
  lblTickets.Caption = frmCanje.lblTickets.Caption

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

End Sub

Public Sub cmdBuscar_Click()

  'Buscar Acumulacion según rango de fecha

  On Error GoTo LineaError

  lblLabels(4).Caption = "Canje Puntos"
  lblLabels(5).Caption = "Canje Tickets"
  
  lvwCanjePunto.ListItems.Clear
  lvwCanjeTicket.ListItems.Clear

  LlenarListaCanjePunto
  LlenarListaCanjeTicket
  ManejarControles

  Exit Sub

LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation

End Sub

Public Sub LlenarListaCanjePunto()

  'Llena la lista CanjePunto

  On Error GoTo LineaError

  Dim sSQL As String
  Dim ADORS As ADODB.Recordset

  Dim itemX As ListItem

  sSQL = "SELECT a.*, sPremDesc " + _
         "FROM Canje_Punto a, Premio_Punto b " + _
         "WHERE a.cPremCode = b.cPremCode AND " + _
         "cClieCode = $ AND " + _
         "FORMAT(dCanjDate, 'yyyy/mm/dd') >= '$' AND " + _
         "FORMAT(dCanjDate, 'yyyy/mm/dd') <= '$' " + _
         "Order by dCanjDate DESC"
  sSQL = VBsprintf(sSQL, sCliente, _
         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 = lvwCanjePunto.ListItems.Add(, "k" + LeerCampo(ADORS!cCanjCode), Format(LeerCampo(ADORS!dCanjDate), "dd/mm/yyyy hh:mm"))
    itemX.SubItems(1) = LeerCampo(ADORS!nTarjNumb)
    itemX.SubItems(2) = LeerCampo(ADORS!sPremDesc)
    itemX.SubItems(3) = Format(LeerCampo(ADORS!nPremCant), "##,##0")
    itemX.SubItems(4) = Format(LeerCampo(ADORS!nPuntCant), "##,##0")
    itemX.SubItems(5) = LeerCampo(ADORS!sUserDesc)
    
    If LeerCampo(ADORS!dExtoDate) = "" Then
      itemX.Icon = 1
      itemX.SmallIcon = 1
    Else
      itemX.SubItems(6) = Format(LeerCampo(ADORS!dExtoDate), "dd/mm/yyyy hh:mm")
      itemX.SubItems(7) = LeerCampo(ADORS!sUseEDesc)
      itemX.Icon = 2
      itemX.SmallIcon = 2
    End If

    ADORS.MoveNext

  Loop

  lblLabels(4).Caption = "Canje Puntos   -   Del " + Format(dtpFInicio.Value, "dd/mm/yyyy") + " Al " + Format(dtpFFin.Value, "dd/mm/yyyy")
  
  GoTo Salir

LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation
  
Salir:
  Set ADORS = Nothing

End Sub

Public Sub LlenarListaCanjeTicket()

  'Llena la lista CanjeTicket

  On Error GoTo LineaError

  Dim sSQL As String
  Dim ADORS As ADODB.Recordset

  Dim itemX As ListItem

  sSQL = "SELECT a.*, sPremDesc " + _
         "FROM Canje_Ticket a, Premio_Ticket b " + _
         "WHERE a.cPremCode = b.cPremCode AND " + _
         "cClieCode = $ AND " + _
         "FORMAT(dCanjDate, 'yyyy/mm/dd') >= '$' AND " + _
         "FORMAT(dCanjDate, 'yyyy/mm/dd') <= '$' " + _
         "Order by dCanjDate DESC"
  sSQL = VBsprintf(sSQL, sCliente, _
         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 = lvwCanjeTicket.ListItems.Add(, "k" + RPad(LeerCampo(ADORS!cCanjCode), 10, " ") + LeerCampo(ADORS!cPremCode), Format(LeerCampo(ADORS!dCanjDate), "dd/mm/yyyy hh:mm"))
    itemX.SubItems(1) = LeerCampo(ADORS!nTarjNumb)
    itemX.SubItems(2) = LeerCampo(ADORS!sPremDesc)
    itemX.SubItems(3) = Format(LeerCampo(ADORS!nPremCant), "##,##0")
    itemX.SubItems(4) = Format(LeerCampo(ADORS!nTickCant), "##,##0")
    itemX.SubItems(5) = LeerCampo(ADORS!sUserDesc)
    
    If LeerCampo(ADORS!dExtoDate) = "" Then
      itemX.Icon = 1
      itemX.SmallIcon = 1
    Else
      itemX.SubItems(6) = Format(LeerCampo(ADORS!dExtoDate), "dd/mm/yyyy hh:mm")
      itemX.SubItems(7) = LeerCampo(ADORS!sUseEDesc)
      itemX.Icon = 2
      itemX.SmallIcon = 2
    End If

    ADORS.MoveNext

  Loop

  lblLabels(5).Caption = "Canje Tickets   -   Del " + Format(dtpFInicio.Value, "dd/mm/yyyy") + " Al " + Format(dtpFFin.Value, "dd/mm/yyyy")
  
  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(cmdExtornar(kPUNTO), False)
  Call DeshabilitarControl(cmdExtornar(kTICKET), False)
  
  If piPerfil_Codigo = kPERFIL_ADMINISTRADOR Or piPerfil_Codigo = kPERFIL_SUPERVISOR Then

    If lvwCanjePunto.ListItems.Count > 0 Then
      lvwCanjePunto.SelectedItem.EnsureVisible
      Call HabilitarControl(cmdExtornar(kPUNTO), False)
    End If
    
    If lvwCanjeTicket.ListItems.Count > 0 Then
      lvwCanjeTicket.SelectedItem.EnsureVisible
      Call HabilitarControl(cmdExtornar(kTICKET), False)
    End If

  End If

  Exit Sub

LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation

End Sub

Private Sub lvwCanjePunto_ColumnClick(ByVal ColumnHeader As MSComctlLib.ColumnHeader)

  'Ordenar Según la columna seleccionada

  On Error GoTo LineaError

  If ColumnHeader.Index = 1 Or ColumnHeader.Index = 7 Then

    Call APISort(lvwCanjePunto, ColumnHeader.Index, _
                 gbytLVW_SORT_DATE)

  ElseIf ColumnHeader.Index = 4 Or ColumnHeader.Index = 5 Then

    Call APISort(lvwCanjePunto, ColumnHeader.Index, _
                 gbytLVW_SORT_VALUE)

  Else

    Call APISort(lvwCanjePunto, ColumnHeader.Index, _
                 gbytLVW_SORT_DEFAULT)

  End If
  Exit Sub

LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation

End Sub

Private Sub lvwCanjeTicket_ColumnClick(ByVal ColumnHeader As MSComctlLib.ColumnHeader)

  'Ordenar Según la columna seleccionada

  On Error GoTo LineaError

  If ColumnHeader.Index = 1 Or ColumnHeader.Index = 7 Then

    Call APISort(lvwCanjeTicket, ColumnHeader.Index, _
                 gbytLVW_SORT_DATE)

  ElseIf ColumnHeader.Index = 4 Or ColumnHeader.Index = 5 Then

    Call APISort(lvwCanjeTicket, ColumnHeader.Index, _
                 gbytLVW_SORT_VALUE)

  Else

    Call APISort(lvwCanjeTicket, ColumnHeader.Index, _
                 gbytLVW_SORT_DEFAULT)

  End If

  Exit Sub

LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation

End Sub

Private Sub cmdExtornar_Click(Index As Integer)

  'Extornar

  On Error GoTo LineaError
  
  If Index = kPUNTO Then
    ExtornarCanjePunto
  Else
    ExtornarCanjeTicket
  End If
  
  Screen.MousePointer = vbDefault

  Exit Sub

LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation
  Screen.MousePointer = vbDefault

End Sub

Private Sub ExtornarCanjePunto()

  'Extornar Canje de Puntos

  On Error GoTo LineaError

  Dim sSQL As String
  Dim ADORS As ADODB.Recordset

  Dim itemX As ListItem
  Dim bConnFlag As Boolean

  Screen.MousePointer = vbHourglass

  If lvwCanjePunto.SelectedItem.SmallIcon = 2 Then
    MsgBox "Transacción ya ha sido extornada", vbOKOnly + vbInformation
    Exit Sub
  End If

  If MsgBox("Se extornará transacción seleccionada (Fecha: " + lvwCanjePunto.SelectedItem.Text + " - Premio: " + lvwCanjePunto.SelectedItem.SubItems(2) + " - Cantidad: " + lvwCanjePunto.SelectedItem.SubItems(3) + " - Puntos Canjeados: " + lvwCanjePunto.SelectedItem.SubItems(4) + "). Confirma Acción?", _
  vbQuestion + vbYesNo + vbDefaultButton2) = vbNo Then Exit Sub

  ADOCnn.BeginTrans
  bConnFlag = True

  sSQL = "UPDATE Canje_Punto SET dExtoDate = '$', sUseEDesc = '$' " + _
         "WHERE cClieCode = $ AND cCanjCode = $"
  sSQL = VBsprintf(sSQL, Format(Now, "yyyy/mm/dd hh:mm"), ReemplazarComilla(psUsuario_Descripcion), sCliente, _
         Mid(lvwCanjePunto.SelectedItem.Key, 2))

  If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo LineaError1

  sSQL = "UPDATE Cliente SET nPuntCant = nPuntCant + $ " + _
         "WHERE cClieCode = $"
  sSQL = VBsprintf(sSQL, Format(lvwCanjePunto.SelectedItem.SubItems(4), "####0"), _
         sCliente)

  If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo LineaError1
  
  ADOCnn.CommitTrans
  bConnFlag = False

  Set itemX = lvwCanjePunto.SelectedItem

  itemX.SubItems(6) = Format(Now, "dd/mm/yyyy hh:mm")
  itemX.SubItems(7) = psUsuario_Descripcion
  itemX.Icon = 2
  itemX.SmallIcon = 2
  
  lblPuntos.Caption = Format(CLng(lblPuntos.Caption) + CLng(lvwCanjePunto.SelectedItem.SubItems(4)), "##,##0")
  frmPrincipal.lvwCliente.SelectedItem.SubItems(4) = lblPuntos.Caption

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

LineaError1:
  If bConnFlag Then ADOCnn.RollbackTrans

End Sub

Private Sub ExtornarCanjeTicket()

  'Extornar Canje de Tickets

  On Error GoTo LineaError

  Dim sSQL As String
  Dim ADORS As ADODB.Recordset

  Dim itemX As ListItem
  Dim bConnFlag As Boolean

  Screen.MousePointer = vbHourglass

  If lvwCanjeTicket.SelectedItem.SmallIcon = 2 Then
    MsgBox "Transacción ya ha sido extornada", vbOKOnly + vbInformation
    Exit Sub
  End If

  If MsgBox("Se extornará transacción seleccionada (Fecha: " + lvwCanjeTicket.SelectedItem.Text + " - Premio: " + lvwCanjeTicket.SelectedItem.SubItems(2) + " - Cantidad: " + lvwCanjeTicket.SelectedItem.SubItems(3) + " - Tickets Canjeados: " + lvwCanjeTicket.SelectedItem.SubItems(4) + "). Confirma Acción?", _
  vbQuestion + vbYesNo + vbDefaultButton2) = vbNo Then Exit Sub

  ADOCnn.BeginTrans
  bConnFlag = True

  sSQL = "UPDATE Canje_Ticket SET dExtoDate = '$', sUseEDesc = '$' " + _
         "WHERE cClieCode = $ AND cCanjCode = $"
  sSQL = VBsprintf(sSQL, Format(Now, "yyyy/mm/dd hh:mm"), ReemplazarComilla(psUsuario_Descripcion), sCliente, _
         Mid(lvwCanjeTicket.SelectedItem.Key, 2, 10))

  If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo LineaError1

  sSQL = "UPDATE Cliente SET nTickCant = nTickCant + $ " + _
         "WHERE cClieCode = $"
  sSQL = VBsprintf(sSQL, Format(lvwCanjeTicket.SelectedItem.SubItems(4), "####0"), _
         sCliente)

  If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo LineaError1
  
  sSQL = "UPDATE Premio_Ticket SET nPremStoc = nPremStoc + $ " + _
         "WHERE cPremCode = $"
  sSQL = VBsprintf(sSQL, Format(lvwCanjeTicket.SelectedItem.SubItems(3), "####0"), _
         Mid(lvwCanjeTicket.SelectedItem.Key, 12))

  If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo LineaError1

  ADOCnn.CommitTrans
  bConnFlag = False

  Set itemX = lvwCanjeTicket.SelectedItem

  itemX.SubItems(6) = Format(Now, "dd/mm/yyyy hh:mm")
  itemX.SubItems(7) = psUsuario_Descripcion
  itemX.Icon = 2
  itemX.SmallIcon = 2
  
  lblTickets.Caption = Format(CLng(lblTickets.Caption) + CLng(lvwCanjeTicket.SelectedItem.SubItems(4)), "##,##0")
  frmPrincipal.lvwCliente.SelectedItem.SubItems(5) = lblTickets.Caption

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

LineaError1:
  If bConnFlag Then ADOCnn.RollbackTrans

End Sub

Private Sub cmdCliente_Click()

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

End Sub

Private Sub CmdSalir_Click()

  'Descargar Form

  On Error GoTo LineaError

  frmCanje.lblPuntos.Caption = lblPuntos.Caption
  frmCanje.lblTickets.Caption = lblTickets.Caption
  
  Unload Me

  Exit Sub

LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation

End Sub

