VERSION 5.00
Object = "{5E9E78A0-531B-11CF-91F6-C2863C385E30}#1.0#0"; "MSFLXGRD.OCX"
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "mscomctl.ocx"
Object = "{6B7E6392-850A-101B-AFC0-4210102A8DA7}#1.3#0"; "comctl32.ocx"
Object = "{00025600-0000-0000-C000-000000000046}#4.6#0"; "crystl32.ocx"
Begin VB.Form Form_pre_eval_evaluacion 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Form1"
   ClientHeight    =   6765
   ClientLeft      =   45
   ClientTop       =   435
   ClientWidth     =   11265
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MDIChild        =   -1  'True
   MinButton       =   0   'False
   ScaleHeight     =   6765
   ScaleWidth      =   11265
   Begin VB.ComboBox text2 
      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
      Style           =   2  'Dropdown List
      TabIndex        =   24
      Top             =   120
      Visible         =   0   'False
      Width           =   615
   End
   Begin VB.CommandButton cmd_Limpiar 
      Caption         =   "Limpiar"
      CausesValidation=   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            =   9840
      TabIndex        =   23
      Top             =   240
      Width           =   1215
   End
   Begin VB.Frame Frame1 
      Caption         =   "Selección por Curso"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00C00000&
      Height          =   1095
      Left            =   120
      TabIndex        =   11
      Top             =   120
      Width           =   8175
      Begin VB.CommandButton Btn_Ver_Lista 
         Caption         =   "Ver"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   735
         Left            =   7320
         Picture         =   "oo.frx":0000
         Style           =   1  'Graphical
         TabIndex        =   14
         Top             =   240
         Width           =   735
      End
      Begin VB.CheckBox Check_Letra 
         Caption         =   "Letra"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H00C00000&
         Height          =   195
         Left            =   4920
         TabIndex        =   13
         Top             =   240
         Value           =   1  'Checked
         Visible         =   0   'False
         Width           =   735
      End
      Begin MSComctlLib.ImageCombo IC_Periodo 
         Height          =   345
         Left            =   5640
         TabIndex        =   12
         Top             =   480
         Width           =   1575
         _ExtentX        =   2778
         _ExtentY        =   609
         _Version        =   393216
         ForeColor       =   -2147483640
         BackColor       =   -2147483643
         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 MSComctlLib.ImageCombo IC_Ensenanza 
         Height          =   345
         Left            =   1200
         TabIndex        =   15
         Top             =   480
         Width           =   2535
         _ExtentX        =   4471
         _ExtentY        =   609
         _Version        =   393216
         ForeColor       =   -2147483640
         BackColor       =   -2147483643
         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
         Locked          =   -1  'True
      End
      Begin MSComctlLib.ImageCombo IC_Nivel 
         Height          =   345
         Left            =   3720
         TabIndex        =   16
         Top             =   480
         Width           =   1095
         _ExtentX        =   1931
         _ExtentY        =   609
         _Version        =   393216
         ForeColor       =   -2147483640
         BackColor       =   -2147483643
         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
         Locked          =   -1  'True
      End
      Begin MSComctlLib.ImageCombo IC_Letra 
         Height          =   345
         Left            =   4920
         TabIndex        =   17
         Top             =   480
         Width           =   735
         _ExtentX        =   1296
         _ExtentY        =   609
         _Version        =   393216
         ForeColor       =   -2147483640
         BackColor       =   -2147483643
         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
         Locked          =   -1  'True
      End
      Begin MSComctlLib.ImageCombo IC_Agno 
         Height          =   345
         Left            =   120
         TabIndex        =   18
         Top             =   480
         Width           =   1095
         _ExtentX        =   1931
         _ExtentY        =   609
         _Version        =   393216
         ForeColor       =   -2147483640
         BackColor       =   -2147483643
         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
         Locked          =   -1  'True
      End
      Begin VB.Label Label3 
         Alignment       =   2  'Center
         Caption         =   "Nivel"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H00C00000&
         Height          =   255
         Left            =   3600
         TabIndex        =   22
         Top             =   240
         Width           =   855
      End
      Begin VB.Label Label2 
         Alignment       =   2  'Center
         Caption         =   "Enseñanza"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H00C00000&
         Height          =   255
         Left            =   1200
         TabIndex        =   21
         Top             =   240
         Width           =   975
      End
      Begin VB.Label Label1 
         Alignment       =   2  'Center
         Caption         =   "Año"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H00C00000&
         Height          =   255
         Left            =   120
         TabIndex        =   20
         Top             =   240
         Width           =   495
      End
      Begin VB.Label Label5 
         Caption         =   "Periodo"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H00C00000&
         Height          =   255
         Left            =   5640
         TabIndex        =   19
         Top             =   240
         Width           =   1095
      End
   End
   Begin VB.Frame Frame2 
      Caption         =   "Consulta"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00C00000&
      Height          =   1455
      Left            =   120
      TabIndex        =   8
      Top             =   5160
      Width           =   5775
      Begin VB.Label Label4 
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   14.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H000000FF&
         Height          =   1095
         Left            =   240
         TabIndex        =   9
         Top             =   240
         Width           =   5295
      End
   End
   Begin VB.Frame Frame3 
      Caption         =   "Observación"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00C00000&
      Height          =   1455
      Left            =   6000
      TabIndex        =   6
      Top             =   5160
      Width           =   5175
      Begin VB.TextBox txt_observacion 
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   12
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   1095
         Left            =   120
         Locked          =   -1  'True
         MultiLine       =   -1  'True
         TabIndex        =   7
         Top             =   240
         Width           =   4935
      End
   End
   Begin VB.CommandButton cmd_Grabar 
      Caption         =   "Grabar"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   8400
      TabIndex        =   5
      Top             =   240
      Width           =   1215
   End
   Begin VB.Frame Barra 
      Caption         =   "Actualización de Datos"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00C00000&
      Height          =   1695
      Left            =   1440
      TabIndex        =   2
      Top             =   2520
      Visible         =   0   'False
      Width           =   8175
      Begin ComctlLib.ProgressBar progreso 
         Height          =   255
         Left            =   240
         TabIndex        =   3
         Top             =   1200
         Width           =   7695
         _ExtentX        =   13573
         _ExtentY        =   450
         _Version        =   327682
         Appearance      =   1
      End
      Begin VB.Label Label6 
         Caption         =   "Espere Mientras el Sistema Actualiza los Datos"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   14.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   375
         Left            =   960
         TabIndex        =   4
         Top             =   480
         Width           =   6495
      End
   End
   Begin VB.CommandButton Command2 
      Caption         =   "Cerrar Informe"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   9840
      TabIndex        =   1
      Top             =   720
      Width           =   1215
   End
   Begin VB.CommandButton cmd_imprimir 
      Caption         =   "Imprimir"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   8400
      TabIndex        =   0
      Top             =   720
      Width           =   1215
   End
   Begin Crystal.CrystalReport cr_perso 
      Left            =   10320
      Top             =   4440
      _ExtentX        =   741
      _ExtentY        =   741
      _Version        =   262150
   End
   Begin MSFlexGridLib.MSFlexGrid MSFlexGrid1 
      Height          =   3735
      Left            =   120
      TabIndex        =   10
      Top             =   1320
      Width           =   10935
      _ExtentX        =   19288
      _ExtentY        =   6588
      _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
   End
End
Attribute VB_Name = "Form_pre_eval_evaluacion"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Btn_Ver_Lista_Click()
    Dim total_itemes As Integer
    Dim Ind As Integer
    Dim a As Integer
    Dim mat2(100, 3) As String
    'Dim i As Integer
    Dim periodo As Integer
    Dim sw As Boolean
    Dim rut_prof As String
    Dim Valor As String
    Dim mat(10, 2) As String
    Dim i, j, X, tope, n_item As Integer
    Dim objRS As ADODB.Recordset
    Set objRS = New ADODB.Recordset
    Dim REC As ADODB.Recordset
    Set REC = New ADODB.Recordset
    Dim rec2 As ADODB.Recordset
    Set rec2 = New ADODB.Recordset
    Dim var_sql As String
    
    Me.text2.Visible = True
    
    If IC_Periodo.Text = "Primer Semestre" Then
        periodo = 1
    Else
        periodo = 2
    End If
    
    var_sql = "Select pre_eval_formato_inf_agno.t_item,pre_eval_formato_inf_agno.n_item" _
            & " from pre_eval_formato_inf_agno join `pre_eval_item_des`" _
            & " where pre_eval_formato_inf_agno.cod_ens='" & Mid(IC_Ensenanza.SelectedItem.Key, 2) _
            & "' and pre_eval_formato_inf_agno.num_gra='" & CInt(IC_Nivel.Text) _
            & "' and pre_eval_formato_inf_agno.n_item=pre_eval_item_des.n_item" _
            & " and pre_eval_formato_inf_agno.t_item=pre_eval_item_des.t_item and agno = " & IC_Agno.Text _
            & " and `pre_eval_item_des`.cod_ens = '" & Mid(IC_Ensenanza.SelectedItem.Key, 2) & "' order by t_item,n_item"
    objRS.Open var_sql, conn
    i = 0
    While Not objRS.EOF
        i = i + 1
        mat2(i, 0) = objRS("n_item")
        mat2(i, 1) = objRS("t_item")
        mat2(i, 2) = i
        objRS.MoveNext
    Wend
    total_itemes = i
    objRS.Close
        
'    var_sql = "Select RUT_USU,right(cargo_usu,5) as marca,cargo_usu from usuarios where AUT_NOMBRE_USUARIO='" _
'    & Nom_usu_ses & "'"
'    objRS.Open var_sql, conn
'    rut_prof = objRS("rut_usu")
'    'marca = objRS("marca")
'    'cargo = objRS("cargo_usu")
'    objRS.Close
'
'    var_sql = "select * from cursos where rut_prof = '" & rut_prof & "' and agno = " & IC_Agno.Text _
'            & " and cod_ens = '" & IC_Ensenanza.Text _
'            & "' and num_gra = " & IC_Nivel.Text _
'            & " and let_cur = '" & IC_Letra.Text & "'"
'    objRS.Open var_sql, conn
'    If objRS.EOF Then
'        objRS.Close
'        Exit Sub
'    End If
'    objRS.Close
    
    var_sql = "select axc.ci_alu,concat(ape_pat_alu,' ',ape_mat_alu,' ',nom_alu) as 'nombre'" _
            & " from alu_x_cur axc,postulantes p where axc.agno = " & IC_Agno.Text _
            & " and axc.cod_ens = '" & Mid(IC_Ensenanza.SelectedItem.Key, 2) _
            & "' and axc.let_cur = '" & IC_Letra.Text _
            & "' and activo_alu = 'SI' and axc.num_gra = " & IC_Nivel.Text _
            & " and axc.ci_alu = p.ci_alu" _
            & " order by 'nombre'"
    objRS.Open var_sql, conn
    
    var_sql = "Select pre_eval_formato_inf_agno.t_item,count(pre_eval_formato_inf_agno.t_item) as total" _
            & " from pre_eval_formato_inf_agno join `pre_eval_item_des`" _
            & " where pre_eval_formato_inf_agno.cod_ens='" & Mid(IC_Ensenanza.SelectedItem.Key, 2) _
            & "' and pre_eval_formato_inf_agno.num_gra='" & Val(IC_Nivel.Text) & "'" _
            & " and pre_eval_formato_inf_agno.n_item=pre_eval_item_des.n_item" _
            & " and pre_eval_formato_inf_agno.t_item=pre_eval_item_des.t_item" _
            & " and agno = " & IC_Agno.Text _
            & " and pre_eval_item_des.cod_ens = '" & Mid(IC_Ensenanza.SelectedItem.Key, 2) & "'" _
            & " group by pre_eval_formato_inf_agno.t_item" _
            & " order by pre_eval_formato_inf_agno.t_item,pre_eval_formato_inf_agno.n_item"
    REC.Open var_sql, conn
    
'    var_sql = "select ci_alu,t_item,n_item,valor,observaciones from pre_eval_cab dc,pre_eval_item_deta did" _
'            & " where dc.folio_persoc = did.folio_persoc and" _
'            & " agno = " & IC_Agno.Text & " and cod_ens = '" & Mid(IC_Ensenanza.SelectedItem.Key, 2) _
'            & "' and num_gra = " & IC_Nivel.Text & " and let_cur = '" & IC_Letra.Text & "'" _
'            & " and periodo = " & Periodo _
'            & " order by ci_alu,t_item,n_item"
            
    var_sql = "select ci_alu,did.t_item,did.n_item,valor,observaciones" _
            & " from pre_eval_cab dc,pre_eval_item_deta did,pre_eval_formato_inf_agno d" _
            & " Where dc.folio_persoc = did.folio_persoc" _
            & " and dc.agno = " & IC_Agno.Text & " and dc.cod_ens = '" _
            & Mid(IC_Ensenanza.SelectedItem.Key, 2) & "' and dc.num_gra = " _
            & IC_Nivel.Text & " and dc.let_cur = '" & IC_Letra.Text _
            & "' and periodo = " & periodo _
            & " and dc.cod_ens = d.cod_ens and dc.num_gra = d.num_gra and dc.agno = d.agno and" _
            & " did.t_item = d.t_item And did.n_item = d.n_item" _
            & " order by ci_alu,t_item,n_item"

    rec2.Open var_sql, conn
    
    Barra.Visible = True
    progreso.Min = 1
    progreso.Max = objRS.RecordCount + REC.RecordCount + rec2.RecordCount + 1
    progreso.Value = 1
    
    MSFlexGrid1.Rows = 2
    MSFlexGrid1.Cols = 5
    MSFlexGrid1.ColWidth(1) = 4000
    MSFlexGrid1.ColWidth(0) = 0
    MSFlexGrid1.Clear
    While Not objRS.EOF
        progreso.Value = progreso.Value + 1
        MSFlexGrid1.Row = MSFlexGrid1.Rows - 1
        MSFlexGrid1.Col = 0
        MSFlexGrid1.Text = objRS("ci_alu")
        MSFlexGrid1.Col = 1
        MSFlexGrid1.Text = objRS("ci_alu") & " - " & objRS("nombre")
        MSFlexGrid1.CellAlignment = flexAlignLeftCenter
        objRS.MoveNext
        MSFlexGrid1.Rows = MSFlexGrid1.Rows + 1
    Wend
    MSFlexGrid1.Rows = MSFlexGrid1.Rows - 1
    objRS.Close
        
'    var_sql = "Select pre_eval_formato_inf_agno.t_item,count(pre_eval_formato_inf_agno.t_item) as total" _
'            & " from pre_eval_formato_inf_agno join `pre_eval_item_des`" _
'            & " where pre_eval_formato_inf_agno.cod_ens='" & Mid(IC_Ensenanza.SelectedItem.Key, 2) _
'            & "' and pre_eval_formato_inf_agno.num_gra='" & Val(IC_Nivel.Text) & "'" _
'            & " and pre_eval_formato_inf_agno.n_item=pre_eval_item_des.n_item" _
'            & " and pre_eval_formato_inf_agno.t_item=pre_eval_item_des.t_item" _
'            & " group by pre_eval_formato_inf_agno.t_item"
'    REC.Open var_sql, conn
    i = 0
    j = 4
    
    sw = True
    If REC.EOF Then
        sw = False
    End If
    
    While Not REC.EOF
        progreso.Value = progreso.Value + 1
        i = i + 1
        MSFlexGrid1.Row = i
        MSFlexGrid1.Col = 2
        MSFlexGrid1.Text = REC("t_item")
        MSFlexGrid1.Col = 3
        MSFlexGrid1.Text = j + 1
        MSFlexGrid1.Col = 4
        MSFlexGrid1.Text = REC("total") + j
        j = REC("total") + j
        REC.MoveNext

    Wend
    
    REC.Close
    MSFlexGrid1.Cols = MSFlexGrid1.Cols + j - 4
    'For x = 1 To MSFlexGrid1.Rows - 1
        MSFlexGrid1.Row = 0
        For i = 5 To MSFlexGrid1.Cols - 1
            MSFlexGrid1.Col = i
            MSFlexGrid1.Text = i - 4
            MSFlexGrid1.CellAlignment = flexAlignLeftCenter
            MSFlexGrid1.ColWidth(i) = 1500
        Next i
   ' Next x
    
    MSFlexGrid1.ColWidth(2) = 0
    MSFlexGrid1.ColWidth(3) = 0
    MSFlexGrid1.ColWidth(4) = 0
    MSFlexGrid1.TextMatrix(0, 1) = "Alumnos"
    MSFlexGrid1.Cols = MSFlexGrid1.Cols + 1
    MSFlexGrid1.ColWidth(MSFlexGrid1.Cols - 1) = 0
    
    var_sql = "select criterio,descripcion from pre_eval_crit_eval"
    objRS.Open var_sql, conn
    i = -1
    While Not objRS.EOF
        i = i + 1
        mat(i, 0) = objRS("criterio")
        mat(i, 1) = objRS("descripcion")
        objRS.MoveNext
    Wend
    objRS.Close
    tope = i
    
'    var_sql = "select ci_alu,t_item,n_item,valor,observaciones from pre_eval_cab dc,pre_eval_item_deta did" _
'            & " where dc.folio_persoc = did.folio_persoc and" _
'            & " agno = " & IC_Agno.Text & " and cod_ens = '" & Mid(IC_Ensenanza.SelectedItem.Key, 2) _
'            & "' and num_gra = " & IC_Nivel.Text & " and let_cur = '" & IC_Letra.Text & "'" _
'            & " order by ci_alu,t_item,n_item"
'    REC2.Open var_sql, conn
    
    While Not rec2.EOF
        progreso.Value = progreso.Value + 1
        For i = 1 To MSFlexGrid1.Rows - 1
            If CStr(rec2("ci_alu")) = CStr(MSFlexGrid1.TextMatrix(i, 0)) Then
                'For j = 5 To MSFlexGrid1.Cols - 2
                   Valor = ""
                   For k = 0 To tope
                     If mat(k, 0) = rec2("valor") And rec2("valor") <> "" Then
                        Valor = mat(k, 1)
                     End If
                   Next k
                   For k = 1 To 5
                    If MSFlexGrid1.TextMatrix(k, 2) = rec2("t_item") Then
                       n_item = CInt(MSFlexGrid1.TextMatrix(k, 3)) + CInt(rec2("n_item")) - 1
                    End If
                   Next k
                'Next j
                For a = 1 To total_itemes
                    If CInt(mat2(a, 0)) = CInt(rec2("n_item")) And CStr(mat2(a, 1)) = CStr(rec2("t_item")) Then
                       Ind = mat2(a, 2)
                       Exit For
                    End If
                Next a
                MSFlexGrid1.TextMatrix(i, Ind + 4) = Valor
                MSFlexGrid1.TextMatrix(i, MSFlexGrid1.Cols - 1) = rec2("observaciones")
            End If
        Next i
        rec2.MoveNext
    Wend
    rec2.Close
    Btn_Ver_Lista.Enabled = False
    Barra.Visible = False
    Frame1.Enabled = False
    
    var_sql = "select * from pre_eval_crit_eval_nivel dn,pre_eval_crit_eval de" _
            & " where cod_ens = '" & Mid(IC_Ensenanza.SelectedItem.Key, 2) _
            & "' and num_gra = " & IC_Nivel.Text & " and dn.criterio = de.criterio"
    objRS.Open var_sql, conn
    text2.Clear
   ' objRS.Open var_sql, conn
   i = 0
   text2.AddItem "", i
    While Not objRS.EOF
        i = i + 1
        text2.AddItem objRS("descripcion"), i
        objRS.MoveNext
    Wend
    objRS.Close
    If sw = False Then
        'sw = False
        MsgBox "No se ha definido formato para este nivel de enseñanza", vbInformation
    End If
End Sub

Private Sub cmd_Grabar_Click()
    'Dim i As Integer
    Dim mat2(100) As Integer
    Dim j As Integer
    Dim periodo As String
    Dim Criterio As String
    Dim i, tope As Integer
    Dim mat(10, 2) As String
    Dim folio_persoc As String
    Dim rut_prof As String
    Dim var_sql As String
    Dim objRS As ADODB.Recordset
    Set objRS = New ADODB.Recordset
    
    If text2.Visible = True Then
        MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, MSFlexGrid1.Col) = text2.Text
    End If
    
    var_sql = "Select pre_eval_formato_inf_agno.t_item,pre_eval_formato_inf_agno.n_item" _
            & " from pre_eval_formato_inf_agno join `pre_eval_item_des`" _
            & " where pre_eval_formato_inf_agno.cod_ens='" & Mid(IC_Ensenanza.SelectedItem.Key, 2) _
            & "' and pre_eval_formato_inf_agno.num_gra='" & CInt(IC_Nivel.Text) _
            & "' and pre_eval_formato_inf_agno.n_item=pre_eval_item_des.n_item" _
            & " and pre_eval_formato_inf_agno.t_item=pre_eval_item_des.t_item and agno = " & IC_Agno.Text _
            & " and pre_eval_item_des.cod_ens = '" & Mid(IC_Ensenanza.SelectedItem.Key, 2) & "'" _
            & " order by t_item,n_item"
    objRS.Open var_sql, conn
    i = 0
    While Not objRS.EOF
        i = i + 1
        mat2(i) = objRS("n_item")
        objRS.MoveNext
    Wend
    objRS.Close
    
    If MSFlexGrid1.Rows = 2 And MSFlexGrid1.Cols = 2 _
    And Val(MSFlexGrid1.TextMatrix(1, 1)) = 0 Then Exit Sub
    
    var_sql = "select * from cursos where" _
            & " cod_ens = '" & Mid(IC_Ensenanza.SelectedItem.Key, 2) _
            & "' and num_gra = " & IC_Nivel.Text _
            & " and let_cur = '" & IC_Letra.Text & "' and agno = " & IC_Agno.Text
    objRS.Open var_sql, conn
    rut_prof = objRS("rut_prof")
    objRS.Close
    
    var_sql = "select criterio,descripcion from pre_eval_crit_eval"
    objRS.Open var_sql, conn
    i = -1
    While Not objRS.EOF
        i = i + 1
        mat(i, 0) = objRS("criterio")
        mat(i, 1) = objRS("descripcion")
        objRS.MoveNext
    Wend
    objRS.Close
    tope = i
    If IC_Periodo.Text = "Primer Semestre" Then
        periodo = 1
    Else
        periodo = 2
    End If
'    periodo = IC_Periodo.Text
    Barra.Visible = True
    progreso.Min = 1
    progreso.Max = MSFlexGrid1.Rows
    progreso.Value = 1
    For i = 1 To MSFlexGrid1.Rows - 1
        progreso.Value = progreso.Value + 1
        var_sql = "select folio_persoc from pre_eval_cab" _
                & " where agno = " & IC_Agno.Text _
                & " and cod_ens = '" & Mid(IC_Ensenanza.SelectedItem.Key, 2) _
                & "' and num_gra = " & IC_Nivel.Text & " and let_cur = '" _
                & IC_Letra.Text & "' and ci_alu = '" & MSFlexGrid1.TextMatrix(i, 0) & "' and periodo = " & periodo
        objRS.Open var_sql, conn
        folio_persoc = ""
        If Not objRS.EOF Then
            folio_persoc = objRS("folio_persoc")
        End If
        objRS.Close
        If folio_persoc = "" Then
            var_sql = "select * from pre_eval_item_deta" _
                    & " order by folio_persoc desc limit 1"
            objRS.Open var_sql, conn
            If Not objRS.EOF Then
                folio_persoc = objRS("folio_persoc") + 1
            Else
                folio_persoc = 1
            End If
            objRS.Close
        End If
        
        var_sql = "replace into pre_eval_cab(folio_persoc,periodo,estado,ci_alu,rut_prof,cod_ens,num_gra,let_cur,agno,observaciones)" _
                & " values(" & folio_persoc & "," & periodo & ",'A','" & MSFlexGrid1.TextMatrix(i, 0) _
                & "','" & rut_prof & "','" & Mid(IC_Ensenanza.SelectedItem.Key, 2) _
                & "'," & IC_Nivel.Text & ",'" & IC_Letra.Text _
                & "'," & IC_Agno.Text & ",'" & MSFlexGrid1.TextMatrix(i, MSFlexGrid1.Cols - 1) & "')"
        conn.Execute var_sql
              
        For j = 5 To MSFlexGrid1.Cols - 2
            Criterio = ""
            For k = 0 To tope
                If mat(k, 1) = MSFlexGrid1.TextMatrix(i, j) Then
                    Criterio = mat(k, 0)
                End If
            Next k
            
            If MSFlexGrid1.TextMatrix(1, 3) <> "" Then
            If CInt(j) >= CInt(MSFlexGrid1.TextMatrix(1, 3)) And CInt(j) <= CInt(MSFlexGrid1.TextMatrix(1, 4)) Then
                t_item = MSFlexGrid1.TextMatrix(1, 2)
                'n_item = j - 4
                n_item = mat2(CInt(MSFlexGrid1.TextMatrix(0, j)))
            End If
            End If
    
            If MSFlexGrid1.TextMatrix(2, 3) <> "" Then
            If CInt(j) >= MSFlexGrid1.TextMatrix(2, 3) And CInt(j) <= MSFlexGrid1.TextMatrix(2, 4) Then
                t_item = MSFlexGrid1.TextMatrix(2, 2)
                'n_item = j - MSFlexGrid1.TextMatrix(1, 4)
                n_item = mat2(CInt(MSFlexGrid1.TextMatrix(0, j)))
            End If
            End If
    
            If MSFlexGrid1.TextMatrix(3, 3) <> "" Then
            If CInt(j) >= MSFlexGrid1.TextMatrix(3, 3) And CInt(j) <= MSFlexGrid1.TextMatrix(3, 4) Then
                t_item = MSFlexGrid1.TextMatrix(3, 2)
                'n_item = j - MSFlexGrid1.TextMatrix(2, 4)
                n_item = mat2(CInt(MSFlexGrid1.TextMatrix(0, j - 4)))
            End If
            End If
    
            If MSFlexGrid1.TextMatrix(4, 3) <> "" Then
            If CInt(j) >= MSFlexGrid1.TextMatrix(4, 3) And CInt(j) <= MSFlexGrid1.TextMatrix(4, 4) Then
                t_item = MSFlexGrid1.TextMatrix(4, 2)
                'n_item = j - MSFlexGrid1.TextMatrix(3, 4)
                n_item = mat2(CInt(MSFlexGrid1.TextMatrix(0, j)))
            End If
            End If
            
            If MSFlexGrid1.TextMatrix(5, 3) <> "" Then
            If CInt(j) >= MSFlexGrid1.TextMatrix(5, 3) And CInt(j) <= MSFlexGrid1.TextMatrix(5, 4) Then
                t_item = MSFlexGrid1.TextMatrix(5, 2)
                'n_item = j - MSFlexGrid1.TextMatrix(4, 4)
                n_item = mat2(CInt(MSFlexGrid1.TextMatrix(0, j)))
            End If
            End If
            
            n_item = mat2(CInt(MSFlexGrid1.TextMatrix(0, j)))
            
            var_sql = "replace into pre_eval_item_deta(folio_persoc,t_item,n_item,valor)" _
                    & " values (" & folio_persoc & ",'" & t_item _
                    & "'," & n_item _
                    & ",'" & Criterio & "')"
            conn.Execute var_sql
        Next j
    Next i
    Barra.Visible = False
    MsgBox "Los cambios han sido grabados exitosamente", vbInformation
End Sub

Private Sub cmd_imprimir_Click()
    Dim periodo As Integer
    Dim Per As String
    Dim var_sql As String
    Dim objRS As ADODB.Recordset
    Set objRS = New ADODB.Recordset
    
    If IC_Periodo.Text = "Primer Semestre" Then
        periodo = 1
    Else
        periodo = 2
    End If
    
    var_sql = "select * from alu_x_cur axc,pre_eval_cab dc" _
            & " where axc.agno = " & IC_Agno.Text _
            & " and axc.cod_ens = '" & Mid(IC_Ensenanza.SelectedItem.Key, 2) & "'" _
            & " and axc.num_gra = " & IC_Nivel.Text _
            & " and axc.let_cur = '" & IC_Letra.Text & "' and axc.activo_alu = 'SI' and" _
            & " axc.agno = dc.agno And axc.Cod_Ens = dc.Cod_Ens And axc.Num_Gra = axc.Num_Gra" _
            & " and axc.let_cur = dc.let_cur and axc.ci_alu = dc.ci_alu and estado = 'C'" _
            & " and periodo = " & periodo
    objRS.Open var_sql, conn
    If objRS.RecordCount = 0 Then
        MsgBox "Para poder imprimir el informe para todo el curso, antes debe tener cerrado el curso completo", vbInformation
        objRS.Close
        Exit Sub
    End If
    objRS.Close
    
    Per = ""
    If IC_Periodo.Text = "Primer Semestre" Then
        Per = " and {pre_eval_cab.periodo}=1 "
    ElseIf IC_Periodo.Text = "Segundo Semestre" Then
        Per = " and {pre_eval_cab.periodo}=2 "
    End If
    
'        Form_main.CrystalReport.Formulas(0) = "colegio = '" & nombre & "'"
'            Form_main.CrystalReport.Formulas(1) = "fecha = '" & Format(Now, "dd/mm/yyyy") & "'"
'            Form_main.CrystalReport.Formulas(2) = "hora = '" & Format(Now, "hh:mm AM/PM") & "'"
    
        'MSFlexGrid2.Col = 0
        xcod = Mid(IC_Ensenanza.SelectedItem.Key, 2)
       ' MSFlexGrid2.Col = 1
        xnum_gra = IC_Nivel.Text
       ' MSFlexGrid2.Col = 2
        xletra = IC_Letra.Text
        xagno = IC_Agno.Text
        'MsgBox xcod & " " & xnum_gra & " " & xletra
        
         var_sql = "SELECT nombre,colegio" _
            & " From hist_cod_colegio" _
            & " where colegio = (select valor from cfg where param = 'codbc')"
    objRS.Open var_sql, conn
    colegio = objRS("colegio")
    nombre = objRS("nombre")
    objRS.Close
        
        
        If xcod = "110" And Val(xnum_gra) < 5 Then
             '************************IMPRESION DE INFORME PARA ALUMNOS DE NB1-NB2-NB3-NB4*******************
            cr_perso.ReportFileName = App.Path & "\rpt\informe_pre_eval110.rpt"
            cr_perso.WindowState = crptMaximized
            cr_perso.WindowTitle = "Informe De Desarrollo Personal y Social"
            cr_perso.ReplaceSelectionFormula ("")
            
            cr_perso.Formulas(0) = "colegio = '" & nombre & "'"
            cr_perso.Formulas(1) = "fecha = '" & Format(Now, "dd/mm/yyyy") & "'"
            cr_perso.Formulas(2) = "hora = '" & Format(Now, "hh:mm AM/PM") & "'"
            
            cr_perso.ReplaceSelectionFormula ("{pre_eval_cab.cod_ens}='" & xcod & "' and {pre_eval_cab.num_gra}='" & CInt(xnum_gra) & "' and {pre_eval_cab.let_cur}='" & xletra & "' and {pre_eval_cab.agno}=" & str(xagno)) & Per
            cr_perso.Destination = crptToWindow
            cr_perso.Action = 1
        '************************FIN IMPRESION DE INFORME PARA ALUMNOS De NB1 - NB2 - NB3 - NB4
        ElseIf xcod = "110" And Val(xnum_gra) > 4 Then
        '************************IMPRESION DE INFORME PARA ALUMNOS DE NB5-NB6-NB7-NB8*******************
            cr_perso.ReportFileName = App.Path & "\rpt\informe_pre_eval1108.rpt"
            cr_perso.WindowState = crptMaximized
            cr_perso.WindowTitle = "Informe De Desarrollo Personal y Social"
            cr_perso.ReplaceSelectionFormula ("")
            
            cr_perso.Formulas(0) = "colegio = '" & nombre & "'"
            cr_perso.Formulas(1) = "fecha = '" & Format(Now, "dd/mm/yyyy") & "'"
            cr_perso.Formulas(2) = "hora = '" & Format(Now, "hh:mm AM/PM") & "'"
            
            cr_perso.ReplaceSelectionFormula ("{pre_eval_cab.cod_ens}='" & xcod & "' and {pre_eval_cab.num_gra}='" & CInt(xnum_gra) & "' and {pre_eval_cab.let_cur}='" & xletra & "' and {pre_eval_cab.agno}=" & str(xagno)) & Per
            cr_perso.Destination = crptToWindow
            cr_perso.Action = 1
        '************************FIN IMPRESION DE INFORME PARA ALUMNOS DE NB5-NB6-NB7-NB8*******************
        ElseIf xcod = "310" Then
        '************************IMPRESION DE INFORME PARA ALUMNOS DE NM1 - NM2 - NM3 ******************
            cr_perso.ReportFileName = App.Path & "\rpt\informe_pre_eval310.rpt"
            cr_perso.WindowState = crptMaximized
            cr_perso.WindowTitle = "Informe De Desarrollo Personal y Social"
            cr_perso.ReplaceSelectionFormula ("")
            
            cr_perso.Formulas(0) = "colegio = '" & nombre & "'"
            cr_perso.Formulas(1) = "fecha = '" & Format(Now, "dd/mm/yyyy") & "'"
            cr_perso.Formulas(2) = "hora = '" & Format(Now, "hh:mm AM/PM") & "'"
            
            cr_perso.ReplaceSelectionFormula ("{pre_eval_cab.cod_ens}='" & xcod & "' and {pre_eval_cab.num_gra}='" & CInt(xnum_gra) & "' and {pre_eval_cab.let_cur}='" & xletra & "' and {pre_eval_cab.agno}=" & str(xagno)) & Per
            cr_perso.Destination = crptToWindow
            cr_perso.Action = 1
        '************************FIN IMPRESION DE INFORME PARA ALUMNOS DE NM1 - NM2 - NM3 ******************
            
        End If

End Sub

Private Sub cmd_limpiar_Click()
'    Dim var_sql As String
'    Dim objRS As ADODB.Recordset
'    Set objRS = New ADODB.Recordset
'
'    var_sql = "Select RUT_USU,right(cargo_usu,5) as marca,cargo_usu from usuarios where AUT_NOMBRE_USUARIO='" _
'    & Nom_usu_ses & "'"
'    objRS.Open var_sql, conn
'    rut_prof = objRS("rut_usu")
'    'marca = objRS("marca")
'    cargo = objRS("cargo_usu")
'    objRS.Close
    
'    If cargo = "DOCENTE" Then
'
'    Else
         Me.text2.Visible = False
        Btn_Ver_Lista.Enabled = True
        MSFlexGrid1.Rows = 2
        MSFlexGrid1.Cols = 2
        MSFlexGrid1.Clear
        text2.Visible = False
        Frame1.Enabled = True
    'End If
'    Call Set_IC_Agno
'    IC_Agno.Text = Anno
End Sub

Private Sub cmd_Salir_Click()
    Unload Me
End Sub

Private Sub Command1_Click()
    Dim mivariable As String
    Dim i As Integer
    Open "c:\ruts.txt" For Input As #1
    i = 0
    While Not EOF(1)
        i = i + 1
        Line Input #1, mivariable
        'MsgBox Mid(mivariable, 1, 8) & "-" & Mid(mivariable, 10, 1)
        var_sql = "insert into riesgo_social" _
                & " values('" & Mid(mivariable, 1, 8) & "-" & Mid(mivariable, 10, 1) & "',2007)"
        conn.Execute var_sql
        'Mid(mivariable, 1, 8) & "-" & Val(Mid(mivariable, 9))
       'If i = 3 Then Exit Sub
    Wend
    MsgBox "Listo"
    Close #1
End Sub

Private Sub Command2_Click()
    Dim periodo As Integer
    Dim var_sql As String
    Dim sw As Boolean
    sw = True
    Dim i As Integer
    Dim j As Integer
    
    cmd_Grabar_Click
    
    If IC_Periodo.Text = "Primer Semestre" Then
        periodo = 1
    Else
        periodo = 2
    End If
    
    For i = 1 To MSFlexGrid1.Rows - 1
        For j = 5 To MSFlexGrid1.Cols - 1
            If MSFlexGrid1.TextMatrix(i, j) = "" Then sw = False
        Next j
    Next i
    If sw = False Then
        MsgBox "Para poder cerrar el curso debe completar primero el informe de desarrollo y social para cada alumno", vbInformation
        Exit Sub
    End If
    var_sql = "update pre_eval_cab set estado = 'C'" _
            & " where agno = " & IC_Agno.Text & " and cod_ens = '" & Mid(IC_Ensenanza.SelectedItem.Key, 2) _
            & "' and num_gra = " & IC_Nivel.Text & " and let_cur = '" & IC_Letra.Text & "'" _
            & " and estado = 'A' and periodo = " & periodo
    conn.Execute var_sql
End Sub



Private Sub Form_Load()
    Dim i As Integer
    Dim rut_prof, cargo, marca As String
    Dim objRS As ADODB.Recordset
    Set objRS = New ADODB.Recordset
    Dim var_sql As String
    Form_pre_eval_evaluacion.Show
    'text2.SetFocus

    
    'text2.SetFocus
    'IC_Periodo.ComboItems.Add i, , REC!Let_Cur
    IC_Periodo.ComboItems.Add 1, , "Primer Semestre"
    IC_Periodo.ComboItems.Add 2, , "Segundo Semestre"
    IC_Periodo.Text = "Primer Semestre"
'    MsgBox IC_Periodo.ComboItems(1)
'    MsgBox IC_Periodo.Index
    Call Set_IC_Agno
'    var_sql = "Select RUT_USU,right(cargo_usu,5) as marca,cargo_usu from usuarios where AUT_NOMBRE_USUARIO='" _
'    & Nom_usu_ses & "'"
'    objRS.Open var_sql, conn
'    rut_prof = objRS("rut_usu")
'    marca = objRS("marca")
'    cargo = objRS("cargo_usu")
'    objRS.Close
'    If cargo = "DOCENTE" Then
'
'        var_sql = "select * from cursos where rut_prof = '" _
'        & rut_prof & "' and agno = " & Anno _
'        & " group by cod_ens"
'        objRS.Open var_sql, conn
'        IC_Ensenanza.ComboItems.Clear
'        i = 0
'        While Not objRS.EOF
'            i = i + 1
'            'IC_Letra.ComboItems.Add i, , REC!Let_Cur
'            IC_Ensenanza.ComboItems.Add i, , objRS("cod_ens")
'            objRS.MoveNext
'        Wend
'        objRS.Close
'
'        var_sql = "select * from cursos where rut_prof = '" _
'        & rut_prof & "' and agno = " & Anno _
'        & " group by num_gra"
'        objRS.Open var_sql, conn
'        IC_Nivel.ComboItems.Clear
'        i = 0
'        While Not objRS.EOF
'            i = i + 1
'            'IC_Letra.ComboItems.Add i, , REC!Let_Cur
'            IC_Nivel.ComboItems.Add i, , objRS("num_gra")
'            objRS.MoveNext
'        Wend
'        objRS.Close
'
'        var_sql = "select * from cursos where rut_prof = '" _
'        & rut_prof & "' and agno = " & Anno _
'        & " group by let_cur"
'        objRS.Open var_sql, conn
'        IC_Letra.ComboItems.Clear
'        i = 0
'        While Not objRS.EOF
'            i = i + 1
'            'IC_Letra.ComboItems.Add i, , REC!Let_Cur
'            IC_Letra.ComboItems.Add i, , objRS("let_cur")
'            objRS.MoveNext
'        Wend
'        objRS.Close
'
'    End If
    text2.AddItem ""
    
End Sub

Private Sub IC_Agno_Click()
'    Dim var_sql As String
'    Dim objRS As ADODB.Recordset
'    Set objRS = New ADODB.Recordset
'
'    var_sql = "Select RUT_USU,right(cargo_usu,5) as marca,cargo_usu from usuarios where AUT_NOMBRE_USUARIO='" _
'    & Nom_usu_ses & "'"
'    objRS.Open var_sql, conn
'    rut_prof = objRS("rut_usu")
'    'marca = objRS("marca")
'    cargo = objRS("cargo_usu")
'    objRS.Close
'
'    If cargo = "DOCENTE" Then
'        Exit Sub
'    End If
    
    IC_Ensenanza.Enabled = True
    Set_IC_Ensenanza
End Sub

Private Sub IC_Ensenanza_Click()
'    Dim var_sql As String
'    Dim objRS As ADODB.Recordset
'    Set objRS = New ADODB.Recordset
'
'    var_sql = "Select RUT_USU,right(cargo_usu,5) as marca,cargo_usu from usuarios where AUT_NOMBRE_USUARIO='" _
'    & Nom_usu_ses & "'"
'    objRS.Open var_sql, conn
'    rut_prof = objRS("rut_usu")
'    'marca = objRS("marca")
'    cargo = objRS("cargo_usu")
'    objRS.Close
'
'    If cargo = "DOCENTE" Then
'        Exit Sub
'    End If

    IC_Nivel.Enabled = True
    Call Set_IC_Nivel
End Sub

Private Sub IC_Nivel_Click()
'    Dim var_sql As String
'    Dim objRS As ADODB.Recordset
'    Set objRS = New ADODB.Recordset
'
'    var_sql = "Select RUT_USU,right(cargo_usu,5) as marca,cargo_usu from usuarios where AUT_NOMBRE_USUARIO='" _
'    & Nom_usu_ses & "'"
'    objRS.Open var_sql, conn
'    rut_prof = objRS("rut_usu")
'    'marca = objRS("marca")
'    cargo = objRS("cargo_usu")
'    objRS.Close
'
'    If cargo = "DOCENTE" Then
'        Exit Sub
'    End If

'    If Check_Letra.Value = 1 Then
        IC_Letra.Enabled = True
        Call Set_IC_Letra
'    End If
End Sub

Private Sub Set_IC_Agno()
    Dim agno As Integer
    agno = IIf(Year(Date) < 2005, 2005, Year(Date))
    IC_Agno.ComboItems.Clear
    For i = 1 To (agno - 2004) + 1
        IC_Agno.ComboItems.Add i, , str(i + 2004)
    Next i
    Set IC_Agno.SelectedItem = IC_Agno.ComboItems.Item(i - 2)
    ErrorStatus = False
    ' Llenar combo enseñanza
    IC_Ensenanza.Enabled = True
    IC_Nivel.Enabled = False
    IC_Letra.Enabled = False
    Call Set_IC_Ensenanza
End Sub

Private Sub Set_IC_Ensenanza()
    Dim REC As ADODB.Recordset
    Dim QRY As String
    Dim var_sql As String
    Dim rut_prof As String
    Dim cargo As String
    Dim objRS As ADODB.Recordset
    Set objRS = New ADODB.Recordset

    var_sql = "Select RUT_USU,right(cargo_usu,5) as marca,cargo_usu from usuarios where AUT_NOMBRE_USUARIO='" _
    & Nom_usu_ses & "'"
    objRS.Open var_sql, conn
    rut_prof = objRS("rut_usu")
    'marca = objRS("marca")
    cargo = objRS("cargo_usu")
    objRS.Close
    
    If cargo = "DOCENTE" Then
        QRY = "select DISTINCT c.cod_ens, ce.des_ens" _
            & " from cursos as c,codigos_ensenanza as ce" _
            & " where agno = " & IC_Agno.SelectedItem.Text & " and rut_prof = '" & rut_prof & "'" _
            & " and c.cod_ens=ce.cod_ens" _
            & " ORDER BY ce.ord_ens;"
    Else
        QRY = "SELECT DISTINCT m.cod_ens, ce.des_ens FROM matriculas as m, codigos_ensenanza as ce WHERE m.cod_ens=ce.cod_ens AND m.anno_mat=" & IC_Agno.SelectedItem.Text & " ORDER BY ce.ord_ens;"
    End If
        
    Set REC = New ADODB.Recordset
    REC.Open QRY, conn
    
    IC_Ensenanza.ComboItems.Clear
    If REC.RecordCount > 0 Then
        REC.MoveFirst
        For i = 1 To REC.RecordCount
            IC_Ensenanza.ComboItems.Add i, "K" & Format(REC!Cod_Ens, "000"), REC!des_ens
            REC.MoveNext
        Next i
        Set IC_Ensenanza.SelectedItem = IC_Ensenanza.ComboItems.Item(1)
        ErrorStatus = False
        ' Llenar Siguiente Combo.
        IC_Nivel.Enabled = True
        IC_Letra.Enabled = False
        Call Set_IC_Nivel
    Else
        ErrorStatus = True
        IC_Ensenanza.Enabled = False
        IC_Nivel.Enabled = False
        IC_Letra.Enabled = False
    End If
    REC.Close
End Sub

Private Sub Set_IC_Nivel()
    Dim REC As ADODB.Recordset
    Dim QRY As String
    Dim var_sql As String
    Dim rut_prof As String
    Dim cargo As String
    Dim objRS As ADODB.Recordset
    Set objRS = New ADODB.Recordset

    var_sql = "Select RUT_USU,right(cargo_usu,5) as marca,cargo_usu from usuarios where AUT_NOMBRE_USUARIO='" _
    & Nom_usu_ses & "'"
    objRS.Open var_sql, conn
    rut_prof = objRS("rut_usu")
    'marca = objRS("marca")
    cargo = objRS("cargo_usu")
    objRS.Close
    
    If cargo = "DOCENTE" Then
        QRY = "select DISTINCT c.num_gra" _
            & " from cursos as c,codigos_ensenanza as ce" _
            & " where agno = " & IC_Agno.SelectedItem.Text _
            & " and rut_prof = '" & rut_prof & "' and c.cod_ens='" & Mid(IC_Ensenanza.SelectedItem.Key, 2) & "'" _
            & " and c.cod_ens=ce.cod_ens" _
            & " ORDER BY ce.ord_ens;"
    Else
        QRY = "SELECT DISTINCT m.num_gra FROM matriculas as m WHERE m.cod_ens='" & Mid(IC_Ensenanza.SelectedItem.Key, 2) & "' AND m.anno_mat=" & IC_Agno.SelectedItem.Text & " ORDER BY m.num_gra;"
    End If
    
    

   ' QRY = "SELECT DISTINCT m.num_gra FROM matriculas as m WHERE m.cod_ens='" & Mid(IC_Ensenanza.SelectedItem.Key, 2) & "' AND m.anno_mat=" & IC_Agno.SelectedItem.Text & " ORDER BY m.num_gra;"
    Set REC = New ADODB.Recordset
    REC.Open QRY, conn
    
    IC_Nivel.ComboItems.Clear
    If REC.RecordCount > 0 Then
        REC.MoveFirst
        For i = 1 To REC.RecordCount
            IC_Nivel.ComboItems.Add i, , str(REC!Num_Gra)
            REC.MoveNext
        Next i
        Set IC_Nivel.SelectedItem = IC_Nivel.ComboItems.Item(1)
        ErrorStatus = False
        ' Llenar Siguiente Combo.
        If Check_Letra.Value = 1 Then
            IC_Letra.Enabled = True
            Call Set_IC_Letra
        End If
    Else
        ErrorStatus = True
        IC_Nivel.Enabled = False
        IC_Letra.Enabled = False
    End If
    REC.Close
End Sub

Private Sub Check_Letra_Click()
    If Check_Letra.Value = 0 Then
        IC_Letra.Enabled = False
    ElseIf Check_Letra.Value = 1 And Not (ErrorStatus) And IC_Ensenanza.Enabled And IC_Nivel.Enabled Then
        IC_Letra.Enabled = True
        Call Set_IC_Letra
    Else
        Check_Letra.Value = 0
        IC_Letra.Enabled = False
    End If
End Sub

Private Sub Set_IC_Letra()
    Dim REC As ADODB.Recordset
    Dim QRY As String
    Dim var_sql As String
    Dim rut_prof As String
    Dim cargo As String
    Dim objRS As ADODB.Recordset
    Set objRS = New ADODB.Recordset
    
    
  '  If Check_Letra.Value = 1 Then
    
        var_sql = "Select RUT_USU,right(cargo_usu,5) as marca,cargo_usu from usuarios where AUT_NOMBRE_USUARIO='" _
                & Nom_usu_ses & "'"
        objRS.Open var_sql, conn
        rut_prof = objRS("rut_usu")
        'marca = objRS("marca")
        cargo = objRS("cargo_usu")
        objRS.Close
        IC_Letra.ComboItems.Clear
        IC_Letra.Text = ""
        
        If cargo = "DOCENTE" Then
            QRY = "select DISTINCT c.let_cur" _
                & " from cursos as c,codigos_ensenanza as ce" _
                & " where agno = " & Trim(IC_Agno.SelectedItem.Text) _
                & " and rut_prof = '" & rut_prof & "' and c.cod_ens='" _
                & Mid(IC_Ensenanza.SelectedItem.Key, 2) & "' AND c.num_gra='" _
                & Trim(IC_Nivel.SelectedItem.Text) & "'" _
                & " and c.cod_ens=ce.cod_ens" _
                & " ORDER BY ce.ord_ens;"
        Else
            QRY = "SELECT DISTINCT m.let_cur FROM alu_x_cur as m WHERE m.cod_ens='" & Mid(IC_Ensenanza.SelectedItem.Key, 2) & "' AND m.agno=" & Trim(IC_Agno.SelectedItem.Text) & " AND m.num_gra='" & Trim(IC_Nivel.SelectedItem.Text) & "' ORDER BY m.num_gra;"
        End If
        
        Set REC = New ADODB.Recordset
        REC.Open QRY, conn
        If REC.RecordCount > 0 Then
            REC.MoveFirst
            For i = 1 To REC.RecordCount
                IC_Letra.ComboItems.Add i, , REC!Let_Cur
                REC.MoveNext
            Next i
            Set IC_Letra.SelectedItem = IC_Letra.ComboItems.Item(1)
            ErrorStatus = False
            ' Llenar Siguiente Combo.
        Else
            ErrorStatus = True
            Check_Letra.Value = 0
            IC_Letra.Enabled = False
        End If
        REC.Close
'    Else
'        ErrorStatus = False
'        IC_Letra.Enabled = False
'    End If
End Sub

Private Sub MSFlexGrid1_Click()
    Dim var_sql, t_item As String
    Dim periodo As Integer
    Dim objRS As ADODB.Recordset
    Set objRS = New ADODB.Recordset
    If MSFlexGrid1.Row < 1 Or MSFlexGrid1.Row > MSFlexGrid1.Rows - 1 Then Exit Sub
    txt_observacion.Text = MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, MSFlexGrid1.Cols - 1)
    If IC_Periodo.Text = "Primer Semestre" Then
        periodo = 1
    Else
        periodo = 2
    End If
    var_sql = "select * from pre_eval_cab" _
            & " where agno = " & IC_Agno.Text & " and cod_ens = '" _
            & Mid(IC_Ensenanza.SelectedItem.Key, 2) _
            & "' and num_gra = " _
            & IC_Nivel.Text & " and let_cur = '" & IC_Letra.Text & "'" _
            & " and estado = 'C' and ci_alu = '" & MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, 0) & "' and periodo = " & periodo
    objRS.Open var_sql, conn
    If Not objRS.EOF Then
        MsgBox "No se puede modificar este informe, debido a que ya fue cerrado", vbInformation
        objRS.Close
        txt_observacion.Locked = True
        Exit Sub
    End If
    'objRS.Close
'    text2.Text = ""
   ' GridEdit Asc(" ")
    txt_observacion.Locked = False
End Sub

Private Sub MSFlexGrid1_DblClick()
    Dim periodo As Integer
    Dim mat(100) As Integer
    Dim i As Integer
    Dim n_item As Integer
    Dim var_sql, t_item As String
    Dim objRS As ADODB.Recordset
    Set objRS = New ADODB.Recordset
    If MSFlexGrid1.Row < 1 Or MSFlexGrid1.Row > MSFlexGrid1.Rows - 1 Then Exit Sub
    'txt_observacion.Text = MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, MSFlexGrid1.Cols - 1)
    If MSFlexGrid1.Col < 5 Or MSFlexGrid1.Col > MSFlexGrid1.Cols - 2 Then Exit Sub
    
    var_sql = "Select pre_eval_formato_inf_agno.t_item,pre_eval_formato_inf_agno.n_item" _
            & " from pre_eval_formato_inf_agno join `pre_eval_item_des`" _
            & " where pre_eval_formato_inf_agno.cod_ens='" & Mid(IC_Ensenanza.SelectedItem.Key, 2) _
            & "' and pre_eval_formato_inf_agno.num_gra='" & CInt(IC_Nivel.Text) _
            & "' and pre_eval_formato_inf_agno.n_item=pre_eval_item_des.n_item" _
            & " and pre_eval_formato_inf_agno.t_item=pre_eval_item_des.t_item and agno = " & IC_Agno.Text _
            & " and `pre_eval_item_des`.cod_ens = '" & Mid(IC_Ensenanza.SelectedItem.Key, 2) & "' order by t_item,n_item"
    objRS.Open var_sql, conn
    i = 0
    While Not objRS.EOF
        i = i + 1
        mat(i) = objRS("n_item")
        objRS.MoveNext
    Wend
    objRS.Close
    
    'If MSFlexGrid1.Col < 5 Or MSFlexGrid1.Col > MSFlexGrid1.Cols - 2 Then
    If MSFlexGrid1.TextMatrix(1, 3) <> "" Then
    If CInt(MSFlexGrid1.Col) >= CInt(MSFlexGrid1.TextMatrix(1, 3)) And CInt(MSFlexGrid1.Col) <= CInt(MSFlexGrid1.TextMatrix(1, 4)) Then
        t_item = MSFlexGrid1.TextMatrix(1, 2)
        'n_item = MSFlexGrid1.TextMatrix(0, MSFlexGrid1.Col)
        n_item = mat(MSFlexGrid1.TextMatrix(0, MSFlexGrid1.Col))
    End If
    End If
    
    If MSFlexGrid1.TextMatrix(2, 3) <> "" Then
    If CInt(MSFlexGrid1.Col) >= MSFlexGrid1.TextMatrix(2, 3) And CInt(MSFlexGrid1.Col) <= MSFlexGrid1.TextMatrix(2, 4) Then
            t_item = MSFlexGrid1.TextMatrix(2, 2)
            'n_item = MSFlexGrid1.Col - MSFlexGrid1.TextMatrix(1, 4)
            n_item = mat(MSFlexGrid1.TextMatrix(0, MSFlexGrid1.Col))
    End If
    End If
    
    If MSFlexGrid1.TextMatrix(3, 3) <> "" Then
    If CInt(MSFlexGrid1.Col) >= MSFlexGrid1.TextMatrix(3, 3) And CInt(MSFlexGrid1.Col) <= MSFlexGrid1.TextMatrix(3, 4) Then
            t_item = MSFlexGrid1.TextMatrix(3, 2)
            'n_item = MSFlexGrid1.Col - MSFlexGrid1.TextMatrix(2, 4)
            n_item = mat(MSFlexGrid1.TextMatrix(0, MSFlexGrid1.Col))
    End If
    End If
    
    If MSFlexGrid1.TextMatrix(4, 3) <> "" Then
        If CInt(MSFlexGrid1.Col) >= MSFlexGrid1.TextMatrix(4, 3) And CInt(MSFlexGrid1.Col) <= MSFlexGrid1.TextMatrix(4, 4) Then
            t_item = MSFlexGrid1.TextMatrix(4, 2)
            'n_item = MSFlexGrid1.Col - MSFlexGrid1.TextMatrix(3, 4)
            n_item = mat(MSFlexGrid1.TextMatrix(0, MSFlexGrid1.Col))
        End If
    End If
    
    If MSFlexGrid1.TextMatrix(5, 3) <> "" Then
        If CInt(MSFlexGrid1.Col) >= CInt(MSFlexGrid1.TextMatrix(5, 3)) And CInt(MSFlexGrid1.Col) <= CInt(MSFlexGrid1.TextMatrix(5, 4)) Then
            t_item = MSFlexGrid1.TextMatrix(5, 2)
            'n_item = MSFlexGrid1.Col - MSFlexGrid1.TextMatrix(4, 4)
            n_item = mat(MSFlexGrid1.TextMatrix(0, MSFlexGrid1.Col))
        End If
    End If
    
    If MSFlexGrid1.TextMatrix(6, 3) <> "" Then
        If CInt(MSFlexGrid1.Col) >= CInt(MSFlexGrid1.TextMatrix(6, 3)) And CInt(MSFlexGrid1.Col) <= CInt(MSFlexGrid1.TextMatrix(6, 4)) Then
            t_item = MSFlexGrid1.TextMatrix(6, 2)
            'n_item = MSFlexGrid1.Col - MSFlexGrid1.TextMatrix(4, 4)
            n_item = mat(MSFlexGrid1.TextMatrix(0, MSFlexGrid1.Col))
        End If
    End If
    
    If MSFlexGrid1.TextMatrix(7, 3) <> "" Then
        If CInt(MSFlexGrid1.Col) >= CInt(MSFlexGrid1.TextMatrix(7, 3)) And CInt(MSFlexGrid1.Col) <= CInt(MSFlexGrid1.TextMatrix(7, 4)) Then
            t_item = MSFlexGrid1.TextMatrix(7, 2)
            'n_item = MSFlexGrid1.Col - MSFlexGrid1.TextMatrix(4, 4)
            n_item = mat(MSFlexGrid1.TextMatrix(0, MSFlexGrid1.Col))
        End If
    End If
    
    If MSFlexGrid1.TextMatrix(8, 3) <> "" Then
        If CInt(MSFlexGrid1.Col) >= CInt(MSFlexGrid1.TextMatrix(8, 3)) And CInt(MSFlexGrid1.Col) <= CInt(MSFlexGrid1.TextMatrix(8, 4)) Then
            t_item = MSFlexGrid1.TextMatrix(8, 2)
            'n_item = MSFlexGrid1.Col - MSFlexGrid1.TextMatrix(4, 4)
            n_item = mat(MSFlexGrid1.TextMatrix(0, MSFlexGrid1.Col))
        End If
    End If
    
    If MSFlexGrid1.TextMatrix(9, 3) <> "" Then
        If CInt(MSFlexGrid1.Col) >= CInt(MSFlexGrid1.TextMatrix(9, 3)) And CInt(MSFlexGrid1.Col) <= CInt(MSFlexGrid1.TextMatrix(9, 4)) Then
            t_item = MSFlexGrid1.TextMatrix(9, 2)
            'n_item = MSFlexGrid1.Col - MSFlexGrid1.TextMatrix(4, 4)
            n_item = mat(MSFlexGrid1.TextMatrix(0, MSFlexGrid1.Col))
        End If
    End If
    
    
    'End If
    'text2.Style = 0
    n_item = mat(MSFlexGrid1.TextMatrix(0, MSFlexGrid1.Col))
    
    text2.ListIndex = 0
    For i = 1 To text2.ListCount - 1
    If text2.List(i) = MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, MSFlexGrid1.Col) Then
        text2.ListIndex = i
        Exit For
    End If
    Next i
    
    
    'text2.Style 2
        
'    Select Case MSFlexGrid1.Col
'        Case CInt(MSFlexGrid1.Col) >= CInt(MSFlexGrid1.TextMatrix(1, 3)) And CInt(MSFlexGrid1.Col) <= CInt(MSFlexGrid1.TextMatrix(1, 4))
'            t_item = MSFlexGrid1.TextMatrix(1, 2)
'            n_item = MSFlexGrid1.TextMatrix(0, MSFlexGrid1.Col)
'        Case MSFlexGrid1.Col >= MSFlexGrid1.TextMatrix(2, 3) And MSFlexGrid1.Col <= MSFlexGrid1.TextMatrix(2, 4)
'            t_item = MSFlexGrid1.TextMatrix(2, 2)
'            n_item = MSFlexGrid1.TextMatrix(0, MSFlexGrid1.Col) - MSFlexGrid1.TextMatrix(1, 4)
'        Case MSFlexGrid1.Col >= MSFlexGrid1.TextMatrix(3, 3) And MSFlexGrid1.Col <= MSFlexGrid1.TextMatrix(3, 4)
'            t_item = MSFlexGrid1.TextMatrix(3, 2)
'            n_item = MSFlexGrid1.TextMatrix(0, MSFlexGrid1.Col) - MSFlexGrid1.TextMatrix(2, 4)
'        Case MSFlexGrid1.Col >= MSFlexGrid1.TextMatrix(4, 3) And MSFlexGrid1.Col <= MSFlexGrid1.TextMatrix(4, 4)
'            t_item = MSFlexGrid1.TextMatrix(4, 2)
'            n_item = MSFlexGrid1.TextMatrix(0, MSFlexGrid1.Col) - MSFlexGrid1.TextMatrix(3, 4)
'    End Select
        
    'If MSFlexGrid1.Col < 5 Or MSFlexGrid1.Col > MSFlexGrid1.Cols - 2 Then
    var_sql = "select * from pre_eval_item_des where t_item = '" & t_item & "' and n_item = " & n_item
    objRS.Open var_sql, conn
    Label4.Caption = objRS("descripcion")
    objRS.Close
    'End If
    
    'Dim i As Integer
'    var_sql = "select * from pre_eval_crit_eval_nivel" _
'            & " where cod_ens = '" & Mid(IC_Ensenanza.SelectedItem.Key, 2) & "' and num_gra = " & IC_Nivel.Text

    
'    For i = 1 To 10
'        text2.AddItem "Hola" & i & i & i
'    Next i

    If IC_Periodo.Text = "Primer Semestre" Then
        periodo = 1
    Else
        periodo = 2
    End If
    var_sql = "select * from pre_eval_cab" _
            & " where agno = " & IC_Agno.Text & " and cod_ens = '" _
            & Mid(IC_Ensenanza.SelectedItem.Key, 2) _
            & "' and num_gra = " _
            & IC_Nivel.Text & " and let_cur = '" & IC_Letra.Text & "'" _
            & " and estado = 'C' and ci_alu = '" & MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, 0) & "'" _
            & " and periodo = " & periodo
    objRS.Open var_sql, conn
    If Not objRS.EOF Then
        MsgBox "No se puede modificar este informe, debido a que ya fue cerrado", vbInformation
        objRS.Close
        txt_observacion.Locked = True
        Exit Sub
    End If
    objRS.Close
'    text2.Text = ""
    GridEdit Asc(" ")
    txt_observacion.Locked = False
    
End Sub

Private Sub MSFlexGrid1_KeyPress(KeyAscii As Integer)
  If KeyAscii = 13 Then MSFlexGrid1_DblClick
  GridEdit KeyAscii
End Sub

Sub GridEdit(KeyAscii As Integer)
   ' On Error Resume Next
  'emplear la fuente correcta
  text2.FontName = MSFlexGrid1.FontName
  text2.FontSize = MSFlexGrid1.FontSize
  Select Case KeyAscii
    Case 0 To Asc(" ")
         'text2 = MSFlexGrid1
         'text2.SelStart = 1000
    Case Else
         text2 = Chr(KeyAscii)
         text2.SelStart = 1
  End Select
  'posicionar el textbox
  text2.Left = MSFlexGrid1.CellLeft + MSFlexGrid1.Left
  text2.Top = MSFlexGrid1.CellTop + MSFlexGrid1.Top
  text2.Width = MSFlexGrid1.CellWidth
'  text2.Height = MSFlexGrid1.CellHeight
  text2.Visible = True
  text2.Enabled = True
  'text2.Clear
  Form_pre_eval_evaluacion.Show
  Me.text2.SetFocus
End Sub

Private Sub MSFlexGrid1_LeaveCell()
  If text2.Visible Then
     'If text2 <> "" Then
        MSFlexGrid1 = text2
     'End If
     text2.Visible = False
     'valida_grilla
  End If
End Sub

Private Sub MSFlexGrid1_Scroll()
    text2.Visible = False
End Sub

Private Sub text2_KeyDown(KeyCode As Integer, Shift As Integer)
  Select Case KeyCode
    Case vbKeyEscape
      text2.Visible = False
      MSFlexGrid1.SetFocus
    Case vbKeyReturn
      MSFlexGrid1.SetFocus
    Case vbKeyDown
      MSFlexGrid1.SetFocus
      DoEvents
      If MSFlexGrid1.Row < MSFlexGrid1.Rows - 1 Then
         MSFlexGrid1.Row = MSFlexGrid1.Row + 1
      End If
    Case vbKeyUp
      MSFlexGrid1.SetFocus
      DoEvents
      If MSFlexGrid1.Row > MSFlexGrid1.FixedRows Then
         MSFlexGrid1.Row = MSFlexGrid1.Row - 1
      End If
  End Select
End Sub

Private Sub Text2_KeyPress(KeyAscii As Integer)
  'suppresión del beep
  If KeyAscii = vbKeyReturn Then KeyAscii = 0
End Sub

Private Sub Timer1_Timer()
        If text2.Enabled = True Then
             text2.SetFocus
        Else
             MsgBox "NO"
        End If
End Sub
        


Private Sub txt_observacion_Change()
    Dim periodo As Integer
    Dim var_sql As String
    Dim objRS As ADODB.Recordset
    Set objRS = New ADODB.Recordset
    If IC_Periodo.Text = "Primer Semestre" Then
        periodo = 1
    Else
        periodo = 2
    End If
    var_sql = "select * from pre_eval_cab" _
            & " where agno = " & IC_Agno.Text & " and cod_ens = '" _
            & Mid(IC_Ensenanza.SelectedItem.Key, 2) _
            & "' and num_gra = " _
            & IC_Nivel.Text & " and let_cur = '" & IC_Letra.Text & "'" _
            & " and estado = 'C' and ci_alu = '" & MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, 0) & "' and periodo = " & periodo
    objRS.Open var_sql, conn
    If Not objRS.EOF Then
        MsgBox "No se puede modificar este informe, debido a que ya fue cerrado", vbInformation
        Exit Sub
    End If
    objRS.Close
    MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, MSFlexGrid1.Cols - 1) = txt_observacion.Text
   ' txt_observacion.Locked = True
End Sub

Private Sub txt_observacion_LostFocus()
    txt_observacion.Locked = True
End Sub


