VERSION 5.00
Begin VB.Form Form_Convenio_jardin 
   BorderStyle     =   1  'Fixed Single
   ClientHeight    =   3300
   ClientLeft      =   45
   ClientTop       =   435
   ClientWidth     =   10380
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MDIChild        =   -1  'True
   MinButton       =   0   'False
   ScaleHeight     =   3300
   ScaleWidth      =   10380
   Begin VB.ListBox List_nombre 
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   1320
      Left            =   840
      TabIndex        =   6
      TabStop         =   0   'False
      Top             =   720
      Visible         =   0   'False
      Width           =   5295
   End
   Begin VB.ListBox List_rut 
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   1320
      Left            =   6720
      TabIndex        =   5
      TabStop         =   0   'False
      Top             =   720
      Visible         =   0   'False
      Width           =   1335
   End
   Begin VB.CommandButton cmb_quita 
      Caption         =   "Quitar"
      Enabled         =   0   'False
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   405
      Left            =   9000
      TabIndex        =   19
      Top             =   2160
      Width           =   1215
   End
   Begin VB.CommandButton cmb_cambiaalumno 
      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          =   405
      Left            =   9000
      TabIndex        =   16
      Top             =   1200
      Width           =   1215
   End
   Begin VB.Frame Frame2 
      Height          =   2055
      Left            =   120
      TabIndex        =   7
      Top             =   1080
      Width           =   8655
      Begin VB.TextBox txt_rutapo 
         Enabled         =   0   'False
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   285
         Left            =   1200
         Locked          =   -1  'True
         TabIndex        =   20
         Top             =   240
         Width           =   1455
      End
      Begin VB.TextBox txt_jardin 
         Enabled         =   0   'False
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   285
         Left            =   1200
         TabIndex        =   17
         Top             =   1320
         Width           =   6375
      End
      Begin VB.TextBox txt_apo_alu 
         Enabled         =   0   'False
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   285
         Left            =   1200
         Locked          =   -1  'True
         TabIndex        =   13
         Top             =   600
         Width           =   3855
      End
      Begin VB.TextBox txt_direccion 
         Enabled         =   0   'False
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   285
         Left            =   1200
         Locked          =   -1  'True
         TabIndex        =   12
         Top             =   960
         Width           =   6375
      End
      Begin VB.Label lb_mensaje 
         BackColor       =   &H80000005&
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H00FF0000&
         Height          =   615
         Left            =   5160
         TabIndex        =   22
         Top             =   240
         Width           =   3375
      End
      Begin VB.Label Label5 
         Caption         =   "Apoderado"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   240
         TabIndex        =   21
         Top             =   240
         Width           =   855
      End
      Begin VB.Label Label4 
         Caption         =   "Jardin en convenio"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   375
         Left            =   240
         TabIndex        =   18
         Top             =   1440
         Width           =   855
      End
      Begin VB.Label Label15 
         Caption         =   "Apoderado"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   240
         TabIndex        =   15
         Top             =   600
         Width           =   855
      End
      Begin VB.Label Label17 
         Caption         =   "Dirección"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   240
         TabIndex        =   14
         Top             =   960
         Width           =   855
      End
   End
   Begin VB.CommandButton cmb_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          =   405
      Left            =   9000
      TabIndex        =   9
      Top             =   2640
      Width           =   1215
   End
   Begin VB.CommandButton cmb_guarda 
      Caption         =   "Guardar"
      Enabled         =   0   'False
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   405
      Left            =   9000
      TabIndex        =   8
      Top             =   1680
      Width           =   1215
   End
   Begin VB.Frame Frame1 
      Caption         =   "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          =   855
      Left            =   120
      TabIndex        =   0
      Top             =   120
      Width           =   10095
      Begin VB.ComboBox cmb_agno 
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   330
         Left            =   9120
         TabIndex        =   11
         Text            =   "2011"
         Top             =   360
         Width           =   735
      End
      Begin VB.TextBox txt_nombre 
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   285
         Left            =   720
         TabIndex        =   2
         Top             =   360
         Width           =   5295
      End
      Begin VB.TextBox txt_rut 
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   285
         Left            =   6600
         TabIndex        =   1
         Top             =   360
         Width           =   1335
      End
      Begin VB.Label Label3 
         Caption         =   "Año Matricula"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   8040
         TabIndex        =   10
         Top             =   360
         Width           =   1095
      End
      Begin VB.Label Label1 
         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        =   4
         Top             =   360
         Width           =   855
      End
      Begin VB.Label Label2 
         Caption         =   "Run"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   6120
         TabIndex        =   3
         Top             =   360
         Width           =   375
      End
   End
End
Attribute VB_Name = "Form_Convenio_jardin"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim Flag_sub As Boolean

Private Sub Cmb_Agno_Click()
    If txt_rut.Locked Then
        llena_info_adicional
    End If
End Sub

Private Sub cmb_cambiaalumno_Click()
    Flag_sub = True
    cmb_guarda.Enabled = False
    cmb_quita.Enabled = False
    txt_rut.Locked = False
    txt_nombre.Locked = False
    txt_jardin.Enabled = False
    txt_rut.Text = ""
    txt_nombre.Text = ""
    txt_apo_alu.Text = ""
    txt_Direccion.Text = ""
    txt_jardin.Text = ""
    txt_RutApo.Text = ""
    lb_mensaje.Caption = ""
    Flag_sub = False
End Sub

Private Sub cmb_guarda_Click()
    Dim accion As String
    
    
    If (MsgBox("Esta Seguro de aplicar el descuento al Alumno?", vbYesNo) = vbYes) Then
        sql = "REPLACE fnza_convenio_jardin SET run_alu = '" & txt_rut.Text & "', agno = " & Cmb_Agno.Text & ", run_apo = '" & txt_RutApo.Text & "', jardin = '" & txt_jardin.Text & "', fecha_asignacion = '" & Format(Date, "yyyy-mm-dd") & "', usuario = '" & Nom_com_usu_ses & "'"
        conn.Execute sql, Affected
        If Affected > 0 Then
            accion = "Se ha agregado convenio de jardin al alumno con rut :" & txt_rut.Text
            Call Inserta_Vitacora_Alumno(txt_rut.Text, accion)
            
            RecalculaCuota_Alu txt_rut.Text, Cmb_Agno.Text, conn
            guarda_log txt_rut.Text, "INSERTA/MODIFICA CONVENIO", Cmb_Agno.Text, txt_jardin.Text
            lb_mensaje.Caption = "Con convenio para el año " & Cmb_Agno.Text
            lb_mensaje.ForeColor = &HFF0000
            lb_mensaje.Refresh
            MsgBox "Datos Guardados"
        Else
            MsgBox "Ocurrio un problema durante el guardado de los datos"
        End If
    End If
End Sub

Private Sub cmb_quita_Click()
    Dim accion As String
    If (MsgBox("Esta Seguro de eliminar el descuento al Alumno?", vbYesNo) = vbYes) Then
        sql = "DELETE FROM fnza_convenio_jardin WHERE run_alu = '" & txt_rut.Text & "' AND agno = " & Cmb_Agno.Text
        conn.Execute sql, Affected
        If Affected > 0 Then
        
            accion = "Se ha eliminado el convenio de jardin al alumno con rut :" & txt_rut.Text
            Call Inserta_Vitacora_Alumno(txt_rut.Text, accion)
        
            RecalculaCuota_Alu txt_rut.Text, Cmb_Agno.Text, conn
            guarda_log txt_rut.Text, "ELIMINA CONVENIO", Cmb_Agno.Text, txt_jardin.Text
            lb_mensaje.Caption = "Sin convenio para el año " & Cmb_Agno.Text
            lb_mensaje.ForeColor = &HFF&
            lb_mensaje.Refresh
            txt_jardin.Text = ""
            MsgBox "Datos Eliminados"
        Else
            MsgBox "Ocurrio un problema durante la eliminacion de los datos"
        End If
    End If
End Sub

Private Sub cmb_salir_Click()
    Unload Me
End Sub



Private Sub Form_Load()
    Call llenacombo(Me.Cmb_Agno, "matriculas", "anno_mat", " group by anno_mat order by anno_mat desc", conn)
    Cmb_Agno.ListIndex = 0
End Sub



Private Sub list_nombre_Click()
    Dim RC As ADODB.Recordset
    Set RC = New ADODB.Recordset
    
    txt_nombre.Text = list_nombre.Text
    list_nombre.Visible = False
    list_rut.Visible = False
    RC.Open "SELECT ci_alu FROM postulantes WHERE left(CONCAT(ape_Pat_alu,' ',ape_Mat_alu,' ',nom_alu)," & Len(txt_nombre.Text) & ")='" & txt_nombre.Text & "' ORDER BY ape_pat_alu, ape_mat_alu, nom_alu;", conn
    RC.MoveFirst
    Flag_sub = True
    txt_rut.Text = RC("ci_alu")
    RC.Close
    Flag_sub = False
    txt_rut.Locked = True
    txt_nombre.Locked = True
    llena_info_adicional
End Sub

Private Sub list_rut_Click()
    Dim RC As ADODB.Recordset
    Set RC = New ADODB.Recordset
    
    txt_rut.Text = list_rut.Text
    list_nombre.Visible = False
    list_rut.Visible = False
    RC.Open "SELECT CONCAT(ape_pat_alu,' ',ape_mat_alu,' ',nom_alu) as nombre_alu FROM postulantes WHERE ci_alu='" & txt_rut.Text & "' ORDER BY ci_alu;", conn
    RC.MoveFirst
    Flag_sub = True
    txt_nombre.Text = RC("nombre_alu")
    RC.Close
    Flag_sub = False
    txt_nombre.Locked = True
    txt_rut.Locked = True
    llena_info_adicional
End Sub


Private Sub txt_jardin_KeyPress(KeyAscii As Integer)
    KeyAscii = Asc(UCase(Chr(KeyAscii)))
End Sub

Private Sub txt_nombre_Change()
    Dim sql As String
    Dim RC As ADODB.Recordset
    ' Si el cambio lo hace un Sub no hacer nada
    If Flag_sub Then Exit Sub
    If txt_nombre.Text = "" Then Exit Sub
    Set RC = New ADODB.Recordset
    sql = "SELECT DISTINCT a.ape_pat_alu, a.ape_mat_alu, a.nom_alu FROM postulantes a, matriculas m WHERE left(CONCAT(a.ape_pat_alu,' ',a.ape_mat_alu,' ',a.nom_alu)," & Len(txt_nombre.Text) & ")='" & txt_nombre.Text & "' AND a.ci_alu=m.ci_alu AND m.anno_mat = " & Cmb_Agno.Text & " and ((m.cod_ens = '110' and m.num_gra <= 8) or (m.cod_ens = '010') or (m.cod_ens = '996')) ORDER BY a.ape_pat_alu, a.ape_mat_alu, a.nom_alu"
    RC.Open sql, conn
    list_nombre.Clear
    If RC.RecordCount > 0 Then
        While Not (RC.EOF)
            list_nombre.AddItem RC("ape_pat_alu") & " " & RC("ape_mat_alu") & " " & RC("nom_alu")
            RC.MoveNext
        Wend
        list_nombre.Visible = True
        list_rut.Visible = False
    End If
    RC.Close
End Sub

Private Sub txt_rut_Change()
    Dim sql As String
    Dim RC As ADODB.Recordset
    ' Si el cambio lo hace un Sub no hacer nada
    If Flag_sub Then Exit Sub
    If txt_rut.Text = "" Then Exit Sub
    Set RC = New ADODB.Recordset
    sql = "SELECT DISTINCT a.ci_alu FROM postulantes a, matriculas m WHERE left(a.ci_alu," & Len(txt_rut.Text) & ")='" & txt_rut.Text & "' AND a.ci_alu=m.ci_alu AND m.anno_mat = " & Cmb_Agno.Text & " and ((m.cod_ens = '110' and m.num_gra <= 8) or (m.cod_ens = '010') or (m.cod_ens = '996')) ORDER BY a.ci_alu;"
    RC.Open sql, conn
    list_rut.Clear
    If RC.RecordCount > 0 Then
        While Not (RC.EOF)
            list_rut.AddItem RC("ci_alu")
            RC.MoveNext
        Wend
        list_nombre.Visible = False
        list_rut.Visible = True
    End If
    RC.Close
End Sub

Private Sub llena_info_adicional()
    Dim RC As ADODB.Recordset
    Set RC = New ADODB.Recordset
    cmb_guarda.Enabled = True
    cmb_quita.Enabled = True
    txt_jardin.Enabled = True
    lb_mensaje.Caption = ""
    Indi = 0
    Busqueda = 0
    Busqueapo = 0
    RutApo = devuelvecampo("apo_x_alu", "", "rut_apo", "ci_alu ='" & txt_rut.Text & "' AND agno = " & Cmb_Agno.Text, conn)
    nombreapo = devuelvecampo("apoderados", "", "noms_apo", "rut_apo ='" & RutApo & "'", conn)
    ape1apo = devuelvecampo("apoderados", "", "ape1_apo", "rut_apo ='" & RutApo & "'", conn)
    ape2apo = devuelvecampo("apoderados", "", "ape2_apo", "rut_apo ='" & RutApo & "'", conn)
    dirapo = devuelvecampo("apoderados", "", "dir_apo", "rut_apo ='" & RutApo & "'", conn)
    txt_apo_alu.Text = nombreapo & " " & ape1apo & " " & ape2apo
    txt_Direccion.Text = dirapo
    txt_RutApo.Text = RutApo
    RC.Open "SELECT jardin FROM fnza_convenio_jardin WHERE run_alu = '" & txt_rut.Text & "' AND agno = " & Cmb_Agno.Text, conn
    If RC.RecordCount > 0 Then
        txt_jardin.Text = RC("jardin")
        lb_mensaje.Caption = "Con convenio para el año " & Cmb_Agno.Text
        lb_mensaje.ForeColor = &HFF0000
        lb_mensaje.Refresh
    Else
        lb_mensaje.Caption = "Sin convenio para el año " & Cmb_Agno.Text
        lb_mensaje.ForeColor = &HFF&
        lb_mensaje.Refresh
    End If
    RC.Close
End Sub

Private Sub guarda_log(run_alu As String, accion As String, agno As String, jardin As String)
    sql = "CREATE TABLE IF NOT EXISTS `fnza_log_convenio_jardin`(`id` bigint(20) NOT NULL auto_increment,`LOGIN_USUARIO` varchar(100) NOT NULL default '',`NOMBRE_USUARIO` varchar(100) NOT NULL default '',`NOMBRE_JARDIN` varchar(100) NOT NULL default '',`RUN_ALU` varchar(10) NOT NULL default '',`AGNO` int(11) NOT NULL default '0',`ACCION` varchar(100) NOT NULL default '',`FECHA_MODIFICACION` datetime NOT NULL default '0000-00-00 00:00:00',PRIMARY KEY  (`id`),UNIQUE KEY `becas_log_sec_key` (`FECHA_MODIFICACION`,`LOGIN_USUARIO`),KEY `becas_log_index_one` (`RUN_ALU`,`AGNO`)) ENGINE=MyISAM;"
    conn.Execute sql
    sql = "INSERT INTO fnza_log_convenio_jardin(LOGIN_USUARIO,NOMBRE_USUARIO,AGNO,FECHA_MODIFICACION,ACCION, RUN_ALU, NOMBRE_JARDIN) VALUES ('" & Nom_usu_ses & "','" & Nom_com_usu_ses & "','" & agno & "',concat(current_date,' ',current_time),'" & accion & "','" & run_alu & "','" & jardin & "');"
    conn.Execute sql
End Sub
