VERSION 5.00
Object = "{5E9E78A0-531B-11CF-91F6-C2863C385E30}#1.0#0"; "MSFLXGRD.OCX"
Object = "{86CF1D34-0C5F-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCT2.OCX"
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.2#0"; "MSCOMCTL.OCX"
Begin VB.Form Form_mant_alu_x_cur 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Mantencion de Alumnos por Curso"
   ClientHeight    =   7350
   ClientLeft      =   45
   ClientTop       =   435
   ClientWidth     =   9015
   Icon            =   "Form_mant_alu_x_cur.frx":0000
   MaxButton       =   0   'False
   MDIChild        =   -1  'True
   ScaleHeight     =   7350
   ScaleWidth      =   9015
   Begin VB.CommandButton Btn_carga_alumnos 
      Caption         =   "Car&gar alumnos"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   7200
      TabIndex        =   32
      Top             =   600
      Visible         =   0   'False
      Width           =   1455
   End
   Begin VB.Frame Frame_Man_alu_x_cur 
      Caption         =   "Asignación de alumnos matriculados a cursos"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00C00000&
      Height          =   7095
      Left            =   120
      TabIndex        =   0
      Top             =   120
      Visible         =   0   'False
      Width           =   8775
      Begin VB.CommandButton Btn_Alta_Alu 
         Caption         =   "Alta"
         Enabled         =   0   'False
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   375
         Left            =   7080
         TabIndex        =   33
         Top             =   4200
         Width           =   1455
      End
      Begin VB.ComboBox cmb_ano 
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   330
         Left            =   4680
         Style           =   2  'Dropdown List
         TabIndex        =   30
         Top             =   480
         Width           =   2175
      End
      Begin VB.ComboBox Cmb_niv_alu 
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   330
         Left            =   1440
         Style           =   2  'Dropdown List
         TabIndex        =   16
         ToolTipText     =   "Nivel"
         Top             =   840
         Width           =   1935
      End
      Begin VB.CommandButton Btn_agrega_alu 
         Caption         =   "Agregar"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   375
         Left            =   7080
         TabIndex        =   14
         Top             =   2760
         Width           =   1455
      End
      Begin VB.CommandButton Btn_quita_alu 
         Caption         =   "Quitar"
         Enabled         =   0   'False
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   375
         Left            =   7080
         TabIndex        =   13
         Top             =   2280
         Width           =   1455
      End
      Begin VB.ComboBox Cmb_let_cur 
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   330
         Left            =   1560
         Style           =   2  'Dropdown List
         TabIndex        =   12
         ToolTipText     =   "Letra del Curso"
         Top             =   3600
         Width           =   975
      End
      Begin VB.ComboBox Cmb_mod_alu 
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   330
         Left            =   1440
         Style           =   2  'Dropdown List
         TabIndex        =   11
         ToolTipText     =   "Modalidad"
         Top             =   480
         Width           =   1935
      End
      Begin VB.CommandButton Btn_Can_man_alu_x_cur 
         Caption         =   "Cerrar"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   375
         Left            =   7200
         TabIndex        =   10
         Top             =   6600
         Width           =   1455
      End
      Begin VB.TextBox Txt_Alu_Concurso 
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   285
         Left            =   2280
         Locked          =   -1  'True
         TabIndex        =   9
         Top             =   6600
         Width           =   495
      End
      Begin VB.TextBox Txt_Alu_sincurso 
         Height          =   285
         Left            =   2520
         TabIndex        =   8
         Top             =   1440
         Width           =   495
      End
      Begin VB.TextBox txt_vac_cur 
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   285
         Left            =   4920
         Locked          =   -1  'True
         TabIndex        =   7
         Top             =   6240
         Width           =   495
      End
      Begin VB.ComboBox cmb_jor_alu 
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   330
         ItemData        =   "Form_mant_alu_x_cur.frx":2A8B2
         Left            =   4680
         List            =   "Form_mant_alu_x_cur.frx":2A8B4
         TabIndex        =   6
         ToolTipText     =   "Nivel"
         Top             =   840
         Width           =   2175
      End
      Begin VB.TextBox txt_jornada_cur 
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   285
         Left            =   4200
         Locked          =   -1  'True
         TabIndex        =   5
         Top             =   3600
         Width           =   1815
      End
      Begin VB.TextBox txt_max_alu 
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   285
         Left            =   2280
         Locked          =   -1  'True
         TabIndex        =   4
         Top             =   6240
         Width           =   495
      End
      Begin VB.TextBox txt_exe_cur 
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   285
         Left            =   4920
         Locked          =   -1  'True
         TabIndex        =   3
         Top             =   6600
         Width           =   495
      End
      Begin VB.CommandButton BTN_correccion 
         Caption         =   "Corregir Numgra"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   375
         Left            =   7080
         TabIndex        =   2
         Top             =   960
         Visible         =   0   'False
         Width           =   1455
      End
      Begin MSComctlLib.ProgressBar Prg_Correc_Numgra 
         Height          =   255
         Left            =   2280
         TabIndex        =   1
         Top             =   5760
         Visible         =   0   'False
         Width           =   4575
         _ExtentX        =   8070
         _ExtentY        =   450
         _Version        =   393216
         Appearance      =   1
         Min             =   1e-4
         Scrolling       =   1
      End
      Begin MSFlexGridLib.MSFlexGrid Grd_alu_sincurso 
         Height          =   1575
         Left            =   240
         TabIndex        =   15
         Top             =   1920
         Width           =   6615
         _ExtentX        =   11668
         _ExtentY        =   2778
         _Version        =   393216
         Cols            =   4
         FixedCols       =   0
         FocusRect       =   0
         FillStyle       =   1
         SelectionMode   =   1
         AllowUserResizing=   1
         FormatString    =   "Apellido paterno     | Apellido materno     | Nombres                                 | R.U.N         "
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
      End
      Begin MSFlexGridLib.MSFlexGrid Grd_alu_concurso 
         Height          =   1575
         Left            =   240
         TabIndex        =   17
         Top             =   4200
         Width           =   6615
         _ExtentX        =   11668
         _ExtentY        =   2778
         _Version        =   393216
         Cols            =   4
         FixedCols       =   0
         FocusRect       =   0
         FillStyle       =   1
         SelectionMode   =   1
         FormatString    =   "Apellido paterno     | Apellido materno     | Nombres                                 | R.U.N         "
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
      End
      Begin MSComCtl2.DTPicker DTP_FechaAlta 
         Height          =   375
         Left            =   7080
         TabIndex        =   34
         Top             =   5160
         Width           =   1455
         _ExtentX        =   2566
         _ExtentY        =   661
         _Version        =   393216
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Format          =   91881473
         CurrentDate     =   40624
      End
      Begin VB.Label Label9 
         Alignment       =   2  'Center
         Caption         =   "Fecha de Alta"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   7080
         TabIndex        =   35
         Top             =   4800
         Width           =   1455
      End
      Begin VB.Label lbl_ano 
         Caption         =   "Año"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   3720
         TabIndex        =   31
         Top             =   480
         Width           =   975
      End
      Begin VB.Label Label1 
         Caption         =   "Alumnos en este Curso"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   360
         TabIndex        =   29
         Top             =   6600
         Width           =   1695
      End
      Begin VB.Label Label2 
         Caption         =   "Curso Actual"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   360
         TabIndex        =   28
         Top             =   5880
         Width           =   1215
      End
      Begin VB.Label Label3 
         Caption         =   "Modalidad"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   360
         TabIndex        =   27
         Top             =   480
         Width           =   975
      End
      Begin VB.Label Label4 
         Caption         =   "Nivel"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   360
         TabIndex        =   26
         Top             =   840
         Width           =   735
      End
      Begin VB.Label Label5 
         Alignment       =   1  'Right Justify
         Caption         =   "Letra Curso"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   240
         TabIndex        =   25
         Top             =   3600
         Width           =   1095
      End
      Begin VB.Label Label6 
         Caption         =   "Total Alumnos sin curso"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   360
         TabIndex        =   24
         Top             =   1440
         Width           =   1815
      End
      Begin VB.Label Label8 
         Caption         =   "Vacantes Actuales"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   3000
         TabIndex        =   23
         Top             =   6240
         Width           =   1575
      End
      Begin VB.Label Label14 
         Caption         =   "Jornada"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   3720
         TabIndex        =   22
         Top             =   840
         Width           =   735
      End
      Begin VB.Label lbl_curso_actual 
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   9.75
            Charset         =   0
            Weight          =   700
            Underline       =   -1  'True
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   1560
         TabIndex        =   21
         Top             =   5520
         Width           =   3615
      End
      Begin VB.Label Label7 
         Caption         =   "Vacantes Inicial"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   360
         TabIndex        =   20
         Top             =   6240
         Width           =   1575
      End
      Begin VB.Label Label16 
         Caption         =   "Excendentes"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   3000
         TabIndex        =   19
         Top             =   6600
         Width           =   1575
      End
      Begin VB.Label Label20 
         Alignment       =   1  'Right Justify
         Caption         =   "Jornada"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   3000
         TabIndex        =   18
         Top             =   3600
         Width           =   1095
      End
   End
End
Attribute VB_Name = "Form_mant_alu_x_cur"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
' Var del Form
Dim FechaDeAlta As Date
Dim EsAlta As Boolean
'

Private Sub Btn_agrega_alu_Click()
    'Procedimiento
    EsAlta = False
    FechaDeAlta = RetornaCampo("CFG", "date_format(current_date,'%Y-%m-%d') as Fecha", "1=1", conn)
    PoneAlumnoEnCurso
End Sub

Private Sub Btn_quita_alu_Click()
    Dim RECH As String
    RECH = RetornaCampo("CFG", "valor", "param='CodRegistroINI' and agno='" & Trim(cmb_ano.Text) & "'", conn)
    If RECH = "NO" Then
        QuitarAlumno
    Else
        MsgBox "No se pueden quitar alumnos de un curso debido a que " & vbCrLf & "el Registro Inicial ya fue hecho para este año de trabajo.", vbInformation, "Denegado"
    End If
End Sub

Private Sub cmb_ano_Click()
    Dim RECH As String
    If cmb_jor_alu.Text <> "" Then cmb_jor_alu_Click
        'Verifico si el Registro Inicial esta hecho.
    RECH = RetornaCampo("CFG", "valor", "param='CodRegistroINI' and agno='" & Trim(cmb_ano.Text) & "'", conn)
    If RECH = "SI" Then
        Btn_agrega_alu.Enabled = False
        Btn_quita_alu.Enabled = False
        Btn_Alta_Alu.Enabled = True
        DTP_FechaAlta.Enabled = True
        EsAlta = True
    Else
        Btn_agrega_alu.Enabled = True
        Btn_quita_alu.Enabled = True
        Btn_Alta_Alu.Enabled = False
        DTP_FechaAlta.Enabled = False
        EsAlta = False
    End If
End Sub

Private Sub Btn_Alta_alu_Click()
    'Procedimiento
    EsAlta = True
    FechaDeAlta = DTP_FechaAlta.Value
    RECH = RetornaCampo("CFG", "valor", "param='PerEscIni' and agno='" & Anno & "'", conn)
    If FechaDeAlta <= RECH Then
        MsgBox "La fecha del alta no puede ser menor o igual a la del registro inicial", vbInformation
        Exit Sub
    End If
    PoneAlumnoEnCurso
End Sub

Private Sub Form_Load()
    Dim RECH As String
    
    Txt_Alu_Concurso = 0
    txt_max_alu = 0
    txt_vac_cur = 0
    Frame_Man_alu_x_cur.Visible = True
    Call LlenaCombo(Cmb_mod_alu, "codigos_ensenanza", "des_ens", "order by ord_ens", conn)
    Call LlenaCombo(cmb_jor_alu, "jornadas", "des_jor", "order by des_jor", conn)
    
    cmb_ano.AddItem Anno
    cmb_ano.AddItem Anno + 1
    CentrarForma Me
    Txt_Alu_sincurso.Locked = True
    Txt_Alu_Concurso.Locked = True
    Cmb_niv_alu.Enabled = False
    Txt_Alu_Concurso.Enabled = False
    Grd_alu_concurso.Enabled = False
    Grd_alu_sincurso.Enabled = False
    Txt_Alu_sincurso.Enabled = False
    
    'La fecha de alta minima es el día de hoy.
    DTP_FechaAlta.MinDate = CDate(RetornaCampo("CFG", "date_format(valor,'%Y-%m-%d') as Fecha", "param = 'PerEscIni' and agno = '" & Anno & "'", conn))
    DTP_FechaAlta.Value = DTP_FechaAlta.MinDate
    DTP_FechaAlta.Value = Date
    
    'Verifico si el Registro Inicial esta hecho.
    RECH = RetornaCampo("CFG", "valor", "param='CodRegistroINI' and agno='" & Anno & "'", conn)
    If RECH = "SI" Then
        Btn_agrega_alu.Enabled = False
        Btn_quita_alu.Enabled = False
        Btn_Alta_Alu.Enabled = True
        DTP_FechaAlta.Enabled = True
        EsAlta = True
    Else
        Btn_agrega_alu.Enabled = True
        Btn_quita_alu.Enabled = True
        Btn_Alta_Alu.Enabled = False
        DTP_FechaAlta.Enabled = False
        EsAlta = False
    End If
    
End Sub

Private Sub PoneAlumnoEnCurso()
Dim objRS As ADODB.Recordset
Set objRS = New ADODB.Recordset
Dim var_sql As String

Dim iniCiclo, finCiclo As Integer
Dim FechaMatricula As Date
Dim ci_alu, Repitente As String
Dim AsigneCurso As Boolean
Dim RutSinCurso As String
Dim ApePat, ApeMat, nombre As String
Dim CodJornada As String
Dim NumAlta As Long
Dim swalta As Boolean
Dim curso, grado, accion_realizada As String
Dim log As Boolean

If CInt(cmb_ano.Text) < Year(Date) Then Exit Sub
If Me.Cmb_let_cur.Text <> "" Then
    AsigneCurso = False
    iniCiclo = 1
    finCiclo = 1
    
        CodModalidad = DevuelveCampo("codigos_ensenanza", "des_ens", "cod_ens", "des_ens = '" & Me.Cmb_mod_alu.Text & "'", conn)
        Ngrado = Me.Cmb_niv_alu.Text
        letra = Me.Cmb_let_cur.Text
        If Me.Grd_alu_sincurso.Row > Me.Grd_alu_sincurso.RowSel Then
            iniCiclo = Me.Grd_alu_sincurso.Row
            finCiclo = Me.Grd_alu_sincurso.RowSel
        ElseIf Me.Grd_alu_sincurso.RowSel > Me.Grd_alu_sincurso.Row Then
            iniCiclo = Me.Grd_alu_sincurso.RowSel
            finCiclo = Me.Grd_alu_sincurso.Row
        Else
            iniCiclo = Me.Grd_alu_sincurso.Row
            finCiclo = Me.Grd_alu_sincurso.RowSel
        End If
        AsigneCurso = True
        If ((iniCiclo - finCiclo) + 1) > val(Me.txt_vac_cur.Text) Then
            If MsgBox("Vacantes insuficientes para esta cantidad de alumnos" & Chr(13) & chr13 & Chr(13) & "Capacidad disponible en este curso : " & val(Me.txt_vac_cur) & Chr(13) & "Cantidad de excedentes después de la acción : " & ((iniCiclo - finCiclo) + 1) - val(Me.txt_vac_cur.Text) & Chr(13) & Chr(13) & "¿Desea continuar con ?", vbYesNo + vbQuestion) = vbYes Then
                AsigneCurso = True
            Else
                AsigneCurso = False
            End If
        End If
        swalta = False
        If AsigneCurso Then
                For t = iniCiclo To finCiclo Step -1
                
                RutSinCurso = alumnossincurso(t, 3)
                ApePat = alumnossincurso(t, 0)
                ApeMat = alumnossincurso(t, 1)
                nombre = alumnossincurso(t, 2)
                
                'Fecha de Matricula
                FechaMatricula = RetornaCampo("matriculas", "fec_mat", "ci_alu = '" & RutSinCurso & "' and activo_alu = 'SI' and anno_mat='" & cmb_ano.Text & "'", conn)
'                If FechaMatricula > FechaDeAlta Then
'                    swalta = True
'                Else
                    If t <= 2 And Me.Grd_alu_sincurso.Rows = 2 Then
                        Me.Grd_alu_sincurso.Clear
                        Me.Grd_alu_sincurso.FormatString = "Apellido paterno     | Apellido materno     | Nombres                                 | R.U.N         "
                    Else
                        Me.Grd_alu_sincurso.RemoveItem (t)
                    End If
                    
                    If ExistReg("repitentes", "ci_alu = '" & RutSinCurso & "' and cod_ens = '" & CodModalidad & "' and num_gra = '" & Ngrado & "' and ANNO_REP='" & Trim(val(cmb_ano.Text) - 1) & "'", conn) Then
                        Repitente = "1"
                    Else
                        Repitente = "2"
                    End If
                    
                    'Asignar numero de matricula a la alta.
                    If EsAlta Then
                        If CodModalidad = "010" Or CodModalidad = "996" Then
                            var_sql = "SELECT max(num_mat) as maximo" _
                                    & " FROM matriculas where (cod_ens = '010' or " _
                                    & "cod_ens = '996') and anno_mat = " & Trim(cmb_ano.Text)
                            objRS.Open var_sql, conn
                            NumAlta = objRS("maximo") + 1
                            objRS.Close
'                            NumAlta = Val(RetornaCampo("matriculas", "max(num_mat+1)", "anno_mat='" & Trim(cmb_ano.Text) & "' AND cod_ens='996'", conn))
'                            NumAlta = NumAlta + Val(RetornaCampo("matriculas", "max(num_mat+1)", "anno_mat='" & Trim(cmb_ano.Text) & "' AND cod_ens='010'", conn))
                        Else
                            var_sql = "SELECT max(num_mat) as maximo" _
                                    & " FROM matriculas where cod_ens = '" & CodModalidad & "'" _
                                    & " and anno_mat = " & Trim(cmb_ano.Text)
                            objRS.Open var_sql, conn
                            NumAlta = objRS("maximo") + 1
                            objRS.Close
                            NumAlta = val(RetornaCampo("matriculas", "max(num_mat+1)", "anno_mat='" & Trim(cmb_ano.Text) & "' AND cod_ens='" & CodModalidad & "'", conn))
                        End If
                        conn.Execute "UPDATE matriculas SET num_mat='" & Format(NumAlta, "00000") _
                        & "',fec_mat = '" & Format(FechaDeAlta, "yyyy-mm-dd") & "' WHERE ci_alu='" & RutSinCurso & "' AND anno_mat='" & Trim(cmb_ano.Text) & "' AND fec_mat='" & Format(FechaMatricula, "yyyy-mm-dd") & "' LIMIT 1;"
                    End If
                    
                    If EsAlta Then
                        strsql = "INSERT INTO alu_x_cur(cod_ens, num_gra, let_cur, ci_alu, activo_alu, fec_mat, fec_cam, num_gra_new, let_cur_new, ind_rep, fec_ing_curso, agno, fec_alta) VALUES('" & CodModalidad & "' , '" & Ngrado & "' , '" & letra & "' , '" & RutSinCurso & "', 'SI' , '" & Format(FechaDeAlta, "yyyy-mm-dd") & "' , '1111-11-11','', '','" & Repitente & "','" & Format(FechaDeAlta, "yyyy-mm-dd") & "','" & Trim(cmb_ano.Text) & "','" & Format(FechaDeAlta, "yyyy-mm-dd") & "')"
                    Else
                        strsql = "INSERT INTO alu_x_cur(cod_ens, num_gra, let_cur, ci_alu, activo_alu, fec_mat, fec_cam, num_gra_new, let_cur_new, ind_rep, fec_ing_curso, agno, fec_alta) VALUES('" & CodModalidad & "' , '" & Ngrado & "' , '" & letra & "' , '" & RutSinCurso & "', 'SI' , '" & Format(FechaMatricula, "yyyy-mm-dd") & "' , '1111-11-11','', '','" & Repitente & "','" & Format(FechaDeAlta, "yyyy-mm-dd") & "','" & Trim(cmb_ano.Text) & "','" & Format(FechaDeAlta, "yyyy-mm-dd") & "')"
                    End If
                    conn.Execute strsql
                    CodJornada = DevuelveCampo("cursos", "", "cod_jor", "cod_ens = '" & CodModalidad & " ' and num_gra = '" & Ngrado & "' and let_cur ='" & letra & "'", conn)
                    strsql = "UPDATE POSTULANTES SET cod_jor='" & CodJornada & "' WHERE ci_alu='" & RutConCurso & "'"
                    conn.Execute strsql
                    strsql = "UPDATE postulaciones SET cod_jor='" & CodJornada & "' WHERE ci_alu='" & RutConCurso & "' and anno_pos_alu = " & cmb_ano.Text
                    conn.Execute strsql
                    
                    'Asignar log
                    Select Case CodModalidad
                        Case "996"
                            grado = "PK"
                        Case "010"
                            grado = "K"
                        Case "110"
                            grado = "EB"
                        Case "310"
                            grado = "EM"
                    End Select
                    curso = CStr(Ngrado) & "º " & letra & " " & grado
                    accion_realizada = "Se realizo alta del alumno, en el curso " & curso
                    log = Inserta_Vitacora_Alumno(RutSinCurso, accion_realizada)
                    'log = inserta_vitacora_alumno(RutSinCurso, "", "", "", "", "", "alta", CStr(curso), "", "1111-11-11", 0)
                    'Fin de log
                    
                    '
                'End If
            Next t
'            If swalta Then
'                MsgBox "Hay alumnos a los cuales no se les dio de alta" & vbCrLf & "ya que su fecha de matricula es mayor a la de alta"
'            End If
            Btn_carga_alumnos_Click
            Cmb_let_cur_Click
        End If
    Else
        MsgBox ("Debe Asignar letra al curso")
    End If
End Sub

Private Sub Btn_Can_man_alu_x_cur_Click()
Unload Me
End Sub

Private Sub Btn_carga_alumnos_Click()
    Dim rs As ADODB.Recordset
    Set rs = New ADODB.Recordset
    
    Me.Txt_Alu_sincurso.Text = 0
    Me.Grd_alu_sincurso.Clear
    Me.Grd_alu_sincurso.FormatString = "Apellido paterno     | Apellido materno     | Nombres                                 | R.U.N         "
    CodModalidad = DevuelveCampo("codigos_ensenanza", "des_ens", "cod_ens", "des_ens = '" & Me.Cmb_mod_alu.Text & "'", conn)
    Ngrado = Me.Cmb_niv_alu.Text
    jornada = DevuelveCampo("jornadas", "", "cod_jor", "des_jor = '" & Me.cmb_jor_alu.Text & "'", conn)
    rs.CursorLocation = adUseClient
    
    'update de validacion, esta pendiente encontrar donde se genera la disrrupcion
    conn.Execute "UPDATE alu_x_cur as ac, matriculas as m SET ac.fec_mat=m.fec_mat WHERE ac.ci_alu=m.ci_alu AND ac.agno=m.anno_mat AND ac.activo_alu=m.activo_alu AND m.activo_alu='SI';"
    
    a = "select p.ape_pat_alu, p.ape_mat_alu, p.nom_alu, p.ci_alu, m.cod_jor " & _
    " from  postulantes p, matriculas m " & _
    " LEFT OUTER JOIN alu_x_cur ax ON m.ci_alu=ax.ci_alu AND ax.activo_alu=m.activo_alu AND ax.activo_alu='SI' and ax.agno =  " & cmb_ano.Text & _
    " WHERE p.ci_alu = m.ci_alu and m.activo_alu = 'SI' and m.cod_ens = '" & CodModalidad & " ' and m.num_gra = '" & Ngrado & "' and m.cod_jor = '" & jornada & "' AND ISNULL(ax.ci_alu) and m.anno_mat = '" & cmb_ano.Text & "' AND m.confirmado='SI' AND m.fec_mat_r IS NOT NULL AND fec_mat_r <> '0000-00-00'" & _
    " order by ape_pat_alu, ape_mat_alu, nom_alu, ci_alu ASC"
    rs.Open a, conn
    c = 1
    Me.Grd_alu_sincurso.Rows = 2
    Me.Grd_alu_sincurso.Enabled = False
    Me.Btn_agrega_alu.Enabled = False
    If rs.RecordCount > 0 Then
        ReDim alumnossincurso(rs.RecordCount, 3)
        While Not rs.EOF
                Me.Grd_alu_sincurso.Row = c
                Me.Grd_alu_sincurso.Col = 0
                Me.Grd_alu_sincurso.Text = rs("ape_pat_alu")
                Me.Grd_alu_sincurso.Col = 1
                Me.Grd_alu_sincurso.Text = rs("ape_mat_alu")
                Me.Grd_alu_sincurso.Col = 2
                Me.Grd_alu_sincurso.Text = rs("nom_alu")
                Me.Grd_alu_sincurso.Col = 3
                Me.Grd_alu_sincurso.Text = rs("ci_alu")
                alumnossincurso(c, 0) = rs("ape_pat_alu")
                alumnossincurso(c, 1) = rs("ape_mat_alu")
                alumnossincurso(c, 2) = rs("nom_alu")
                alumnossincurso(c, 3) = rs("ci_alu")
                c = c + 1
                Me.Grd_alu_sincurso.Rows = Me.Grd_alu_sincurso.Rows + 1
                Me.Grd_alu_sincurso.Enabled = True
                'Me.Btn_agrega_alu.Enabled = True
            'End If
            rs.MoveNext
        Wend
        Me.Txt_Alu_sincurso.Text = c - 1
        If Me.Grd_alu_sincurso.Rows > 2 Then
            Me.Grd_alu_sincurso.RemoveItem (Me.Grd_alu_sincurso.Rows)
        End If
    End If
    rs.Close
End Sub

Private Sub BTN_correccion_Click()
Set rs = New ADODB.Recordset
rs.CursorLocation = adUseClient
rs.Open "select ci_alu, num_gra, cod_ens from alu_x_cur where ucase(activo_alu)='SI'", conn
Me.Prg_Correc_Numgra.Value = 0
If rs.RecordCount > 0 Then
    Me.Prg_Correc_Numgra.Max = rs.RecordCount
    While Not rs.EOF
        conn.Execute "update matriculas set num_gra = '" & rs("num_gra") & "' where ci_alu ='" & rs("ci_alu") & "'"
        conn.Execute "update matriculas set cod_ens = '" & rs("cod_ens") & "' where ci_alu ='" & rs("ci_alu") & "' and cod_ens <> '" & rs("cod_ens") & "'"
        Me.Prg_Correc_Numgra.Value = Me.Prg_Correc_Numgra.Value + 1
        rs.MoveNext
    Wend
End If
rs.Close
Me.Prg_Correc_Numgra.Value = 0
rs.CursorLocation = adUseClient
rs.Open "select p.ci_alu, p.num_gra from postulantes p, matriculas m where p.ci_alu=m.ci_alu and isnull(m.num_gra)", conn
If rs.RecordCount > 0 Then
    Me.Prg_Correc_Numgra.Max = rs.RecordCount
    While Not rs.EOF
        conn.Execute "update matriculas set num_gra = '" & rs("num_gra") & "' where ci_alu ='" & rs("ci_alu") & "'"
        Me.Prg_Correc_Numgra.Value = Me.Prg_Correc_Numgra.Value + 1
        rs.MoveNext
    Wend
End If
conn.Execute "update matriculas set cod_jor='2' where cod_jor='0'"
conn.Execute "update matriculas set cod_jor='3' where cod_jor='1'"
rs.Close
Set rs = Nothing
End Sub

Private Sub QuitarAlumno()
Dim t, iniCiclo, finCiclo As Integer
Dim RutConCurso, strsql As String
Dim CodJornada As String

If CInt(cmb_ano.Text) < Year(Date) Then Exit Sub
If MsgBox("¿ Está seguro ?", vbYesNo + vbQuestion) = vbYes Then
    If Me.txt_jornada_cur <> "" Then
        CodModalidad = DevuelveCampo("codigos_ensenanza", "des_ens", "cod_ens", "des_ens = '" & Me.Cmb_mod_alu.Text & "'", conn)
        Ngrado = Me.Cmb_niv_alu.Text
        letra = Me.Cmb_let_cur.Text
        If Me.Grd_alu_concurso.Row > Me.Grd_alu_concurso.RowSel Then
            iniCiclo = Me.Grd_alu_concurso.Row
            finCiclo = Me.Grd_alu_concurso.RowSel
        ElseIf Me.Grd_alu_concurso.RowSel > Me.Grd_alu_concurso.Row Then
            iniCiclo = Me.Grd_alu_concurso.RowSel
            finCiclo = Me.Grd_alu_concurso.Row
        Else
            iniCiclo = Me.Grd_alu_concurso.Row
            finCiclo = Me.Grd_alu_concurso.RowSel
        End If
        
        For t = iniCiclo To finCiclo Step -1
            RutConCurso = alumnosconcurso(t, 3)
            If t <= 2 And Me.Grd_alu_concurso.Rows = 2 Then
                Me.Grd_alu_concurso.Clear
                Me.Grd_alu_concurso.FormatString = "Apellido paterno     | Apellido materno     | Nombres                                 | R.U.N         "
            Else
                Me.Grd_alu_concurso.RemoveItem (t)
            End If
            strsql = "DELETE FROM alu_x_cur where ci_alu ='" & RutConCurso & "' and cod_ens = '" & CodModalidad & " ' and num_gra = '" & Ngrado & "' and let_cur = '" & letra & "'"
            conn.Execute strsql
            CodJornada = DevuelveCampo("cursos", "", "cod_jor", "cod_ens = '" & CodModalidad & " ' and num_gra = '" & Ngrado & "' and let_cur ='" & letra & "'", conn)
            strsql = "UPDATE MATRICULAS SET cod_jor='" & CodJornada & "' WHERE ci_alu='" & RutConCurso & "'"
            conn.Execute strsql
            strsql = "UPDATE POSTULANTES SET cod_jor='" & CodJornada & "' WHERE ci_alu='" & RutConCurso & "'"
            conn.Execute strsql
            strsql = "UPDATE postulaciones SET cod_jor='" & CodJornada & "' WHERE ci_alu='" & RutConCurso & "'"
            conn.Execute strsql
        Next t
        Cmb_let_cur_Click
        Btn_carga_alumnos_Click
    Else
        MsgBox "Curso Seleccionado No tiene Jornada Ingresada, debe ingresarla para poder llevar a cabo esta operación", vbCritical, "ALERTA DE VALIDACIÓN"
    End If
End If
End Sub

Private Sub cmb_jor_alu_Click()
    Dim AF As String
    If cmb_ano.Text = "" Then MsgBox "Debe Seleccionar Año": cmb_jor_alu.Text = "": Exit Sub
    CodModalidad = DevuelveCampo("codigos_ensenanza", "des_ens", "cod_ens", "des_ens = '" & Me.Cmb_mod_alu.Text & "'", conn)
    Ngrado = Me.Cmb_niv_alu.Text
    jornada = Me.cmb_jor_alu.Text
    AF = "where cod_ens = '" & CodModalidad & "' and num_gra = '" & Ngrado & "' and agno = " & cmb_ano.Text
    letraactual = Me.Cmb_let_cur.Text
    Me.Cmb_let_cur.Clear
    Call LlenaCombo(Me.Cmb_let_cur, "cursos", "let_cur", AF, conn)
    If letraactual <> "" Then
        Cmb_let_cur.Text = letraactual
    End If
    Call Btn_carga_alumnos_Click
End Sub

Private Sub Cmb_jor_alu_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 And Len(Trim(Me.cmb_jor_alu.Text)) <> 0 Then
        Me.Cmb_let_cur.SetFocus
    End If
    KeyAscii = 0
End Sub

Private Sub Cmb_let_cur_Click()
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
Dim rsConCurso As ADODB.Recordset
Set rsConCurso = New ADODB.Recordset
Dim RECH As String
    
    RECH = RetornaCampo("CFG", "valor", "param='CodRegistroINI' and agno='" & Trim(cmb_ano.Text) & "'", conn)
    If RECH = "SI" Then
        Btn_Alta_Alu.Enabled = True
        Btn_agrega_alu.Enabled = False
    Else
        Btn_Alta_Alu.Enabled = False
        Btn_agrega_alu.Enabled = True
    End If

Me.Grd_alu_concurso.Clear
Me.Grd_alu_concurso.FormatString = "Apellido paterno     | Apellido materno     | Nombres                                 | R.U.N         "
CodModalidad = DevuelveCampo("codigos_ensenanza", "des_ens", "cod_ens", "des_ens = '" & Me.Cmb_mod_alu.Text & "'", conn)
Ngrado = Me.Cmb_niv_alu.Text
letra = Me.Cmb_let_cur.Text
rsConCurso.CursorLocation = adUseClient
a = "select p.ape_pat_alu, p.ape_mat_alu, p.nom_alu, p.ci_alu from  postulantes p, alu_x_cur a where p.ci_alu = a.ci_alu and a.activo_alu='SI' and a.cod_ens = '" & CodModalidad & " ' and a.num_gra = '" & Ngrado & "' and a.let_cur ='" & letra & "' and agno = " & cmb_ano.Text & " order by ape_pat_alu, ape_mat_alu, nom_alu, ci_alu ASC"
rsConCurso.Open a, conn

Vacantes = DevuelveCampo("cursos", "", "vacantes_cur", "cod_ens = '" & CodModalidad & " ' and num_gra = '" & Ngrado & "' and let_cur ='" & letra & "' and agno = " & cmb_ano.Text, conn)
rs.CursorLocation = adUseClient
rs.Open "select ci_alu from alu_x_cur a where cod_ens = '" & CodModalidad & "'and num_gra = '" & Ngrado & "' and let_cur = '" & letra & "' and a.activo_alu ='SI' and a.agno = " & cmb_ano.Text, conn
OCUPADOS = rs.RecordCount
rs.Close

jornada = DevuelveCampo("cursos", "", "cod_jor", "cod_ens = '" & CodModalidad & " ' and num_gra = '" & Ngrado & "' and let_cur ='" & letra & "' and agno = " & cmb_ano.Text, conn)
Me.txt_jornada_cur.Text = DevuelveCampo("jornadas", "", "des_jor", "cod_jor = '" & jornada & "'", conn)
Me.lbl_curso_actual.Caption = Me.Cmb_niv_alu + Me.Cmb_let_cur + " " + Me.Cmb_mod_alu + " " + Me.cmb_jor_alu

Me.txt_max_alu.Text = Vacantes
Me.Txt_Alu_Concurso.Text = OCUPADOS
If (val(Vacantes) - val(OCUPADOS)) < 0 Then
    Me.txt_vac_cur.Text = 0
    Me.txt_exe_cur.Text = val(OCUPADOS) - val(Vacantes)
Else
    Me.txt_vac_cur.Text = val(Vacantes) - val(OCUPADOS)
    Me.txt_exe_cur.Text = 0
End If

c = 1
Me.Grd_alu_concurso.Rows = 2
If rsConCurso.RecordCount > 0 Then
    'Me.Btn_quita_alu.Enabled = True
    Me.Grd_alu_concurso.Enabled = True
    Me.Txt_Alu_Concurso.Text = rsConCurso.RecordCount
    ReDim alumnosconcurso(rsConCurso.RecordCount, 3)
    Me.Grd_alu_concurso.Refresh
    While Not rsConCurso.EOF
        Me.Grd_alu_concurso.Row = c
        Me.Grd_alu_concurso.Col = 0
        Me.Grd_alu_concurso.Text = rsConCurso("ape_pat_alu")
        Me.Grd_alu_concurso.Col = 1
        Me.Grd_alu_concurso.Text = rsConCurso("ape_mat_alu")
        Me.Grd_alu_concurso.Col = 2
        Me.Grd_alu_concurso.Text = rsConCurso("nom_alu")
        Me.Grd_alu_concurso.Col = 3
        Me.Grd_alu_concurso.Text = rsConCurso("ci_alu")
        alumnosconcurso(c, 0) = rsConCurso("ape_pat_alu")
        alumnosconcurso(c, 1) = rsConCurso("ape_mat_alu")
        alumnosconcurso(c, 2) = rsConCurso("nom_alu")
        alumnosconcurso(c, 3) = rsConCurso("ci_alu")
        rsConCurso.MoveNext
        c = c + 1
        Me.Grd_alu_concurso.Rows = Me.Grd_alu_concurso.Rows + 1
    Wend
If Me.Grd_alu_concurso.Rows > 2 Then
    Me.Grd_alu_concurso.RemoveItem (Me.Grd_alu_concurso.Rows)
Else



End If
Else
    Me.Grd_alu_concurso.Enabled = False
    'Me.Btn_quita_alu.Enabled = False
End If
rsConCurso.Close
End Sub

Private Sub Cmb_mod_alu_Click()
Dim t As Integer
Call limpia_form_proc_cursos
If Len(Me.Cmb_mod_alu.Text) <> 0 Then
 nivel = DevuelveCampo("codigos_ensenanza", "des_ens", "num_gra_max", "des_ens = " & "'" & Me.Cmb_mod_alu.Text & "'", conn)
 Me.Cmb_niv_alu.Enabled = True
 Me.Cmb_niv_alu.Clear
 For t = 1 To val(nivel)
    Me.Cmb_niv_alu.AddItem t
 Next t
End If

End Sub

Private Sub Cmb_mod_alu_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 And Len(Me.Cmb_mod_alu.Text) <> 0 Then
    Me.Cmb_niv_alu.Enabled = True
    Me.Cmb_niv_alu.SetFocus
End If
End Sub

Private Sub Cmb_niv_alu_Click()
    Call limpia_form_proc_cursos
End Sub

Private Sub Cmb_niv_alu_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 And Len(Trim(Me.Cmb_niv_alu.Text)) <> 0 Then
    Me.cmb_jor_alu.Enabled = True
    Me.cmb_jor_alu.SetFocus
End If
End Sub

Sub limpia_form_proc_cursos()
Me.Txt_Alu_sincurso.Text = 0
Me.Grd_alu_sincurso.Rows = 2
Me.Grd_alu_sincurso.Clear
Me.Grd_alu_sincurso.FormatString = "Apellido paterno     | Apellido materno     | Nombres                                 | R.U.N         "
Me.Grd_alu_concurso.Rows = 2
Me.Grd_alu_concurso.Clear
Me.Grd_alu_concurso.FormatString = "Apellido paterno     | Apellido materno     | Nombres                                 | R.U.N         "
Me.cmb_jor_alu.Text = ""
Me.txt_jornada_cur.Text = ""
Me.Txt_Alu_Concurso.Text = ""
Me.txt_vac_cur.Text = ""
Me.txt_max_alu.Text = ""
End Sub

