VERSION 5.00
Object = "{5E9E78A0-531B-11CF-91F6-C2863C385E30}#1.0#0"; "MSFLXGRD.OCX"
Begin VB.Form Form_Talleres 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Mantención de Talleres"
   ClientHeight    =   5925
   ClientLeft      =   45
   ClientTop       =   435
   ClientWidth     =   8805
   Icon            =   "Form_Talleres.frx":0000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MDIChild        =   -1  'True
   MinButton       =   0   'False
   ScaleHeight     =   12338.96
   ScaleMode       =   0  'User
   ScaleWidth      =   8805
   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          =   375
      Left            =   7320
      TabIndex        =   10
      Top             =   720
      Width           =   1335
   End
   Begin VB.CommandButton Command1 
      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            =   7320
      TabIndex        =   9
      Top             =   240
      Width           =   1335
   End
   Begin VB.ComboBox cb_nivel 
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   330
      Left            =   1920
      TabIndex        =   5
      Top             =   720
      Width           =   4455
   End
   Begin VB.ComboBox cb_codigos 
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   330
      Left            =   1920
      TabIndex        =   4
      Top             =   240
      Width           =   4455
   End
   Begin VB.Frame Frame2 
      Height          =   735
      Left            =   4200
      TabIndex        =   3
      Top             =   5040
      Width           =   4455
      Begin VB.CommandButton Command3 
         Caption         =   "Eliminar"
         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          =   375
         Left            =   3000
         TabIndex        =   8
         Top             =   240
         Width           =   1335
      End
      Begin VB.CommandButton cmd_modificar 
         Caption         =   "Modificar"
         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          =   375
         Left            =   1560
         TabIndex        =   7
         Top             =   240
         Width           =   1335
      End
      Begin VB.CommandButton cmd_nuevo 
         Caption         =   "Nuevo"
         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          =   375
         Left            =   120
         TabIndex        =   6
         Top             =   240
         Width           =   1335
      End
   End
   Begin VB.Frame Frame_Listado 
      Caption         =   "Listado de Talleres"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00C00000&
      Height          =   3735
      Left            =   120
      TabIndex        =   2
      Top             =   1200
      Width           =   8535
      Begin VB.Frame Frame_Nuevo 
         Caption         =   "Ingreso de Taller"
         BeginProperty Font 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ForeColor       =   &H00C00000&
         Height          =   2655
         Left            =   1920
         TabIndex        =   12
         Top             =   480
         Visible         =   0   'False
         Width           =   4455
         Begin VB.CommandButton cmd_cancelar 
            Caption         =   "Cancelar"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   375
            Left            =   2400
            TabIndex        =   20
            Top             =   1920
            Width           =   1335
         End
         Begin VB.CommandButton cmd_grabar_ingresar 
            Caption         =   "Guardar"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   375
            Left            =   720
            TabIndex        =   19
            Top             =   1920
            Width           =   1335
         End
         Begin VB.ComboBox cb_tipo 
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   330
            Left            =   960
            TabIndex        =   18
            Top             =   1320
            Width           =   3255
         End
         Begin VB.TextBox txt_taller 
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   315
            Left            =   960
            TabIndex        =   16
            Top             =   960
            Width           =   3255
         End
         Begin VB.TextBox txt_codigo 
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   315
            Left            =   960
            TabIndex        =   14
            Top             =   600
            Width           =   1095
         End
         Begin VB.Label Label5 
            Caption         =   "Tipo"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            ForeColor       =   &H00000000&
            Height          =   255
            Left            =   240
            TabIndex        =   17
            Top             =   1320
            Width           =   615
         End
         Begin VB.Label Label4 
            Caption         =   "Taller"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            ForeColor       =   &H00000000&
            Height          =   255
            Left            =   240
            TabIndex        =   15
            Top             =   960
            Width           =   495
         End
         Begin VB.Label Label3 
            Caption         =   "Código"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            ForeColor       =   &H00000000&
            Height          =   375
            Left            =   240
            TabIndex        =   13
            Top             =   600
            Width           =   1095
         End
      End
      Begin MSFlexGridLib.MSFlexGrid grid_talleres 
         Height          =   3255
         Left            =   120
         TabIndex        =   11
         Top             =   360
         Width           =   8295
         _ExtentX        =   14631
         _ExtentY        =   5741
         _Version        =   393216
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Arial"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
      End
   End
   Begin VB.Label Label2 
      Caption         =   "Nivel"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00000000&
      Height          =   255
      Left            =   240
      TabIndex        =   1
      Top             =   720
      Width           =   1215
   End
   Begin VB.Label Label1 
      Caption         =   "Tipo de Enseñanza"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00000000&
      Height          =   255
      Left            =   240
      TabIndex        =   0
      Top             =   240
      Width           =   1455
   End
End
Attribute VB_Name = "Form_Talleres"
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
            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 cb_codigos_Click()
    Dim i As Integer
    Dim objRS As ADODB.Recordset
    Set objRS = New ADODB.Recordset
    Dim var_sql As String
    var_sql = "SELECT * FROM codigos_ensenanza" _
            & " where des_ens = '" & cb_codigos.Text & "'"
    objRS.Open var_sql, conn
    cb_nivel.Clear
    For i = 1 To CInt(objRS("num_gra_max"))
        cb_nivel.AddItem i
    Next i
    objRS.Close
End Sub

Private Sub cb_nivel_Click()
    Dim Row As Integer
    Dim objRS As ADODB.Recordset
    Set objRS = New ADODB.Recordset
    Dim var_sql As String
'    var_sql = "select t.* from talleres t,codigos_ensenanza ce" _
'            & " where t.cod_ens = ce.cod_ens and des_ens = '" _
'            & cb_codigos.Text & "' and num_gra = '" & cb_nivel.Text & "'"
    var_sql = "select cod_tall,nom_tall,desc_tipo from talleres t,codigos_ensenanza ce,tipo_talleres tt" _
            & " where t.cod_ens = ce.cod_ens and des_ens = '" & cb_codigos.Text & "' and num_gra = '" & cb_nivel.Text & "' and t.tipo_tall = tt.cod_tipo"

    objRS.Open var_sql, conn
    grid_talleres.Rows = 2
    grid_talleres.Clear
    Call Rec2Grid(objRS, grid_talleres, True)
    objRS.Close
    cb_codigos.Enabled = False
    cb_nivel.Enabled = False
    cmd_nuevo.Enabled = True
    cmd_modificar.Enabled = True
    Command3.Enabled = True
End Sub

Private Sub cmd_Cancelar_Click()
    Frame_Nuevo.Visible = False
End Sub

Private Sub cmd_grabar_ingresar_Click()
    Dim Mensaje As String
    Dim Cod_Ens, tipo_tall, tipo_tall2 As String
    Dim Row As Integer
    Dim objRS As ADODB.Recordset
    Set objRS = New ADODB.Recordset
    Dim var_sql As String
    
    Mensaje = ""
    If txt_codigo.Text = "" Then Mensaje = "el codigo del taller"
    If txt_taller.Text = "" Then Mensaje = "el nombre del taller"
    If cb_tipo.Text = "" Then Mensaje = "el tipo de taller"
    If Mensaje <> "" Then
            MsgBox "Debe ingresar " & Mensaje, vbInformation
            Exit Sub
    End If
    
    var_sql = "SELECT * FROM codigos_ensenanza" _
            & " where des_ens = '" & cb_codigos.Text & "'"
    objRS.Open var_sql, conn
    Cod_Ens = objRS("cod_ens")
    objRS.Close
    
    var_sql = "SELECT * FROM tipo_talleres" _
            & " where desc_tipo = '" & cb_tipo.Text & "'"
    objRS.Open var_sql, conn
    tipo_tall = objRS("cod_tipo")
    objRS.Close
    
    If Frame_Nuevo.Caption = "Ingreso de Talleres" Then
        var_sql = "insert into talleres(cod_tall,cod_ens,nom_tall,num_gra,tipo_tall)" _
                & " values('" & txt_codigo.Text _
                & "','" & Cod_Ens & "','" _
                & txt_taller.Text & "','" & cb_nivel.Text _
                & "','" & tipo_tall & "')"
        conn.Execute var_sql
    Else
'        var_sql = "SELECT * FROM codigos_ensenanza" _
'            & " where des_ens = '" & cb_codigos.Text & "'"
'        objRS.Open var_sql, conn
'        Cod_Ens = objRS("cod_ens")
'        objRS.Close
        Row = grid_talleres.Row
        var_sql = "SELECT * FROM tipo_talleres" _
                & " where desc_tipo = '" & grid_talleres.TextMatrix(Row, 3) & "'"
        objRS.Open var_sql, conn
        tipo_tall2 = objRS("cod_tipo")
        objRS.Close
        
        Row = grid_talleres.Row
        var_sql = "update talleres set cod_tall = '" & txt_codigo.Text _
                        & "',cod_ens = '" & Cod_Ens _
                        & "',nom_tall = '" & txt_taller.Text _
                        & "',num_gra = '" & cb_nivel.Text _
                        & "',tipo_tall = '" & tipo_tall & "'" _
                & " where cod_tall = '" & grid_talleres.TextMatrix(Row, 1) _
                & "' and cod_ens = '" & Cod_Ens _
                & "' and num_gra = '" & cb_nivel _
                & "' and tipo_tall = '" _
                & tipo_tall2 & "'"
        conn.Execute var_sql
    End If
    Frame_Nuevo.Visible = False
    cb_nivel_Click
End Sub

Private Sub cmd_modificar_Click()
    If grid_talleres.Rows = 2 And grid_talleres.TextMatrix(1, 1) = "" Then
        Exit Sub
    End If
    If grid_talleres.Row < 1 Then
        MsgBox "Debe seleccionar el taller que desea eliminar", vbInformation
        Exit Sub
    End If
    Dim objRS As ADODB.Recordset
    Set objRS = New ADODB.Recordset
    Dim var_sql As String
    'var_sql = "SELECT * FROM tipo_talleres where cod_tipo = '" & grid_talleres.TextMatrix(grid_talleres.Row, 5) & "'"
    'objRS.Open var_sql, conn
    grid_talleres.Col = 1
    txt_codigo.Text = grid_talleres.Text
    grid_talleres.Col = 2
    txt_taller.Text = grid_talleres.Text
    grid_talleres.Col = 3
    cb_tipo.Text = grid_talleres.Text
    Frame_Nuevo.Caption = "Modificación de Talleres"
    Frame_Nuevo.Visible = True
   ' objRS.Close
End Sub

Private Sub cmd_nuevo_Click()
    txt_codigo.Text = ""
    txt_taller.Text = ""
    cb_tipo.Text = ""
    Frame_Nuevo.Caption = "Ingreso de Talleres"
    Frame_Nuevo.Visible = True
End Sub

Private Sub cmd_Salir_Click()
    Unload Me
End Sub

Private Sub Command1_Click()
    cb_codigos.Enabled = True
    cb_nivel.Enabled = True
    cmd_nuevo.Enabled = False
    cmd_modificar.Enabled = False
    Command3.Enabled = False
    cb_nivel.Text = ""
End Sub

Private Sub Command3_Click()
    Dim Tipo, Cod_Ens As String
    Dim objRS As ADODB.Recordset
    Set objRS = New ADODB.Recordset
    Dim var_sql As String
    
    If grid_talleres.Rows = 2 And grid_talleres.TextMatrix(1, 1) = "" Then Exit Sub
    
    If grid_talleres.Row < 1 Then
        MsgBox "Debe seleccionar el taller que desea eliminar", vbInformation
        Exit Sub
    End If
    
    var_sql = "SELECT * FROM tipo_talleres" _
            & " where desc_tipo = '" & grid_talleres.TextMatrix(grid_talleres.Row, 3) & "'"
    objRS.Open var_sql, conn
    Tipo = objRS("cod_tipo")
    objRS.Close
    
    var_sql = "SELECT * FROM codigos_ensenanza" _
            & " where des_ens = '" & cb_codigos.Text & "'"
    objRS.Open var_sql, conn
    Cod_Ens = objRS("cod_ens")
    objRS.Close
    
    var_sql = "SELECT * FROM tall_x_cur_prof WHERE" _
            & " cod_ens = '" & Cod_Ens & "' AND num_gra = " & cb_nivel.Text _
            & " AND cod_tall = " & grid_talleres.TextMatrix(grid_talleres.Row, 1) & " AND agno = " & Anno
    objRS.Open var_sql, conn
    If objRS.RecordCount > 0 Then
        MsgBox "Este taller no puede ser eliminado, porque tiene profesor asignado"
        Exit Sub
    End If
    objRS.Close
    
    'MsgBox grid_talleres.Row
   ' Dim var_sql As String
    If grid_talleres.Rows = 2 And grid_talleres.TextMatrix(1, 1) = "" Then Exit Sub
    var_sql = "delete from talleres where" _
            & " cod_tall = '" & grid_talleres.TextMatrix(grid_talleres.Row, 1) _
            & "' and cod_ens = '" & Cod_Ens _
            & "' and num_gra = '" & cb_nivel.Text _
            & "' and tipo_tall = '" & Tipo & "'"
    conn.Execute var_sql
    cb_nivel_Click
    MsgBox "El taller fue eliminado satisfactoriamente", vbInformation
End Sub

Private Sub Form_Load()
    Dim objRS As ADODB.Recordset
    Set objRS = New ADODB.Recordset
    Dim var_sql As String
    var_sql = "SELECT * FROM codigos_ensenanza"
    objRS.Open var_sql, conn
    While Not objRS.EOF
        cb_codigos.AddItem objRS("des_ens")
        objRS.MoveNext
    Wend
    objRS.Close
    var_sql = "SELECT * FROM tipo_talleres"
    objRS.Open var_sql, conn
    While Not objRS.EOF
        cb_tipo.AddItem objRS("desc_tipo")
        objRS.MoveNext
    Wend
    objRS.Close
End Sub

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

