VERSION 5.00
Object = "{67397AA1-7FB1-11D0-B148-00A0C922E820}#6.0#0"; "MSADODC.OCX"
Object = "{F0D2F211-CCB0-11D0-A316-00AA00688B10}#1.0#0"; "MSDATLST.OCX"
Begin VB.Form frmUsuario 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Usuario"
   ClientHeight    =   3345
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   7170
   Icon            =   "frmUsuario.frx":0000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   3345
   ScaleWidth      =   7170
   StartUpPosition =   2  'CenterScreen
   Begin VB.Frame fraUsuario 
      Height          =   2655
      Left            =   120
      TabIndex        =   16
      Top             =   120
      Width           =   6975
      Begin VB.Frame fraActivo 
         Height          =   1455
         Left            =   5280
         TabIndex        =   17
         Top             =   120
         Width           =   1575
         Begin VB.OptionButton optActivo 
            Caption         =   "Activo"
            Height          =   255
            Index           =   1
            Left            =   240
            TabIndex        =   13
            Top             =   840
            Width           =   1215
         End
         Begin VB.OptionButton optActivo 
            Caption         =   "Inactivo"
            Height          =   255
            Index           =   0
            Left            =   240
            TabIndex        =   12
            Top             =   480
            Width           =   1215
         End
      End
      Begin VB.TextBox txtNombres 
         Height          =   315
         Left            =   2040
         MaxLength       =   50
         TabIndex        =   11
         Top             =   2040
         Width           =   4815
      End
      Begin VB.TextBox txtApellidos 
         Height          =   315
         Left            =   2040
         MaxLength       =   50
         TabIndex        =   9
         Top             =   1680
         Width           =   4815
      End
      Begin VB.TextBox txtReingresarPassword 
         Height          =   315
         IMEMode         =   3  'DISABLE
         Left            =   2040
         MaxLength       =   15
         PasswordChar    =   "*"
         TabIndex        =   5
         Top             =   960
         Width           =   3015
      End
      Begin VB.TextBox txtPassword 
         Height          =   315
         IMEMode         =   3  'DISABLE
         Left            =   2040
         MaxLength       =   15
         PasswordChar    =   "*"
         TabIndex        =   3
         Top             =   600
         Width           =   3015
      End
      Begin VB.TextBox txtUsuario 
         Height          =   315
         Left            =   2040
         MaxLength       =   15
         TabIndex        =   1
         Top             =   240
         Width           =   3015
      End
      Begin MSDataListLib.DataCombo dcbPerfil 
         Bindings        =   "frmUsuario.frx":0442
         Height          =   315
         Left            =   2040
         TabIndex        =   7
         Top             =   1320
         Width           =   3015
         _ExtentX        =   5318
         _ExtentY        =   556
         _Version        =   393216
         Style           =   2
         ListField       =   "sPerfDesc"
         BoundColumn     =   "cPerfCode"
         Text            =   ""
      End
      Begin VB.Label lblLabels 
         Caption         =   "&Nombres"
         Height          =   375
         Index           =   5
         Left            =   240
         TabIndex        =   10
         Top             =   2160
         Width           =   1695
      End
      Begin VB.Label lblLabels 
         Caption         =   "Ape&llidos"
         Height          =   375
         Index           =   4
         Left            =   240
         TabIndex        =   8
         Top             =   1800
         Width           =   1695
      End
      Begin VB.Label lblLabels 
         Caption         =   "Per&fil"
         Height          =   375
         Index           =   3
         Left            =   240
         TabIndex        =   6
         Top             =   1440
         Width           =   1695
      End
      Begin VB.Label lblLabels 
         Caption         =   "&Reingresar Password"
         Height          =   375
         Index           =   2
         Left            =   240
         TabIndex        =   4
         Top             =   1080
         Width           =   1695
      End
      Begin VB.Label lblLabels 
         Caption         =   "&Usuario"
         Height          =   375
         Index           =   0
         Left            =   240
         TabIndex        =   0
         Top             =   360
         Width           =   1455
      End
      Begin VB.Label lblLabels 
         Caption         =   "&Password"
         Height          =   375
         Index           =   1
         Left            =   240
         TabIndex        =   2
         Top             =   720
         Width           =   1455
      End
   End
   Begin VB.CommandButton cmdEstandar 
      Caption         =   "&Aceptar"
      Default         =   -1  'True
      Height          =   375
      Index           =   0
      Left            =   4320
      TabIndex        =   14
      Top             =   2880
      Width           =   1335
   End
   Begin VB.CommandButton cmdEstandar 
      Cancel          =   -1  'True
      Caption         =   "&Cancelar"
      Height          =   375
      Index           =   1
      Left            =   5760
      TabIndex        =   15
      Top             =   2880
      Width           =   1335
   End
   Begin MSAdodcLib.Adodc adoPerfil 
      Height          =   330
      Left            =   1920
      Top             =   3000
      Visible         =   0   'False
      Width           =   1200
      _ExtentX        =   2117
      _ExtentY        =   582
      ConnectMode     =   0
      CursorLocation  =   3
      IsolationLevel  =   -1
      ConnectionTimeout=   15
      CommandTimeout  =   30
      CursorType      =   3
      LockType        =   3
      CommandType     =   8
      CursorOptions   =   0
      CacheSize       =   50
      MaxRecords      =   0
      BOFAction       =   0
      EOFAction       =   0
      ConnectStringType=   1
      Appearance      =   1
      BackColor       =   -2147483643
      ForeColor       =   -2147483640
      Orientation     =   0
      Enabled         =   -1
      Connect         =   ""
      OLEDBString     =   ""
      OLEDBFile       =   ""
      DataSourceName  =   ""
      OtherAttributes =   ""
      UserName        =   ""
      Password        =   ""
      RecordSource    =   ""
      Caption         =   "Adodc1"
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      _Version        =   393216
   End
End
Attribute VB_Name = "frmUsuario"
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
  
  LlenarCombo
  InicializarForm
  
  Screen.MousePointer = vbDefault
  
  Exit Sub
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation
  Screen.MousePointer = vbDefault

End Sub

Private Sub LlenarCombo()

  'El combo es alimentado con la información de las tabla
  'Perfil
  
  On Error GoTo LineaError

  Dim sSQL As String
  
  sSQL = "SELECT * FROM Perfil"
  
  With adoPerfil
    .ConnectionString = kCONNECT_STRING + psRutaMdb
    .RecordSource = sSQL
    .Refresh
  End With
  
  If Not adoPerfil.Recordset.EOF And iEditar = kCMD_NUEVO Then
    dcbPerfil.BoundText = adoPerfil.Recordset!cPerfCode
  End If
  
  Exit Sub
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation
  
End Sub

Private Sub InicializarForm()

  'Inicializa Form según opción

  On Error GoTo LineaError

  Select Case iEditar
  
  Case kCMD_NUEVO
    Me.Caption = "Nuevo Usuario"
    optActivo(kSI).Value = True
  
  Case kCMD_EDITAR
    Me.Caption = "Editar Usuario"
    If iEditar = kCMD_EDITAR And frmUsuarioLista.lvwUsuario.SelectedItem.Text = psUsuario_Descripcion Then Call DeshabilitarControl(dcbPerfil, True)
    TraerData
    DeshabilitarControles False
  
  Case kCMD_BORRAR
    Me.Caption = "Borrar Usuario"
    TraerData
    DeshabilitarControles True
    
  Case kCMD_VER
    Me.Caption = "Usuario"
    TraerData
    DeshabilitarControles True
    
  End Select
  
  Exit Sub
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation

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 Usuario " + _
         "WHERE TRIM(sUserDesc) = TRIM('$')"
  sSQL = VBsprintf(sSQL, frmUsuarioLista.lvwUsuario.SelectedItem.Text)
  
  If oDBAdmin.EjecutarConsulta(ADOCnn, sSQL, ADORS) Then
  
    If Not ADORS.EOF Then
      
      txtUsuario.Text = LeerCampo(ADORS!sUserDesc)
      txtPassword.Text = LeerCampo(ADORS!sUserPass)
      txtReingresarPassword.Text = txtPassword.Text
      dcbPerfil.BoundText = LeerCampo(ADORS!cPerfCode)
      txtApellidos.Text = LeerCampo(ADORS!sUserApel)
      txtNombres.Text = LeerCampo(ADORS!sUserName)
      
      If LeerCampo(ADORS!cUserActi) <> kSI Then
        optActivo(kNO).Value = True
      Else
        optActivo(kSI).Value = True
      End If
      
    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(txtUsuario, True)
  
  If bTodoFlag Then
    Call DeshabilitarControl(txtPassword, True)
    Call DeshabilitarControl(txtReingresarPassword, True)
    Call DeshabilitarControl(dcbPerfil, True)
    Call DeshabilitarControl(txtApellidos, True)
    Call DeshabilitarControl(txtNombres, True)
    Call DeshabilitarControl(optActivo(kNO), False)
    Call DeshabilitarControl(optActivo(kSI), False)
  End If
  
  Exit Sub
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation
  
End Sub

Private Sub txtApellidos_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 txtNombres_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
    
        If psForm = kFORM_USUARIO_LISTA Then
    
          ActualizarLista
          frmUsuarioLista.ManejarControles
          Call frmUsuarioLista.lvwUsuario_Click
          
          If iEditar = kCMD_EDITAR And _
            psUsuario_Descripcion = Trim(txtUsuario.Text) And psUsuario_Password <> Trim(txtPassword.Text) Then
            psUsuario_Password = Trim(txtPassword.Text)
          End If
          
        End If
        
        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
  
  If Trim(txtUsuario.Text) = "" Then
    MsgBox "Ingresar Nombre de Usuario", vbOKOnly + vbInformation
    txtUsuario.SetFocus
    Exit Function
  End If
  
  If Trim(txtPassword.Text) <> "" And Trim(txtReingresarPassword.Text) = "" Then
    MsgBox "Reingresar Password de Usuario", vbOKOnly + vbInformation
    txtReingresarPassword.SetFocus
    Exit Function
  End If
  
  If Trim(txtPassword.Text) <> Trim(txtReingresarPassword.Text) Then
    MsgBox "Password reingresado incorrecto", vbOKOnly + vbInformation
    txtReingresarPassword.SetFocus
    Exit Function
  End If
  
  If Trim(dcbPerfil.BoundText) = "" Then
    MsgBox "Seleccionar Perfil", vbOKOnly + vbInformation
    dcbPerfil.SetFocus
    Exit Function
  End If
  
  If Trim(txtApellidos.Text) = "" Then
    MsgBox "Ingresar Apellidos", vbOKOnly + vbInformation
    txtApellidos.SetFocus
    Exit Function
  End If
  
  If Trim(txtNombres.Text) = "" Then
    MsgBox "Ingresar Nombres", vbOKOnly + vbInformation
    txtApellidos.SetFocus
    Exit Function
  End If
  
  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 Usuario (sUserDesc, sUserPass, cPerfCode, sUserApel, sUserName, cUserActi) " + _
           "VALUES ('$', '$', $, '$', '$', $)"
    sSQL = VBsprintf(sSQL, ReemplazarComilla(Trim(txtUsuario.Text)), _
           ReemplazarComilla(Trim(txtPassword.Text)), _
           dcbPerfil.BoundText, _
           ReemplazarComilla(Trim(txtApellidos.Text)), _
           ReemplazarComilla(Trim(txtNombres.Text)), _
           IIf(optActivo(kSI).Value, kSI, kNO))
  
  Case kCMD_EDITAR
  
    sSQL = "UPDATE Usuario SET sUserPass = '$', " + _
           "cPerfCode = $, sUserApel = '$', sUserName = '$', cUserActi = $ " + _
           "WHERE TRIM(sUserDesc) = TRIM('$')"
    sSQL = VBsprintf(sSQL, ReemplazarComilla(Trim(txtPassword.Text)), _
           dcbPerfil.BoundText, _
           Trim(txtApellidos.Text), _
           Trim(txtNombres.Text), _
           IIf(optActivo(kSI).Value, kSI, kNO), _
           Trim(txtUsuario.Text))
  
  Case kCMD_BORRAR
  
    sSQL = "DELETE * FROM Usuario " + _
           "WHERE TRIM(sUserDesc) = TRIM('$')"
    sSQL = VBsprintf(sSQL, Trim(txtUsuario.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 = frmUsuarioLista.lvwUsuario.ListItems.Add(, , Trim(txtUsuario.Text))
    Else
      Set itemX = frmUsuarioLista.lvwUsuario.SelectedItem
      itemX.Text = Trim(txtUsuario.Text)
    End If
    
    itemX.SubItems(1) = dcbPerfil.Text
    itemX.SubItems(2) = Trim(txtApellidos.Text) + " " + Trim(txtNombres.Text)
    
    If optActivo(kSI).Value Then
      itemX.Icon = 1
      itemX.SmallIcon = 1
    Else
      itemX.Icon = 2
      itemX.SmallIcon = 2
    End If
    
    itemX.Selected = True
    
  Case kCMD_BORRAR
  
    frmUsuarioLista.lvwUsuario.ListItems.Remove (frmUsuarioLista.lvwUsuario.SelectedItem.Index)
    
  End Select
      
  Exit Sub
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation
  
End Sub
