VERSION 5.00
Object = "{BDC217C8-ED16-11CD-956C-0000C04E4C0A}#1.1#0"; "TABCTL32.OCX"
Object = "{5E9E78A0-531B-11CF-91F6-C2863C385E30}#1.0#0"; "MSFLXGRD.OCX"
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.2#0"; "MSCOMCTL.OCX"
Begin VB.Form Form_pre_eval_relacion_Semestre 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Ambito Relación Natural y Cultural"
   ClientHeight    =   6930
   ClientLeft      =   45
   ClientTop       =   435
   ClientWidth     =   10890
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MDIChild        =   -1  'True
   MinButton       =   0   'False
   ScaleHeight     =   6930
   ScaleWidth      =   10890
   Begin VB.Frame Frame1 
      Caption         =   "Detalles del Nivel, Curso y Año a Definir"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00C00000&
      Height          =   6735
      Left            =   120
      TabIndex        =   0
      Top             =   120
      Width           =   10695
      Begin TabDlg.SSTab SSTab1 
         Height          =   5655
         Left            =   120
         TabIndex        =   1
         Top             =   960
         Width           =   10485
         _ExtentX        =   18494
         _ExtentY        =   9975
         _Version        =   393216
         TabOrientation  =   1
         Tabs            =   4
         Tab             =   1
         TabHeight       =   706
         TabMaxWidth     =   5644
         ForeColor       =   -2147483640
         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
         TabCaption(0)   =   "&Núcleo seres vivos y su entorno"
         TabPicture(0)   =   "Form_pre_eval_relacion_Semestre.frx":0000
         Tab(0).ControlEnabled=   0   'False
         Tab(0).Control(0)=   "MSFlexGrid1(0)"
         Tab(0).Control(1)=   "Command1(5)"
         Tab(0).Control(2)=   "Command2(0)"
         Tab(0).Control(3)=   "Command3(0)"
         Tab(0).ControlCount=   4
         TabCaption(1)   =   "&Grupos humanos"
         TabPicture(1)   =   "Form_pre_eval_relacion_Semestre.frx":001C
         Tab(1).ControlEnabled=   -1  'True
         Tab(1).Control(0)=   "MSFlexGrid1(1)"
         Tab(1).Control(0).Enabled=   0   'False
         Tab(1).Control(1)=   "Command1(6)"
         Tab(1).Control(1).Enabled=   0   'False
         Tab(1).Control(2)=   "Command2(1)"
         Tab(1).Control(2).Enabled=   0   'False
         Tab(1).Control(3)=   "Command3(3)"
         Tab(1).Control(3).Enabled=   0   'False
         Tab(1).ControlCount=   4
         TabCaption(2)   =   "&Núcleo relaciones lógico matemáticas y cuantificación"
         TabPicture(2)   =   "Form_pre_eval_relacion_Semestre.frx":0038
         Tab(2).ControlEnabled=   0   'False
         Tab(2).Control(0)=   "MSFlexGrid1(2)"
         Tab(2).Control(1)=   "Command1(7)"
         Tab(2).Control(2)=   "Command2(2)"
         Tab(2).Control(3)=   "Command3(2)"
         Tab(2).ControlCount=   4
         TabCaption(3)   =   "&Participación de la familia en cuanto a:"
         TabPicture(3)   =   "Form_pre_eval_relacion_Semestre.frx":0054
         Tab(3).ControlEnabled=   0   'False
         Tab(3).Control(0)=   "MSFlexGrid1(3)"
         Tab(3).Control(1)=   "Command1(1)"
         Tab(3).Control(2)=   "Command2(3)"
         Tab(3).Control(3)=   "Command3(1)"
         Tab(3).ControlCount=   4
         Begin VB.CommandButton Command3 
            Caption         =   "Borrar"
            Height          =   855
            Index           =   3
            Left            =   9240
            TabIndex        =   23
            Top             =   2040
            Visible         =   0   'False
            Width           =   855
         End
         Begin VB.CommandButton Command3 
            Caption         =   "Borrar"
            Height          =   855
            Index           =   2
            Left            =   -65760
            TabIndex        =   22
            Top             =   2040
            Visible         =   0   'False
            Width           =   855
         End
         Begin VB.CommandButton Command3 
            Caption         =   "Borrar"
            Height          =   855
            Index           =   1
            Left            =   -65760
            TabIndex        =   21
            Top             =   2040
            Visible         =   0   'False
            Width           =   855
         End
         Begin VB.CommandButton Command3 
            Caption         =   "Borrar"
            Height          =   855
            Index           =   0
            Left            =   -65760
            TabIndex        =   20
            Top             =   2280
            Visible         =   0   'False
            Width           =   855
         End
         Begin VB.CommandButton Command2 
            Caption         =   "Agregar"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   855
            Index           =   3
            Left            =   -65760
            Picture         =   "Form_pre_eval_relacion_Semestre.frx":0070
            Style           =   1  'Graphical
            TabIndex        =   18
            ToolTipText     =   "Nuevo Item"
            Top             =   120
            Width           =   855
         End
         Begin VB.CommandButton Command1 
            Caption         =   "Guardar"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   855
            Index           =   1
            Left            =   -65760
            Picture         =   "Form_pre_eval_relacion_Semestre.frx":0610
            Style           =   1  'Graphical
            TabIndex        =   17
            ToolTipText     =   "GrabarTodo"
            Top             =   1080
            Width           =   855
         End
         Begin VB.CommandButton Command2 
            Caption         =   "Agregar"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   855
            Index           =   0
            Left            =   -65760
            Picture         =   "Form_pre_eval_relacion_Semestre.frx":0C69
            Style           =   1  'Graphical
            TabIndex        =   7
            ToolTipText     =   "Nuevo Item"
            Top             =   120
            Width           =   855
         End
         Begin VB.CommandButton Command2 
            Caption         =   "Agregar"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   855
            Index           =   1
            Left            =   9240
            Picture         =   "Form_pre_eval_relacion_Semestre.frx":1209
            Style           =   1  'Graphical
            TabIndex        =   6
            ToolTipText     =   "Nuevo Item"
            Top             =   120
            Width           =   855
         End
         Begin VB.CommandButton Command2 
            Caption         =   "Agregar"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   855
            Index           =   2
            Left            =   -65760
            Picture         =   "Form_pre_eval_relacion_Semestre.frx":17A9
            Style           =   1  'Graphical
            TabIndex        =   5
            ToolTipText     =   "Nuevo Item"
            Top             =   120
            Width           =   855
         End
         Begin VB.CommandButton Command1 
            Caption         =   "Guardar"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   855
            Index           =   5
            Left            =   -65760
            Picture         =   "Form_pre_eval_relacion_Semestre.frx":1D49
            Style           =   1  'Graphical
            TabIndex        =   4
            ToolTipText     =   "GrabarTodo"
            Top             =   1200
            Width           =   855
         End
         Begin VB.CommandButton Command1 
            Caption         =   "Guardar"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   855
            Index           =   6
            Left            =   9240
            Picture         =   "Form_pre_eval_relacion_Semestre.frx":23A2
            Style           =   1  'Graphical
            TabIndex        =   3
            ToolTipText     =   "GrabarTodo"
            Top             =   1080
            Width           =   855
         End
         Begin VB.CommandButton Command1 
            Caption         =   "Guardar"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   855
            Index           =   7
            Left            =   -65760
            Picture         =   "Form_pre_eval_relacion_Semestre.frx":29FB
            Style           =   1  'Graphical
            TabIndex        =   2
            ToolTipText     =   "GrabarTodo"
            Top             =   1080
            Width           =   855
         End
         Begin MSFlexGridLib.MSFlexGrid MSFlexGrid1 
            Height          =   4575
            Index           =   0
            Left            =   -74880
            TabIndex        =   8
            Top             =   120
            Width           =   9015
            _ExtentX        =   15901
            _ExtentY        =   8070
            _Version        =   393216
            Cols            =   7
            FixedCols       =   0
            WordWrap        =   -1  'True
            TextStyleFixed  =   3
            FocusRect       =   2
            FillStyle       =   1
            ScrollBars      =   2
            SelectionMode   =   1
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
         End
         Begin MSFlexGridLib.MSFlexGrid MSFlexGrid1 
            Height          =   4575
            Index           =   1
            Left            =   120
            TabIndex        =   9
            Top             =   120
            Width           =   9015
            _ExtentX        =   15901
            _ExtentY        =   8070
            _Version        =   393216
            Cols            =   7
            FixedCols       =   0
            WordWrap        =   -1  'True
            TextStyleFixed  =   3
            FocusRect       =   2
            ScrollBars      =   2
            SelectionMode   =   1
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
         End
         Begin MSFlexGridLib.MSFlexGrid MSFlexGrid1 
            Height          =   4575
            Index           =   2
            Left            =   -74880
            TabIndex        =   10
            Top             =   120
            Width           =   9015
            _ExtentX        =   15901
            _ExtentY        =   8070
            _Version        =   393216
            Cols            =   7
            FixedCols       =   0
            WordWrap        =   -1  'True
            TextStyleFixed  =   3
            FocusRect       =   2
            ScrollBars      =   2
            SelectionMode   =   1
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
         End
         Begin MSFlexGridLib.MSFlexGrid MSFlexGrid1 
            Height          =   4575
            Index           =   3
            Left            =   -74880
            TabIndex        =   19
            Top             =   120
            Width           =   9015
            _ExtentX        =   15901
            _ExtentY        =   8070
            _Version        =   393216
            Cols            =   7
            FixedCols       =   0
            WordWrap        =   -1  'True
            TextStyleFixed  =   3
            FocusRect       =   2
            ScrollBars      =   2
            SelectionMode   =   1
            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
      Begin MSComctlLib.ImageCombo IC_CodEns 
         Height          =   345
         Index           =   0
         Left            =   1440
         TabIndex        =   11
         Top             =   360
         Width           =   3495
         _ExtentX        =   6165
         _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_CodEns 
         Height          =   345
         Index           =   1
         Left            =   5760
         TabIndex        =   12
         Top             =   360
         Width           =   975
         _ExtentX        =   1720
         _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_CodEns 
         Height          =   345
         Index           =   2
         Left            =   7560
         TabIndex        =   13
         Top             =   360
         Width           =   1335
         _ExtentX        =   2355
         _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 Label1 
         Alignment       =   2  'Center
         AutoSize        =   -1  'True
         Caption         =   "Enseñanza :"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   9.75
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   240
         Index           =   0
         Left            =   210
         TabIndex        =   16
         Top             =   360
         Width           =   1125
      End
      Begin VB.Label Label1 
         Alignment       =   2  'Center
         AutoSize        =   -1  'True
         Caption         =   "Nivel :"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   9.75
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   240
         Index           =   1
         Left            =   5115
         TabIndex        =   15
         Top             =   360
         Width           =   555
      End
      Begin VB.Label Label1 
         Alignment       =   2  'Center
         AutoSize        =   -1  'True
         Caption         =   "Año :"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   9.75
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   240
         Index           =   2
         Left            =   6990
         TabIndex        =   14
         Top             =   360
         Width           =   495
      End
   End
End
Attribute VB_Name = "Form_pre_eval_relacion_Semestre"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False

Function estaono(sql As String) As Boolean
    Dim found As Integer
    Dim verificado As ADODB.Recordset
    
    Set verificado = New ADODB.Recordset
    
    verificado.Open sql, conn
    found = verificado!sn
    If found = 1 Then
        estaono = True
    Else
        estaono = False
    End If
    verificado.Close
End Function


Private Sub Command1_Click(Index As Integer)
    If Index <= 3 Then
        
    Else
    
        Command3_Click (1)
        
        Dim teSt As String
        teSt = Tipo_Item_Formacion
        Tipo_Item_Formacion = "NSV"
        buscarygrabar MSFlexGrid1(0)
        Tipo_Item_Formacion = "GH"
        buscarygrabar MSFlexGrid1(1)
        Tipo_Item_Formacion = "NRM"
        buscarygrabar MSFlexGrid1(2)
        Tipo_Item_Formacion = "PF"
        buscarygrabar MSFlexGrid1(3)
'        Tipo_Item_Formacion = "CFC"
'        buscarygrabar MSFlexGrid1(4)
    '    Tipo_Item_Formacion = Trim(teSt)
    End If
        
End Sub

Private Sub Command2_Click(Index As Integer)
    verificatipo
    Load Form_pre_eval_Add_Item_Semestre
    Form_pre_eval_Add_Item_Semestre.Show
    Me.Enabled = False
End Sub

Private Sub Command3_Click(Index As Integer)
     Num_Gra = IC_CodEns(1).Text
    Cod_Ens = Mid(IC_CodEns(0).SelectedItem.Key, 2)
    agno = IC_CodEns(2).Text
    
    SSTab1.Tab = 0
    Tipo_Item = "NSV"
    
    ambito = Mid(SSTab1.Caption, Len(SSTab1.Caption))
    num_item = MSFlexGrid1(SSTab1.Tab).TextMatrix(MSFlexGrid1(SSTab1.Tab).Row, 3)
    confirma = MSFlexGrid1(SSTab1.Tab).TextMatrix(MSFlexGrid1(SSTab1.Tab).Row, 5)
 
    For i = 1 To (MSFlexGrid1(SSTab1.Tab).Rows - 1)
        num_item = MSFlexGrid1(SSTab1.Tab).TextMatrix(i, 3)
        confirma = MSFlexGrid1(SSTab1.Tab).TextMatrix(i, 5)
        If confirma = "NO" Then
            var_sql = "delete from pre_sem_eval_item_deta" _
                    & " where t_item = '" & Tipo_Item & "' and n_item = " & num_item & " and folio_persoc in" _
                    & " (select folio_persoc from pre_sem_eval_cab where agno = " & agno _
                    & " and cod_ens = '" & Cod_Ens & "' and num_gra = " & Num_Gra & ")" '_
                    '& " and t_item = '" & Tipo_Item & "' and n_item = " & num_item
        conn.Execute var_sql
        End If
    Next i
             
    SSTab1.Tab = 1
    Tipo_Item = "GH"
    
    ambito = Mid(SSTab1.Caption, Len(SSTab1.Caption))
    num_item = MSFlexGrid1(SSTab1.Tab).TextMatrix(MSFlexGrid1(SSTab1.Tab).Row, 3)
    confirma = MSFlexGrid1(SSTab1.Tab).TextMatrix(MSFlexGrid1(SSTab1.Tab).Row, 5)
 
    For i = 1 To (MSFlexGrid1(SSTab1.Tab).Rows - 1)
        num_item = MSFlexGrid1(SSTab1.Tab).TextMatrix(i, 3)
        confirma = MSFlexGrid1(SSTab1.Tab).TextMatrix(i, 5)
        If confirma = "NO" Then
            var_sql = "delete from pre_sem_eval_item_deta" _
                    & " where t_item = '" & Tipo_Item & "' and n_item = " & num_item & " and folio_persoc in" _
                    & " (select folio_persoc from pre_sem_eval_cab where agno = " & agno _
                    & " and cod_ens = '" & Cod_Ens & "' and num_gra = " & Num_Gra & ")" '_
                    '& " and t_item = '" & Tipo_Item & "' and n_item = " & num_item
        conn.Execute var_sql
        End If
    Next i
    
    
    SSTab1.Tab = 2
    Tipo_Item = "NRM"
    
    ambito = Mid(SSTab1.Caption, Len(SSTab1.Caption))
    num_item = MSFlexGrid1(SSTab1.Tab).TextMatrix(MSFlexGrid1(SSTab1.Tab).Row, 3)
    confirma = MSFlexGrid1(SSTab1.Tab).TextMatrix(MSFlexGrid1(SSTab1.Tab).Row, 5)
 
    For i = 1 To (MSFlexGrid1(SSTab1.Tab).Rows - 1)
        num_item = MSFlexGrid1(SSTab1.Tab).TextMatrix(i, 3)
        confirma = MSFlexGrid1(SSTab1.Tab).TextMatrix(i, 5)
        If confirma = "NO" Then
            var_sql = "delete from pre_sem_eval_item_deta" _
                    & " where t_item = '" & Tipo_Item & "' and n_item = " & num_item & " and folio_persoc in" _
                    & " (select folio_persoc from pre_sem_eval_cab where agno = " & agno _
                    & " and cod_ens = '" & Cod_Ens & "' and num_gra = " & Num_Gra & ")" '_
                    '& " and t_item = '" & Tipo_Item & "' and n_item = " & num_item
        conn.Execute var_sql
        End If
    Next i
    
    
    SSTab1.Tab = 3
    Tipo_Item = "PF"
    
    ambito = Mid(SSTab1.Caption, Len(SSTab1.Caption))
    num_item = MSFlexGrid1(SSTab1.Tab).TextMatrix(MSFlexGrid1(SSTab1.Tab).Row, 3)
    confirma = MSFlexGrid1(SSTab1.Tab).TextMatrix(MSFlexGrid1(SSTab1.Tab).Row, 5)
 
    For i = 1 To (MSFlexGrid1(SSTab1.Tab).Rows - 1)
        num_item = MSFlexGrid1(SSTab1.Tab).TextMatrix(i, 3)
        confirma = MSFlexGrid1(SSTab1.Tab).TextMatrix(i, 5)
        If confirma = "NO" Then
            var_sql = "delete from pre_sem_eval_item_deta" _
                    & " where t_item = '" & Tipo_Item & "' and n_item = " & num_item & " and folio_persoc in" _
                    & " (select folio_persoc from pre_sem_eval_cab where agno = " & agno _
                    & " and cod_ens = '" & Cod_Ens & "' and num_gra = " & Num_Gra & ")" '_
                    '& " and t_item = '" & Tipo_Item & "' and n_item = " & num_item
        conn.Execute var_sql
        End If
    Next i
End Sub

Private Sub Form_Load()

    Dim recorre As Integer
    Dim StringsqlEns As String
    Dim sacarrut As ADODB.Recordset
    
    ' Validar esto en el main
    'If session_rut = "" Then
    '    MsgBox "El usuario no tiene RUT definido, consulte al administrador de Bases de Datos", vbOKOnly, "Sistema GesCol"
    '    Exit Sub
    'ElseIf Not (CodPerfil = "#ADM#" Or CodPerfil = "#UTP#" Or CorPerfil = "#SBD#") Then
    '    MsgBox "Usted no posee los privilegios necesarios para esta opción", vbCritical, "Acceso Denegado"
    '    Exit Sub
    'End If

    Me.Width = 10960
    Me.Height = 7300
    
    IC_CodEns(0).Enabled = True
    IC_CodEns(1).Enabled = True
    IC_CodEns(2).Enabled = True
    
     StringsqlEns = "Select DES_ENS,COD_ENS From codigos_ensenanza" _
                & " where cod_ens <> '110' and cod_ens <> '310' ORDER BY ORD_ENS"
    
    llenarCmb IC_CodEns(0), StringsqlEns
    llenarAgno IC_CodEns(2), Year(Date)
    
    cod = IC_CodEns(0).SelectedItem.Key
    buscar = Mid(cod, 2)
    StringsqlEns = "Select NUM_GRA From cursos where COD_ENS=" & buscar & " group by NUM_GRA"
    llenarCmbGra IC_CodEns(1), StringsqlEns
    
    For recorre = 0 To 3
        Formatogrilla MSFlexGrid1(recorre)
    Next
    limpiartodas
    Tipo_Item_Formacion = "NSV"
    SSTab1_Click (1)
End Sub
Private Sub llenarCmb(Combo As ImageCombo, ConsultaSql As String)
    Dim limite_ens, recorre As Integer
    Dim combo_ens As ADODB.Recordset
    Dim Codigo As String
    
    recorre = 1
    
    Set combo_ens = New ADODB.Recordset
    'recuperacion de datos para el combo box de enseñanza
    
    combo_ens.Open ConsultaSql, conn
    combo_ens.MoveFirst
    
    limite_ens = combo_ens.RecordCount
    Combo.ComboItems.Clear
    While Not combo_ens.EOF
        Codigo = combo_ens!Cod_Ens
        
        Combo.ComboItems.Add recorre, "C" & Codigo, combo_ens!des_ens
        recorre = recorre + 1
        combo_ens.MoveNext
    Wend
    combo_ens.Close
    Set Combo.SelectedItem = Combo.ComboItems.Item(1)
End Sub



Private Sub Form_Unload(Cancel As Integer)
    Command1_Click (5)
    If MsgBox("¿Desea guardar antes de salir?", vbQuestion + vbYesNo) = vbYes Then
        Command1_Click (5)
        MsgBox "Los cambios fueron guardados exitosamente"
    Else
        If MsgBox("¿Esta seguro que no desea guardar los cambios efectuados?", vbQuestion + vbYesNo) = vbYes Then
        Else
            Command1_Click (5)
            MsgBox "Los cambios fueron guardados exitosamente"
        End If
    End If
End Sub

Private Sub IC_CodEns_Change(Index As Integer)
    Dim Stringsql As String
    Dim buscar, cod As String
    
    If Index = 0 Then
        cod = IC_CodEns(0).SelectedItem.Key
        buscar = Mid(cod, 2)
        Stringsql = "Select NUM_GRA From cursos where COD_ENS=" & buscar & " group by NUM_GRA"
        llenarCmbGra IC_CodEns(1), Stringsql
    End If
    
End Sub
Private Sub IC_CodEns_Click(Index As Integer)
    Dim Stringsql As String
    Dim buscar, cod As String
    
    If Index = 0 Then
        cod = IC_CodEns(0).SelectedItem.Key
        buscar = Mid(cod, 2)
        'MsgBox (buscar)
        Stringsql = "Select NUM_GRA From cursos where COD_ENS=" & buscar & " group by NUM_GRA"
        llenarCmbGra IC_CodEns(1), Stringsql
    End If
    limpiartodas
    MSFlexGrid1(0).SetFocus
    Tipo_Item_Formacion = "NSV"
    llenargrillaSql MSFlexGrid1(0), "Select * from pre_sem_eval_item_des where cod_ens = '" & buscar & "' and T_ITEM='" + Tipo_Item_Formacion + "'", "s"
    
End Sub
Private Sub llenarCmbGra(Combo As ImageCombo, ConsultaSql As String)
    Dim limite_ens, recorre As Integer
    Dim combo_ens As ADODB.Recordset
    Dim Codigo As Integer
    
    recorre = 1
    
    Set combo_ens = New ADODB.Recordset
    'recuperacion de datos para el combo box de enseñanza
    
    combo_ens.Open ConsultaSql, conn
    combo_ens.MoveFirst
    
    limite_ens = combo_ens.RecordCount
    Combo.ComboItems.Clear
    While Not combo_ens.EOF

        Combo.ComboItems.Add recorre, "C" & combo_ens!Num_Gra, combo_ens!Num_Gra
        recorre = recorre + 1
        combo_ens.MoveNext
    Wend
    combo_ens.Close
    Set Combo.SelectedItem = Combo.ComboItems.Item(1)
    Combo.Refresh
    limpiartodas
End Sub
Private Sub llenarAgno(Combo As ImageCombo, agno As Integer)
    Dim limite, marcar As Integer
    inicio = 1
    Combo.ComboItems.Clear
    For limite = 2005 To agno + 2
        Combo.ComboItems.Add inicio, "C" & limite, limite
        If agno = limite Then
           marcar = inicio
        End If
        inicio = inicio + 1
    Next
    Set Combo.SelectedItem = Combo.ComboItems.Item(marcar)
End Sub

Private Sub Formatogrilla(Grilla As MSFlexGrid)
    Dim formato As Integer
    
    Grilla.Clear
    Grilla.FillStyle = flexFillRepeat
    Grilla.Cols = 7
    Grilla.ColWidth(0) = 0
    Grilla.ColWidth(1) = 0
    Grilla.ColWidth(2) = 0
    Grilla.ColWidth(3) = 400
    Grilla.ColWidth(4) = 7340
    Grilla.ColWidth(5) = 900
    Grilla.ColWidth(6) = 0
    Grilla.ColPosition(0) = 0
    Grilla.RowPosition(0) = 0
    Grilla.RowHeight(0) = 300
    Grilla.Row = 0
    For formato = 3 To 5
        Grilla.Col = formato
        Grilla.CellAlignment = Center
        Grilla.CellFontName = "MS Sans Serif"
        Grilla.CellFontBold = True
        If formato = 3 Then
            Grilla.Text = "Nº"
        ElseIf formato = 4 Then
            Grilla.Text = "Item Evaluador Disponible"
        ElseIf formato = 5 Then
            Grilla.Text = "Estado"
        End If
    Next
End Sub
Private Sub llenargrillaSql(Grilla As MSFlexGrid, sqlstring As String, Primera As String)
If Primera = "n" Then
    Exit Sub
Else
    
    Dim llenado As ADODB.Recordset
    Dim veriSql As String
    Dim sb As Integer
    
    Set llenado = New ADODB.Recordset
        
    
    
    llenado.Open sqlstring, conn
    
    Grilla.Rows = llenado.RecordCount + 1
    Grilla.Row = 0
      
    If llenado.RecordCount <> 0 Then
        llenado.MoveFirst
        While Not llenado.EOF
            veriSql = "Select count(*) as sn from pre_sem_eval_formato_inf_agno where COD_ENS='"
            Grilla.Row = Grilla.Row + 1
            Grilla.Col = 0
            Grilla.Text = Mid(IC_CodEns(0).SelectedItem.Key, 2)
            veriSql = veriSql + Trim(Mid(IC_CodEns(0).SelectedItem.Key, 2)) + "' AND NUM_GRA='"
            Grilla.Col = 1
            Grilla.Text = Mid(IC_CodEns(1).SelectedItem.Key, 2)
            veriSql = veriSql + Trim(Mid(IC_CodEns(1).SelectedItem.Key, 2)) + "' AND AGNO="
            Grilla.Col = 2
            Grilla.Text = Mid(IC_CodEns(2).SelectedItem.Key, 2)
            veriSql = veriSql + Trim(Mid(IC_CodEns(2).SelectedItem.Key, 2)) + " AND T_ITEM='" + Tipo_Item_Formacion + "' AND N_ITEM="
            Grilla.Col = 3
            Grilla.Text = llenado!n_item
            veriSql = veriSql + str(llenado!n_item) + ""
            Grilla.CellBackColor = &HC0C0FF
            Grilla.Col = 4
            Grilla.CellBackColor = &HC0C0FF
            Grilla.Text = llenado!descripcion
            Grilla.Col = 5
            
            If estaono(veriSql) Then
               Grilla.Text = "OK"
                Grilla.Col = 0
                Grilla.ColSel = Grilla.Cols - 1
                Grilla.CellBackColor = &HC0FFC0
                Grilla.Refresh
                Grilla.Col = 6
                Grilla.Text = "OK"
            Else
                Grilla.Text = "NO"
                Grilla.CellBackColor = &HC0C0FF
                Grilla.Col = 6
                Grilla.Text = "NO"
            End If
            
            
            llenado.MoveNext

        Wend
    End If
    llenado.Close
End If
End Sub

Private Sub MSFlexGrid1_Click(Index As Integer)
    Dim cambiar As Integer
        
    MSFlexGrid1(Index).Col = 5
    
    If MSFlexGrid1(Index).Text = "NO" Then
        MSFlexGrid1(Index).Col = 5
        MSFlexGrid1(Index).Text = "OK"
        For cambiar = 3 To 5
            MSFlexGrid1(Index).Col = cambiar
            MSFlexGrid1(Index).CellBackColor = &HC0FFC0
        Next
    Else
        MSFlexGrid1(Index).Col = 5
        MSFlexGrid1(Index).Text = "NO"
        For cambiar = 3 To 5
            MSFlexGrid1(Index).Col = cambiar
            MSFlexGrid1(Index).CellBackColor = &HC0C0FF
        Next
    End If
    
End Sub

Private Sub SSTab1_Click(PreviousTab As Integer)
    cod = IC_CodEns(0).SelectedItem.Key
    buscar = Mid(cod, 2)
    verificatipo
    llenargrillaSql MSFlexGrid1(SSTab1.Tab), "Select * from pre_sem_eval_item_des where cod_ens = '" & buscar & "' and T_ITEM='" + Tipo_Item_Formacion + "' order by n_item", "n"
End Sub

Private Sub limpiartodas()
    cod = IC_CodEns(0).SelectedItem.Key
    buscar = Mid(cod, 2)

    Tipo_Item_Formacion = "NSV"
    llenargrillaSql MSFlexGrid1(0), "Select * from pre_sem_eval_item_des where cod_ens = '" & buscar & "' and T_ITEM='" + Tipo_Item_Formacion + "' order by n_item", "s"
    Tipo_Item_Formacion = "GH"
    llenargrillaSql MSFlexGrid1(1), "Select * from pre_sem_eval_item_des where cod_ens = '" & buscar & "' and T_ITEM='" + Tipo_Item_Formacion + "' order by n_item", "s"
    Tipo_Item_Formacion = "NRM"
    llenargrillaSql MSFlexGrid1(2), "Select * from pre_sem_eval_item_des where cod_ens = '" & buscar & "' and T_ITEM='" + Tipo_Item_Formacion + "' order by n_item", "s"
    Tipo_Item_Formacion = "PF"
    llenargrillaSql MSFlexGrid1(3), "Select * from pre_sem_eval_item_des where cod_ens = '" & buscar & "' and T_ITEM='" + Tipo_Item_Formacion + "' order by n_item", "s"
'    Tipo_Item_Formacion = "CFC"
'    llenargrillaSql MSFlexGrid1(4), "Select * from pre_sem_eval_item_des where T_ITEM='" + Tipo_Item_Formacion + "'", "s"
    Tipo_Item_Formacion = "NA"
End Sub
Private Sub verificatipo()
   If SSTab1.Tab = 0 Then
        Tipo_Item_Formacion = "NSV"
    ElseIf SSTab1.Tab = 1 Then
        Tipo_Item_Formacion = "GH"
    ElseIf SSTab1.Tab = 2 Then
        Tipo_Item_Formacion = "NRM"
    ElseIf SSTab1.Tab = 3 Then
        Tipo_Item_Formacion = "PF"
    End If
    cod = IC_CodEns(0).SelectedItem.Key
    buscar = Mid(cod, 2)
    pre_ens = buscar
End Sub
Private Sub grabardatos(GGrilla As MSFlexGrid, XCual As String)
    Dim CMD As ADODB.Command
    Dim Affected As Long
    Dim limite, X, Y As Integer
    Dim ConstruirSql As String
    
    Set CMD = New ADODB.Command
    CMD.CommandType = adCmdText
    CMD.ActiveConnection = conn
    X = 0
    Y = 1
    limite = GGrilla.Rows
    
    For Y = 1 To limite - 1
        GGrilla.Row = Y
        ConstruirSql = "REPLACE INTO pre_sem_eval_formato_inf_agno (`COD_ENS`,`NUM_GRA`,`AGNO`,`N_ITEM`,`T_ITEM`) VALUES ("
        GGrilla.Col = 5
        If GGrilla.Text = "OK" Then
            For X = 0 To 3
                GGrilla.Col = X
                ConstruirSql = ConstruirSql + "'" + GGrilla.Text + "'"
                If X = 3 Then
                    ConstruirSql = ConstruirSql + ",'" + Tipo_Item_Formacion + "')"
                Else
                    ConstruirSql = ConstruirSql + ","
                End If
            Next
            CMD.CommandText = ConstruirSql
            CMD.Execute
        End If
    
    Next
    
End Sub
Private Sub buscarygrabar(SDGrilla As MSFlexGrid)
    Dim recorre, limite As Integer
    Dim repladele, ConstriurSql, t_CODENS, t_NUMGRA, t_AGNO, t_TItem, t_NItem, Col5, Col6 As String
    Dim accion As ADODB.Recordset
    
    limite = SDGrilla.Rows
    
    For recorre = 1 To limite - 1
        SDGrilla.Row = recorre
        
        SDGrilla.Col = 5
        Col5 = Trim(SDGrilla.Text)
        
        SDGrilla.Col = 6
        Col6 = Trim(SDGrilla.Text)

        
        If Col5 = "NO" And Col6 = "OK" Then
            SDGrilla.Col = 0
            t_CODENS = SDGrilla.Text
            SDGrilla.Col = 1
            t_NUMGRA = SDGrilla.Text
            SDGrilla.Col = 2
            t_AGNO = Trim(str(SDGrilla.Text))
            SDGrilla.Col = 3
            t_NItem = SDGrilla.Text
            t_TItem = Tipo_Item_Formacion
            
            repladele = "Delete from pre_sem_eval_formato_inf_agno where COD_ENS='" & t_CODENS & "' AND NUM_GRA=" & t_NUMGRA
            repladele = repladele & " AND AGNO=" & t_AGNO & " AND T_ITEM='" & Tipo_Item_Formacion & "' AND N_ITEM=" & t_NItem
            
            Set accion = New ADODB.Recordset
            
            accion.Open repladele, conn
        ElseIf Col5 = "OK" And Col6 = "NO" Then
            X = 0
    
            ConstruirSql = "REPLACE INTO pre_sem_eval_formato_inf_agno (COD_ENS,NUM_GRA,AGNO,N_ITEM,T_ITEM) VALUES ("
            For X = 0 To 3
                    SDGrilla.Col = X
                    ConstruirSql = ConstruirSql + "'" + SDGrilla.Text + "'"
                    If X = 3 Then
                        ConstruirSql = ConstruirSql + ",'" + Tipo_Item_Formacion + "')"
                    Else
                        ConstruirSql = ConstruirSql + ","
                    End If
            Next
            
            Set accion = New ADODB.Recordset
            accion.Open ConstruirSql, conn
            
        
        End If
    Next
                        
            
End Sub




