VERSION 5.00
Begin VB.Form frmIngresoPremioTicket 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Ingresar Cantidad (Premio - Ticket)"
   ClientHeight    =   1545
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   4680
   Icon            =   "frmIngresoPremioTicket.frx":0000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   ScaleHeight     =   1545
   ScaleWidth      =   4680
   StartUpPosition =   2  'CenterScreen
   Begin VB.CommandButton cmdEstandar 
      Caption         =   "&Aceptar"
      Default         =   -1  'True
      Height          =   375
      Index           =   0
      Left            =   3240
      TabIndex        =   3
      Top             =   480
      Width           =   1335
   End
   Begin VB.CommandButton cmdEstandar 
      Cancel          =   -1  'True
      Caption         =   "&Cancelar"
      Height          =   375
      Index           =   1
      Left            =   3240
      TabIndex        =   4
      Top             =   960
      Width           =   1335
   End
   Begin VB.Frame fraIngresoPremioTicket 
      Height          =   975
      Left            =   120
      TabIndex        =   5
      Top             =   360
      Width           =   2895
      Begin VB.TextBox txtCantidad 
         Height          =   315
         Left            =   1320
         TabIndex        =   2
         Top             =   360
         Width           =   1215
      End
      Begin VB.Label lblLabels 
         Caption         =   "Can&tidad"
         Height          =   375
         Index           =   0
         Left            =   240
         TabIndex        =   1
         Top             =   360
         Width           =   1455
      End
   End
   Begin VB.Label lblPremio 
      Alignment       =   2  'Center
      Caption         =   "Premio"
      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        =   0
      Top             =   120
      Width           =   4575
   End
End
Attribute VB_Name = "frmIngresoPremioTicket"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Dim sCodigo As String

Private Sub txtCantidad_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 txtCantidad_LostFocus()

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

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

Private Sub cmdEstandar_Click(Index As Integer)

  'Permite descargar el formulario, previamente haciendo cambios o no en
  'la tabla Ingreso_Premio_Ticket
  
  On Error GoTo LineaError

  Screen.MousePointer = vbHourglass
  
  Select Case Index
  
  Case kCMD_ACEPTAR
        
    If ValidarData Then
    
      If ActualizarTabla Then
    
        ActualizarLista
        Unload Me
        
      End If
    
    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 ValidarData() As Boolean

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

  ValidarData = False
  
  If Trim(txtCantidad.Text) = "" Then
    MsgBox "Ingresar Cantidad, vbOKOnly + vbInformation"
    txtCantidad.SetFocus
    Exit Function
  End If
  
  ValidarData = True
  
  Exit Function
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation

End Function

Private Function ActualizarTabla() As Boolean

  'Inserta el registro de Ingreso_Premio_Ticket

  On Error GoTo LineaError

  Dim sSQL As String
  Dim ADORS As ADODB.Recordset
  
  Dim bConnFlag As Boolean
  Dim sPremio As String

  ActualizarTabla = False
  
  sPremio = Mid(frmPremioTicketLista.lvwPremioTicket.SelectedItem.Key, 2)
  
  sSQL = "SELECT MAX(cIngrCode) AS Codigo FROM Ingreso_Premio_Ticket " + _
         "WHERE cPremCode = $"
  sSQL = VBsprintf(sSQL, sPremio)
  If Not oDBAdmin.EjecutarConsulta(ADOCnn, sSQL, ADORS) Then GoTo LineaError1

  sCodigo = "1"

  If Not ADORS.EOF Then

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

  End If

  Set ADORS = Nothing
  
  ADOCnn.BeginTrans
  bConnFlag = True
  
  sSQL = "INSERT INTO Ingreso_Premio_Ticket (cIngrCode, cPremCode, dIngrDate, " + _
         "nIngrCant, sUserDesc) " + _
         "VALUES($, $, '$', $, '$')"
  sSQL = VBsprintf(sSQL, sCodigo, sPremio, Format(Now, "yyyy/mm/dd hh:mm"), _
         Format(txtCantidad.Text, "####0"), ReemplazarComilla(psUsuario_Descripcion))
         
  If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo LineaError1
    
  sSQL = "UPDATE Premio_Ticket SET nPremStoc = nPremStoc + $ " + _
         "WHERE cPremCode = $"
  sSQL = VBsprintf(sSQL, Format(txtCantidad.Text, "####0"), _
         sPremio)

  If oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then
    ADOCnn.CommitTrans
    bConnFlag = False
    ActualizarTabla = True
  Else
    GoTo LineaError1
  End If

  Exit Function

LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation
  
LineaError1:
  Set ADORS = Nothing
  If bConnFlag Then ADOCnn.RollbackTrans
  
End Function

Private Sub ActualizarLista()

  'Actualiza las listas de frmPremioTicketLista

  On Error GoTo LineaError
  
  Dim itemX As ListItem
  Dim lStock As Long
  
  lStock = CLng(frmPremioTicketLista.lvwPremioTicket.SelectedItem.SubItems(1))
  
  frmPremioTicketLista.lvwPremioTicket.SelectedItem.SubItems(1) = Format(lStock + CLng(txtCantidad.Text), "##,##0")
  
  If Date >= frmPremioTicketLista.dFInicio And Date <= frmPremioTicketLista.dFFin Then
  
    Set itemX = frmPremioTicketLista.lvwIngresoPremioTicket.ListItems.Add(, "k" + sCodigo, Format(Now, "dd/mm/yyyy hh:mm"))
    itemX.SubItems(1) = Format(txtCantidad.Text, "##,##0")
    itemX.SubItems(2) = psUsuario_Descripcion
  
    itemX.Icon = 1
    itemX.SmallIcon = 1
  
    itemX.Selected = True
    
  Else
  
    frmPremioTicketLista.dtpFInicio.Value = Date - 15
    frmPremioTicketLista.dtpFFin.Value = Date
    
    Call frmPremioTicketLista.cmdBuscar_Click
    
  End If
         
  Exit Sub
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation
  
End Sub




