VERSION 5.00
Object = "{5E9E78A0-531B-11CF-91F6-C2863C385E30}#1.0#0"; "MSFLXGRD.OCX"
Object = "{6B7E6392-850A-101B-AFC0-4210102A8DA7}#1.3#0"; "comctl32.ocx"
Begin VB.Form Form_listado_medidas_cautelares 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Form listado de medidas cautelares"
   ClientHeight    =   7755
   ClientLeft      =   45
   ClientTop       =   375
   ClientWidth     =   11520
   Icon            =   "Form_listado_medidas_cautelares.frx":0000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MDIChild        =   -1  'True
   MinButton       =   0   'False
   ScaleHeight     =   7755
   ScaleWidth      =   11520
   Begin VB.OptionButton opt_todos 
      Caption         =   "Todos"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   360
      TabIndex        =   9
      Top             =   1080
      Value           =   -1  'True
      Width           =   1215
   End
   Begin VB.OptionButton opt_alumno 
      Caption         =   "Por Alumno"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   360
      TabIndex        =   8
      Top             =   720
      Width           =   1215
   End
   Begin VB.Frame Frame_medidas 
      Caption         =   "Listado de medidas cautelares"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00C00000&
      Height          =   6135
      Left            =   120
      TabIndex        =   2
      Top             =   120
      Width           =   11175
      Begin VB.Frame opt_opcion 
         Caption         =   "Opción"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H00C00000&
         Height          =   1215
         Left            =   120
         TabIndex        =   7
         Top             =   360
         Width           =   1455
      End
      Begin VB.Frame Frame2 
         Caption         =   "Frame2"
         Height          =   2175
         Left            =   2640
         TabIndex        =   3
         Top             =   2880
         Visible         =   0   'False
         Width           =   6015
         Begin VB.Label Label2 
            Caption         =   "En proceso"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   48
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   975
            Left            =   600
            TabIndex        =   4
            Top             =   600
            Width           =   4935
         End
      End
      Begin MSFlexGridLib.MSFlexGrid MSFlexGrid1 
         Height          =   4455
         Left            =   120
         TabIndex        =   5
         Top             =   1680
         Width           =   10935
         _ExtentX        =   19288
         _ExtentY        =   7858
         _Version        =   393216
      End
      Begin VB.Frame Frame_todos 
         Caption         =   "Todos"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H00C00000&
         Height          =   1215
         Left            =   1680
         TabIndex        =   19
         Top             =   360
         Visible         =   0   'False
         Width           =   9375
         Begin VB.CommandButton Command1 
            Caption         =   "Listar medidas cautelares"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   495
            Left            =   6600
            TabIndex        =   20
            Top             =   360
            Width           =   2535
         End
      End
      Begin VB.Frame Frame_alumno 
         Caption         =   "Por Alumno"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H00C00000&
         Height          =   1215
         Left            =   1680
         TabIndex        =   10
         Top             =   360
         Visible         =   0   'False
         Width           =   9375
         Begin VB.CommandButton btnOtroAlumno 
            Caption         =   "Otro Alumno"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   735
            Left            =   8040
            Picture         =   "Form_listado_medidas_cautelares.frx":2A8B2
            Style           =   1  'Graphical
            TabIndex        =   18
            Top             =   360
            Width           =   1215
         End
         Begin VB.CommandButton btn_Ver 
            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            =   6720
            Picture         =   "Form_listado_medidas_cautelares.frx":2AE07
            Style           =   1  'Graphical
            TabIndex        =   17
            Top             =   360
            Width           =   1215
         End
         Begin VB.ListBox lst_Rut 
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   900
            Left            =   5280
            TabIndex        =   14
            Top             =   600
            Visible         =   0   'False
            Width           =   1335
         End
         Begin VB.ListBox lst_Alumnos 
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   900
            Left            =   840
            TabIndex        =   13
            Top             =   600
            Visible         =   0   'False
            Width           =   3735
         End
         Begin VB.TextBox txt_NombreCompleto 
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   285
            Left            =   840
            TabIndex        =   12
            Top             =   360
            Width           =   3735
         End
         Begin VB.TextBox txt_RutBusqueda 
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   285
            Left            =   5280
            TabIndex        =   11
            Top             =   360
            Width           =   1335
         End
         Begin VB.Label Label13 
            Caption         =   "Nombre"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   255
            Left            =   120
            TabIndex        =   16
            Top             =   360
            Width           =   735
         End
         Begin VB.Label Label14 
            Caption         =   "R.u.t."
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   255
            Left            =   4680
            TabIndex        =   15
            Top             =   360
            Width           =   615
         End
      End
   End
   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          =   855
      Left            =   9360
      Picture         =   "Form_listado_medidas_cautelares.frx":2B37E
      Style           =   1  'Graphical
      TabIndex        =   1
      Top             =   6720
      Width           =   1575
   End
   Begin VB.CommandButton Command2 
      Caption         =   "Exportar Excel"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   855
      Left            =   480
      Picture         =   "Form_listado_medidas_cautelares.frx":2B9A4
      Style           =   1  'Graphical
      TabIndex        =   0
      Top             =   6720
      Width           =   1575
   End
   Begin ComctlLib.ProgressBar pgbar 
      Height          =   255
      Left            =   120
      TabIndex        =   6
      Top             =   6360
      Width           =   11175
      _ExtentX        =   19711
      _ExtentY        =   450
      _Version        =   327682
      Appearance      =   1
   End
End
Attribute VB_Name = "Form_listado_medidas_cautelares"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Rec2Grid(ByRef REC As ADODB.Recordset, ByRef grid As Object, Optional ByVal Numeracion As Boolean = True)
    grid.Clear
    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

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

    var_sql = "SELECT run_mc AS 'R.U.N.',CONCAT(ape_pat_mc,' ',ape_mat_mc,' ',nombres_mc) AS Persona ,dir_mc AS Direccion,comuna,tribunal_mc," _
            & "orden_por_mc,fecha_inicio_mc,dias_hab_mc,observacion_mc,fecha_termino_mc,permanente" _
            & " FROM medidas_cautelares mc,codigos__geograficos cg" _
            & " WHERE mc.comuna_mc = cg.cod_geo AND run_alu_mc = '" & txt_RutBusqueda.Text & "'"
                
    objRS.Open var_sql, conn
    If Not objRS.EOF Then
        Call Rec2Grid(objRS, MSFlexGrid1, True)
       ' msflex_alumnos.ColSel = 5
    Else
        'MsgBox "Esta mensualidad aún no ha vencido", vbInformation
    End If
    objRS.Close
End Sub

Private Sub btnOtroAlumno_Click()
   txt_RutBusqueda.Locked = False
    txt_NombreCompleto.Locked = False
    btn_Ver.Enabled = True
    'limpia_controles
    'frm_DatosAlumno.Visible = False
    'desabilita_controles
    lst_Rut.Visible = False
    lst_Alumnos.Visible = False
'    msflex_matriculas.Clear
'    msflex_matriculas.Rows = 1
'    mshflex_Apoderados.Clear
'    mshflex_Apoderados.Rows = 1
'    sst_Busqueda.Enabled = False
   ' sst_Busqueda.Tab = 0
    txt_NombreCompleto.Text = ""
    txt_RutBusqueda.Text = ""
    MSFlexGrid1.Clear
    MSFlexGrid1.Rows = 2
    'Frame1.Visible = False
End Sub

Private Sub cmd_salir_Click()
    Unload Me
End Sub

Private Sub Command1_Click()
    Dim var_sql As String
    Dim conecta As Boolean
    Dim maximo_mes As Integer
   
    Dim objRS As ADODB.Recordset
    Set objRS = New ADODB.Recordset
    
    Frame2.Visible = True
        
    var_sql = "SELECT a.ci_alu,CONCAT(ape_pat_alu,' ',ape_mat_alu,' ',nom_alu) AS alumno,CONCAT(a.num_gra,' ',a.let_cur,' ',des_ens_abrev) AS curso," _
            & "run_mc AS 'R.U.N.',CONCAT(ape_pat_mc,' ',ape_mat_mc,' ',nombres_mc) AS Persona ,dir_mc AS Direccion,comuna,tribunal_mc,orden_por_mc,fecha_inicio_mc," _
            & "fecha_termino_mc,dias_hab_mc,observacion_mc,permanente" _
            & " FROM medidas_cautelares mc,codigos__geograficos cg,alu_x_cur a,codigos_ensenanza ce,postulantes p" _
            & " Where mc.comuna_mc = cg.cod_geo And mc.run_alu_mc = a.ci_alu And a.agno = 2015 And a.Cod_Ens = ce.Cod_Ens And a.ci_alu = p.ci_alu" _
            & " ORDER BY a.cod_ens,a.num_gra,a.let_cur,alumno"
                
    objRS.Open var_sql, conn
    If Not objRS.EOF Then
        Call Rec2Grid(objRS, MSFlexGrid1, True)
       ' msflex_alumnos.ColSel = 5
    Else
        'MsgBox "Esta mensualidad aún no ha vencido", vbInformation
    End If
    objRS.Close
    MSFlexGrid1.Refresh
    
    Frame2.Visible = False
    
    
End Sub

Private Sub Command2_Click()
    Dim ApExcel As Variant
    Set ApExcel = CreateObject("Excel.application")
    ApExcel.Workbooks.Add
          
    For i = 1 To Me.MSFlexGrid1.Cols - 1
        ApExcel.Cells(1, i).Font.Size = 12
        ApExcel.Cells(1, i).Font.Bold = True
        ApExcel.Cells(1, i).Formula = Me.MSFlexGrid1.TextMatrix(0, i)
    Next i
    pgbar.Min = 1
    pgbar.Max = MSFlexGrid1.Rows
    pgbar.Value = pgbar.Min
    For i = 1 To MSFlexGrid1.Rows - 1

         For j = 1 To MSFlexGrid1.Cols - 1
            ApExcel.Cells((i + 1), j).Formula = IIf(MSFlexGrid1.TextMatrix(i, j) = "Null", "", MSFlexGrid1.TextMatrix(i, j))
        
        pgbar.Value = i
        Next j
    Next i
            
    ApExcel.Visible = True
    'ApExcel.Range("a1:x1").Borders.color = RGB(255, 0, 0)
    Set ApExcel = Nothing
End Sub

Private Sub Form_Load()
    Frame_todos.Visible = True
End Sub

Private Sub lst_Alumnos_dblClick()
    'Dim dig As String
    'dig = digito(lst_Alumnos.ItemData(lst_Alumnos.ListIndex))
    'Dim Rut As String
    Dim varsql As String
    'Rut = lst_Alumnos.ItemData(lst_Alumnos.ListIndex) & "-" & dig
    
    Dim objRS As ADODB.Recordset
    varsql = "SELECT ci_alu" _
           & " FROM postulantes where concat(ape_pat_alu,' ',ape_mat_alu,' ',nom_alu) = '" _
           & lst_Alumnos.Text & "'"

    Set objRS = New ADODB.Recordset
    objRS.Open varsql, conn
    If Not objRS.EOF Then
        txt_NombreCompleto.Text = lst_Alumnos.Text
        txt_RutBusqueda.Text = objRS("ci_alu")
    End If
    objRS.Close
    lst_Rut.Clear
    lst_Rut.Visible = False
    If txt_RutBusqueda.Text <> "" And txt_NombreCompleto.Text <> "" Then
        txt_RutBusqueda.Locked = True
        txt_NombreCompleto.Locked = True
    End If
End Sub

Private Sub lst_Alumnos_LostFocus()
    lst_Alumnos.Visible = False
End Sub

Private Sub lst_Rut_DblClick()
    txt_RutBusqueda.Text = lst_Rut.Text
    lst_Rut.Visible = False
    Dim objRS As ADODB.Recordset
    Dim varsql As String
    varsql = "SELECT ape_pat_alu,ape_mat_alu,nom_alu" _
           & " FROM postulantes where ci_alu='" & txt_RutBusqueda.Text & "'"

    Set objRS = New ADODB.Recordset
        objRS.Open varsql, conn
    If Not objRS.EOF Then
        txt_NombreCompleto.Text = objRS("ape_pat_alu") & " " & objRS("ape_mat_alu") & " " & objRS("nom_alu")
    End If
    objRS.Close
    lst_Alumnos.Visible = False
    lst_Rut.Clear
    If txt_RutBusqueda.Text <> "" And txt_NombreCompleto.Text <> "" Then
        txt_RutBusqueda.Locked = True
        txt_NombreCompleto.Locked = True
    End If
End Sub

Private Sub opt_alumno_Click()
    Frame_alumno.Visible = True
    Frame_todos.Visible = False
End Sub

Private Sub opt_todos_Click()
    Frame_todos.Visible = True
    Frame_alumno.Visible = False
End Sub

Private Sub txt_NombreCompleto_Change()
    If txt_NombreCompleto.Text <> "" Then
    Dim varsql As String
    'lst_Rut.Visible = False
    Dim objRC As ADODB.Recordset
    Dim rut As Long
    Set objRS = New ADODB.Recordset
    varsql = "SELECT distinct p.CI_ALU,APE_PAT_ALU,APE_MAT_ALU,NOM_ALU" _
           & " FROM postulantes p,matriculas m" _
           & " where concat(APE_PAT_ALU,' ',ape_mat_alu,' ',nom_alu) LIKE '" & txt_NombreCompleto.Text & "%'" _
           & " and p.ci_alu = m.ci_alu" _
           & " order by ape_pat_alu,ape_mat_alu,nom_alu"
    objRS.Open varsql, conn
    lst_Alumnos.Clear
    If Not objRS.EOF Then
        lst_Alumnos.Visible = True
    End If
    While Not objRS.EOF
        lst_Alumnos.AddItem objRS("APE_PAT_ALU") & " " & objRS("APE_MAT_ALU") & " " & objRS("NOM_ALU")
        rut = Mid(objRS("CI_ALU"), 1, 8)
        lst_Alumnos.ItemData(lst_Alumnos.NewIndex) = rut
        objRS.MoveNext
    Wend
    objRS.Close
    End If
End Sub
Private Sub txt_NombreCompleto_KeyPress(KeyAscii As Integer)
    KeyAscii = Asc(UCase(Chr(KeyAscii)))
End Sub

Private Sub txt_RutBusqueda_Change()
    If txt_RutBusqueda.Text <> "" Then
    Dim varsql As String
    lst_Rut.Visible = False
    lst_Alumnos.Visible = False
    Dim objRC As ADODB.Recordset
    Dim rut As Long
    Set objRS = New ADODB.Recordset
    varsql = "SELECT distinct m.CI_ALU" _
           & " FROM postulantes p,matriculas m" _
           & " where p.CI_ALU LIKE '" & txt_RutBusqueda & "%'" _
           & " and p.ci_alu = m.ci_alu"
    objRS.Open varsql, conn
    lst_Rut.Clear
    If Not objRS.EOF Then
        lst_Rut.Visible = True
    End If
    While Not objRS.EOF
        lst_Rut.AddItem objRS("CI_ALU")
        objRS.MoveNext
    Wend
    objRS.Close
    End If
End Sub








