VERSION 5.00
Begin VB.Form Form_man_asi_x_prof 
   BorderStyle     =   3  'Fixed Dialog
   Caption         =   "Mantención de asignaturas por profesor"
   ClientHeight    =   5550
   ClientLeft      =   45
   ClientTop       =   435
   ClientWidth     =   10515
   Icon            =   "Form_man_asi_x_prof.frx":0000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MDIChild        =   -1  'True
   MinButton       =   0   'False
   ScaleHeight     =   5550
   ScaleWidth      =   10515
   ShowInTaskbar   =   0   'False
   Begin VB.Frame Frame_Asi_x_prof 
      Caption         =   "Asignaturas por Profesor"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00C00000&
      Height          =   5295
      Left            =   120
      TabIndex        =   0
      Top             =   120
      Width           =   10335
      Begin VB.ListBox lst_nom_asi_prof 
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   1110
         Left            =   1200
         TabIndex        =   1
         Top             =   720
         Visible         =   0   'False
         Width           =   4095
      End
      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            =   1200
         Style           =   2  'Dropdown List
         TabIndex        =   22
         Top             =   360
         Width           =   1455
      End
      Begin VB.TextBox txt_dig_asi_prof 
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   285
         Left            =   2400
         TabIndex        =   14
         Top             =   1080
         Width           =   255
      End
      Begin VB.TextBox txt_rut_asi_prof 
         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        =   13
         Top             =   1080
         Width           =   1095
      End
      Begin VB.TextBox txt_nom_asi_prof 
         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
         MaxLength       =   30
         TabIndex        =   12
         Top             =   720
         Width           =   4095
      End
      Begin VB.ComboBox cmb_numgra_asi_prof 
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   330
         Left            =   1200
         TabIndex        =   11
         Top             =   1800
         Width           =   1095
      End
      Begin VB.ComboBox cmb_mod_asi_prof 
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   330
         Left            =   1200
         TabIndex        =   10
         Top             =   1440
         Width           =   3015
      End
      Begin VB.ListBox lst_asi_existentes 
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   2160
         Left            =   120
         Sorted          =   -1  'True
         TabIndex        =   9
         Top             =   3000
         Width           =   4695
      End
      Begin VB.ListBox lst_asi_asignadas 
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   2160
         Left            =   5880
         Sorted          =   -1  'True
         TabIndex        =   8
         Top             =   3000
         Width           =   4335
      End
      Begin VB.CommandButton Btn_asigna_asi 
         Height          =   615
         Left            =   5040
         Picture         =   "Form_man_asi_x_prof.frx":2A8B2
         Style           =   1  'Graphical
         TabIndex        =   7
         Top             =   3240
         Width           =   615
      End
      Begin VB.CommandButton btn_quita_asi 
         Height          =   615
         Left            =   5040
         Picture         =   "Form_man_asi_x_prof.frx":2AF27
         Style           =   1  'Graphical
         TabIndex        =   6
         Top             =   4200
         Width           =   615
      End
      Begin VB.CommandButton btn_lim_asi_prof 
         Caption         =   "Limpiar"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   375
         Left            =   7080
         TabIndex        =   5
         Top             =   360
         Width           =   1215
      End
      Begin VB.CommandButton btn_cerr_asi_prof 
         Caption         =   "Cerrar"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   375
         Left            =   7080
         TabIndex        =   4
         Top             =   840
         Width           =   1215
      End
      Begin VB.ComboBox cmb_let_cur_asi_prof 
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   330
         Left            =   3240
         TabIndex        =   3
         Top             =   1800
         Width           =   975
      End
      Begin VB.CommandButton btn_carga_asignaturas 
         Caption         =   "Carga Oculta"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   375
         Left            =   7080
         TabIndex        =   2
         Top             =   1320
         Visible         =   0   'False
         Width           =   1215
      End
      Begin VB.Label Label3 
         Caption         =   "Año:"
         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        =   23
         Top             =   375
         Width           =   375
      End
      Begin VB.Label lbl_rut_PRO 
         Caption         =   "Rut"
         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             =   1080
         Width           =   1335
      End
      Begin VB.Label lbl_nom_PRO 
         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            =   240
         TabIndex        =   20
         Top             =   720
         Width           =   1095
      End
      Begin VB.Label Label16 
         Caption         =   "Nivel"
         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        =   19
         Top             =   1800
         Width           =   975
      End
      Begin VB.Label Label17 
         Caption         =   "Modalidad"
         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        =   18
         Top             =   1440
         Width           =   975
      End
      Begin VB.Label Label18 
         Caption         =   "Letra"
         Height          =   255
         Left            =   2640
         TabIndex        =   17
         Top             =   1560
         Width           =   495
      End
      Begin VB.Label Label21 
         Caption         =   "Asignaturas Disponibles"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   -1  'True
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   600
         TabIndex        =   16
         Top             =   2640
         Width           =   2055
      End
      Begin VB.Label Label22 
         Caption         =   "Asignaturas Asignadas"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   -1  'True
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   7080
         TabIndex        =   15
         Top             =   2640
         Width           =   2055
      End
   End
End
Attribute VB_Name = "Form_man_asi_x_prof"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub cmb_agno_Click()
    If cmb_let_cur_asi_prof.Text <> "" Then cmb_let_cur_asi_prof_Click
End Sub

Private Sub Form_Load()
    txt_rut_asi_prof.Enabled = False
    txt_dig_asi_prof.Enabled = False
    cmb_mod_asi_prof.Clear
    cmb_numgra_asi_prof.Clear
    cmb_let_cur_asi_prof.Clear
    Call LlenaCombo(cmb_mod_asi_prof, "codigos_ensenanza", "des_ens", "order by ord_ens", conn)
    Call LlenaCombo(cmb_agno, "cursos", "distinct agno", "order by agno desc", conn)
    cmb_mod_asi_prof.Enabled = False
    cmb_numgra_asi_prof.Enabled = False
    cmb_let_cur_asi_prof.Enabled = False
    lst_asi_existentes.Clear
    lst_asi_asignadas.Clear
    Btn_asigna_asi.Enabled = False
    btn_quita_asi.Enabled = False
    CentrarForma Me
End Sub

Private Sub Btn_asigna_asi_Click()
    Dim grado As String
    Dim accion As String
    Dim nombreasignatura As String
    Dim accion_realizada As String
    Dim curso As String
    Dim log As Boolean
    Dim RutProfe As String
    Dim rs As ADODB.Recordset
    Set rs = New ADODB.Recordset
    
    If Me.lst_asi_existentes.Text <> "" Then
    If Len(Me.cmb_let_cur_asi_prof.Text) <> 0 Then
        CodModalidad = DevuelveCampo("codigos_ensenanza", "", "cod_ens", "des_ens = '" & Me.cmb_mod_asi_prof.Text & "'", conn)
        Ngrado = Me.cmb_numgra_asi_prof.Text
        RutProfe = Me.txt_rut_asi_prof.Text + "-" + Me.txt_dig_asi_prof.Text
        letracurso = Me.cmb_let_cur_asi_prof.Text
        nombreasignatura = Me.lst_asi_existentes.Text
        rs.CursorLocation = adUseClient
        'se modifica por jvv 09-05-2022
        'a = "select cod_sec, cod_asi from subsectores where cod_ens = '" & CodModalidad & "' and nom_asi = '" & Trim(nombreasignatura) & "' and num_gra = '" & Ngrado & "'"
        a = "select cod_sec, cod_asi from subsectores where cod_ens = '" & CodModalidad & "' and nom_asi = '" & Trim(Mid(nombreasignatura, InStr(nombreasignatura, " "), Len(nombreasignatura))) & "' and num_gra = '" & Ngrado & "'"
        rs.CursorLocation = adUseClient
        rs.Open a, conn
        ' aqui siempre tomara la primera asignatura que encuentre con ese nombre porque se supone
        ' que los nombres de asignatura no se deben repetir
        If rs.RecordCount > 0 Then
            codasignatura = rs("cod_asi")
            codsectorasi = rs("cod_sec")
        End If
        rs.Close
        If Not ExistReg("asi_x_cur_prof", "cod_sec = '" & codsectorasi & "' and cod_asi = '" & codasignatura & "' and cod_ens = '" & CodModalidad & "' and num_gra = '" & Ngrado & "' and let_cur = '" & letracurso & "' and agno =" & cmb_agno.Text, conn) Then
            conn.Execute "INSERT INTO asi_x_cur_prof (cod_sec, cod_asi, rut_prof, cod_ens, num_gra, let_cur, agno) values(" & "'" & codsectorasi & "' , '" & codasignatura & "' , '" & RutProfe & "' , '" & CodModalidad & "' , '" & Ngrado & "' , '" & letracurso & "'," & cmb_agno.Text & ")"
            If Not ExistReg("sitprof_x_asi", "rut_prof = '" & RutProfe & "' and  cod_sec = '" & codsectorasi & "' and cod_asi = '" & codasignatura & "' and cod_ens ='" & CodModalidad & "' and num_gra ='" & Ngrado & "' and agno = " & cmb_agno.Text, conn) Then
                conn.Execute "INSERT INTO sitprof_x_asi(cod_sec, cod_asi, rut_prof, cod_ens, num_gra, cod_sit_prof, agno) values(" & "'" & codsectorasi & "' , '" & codasignatura & "' , '" & RutProfe & "' , '" & CodModalidad & "' , '" & Ngrado & "' , 'TIT', " & cmb_agno.Text & ")"
            End If
            
            ' Insertar Log de ASIGNACION de asignatura.
                Select Case CodModalidad
                    Case "996"
                        grado = "PK"
                    Case "010"
                        grado = "K"
                    Case "110"
                        grado = "EB"
                    Case "310"
                        grado = "EM"
                End Select
                curso = CStr(Ngrado) & "º " & letracurso & " " & grado
                accion_realizada = "Al profesor " & txt_nom_asi_prof.Text _
                                 & " se le a ASIGNADO la asignatura " _
                                 & nombreasignatura & " con codigo de subsector " & codasignatura _
                                 & " y codigo de sector " & codsectorasi _
                                 & " para el curso " & curso _
                                 & " para el año " & cmb_agno
                log = Inserta_Vitacora_Profesores(RutProfe, "ASIGNAR ASIGNATURA", accion_realizada)
            ' Fin Log.
            
            Me.lst_asi_asignadas.AddItem nombreasignatura
            cmb_let_cur_asi_prof_Click
            btn_carga_asignaturas_Click
        Else
            profeconasig = DevuelveCampo("asi_x_cur_prof", "", "rut_prof", "cod_sec = '" & codsectorasi & "' and cod_asi = '" & codasignatura & "' and cod_ens = '" & CodModalidad & "' and num_gra = '" & Ngrado & "' and let_cur = '" & letracurso & "' and agno = " & cmb_agno.Text, conn)
            nombreprofe = DevuelveCampo("profesores", "", "noms_prof", "rut_prof = '" & profeconasig & "'", conn)
            apellido1profe = DevuelveCampo("profesores", "", "ape1_prof", "rut_prof = '" & profeconasig & "'", conn)
            apellido2profe = DevuelveCampo("profesores", "", "ape2_prof", "rut_prof = '" & profeconasig & "'", conn)
            MsgBox ("La asignatura ya es impartida por " & nombreprofe & " " & apellido1profe & " " & apellido2profe & vbCrLf & "en este curso")
        End If
    Else
        Me.cmb_let_cur_asi_prof.SetFocus
        MsgBox ("Debe asignar letra al curso")
    End If
    Else
        MsgBox ("Debe seleccionar asignatura")
    End If
End Sub

Private Sub btn_carga_asignaturas_Click()
    Dim ax As String
    Dim campo As String
    campo = "Cod_asi" & "," & "nom_asi"
    CodModalidad = DevuelveCampo("codigos_ensenanza", "", "cod_ens", "des_ens = '" & Me.cmb_mod_asi_prof.Text & "'", conn)
    Ngrado = Me.cmb_numgra_asi_prof.Text
    ax = "where cod_ens = '" & CodModalidad & "' and num_gra = '" & Ngrado & "'"
    Me.lst_asi_existentes.Clear
    
    Call llenalistaespecialAsignatura(lst_asi_existentes, "subsectores", campo, ax, conn)
    If Me.lst_asi_existentes.ListCount > 0 Then
        Me.Btn_asigna_asi.Enabled = True
    Else
        Me.Btn_asigna_asi.Enabled = False
    End If
End Sub

Private Sub btn_cerr_asi_prof_Click()
    Unload Me
End Sub
Private Sub btn_lim_asi_prof_Click()
    Me.txt_nom_asi_prof.Locked = False
    Me.txt_nom_asi_prof.Text = ""
    Me.lst_nom_asi_prof.Clear
    Me.lst_nom_asi_prof.Visible = False
    Me.txt_rut_asi_prof.Text = ""
    Me.txt_dig_asi_prof.Text = ""
    Me.txt_rut_asi_prof.Enabled = False
    Me.txt_dig_asi_prof.Enabled = False
    Me.cmb_mod_asi_prof.Clear
    Me.cmb_numgra_asi_prof.Clear
    Me.cmb_let_cur_asi_prof.Clear
    Me.lst_asi_existentes.Clear
    Me.lst_asi_asignadas.Clear
    Call LlenaCombo(cmb_mod_asi_prof, "codigos_ensenanza", "des_ens", "order by ord_ens", conn)
    Me.cmb_mod_asi_prof.Enabled = False
    Me.cmb_numgra_asi_prof.Enabled = False
    Me.cmb_let_cur_asi_prof.Enabled = False
    Me.txt_nom_asi_prof.SetFocus
End Sub

Private Sub btn_quita_asi_Click()
    Dim grado As String
    Dim accion As String
    Dim nombreasignatura As String
    Dim accion_realizada As String
    Dim curso As String
    Dim log As Boolean
    Dim RutProfe As String
    Dim rs As ADODB.Recordset
    Set rs = New ADODB.Recordset
    
    If Me.lst_asi_asignadas.Text <> "" Then
        CodModalidad = DevuelveCampo("codigos_ensenanza", "", "cod_ens", "des_ens = '" & Me.cmb_mod_asi_prof.Text & "'", conn)
        Ngrado = Me.cmb_numgra_asi_prof.Text
        RutProfe = Me.txt_rut_asi_prof.Text + "-" + Me.txt_dig_asi_prof.Text
        letracurso = Me.cmb_let_cur_asi_prof.Text
        nombreasignatura = Me.lst_asi_asignadas.Text
        rs.CursorLocation = adUseClient
        'se modifica por jvv 10-02-2022
        a = "select cod_sec, cod_asi from subsectores where cod_ens = '" & CodModalidad & "' and nom_asi = '" & Trim(Mid(nombreasignatura, InStr(nombreasignatura, " "), Len(nombreasignatura))) & "' and num_gra = '" & Ngrado & "'"
        rs.Open a, conn
        ' aqui siempre tomara la primera asignatura que encuentre con ese nombre porque se supone
        ' que los nombres de asignatura no se deben repetir
        If rs.RecordCount > 0 Then
            codasignatura = rs("cod_asi")
            codsectorasi = rs("cod_sec")
        End If
        rs.Close
        'Borro el registro de la tabla asi_x_cur_prof
        conn.Execute "DELETE FROM asi_x_cur_prof WHERE cod_sec = '" & codsectorasi & "' and cod_asi = '" & codasignatura & "' and rut_prof = '" & RutProfe & "' and cod_ens = '" & CodModalidad & "' and num_gra = '" & Ngrado & "' and let_cur = '" & letracurso & "' and agno = " & cmb_agno.Text
        'Borro el registro de la tabla sitprof_x_asi pero antes pregunto si no imparte
        'a "NINGÚN" curso la asignatura.
        If Not ExistReg("asi_x_cur_prof", "rut_prof ='" & RutProfe & "' and cod_sec = '" & codsectorasi & "' and cod_asi = '" & codasignatura & "' and cod_ens = '" & CodModalidad & "' and num_gra = '" & Ngrado & "' and agno = " & cmb_agno.Text, conn) Then
            conn.Execute "DELETE FROM sitprof_x_asi WHERE cod_sec = '" & codsectorasi & "' and cod_asi = '" & codasignatura & "' and rut_prof = '" & RutProfe & "' and cod_ens = '" & CodModalidad & "' and num_gra = '" & Ngrado & "' and agno = " & cmb_agno.Text
        End If
        
        ' Insertar Log de DES-ASIGNACION de asignatura.
                Select Case CodModalidad
                    Case "996"
                        grado = "PK"
                    Case "010"
                        grado = "K"
                    Case "110"
                        grado = "EB"
                    Case "310"
                        grado = "EM"
                End Select
                curso = CStr(Ngrado) & "º " & letracurso & " " & grado
                accion_realizada = "Al profesor " & txt_nom_asi_prof.Text _
                                 & " se le a DES-ASIGNADO la asignatura " _
                                 & nombreasignatura & " con codigo de subsector " & codasignatura _
                                 & " y codigo de sector " & codsectorasi _
                                 & " para el curso " & curso _
                                 & " para el año " & cmb_agno
                log = Inserta_Vitacora_Profesores(RutProfe, "DES-ASIGNAR ASIGNATURA", accion_realizada)
        ' Fin Log.
        
        cmb_let_cur_asi_prof_Click
        btn_carga_asignaturas_Click
    Else
        MsgBox ("Debe seleccionar asignatura")
    End If
End Sub

Private Sub cmb_let_cur_asi_prof_Change()
    If Len(Me.cmb_let_cur_asi_prof.Text) <> 0 Then
        Me.cmb_let_cur_asi_prof.Text = letracursoaux
    End If
End Sub

Private Sub cmb_let_cur_asi_prof_Click()
    Dim RsAux As ADODB.Recordset
    Set RsAux = New ADODB.Recordset
    
    If cmb_agno.Text = "" Then MsgBox "Seleccione Año": cmb_let_cur_asi_prof.Text = "": Exit Sub
    CodModalidad = DevuelveCampo("codigos_ensenanza", "", "cod_ens", "des_ens = '" & Me.cmb_mod_asi_prof.Text & "'", conn)
    Ngrado = Me.cmb_numgra_asi_prof.Text
    RutProfe = Me.txt_rut_asi_prof.Text + "-" + Me.txt_dig_asi_prof.Text
    letracurso = Me.cmb_let_cur_asi_prof.Text
    Me.lst_asi_asignadas.Clear
    RsAux.CursorLocation = adUseClient
    RsAux.Open "select cod_sec, cod_asi from asi_x_cur_prof where rut_prof = '" & RutProfe & "' and cod_ens = '" & CodModalidad & "' and num_gra = '" & Ngrado & "' and let_cur = '" & letracurso & "' and agno = " & cmb_agno.Text, conn
    If RsAux.RecordCount > 0 Then
        While Not RsAux.EOF
            asigprofecurso = DevuelveCampo("subsectores", "", "Nom_asi", "cod_sec = '" & RsAux("cod_sec") & "' and cod_asi = '" & RsAux("cod_asi") & "' and num_gra = '" & Ngrado & "' and cod_ens = '" & CodModalidad & "'", conn)
            'Me.lst_asi_asignadas.AddItem  asigprofecurso
            Me.lst_asi_asignadas.AddItem "(" & RsAux!cod_asi & ")" & " " & asigprofecurso
            RsAux.MoveNext
        Wend
    End If
    RsAux.Close
    If Me.lst_asi_asignadas.ListCount > 0 Then
        Me.btn_quita_asi.Enabled = True
    Else
        Me.btn_quita_asi.Enabled = False
    End If
    btn_carga_asignaturas_Click
End Sub

Private Sub cmb_let_cur_asi_prof_KeyPress(KeyAscii As Integer)
    KeyAscii = 0
End Sub

Private Sub cmb_mod_asi_prof_Click()
    Me.cmb_numgra_asi_prof.Clear
    Me.cmb_let_cur_asi_prof.Clear
    Me.lst_asi_existentes.Clear
    Me.lst_asi_asignadas.Clear
    Me.cmb_let_cur_asi_prof.Enabled = False
    If Len(Me.cmb_mod_asi_prof.Text) <> 0 Then
     nivel = DevuelveCampo("codigos_ensenanza", "des_ens", "num_gra_max", "des_ens = " & "'" & Me.cmb_mod_asi_prof.Text & "'", conn)
     Me.cmb_numgra_asi_prof.Enabled = True
     Me.cmb_numgra_asi_prof.Clear
     For t = 1 To val(nivel)
        Me.cmb_numgra_asi_prof.AddItem t
     Next t
    End If
End Sub

Private Sub cmb_mod_asi_prof_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 And Len(Me.cmb_mod_asi_prof.Text) <> 0 Then
        Me.cmb_numgra_asi_prof.Enabled = True
        Me.cmb_numgra_asi_prof.SetFocus
    End If
    KeyAscii = 0
End Sub

Private Sub cmb_numgra_asi_prof_Click()
    CodModalidad = DevuelveCampo("codigos_ensenanza", "", "cod_ens", "des_ens = '" & Me.cmb_mod_asi_prof.Text & "'", conn)
    Ngrado = Me.cmb_numgra_asi_prof.Text
    Me.cmb_let_cur_asi_prof.Clear
    Call LlenaCombo(cmb_let_cur_asi_prof, "cursos", "let_cur", "where cod_ens = '" & CodModalidad & "' and num_gra = '" & Ngrado & "' and agno='" & Trim(cmb_agno.Text) & "'", conn)
    btn_carga_asignaturas_Click
    Me.cmb_let_cur_asi_prof.Enabled = True
    Me.lst_asi_asignadas.Clear
End Sub

Private Sub cmb_numgra_asi_prof_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 And Len(Me.cmb_numgra_asi_prof.Text) <> 0 Then
        Me.cmb_let_cur_asi_prof.Enabled = True
        Me.cmb_let_cur_asi_prof.SetFocus
    End If
    KeyAscii = 0
End Sub

Private Sub lst_asi_asignadas_DblClick()
    btn_quita_asi_Click
End Sub

Private Sub lst_asi_existentes_DblClick()
    Btn_asigna_asi_Click
End Sub


Private Sub lst_nom_asi_prof_DblClick()
    Dim rs As ADODB.Recordset
    Set rs = New ADODB.Recordset
    Dim rutprof As String
    
    Indi = 0
    RutProfe = aprofesores(lst_nom_asi_prof.ListIndex)
    a = "SELECT * FROM profesores where rut_prof = " & "'" & RutProfe & "'"
    rs.CursorLocation = adUseClient
    rs.Open a, conn
    If rs.RecordCount > 0 Then
        apellido_p = rs("ape1_prof")
        apellido_m = rs("ape2_prof")
        nombres = rs("noms_prof")
        rutprof = rs("rut_prof")
        rs.Close
        Me.txt_nom_asi_prof.Text = apellido_p + " " + apellido_m + " " + nombres
        Me.txt_rut_asi_prof.Text = separarut(rutprof)
        Me.txt_dig_asi_prof.Text = separadigito(rutprof)
        Me.lst_nom_asi_prof.Visible = False
        Me.txt_nom_asi_prof.Locked = True
        Me.txt_rut_asi_prof.Enabled = False
        Me.txt_dig_asi_prof.Enabled = False
        Me.cmb_mod_asi_prof.Enabled = True
        Me.cmb_mod_asi_prof.SetFocus
        SendKeys "{home}"
    End If
End Sub

Private Sub lst_nom_asi_prof_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Then
     Call lst_nom_asi_prof_DblClick
    End If
End Sub

Private Sub txt_nom_asi_prof_Change()
    Dim rs As ADODB.Recordset
    Set rs = New ADODB.Recordset
    rs.CursorLocation = adUseClient
    'fetch the initial table ..
    'rs.Open "SELECT * FROM tipo_apo", conn
    lst_nom_asi_prof.Clear
    If Not ((Chr(KeyAscii) >= "A" And Chr(KeyAscii) <= "Z") Or (Chr(KeyAscii) >= "a" And Chr(KeyAscii) <= "z")) Then
        KeyAscii = 0
        If Me.txt_nom_asi_prof.Text <> "" Then
          Criterio = "'" + Me.txt_nom_asi_prof.Text + Consulta + "%'"
          rs.Open "SELECT * FROM profesores where ape1_prof like " & Criterio & " order by ape1_prof, ape2_prof, noms_prof", conn
          'rs.FindFirst "des_pre like " + Criterio
                'rs.MoveFirst
            lst_nom_asi_prof.Visible = False
            'Me.Txt_cod_TipoApo.Text = ""
            If rs.RecordCount > 0 Then
                ReDim aprofesores(rs.RecordCount)
                Indi = 0
                X = 0
                While Not rs.EOF
                    'Me.Txt_cod_TipoApo.Text = rs(0)
                    lst_nom_asi_prof.AddItem rs("ape1_prof") + " " + rs("ape2_prof") + " " + rs("noms_prof")
                    aprofesores(X) = rs("rut_prof")
                    lst_nom_asi_prof.Visible = True
                    rs.MoveNext
                    X = X + 1
                Wend
            Else
                Indi = 0
            End If
            rs.Close
        Else
        lst_nom_asi_prof.Visible = False
        End If
    End If


End Sub

Private Sub txt_nom_asi_prof_KeyPress(KeyAscii As Integer)
    If KeyAscii = 27 Then
        Me.txt_nom_asi_prof.Text = ""
        Me.txt_rut_asi_prof.Text = ""
        Me.txt_dig_asi_prof.Text = ""
        Me.cmb_mod_asi_prof.Text = ""
        Me.cmb_numgra_asi_prof.Text = ""
        Me.cmb_let_cur_asi_prof.Text = ""
        lst_nom_asi_prof.Visible = False
        KeyAscii = 0
    ElseIf ((Chr(KeyAscii) >= "A" And Chr(KeyAscii) <= "Z") Or (Chr(KeyAscii) >= "a" And Chr(KeyAscii) <= "z")) Then Exit Sub
    ElseIf (Chr(KeyAscii) >= "0" And Chr(KeyAscii) <= "9") Then Exit Sub
    ElseIf KeyAscii = 8 Then Exit Sub
    ElseIf KeyAscii = 32 Then Exit Sub
    ElseIf Me.txt_nom_asi_prof.Text = "" Then
            If KeyAscii = 37 Then Exit Sub
    End If
        KeyAscii = 0: Exit Sub

End Sub

Public Sub llenalistaespecialAsignatura(Control As ListBox, tabla, campo, criteriobus As String, Conexion As ADODB.Connection)
'esta funcion llena la lista de asignaturas segun nivel y compara si esa asignatura
' ya esta asignada a un curso y su profesor X
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
rs.CursorLocation = adUseClient
a = " SELECT " & campo & " FROM " & tabla & " " & criteriobus
a = a & " order by nom_asi "
rs.Open a, Conexion
If rs.RecordCount > 0 Then
    For t = 0 To rs.RecordCount - 1
        If Not valorenlista(Form_man_asi_x_prof.lst_asi_asignadas, rs!Nom_Asi) Then
            Control.AddItem "(" & rs!cod_asi & ")" & " " & rs!Nom_Asi
        End If
        rs.MoveNext
    Next t
End If
rs.Close
End Sub
