VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MsComCtl.ocx"
Begin VB.Form frmReglaPunto 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Reglas - Punto"
   ClientHeight    =   5925
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   10785
   Icon            =   "frmReglaPunto.frx":0000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   ScaleHeight     =   5925
   ScaleWidth      =   10785
   StartUpPosition =   2  'CenterScreen
   Begin VB.CommandButton cmdEstandar 
      Cancel          =   -1  'True
      Caption         =   "&Cancelar"
      Height          =   375
      Index           =   1
      Left            =   9360
      TabIndex        =   22
      Top             =   5400
      Width           =   1335
   End
   Begin VB.CommandButton cmdEstandar 
      Caption         =   "&Aceptar"
      Default         =   -1  'True
      Height          =   375
      Index           =   0
      Left            =   7920
      TabIndex        =   21
      Top             =   5400
      Width           =   1335
   End
   Begin VB.Frame fraReglaPunto 
      Height          =   5175
      Index           =   0
      Left            =   120
      TabIndex        =   23
      Top             =   120
      Width           =   10575
      Begin VB.CommandButton cmdMarcar 
         Caption         =   "&Marcar Todo"
         Height          =   375
         Left            =   4920
         TabIndex        =   31
         Top             =   4200
         Width           =   1335
      End
      Begin VB.Frame fraPremioPunto 
         Caption         =   "Ver "
         Height          =   1095
         Index           =   1
         Left            =   4920
         TabIndex        =   28
         Top             =   1440
         Width           =   1335
         Begin VB.OptionButton optActivos 
            Caption         =   "Activos"
            Height          =   255
            Index           =   1
            Left            =   240
            TabIndex        =   30
            Top             =   600
            Width           =   975
         End
         Begin VB.OptionButton optActivos 
            Caption         =   "Inactivos"
            Height          =   255
            Index           =   0
            Left            =   240
            TabIndex        =   29
            Top             =   240
            Width           =   975
         End
      End
      Begin VB.CommandButton cmdActivar 
         Caption         =   "Ac&tivar"
         Height          =   375
         Left            =   4920
         TabIndex        =   12
         Top             =   4680
         Width           =   1335
      End
      Begin VB.Frame fraPremioPunto 
         Height          =   3615
         Index           =   0
         Left            =   6720
         TabIndex        =   25
         Top             =   1440
         Width           =   3735
         Begin VB.Frame fraActivo 
            Height          =   1095
            Left            =   1200
            TabIndex        =   27
            Top             =   1680
            Width           =   2415
            Begin VB.OptionButton optActivo 
               Caption         =   "Inactivo"
               Height          =   255
               Index           =   0
               Left            =   600
               TabIndex        =   18
               Top             =   240
               Width           =   1215
            End
            Begin VB.OptionButton optActivo 
               Caption         =   "Activo"
               Height          =   255
               Index           =   1
               Left            =   600
               TabIndex        =   19
               Top             =   600
               Width           =   1215
            End
         End
         Begin VB.TextBox txtPuntaje 
            Height          =   315
            Left            =   1200
            TabIndex        =   14
            Top             =   360
            Width           =   1215
         End
         Begin VB.CommandButton cmdGrabar 
            Caption         =   "&Grabar"
            Height          =   375
            Left            =   2280
            TabIndex        =   20
            Top             =   3000
            Width           =   1335
         End
         Begin VB.TextBox txtPremio 
            Height          =   915
            Left            =   1200
            MaxLength       =   255
            MultiLine       =   -1  'True
            ScrollBars      =   2  'Vertical
            TabIndex        =   17
            Top             =   720
            Width           =   2415
         End
         Begin VB.Label lblLabels 
            Caption         =   "Se Gana"
            Height          =   375
            Index           =   8
            Left            =   240
            TabIndex        =   16
            Top             =   840
            Width           =   855
         End
         Begin VB.Label lblLabels 
            Caption         =   "Puntos"
            Height          =   375
            Index           =   5
            Left            =   2640
            TabIndex        =   15
            Top             =   360
            Width           =   855
         End
         Begin VB.Label lblLabels 
            Caption         =   "Cada"
            Height          =   375
            Index           =   6
            Left            =   240
            TabIndex        =   13
            Top             =   360
            Width           =   855
         End
      End
      Begin VB.CommandButton cmdEditar 
         Caption         =   "&Nuevo"
         Height          =   375
         Index           =   0
         Left            =   4920
         TabIndex        =   9
         Top             =   2760
         Width           =   1335
      End
      Begin VB.CommandButton cmdEditar 
         Caption         =   "&Editar"
         Height          =   375
         Index           =   1
         Left            =   4920
         TabIndex        =   10
         Top             =   3240
         Width           =   1335
      End
      Begin VB.CommandButton cmdEditar 
         Caption         =   "&Borrar"
         Height          =   375
         Index           =   2
         Left            =   4920
         TabIndex        =   11
         Top             =   3720
         Width           =   1335
      End
      Begin VB.Frame fraReglaPunto 
         Height          =   115
         Index           =   1
         Left            =   25
         TabIndex        =   24
         Top             =   1200
         Width           =   10495
      End
      Begin VB.TextBox txtPunto 
         Height          =   315
         Left            =   7800
         TabIndex        =   6
         Top             =   720
         Width           =   1215
      End
      Begin VB.TextBox txtImporte 
         Height          =   315
         Left            =   7800
         TabIndex        =   3
         Top             =   360
         Width           =   1215
      End
      Begin VB.TextBox txtImporteMaximo 
         Height          =   315
         Left            =   2880
         TabIndex        =   1
         Top             =   720
         Width           =   1215
      End
      Begin MSComctlLib.ListView lvwPremioPunto 
         Height          =   3375
         Left            =   120
         TabIndex        =   8
         Top             =   1680
         Width           =   4695
         _ExtentX        =   8281
         _ExtentY        =   5953
         LabelEdit       =   1
         LabelWrap       =   -1  'True
         HideSelection   =   0   'False
         _Version        =   393217
         Icons           =   "imlPuntaje"
         SmallIcons      =   "imlPuntaje"
         ForeColor       =   -2147483640
         BackColor       =   -2147483643
         BorderStyle     =   1
         Appearance      =   1
         NumItems        =   0
      End
      Begin VB.Label lblLabels 
         Caption         =   "Nuevos Soles"
         Height          =   375
         Index           =   9
         Left            =   4320
         TabIndex        =   32
         Top             =   720
         Width           =   1095
      End
      Begin VB.Label lblLabels 
         Alignment       =   2  'Center
         BorderStyle     =   1  'Fixed Single
         Caption         =   "Premios por Puntaje"
         Height          =   255
         Index           =   7
         Left            =   120
         TabIndex        =   26
         Top             =   1440
         Width           =   4695
      End
      Begin VB.Label lblLabels 
         Caption         =   "Puntos"
         Height          =   375
         Index           =   4
         Left            =   9240
         TabIndex        =   7
         Top             =   720
         Width           =   615
      End
      Begin VB.Label lblLabels 
         Caption         =   "Se Gana"
         Height          =   375
         Index           =   3
         Left            =   6840
         TabIndex        =   5
         Top             =   720
         Width           =   855
      End
      Begin VB.Label lblLabels 
         Caption         =   "Nuevos Soles"
         Height          =   375
         Index           =   2
         Left            =   9240
         TabIndex        =   4
         Top             =   360
         Width           =   1095
      End
      Begin VB.Label lblLabels 
         Caption         =   "Cada"
         Height          =   375
         Index           =   1
         Left            =   6840
         TabIndex        =   2
         Top             =   360
         Width           =   615
      End
      Begin VB.Label lblLabels 
         Caption         =   $"frmReglaPunto.frx":0442
         Height          =   975
         Index           =   0
         Left            =   120
         TabIndex        =   0
         Top             =   240
         Width           =   5295
      End
   End
   Begin MSComctlLib.ImageList imlPuntaje 
      Left            =   360
      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         =   "frmReglaPunto.frx":04FA
            Key             =   ""
         EndProperty
         BeginProperty ListImage2 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "frmReglaPunto.frx":094C
            Key             =   ""
         EndProperty
      EndProperty
   End
End
Attribute VB_Name = "frmReglaPunto"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Dim bInsertarFlag As Boolean
Dim iEditar As Integer
Dim iItem As Integer

Dim sCodigo As String

Private Sub Form_Load()

  'Carga el formulario

  On Error GoTo LineaError

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

End Sub

Private Sub InicializarForm()

  'Inicializa Form según opción

  On Error GoTo LineaError
  
  txtImporteMaximo.Text = 0
  optActivos(kSI).Value = True
  optActivo(kSI).Value = True
  
  iItem = 0
  bInsertarFlag = False
  
  If piPerfil_Codigo = kPERFIL_ADMINISTRADOR Or piPerfil_Codigo = kPERFIL_SUPERVISOR Then
    Call DeshabilitarControles(False)
  Else
    Call DeshabilitarControles(True)
  End If

  Exit Sub

LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation

End Sub

Private Sub DeshabilitarControles(bTodoFlag As Boolean)

  If bTodoFlag Then
    Call DeshabilitarControl(txtImporteMaximo, True)
    Call DeshabilitarControl(txtImporte, True)
    Call DeshabilitarControl(txtPunto, True)
  End If

  Call DeshabilitarControl(txtPuntaje, True)
  Call DeshabilitarControl(txtPremio, True)
  Call DeshabilitarControl(optActivo(kSI), False)
  Call DeshabilitarControl(optActivo(kNO), False)
  Call DeshabilitarControl(cmdGrabar, False)
  
  cmdEstandar(kCMD_ACEPTAR).Default = True

End Sub

Private Sub HabilitarControles(bTodoFlag As Boolean)

  Call HabilitarControl(txtPuntaje, True)
  
  If bTodoFlag Then
    Call HabilitarControl(txtPremio, True)
  End If
  
  Call HabilitarControl(optActivo(kSI), False)
  Call HabilitarControl(optActivo(kNO), False)
  Call HabilitarControl(cmdGrabar, False)
  
  cmdGrabar.Default = True

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(2) As String
  ReDim aColumnWidth(2) As Single
  ReDim aColumnAlign(2) As Integer

  aColumnTitle(0) = "Premio"
  aColumnTitle(1) = "Cant.Puntos"
  
  aColumnWidth(0) = 0.65
  aColumnWidth(1) = 0.26
  
  aColumnAlign(0) = lvwColumnLeft
  aColumnAlign(1) = lvwColumnRight
  
  lvwPremioPunto.CheckBoxes = True
    
  Call oListAdmin.InicializarLista(lvwPremioPunto, aColumnTitle, _
                                   aColumnWidth, aColumnAlign, lvwReport)
                                   
  Exit Sub
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation

End Sub

Private Sub TraerData()

  'Trae los datos de la Tabla Regla_Ticket
  
  On Error GoTo LineaError

  Dim sSQL As String
  Dim ADORS As ADODB.Recordset
  
  sSQL = "SELECT * FROM Regla_Punto"
  If Not oDBAdmin.EjecutarConsulta(ADOCnn, sSQL, ADORS) Then GoTo Salir
  
  If ADORS.EOF Then
    
    bInsertarFlag = True
  
  Else
  
    txtImporteMaximo.Text = Format(LeerCampo(ADORS!nImpoMaxi), "##,##0")
    txtImporte.Text = Format(LeerCampo(ADORS!nPuntImpo), "##,##0")
    txtPunto.Text = Format(LeerCampo(ADORS!nPuntCant), "##,##0")
  
  End If
  
  GoTo Salir
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation
  
Salir:
  Set ADORS = Nothing

End Sub

Private Sub optActivos_Click(Index As Integer)

  Call LlenarLista
  Call ManejarControles

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
  
  lvwPremioPunto.ListItems.Clear
  cmdMarcar.Caption = "&Marcar Todo"
  
  sSQL = "SELECT * " + _
         "FROM Premio_Punto " + _
         "WHERE cPremActi = $"
  sSQL = VBsprintf(sSQL, IIf(optActivos(kSI), kSI, kNO))
  If Not oDBAdmin.EjecutarConsulta(ADOCnn, sSQL, ADORS) Then GoTo Salir
  
  Do While Not ADORS.EOF
  
    Set itemX = lvwPremioPunto.ListItems.Add(, "k" + LeerCampo(ADORS!cPremCode), LeerCampo(ADORS!sPremDesc))
    itemX.SubItems(1) = Format(LeerCampo(ADORS!nPuntCant), "##,##0")
    
    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 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(cmdMarcar, False)
  Call DeshabilitarControl(cmdActivar, False)
  
  If piPerfil_Codigo = kPERFIL_ADMINISTRADOR Or piPerfil_Codigo = kPERFIL_SUPERVISOR Then
    Call HabilitarControl(cmdEditar(kCMD_NUEVO), False)
  End If

  If lvwPremioPunto.ListItems.Count > 0 Then
    
    lvwPremioPunto.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(cmdMarcar, False)
      Call HabilitarControl(cmdActivar, False)
      
    End If
    
  End If
  
  Exit Sub
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation
  
End Sub

Private Sub txtImporteMaximo_KeyPress(KeyAscii As Integer)

  'Valida q se ingrese solo valores numéricos (enteros)

  On Error GoTo LineaError

  Call ValidKeyPress(KeyAscii, kVKP_NUMERIC_INTEGER_ONLY)

  Exit Sub

LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation

End Sub

Private Sub txtImporteMaximo_LostFocus()

  'Formatea el texto
  
  On Error GoTo LineaError
  
  txtImporteMaximo.Text = Format(txtImporteMaximo.Text, "##,##0")
  
  Exit Sub

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

Private Sub txtImporte_KeyPress(KeyAscii As Integer)

  'Valida q se ingrese solo valores numéricos (enteros)

  On Error GoTo LineaError

  Call ValidKeyPress(KeyAscii, kVKP_NUMERIC_INTEGER_ONLY)

  Exit Sub

LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation

End Sub

Private Sub txtImporte_LostFocus()

  'Formatea el texto
  
  On Error GoTo LineaError
  
  txtImporte.Text = Format(txtImporte.Text, "##,##0")
  
  Exit Sub

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

Private Sub txtPunto_KeyPress(KeyAscii As Integer)

  'Valida q se ingrese solo valores numéricos (enteros)

  On Error GoTo LineaError

  Call ValidKeyPress(KeyAscii, kVKP_NUMERIC_INTEGER_ONLY)

  Exit Sub

LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation

End Sub

Private Sub txtPunto_LostFocus()

  'Formatea el texto
  
  On Error GoTo LineaError
  
  txtPunto.Text = Format(txtPunto.Text, "##,##0")
  
  Exit Sub

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

Private Sub txtPuntaje_KeyPress(KeyAscii As Integer)

  'Valida q se ingrese solo valores numéricos (enteros)

  On Error GoTo LineaError

  Call ValidKeyPress(KeyAscii, kVKP_NUMERIC_INTEGER_ONLY)

  Exit Sub

LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation

End Sub

Private Sub txtPuntaje_LostFocus()

  'Formatea el texto
  
  On Error GoTo LineaError
  
  txtPuntaje.Text = Format(txtPuntaje.Text, "##,##0")
  
  Exit Sub

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

Private Sub txtPremio_KeyPress(KeyAscii As Integer)

  'Convierte cada caracter digitado a mayúsculas

  On Error GoTo LineaError

  Call ValidKeyPress(KeyAscii, kVKP_UPPER_CASE)

  Exit Sub

LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation

End Sub

Private Sub cmdEditar_Click(Index As Integer)

  'Edición de Tabla Premio_Punto
  
  On Error GoTo LineaError
  
  Dim sSQL As String
  Dim ADORS As ADODB.Recordset
  
  Dim bTodoFlag As Boolean
  
  iEditar = Index
  
  bTodoFlag = True
  LimpiarControles
  Call DeshabilitarControles(False)
   
  If Index = kCMD_EDITAR Or Index = kCMD_BORRAR Then

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

    If Not ADORS.EOF Then
      If Index = kCMD_EDITAR Then
        bTodoFlag = False
      Else
        MsgBox "No se puede borrar Premio. El premio registra transacciones", vbOKOnly + vbInformation
        Exit Sub
      End If
    End If
    
    Set ADORS = Nothing

  End If

  Select Case iEditar
  
  Case kCMD_NUEVO, kCMD_EDITAR
    
    If iEditar = kCMD_EDITAR Then
  
      sCodigo = Mid(lvwPremioPunto.SelectedItem.Key, 2)
      
      sSQL = "SELECT * FROM Premio_Punto " + _
             "WHERE cPremCode = $"
      sSQL = VBsprintf(sSQL, sCodigo)
      
      If Not oDBAdmin.EjecutarConsulta(ADOCnn, sSQL, ADORS) Then Exit Sub
      
      If Not ADORS.EOF Then
        
        txtPuntaje.Text = Format(LeerCampo(ADORS!nPuntCant), "##,##0")
        txtPremio.Text = LeerCampo(ADORS!sPremDesc)
        
        If LeerCampo(ADORS!cPremActi) <> kSI Then
          optActivo(kNO).Value = True
        Else
          optActivo(kSI).Value = True
        End If
        
      End If
      
      Set ADORS = Nothing
    
    End If
    
    HabilitarControles (bTodoFlag)
    
  Case kCMD_BORRAR
  
    If MsgBox("Se borrará " + lvwPremioPunto.SelectedItem.Text + ".Confirma Acción?", vbQuestion + vbYesNo + vbDefaultButton2) = vbNo Then Exit Sub
  
    sSQL = "DELETE FROM Premio_Punto WHERE cPremCode = $"
    sSQL = VBsprintf(sSQL, Mid(lvwPremioPunto.SelectedItem.Key, 2))
    
    If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then Exit Sub
    
    ActualizarLista
    
  End Select
  
  On Error Resume Next
  txtPuntaje.SetFocus
  
  GoTo Salir

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

Private Sub cmdGrabar_Click()

  'Inserta/Actualiza el registro de Premio_Punto

  On Error GoTo LineaError

  Dim sSQL As String
  Dim ADORS As ADODB.Recordset
  
  Screen.MousePointer = vbHourglass
  
  If Not ValidarData(True) Then GoTo Salir

  Select Case iEditar

  Case kCMD_NUEVO
  
    sSQL = "SELECT MAX(cPremCode) AS Codigo FROM Premio_Punto"
    If Not oDBAdmin.EjecutarConsulta(ADOCnn, sSQL, ADORS) Then GoTo Salir

    sCodigo = "1"

    If Not ADORS.EOF Then

      If LeerCampo(ADORS!Codigo) <> "" Then
        sCodigo = CStr(ADORS!Codigo + 1)
      End If

    End If

    Set ADORS = Nothing
  
    sSQL = "INSERT INTO Premio_Punto (cPremCode, nPuntCant, sPremDesc, cPremActi) " + _
           "VALUES ($, $, '$', $)"
    sSQL = VBsprintf(sSQL, sCodigo, _
           Format(txtPuntaje.Text, "####0"), _
           ReemplazarComilla(Trim(txtPremio.Text)), _
           IIf(optActivo(kSI).Value, kSI, kNO))
    
  Case kCMD_EDITAR

    sSQL = "UPDATE Premio_Punto SET nPuntCant = $, sPremDesc ='$', cPremActi = $ " + _
           "WHERE cPremCode = $"
    sSQL = VBsprintf(sSQL, Format(txtPuntaje.Text, "####0"), _
           ReemplazarComilla(Trim(txtPremio.Text)), _
           IIf(optActivo(kSI).Value, kSI, kNO), _
           sCodigo)

  End Select

  If oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then ActualizarLista
  
  GoTo Salir

LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation
  
Salir:
  Set ADORS = Nothing
  Screen.MousePointer = vbDefault
  
End Sub

Private Function ValidarData(bPremioPuntoFlag As Boolean) As Boolean

  'Valida que la información ingresada sea correcta y completa
  
  On Error GoTo LineaError

  ValidarData = False
  
  If bPremioPuntoFlag Then
  
    If Trim(txtPuntaje.Text) = "" Then
      MsgBox "Ingresar Puntaje", vbOKOnly + vbInformation
      txtPuntaje.SetFocus
      Exit Function
    End If
  
    If Trim(txtPremio.Text) = "" Then
      MsgBox "Ingresar Premio", vbOKOnly + vbInformation
      txtPremio.SetFocus
      Exit Function
    End If
    
  Else
  
    If Trim(txtImporteMaximo.Text) = "" Then
      MsgBox "Ingresar máximo importe", vbOKOnly + vbInformation
      txtImporteMaximo.SetFocus
      Exit Function
    End If
  
    If Trim(txtImporte.Text) = "" Then
      MsgBox "Ingresar importe", vbOKOnly + vbInformation
      txtImporte.SetFocus
      Exit Function
    End If
    
    If CLng(txtImporte.Text) = 0 Then
      MsgBox "Ingresar importe mayor a 0", vbOKOnly + vbInformation
      txtImporte.SetFocus
      Exit Function
    End If
  
    If Trim(txtPunto.Text) = "" Then
      MsgBox "Ingresar puntos", vbOKOnly + vbInformation
      txtPunto.SetFocus
      Exit Function
    End If
    
  End If
  
  ValidarData = True
  
  Exit Function
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation

End Function

Private Sub ActualizarLista()

  'Actualiza la lista de frmusuarioLista

  On Error GoTo LineaError
  
  Dim itemX As ListItem
  
  Select Case iEditar
  
  Case kCMD_NUEVO, kCMD_EDITAR
  
    If optActivos(kSI).Value = optActivo(kSI).Value Or optActivos(kNO).Value = optActivo(kNO).Value Then
  
      If iEditar = kCMD_NUEVO Then
        Set itemX = lvwPremioPunto.ListItems.Add(, "k" + sCodigo, Trim(txtPremio.Text))
      Else
        Set itemX = lvwPremioPunto.SelectedItem
        itemX.Text = Trim(txtPremio.Text)
      End If
    
      itemX.SubItems(1) = Format(txtPuntaje.Text, "##,##0")
      
      If optActivo(kSI).Value Then
        itemX.Icon = 1
        itemX.SmallIcon = 1
      Else
        itemX.Icon = 2
        itemX.SmallIcon = 2
      End If
      
      itemX.Selected = True
      
    Else
    
      If iEditar = kCMD_NUEVO Then
        
        If optActivo(kSI).Value Then
          optActivos(kSI).Value = True
        Else
          optActivos(kNO).Value = True
        End If
      
      ElseIf iEditar = kCMD_EDITAR Then
        lvwPremioPunto.ListItems.Remove (lvwPremioPunto.SelectedItem.Index)
      End If
      
    End If
    
  Case kCMD_BORRAR
  
    lvwPremioPunto.ListItems.Remove (lvwPremioPunto.SelectedItem.Index)
    
  End Select
  
  Call LimpiarControles
  Call DeshabilitarControles(False)
  Call ManejarControles
      
  Exit Sub
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation
  
End Sub

Private Sub LimpiarControles()

  'Limpiar Controles
  
  On Error GoTo LineaError

  txtPuntaje.Text = ""
  txtPremio.Text = ""
  optActivo(kSI).Value = True
  
  Exit Sub
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation
  
End Sub

Private Sub lvwPremioPunto_ColumnClick(ByVal ColumnHeader As MSComctlLib.ColumnHeader)

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

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

Private Sub lvwPremioPunto_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 = lvwPremioPunto.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 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 lvwPremioPunto.ListItems.Count
      lvwPremioPunto.ListItems(i).Checked = True
    Next
    
    cmdMarcar.Caption = "Des&marc. Todo"
      
  Else
  
    For i = 1 To lvwPremioPunto.ListItems.Count
      lvwPremioPunto.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
  
  LimpiarControles
  Call DeshabilitarControles(False)
  
  i = 1
  iCant = lvwPremioPunto.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 lvwPremioPunto.ListItems(i).Checked Then
    
      sSQL = "UPDATE Premio_Punto SET cPremActi = $ " + _
             "WHERE cPremCode = $"
      sSQL = VBsprintf(sSQL, IIf(optActivos(kSI).Value, kNO, kSI), _
             Mid(lvwPremioPunto.ListItems(i).Key, 2))
               
      If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
        
      lvwPremioPunto.ListItems.Remove (lvwPremioPunto.ListItems(i).Index)
        
      iCant = lvwPremioPunto.ListItems.Count
      i = i - 1
      
    End If
    
    i = i + 1
  
  Loop
  
  Call ManejarControles
  
  GoTo Salir
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation
  
Salir:
  Screen.MousePointer = vbDefault

End Sub

Private Sub cmdEstandar_Click(Index As Integer)

  'Permite descargar el formulario, previamente haciendo cambios o no en
  'la tabla Regla_Punto
  
  On Error GoTo LineaError
  
  Screen.MousePointer = vbHourglass
  
  Select Case Index

  Case kCMD_ACEPTAR
  
    If piPerfil_Codigo = kPERFIL_ADMINISTRADOR Or piPerfil_Codigo = kPERFIL_SUPERVISOR Then

      If ValidarData(False) Then

        If ActualizarTabla Then Unload Me
      
      End If
      
    Else
    
      Unload Me
      
    End If

  Case kCMD_CANCELAR

    Unload Me

  End Select

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

End Sub

Private Function ActualizarTabla() As Boolean

  'Actualiza la cantidad máxima de tickets

  On Error GoTo LineaError

  Dim sSQL As String
  Dim ADORS As ADODB.Recordset

  ActualizarTabla = False
  
  If bInsertarFlag Then
  
    sSQL = "INSERT INTO Regla_Punto (nImpoMaxi, nPuntImpo, nPuntCant) " + _
           "VALUES ($, $, $)"
    sSQL = VBsprintf(sSQL, Format(txtImporteMaximo.Text, "####0"), _
           Format(txtImporte.Text, "####0"), _
           Format(txtPunto.Text, "####0"))
  
  Else
  
    sSQL = "UPDATE Regla_Punto SET nImpoMaxi = $, nPuntImpo = $, nPuntCant = $ "
    sSQL = VBsprintf(sSQL, Format(txtImporteMaximo.Text, "####0"), _
           Format(txtImporte.Text, "####0"), _
           Format(txtPunto.Text, "####0"))

  End If

  If oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then ActualizarTabla = True
  
  Exit Function

LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation
  
End Function




