VERSION 5.00
Begin VB.Form Form_cambio_rut_apo 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Cambio de Rut Apoderado"
   ClientHeight    =   1995
   ClientLeft      =   45
   ClientTop       =   375
   ClientWidth     =   6060
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MDIChild        =   -1  'True
   MinButton       =   0   'False
   ScaleHeight     =   1995
   ScaleWidth      =   6060
   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        =   6
      Top             =   120
      Visible         =   0   'False
      Width           =   2895
   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            =   4440
      TabIndex        =   5
      Top             =   120
      Visible         =   0   'False
      Width           =   1335
   End
   Begin VB.Frame Frame_Apo_Caja 
      Caption         =   "Busqueda del Apoderado"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00C00000&
      Height          =   735
      Left            =   120
      TabIndex        =   7
      Top             =   0
      Width           =   5775
      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            =   4320
         TabIndex        =   9
         Top             =   360
         Width           =   1335
      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            =   720
         TabIndex        =   8
         Top             =   360
         Width           =   2895
      End
      Begin VB.Label Label2 
         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            =   3840
         TabIndex        =   11
         Top             =   360
         Width           =   615
      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        =   10
         Top             =   360
         Width           =   735
      End
   End
   Begin VB.CommandButton Command5 
      Caption         =   "Limpiar"
      Height          =   372
      Left            =   4680
      TabIndex        =   4
      Top             =   840
      Width           =   972
   End
   Begin VB.CommandButton Command6 
      Caption         =   "Salir"
      Height          =   372
      Left            =   4680
      TabIndex        =   3
      Top             =   1320
      Width           =   972
   End
   Begin VB.Frame Frame3 
      Caption         =   "Cambiar Rut. Apoderado"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   7.5
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00C00000&
      Height          =   975
      Left            =   120
      TabIndex        =   0
      Top             =   840
      Width           =   3615
      Begin VB.TextBox txt_digito_cambio 
         Height          =   285
         Left            =   1320
         MaxLength       =   1
         TabIndex        =   12
         Top             =   360
         Width           =   255
      End
      Begin VB.TextBox txt_rut_cambio 
         Height          =   288
         Left            =   120
         MaxLength       =   9
         TabIndex        =   2
         Top             =   360
         Width           =   1095
      End
      Begin VB.CommandButton Command3 
         Caption         =   "Cambiar Rut."
         Height          =   372
         Left            =   1680
         TabIndex        =   1
         Top             =   360
         Width           =   1575
      End
   End
End
Attribute VB_Name = "Form_cambio_rut_apo"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False


Private Sub Command3_Click()
    Dim var_sql As String
    Dim rut As String
    
    If Len(txt_rut_cambio.Text) < 7 Or Len(txt_digito_cambio.Text) < 1 Then
        MsgBox "Debe ingresar el rut correcto para poder realizar el cambio de apoderado", vbInformation
        Exit Sub
    End If
    
    If digito(txt_rut_cambio.Text) <> txt_digito_cambio.Text Then
        MsgBox "Rut erroneo, debe ingresar un rut correcto", vbInformation
        Exit Sub
    End If
    
    rut = txt_rut_cambio.Text & "-" & txt_digito_cambio.Text
            
    var_sql = "update apo_x_alu set rut_apo = '" & rut & "' WHERE rut_apo = '" & txt_RutBusqueda.Text & "'"
    conn.Execute var_sql
    var_sql = "delete FROM apoderados WHERE rut_apo = '" & rut & "'"
    conn.Execute var_sql
    var_sql = "update apoderados set rut_apo = '" & rut & "' WHERE rut_apo = '" & txt_RutBusqueda.Text & "'"
    conn.Execute var_sql
    var_sql = "update fnza_mensualidad set run_apo = '" & rut & "' WHERE run_apo = '" & txt_RutBusqueda.Text & "'"
    conn.Execute var_sql
    var_sql = "update fnza_cuponeras set rut_apo = '" & rut & "' WHERE rut_apo = '" & txt_RutBusqueda.Text & "'"
    conn.Execute var_sql
    var_sql = "update fnza_cheques_recibidos set run_apo = '" & rut & "' WHERE run_apo = '" & txt_RutBusqueda.Text & "'"
    conn.Execute var_sql
    var_sql = "update fnza_boletas set run_apo = '" & rut & "' WHERE run_apo = '" & txt_RutBusqueda.Text & "'"
    conn.Execute var_sql
    Command5_Click
    MsgBox "El cambio de Rut fue realizado exitosamente", vbInformation
End Sub

Private Sub Command5_Click()
    txt_rut_cambio.Text = ""
    txt_RutBusqueda.Locked = False
    txt_NombreCompleto.Locked = False
    txt_RutBusqueda.Text = ""
    txt_NombreCompleto.Text = ""
    lst_Rut.Visible = False
    lst_Alumnos.Visible = False
    txt_rut_cambio.Locked = True
End Sub

Private Sub Command6_Click()
    Unload Me
End Sub

Private Sub Form_Load()
    txt_rut_cambio.Locked = True
    Command5_Click
End Sub

Private Sub lst_Alumnos_Click()
    '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 rut_apo" _
           & " FROM apoderados where concat(ape1_apo,' ',ape2_apo,' ',noms_apo) = '" _
           & 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("rut_apo")
        txt_rut_cambio.Text = objRS("rut_apo")
        txt_digito_cambio.Text = Mid(objRS("rut_apo"), Len(objRS("rut_apo")), 1)
    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
        txt_rut_cambio.Locked = False
    End If
 '   Option1.Value = False
  '  Option2.Value = False
   ' Option3.Value = False
   ' lbl_porcentaje.Visible = False
   ' txt_porcentaje.Text = ""
    'txt_porcentaje.Visible = False
End Sub

Private Sub lst_Rut_Click()
    txt_RutBusqueda.Text = lst_Rut.Text
    lst_Rut.Visible = False
    Dim objRS As ADODB.Recordset
    Dim varsql As String
    varsql = "SELECT rut_apo,ape1_apo,ape2_apo,noms_apo" _
           & " FROM apoderados where" _
           & " rut_apo ='" & txt_RutBusqueda.Text & "'"

    Set objRS = New ADODB.Recordset
        objRS.Open varsql, conn
    If Not objRS.EOF Then
        txt_NombreCompleto.Text = objRS("ape1_apo") & " " & objRS("ape2_apo") & " " & objRS("noms_apo")
        txt_rut_cambio.Text = objRS("rut_apo")
        txt_digito_cambio.Text = Mid(objRS("rut_apo"), Len(objRS("rut_apo")), 1)
    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
        txt_rut_cambio.Locked = False
    End If
   ' Option1.Value = False
   ' Option2.Value = 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 rut_apo,ape1_apo,ape2_apo,noms_apo" _
           & " FROM apoderados" _
           & " where concat(APE1_apo,' ',ape2_apo,' ',noms_apo) LIKE '" & txt_NombreCompleto.Text & "%'" _
           & " order by ape1_apo,ape2_apo,noms_apo"
    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("ape1_apo") & " " & objRS("ape2_apo") & " " & objRS("NOMs_apo")
        rut = Mid(objRS("rut_apo"), 1, 8)
        lst_Alumnos.ItemData(lst_Alumnos.NewIndex) = rut
        objRS.MoveNext
    Wend
    objRS.Close
    End If
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 rut_apo" _
           & " FROM apoderados" _
           & " where rut_apo LIKE '" & txt_RutBusqueda & "%'"
           
    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("rut_apo")
        objRS.MoveNext
    Wend
    objRS.Close
    End If
End Sub
