VERSION 5.00
Begin VB.Form Form_Marcar_Protesto 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Administrar Marcas de Protestos Pendientes."
   ClientHeight    =   3120
   ClientLeft      =   45
   ClientTop       =   435
   ClientWidth     =   8505
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MDIChild        =   -1  'True
   MinButton       =   0   'False
   ScaleHeight     =   3120
   ScaleWidth      =   8505
   Begin VB.ListBox List1 
      Height          =   1230
      Left            =   1680
      TabIndex        =   12
      Top             =   720
      Width           =   4455
   End
   Begin VB.ListBox List2 
      Height          =   1230
      Left            =   6240
      TabIndex        =   13
      Top             =   720
      Width           =   1335
   End
   Begin VB.Frame Frame2 
      Height          =   1095
      Left            =   1560
      TabIndex        =   3
      Top             =   0
      Width           =   6855
      Begin VB.CommandButton Btn_Ver_Alumno 
         Caption         =   "Ver"
         Height          =   255
         Left            =   6120
         TabIndex        =   6
         Top             =   480
         Width           =   615
      End
      Begin VB.TextBox Text2 
         Height          =   285
         Left            =   4680
         TabIndex        =   5
         Text            =   "Text2"
         Top             =   480
         Width           =   1335
      End
      Begin VB.TextBox Text1 
         Height          =   285
         Left            =   120
         TabIndex        =   4
         Text            =   "Text1"
         Top             =   480
         Width           =   4455
      End
   End
   Begin VB.Frame Frame1 
      Caption         =   "Buscar"
      ForeColor       =   &H00FF0000&
      Height          =   1095
      Left            =   120
      TabIndex        =   0
      Top             =   0
      Width           =   1335
      Begin VB.OptionButton Option1 
         Caption         =   "Titular C.C."
         Height          =   195
         Index           =   2
         Left            =   120
         TabIndex        =   15
         Top             =   720
         Width           =   1095
      End
      Begin VB.OptionButton Option1 
         Caption         =   "Apoderado"
         Height          =   195
         Index           =   1
         Left            =   120
         TabIndex        =   2
         Top             =   480
         Value           =   -1  'True
         Width           =   1095
      End
      Begin VB.OptionButton Option1 
         Caption         =   "Alumno"
         Height          =   195
         Index           =   0
         Left            =   120
         TabIndex        =   1
         Top             =   240
         Width           =   1095
      End
   End
   Begin VB.Frame Frame4 
      Caption         =   "Estado"
      ForeColor       =   &H00FF0000&
      Height          =   1815
      Left            =   5280
      TabIndex        =   10
      Top             =   1200
      Width           =   3135
      Begin VB.ComboBox cb_estado 
         Height          =   315
         Left            =   120
         TabIndex        =   21
         Top             =   720
         Width           =   1695
      End
      Begin VB.CommandButton cmb_cambiaestado 
         Caption         =   "Cambiar Estado"
         Height          =   615
         Left            =   1920
         TabIndex        =   11
         Top             =   600
         Width           =   1095
      End
   End
   Begin VB.Frame Frame3 
      Caption         =   "Información"
      ForeColor       =   &H00FF0000&
      Height          =   1815
      Left            =   120
      TabIndex        =   7
      Top             =   1200
      Width           =   5055
      Begin VB.Label Label3 
         Caption         =   "Estado"
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   240
         TabIndex        =   19
         Top             =   1200
         Width           =   1095
      End
      Begin VB.Label Label2 
         Caption         =   "Rut"
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   240
         TabIndex        =   18
         Top             =   720
         Width           =   735
      End
      Begin VB.Label Label1 
         Caption         =   "Nombre:"
         BeginProperty Font 
            Name            =   "MS Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   240
         TabIndex        =   17
         Top             =   240
         Width           =   855
      End
      Begin VB.Label Label_Estado 
         Caption         =   "Label_Estado"
         Height          =   255
         Left            =   240
         TabIndex        =   14
         Top             =   1440
         Width           =   2295
      End
      Begin VB.Label Label_RUT 
         Caption         =   "Label_RUT"
         Height          =   255
         Left            =   240
         TabIndex        =   9
         Top             =   960
         Width           =   2055
      End
      Begin VB.Label Label_Nombre 
         Caption         =   "Label_Nombre"
         Height          =   255
         Left            =   240
         TabIndex        =   8
         Top             =   480
         Width           =   4575
      End
   End
   Begin VB.Frame Frame6 
      Caption         =   "Guardar / Modificar"
      ForeColor       =   &H00FF0000&
      Height          =   1815
      Left            =   5280
      TabIndex        =   20
      Top             =   1200
      Width           =   3135
      Begin VB.CommandButton bt_cambiar 
         Caption         =   "Cambiar Estado"
         Height          =   615
         Left            =   1920
         TabIndex        =   33
         Top             =   600
         Width           =   1095
      End
      Begin VB.ComboBox cb_estad 
         Height          =   315
         Left            =   120
         TabIndex        =   32
         Top             =   720
         Width           =   1695
      End
   End
   Begin VB.Frame Frame5 
      Caption         =   "Cuenta Correntista"
      ForeColor       =   &H00FF0000&
      Height          =   1815
      Left            =   120
      TabIndex        =   16
      Top             =   1200
      Width           =   5055
      Begin VB.CommandButton bt_nuevo 
         Caption         =   "Nuevo"
         Height          =   255
         Left            =   4080
         TabIndex        =   34
         Top             =   1440
         Width           =   855
      End
      Begin VB.TextBox tx_apepat 
         Enabled         =   0   'False
         Height          =   285
         Left            =   1680
         TabIndex        =   30
         Top             =   840
         Width           =   2175
      End
      Begin VB.TextBox tx_nombre 
         Enabled         =   0   'False
         Height          =   285
         Left            =   1680
         TabIndex        =   29
         Top             =   540
         Width           =   2175
      End
      Begin VB.TextBox tx_rut 
         Enabled         =   0   'False
         Height          =   285
         Left            =   1680
         TabIndex        =   28
         Top             =   240
         Width           =   1215
      End
      Begin VB.TextBox tx_apemat 
         Enabled         =   0   'False
         Height          =   285
         Left            =   1680
         TabIndex        =   27
         Top             =   1140
         Width           =   2175
      End
      Begin VB.Label lb_estado 
         Height          =   255
         Left            =   1680
         TabIndex        =   31
         Top             =   1440
         Width           =   1215
      End
      Begin VB.Label Label8 
         Caption         =   "Estado"
         Height          =   255
         Left            =   360
         TabIndex        =   26
         Top             =   1440
         Width           =   1215
      End
      Begin VB.Label Label7 
         Caption         =   "Apellido Paterno"
         Height          =   255
         Left            =   360
         TabIndex        =   25
         Top             =   840
         Width           =   1215
      End
      Begin VB.Label Label6 
         Caption         =   "Apellido Materno"
         Height          =   255
         Left            =   360
         TabIndex        =   24
         Top             =   1140
         Width           =   1215
      End
      Begin VB.Label Label5 
         Caption         =   "Rut:"
         Height          =   255
         Left            =   360
         TabIndex        =   23
         Top             =   240
         Width           =   1215
      End
      Begin VB.Label Label4 
         Caption         =   "Nombre"
         Height          =   255
         Left            =   360
         TabIndex        =   22
         Top             =   540
         Width           =   1095
      End
   End
End
Attribute VB_Name = "Form_Marcar_Protesto"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'variables generales
Dim Flag_Sub As Boolean
Dim flag_new As Boolean

Private Sub bt_cambiar_Click()
    Dim Tipo, EstadO As String
    Dim RC As ADODB.Recordset
    Set RC = New ADODB.Recordset
    If Not ValidaRut(Trim(tx_rut.Text)) Then
        MsgBox "El Rut se encuentra mal ingresado"
        Exit Sub
    End If
    
    Tipo = "CTCT"
    Select Case cb_estad.Text
        Case "Ninguno": EstadO = "NONE"
        Case "Aclarado": EstadO = "ACLA"
        Case "Protesto": EstadO = "PROT"
    End Select
    sql = "REPLACE fnza_lista_protestos SET  rut = '" & tx_rut.Text & "', ape_pat = '" & UCase(tx_apepat.Text) & "', ape_mat = '" & UCase(tx_apemat.Text) & "', nombre = '" & UCase(tx_nombre.Text) & "', tipo = '" & Tipo & "', estado = '" & EstadO & "'"
    conn.Execute sql, Affected
    If Affected = 1 Then
        MsgBox "Cuenta Correntista Agregado"
    Else
        MsgBox "Se ha modificado el estado de protesto"
    End If
End Sub

Private Sub bt_nuevo_Click()
    tx_rut.Enabled = True
    tx_nombre.Enabled = True
    tx_apepat.Enabled = True
    tx_apemat.Enabled = True
    bt_cambiar.Enabled = True
    cb_estad.Enabled = True
    tx_rut.Text = ""
    tx_nombre.Text = ""
    tx_apepat.Text = ""
    tx_apemat.Text = ""
    flag_new = True
End Sub

Private Sub Btn_Ver_Alumno_Click()
    flag_new = False
    If Option1(0).Value = True Then
        llena_datos "ALUM", Text2.Text, Text1.Text
        cmb_cambiaestado.Enabled = True
        cb_estado.Enabled = True
    ElseIf Option1(1).Value = True Then
        llena_datos "APOD", Text2.Text, Text1.Text
        cmb_cambiaestado.Enabled = True
        cb_estado.Enabled = True
    ElseIf Option1(2).Value = True Then
        llena_datos "CTCT", Text2.Text, Text1.Text
        bt_nuevo.Enabled = False
        tx_rut.Enabled = False
        tx_nombre.Enabled = False
        tx_apepat.Enabled = False
        tx_apemat.Enabled = False
        bt_cambiar.Enabled = True
        cb_estad.Enabled = True
    End If
End Sub

Private Sub cmb_cambiaestado_Click()
    Dim Tipo, EstadO As String
    Dim RC As ADODB.Recordset
    Set RC = New ADODB.Recordset
    
    If Option1(0).Value = True Then
        RC.Open "SELECT ape_pat_alu as apepat, ape_mat_alu as apemat, nom_alu as nombre  FROM postulantes WHERE ci_alu='" & Label_RUT.Caption & "' ;", conn
        Tipo = "ALUM"
    ElseIf Option1(1).Value = True Then
        RC.Open "SELECT ape1_apo as apepat ,ape2_apo as apemat, noms_apo as nombre FROM apoderados where rut_apo='" & Label_RUT.Caption & "' ;", conn
        Tipo = "APOD"
    End If
    Select Case cb_estado.Text
        Case "Ninguno": EstadO = "NONE"
        Case "Aclarado": EstadO = "ACLA"
        Case "Protesto": EstadO = "PROT"
    End Select
    sql = "REPLACE fnza_lista_protestos SET  rut = '" & Label_RUT.Caption & "', ape_pat = '" & RC("apepat") & "', ape_mat = '" & RC("apemat") & "', nombre = '" & RC("nombre") & "', tipo = '" & Tipo & "', estado = '" & EstadO & "'"
    conn.Execute sql, Affected
    If Affected = 1 Then
        MsgBox "Estado Agregado"
    Else
        MsgBox "Se ha modificado el estado de protesto"
    End If
End Sub

Private Sub Form_Load()
    Flag_Sub = True
    Text1.Text = ""
    Text2.Text = ""
    Label_Nombre.Caption = ""
    Label_RUT.Caption = ""
    Label_Estado.Caption = ""
    List1.Visible = False
    List2.Visible = False
    Btn_Ver_Alumno.Enabled = False
    cmb_cambiaestado.Enabled = False
    Flag_Sub = False
    cb_estado.AddItem "Ninguno"
    cb_estado.AddItem "Aclarado"
    cb_estado.AddItem "Protesto"
    cb_estad.AddItem "Ninguno"
    cb_estad.AddItem "Aclarado"
    cb_estad.AddItem "Protesto"
    cb_estad.Enabled = False
    cb_estado.Enabled = False
End Sub

Private Sub List1_DblClick()
    Dim RC As ADODB.Recordset
    Set RC = New ADODB.Recordset
    
    Text1.Text = List1.Text
    List1.Visible = False
    List2.Visible = False
    If Option1(0).Value = True Then
        RC.Open "SELECT ci_alu FROM postulantes WHERE left(CONCAT(ape_Pat_alu,' ',ape_Mat_alu,' ',nom_alu)," & Len(Text1.Text) & ")='" & Text1.Text & "' ORDER BY ape_pat_alu, ape_mat_alu, nom_alu;", conn
    ElseIf Option1(1).Value = True Then
        RC.Open "SELECT rut_apo FROM `apoderados` where left(CONCAT(ape1_apo,' ',ape2_apo,' ',noms_apo)," & Len(Text1.Text) & ")='" & Text1.Text & "' ORDER BY ape1_apo, ape2_apo, noms_apo;", conn
    Else
        RC.Open "SELECT rut FROM fnza_lista_protestos WHERE LEFT(CONCAT(ape_pat,' ',ape_mat,' ',nombre)," & Len(Text1.Text) & ")='" & Text1.Text & "' ORDER BY ape_pat, ape_mat, nombre;", conn
    End If
    RC.MoveFirst
    Flag_Sub = True
    If Option1(0).Value = True Then
        Text2.Text = RC("ci_alu")
    ElseIf Option1(1).Value = True Then
        Text2.Text = RC("rut_apo")
    ElseIf Option1(2).Value = True Then
        Text2.Text = RC!Rut
    End If
    RC.Close
    Flag_Sub = False
    Btn_Ver_Alumno.Enabled = True
End Sub

Private Sub List2_DblClick()
    Dim RC As ADODB.Recordset
    Set RC = New ADODB.Recordset
    
    Text2.Text = List2.Text
    List2.Visible = False
    List1.Visible = False
    If Option1(0).Value = True Then
        RC.Open "SELECT CONCAT(ape_pat_alu,' ',ape_mat_alu,' ',nom_alu) as nombre_alu FROM postulantes WHERE ci_alu='" & Text2.Text & "' ORDER BY ci_alu;", conn
    ElseIf Option1(1).Value = True Then
        RC.Open "SELECT CONCAT(ape1_apo,' ',ape2_apo,' ',noms_apo) as nombre_apo FROM apoderados where rut_apo='" & Text2.Text & "' ORDER BY rut_apo;", conn
    Else
        RC.Open "SELECT CONCAT(ape_pat,' ',ape_mat,' ',nombre) as nombre_cc FROM fnza_lista_protestos WHERE rut='" & Text2.Text & "' ORDER BY rut;", conn
    End If
    RC.MoveFirst
    Flag_Sub = True
    If Option1(0).Value = True Then
        Text1.Text = RC("nombre_alu")
    ElseIf Option1(1).Value = True Then
        Text1.Text = RC("nombre_apo")
    ElseIf Option1(2).Value = True Then
        Text1.Text = RC!nombre_cc
    End If
    RC.Close
    Flag_Sub = False
    Btn_Ver_Alumno.Enabled = True
End Sub

Private Sub Option1_Click(Index As Integer)
    List1.Visible = False
    List2.Visible = False
    Text1 = ""
    Text2 = ""
    If Index = 2 Then
        Frame3.Visible = False
        Frame4.Visible = False
    Else
        Frame3.Visible = True
        Frame4.Visible = True
    End If
    tx_rut.Enabled = False
    tx_nombre.Enabled = False
    tx_apepat.Enabled = False
    tx_apemat.Enabled = False
    bt_cambiar.Enabled = False
    cb_estad.Enabled = False
    tx_rut.Text = ""
    tx_nombre.Text = ""
    tx_apepat.Text = ""
    tx_apemat.Text = ""
    cb_estad.Text = ""
    Label_Nombre.Caption = ""
    Label_RUT.Caption = ""
    Label_Estado.Caption = ""
    lb_estado.Caption = ""
    bt_nuevo.Enabled = True
End Sub

Private Sub Text1_Change()
     Dim RC As ADODB.Recordset
    ' Si el cambio lo hace un Sub no hacer nada
    If Flag_Sub Then Exit Sub
    If Text1.Text = "" Then Exit Sub
    Set RC = New ADODB.Recordset
    
    If Option1(0).Value = True Then
        RC.Open "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(Text1.Text) & ")='" & Text1.Text & "' AND a.ci_alu=m.ci_alu ORDER BY a.ape_pat_alu, a.ape_mat_alu, a.nom_alu;", conn
    ElseIf Option1(1).Value = True Then
        RC.Open "SELECT DISTINCT a.ape1_apo, a.ape2_apo, a.noms_apo FROM apoderados a, fnza_mensualidad fm where left(CONCAT(a.ape1_apo,' ',a.ape2_apo,' ',a.noms_apo)," & Len(Text1.Text) & ")='" & Text1.Text & "' and a.rut_apo=fm.run_apo ORDER BY a.ape1_apo, a.ape2_apo, a.noms_apo;", conn
    Else
        RC.Open "SELECT DISTINCT ape_pat, ape_mat, nombre FROM fnza_lista_protestos WHERE LEFT (CONCAT(ape_pat,' ',ape_mat,' ',nombre)," & Len(Text1.Text) & ")='" & Text1.Text & "' AND tipo='CTCT' ORDER BY ape_pat, ape_mat, nombre", conn
    End If
    List1.Clear
    If RC.RecordCount > 0 Then
        While Not (RC.EOF)
            If Option1(0).Value = True Then
                List1.AddItem RC("ape_pat_alu") & " " & RC("ape_mat_alu") & " " & RC("nom_alu")
            ElseIf Option1(1).Value = True Then
                List1.AddItem RC("ape1_apo") & " " & RC("ape2_apo") & " " & RC("noms_apo")
            ElseIf Option1(2).Value = True Then
                List1.AddItem RC!ape_pat & " " & RC!ape_mat & " " & RC!nombre
            End If
            RC.MoveNext
        Wend
        List1.Visible = True
        List2.Visible = False
    Else
        List1.Visible = False
        List2.Visible = False
    End If
    RC.Close
    If Option1(2).Value = True Then
        Btn_Ver_Alumno.Enabled = False
        bt_nuevo.Enabled = True
        Text2.Text = ""
    Else
        Btn_Ver_Alumno.Enabled = False
    End If
End Sub

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

Private Sub Text2_Change()
    Dim RC As ADODB.Recordset
    ' Si el cambio lo hace un Sub no hacer nada
    If Flag_Sub Then Exit Sub
    If Text2.Text = "" Then Exit Sub
    Set RC = New ADODB.Recordset
    If Option1(0).Value = True Then
        RC.Open "SELECT DISTINCT a.ci_alu FROM postulantes a, matriculas m WHERE left(a.ci_alu," & Len(Text2.Text) & ")='" & Text2.Text & "' AND a.ci_alu=m.ci_alu ORDER BY a.ci_alu;", conn
    ElseIf Option1(1).Value = True Then
        RC.Open "SELECT DISTINCT fm.run_apo FROM apoderados a, fnza_mensualidad fm WHERE left(a.rut_apo," & Len(Text2.Text) & ")='" & Text2.Text & "' AND a.rut_apo=fm.run_apo ORDER BY a.rut_apo;", conn
    Else
        RC.Open "SELECT DISTINCT rut FROM fnza_lista_protestos WHERE LEFT(rut," & Len(Text2.Text) & ")='" & Text2.Text & "' AND tipo='CTCT' ORDER BY rut", conn
    End If
    List2.Clear
    If RC.RecordCount > 0 Then
        While Not (RC.EOF)
            If Option1(0).Value = True Then
                List2.AddItem RC("ci_alu")
            ElseIf Option1(1).Value = True Then
                List2.AddItem RC("run_apo")
            ElseIf Option1(2).Value = True Then
                List2.AddItem RC!Rut
            End If
            RC.MoveNext
        Wend
        List1.Visible = False
        List2.Visible = True
    Else
        List1.Visible = False
        List2.Visible = False
    End If
    RC.Close
    If Option1(2).Value = True Then
        Btn_Ver_Alumno.Enabled = False
        bt_nuevo.Enabled = True
        Text1.Text = ""
    Else
        Btn_Ver_Alumno.Enabled = False
    End If
End Sub

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

Private Sub llena_datos(Tipo As String, ci As String, nombre As String)
    Dim RC As ADODB.Recordset
    Set RC = New ADODB.Recordset
    sql = "SELECT * FROM fnza_lista_protestos WHERE rut = '" & ci & "' AND tipo = '" & Tipo & "'"
    RC.Open sql, conn
    If Option1(2).Value Then
        tx_rut.Text = RC("rut")
        tx_nombre.Text = RC("nombre")
        tx_apepat.Text = RC("ape_pat")
        tx_apemat.Text = RC("ape_mat")
    Else
        Label_Nombre.Caption = nombre
        Label_RUT.Caption = ci
    End If
    If RC.RecordCount = 0 Then
        Label_Estado.Caption = "NINGUNO"
    Else
        Select Case RC("estado")
            Case "NONE": Label_Estado.Caption = "NINGUNO"
            Case "ACLA": Label_Estado.Caption = "ACLARADO"
            Case "PROT": Label_Estado.Caption = "PROTESTADO"
        End Select
    End If
    lb_estado.Caption = Label_Estado.Caption
End Sub

