VERSION 5.00
Object = "{5E9E78A0-531B-11CF-91F6-C2863C385E30}#1.0#0"; "MSFLXGRD.OCX"
Object = "{F39CBE5C-2D1B-11D6-8D4A-0050043A2E60}#2.0#0"; "ProgBarProzent.ocx"
Begin VB.Form Form_PromALu 
   BorderStyle     =   3  'Fixed Dialog
   Caption         =   "Promoción de alumnos"
   ClientHeight    =   6810
   ClientLeft      =   1605
   ClientTop       =   2160
   ClientWidth     =   11730
   Icon            =   "Form_PromALu.frx":0000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MDIChild        =   -1  'True
   MinButton       =   0   'False
   ScaleHeight     =   6810
   ScaleWidth      =   11730
   ShowInTaskbar   =   0   'False
   Begin VB.PictureBox PicValoresCrit 
      Appearance      =   0  'Flat
      ForeColor       =   &H80000008&
      Height          =   1695
      Left            =   3600
      ScaleHeight     =   1665
      ScaleWidth      =   4905
      TabIndex        =   16
      Top             =   4200
      Visible         =   0   'False
      Width           =   4935
      Begin VB.Frame FrmValoresCrit 
         Appearance      =   0  'Flat
         Caption         =   "Notas deficientes"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H00C00000&
         Height          =   975
         Left            =   120
         TabIndex        =   19
         Top             =   120
         Width           =   4695
         Begin VB.ComboBox CmdValoresCrit 
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   330
            Left            =   240
            Sorted          =   -1  'True
            Style           =   2  'Dropdown List
            TabIndex        =   20
            Top             =   360
            Width           =   4335
         End
      End
      Begin VB.CommandButton BtnCanValoresCrit 
         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            =   3720
         TabIndex        =   18
         Top             =   1200
         Width           =   1095
      End
      Begin VB.CommandButton BtnAceValoresCrit 
         Caption         =   "Aceptar"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   375
         Left            =   2520
         TabIndex        =   17
         Top             =   1200
         Width           =   1095
      End
   End
   Begin VB.Frame Frame2 
      Height          =   1455
      Left            =   4080
      TabIndex        =   7
      Top             =   120
      Width           =   7455
      Begin VB.Label Label6 
         Caption         =   "Porcentage de asistencia"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   4680
         TabIndex        =   25
         Top             =   240
         Width           =   1935
      End
      Begin VB.Label LblAsis_P 
         Appearance      =   0  'Flat
         BackColor       =   &H80000005&
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H80000008&
         Height          =   255
         Left            =   6720
         TabIndex        =   24
         Top             =   240
         Width           =   495
      End
      Begin VB.Label Label7 
         Caption         =   "Promedio general"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H00000000&
         Height          =   255
         Left            =   240
         TabIndex        =   23
         Top             =   240
         Width           =   1335
      End
      Begin VB.Label LblPG 
         Appearance      =   0  'Flat
         BackColor       =   &H80000005&
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H80000008&
         Height          =   255
         Left            =   1800
         TabIndex        =   22
         Top             =   240
         Width           =   495
      End
      Begin VB.Label LblAlu 
         Appearance      =   0  'Flat
         BackColor       =   &H80000005&
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H80000008&
         Height          =   255
         Left            =   1800
         TabIndex        =   11
         Top             =   960
         Width           =   5415
      End
      Begin VB.Label LblCur 
         Appearance      =   0  'Flat
         BackColor       =   &H80000005&
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H80000008&
         Height          =   255
         Left            =   1800
         TabIndex        =   10
         Top             =   600
         Width           =   495
      End
      Begin VB.Label Label5 
         Caption         =   "Alumno"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   240
         TabIndex        =   9
         Top             =   960
         Width           =   615
      End
      Begin VB.Label Label2 
         Caption         =   "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            =   240
         TabIndex        =   8
         Top             =   600
         Width           =   495
      End
   End
   Begin VB.CommandButton BtnGraProm 
      Caption         =   "Grabar"
      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          =   495
      Left            =   9240
      TabIndex        =   21
      Top             =   2160
      Width           =   1095
   End
   Begin VB.CommandButton BtnCritProm 
      Caption         =   "Ver/Modif. Crit. de Promoción"
      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          =   495
      Left            =   4080
      TabIndex        =   15
      Top             =   2160
      Width           =   2535
   End
   Begin VB.CommandButton BtnCan_Prom 
      Caption         =   "Cancelar"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   495
      Left            =   10440
      TabIndex        =   14
      Top             =   2160
      Width           =   1095
   End
   Begin VB.CommandButton BtnVerMod_Prom 
      Caption         =   "Ver/Modif. Promoción"
      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          =   495
      Left            =   6720
      TabIndex        =   13
      Top             =   2160
      Width           =   2415
   End
   Begin MSFlexGridLib.MSFlexGrid MSFlexGrid1 
      Height          =   3855
      Left            =   120
      TabIndex        =   6
      Top             =   2760
      Width           =   11415
      _ExtentX        =   20135
      _ExtentY        =   6800
      _Version        =   393216
      Cols            =   8
      FixedCols       =   0
      Enabled         =   0   'False
      BorderStyle     =   0
      FormatString    =   $"Form_PromALu.frx":2A8B2
      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 ProgBarProzent.ProgBar ProgBar1 
      Height          =   375
      Left            =   4080
      TabIndex        =   12
      Top             =   1680
      Width           =   7455
      _ExtentX        =   13150
      _ExtentY        =   661
   End
   Begin VB.Frame Frame1 
      Height          =   2535
      Left            =   120
      TabIndex        =   0
      Top             =   120
      Width           =   3855
      Begin VB.ComboBox cmb_cod_ens 
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   330
         Left            =   240
         TabIndex        =   3
         Top             =   480
         Width           =   3375
      End
      Begin VB.CheckBox chk_todos_niveles 
         Caption         =   "Todos los niveles"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   240
         TabIndex        =   2
         Top             =   2160
         Width           =   1575
      End
      Begin VB.ListBox lst_niveles 
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   780
         Left            =   240
         Style           =   1  'Checkbox
         TabIndex        =   1
         Top             =   1200
         Width           =   3375
      End
      Begin VB.Label Label4 
         Caption         =   "Niveles"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   240
         TabIndex        =   5
         Top             =   960
         Width           =   735
      End
      Begin VB.Label Label3 
         Caption         =   "Tipo de Enseñanza"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   240
         TabIndex        =   4
         Top             =   240
         Width           =   1575
      End
   End
End
Attribute VB_Name = "Form_PromALu"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim CodModalidad As String
Dim NomModalidad As String
Dim SelCursos As String
Dim RsPromAlu As ADODB.Recordset
Dim Asis As Integer

Sub MuestraPicValoresCrit()
   ' Me.FrmValoresCrit.Width = 4575
   ' Me.CmdValoresCrit.Width = 4335

Select Case MSFlexGrid1.Col
Case 4
    Me.CmdValoresCrit.Visible = False
    Me.PicValoresCrit.Visible = True
    Me.FrmValoresCrit.Caption = "Situación final"
    Me.CmdValoresCrit.Clear
    Call LlenaCombo(CmdValoresCrit, "situaciones_fin", "concat(cod_sit,' - ',des_sit)", "", conn)
    Me.CmdValoresCrit.ListIndex = 0
    Me.CmdValoresCrit.Visible = True
 Case 5
    Me.CmdValoresCrit.Visible = False
    Me.PicValoresCrit.Visible = True
    Me.FrmValoresCrit.Caption = "Observación"
    Me.CmdValoresCrit.Clear
    CmdValoresCrit.AddItem "BORRAR ITEM"
    Call LlenaCombo(CmdValoresCrit, "obserbaciones_fin", "des_obs_fin", "", conn)
    Me.CmdValoresCrit.ListIndex = 0
    Me.CmdValoresCrit.Visible = True
Case 6
    Me.CmdValoresCrit.Visible = False
    Me.PicValoresCrit.Visible = True
    Me.FrmValoresCrit.Caption = "Subsectores deficientes"
    Me.CmdValoresCrit.Clear
    Codens = DevuelveCampo("codigos_ensenanza", "", "cod_ens", "cod_des ='" & Right(Left(Trim(MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, 1)), 5), 2) & "'", conn)
    NumGra = Left(Trim(MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, 1)), 1)
    'Call llenacombo(CmdValoresCrit, "promedios p, subsectores ss", "concat(pg,'-',ss.nom_asi)", "where p.cod_ens=ss.cod_ens and p.ci_alu = '19680833-7' and p.num_gra=ss.num_gra  and p.cod_sec=ss.cod_sec and p.cod_asi=ss.cod_asi and p.cod_ens='" & CodEns & "' and p.num_gra='" & numgra & "' and pg < 4 order by p.ci_alu, ord_asi")
     Call LlenaCombo(CmdValoresCrit, "promedios p, subsectores ss", "concat(pg,'-',ss.nom_asi)", "where p.cod_ens=ss.cod_ens and p.ci_alu ='" & Me.MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, 2) & "' and p.num_gra=ss.num_gra  and p.cod_sec=ss.cod_sec and p.cod_asi=ss.cod_asi and p.cod_ens='" & Codens & "' and p.num_gra='" & NumGra & "' and ss.cod_sec <> '22' and ss.cod_asi <> '22' and ss.cod_sec <> '" & Cod_sec_religion & "' and ss.cod_asi <> '" & Cod_asi_religion & "' and pg < 4 order by p.ci_alu, ord_asi", conn)
    
    If Me.CmdValoresCrit.ListCount > 0 Then Me.CmdValoresCrit.ListIndex = 0
    Me.CmdValoresCrit.Visible = True
    
    

End Select

End Sub


Private Sub BtnAceValoresCrit_Click()
    Select Case MSFlexGrid1.Col
    Case 4
        If CmdValoresCrit.Text = "BORRAR ITEM" Then
            Me.MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, MSFlexGrid1.Col) = ""
        Else
            Me.MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, MSFlexGrid1.Col) = Left(Trim(CmdValoresCrit.Text), 1)
        End If
    Case 5
        If CmdValoresCrit.Text = "BORRAR ITEM" Then
            Me.MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, MSFlexGrid1.Col) = ""
        Else
            Me.MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, MSFlexGrid1.Col) = DevuelveCampo("obserbaciones_fin", "", "cod_obs_fin", "des_obs_fin ='" & Me.CmdValoresCrit.Text & "'", conn) & "-" & CmdValoresCrit.Text
        End If
        
    End Select
    
MSFlexGrid1.SetFocus

Call BtnCanValoresCrit_Click

End Sub


Private Sub BtnCan_Prom_Click()
Unload Me
End Sub

Private Sub BtnCanValoresCrit_Click()
Me.PicValoresCrit.Visible = False
End Sub

Private Sub BtnCritProm_Click()
Call menuhabilitado(False)
Load FormDecProm

End Sub

Private Sub BtnGraProm_Click()
On Error GoTo controler
' ******* Inhabilita controles ***********
Me.Frame1.Enabled = False
Me.MSFlexGrid1.Enabled = False
Me.BtnCritProm.Enabled = False
Me.BtnVerMod_Prom.Enabled = False
Me.BtnGraProm.Enabled = False
Me.BtnCan_Prom.Enabled = False
' ******* FIN Inhabilita controles ********
    
    
    '***********************************************************************
    '* inicializa la barra de progreso                                     *
    '***********************************************************************
    nmax = Me.MSFlexGrid1.Rows - 1
    With ProgBar1
        .MaxValue = nmax
        .Richtung = mDir
        .ProgressStyle = mStyle
        .ShowProzent = 1
        .Zusatztext = "%"
        .ShowProgress 0
    End With
    '***********************************************************************

For i = 1 To Me.MSFlexGrid1.Rows - 1
    cod_sit = Trim(Me.MSFlexGrid1.TextMatrix(i, 4))
    If Trim(MSFlexGrid1.TextMatrix(i, 5)) <> "" Then
        cod_obs_fin = Trim(DevuelveCampo("obserbaciones_fin", "", "cod_obs_fin", "des_obs_fin ='" & Mid(Me.MSFlexGrid1.TextMatrix(i, 5), 5, Len(MSFlexGrid1.TextMatrix(i, 5)) - 4) & "'", conn))
    Else
        cod_obs_fin = ""
    End If
        
    Cod_Crit = Me.MSFlexGrid1.TextMatrix(i, 7)
    
    If cod_sit = "" Then
        cod_sit = "Null"
    Else
        cod_sit = "'" & cod_sit & "'"
    End If
    If cod_obs_fin = "" Then
        cod_obs_fin = "Null"
    Else
        cod_obs_fin = "'" & cod_obs_fin & "'"
    End If
    
    If Cod_Crit = "" Then
        Cod_Crit = "Null"
    Else
        Cod_Crit = "'" & Cod_Crit & "'"
    End If

    'If Me.MSFlexGrid1.TextMatrix(i, 2) = "20497913-8" Then MsgBox "Aqui está"
    conn.Execute "UPDATE matriculas Set cod_sit =" & cod_sit & ", cod_obs_fin =" & cod_obs_fin & ", cod_crit =" & Cod_Crit & " where ci_alu ='" & Me.MSFlexGrid1.TextMatrix(i, 2) & "' and activo_alu ='SI' and anno_mat = " & Anno
    conn.Execute "UPDATE acta_sit_pro SET sit_fin = " & cod_sit & " WHERE agno = " & Anno & " AND run_alu = '" & Me.MSFlexGrid1.TextMatrix(i, 2) & "'"
    ProgBar1.ShowProgress i
    DoEvents
Next i
' ******* Inhabilita controles ***********
Me.Frame1.Enabled = True
Me.MSFlexGrid1.Enabled = True
Me.BtnCritProm.Enabled = True
Me.BtnVerMod_Prom.Enabled = True
Me.BtnGraProm.Enabled = True
Me.BtnCan_Prom.Enabled = True
' ******* FIN Inhabilita controles ********
Exit Sub
controler:
 MsgBox "Error " & Err.Number & " " & Err.Description & Chr(13) & Chr(13) & "en alumno " & i & "/" & nmax & Chr(13) & Chr(13) & "Nombre : " & MSFlexGrid1.TextMatrix(i, 3) & Chr(13) & "RUN : " & MSFlexGrid1.TextMatrix(i, 2) & Chr(13) & "Curso : " & MSFlexGrid1.TextMatrix(i, 1), vbCritical

' ******* Inhabilita controles ***********
Me.Frame1.Enabled = True
Me.MSFlexGrid1.Enabled = True
Me.BtnCritProm.Enabled = True
Me.BtnVerMod_Prom.Enabled = True
Me.BtnGraProm.Enabled = True
Me.BtnCan_Prom.Enabled = True
' ******* FIN Inhabilita controles ********


End Sub

Private Sub BtnVerMod_Prom_Click()
Dim RCauX As ADODB.Recordset
Dim Asis As Double
Set RCauX = New ADODB.Recordset

'On Error GoTo controler
' ******* Inhabilita controles ***********
Me.Frame1.Enabled = False
Me.MSFlexGrid1.Enabled = False
Me.BtnCritProm.Enabled = False
Me.BtnVerMod_Prom.Enabled = False
Me.BtnGraProm.Enabled = False
Me.BtnCan_Prom.Enabled = False
' ******* FIN Inhabilita controles ********

Set RsAux = New ADODB.Recordset
RsAux.CursorLocation = adUseClient
Set RsPromAlu = New ADODB.Recordset
RsPromAlu.CursorLocation = adUseClient
Dim RsAux2 As ADODB.Recordset
Set RsAux2 = New ADODB.Recordset

a = "select p.ape_pat_alu, p.ape_mat_alu, p.nom_alu, p.ci_alu, a.cod_ens, a.num_gra, a.let_cur from  postulantes p, alu_x_cur a, cursos c where p.ci_alu = a.ci_alu and a.activo_alu='SI' and a.cod_ens = '" & CodModalidad & "' and " & SelCursos & " and a.cod_ens = c.cod_ens and a.num_gra = c.num_gra and a.let_cur = c.let_cur and a.agno=c.agno and a.agno=" & Anno & " and valida =  'SI' order by cod_ens, num_gra, let_cur, ape_pat_alu, ape_mat_alu, nom_alu"


RsPromAlu.Open a, conn
If RsPromAlu.RecordCount > 0 Then ' RsPromAlu
    
    '***********************************************************************
    '* inicializa la barra de progreso                                     *
    '***********************************************************************
    nmax = RsPromAlu.RecordCount
    With ProgBar1
        .MaxValue = nmax
        .Richtung = mDir
        .ProgressStyle = mStyle
        .ShowProzent = 1
        .Zusatztext = "%"
        .ShowProgress 0
    End With
    '***********************************************************************
    
    
    MSFlexGrid1.Rows = RsPromAlu.RecordCount + 1
    'While Not rs.EOF
    
    For alumno = 1 To RsPromAlu.RecordCount
        MSFlexGrid1.Col = 0
        MSFlexGrid1.Row = alumno
        MSFlexGrid1.CellAlignment = 1
        MSFlexGrid1.TextMatrix(alumno, 0) = alumno
        MSFlexGrid1.TextMatrix(alumno, 1) = RsPromAlu(5) & RsPromAlu(6) & "-" & NomModalidad
        MSFlexGrid1.TextMatrix(alumno, 2) = RsPromAlu(3)
        MSFlexGrid1.TextMatrix(alumno, 3) = RsPromAlu(0) & " " & RsPromAlu(1) & " " & RsPromAlu(2)
        
        RsAux.Open "SELECT * FROM matriculas WHERE ci_Alu='" & RsPromAlu(3) & "' and anno_mat='" & Anno & "' and activo_Alu='SI'", conn
        If RsAux.RecordCount > 0 Then
            If Not IsNull(RsAux!cod_obs_fin) And Trim(RsAux!cod_obs_fin) <> "" Then
                MSFlexGrid1.TextMatrix(alumno, 5) = RsAux!cod_obs_fin & "-" & RetornaCampo("obserbaciones_fin", "des_obs_fin", "cod_obs_fin='" & RsAux!cod_obs_fin & "'", conn)
            End If
        End If
        RsAux.Close
        
        'If RsPromAlu(3) = "17048703-6" Then MsgBox "ok"
        Asis = CalcAsis(MSFlexGrid1.TextMatrix(alumno, 2), RsPromAlu(4), RsPromAlu(5), RsPromAlu(6), Anno, conn)
        If Asis < 85 Then
            RsAux2.Open "SELECT * FROM `elimina_asistencia_actas` WHERE ci_alu = '" & RsPromAlu(3) & "' AND agno = " & Anno, conn
            If RsAux2.RecordCount > 0 Then
                Asis = 85
            End If
            RsAux2.Close
        End If
        Dim SitAlu, Rojos_en_exc As Integer
        Dim AluConAsiExc As Boolean
        Dim PG As Single
        Dim PGstr As String
        Dim RsExcepCrit As New ADODB.Recordset 'excepciones por criterio
        Dim RsDef As New ADODB.Recordset ' Subsectores deficientes
        '0 NoAsignado
        '1 Pasa
        '2 Repite
        '3 Retirado
        '4 Pendiente
        SitAlu = 0
        AluConAsiExc = False
        Set RsExcepCrit = New ADODB.Recordset
        RsExcepCrit.CursorLocation = adUseClient
        
        'probando
        If CStr(RsPromAlu(3)) = CStr("20955937-4") Then
            si = "SI"
        End If
        
        rojos = CuentaReg("promedios", "ci_alu ='" & RsPromAlu(3) & "' and cod_sec <> '22' and cod_asi <> '22' and cod_sec <> '" & Cod_sec_religion & "' and cod_asi <> '" & Cod_asi_religion & "'and nf < 4 and not isnull(nf) and nf >0 and agno=" & Anno, conn)
        conn.Execute "DELETE FROM promedios where ci_alu = '" & RsPromAlu(3) & "' and cod_sec <> '22' and cod_asi <> '22' and cod_sec <> '" & Cod_sec_religion & "' and cod_asi <> '" & Cod_asi_religion & "' and not isnull(pg) and pg = 0 and agno=" & Anno
        PGstr = DevuelveCampo("promedios", "", "AVG(PG)", "ci_alu ='" & RsPromAlu(3) & "' and cod_sec <> '22' and cod_asi <> '22' and cod_sec <> '" & Cod_sec_religion & "' and cod_asi <> '" & Cod_asi_religion & "' and not isnull(pg)and pg > 0 and agno=" & Anno & " group by ci_alu", conn)
        If Anno > 2004 And DevuelveCampo("establecimientos", "", "rdb", " rdb <> '' ", conn) <> "9782-9" Then
            PGstr = Format(PGstr, "#0.0")
        Else
            PGstr = Int(PGstr * 10) / 10
        End If
        If val(PGstr) > 0 Then
            PG = Format(CDbl(PGstr), "#0.00") 'CDbl(PGstr)
         Else
            PG = 0
        End If
        '*** devuelve criterios para la modalidad y niveles dados ***
        a = "SELECT  * FROM criterios where left(niveles_crit, '3') ='" & CodModalidad & "' and instr(substring(niveles_crit,4,length(niveles_crit)),'" & RsPromAlu(5) & "1')<>0 order by prom_auto desc, exc_crit desc, prom_fin asc"
        RsAux.Open a, conn  'Criterios de promocion
            If RsAux.RecordCount > 0 Then
            Dim Cod_Crit As String
                For crit = 1 To RsAux.RecordCount 'criterios
                    Cod_Crit = RsAux!Cod_Crit
                    If RsAux!prom_auto = "SI" Then 'And Asis >= Val(rsaux!asis_crit) Then
                        If Asis >= val(RsAux!asis_crit) Then
                            MSFlexGrid1.TextMatrix(alumno, 4) = DevuelveCampo("situaciones_fin", "", "des_sit", "cod_int_sit ='PA'", conn)
                            MSFlexGrid1.TextMatrix(alumno, 7) = Cod_Crit
                            SitAlu = 1
                            'Exit For 'criterios
                        Else
                            MSFlexGrid1.TextMatrix(alumno, 4) = DevuelveCampo("situaciones_fin", "", "des_sit", "cod_int_sit ='RE'", conn)
                            SitAlu = 2
                            If rojos > 2 Then
                            a = "update matriculas set reprueva_nota = 'SI' where ci_alu = '" & RsPromAlu(3) _
                                & "' and anno_mat = 2015"
                            End If
                            conn.Execute a
                            Exit For 'criterios
                        End If
                    Else
                        'If rojos > 0 Then MsgBox "ok"
                        If RsAux!exc_crit = 0 Then
                            If rojos <= val(RsAux!num_notas_def) And Asis >= val(RsAux!asis_crit) And PG >= CDbl(RsAux!prom_fin) And AluConAsiExc = False Then
                                
                                SitAlu = 1
                                Exit For
                            End If
                        Else
                            AluConAsiExc = False
                            If Asis >= val(RsAux!asis_crit) Then 'Cumple asistencia
                                If rojos > 0 Then 'analiza subsectores
                                    Set RsDef = New ADODB.Recordset
                                    RsDef.CursorLocation = adUseClient
                                    b = "select p.ci_alu,ss.ord_asi, concat(ss.num_gra,'-', m.cod_des,'  ', ss.nom_asi), ss.cod_ens, p.p1, p.p2, p.p3, p.pg  from promedios p, subsectores ss, codigos_ensenanza m where m.cod_ens = ss.cod_ens and p.cod_ens=ss.cod_ens and p.num_gra=ss.num_gra and p.ci_alu ='" & Me.MSFlexGrid1.TextMatrix(alumno, 2) & "' and p.agno=" & Anno & " and p.cod_sec=ss.cod_sec and p.cod_asi=ss.cod_asi  and  pg < 4 order by p.ci_alu, ord_asi"
                                    RsDef.Open b, conn
                                    If RsDef.RecordCount > 0 Then
                                        Rojos_en_exc = 0
                                        For e = 1 To RsDef.RecordCount
                                            If ExistReg("excepciones_crit", "instr(nom_exc,'" & RsDef(2) & "') and cod_crit ='" & Cod_Crit & "'", conn) Then
                                                Rojos_en_exc = Rojos_en_exc + 1
                                            End If
                                            RsDef.MoveNext
                                        Next e
                                        RsDef.Close

                                    End If
                                End If 'analiza subsectores
                                If Rojos_en_exc = val(RsAux!num_notas_def) Then
                                    If Rojos_en_exc <= val(RsAux!num_notas_def) And rojos <= val(RsAux!num_notas_def) And PG >= CDbl(RsAux!prom_fin) Then
                                        SitAlu = 1
                                        Exit For 'criterios
                                    Else
                                        AluConAsiExc = True
                                    End If
                                End If
                            End If 'Cumple asistencia
                        End If
                    End If
                    RsAux.MoveNext
                      If rojos > 2 Then
                      a = "update matriculas set reprueva_nota = 'SI' where ci_alu = '" & RsPromAlu(3) _
                                & "' and anno_mat = 2015"
                                conn.Execute a
                      SitAlu = 2
                      End If
                Next crit 'criterios
                    
                    
                    '************ Rojo o Azul ***************
                    MSFlexGrid1.Row = alumno
                    MSFlexGrid1.Col = 4
                    MSFlexGrid1.CellBackColor = &H80000004
                        
                    Select Case SitAlu
                        Case 1
                        MSFlexGrid1.CellForeColor = &HFF0000
                        MSFlexGrid1.TextMatrix(alumno, 4) = DevuelveCampo("situaciones_fin", "", "cod_sit", "cod_int_sit ='PA'", conn)
                        MSFlexGrid1.TextMatrix(alumno, 7) = Cod_Crit
                        Case 2
                        MSFlexGrid1.CellForeColor = &HFF
                        MSFlexGrid1.TextMatrix(alumno, 4) = DevuelveCampo("situaciones_fin", "", "cod_sit", "cod_int_sit ='RE'", conn)
                    End Select
                    '************ FIN Rojo o Azul ***************
                ' REPITE
                'If SitAlu = 2 Then MSFlexGrid1.TextMatrix(ALUMNO, 4) = devuelvecampo("situaciones_fin", "", "des_sit", "cod_int_sit ='RE'")
                ' FIN REPITE
                RsAux.Close
                
            Else
                RsAux.Close
            End If
            MSFlexGrid1.TextMatrix(alumno, 6) = rojos
            '************ Rojo o Azul ***************
             MSFlexGrid1.Row = alumno
             MSFlexGrid1.Col = 6
             'MSFlexGrid1.CellBackColor = &H80000004
             Select Case rojos
                 Case 0: MSFlexGrid1.CellForeColor = &HFF0000
                 Case Is > 0: MSFlexGrid1.CellForeColor = &HFF&
             End Select
            '************ FIN Rojo o Azul ***************


        RsPromAlu.MoveNext
    'Wend
    ProgBar1.ShowProgress alumno
    DoEvents
    Next alumno
    'ProgBar1.ShowProgress RsPromAlu.RecordCount
End If
RsPromAlu.Close

a = "select * from  cursos a where a.cod_ens = '" & CodModalidad & "' and " & SelCursos & " and agno=" & Anno & " and valida =  'NO' order by a.cod_ens, a.num_gra, a.let_cur"
RCauX.Open a, conn
Dim MensajeAuX As String
MensajeAuX = ""
If RCauX.RecordCount > 0 Then
    RCauX.MoveFirst
    While Not RCauX.EOF
        MensajeAuX = MensajeAuX & RCauX("num_gra") & " " & RCauX("let_cur") & " " & DevuelveCampo("codigos_ensenanza", "", "cod_des", " cod_ens = '" & RCauX("cod_ens") & "'", conn) & vbCrLf
        RCauX.MoveNext
    Wend
    MsgBox "Los siguiente cursos no se promoveran por no estar validados " & vbCrLf & vbLf & MensajeAuX
End If
' ******* Inhabilita controles ***********
Me.Frame1.Enabled = True
Me.MSFlexGrid1.Enabled = True
Me.BtnCritProm.Enabled = True
Me.BtnVerMod_Prom.Enabled = True
Me.BtnGraProm.Enabled = True
Me.BtnCan_Prom.Enabled = True
' ******* FIN Inhabilita controles ********

Exit Sub
controler:
 MsgBox "Error " & Err.Number & " " & Err.Description & Chr(13) & Chr(13) & "en alumno " & alumno & "/" & nmax & Chr(13) & Chr(13) & "Nombre : " & MSFlexGrid1.TextMatrix(alumno, 3) & Chr(13) & "RUN : " & MSFlexGrid1.TextMatrix(alumno, 2) & Chr(13) & "Curso : " & MSFlexGrid1.TextMatrix(alumno, 1), vbCritical

' ******* Inhabilita controles ***********
Me.Frame1.Enabled = True
Me.MSFlexGrid1.Enabled = True
Me.BtnCritProm.Enabled = True
Me.BtnVerMod_Prom.Enabled = True
Me.BtnGraProm.Enabled = True
Me.BtnCan_Prom.Enabled = True
Resume
' ******* FIN Inhabilita controles ********


End Sub

Private Sub chk_todos_niveles_Click()
If Me.chk_todos_niveles.Value Then
    For t = 0 To Me.lst_niveles.ListCount - 1
        Me.lst_niveles.Selected(t) = True
    Next t
Else
    For t = 0 To Me.lst_niveles.ListCount - 1
        Me.lst_niveles.Selected(t) = False
        Me.lst_niveles.ListIndex = 0
    Next t
End If

End Sub

Private Sub Cmb_Cod_ens_Click()
CodModalidad = DevuelveCampo("codigos_ensenanza", "", "cod_ens", "des_ens = '" & Me.Cmb_Cod_ens.Text & "'", conn)
NomModalidad = DevuelveCampo("codigos_ensenanza", "", "cod_des", "cod_ens ='" & CodModalidad & "'", conn)
Set rs = New ADODB.Recordset
rs.CursorLocation = adUseClient
rs.Open "Select distinct num_gra from subsectores where cod_ens = '" & CodModalidad & "' order by num_gra", conn
'***************LIMPIA LISTA DE NIVELES Y GRILLA *********************
lst_niveles.Clear
Me.MSFlexGrid1.Clear
Me.MSFlexGrid1.FormatString = "Id     |Curso |RUN            | Nombre                                                                         |Sit. Final  |Observación                                                     |Deftes.|Criterio"
'***************FIN LIMPIA LISTA DE NIVELES Y GRILLA *********************
If rs.RecordCount > 0 Then
    While Not rs.EOF
        Me.lst_niveles.AddItem rs("num_gra")
        rs.MoveNext
    Wend
End If
rs.Close

End Sub

Private Sub Command1_Click()
Load FormDecProm
Call menuhabilitado(False)

End Sub


Private Sub Form_Load()
CentrarForma Me
Set rs = New ADODB.Recordset
rs.CursorLocation = adUseClient
'Cod_sec_religion = "13"
'Cod_asi_religion = "13"
Asis = 85 ' asistencia hipotetica para todos los alummnos - se debe sacar cuando este completa la asistencia(Juan Fernandez)

'********* Llena combos ****************

'If CodPerfil = "#UTP#" Or CodPerfil = "#ADM#" Or CodPerfil = "#GES03#" Then
    Call LlenaCombo(Me.Cmb_Cod_ens, "codigos_ensenanza ce", "distinct ce.des_ens", "", conn)
'Else
    'Call llenacombo(cmb_cod_ens, "codigos_ensenanza ce, asi_x_cur_prof ap", "distinct ce.des_ens", "where ce.cod_ens = ap.cod_ens and ap.rut_prof ='" & RutGlobal & "'")
'End If
End Sub

Private Sub Form_Unload(Cancel As Integer)
Call menuhabilitado(True)
End Sub

Private Sub lst_niveles_Click()
Me.MSFlexGrid1.Clear
Me.MSFlexGrid1.FormatString = "Id     |Curso |RUN            | Nombre                                                                         |Sit. Final  |Observación                                                     |Deftes.|Criterio"
Me.MSFlexGrid1.Rows = 2
        SelCursos = ""
        For t = 0 To Me.lst_niveles.ListCount - 1 'Me.MSFlexGrid1.Row - 1
            If Me.lst_niveles.Selected(t) Then 'Me.MSFlexGrid1.Row - 1
                Con = t
            End If
        Next t
        
        For t = 0 To Me.lst_niveles.ListCount - 1 'Me.MSFlexGrid1.Row - 1
            If Me.lst_niveles.Selected(t) Then 'Me.MSFlexGrid1.Row - 1
                If t = Con Then
                    SelCursos = SelCursos & "a.num_gra = '" & Me.lst_niveles.List(t) & "'"
                    Niveles = Niveles & t + 1
                Else
                    SelCursos = SelCursos & "a.num_gra = '" & Me.lst_niveles.List(t) & "' or "
                    Niveles = Niveles & t + 1 & "-"
                End If '{}
            End If
        Next
        If SelCursos = "" Then
            Me.BtnVerMod_Prom.Enabled = False
            Me.BtnGraProm.Enabled = False
            Me.MSFlexGrid1.Enabled = False
            Exit Sub
        End If
        
        SelCursos = "(" & SelCursos & ")"
        Me.BtnVerMod_Prom.Enabled = True
End Sub

Private Sub MSFlexGrid1_Click()
Dim Codens As String
Codens = DevuelveCampo("codigos_ensenanza", "", "cod_ens", "cod_des ='" & Right(Trim(MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, 1)), 2) & "'", conn)
Me.LblAsis_P = CalcAsis(MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, 2), Codens, Left(Trim(MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, 1)), 1), Mid(Trim(MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, 1)), 2, 1), Anno, conn)
PGstr = DevuelveCampo("promedios", "", "AVG(PG)", "ci_alu ='" & Me.MSFlexGrid1.TextMatrix(Me.MSFlexGrid1.Row, 2) & "' and cod_sec <> '22' and cod_asi <> '22' and cod_sec <> '" & Cod_sec_religion & "' and cod_asi <> '" & Cod_asi_religion & "' and not isnull(pg)and pg > 0 group by ci_alu", conn)
PGstr = Format(PGstr, "#0.0")
If val(PGstr) > 0 Then
    PG = Format(CDbl(PGstr), "#0.00")
Else
    PG = 0
End If

Me.LblCur.Caption = MSFlexGrid1.TextMatrix(Me.MSFlexGrid1.Row, 1)
Me.LblAlu.Caption = MSFlexGrid1.TextMatrix(Me.MSFlexGrid1.Row, 3)
Me.LblPG = PG
If Me.MSFlexGrid1.Col >= 4 And Me.MSFlexGrid1.Col <= 6 Then
    Call MuestraPicValoresCrit
Else
    Me.PicValoresCrit.Visible = False
End If
End Sub


Private Sub MSFlexGrid1_SelChange()
Dim Codens As String
Codens = DevuelveCampo("codigos_ensenanza", "", "cod_ens", "cod_des ='" & Right(Trim(MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, 1)), 2) & "'", conn)
Me.LblAsis_P = CalcAsis(MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, 2), Codens, Left(Trim(MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, 1)), 1), Mid(Trim(MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, 1)), 2, 1), Anno, conn)
   
PGstr = DevuelveCampo("promedios", "", "AVG(PG)", "ci_alu ='" & Me.MSFlexGrid1.TextMatrix(Me.MSFlexGrid1.Row, 2) & "' and cod_sec <> '22' and cod_asi <> '22' and cod_sec <> '" & Cod_sec_religion & "' and cod_asi <> '" & Cod_asi_religion & "' and not isnull(pg)and pg > 0 group by ci_alu", conn)
PGstr = Format(PGstr, "#0.0")
If val(PGstr) > 0 Then
    PG = Format(CDbl(PGstr), "#0.00")

Else
    PG = 0
End If

Me.LblCur.Caption = MSFlexGrid1.TextMatrix(Me.MSFlexGrid1.Row, 1)
Me.LblAlu.Caption = MSFlexGrid1.TextMatrix(Me.MSFlexGrid1.Row, 3)
Me.LblPG = PG
If Me.MSFlexGrid1.Col >= 4 And Me.MSFlexGrid1.Col <= 6 Then
    Call MuestraPicValoresCrit
Else
    Me.PicValoresCrit.Visible = False
End If

End Sub


