VERSION 5.00
Begin VB.Form frmReglaTicket 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Reglas - Ticket"
   ClientHeight    =   2160
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   4500
   Icon            =   "frmReglaTicket.frx":0000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   ScaleHeight     =   2160
   ScaleWidth      =   4500
   StartUpPosition =   2  'CenterScreen
   Begin VB.CommandButton cmdEstandar 
      Caption         =   "&Aceptar"
      Default         =   -1  'True
      Height          =   375
      Index           =   0
      Left            =   1560
      TabIndex        =   2
      Top             =   1680
      Width           =   1335
   End
   Begin VB.CommandButton cmdEstandar 
      Cancel          =   -1  'True
      Caption         =   "&Cancelar"
      Height          =   375
      Index           =   1
      Left            =   3000
      TabIndex        =   3
      Top             =   1680
      Width           =   1335
   End
   Begin VB.Frame fraReglaTicket 
      Height          =   1575
      Left            =   120
      TabIndex        =   4
      Top             =   0
      Width           =   4215
      Begin VB.TextBox txtTicket 
         Height          =   315
         Left            =   2640
         TabIndex        =   1
         Top             =   1080
         Width           =   1215
      End
      Begin VB.Label lblLabels 
         Caption         =   $"frmReglaTicket.frx":0442
         Height          =   975
         Index           =   0
         Left            =   240
         TabIndex        =   0
         Top             =   360
         Width           =   3615
      End
   End
End
Attribute VB_Name = "frmReglaTicket"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Dim bInsertarFlag As Boolean

Private Sub Form_Load()

  'Carga el formulario

  On Error GoTo LineaError

  Screen.MousePointer = vbHourglass
  
  InicializarForm
  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
  
  txtTicket.Text = 0
  bInsertarFlag = False
  
  If Not (piPerfil_Codigo = kPERFIL_ADMINISTRADOR Or piPerfil_Codigo = kPERFIL_SUPERVISOR) Then
    Call DeshabilitarControl(txtTicket, True)
  End If

  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 nTickMaxi FROM Regla_Ticket"
  If Not oDBAdmin.EjecutarConsulta(ADOCnn, sSQL, ADORS) Then GoTo Salir
  
  If ADORS.EOF Then
    
    bInsertarFlag = True
  
  Else
  
    txtTicket.Text = Format(LeerCampo(ADORS!nTickMaxi), "##,##0")
  
  End If
  
  GoTo Salir
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation
  
Salir:
  Set ADORS = Nothing

End Sub

Private Sub txtTicket_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 txtTicket_LostFocus()

  'Formatea el texto
  
  On Error GoTo LineaError
  
  txtTicket.Text = Format(txtTicket.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 Regla_Ticket
  
  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 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 ValidarData() As Boolean

  'Valida que la información ingresada sea correcta y completa

  On Error GoTo LineaError

  ValidarData = False
  
  If Trim(txtTicket.Text) = "" Then
    MsgBox "Ingresar máxima cantidad", vbOKOnly + vbInformation
    txtTicket.SetFocus
    Exit Function
  End If

  ValidarData = True

  Exit Function

LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation

End Function

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_Ticket (nTickMaxi) " + _
           "VALUES ($)"
    sSQL = VBsprintf(sSQL, Format(txtTicket.Text, "####0"))
  
  Else
  
    sSQL = "UPDATE Regla_Ticket SET nTickMaxi = $"
    sSQL = VBsprintf(sSQL, Format(txtTicket.Text, "####0"))

  End If

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

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


