VERSION 5.00
Object = "{0F987290-56EE-11D0-9C43-00A0C90F29FC}#1.0#0"; "ActBar.ocx"
Object = "{B02F3647-766B-11CE-AF28-C3A2FBE76A13}#2.5#0"; "ss32x25.ocx"
Begin VB.Form FCO3052F 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Filtrar Trabajadores"
   ClientHeight    =   5325
   ClientLeft      =   45
   ClientTop       =   435
   ClientWidth     =   9555
   BeginProperty Font 
      Name            =   "Arial"
      Size            =   8.25
      Charset         =   0
      Weight          =   400
      Underline       =   0   'False
      Italic          =   0   'False
      Strikethrough   =   0   'False
   EndProperty
   Icon            =   "FCO3052F Filtro Trabajadores.frx":0000
   KeyPreview      =   -1  'True
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   5325
   ScaleWidth      =   9555
   StartUpPosition =   3  'Windows Default
   Begin VB.TextBox txtFiltro 
      Height          =   285
      Index           =   5
      Left            =   3600
      TabIndex        =   6
      Top             =   120
      Width           =   660
   End
   Begin VB.ListBox lstCedulas 
      Height          =   3840
      Left            =   7800
      TabIndex        =   5
      Top             =   480
      Width           =   1455
   End
   Begin VB.TextBox txtFiltro 
      Height          =   285
      Index           =   4
      Left            =   2760
      TabIndex        =   4
      Top             =   120
      Width           =   660
   End
   Begin VB.TextBox txtFiltro 
      Height          =   285
      Index           =   3
      Left            =   2040
      TabIndex        =   3
      Top             =   120
      Width           =   660
   End
   Begin VB.TextBox txtFiltro 
      Height          =   285
      Index           =   2
      Left            =   1320
      TabIndex        =   2
      Top             =   120
      Width           =   660
   End
   Begin VB.TextBox txtFiltro 
      Height          =   285
      Index           =   6
      Left            =   4440
      TabIndex        =   1
      Top             =   120
      Width           =   660
   End
   Begin FPSpread.vaSpread sprDatos 
      Height          =   4065
      Left            =   150
      TabIndex        =   0
      Top             =   480
      Width           =   7455
      _Version        =   131077
      _ExtentX        =   13150
      _ExtentY        =   7170
      _StockProps     =   64
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      MaxCols         =   1
      MaxRows         =   1
      SpreadDesigner  =   "FCO3052F Filtro Trabajadores.frx":030A
   End
   Begin VB.Label lblLabels 
      BackStyle       =   0  'Transparent
      Caption         =   "Incluir en el archivo:"
      BeginProperty Font 
         Name            =   "Arial"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   7680
      TabIndex        =   7
      Top             =   240
      Width           =   1815
   End
   Begin ActiveBarLibraryCtl.ActiveBar abToolbar 
      Left            =   150
      Top             =   4680
      _ExtentX        =   847
      _ExtentY        =   847
      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
      Bands           =   "FCO3052F Filtro Trabajadores.frx":046F
   End
End
Attribute VB_Name = "FCO3052F"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private MAdo As ODBC.ODBCDirecto
Private Micx As Integer 'Conexión
Private MsSelect As String
Private MsWhereAdi As String
Private MsOrder As String
Private MbOrdenAsc As Boolean
Private MsAntOrden As String
Private MiKey As Integer
Private MnAnchos(1 To 6) As Single
Private MiColIzq As Long
Private MbFueUsuario As Boolean
Private MvFiltros(1 To 15, 1 To 3) As Variant
Private MiCampos As Integer
Private Enum TipoDato
    Numerico = 1
    Cadena = 2
End Enum
Private MiBanco As Integer
Private MoBitacora As ADAMBitacora.Bitacora

Private Sub abToolbar_Click(ByVal Tool As ActiveBarLibraryCtl.Tool)
    Select Case LCase(Tool.Name)
        Case "tlseltodo": SeleccionaReg sprDatos, "1"
        Case "tlselnada": SeleccionaReg sprDatos, "0"
        Case "tlsel": Unload Me
    End Select
End Sub

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    Select Case KeyCode
        Case vbKeyF3: Unload Me
    End Select
End Sub

Private Sub Form_Load()
    On Error Resume Next

    GbAError = False
    Me.Tag = GiVenMax%
    Gven(Val(Me.Tag)).icx = Gicx%
    Micx = Gven(Val(Me.Tag)).icx
    Set MAdo = Gtc(Micx).Ado
    
    Width = 9645
    Height = 5805
    Caption = GsDsn & " / " & GsAbreviaturaCia & " - Trabajadores a incluir en archivo plano"
    
    Move (Screen.Width - Width) \ 2, (Screen.Height - Height) \ 2
        
    GAdam.ObtieneColores
    DefineFiltros
    
    AsignaIconos abToolbar, 3, LSELTODO, LSELNADA, LSEL
    ToolInicioGrupo abToolbar, 3, True, 2, 3
                    
    MsSelect = _
    " SELECT procesar, cedula, nombre, compania, clase_nomina, trabajador, " & MiBanco & _
    " FROM vw_fdt_bancos_trab" & _
    " WHERE usuariow = '" & GsUid & "'" & _
      " AND banco = " & MiBanco
    MsWhereAdi = ""
    MsOrder = " ORDER BY 2"
        
    RenuevaDatos
    EstableceAnchosIniciales
    RedimensionaTextos
    ActualizaLista
    
    CreaBitacora

    Screen.MousePointer = vbDefault
End Sub

Private Sub Form_Unload(Cancel As Integer)
    GiEntero = lstCedulas.ListCount
    Set MAdo = Nothing
    Set MoBitacora = Nothing
End Sub

Private Sub lstCedulas_KeyUp(KeyCode As Integer, Shift As Integer)
    If KeyCode = vbKeyDelete Then
        If lstCedulas.ListIndex <> -1 Then
            Screen.MousePointer = vbHourglass
            MAdo.Sql = "sp_fdt_del_bancos_trab '" & GsUid & "'," & MiBanco & ",'" & lstCedulas.List(lstCedulas.ListIndex) & "'"
            MAdo.ExecSQL
            RenuevaDatos
            ActualizaLista
            Screen.MousePointer = vbDefault
        End If
    End If
End Sub

Private Sub sprDatos_ButtonClicked(ByVal Col As Long, ByVal Row As Long, ByVal ButtonDown As Integer)
    If Col = 1 And MbFueUsuario Then
        Screen.MousePointer = vbHourglass
        MoBitacora.mCambia
        MoBitacora.mActualizaBD
        MoBitacora.mVaciaBuffer
        ActualizaLista
        Screen.MousePointer = vbDefault
    End If
End Sub

Private Sub sprDatos_ColWidthChange(ByVal Col1 As Long, ByVal Col2 As Long)
    RedimensionaTextos
End Sub

Private Sub sprDatos_TopLeftChange(ByVal OldLeft As Long, ByVal OldTop As Long, ByVal NewLeft As Long, ByVal NewTop As Long)
    If MbFueUsuario Then RedimensionaTextos
End Sub

Private Sub txtFiltro_KeyPress(Index As Integer, KeyAscii As Integer)
    If KeyAscii <> vbKeyReturn And KeyAscii <> 10 Then
        KeyAscii = Asc(UCase(Chr(KeyAscii)))
    Else
        MiKey = KeyAscii
        KeyAscii = 0
        AplicaFiltros
    End If
End Sub

Private Sub ActualizaLista()
    'Actualiza la lista de cédulas a procesar
    lstCedulas.Clear
    MAdo.Sql = "SELECT cedula FROM fdt_bancos_trab" & _
    " WHERE usuariow = '" & GsUid & "' AND banco = " & MiBanco & _
    " AND procesar = 1" & _
    " ORDER BY 1"
    If MAdo.SendSQL Then
        Do Until MAdo.EOF
            lstCedulas.AddItem MAdo.GetField(1)
            MAdo.Mnext
        Loop
    End If
End Sub

Private Sub AplicaFiltros()
    Dim i As Integer
    MsWhereAdi = ""
    For i = 1 To MiCampos
        If MvFiltros(i, 1) = 1 Then
            If Trim(txtFiltro(i)) <> "" Then
                If MvFiltros(i, 2) = Cadena Then
                    'Se altera el funcionamiento normal solo para esta ventana
                    If i > 1 Then
                        Select Case MiKey
                            Case vbKeyReturn
                                MsWhereAdi = MsWhereAdi & " AND " & MvFiltros(i, 3) & " LIKE '%" & Replace(txtFiltro(i), "/", " ") & "%'"
                            Case 10
                                MsWhereAdi = MsWhereAdi & " AND " & MvFiltros(i, 3) & " LIKE '" & Replace(txtFiltro(i), "/", " ") & "%'"
                        End Select
                    Else
                        MsWhereAdi = MsWhereAdi & " AND " & MvFiltros(i, 3) & " >= '" & Replace(txtFiltro(i), "/", " ") & "'"
                    End If
                Else
                    MsWhereAdi = MsWhereAdi & " AND " & MvFiltros(i, 3) & " >= " & Val(txtFiltro(i))
                End If
            End If
        End If
    Next i
    RenuevaDatos
End Sub

Private Sub CreaBitacora()
    Set MoBitacora = New ADAMBitacora.Bitacora
    MoBitacora.mCreaBitacora sprDatos, MAdo.lhEnv, MAdo.lhDbc, MAdo.lhstmt, MAdo
    MoBitacora.mTablaSPInfo 2, "sp_fdt_upd_bancos_trab", "'" & GsUid & "'", 7, 1, 4, 6
End Sub

Private Sub DefineFiltros()
    'Columnas con filtro
    MvFiltros(2, 1) = 1
    MvFiltros(3, 1) = 1
    MvFiltros(4, 1) = 1
    MvFiltros(5, 1) = 1
    MvFiltros(6, 1) = 1
    
    'Tipos de Columna
    MvFiltros(2, 2) = Cadena
    MvFiltros(3, 2) = Cadena
    MvFiltros(4, 2) = Cadena
    MvFiltros(5, 2) = Cadena
    MvFiltros(6, 2) = Cadena

    'Nombres de Campos
    MvFiltros(2, 3) = "cedula"
    MvFiltros(3, 3) = "nombre"
    MvFiltros(4, 3) = "compania"
    MvFiltros(5, 3) = "clase_nomina"
    MvFiltros(6, 3) = "trabajador"
End Sub

Private Sub EstableceAnchosIniciales()
    With sprDatos
        .ColWidth(1) = 2
        .ColWidth(2) = 12
        .ColWidth(4) = 4
        .ColWidth(5) = 6
        .ColWidth(6) = 8
        If .MaxRows > 15 Then
            .ColWidth(3) = 27.1
        Else
            .ColWidth(3) = 29.2
        End If
    End With
End Sub

Private Sub OrdenarDatos()
    Screen.MousePointer = vbHourglass
    If MsAntOrden = CStr(sprDatos.ActiveCol) Then
        MbOrdenAsc = Not (MbOrdenAsc)
    Else
        MbOrdenAsc = True
    End If
    MsOrder = " Order By " & CStr(sprDatos.ActiveCol) & IIf(MbOrdenAsc, "", "DESC")
    MsAntOrden = CStr(sprDatos.ActiveCol)
    RenuevaDatos
    Screen.MousePointer = vbDefault
End Sub

Public Sub PasarDatos(Banco As Integer)
    MiBanco = Banco
End Sub

Private Sub RedimensionaTextos()
    Dim iAncho As Long
    Dim iPosAcum As Long
    Dim i As Integer
    Dim k As Integer
    Dim bVisible(6) As Boolean
    
    'Número de Columnas del Spread
    MiCampos = 6
    
    'Posición inicial de referencia
    iPosAcum = sprDatos.Left
                
    'Mostrar inicialmente todos los filtros
    For i = 1 To MiCampos
        If MvFiltros(i, 1) = 1 Then bVisible(i) = True
    Next i
    
    'Si el usuario recorre la grilla a la derecha puede haber filtros que no se vean en la izquierda
    For i = sprDatos.ColsFrozen + 1 To MiCampos
        If MvFiltros(i, 1) = 1 Then
            If i < sprDatos.LeftCol Then
                bVisible(i) = False
            Else
                bVisible(i) = True
            End If
        End If
    Next i
    
    'Dimensionando los textos de filtro
    For i = 1 To MiCampos
        sprDatos.ColWidthToTwips sprDatos.ColWidth(i), iAncho
        If sprDatos.LeftCol > i And i > sprDatos.ColsFrozen Then iAncho = 0
        If MvFiltros(i, 1) = 1 Then
            If bVisible(i) Then
                If iAncho = 0 Then
                    bVisible(i) = False
                Else
                    txtFiltro(i).Width = iAncho
                    txtFiltro(i).Left = iPosAcum
                End If
            End If
        End If
        iPosAcum = iPosAcum + iAncho
    Next i
    
    'Evitar que los textos de filtro se pasen del ancho del Spread
    For i = MiCampos To 1 Step -1
        If i = MiCampos Then k = sprDatos.Left Else k = 0
        If MvFiltros(i, 1) = 1 Then
            If txtFiltro(i).Left + txtFiltro(i).Width > sprDatos.Width + k Then
                If sprDatos.Width - txtFiltro(i).Left + sprDatos.Left > 0 Then
                    txtFiltro(i).Width = sprDatos.Width - txtFiltro(i).Left + sprDatos.Left
                Else
                    bVisible(i) = False
                End If
            End If
        End If
    Next i
    
    'Mostrar los textos definitivos
    For i = 1 To MiCampos
        If MvFiltros(i, 1) = 1 Then txtFiltro(i).Visible = bVisible(i)
    Next i
End Sub

Private Sub RenuevaDatos()
    Dim clsSpread As NSpread
    Dim i As Integer
    Dim vaux As Variant
    
    Screen.MousePointer = vbHourglass
    
    MbFueUsuario = False

    For i = 1 To 6
        MnAnchos(i) = sprDatos.ColWidth(i)
    Next i
    MiColIzq = sprDatos.LeftCol
    With sprDatos
        .Visible = False
        .Action = 28
        GAdam.ConfiguracionSpread sprDatos
    
        .Row = 0:
        .Col = 1: .Text = " "
        .Col = 2: .Text = "Cédula"
        .Col = 3: .Text = "Nombre"
        .Col = 4: .Text = "Cia."
        .Col = 5: .Text = "C.Nom."
        .Col = 6: .Text = "Trabajador"
        .Col = 7: .Text = "Banco Oculto"
        .VirtualOverlap = 100 '100 registros se conservarán en memoria
        .VirtualRows = 20 'Se leerán 20 registros más cuando se requiera
        .VirtualMode = -1 'Utliza modo virtual
        .VirtualMaxRows = -1
        .ShadowColor = GAdam.GLSPREADACTIVO
        .ShadowText = GAdam.GLTEXTOACTIVO
        .Col = -1
        .UserResizeCol = 1
        .Col = -1: .Row = -1: .Lock = True
        .ScrollBars = ScrollBarsBoth
        .Col = 7: .ColHidden = True
    End With
    For i = 1 To 6
        sprDatos.ColWidth(i) = MnAnchos(i)
    Next i
    
    MAdo.Sql = MsSelect & MsWhereAdi & MsOrder
    If Not MAdo.SendSQL Then Exit Sub
        
    Set clsSpread = New NSpread
    clsSpread.LlenaSpread 0, sprDatos, MAdo, MAdo.lhDbc, MAdo.lhstmt
    Set clsSpread = Nothing
    
    With sprDatos
        .Row = -1
        .Col = 1: .CellType = 10: .Lock = False
        .Visible = True
        .LeftCol = MiColIzq
    End With
    
    MbFueUsuario = True
    
    Screen.MousePointer = vbDefault
End Sub

Private Sub SeleccionaReg(Spread As vaSpread, Seleccion As String)
    Dim i As Long
    Dim j As Long
    Dim iRowIni As Long
    Dim iRowFin As Long
        
    MbFueUsuario = False
    With Spread
        If .ActiveRow < 0 Or .VirtualMaxRows = 0 Then Exit Sub
        Screen.MousePointer = vbHourglass
        .Action = 18
        If .IsBlockSelected And .MultiSelCount > 0 Then
            'Proceso para un bloque de filas
            For i = 0 To .MultiSelCount - 1
                .MultiSelIndex = i
                If .Row < 1 Then
                    iRowIni = 1
                    iRowFin = .MaxRows
                Else
                    iRowIni = .Row
                    iRowFin = .Row2
                End If
                For j = iRowIni To iRowFin
                    .Col = 1
                    .Row = j
                    If Not .RowHidden And Not .Lock And .Text <> Seleccion Then
                        .Text = Seleccion
                        MoBitacora.mCambia j
                    End If
                Next j
            Next i
        Else
            'Proceso para una todas las filas (no hay bloque seleccionado)
            .Row = .MaxRows  ' se selecciona todo
            .Col = 1
            .Action = 0
            For j = 1 To .MaxRows
                .Col = 1
                .Row = j
                If Not .RowHidden And Not .Lock And .Text <> Seleccion Then
                    .SetText .Col, j, Seleccion
                    MoBitacora.mCambia j
                End If
            Next j
        End If
    End With
    
    MoBitacora.mActualizaBD
    MoBitacora.mVaciaBuffer
    ActualizaLista
    MbFueUsuario = True
    
    Screen.MousePointer = vbDefault
End Sub

