VERSION 5.00
Begin VB.Form frmLogin 
   BackColor       =   &H80000005&
   BorderStyle     =   0  'None
   Caption         =   "Inicio de sesión"
   ClientHeight    =   6180
   ClientLeft      =   2790
   ClientTop       =   3150
   ClientWidth     =   7230
   Icon            =   "frmLogin.frx":0000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   Moveable        =   0   'False
   Picture         =   "frmLogin.frx":2A8B2
   ScaleHeight     =   3651.348
   ScaleMode       =   0  'User
   ScaleWidth      =   6788.579
   ShowInTaskbar   =   0   'False
   StartUpPosition =   2  'CenterScreen
   Begin VB.Frame Frame1 
      BackColor       =   &H00FFFFFF&
      Height          =   6675
      Left            =   0
      TabIndex        =   0
      Top             =   0
      Width           =   7815
      Begin VB.ComboBox cmb_colegio 
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   330
         Left            =   2520
         TabIndex        =   8
         Top             =   4440
         Width           =   2340
      End
      Begin VB.CommandButton cmdCancel 
         Cancel          =   -1  'True
         Caption         =   "Cancelar"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   390
         Left            =   5505
         TabIndex        =   4
         Top             =   4320
         Width           =   1380
      End
      Begin VB.CommandButton cmdOK 
         Caption         =   "Aceptar"
         Default         =   -1  'True
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   390
         Left            =   5520
         TabIndex        =   3
         Top             =   3840
         Width           =   1380
      End
      Begin VB.TextBox txtPassword 
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   345
         IMEMode         =   3  'DISABLE
         Left            =   2520
         PasswordChar    =   "*"
         TabIndex        =   2
         Top             =   4080
         Width           =   2325
      End
      Begin VB.TextBox txtUserName 
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   345
         Left            =   2520
         TabIndex        =   1
         Top             =   3720
         Width           =   2325
      End
      Begin VB.Label Label3 
         BackColor       =   &H00FFFFFF&
         Caption         =   "Colegio"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   9.75
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H00000000&
         Height          =   255
         Left            =   5640
         TabIndex        =   7
         Top             =   2160
         Visible         =   0   'False
         Width           =   810
      End
      Begin VB.Label Label2 
         BackColor       =   &H00FFFFFF&
         Caption         =   "Password"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   9.75
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H00000000&
         Height          =   255
         Left            =   5640
         TabIndex        =   6
         Top             =   1560
         Visible         =   0   'False
         Width           =   930
      End
      Begin VB.Label Label1 
         AutoSize        =   -1  'True
         BackColor       =   &H80000003&
         Caption         =   "Usuario"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   9.75
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H00FFFFFF&
         Height          =   240
         Left            =   5760
         TabIndex        =   5
         Top             =   1080
         Visible         =   0   'False
         Width           =   660
      End
      Begin VB.Image imgLogo 
         Height          =   6180
         Left            =   0
         Picture         =   "frmLogin.frx":34D94
         Top             =   0
         Width           =   7230
      End
   End
End
Attribute VB_Name = "frmLogin"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'Option Explicit
'Public DerUsuario As String
Public LoginSucceeded As Boolean

Private Sub cmdCancel_Click()
    LoginSucceeded = False
    Unload Me
    End
End Sub

Private Sub cmdOK_Click()
On Error GoTo Controlerror:
    Dim Consulta As String
    Dim Privi As String
    Dim Veractual As String
    Dim Base As String
    Dim servidor2 As String
    
'    If base_inicio = "farfa_01" Or base_inicio = "farfa_02" Or base_inicio = "farfa_03" Or _
'        base_inicio = "maipu_01" Or base_inicio = "maipu_02" Or base_inicio = "maipu_03" Or
'   base_inicio = "linco_01" Or base_inicio = "linco_02" Or base_inicio = "linco_03" Or
    If base_inicio = "laflo_01" Or base_inicio = "laflo_02" Or base_inicio = "laflo_03" Or _
        base_inicio = "pudah_01" Or base_inicio = "pudah_02" Or base_inicio = "pudah_03" Or _
        base_inicio = "sanma_01" Or base_inicio = "sanma_02" Or base_inicio = "sanma_03" Or _
        base_inicio = "sanbe_01" Or base_inicio = "sanbe_02" Or base_inicio = "sanbe_03" Or _
        base_inicio = "huech_01" Or base_inicio = "huech_02" Or base_inicio = "huech_03" Then
        'base_inicio = "macul_01" Or base_inicio = "macul_02" Or base_inicio = "macul_03" Then
    Else
        MsgBox "Nombre de base de datos no valida", vbCritical
        Exit Sub
    End If
    
    
    varconecta = ConectarBD(conn, Servidor, base_inicio, "groot", PassBDLocal, True)
        
    servidor2 = Servidor
    
    Servidor = DevuelveCampo("cfg", "", "valor", "param like 'IP_%' and descripcion = '" & Trim(cmb_colegio.Text) & "'", conn)
    Base = DevuelveCampo("cfg", "", "agno", "param like 'IP_%' and descripcion = '" & Trim(cmb_colegio.Text) & "'", conn)
    
    conn.Close
        
    If Servidor = "" Then
        
    Select Case (base_inicio)
'    Case "farfa_02", "farfa_03":
'        Base = base_inicio
'        Servidor = servidor2
'    Case "maipu_02", "maipu_03":
'        Base = base_inicio
'        Servidor = servidor2
    Case "laflo_02", "laflo_03":
        Base = base_inicio
        Servidor = servidor2
    Case "pudah_02", "pudah_03":
        Base = base_inicio
        Servidor = servidor2
'    Case "linco_02", "linco_03":
'        Base = base_inicio
'        Servidor = servidor2
    Case "sanma_02", "sanma_03":
        Base = base_inicio
        Servidor = servidor2
    Case "sanbe_02", "sanbe_03":
        Base = base_inicio
        Servidor = servidor2
    Case "huech_02", "huech_03":
        Base = base_inicio
        Servidor = servidor2
'    Case "macul_02", "macul_03":
'        Base = base_inicio
'        Servidor = servidor2
    Case Else:
        Servidor = "NO"
    End Select
      
    End If
    
    
    If Servidor = "NO" Then
        MsgBox "Base de datos no es valida", vbInformation
        Exit Sub
    End If
    
    varconecta = ConectarBD(conn, Servidor, Base, "groot", PassBDLocal, True)
    If varconecta Then
            AnnoIni = DevuelveCampo("cfg", "", "valor", "param = 'ANNO'", conn)
            Anno = AnnoIni
            PerEscIni = DevuelveCampo("cfg", "", "valor", "param = 'PerEscIni' and agno = " & Anno, conn)
            PerEscFin = DevuelveCampo("cfg", "", "valor", "param = 'PerEscFin' and agno = " & Anno, conn)
            PostIni = DevuelveCampo("cfg", "", "valor", "param = 'PostIni' and agno = " & Anno, conn)
            CODBC = DevuelveCampo("cfg", "", "valor", "param = 'CODBC'", conn)
            CODPK = DevuelveCampo("cfg", "", "valor", "param = 'CODPK'", conn)
            CODCO = DevuelveCampo("cfg", "", "valor", "param = 'CODCO'", conn)
    Else
        MsgBox "se produjo un error al conectar"
        Unload Me
        Exit Sub
    End If
    
    conn.Execute "UPDATE fnza_cheques_recibidos SET estado_chq='clda' WHERE estado_chq='cart' AND chq_fecha<current_date;"
    conn.Execute "UPDATE matriculas SET confirmado = 'NO' WHERE anno_mat = 2017 AND confirmado = 'SI' AND ind_beca = 1 AND fec_mat_r IS NULL"
    conn.Execute "UPDATE matriculas SET confirmado = 'NO' WHERE anno_mat = 2017 AND confirmado = 'SI' AND fec_mat_r IS NULL"
    conn.Execute "UPDATE matriculas SET confirmado = 'NO' WHERE anno_mat = 2018 AND confirmado = 'SI' AND ind_beca = 1 AND fec_mat_r IS NULL"
    conn.Execute "UPDATE matriculas SET confirmado = 'NO' WHERE anno_mat = 2018 AND confirmado = 'SI' AND fec_mat_r IS NULL"
    conn.Execute "UPDATE postulantes SET est_pad = 'Casados', alu_viv_con = 'Los Padres', grupo_viv_en = 'Casa',ing_fam = '1000' ,sit_cas = 'Propia' WHERE est_pad = '' AND grupo_viv_en = '' AND sit_cas = ''"
    conn.Execute "UPDATE postulantes SET ciudad_ext = 269413 WHERE ciudad_ext = '';"
    conn.Execute "UPDATE postulantes SET pais_ext = 'B9' WHERE pais_ext = '';"
        
    If Len(Trim(txtUserName)) <> 0 Then
        If Len(Trim(txtPassword)) <> 0 Then
            LoginSucceeded = False
             Consulta = "SELECT * FROM usuarios where aut_nombre_usuario = " & "'" & txtUserName & "' LIMIT 1;"
            Set rs_Usu = New ADODB.Recordset
            rs_Usu.CursorLocation = adUseClient
            rs_Usu.Open Consulta, conn
            If Not rs_Usu.EOF Then
                If txtPassword = rs_Usu("pas_usu") Then
                    DerFinanzas = IIf(rs_Usu("Finanzas") = 1, True, False)
                    DerUsuario = rs_Usu("priv_usu")
                    LoginSucceeded = True
                    Nom_usu_ses = Me.txtUserName.Text
                    Nom_com_usu_ses = rs_Usu("nombre_completo_usu")
                    Pas_usu_ses = rs_Usu("pas_usu")
                    'modificado 12-03-2022 por jvv
                    'Form_main.lbl_nom_com_usu_ses.Caption = "Usuario: " & Nom_com_usu_ses
                    Form_main.lbl_nom_com_usu_ses.Caption = Nom_com_usu_ses
                    
                    instalacion = DevuelveCampo("instalacion", "", "NUM_INSTAL", "NUM_INSTAL <> ''", conn)
                    'Form_main.Caption = "GesCol " & "Versión " & App.Major & "." & App.Minor & "." & App.Revision & " - Conectado a BD :" & Base & " en " & Servidor
                    Form_main.Caption = "GesCol " & "Versión " & App.Major & "." & App.Minor & "." & instalacion & " - Conectado a BD :" & Base & " en " & Servidor
                    Unload Me
                    Call menuhabilitado(True)
                    RutGlobal = Nom_usu_ses
                    If CodPerfil = "" Then CodPerfil = Right(rs_Usu("cargo_usu"), 5)
                Else
                    MsgBox "La contraseña no es válida. Vuelva a intentarlo", , "Inicio de sesión"
                    txtPassword.SetFocus
                    SendKeys "{Home}+{End}"
                End If
            Else
                MsgBox "El Nombre de Usuario no es valido para el sistema. Vuelva a intentarlo", , "Inicio de sesión"
                Me.txtUserName.SetFocus
                SendKeys "{Home}+{End}"
            End If
            rs_Usu.Close
        Else
            MsgBox "La contraseña no puede ser un campo vacio. Vuelva a intentarlo", , "Inicio de sesión"
            Me.txtPassword.SetFocus
            SendKeys "{Home}+{End}"
        End If
    Else
        MsgBox "El Nombre de Usuario no puede estar vacio. Vuelva a intentarlo", , "Inicio de sesión"
        Me.txtUserName.SetFocus
        SendKeys "{Home}+{End}"
    End If
    
    'actualizo los no confirmados.
    'conn.Execute "UPDATE matriculas SET fec_mat=date_format(current_date,'%Y-%m-%d') WHERE anno_mat=date_format(current_date,'%Y') AND confirmado='NO';"
    ' y los sin curso
    'conn.Execute "UPDATE matriculas as mat, (SELECT m.ci_alu, m.anno_mat, m.fec_mat FROM matriculas AS m LEFT JOIN alu_x_cur AS c ON m.ci_alu=c.ci_alu AND m.anno_mat=c.agno AND c.activo_alu=m.activo_alu WHERE m.anno_mat=date_format(current_date,'%Y') AND m.confirmado='SI'  AND m.activo_alu='SI' AND c.ci_alu is null) as d SET mat.fec_mat=date_format(current_date,'%Y-%m-%d') WHERE mat.ci_alu=d.ci_alu AND mat.anno_mat=d.anno_mat;"
    
    Exit Sub
Controlerror:
    MsgBox "Error de Conexión.", vbCritical + vbOKOnly, "ERROR"
    MsgBox "Error Número :" & Err.Number & vbCrLf & vbCrLf & "Descripción del Error: " & Err.Description & vbCrLf & vbCrLf & "Fuente del Error: " & Err.Source & vbCrLf & vbCrLf & Format(Date, "dd-mm-yyyy") & " " & Format(Time, "H:mm:ss"), vbCritical + vbOKOnly, "ERROR"
End Sub

Private Sub Form_Activate()
'Dim Col As ADODB.Recordset
'Set Col = New ADODB.Recordset
'Col.Open "select * from cfg where param like 'IP_%';", conn
'Me.txtUserName = ""
'Me.txtPassword = ""
'While Not Col.EOF
'    If Servidor = Col!valor Then
'        cmb_colegio.Text = Col!descripcion
'    End If
'    cmb_colegio.AddItem Col!descripcion
'    Col.MoveNext
'Wend
'conn.Close
'Set conn = Nothing

'    If Servidor = Col!valor Then
'        cmb_colegio.Text = Col!descripcion
'    End If
    
    'if base_inicio = "base"
    
    Select Case (base_inicio)
    'Case ("farfa_01"):
     '   cmb_colegio.Text = "Boston Farfana"
    'Case ("maipu_01"):
     '   cmb_colegio.Text = "Boston Maipú"
    Case ("laflo_01"):
        cmb_colegio.Text = "Lincoln Florida"
    Case ("pudah_01"):
        cmb_colegio.Text = "Lincoln Pudahuel"
    'Case ("linco_01"):
     '   cmb_colegio.Text = "Lincoln College"
    Case ("sanma_01"):
        cmb_colegio.Text = "Lincoln San Martín"
    Case ("sanbe_01"):
        cmb_colegio.Text = "Lincoln San Bernardo"
    Case ("huech_01"):
        cmb_colegio.Text = "Lincoln Huechuraba"
    'Case ("macul_01"):
     '   cmb_colegio.Text = "Boston Alto Macul"
    Case Else:
        cmb_colegio.Text = "Prueba de BD"
    End Select
    
    'cmb_colegio.AddItem "Boston Alto Macul"
    'cmb_colegio.AddItem "Boston Farfana"
    cmb_colegio.AddItem "Lincoln Florida"
    cmb_colegio.AddItem "Lincoln Huechuraba"
    'cmb_colegio.AddItem "Lincoln College"
    'cmb_colegio.AddItem "Boston Maipú"
    cmb_colegio.AddItem "Lincoln Pudahuel"
    cmb_colegio.AddItem "Lincoln San Martín"
    cmb_colegio.AddItem "Lincoln San Bernardo"

End Sub

Private Sub Form_KeyPress(KeyAscii As Integer)
KeyAscii = Asc(UCase(Chr(KeyAscii)))
End Sub

Private Sub Form_Load()
    frmLogin.KeyPreview = True
    'Me.LblVersion = "Versión " & App.Major & "." & App.Minor & "." & App.Revision
End Sub

