VERSION 5.00
Begin VB.Form frmCabeceraImpresion 
   Caption         =   "Cabecera de Impresión"
   ClientHeight    =   1755
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   5730
   Icon            =   "frmCabeceraImpresion.frx":0000
   LinkTopic       =   "Form1"
   ScaleHeight     =   1755
   ScaleWidth      =   5730
   StartUpPosition =   1  'CenterOwner
   Begin VB.CommandButton cmdEstandar 
      Cancel          =   -1  'True
      Caption         =   "&Cancelar"
      Height          =   375
      Index           =   1
      Left            =   4155
      TabIndex        =   3
      Top             =   1260
      Width           =   1335
   End
   Begin VB.CommandButton cmdEstandar 
      Caption         =   "&Aceptar"
      Default         =   -1  'True
      Height          =   375
      Index           =   0
      Left            =   2715
      TabIndex        =   2
      Top             =   1260
      Width           =   1335
   End
   Begin VB.Frame fraUsuario 
      Height          =   1095
      Left            =   0
      TabIndex        =   0
      Top             =   0
      Width           =   5565
      Begin VB.TextBox txtLinea 
         BackColor       =   &H00C0FFFF&
         Height          =   315
         Left            =   1170
         Locked          =   -1  'True
         MaxLength       =   15
         TabIndex        =   4
         Top             =   240
         Width           =   900
      End
      Begin VB.TextBox txtDescripcion 
         Height          =   315
         IMEMode         =   3  'DISABLE
         Left            =   1170
         MaxLength       =   60
         TabIndex        =   1
         Top             =   600
         Width           =   4200
      End
      Begin VB.Label lblLabels 
         AutoSize        =   -1  'True
         Caption         =   "Descripción "
         Height          =   195
         Index           =   1
         Left            =   195
         TabIndex        =   6
         Top             =   660
         Width           =   885
      End
      Begin VB.Label lblLabels 
         AutoSize        =   -1  'True
         Caption         =   "Línea"
         Height          =   195
         Index           =   0
         Left            =   195
         TabIndex        =   5
         Top             =   300
         Width           =   420
      End
   End
End
Attribute VB_Name = "frmCabeceraImpresion"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Public iEditar As Integer

Private Sub Form_Load()

  'Cargar formulario
  
  On Error GoTo LineaError

  Screen.MousePointer = vbHourglass
  
  InicializarForm
  
  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

  Select Case iEditar
  
  Case kCMD_NUEVO
    Me.Caption = "Nueva Línea"
    Dim sSQL As String
    Dim ADORS As ADODB.Recordset
 
    sSQL = "SELECT MAX(cCabeLinea) AS Linea FROM Cabecera_Impresion"
    
    If Not oDBAdmin.EjecutarConsulta(ADOCnn, sSQL, ADORS) Then GoTo Salir
    
    If LeerCampo(ADORS("Linea")) = "" Then
      txtLinea = 1
    Else
      txtLinea = LeerCampo(ADORS("Linea")) + 1
    End If
  
  Case kCMD_EDITAR
    Me.Caption = "Editar Línea"
    TraerData
    DeshabilitarControles False
  
  Case kCMD_BORRAR
    Me.Caption = "Borrar Línea"
    TraerData
    DeshabilitarControles True
    
  Case kCMD_VER
    Me.Caption = "Ver Línea"
    TraerData
    DeshabilitarControles True
    
  End Select
  
  GoTo Salir
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation
Salir:
  Set ADORS = Nothing
End Sub

Private Sub TraerData()

  'Trae la data de la tabla Usuario
  
  On Error GoTo LineaError

  Dim sSQL As String
  Dim ADORS As ADODB.Recordset
  
  sSQL = "SELECT * FROM Cabecera_Impresion " + _
         "WHERE TRIM(cCabeLinea) = TRIM($)"
  sSQL = VBsprintf(sSQL, frmCabeceraImpresionLista.lvwCabecera.SelectedItem.Text)
  
  If oDBAdmin.EjecutarConsulta(ADOCnn, sSQL, ADORS) Then
  
    If Not ADORS.EOF Then
      
      txtLinea.Text = LeerCampo(ADORS!cCabeLinea)
      txtDescripcion.Text = LeerCampo(ADORS!sCabeDescripcion)
    End If
    
  End If
  
  Exit Sub
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation
  
End Sub

Private Sub DeshabilitarControles(bTodoFlag As Boolean)

  'Deshabilita controles
  
  On Error GoTo LineaError

  Call DeshabilitarControl(txtLinea, True)
  
  If bTodoFlag Then
    Call DeshabilitarControl(txtDescripcion, True)
  End If
  
  Exit Sub
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation
  
End Sub

Private Sub txtDescripcion_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 cmdEstandar_Click(Index As Integer)

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

  Screen.MousePointer = vbHourglass
  
  Select Case Index
  
  Case kCMD_ACEPTAR
        
    If iEditar = kCMD_VER Then
      Unload Me
      GoTo Salir
    End If
  
    If ValidarData Then
    
      If ActualizarTabla Then
          ActualizarLista
          frmCabeceraImpresionLista.ManejarControles
          Unload Me
        
      End If
    
    End If
  
  Case kCMD_CANCELAR
  
    Unload Me
    
  End Select
  
  GoTo Salir
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation
  
Salir:
  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
  ValidarData = True
  
  Exit Function
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation

End Function

Private Function ActualizarTabla() As Boolean

  'Inserta/Actualiza/Elimina el registro de Usuario
  
  On Error GoTo LineaError

  Dim sSQL As String
     
  ActualizarTabla = False
  
  Select Case iEditar
  
  Case kCMD_NUEVO
  
    sSQL = "INSERT INTO Cabecera_Impresion (cCabeLinea, sCabeDescripcion) " + _
           "VALUES ($, '$')"
    sSQL = VBsprintf(sSQL, Trim(txtLinea.Text), _
           ReemplazarComilla(Trim(txtDescripcion.Text)))
  
  Case kCMD_EDITAR
  
    sSQL = "UPDATE Cabecera_Impresion SET sCabeDescripcion = '$'" + _
           "WHERE cCabeLinea = $"
    sSQL = VBsprintf(sSQL, ReemplazarComilla(Trim(txtDescripcion.Text)), _
           Trim(txtLinea.Text))
  
  Case kCMD_BORRAR
  
    sSQL = "DELETE * FROM cabecera_impresion " + _
           "WHERE cCabeLinea = $"
    sSQL = VBsprintf(sSQL, Trim(txtLinea.Text))
  
  End Select
  
  If oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then ActualizarTabla = 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 iEditar = kCMD_NUEVO Then
      Set itemX = frmCabeceraImpresionLista.lvwCabecera.ListItems.Add(, , Trim(txtLinea.Text))
    Else
      Set itemX = frmCabeceraImpresionLista.lvwCabecera.SelectedItem
      itemX.Text = Trim(txtLinea.Text)
    End If
    
    itemX.SubItems(1) = txtDescripcion.Text
    
    itemX.Selected = True
    
  Case kCMD_BORRAR
  
    frmCabeceraImpresionLista.lvwCabecera.ListItems.Remove (frmCabeceraImpresionLista.lvwCabecera.SelectedItem.Index)
    
  End Select
      
  Exit Sub
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation
  
End Sub
