VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Object = "{0ECD9B60-23AA-11D0-B351-00A0C9055D8E}#6.0#0"; "MSHFLXGD.OCX"
Begin VB.Form Form_Asignacion_Talleres 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Asignación de Talleres de Libre Elección"
   ClientHeight    =   8055
   ClientLeft      =   45
   ClientTop       =   435
   ClientWidth     =   16935
   Icon            =   "Form_Asignacion_Talleres.frx":0000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MDIChild        =   -1  'True
   MinButton       =   0   'False
   ScaleHeight     =   8055
   ScaleWidth      =   16935
   Begin VB.CommandButton cmd_salir 
      Caption         =   "Salir"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   735
      Left            =   15000
      Picture         =   "Form_Asignacion_Talleres.frx":2A8B2
      Style           =   1  'Graphical
      TabIndex        =   11
      Top             =   360
      Width           =   1695
   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          =   735
      Left            =   13080
      Picture         =   "Form_Asignacion_Talleres.frx":2AED8
      Style           =   1  'Graphical
      TabIndex        =   10
      Top             =   360
      Width           =   1695
   End
   Begin MSHierarchicalFlexGridLib.MSHFlexGrid grilla 
      Height          =   6615
      Left            =   120
      TabIndex        =   9
      Top             =   1320
      Width           =   16695
      _ExtentX        =   29448
      _ExtentY        =   11668
      _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
      _NumberOfBands  =   1
      _Band(0).Cols   =   2
   End
   Begin VB.Frame Frame1 
      Caption         =   "Seleccione Curso"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00C00000&
      Height          =   1095
      Left            =   120
      TabIndex        =   0
      Top             =   120
      Width           =   7095
      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       =   &H00000000&
         Height          =   195
         Left            =   5760
         TabIndex        =   1
         Top             =   360
         Value           =   1  'Checked
         Visible         =   0   'False
         Width           =   1095
      End
      Begin MSComctlLib.ImageCombo IC_Ensenanza 
         Height          =   345
         Left            =   1320
         TabIndex        =   2
         Top             =   600
         Width           =   3135
         _ExtentX        =   5530
         _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
         Text            =   "IC_Ensenanza"
      End
      Begin MSComctlLib.ImageCombo IC_Nivel 
         Height          =   345
         Left            =   4560
         TabIndex        =   3
         Top             =   600
         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
         Text            =   "IC_Nivel"
      End
      Begin MSComctlLib.ImageCombo IC_Letra 
         Height          =   345
         Left            =   5760
         TabIndex        =   4
         Top             =   600
         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
         Text            =   "IC_Letra"
      End
      Begin MSComctlLib.ImageCombo IC_Agno 
         Height          =   345
         Left            =   120
         TabIndex        =   5
         Top             =   600
         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
         Text            =   "IC_Agno"
      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       =   &H00000000&
         Height          =   255
         Left            =   120
         TabIndex        =   8
         Top             =   360
         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       =   &H00000000&
         Height          =   255
         Left            =   1320
         TabIndex        =   7
         Top             =   360
         Width           =   2895
      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       =   &H00000000&
         Height          =   255
         Left            =   4560
         TabIndex        =   6
         Top             =   360
         Width           =   855
      End
   End
End
Attribute VB_Name = "Form_Asignacion_Talleres"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub cmd_Grabar_Click()
    Dim rut As String
    Dim objRS As ADODB.Recordset
    Set objRS = New ADODB.Recordset
    Dim Codigo As String
    Dim I, a As Integer
    Dim j As Integer
    Dim Pos As Integer
    Dim var_sql As String
        
    For I = 1 To Grilla.Rows - 1
        Pos = 0
        For a = 1 To 10
            If Mid(Grilla.TextMatrix(I, 0), a, 1) = "-" Then
                Pos = a
            End If
        Next a
        If Pos <> 0 Then
        rut = Mid(Grilla.TextMatrix(I, 0), 1, Pos + 1)
        var_sql = "delete from alumnos_talleres" _
                & " where ci_alu = '" & rut & "'" _
                & " and cod_ens = '" & Mid(IC_Ensenanza.SelectedItem.Key, 2) _
                & "' and numgra = " & IC_Nivel.Text & " and let_cur = '" _
                & IC_Letra.Text & "' and tipo_tall = 2 and agno = " & IC_Agno.Text
        conn.Execute var_sql
        End If
        For j = 1 To Grilla.Cols - 1
            Grilla.Row = I
            Grilla.Col = j
            If Grilla.Text = "OK" Then
                var_sql = "select cod_tall from talleres" _
                        & " where tipo_tall = 2 and num_gra = " & IC_Nivel.Text _
                        & " and nom_tall = '" & Grilla.TextMatrix(0, j) _
                        & "' and cod_ens = '" & Mid(IC_Ensenanza.SelectedItem.Key, 2) & "'"
                objRS.Open var_sql, conn
                Codigo = objRS("cod_tall")
                objRS.Close
                var_sql = "replace into alumnos_talleres(ci_alu,cod_tall,cod_ens,numgra,let_cur,agno,tipo_tall)" _
                        & " values('" & rut & "','" & Codigo & "','" _
                        & Mid(IC_Ensenanza.SelectedItem.Key, 2) _
                        & "'," & IC_Nivel.Text & ",'" & IC_Letra.Text & "'," & IC_Agno.Text _
                        & ",'2')"
                conn.Execute var_sql
            End If
                       
            'Mid(IC_Ensenanza.SelectedItem.Key, 2)
        Next j
        
    Next I
End Sub

Private Sub cmd_Salir_Click()
    Unload Me
End Sub

Private Sub Form_Load()
    Call Set_IC_Agno
End Sub

Private Sub Grilla_DblClick()
    
    Dim c As Integer
    Dim R As Integer
    Dim I As Integer
    Dim cont As Integer
    c = Grilla.Col
    R = Grilla.Row
    If c < 2 Then
        Exit Sub
    End If
    cont = 0
    For I = 2 To Grilla.Cols - 1
        Grilla.Col = I
        If Grilla.CellBackColor = vbGreen Then
            cont = cont + 1
        End If
    Next I
    Grilla.Col = c
    Grilla.Row = R
    If cont = 4 And Not (Grilla.CellBackColor = vbGreen) Then
        MsgBox "Usted ya a seleccionado 2 talleres para este alumno", vbInformation
        Exit Sub
    End If
    If Grilla.CellBackColor <> vbGreen Then
        Grilla.CellBackColor = vbGreen
        Grilla.Text = "OK"
        Grilla.CellAlignment = flexAlignCenterCenter
    Else
        Grilla.CellBackColor = vbWhite
        Grilla.Text = ""
    End If
End Sub

Private Sub IC_Agno_Click()
    IC_Ensenanza.Enabled = True
    Set_IC_Ensenanza
End Sub

Private Sub IC_Ensenanza_Click()
    IC_Nivel.Enabled = True
    Call Set_IC_Nivel
End Sub

Private Sub IC_Letra_Change()
    IC_Letra_Click
End Sub

Private Sub IC_Letra_Click()
    Dim total, I, j As Integer
    Dim codigos(30) As String
    Dim objRS As ADODB.Recordset
    Set objRS = New ADODB.Recordset
    Dim var_sql As String
    
    var_sql = "SELECT axc.ci_alu,concat(axc.ci_alu,' - ',ape_pat_alu,' ',ape_mat_alu,' ',nom_alu) as nombre" _
            & " FROM alu_x_cur axc,postulantes p,codigos_ensenanza ce" _
            & " where axc.num_gra = " & IC_Nivel.Text _
            & " and let_cur = '" & IC_Letra.Text & "' and activo_alu = 'SI' and axc.ci_alu = p.ci_alu" _
            & " and axc.agno = " & IC_Agno.Text & " and axc.cod_ens = ce.cod_ens" _
            & " and ce.des_ens = '" & IC_Ensenanza.Text & "'"
    objRS.Open var_sql, conn
    Grilla.Rows = 2
    Grilla.ClearStructure
    While Not objRS.EOF
        'grilla.CellAlignment = flexAlignLeftCenter
        Grilla.TextMatrix(Grilla.Rows - 1, 0) = objRS("ci_alu")
        Grilla.TextMatrix(Grilla.Rows - 1, 1) = Left(objRS("nombre"), 50)
        Grilla.Row = Grilla.Rows - 1
        Grilla.Col = 1
        Grilla.CellAlignment = flexAlignLeftCenter
        'grilla.ColWidth(grilla.Cols - 1) = TextWidth(grilla.TextMatrix(grilla.Rows - 1, grilla.Cols - 1)) + 100
        objRS.MoveNext
        Grilla.Rows = Grilla.Rows + 1
    Wend
    objRS.Close
    
    var_sql = "select cod_tall,nom_tall from talleres t,codigos_ensenanza ce" _
            & " where ce.des_ens = '" & IC_Ensenanza.Text _
            & "' and t.num_gra = " & IC_Nivel.Text & " and tipo_tall = 2 and t.cod_ens = ce.cod_ens"
    objRS.Open var_sql, conn
    Grilla.Cols = 3
    While Not objRS.EOF
        codigos(Grilla.Cols - 1) = objRS("cod_tall")
        Grilla.TextMatrix(0, Grilla.Cols - 1) = objRS("nom_tall")
        Grilla.ColWidth(Grilla.Cols - 1) = TextWidth(Grilla.TextMatrix(0, Grilla.Cols - 1)) + 100
        objRS.MoveNext
        Grilla.Cols = Grilla.Cols + 1
    Wend
    total = Grilla.Cols - 2
    Grilla.Cols = Grilla.Cols - 1
    objRS.Close
    
    Grilla.TextMatrix(0, 1) = "ALUMNOS"
    Grilla.Rows = Grilla.Rows - 1
    Grilla.ColWidth(1) = 4800
    Grilla.ColWidth(0) = 0
'    grilla.Row = 0
    'grilla.CellAlignment = flexAlignLeftCenter
    'grilla.Cols = grilla.Rows - 1
    
    For I = 2 To total
        For j = 1 To Grilla.Rows - 1
            var_sql = "select * from alumnos_talleres" _
                    & " where ci_alu = '" & Grilla.TextMatrix(j, 0) & "' and cod_tall = '" & codigos(I) & "'" _
                    & " and cod_ens = '" & Mid(IC_Ensenanza.SelectedItem.Key, 2) _
                    & "' and numgra = " & IC_Nivel.Text _
                    & " and let_cur = '" & IC_Letra.Text & "' and tipo_tall = 2 and agno = " & IC_Agno.Text
            objRS.Open var_sql, conn
            If Not objRS.EOF Then
                Grilla.TextMatrix(j, I) = "OK"
                Grilla.Row = j
                Grilla.Col = I
                Grilla.CellBackColor = vbGreen
                Grilla.CellAlignment = flexAlignCenterCenter
            End If
            objRS.Close
        Next j
    Next I
End Sub

Private Sub IC_Nivel_Click()
    IC_Letra.Enabled = True
    Call Set_IC_Letra
End Sub

Private Sub Set_IC_Ensenanza()
    Dim REC As ADODB.Recordset
    Dim QRY As String
    
    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;"
    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

    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 Set_IC_Letra()
    Dim REC As ADODB.Recordset
    Dim QRY As String
    
    'If Check_Letra.Value = 1 Then
        IC_Letra.ComboItems.Clear
        IC_Letra.Text = ""
        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;"
        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 Set_IC_Agno()
    Dim agno As Integer
    
  '  agno = IIf(Year(Date) < 2005, 2005, Year(Date))
  '  IC_Agno.ComboItems.Clear
'    For i = 2005 To (Anno)
'        IC_Agno.ComboItems.Add i, , str(i + 2004)
'    Next i
'    Set IC_Agno.SelectedItem = IC_Agno.ComboItems.Item(i - 1)
'    ErrorStatus = False
    
    agno = IIf(Year(Date) < 2005, 2005, Year(Date))
    IC_Agno.ComboItems.Clear
    For I = 1 To (agno - 2004)
        IC_Agno.ComboItems.Add I, , str(I + 2004)
    Next I
    Set IC_Agno.SelectedItem = IC_Agno.ComboItems.Item(I - 1)
    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 Rec2Grid(ByRef REC As ADODB.Recordset, ByRef grid As Object, Optional ByVal Numeracion As Boolean = True)
    grid.ClearStructure
    If REC.RecordCount > 0 Then
        grid.Cols = REC.Fields.count + 1
        grid.Rows = REC.RecordCount + 1
        grid.FixedCols = 1
        grid.FixedRows = 1
        grid.TextMatrix(0, 0) = "Nº"
        grid.ColWidth(0) = IIf(Numeracion, TextWidth(grid.TextMatrix(0, 0)) + 100, 0)
        For I = 1 To REC.Fields.count
            grid.TextMatrix(0, I) = UCase(REC.Fields(I - 1).Name)
            grid.ColWidth(I) = TextWidth(grid.TextMatrix(0, I)) + 100
        Next I
        REC.MoveFirst
        For I = 1 To REC.RecordCount
            'progreso.Value = i
            grid.TextMatrix(I, 0) = I
            grid.ColWidth(0) = IIf(Numeracion, IIf(TextWidth(grid.TextMatrix(I, 0)) + 100 > grid.ColWidth(0), TextWidth(grid.TextMatrix(I, 0)) + 100, grid.ColWidth(0)), 0)
            For j = 1 To REC.Fields.count
                grid.TextMatrix(I, j) = IIf(IsNull(REC(j - 1)), "Null", REC(j - 1))
                grid.ColWidth(j) = IIf(TextWidth(grid.TextMatrix(I, j)) + 100 > grid.ColWidth(j), TextWidth(grid.TextMatrix(I, j)) + 100, grid.ColWidth(j))
            Next j
            REC.MoveNext
        Next I
    Else
        grid.Cols = 2
        grid.Rows = 2
    End If
End Sub

