VERSION 5.00
Object = "{86CF1D34-0C5F-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCT2.OCX"
Object = "{00025600-0000-0000-C000-000000000046}#5.2#0"; "crystl32.ocx"
Begin VB.Form fmaestrousuarios 
   AutoRedraw      =   -1  'True
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Maestro Usuarios (96.010.00)"
   ClientHeight    =   4440
   ClientLeft      =   555
   ClientTop       =   495
   ClientWidth     =   5940
   MaxButton       =   0   'False
   MDIChild        =   -1  'True
   ScaleHeight     =   4440
   ScaleWidth      =   5940
   Begin VB.CheckBox Chk_activo 
      Height          =   195
      Left            =   1650
      TabIndex        =   18
      Top             =   2280
      Width           =   315
   End
   Begin MSComCtl2.DTPicker dt_expiracion 
      Height          =   375
      Left            =   4440
      TabIndex        =   17
      Top             =   2160
      Visible         =   0   'False
      Width           =   1335
      _ExtentX        =   2355
      _ExtentY        =   661
      _Version        =   393216
      CustomFormat    =   "dd/MM/yyyy"
      Format          =   61276163
      CurrentDate     =   37543
   End
   Begin Crystal.CrystalReport CR1 
      Left            =   4560
      Top             =   3000
      _ExtentX        =   741
      _ExtentY        =   741
      _Version        =   348160
      PrintFileLinesPerPage=   60
   End
   Begin VB.CommandButton cmd_derechos 
      Caption         =   "Derechos"
      Enabled         =   0   'False
      Height          =   855
      Left            =   3120
      Picture         =   "CF9601000.frx":0000
      Style           =   1  'Graphical
      TabIndex        =   14
      Top             =   3480
      Width           =   1575
   End
   Begin VB.CommandButton cmd_grupos 
      Caption         =   "Grupos"
      Enabled         =   0   'False
      Height          =   855
      Left            =   1320
      Picture         =   "CF9601000.frx":030A
      Style           =   1  'Graphical
      TabIndex        =   13
      Top             =   3480
      Width           =   1575
   End
   Begin VB.CommandButton cmd_buscar 
      Enabled         =   0   'False
      Height          =   375
      Left            =   5160
      Picture         =   "CF9601000.frx":0614
      Style           =   1  'Graphical
      TabIndex        =   12
      Top             =   360
      Width           =   495
   End
   Begin VB.TextBox txtphone 
      Height          =   285
      Left            =   1650
      TabIndex        =   3
      Top             =   1080
      Width           =   3375
   End
   Begin VB.TextBox txtpassword 
      Height          =   285
      IMEMode         =   3  'DISABLE
      Left            =   1650
      PasswordChar    =   "*"
      TabIndex        =   6
      Top             =   2640
      Width           =   1980
   End
   Begin VB.TextBox txtlocation 
      Height          =   285
      Left            =   1650
      TabIndex        =   4
      Top             =   1440
      Width           =   3375
   End
   Begin VB.TextBox txtemailaddress 
      Height          =   285
      Left            =   1650
      TabIndex        =   5
      Top             =   1800
      Width           =   3375
   End
   Begin VB.TextBox txtusername 
      Height          =   285
      Left            =   1650
      TabIndex        =   2
      Top             =   720
      Width           =   3375
   End
   Begin VB.TextBox txtuserid 
      Height          =   285
      Left            =   1650
      TabIndex        =   1
      Top             =   360
      Width           =   3405
   End
   Begin VB.Label lblFieldLabel 
      Alignment       =   1  'Right Justify
      AutoSize        =   -1  'True
      Caption         =   "Activo:"
      Height          =   195
      Index           =   7
      Left            =   360
      TabIndex        =   16
      Top             =   2280
      Width           =   495
   End
   Begin VB.Label lblFieldLabel 
      Alignment       =   1  'Right Justify
      AutoSize        =   -1  'True
      Caption         =   "Fecha Expiracion"
      Height          =   195
      Index           =   6
      Left            =   3120
      TabIndex        =   15
      Top             =   2280
      Visible         =   0   'False
      Width           =   1230
   End
   Begin VB.Label lblFieldLabel 
      Alignment       =   1  'Right Justify
      AutoSize        =   -1  'True
      Caption         =   "Telefono:"
      Height          =   195
      Index           =   5
      Left            =   360
      TabIndex        =   11
      Top             =   1080
      Width           =   675
   End
   Begin VB.Label lblFieldLabel 
      AutoSize        =   -1  'True
      Caption         =   "password:"
      Height          =   255
      Index           =   4
      Left            =   360
      TabIndex        =   10
      Top             =   2640
      Width           =   1095
   End
   Begin VB.Label lblFieldLabel 
      Alignment       =   1  'Right Justify
      AutoSize        =   -1  'True
      Caption         =   "Localizacion:"
      Height          =   195
      Index           =   3
      Left            =   360
      TabIndex        =   9
      Top             =   1440
      Width           =   930
   End
   Begin VB.Label lblFieldLabel 
      Alignment       =   1  'Right Justify
      AutoSize        =   -1  'True
      Caption         =   "Direccion Email:"
      Height          =   195
      Index           =   2
      Left            =   360
      TabIndex        =   8
      Top             =   1800
      Width           =   1140
   End
   Begin VB.Label lblFieldLabel 
      Alignment       =   1  'Right Justify
      AutoSize        =   -1  'True
      Caption         =   "Nombre:"
      Height          =   195
      Index           =   1
      Left            =   360
      TabIndex        =   7
      Top             =   720
      Width           =   600
   End
   Begin VB.Label lblFieldLabel 
      Alignment       =   1  'Right Justify
      AutoSize        =   -1  'True
      Caption         =   "Id Usuario:"
      Height          =   195
      Index           =   0
      Left            =   390
      TabIndex        =   0
      Top             =   360
      Width           =   765
   End
End
Attribute VB_Name = "fmaestrousuarios"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'plantilla para formularios maestro de inventario
' fecha ultima modificacion 6/9/2000 9:7 am
' modificaciones
' agregar pbderechhos
' eliminar recordset prderechos
' mover llamada de seguridad al inicio del evento load
'1 cambios en el evento load
'2 cambios en el evento activate, mover llamada a gactualizaropcion al inicio
'1 cambios en el evento queryunload

' se agrego Call asigna_campos en el evento borrar registros

'se agrego el evento imprimir para llamar un reporte por defecto
'se agrego la variable pbderecho_imprimir

' fecha ultima modificacion 5/11/2002 9:07 am
' se agrego la varible pb_tiposcreen
Option Explicit
'REFERENCIAS COMPONENTES
Public mobj_cusuario As DB_SE_MANTENIMIENTOS.C_USUARIO

Public pb_editar As Boolean
Public pb_agregar As Boolean
Public pb_primerregistro As Boolean
Public pb_ultimoregistro As Boolean
Public pbderecho_agregar As Boolean
Public pbderecho_consultar As Boolean
Public pbderecho_editar As Boolean
Public pbderecho_borrar As Boolean
Public pbderecho_imprimir As Boolean
Public pb_tiposcreen As String

Public rs_usuarios As ADODB.Recordset
Public GrecibeUbicacion As BookmarkEnum
Public GrecibeColumnaID As String
Dim mobj_cseguridad As DB_SE_MANTENIMIENTOS.c_seguridad

Private Sub Chk_activo_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Then
        txtpassword.SetFocus
    End If
End Sub

Private Sub cmd_buscar_Click()
'Lineas que llaman al Formulario de Búsqueda
  
  Dim ArrayBusqueda(1 To 2, 1 To 3) As Variant
  ArrayBusqueda(1, 1) = "userid"
  ArrayBusqueda(1, 2) = "ID Usuario"
  ArrayBusqueda(1, 3) = 1000
  
  ArrayBusqueda(2, 1) = "Username"
  ArrayBusqueda(2, 2) = "Nombre Usuario"
  ArrayBusqueda(2, 3) = 6000

  FBusquedasInv.GObtenerRegistros rs_usuarios, ArrayBusqueda, 2, 2
  FBusquedasInv.Show vbModal
  
  If GrecibeUbicacion <> 0 Then
   rs_usuarios.AbsolutePosition = GrecibeUbicacion
    Call asigna_campos
    Call gestadoactualrs(Me, rs_usuarios)
    Call gactualiza_barra(Me) 'pb_editar, pb_primerregistro, pb_ultimoregistro)
  End If

End Sub

Private Sub CMD_DERECHOS_Click()
 fderechosusuariosgrupos.txt_type.Text = "Usuario"
 fderechosusuariosgrupos.TXT_ID.Text = txtuserid.Text
 fderechosusuariosgrupos.TXT_NOMBRE.Text = txtusername.Text
 fderechosusuariosgrupos.Top = Me.Top + 2000
 fderechosusuariosgrupos.Left = Me.Left + 2000
 fderechosusuariosgrupos.Show (vbModal)

End Sub

Private Sub cmd_grupos_Click()
fusuarios_grupos.TXT_ID.Text = txtuserid.Text
fusuarios_grupos.TXT_NOMBRE.Text = txtusername.Text
fusuarios_grupos.Top = Me.Top + 2000
fusuarios_grupos.Left = Me.Left + 2000
fusuarios_grupos.Show (vbModal)
End Sub

Private Sub dt_expiracion_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = 13 Then
       Chk_activo.SetFocus
    End If
End Sub

Private Sub Form_Activate()
Call gactualizaopcion(pbderecho_agregar, pbderecho_editar, pbderecho_borrar, pbderecho_imprimir)
Call gactualiza_barra(Me)
'Call gactualiza_barra(pb_editar, pb_primerregistro, pb_ultimoregistro)
'lineas nuevas
If pbderecho_consultar = False Then
    Unload Me
End If
End Sub
Public Sub primer_registro()
Call Gprimer_registro(Me, rs_usuarios)
Call asigna_campos
End Sub
Public Sub ultimo_registro()
Call Gultimo_registro(Me, rs_usuarios)
Call asigna_campos
End Sub
Public Sub registro_anterior()
Call Gregistro_anterior(Me, rs_usuarios)
Call asigna_campos
End Sub
Public Sub registro_siguiente()
Call Gregistro_siguiente(Me, rs_usuarios)
Call asigna_campos
End Sub
Private Sub Form_Initialize()
Call gHabilitarReg(Me, False)
End Sub
Private Sub Form_Load()
'seguridad
Set mobj_cusuario = New DB_SE_MANTENIMIENTOS.C_USUARIO
Set mobj_cseguridad = New DB_SE_MANTENIMIENTOS.c_seguridad
Call gseguridad(Me)
If pbderecho_consultar Then
    Set mobj_cusuario = New DB_SE_MANTENIMIENTOS.C_USUARIO
    Dim numreg As Long
    Call obtener_datos
    Call asigna_campos
    pb_primerregistro = True
'lineas nuevas
Else
    'Unload Me
    MsgBox ("No tiene Derechos de Consultar en este formulario")
End If

 Me.Top = 100
 Me.Left = (Screen.Width - Me.Width) / 2
End Sub
Public Sub borrar_registro()

On Error GoTo errhandler
 
 mobj_cusuario.EliminarUsuario txtuserid.Text
 'rs_usuarios.Requery
 Call obtener_datos
 Call gborrar_Registro(Me, rs_usuarios, txtuserid)
 Call asigna_campos

Exit Sub
errhandler:
    MsgBox MensajedeError(Err.Number, Err.Description), vbDefaultButton1 + vbCritical, "Advertencia"

End Sub
Function valida_datos()

txtuserid.Text = GVDATO(txtuserid.Text)
txtusername.Text = GVDATO(txtusername.Text)
txtemailaddress.Text = GVDATO(txtemailaddress.Text)
txtlocation.Text = GVDATO(txtlocation.Text)
txtphone.Text = GVDATO(txtphone.Text)
txtpassword.Text = GVDATO(txtpassword.Text)

If Len(txtuserid.Text) = 0 Then
    valida_datos = False
    MsgBox "Debe ingresar un Id Usuario", vbInformation, "Error"
    txtuserid.SetFocus
    Exit Function
End If
If Len(txtusername.Text) = 0 Then
    valida_datos = False
    MsgBox "Debe especificar un Nombre de Usuario", vbInformation, "Error"
    txtusername.SetFocus
    Exit Function
End If
If Len(txtpassword.Text) = 0 Then
    valida_datos = False
    MsgBox "Falta Ingresar Password", vbInformation, "Error"
    txtpassword.SetFocus
    Exit Function
End If
If Len(txtlocation.Text) = 0 Then
    valida_datos = False
    MsgBox "Falta Ingresar localizacion", vbInformation, "Error"
    txtlocation.SetFocus
    Exit Function
End If


'If UCase(Trim(GCUSERID)) = "SYSADMIN" Then
'    valida_datos = True
'Else
    Dim LstrValidapassword As String
    LstrValidapassword = GValidaPassword(txtuserid.Text, Trim(txtpassword.Text))
    
    If LstrValidapassword <> "T" Then
        valida_datos = False
        Exit Function
    End If
'End If

valida_datos = True
End Function
Public Sub grabar_registro()

Dim LINT_EXISTE As Integer
Dim LSTR_USUARIO As String
Dim Larray(1, 4) As Variant

On Error GoTo errhandler

If valida_datos() = True Then
    ' llamada al proc de grabacion
    If pb_agregar Then
        LSTR_USUARIO = txtuserid.Text
        If mobj_cusuario.existeUsuario(LSTR_USUARIO) Then
            MsgBox "codigo de Usuario ya Existe", vbExclamation, "Error"
            Exit Sub
        Else
            If Trim(GCUSERID) = "SYSADMIN" Then
               ' Hay que Utilizar un User para indicar que la clave es solo para 1 vez
               
               Larray(1, 1) = ""
               Larray(1, 2) = "T"
               Larray(1, 3) = 0
               Larray(1, 4) = 0
               mobj_cusuario.AgregarUsuario txtuserid.Text, txtusername.Text, txtemailaddress.Text, txtlocation.Text, Trim(Encrip(UCase(txtpassword.Text))), txtphone.Text, dt_expiracion.Value, IIf(Chk_activo.Value = 1, True, False), Larray
            Else
               Larray(1, 1) = ""
               Larray(1, 2) = ""
               Larray(1, 3) = 0
               Larray(1, 4) = 0
               mobj_cusuario.AgregarUsuario txtuserid.Text, txtusername.Text, txtemailaddress.Text, txtlocation.Text, Trim(Encrip(UCase(txtpassword.Text))), txtphone.Text, dt_expiracion.Value, IIf(Chk_activo.Value = 1, True, False), Larray
            End If
        End If
        
    Else
       If GCUSERID = "SYSADMIN" Then
          Larray(1, 1) = ""
          Larray(1, 2) = "T"
          Larray(1, 3) = 0
          Larray(1, 4) = 0
          mobj_cusuario.ActualizarUsuario txtuserid.Text, txtusername.Text, txtemailaddress.Text, txtlocation.Text, Trim(Encrip(UCase(txtpassword.Text))), txtphone.Text, dt_expiracion.Value, IIf(Chk_activo.Value = 1, True, False), Larray
       Else
          Larray(1, 1) = ""
          Larray(1, 2) = ""
          Larray(1, 3) = 0
          Larray(1, 4) = 0
          mobj_cusuario.ActualizarUsuario txtuserid.Text, txtusername.Text, txtemailaddress.Text, txtlocation.Text, Trim(Encrip(UCase(txtpassword.Text))), txtphone.Text, dt_expiracion.Value, IIf(Chk_activo.Value = 1, True, False), Larray
       End If
        
    End If
    
    pb_ultimoregistro = True
    Call ggrabar_registro(Me)
    Call actualizar_registro
End If

Exit Sub
errhandler:
    MsgBox MensajedeError(Err.Number, Err.Description), vbDefaultButton1 + vbCritical, "Advertencia"

End Sub
Public Sub actualizar_registro()
'llamar al procedimiento de carga
Call obtener_datos
Call asigna_campos
'MsgBox ("Registros Actualizados")
End Sub
Public Sub agregar_registro()
Call gagregar_registro(Me, txtuserid)
dt_expiracion.Value = Date
End Sub
Public Sub modificar_registro()
If Not rs_usuarios.EOF Then
    Call gmodificar_registro(Me, txtuserid)
End If
End Sub
Public Sub descartar_registro()
    ' Revertir cambios
    'adodc1.Recordset.CancelUpdate
    Call gdescartar_registro(Me)
    Call asigna_campos
End Sub
Sub obtener_datos()
Set rs_usuarios = New ADODB.Recordset
rs_usuarios.CursorLocation = adUseClient
Set rs_usuarios = mobj_cusuario.ListarUsuarios
rs_usuarios.MoveFirst
Call asigna_campos
pb_primerregistro = True
pb_ultimoregistro = False
End Sub

Sub salir_formulario()
' validar que no haya procesos pendientes
' si no hay problemas
MDIFconfiguracion.Toolbar1.Buttons(18).Caption = "Salir"    ' boton salir
Unload Me
End Sub

Sub asigna_campos() ' falta decidir si va ha ser public o private
If rs_usuarios.EOF Then
    txtuserid.Text = ""
    txtusername.Text = ""
    txtemailaddress.Text = ""
    txtlocation.Text = ""
    txtphone.Text = ""
    txtpassword.Text = ""
    Chk_activo.Value = False
Else
    txtuserid.Text = rs_usuarios!userid
    txtusername.Text = rs_usuarios!UserName
    txtemailaddress.Text = IIf(IsNull(rs_usuarios!emailaddress), "", rs_usuarios!emailaddress)
    txtlocation.Text = rs_usuarios!location
    txtphone.Text = IIf(IsNull(rs_usuarios!phone), "", rs_usuarios!phone)
    txtpassword.Text = Trim(Encrip(Trim(rs_usuarios!Password)))
    Chk_activo.Value = IIf(rs_usuarios!Status, 1, 0)
    dt_expiracion.Value = rs_usuarios!expired
    
End If
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
If pb_editar Then
    If MsgBox("Desea Cancelar los Cambios", vbYesNo, "Esta Modificando un registro") = vbNo Then
        Cancel = True
    Else
        Call gdesactiva_barra
    End If
Else
    Call gdesactiva_barra
End If
End Sub

Private Sub Form_Unload(Cancel As Integer)
Set rs_usuarios = Nothing
Set mobj_cseguridad = Nothing
End Sub

Public Sub imprimir()

End Sub

Private Sub txtemailaddress_KeyPress(KeyAscii As Integer)
    If KeyAscii = 39 Or KeyAscii = 124 Then
        KeyAscii = 0
    End If
    If KeyAscii = 13 Then
        dt_expiracion.SetFocus
    End If
End Sub

Private Sub txtlocation_KeyPress(KeyAscii As Integer)
    KeyAscii = GBloqueaCaracter(KeyAscii)
    If KeyAscii = 13 Then
        txtemailaddress.SetFocus
    End If
End Sub

Private Sub txtpassword_KeyPress(KeyAscii As Integer)
    KeyAscii = GBloqueaCaracter(KeyAscii)
End Sub

Private Sub txtphone_KeyPress(KeyAscii As Integer)
    KeyAscii = GBloqueaCaracter(KeyAscii)
    If KeyAscii = 13 Then
        txtlocation.SetFocus
    End If
End Sub

Private Sub txtuserid_KeyPress(KeyAscii As Integer)
    KeyAscii = GBloqueaCaracter(KeyAscii)
    If KeyAscii = 13 Then
        txtusername.SetFocus
    End If
End Sub

Private Sub txtusername_KeyPress(KeyAscii As Integer)
    KeyAscii = GBloqueaCaracter(KeyAscii)
    If KeyAscii = 13 Then
        txtphone.SetFocus
    End If
End Sub

