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 FCO2098 
   Caption         =   "Asignación de Número de Planilla"
   ClientHeight    =   7005
   ClientLeft      =   60
   ClientTop       =   450
   ClientWidth     =   6135
   BeginProperty Font 
      Name            =   "Arial"
      Size            =   8.25
      Charset         =   0
      Weight          =   400
      Underline       =   0   'False
      Italic          =   0   'False
      Strikethrough   =   0   'False
   EndProperty
   Icon            =   "FCO2098 Asignacion Numero Planilla.frx":0000
   KeyPreview      =   -1  'True
   LinkTopic       =   "Form1"
   MDIChild        =   -1  'True
   ScaleHeight     =   7005
   ScaleWidth      =   6135
   Begin VB.TextBox txtFiltro 
      Height          =   315
      Index           =   4
      Left            =   2520
      TabIndex        =   5
      Top             =   120
      Width           =   495
   End
   Begin VB.TextBox txtFiltro 
      Height          =   315
      Index           =   3
      Left            =   1920
      TabIndex        =   4
      Top             =   120
      Width           =   495
   End
   Begin VB.TextBox txtFiltro 
      Height          =   315
      Index           =   2
      Left            =   1320
      TabIndex        =   3
      Top             =   120
      Width           =   495
   End
   Begin VB.TextBox txtFiltro 
      Height          =   315
      Index           =   1
      Left            =   720
      TabIndex        =   2
      Top             =   120
      Width           =   495
   End
   Begin VB.TextBox txtFiltro 
      Height          =   315
      Index           =   0
      Left            =   120
      TabIndex        =   1
      Top             =   120
      Width           =   495
   End
   Begin FPSpread.vaSpread sprDatos 
      Bindings        =   "FCO2098 Asignacion Numero Planilla.frx":030A
      Height          =   5895
      Left            =   120
      TabIndex        =   0
      Top             =   480
      Width           =   5895
      _Version        =   131077
      _ExtentX        =   10398
      _ExtentY        =   10398
      _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  =   "FCO2098 Asignacion Numero Planilla.frx":0320
   End
   Begin ActiveBarLibraryCtl.ActiveBar abToolbar 
      Left            =   120
      Top             =   6360
      _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           =   "FCO2098 Asignacion Numero Planilla.frx":0479
   End
End
Attribute VB_Name = "FCO2098"
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
Private MoBitacora As New ADAMBitacora.Bitacora
Private WithEvents clsSpread As NSpread
Attribute clsSpread.VB_VarHelpID = -1
Private MsSql As String
Private MsSqlIni As String
Private MsWhereAdi As String
Private MsOrden As String
Private MbOrdenAsc As Boolean
Private MsAntOrden As String
Private MiFiltros As Byte
Private Enum TipoCampo
    Numerico = 1
    AlfaNumerico = 2
    Fecha = 3
End Enum

Private Sub abToolbar_Click(ByVal Tool As ActiveBarLibraryCtl.Tool)
    Select Case LCase(Tool.Name)
        Case "tlrenueva": Refrescar
        Case "tlordena": OrdenarDatos
        Case "tlguarda": GuardaCambios
        Case "tlsalida": Unload Me
    End Select
End Sub

Private Sub Form_Activate()
    RedimensionaFiltros
End Sub

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

Private Sub Form_Load()
    'Establecer conexión
    GbAError = False
    Me.Tag = GiVenMax%
    Gven(Val(Me.Tag)).icx = Gicx%
    MiCx = Gven(Val(Me.Tag)).icx
    Set MAdo = Gtc(MiCx).Ado
    
    'Revisar nivel de seguridad
    Gven(Val(Me.Tag)).iNivSeguridad = iObtenNivSeguridad(GsOper, GsUid, MiCx)
    If Gven(Val(Me.Tag)).iNivSeguridad = 0 Then
        Screen.MousePointer = vbDefault
        Me.Top = -10000
        GbAError = True
        Exit Sub
    End If
        
    Width = 6255
    Height = 7515
    Caption = GsDsn & " / " & GsCveCia & " - Números de Planilla"
    
    AsignaIconos abToolbar, 3, LRENUEVA, LORDENA, LGUARDA, LSALIDA
    ToolInicioGrupo abToolbar, 3, True, 1, 2, 3
    
    If Gven(Val(Me.Tag)).iNivSeguridad = 1 Then
        abToolbar.Bands(0).Tools(2).Enabled = False
    End If
        
    MsSqlIni = "SELECT anio, mes, sucursal, tipo_planilla, nro_planilla, fecha_pago_real FROM fco_integrada_cab WHERE compania = '" & GsCveCia & "' "
    MsSql = MsSqlIni
    MsWhereAdi = ""
    MsOrden = " ORDER BY 1 desc,2 desc,3,4"
    RenuevaDatos
    
    sprDatos.ShadowColor = GAdam.GLSPREADINACTIVO
    sprDatos.ShadowText = GAdam.GLTEXTOINACTIVO
    
    CreaBitacora
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    If Not bGuardarCambios Then Cancel = True
End Sub

Private Sub Form_Unload(Cancel As Integer)
    Set MAdo = Nothing
    Set MoBitacora = Nothing
    Gtc(MiCx).ihijas = Gtc(MiCx).ihijas - 1
    Set FCO2098 = Nothing
End Sub

Private Sub sprDatos_Change(ByVal Col As Long, ByVal Row As Long)
    MoBitacora.mCambia
End Sub

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

Private Sub sprDatos_GotFocus()
    sprDatos.ShadowColor = GAdam.GLSPREADACTIVO
    sprDatos.ShadowText = GAdam.GLTEXTOACTIVO
End Sub

Private Sub sprDatos_LostFocus()
    sprDatos.ShadowColor = GAdam.GLSPREADINACTIVO
    sprDatos.ShadowText = GAdam.GLTEXTOINACTIVO
End Sub

Private Sub sprDatos_TopLeftChange(ByVal OldLeft As Long, ByVal OldTop As Long, ByVal NewLeft As Long, ByVal NewTop As Long)
    RedimensionaFiltros
End Sub

Private Sub txtFiltro_KeyPress(Index As Integer, KeyAscii As Integer)
    If KeyAscii = vbKeyReturn Or KeyAscii = 10 Then
        Screen.MousePointer = vbHourglass
        Refrescar
        Screen.MousePointer = vbDefault
    End If
End Sub

Private Sub AplicaFiltros()
    Dim i As Integer
    Dim k As Byte
    Dim iTc(0 To 4) As TipoCampo
    Dim sCampos(0 To 4) As String
    
    iTc(0) = Numerico
    iTc(1) = Numerico
    iTc(2) = AlfaNumerico
    iTc(3) = AlfaNumerico
    iTc(4) = AlfaNumerico
    
    sCampos(0) = "anio"
    sCampos(1) = "mes"
    sCampos(2) = "sucursal"
    sCampos(3) = "tipo_planilla"
    sCampos(4) = "nro_planilla"
    
    MsSql = MsSqlIni
    For i = 0 To MiFiltros - 1
        If Trim(txtFiltro(i)) <> "" Then
            'Valores Numéricos
            If iTc(i) = Numerico Then
                MsSql = MsSql & " AND " & sCampos(i) & " = " & Val(txtFiltro(i))
            Else
                If iTc(i) = Fecha Then 'Fecha
                    MsSql = MsSql & " AND " & sCampos(i) & " = '" & Format(txtFiltro(i), "yyyymmdd") & "'"
                Else
                    MsSql = MsSql & " AND " & sCampos(i) & " LIKE '%" & txtFiltro(i) & "%'"
                End If
            End If
        End If
    Next i
    RenuevaDatos
End Sub

Private Function bGuardarCambios() As Boolean
    bGuardarCambios = True
    If MoBitacora.pTransActual > 0 Then
        Select Case clsMsgbox.Mensaje("¿Desea guardar los cambios?", mSiNoCancelar, mConfirma, GsTitMsg)
            Case vbYes
                GuardaCambios
                bGuardarCambios = True
            Case vbNo
                MoBitacora.mVaciaBuffer
                bGuardarCambios = True
            Case vbCancel: bGuardarCambios = False
        End Select
    End If
End Function

Private Sub CreaBitacora()
   MoBitacora.mCreaBitacora sprDatos, MAdo.lhEnv, MAdo.lhDbc, MAdo.lhstmt, MAdo
   MoBitacora.p_ConfirmaBaja = True
   MoBitacora.mTablaSPInfo 2, "sp_fco_upd_integrada_cab", "'" & GsCveCia & "'", 1, 2, 3, 4, 5, 6
End Sub

Private Sub GuardaCambios()
    Screen.MousePointer = vbHourglass
    GbRen = MoBitacora.mActualizaBD
    MoBitacora.mVaciaBuffer
    AplicaFiltros
    RedimensionaFiltros
    Screen.MousePointer = vbDefault
End Sub

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

Private Sub RedimensionaFiltros()
    Dim nAncho As Long
    Dim nPosAcum As Long
    Dim i As Integer
    Dim k As Integer
    Dim x As Integer
    
    x = 0 'Número de Columnas Ocultas al inicio del Spread
    MiFiltros = 5
    For i = 0 To MiFiltros - 1
        If i <= sprDatos.LeftCol - x - 2 Then
            txtFiltro(i).Visible = False
        Else
            txtFiltro(i).Visible = True
        End If
    Next i
    nPosAcum = sprDatos.Left
    
    For i = 0 To MiFiltros - 1
        If txtFiltro(i).Visible Then
            sprDatos.ColWidthToTwips sprDatos.ColWidth(i + x + 1), nAncho
            If nAncho = 0 Then
                txtFiltro(i).Visible = False
            Else
                txtFiltro(i).Width = nAncho
                If i > 0 Then
                    If txtFiltro(i - 1).Visible Then
                        txtFiltro(i).Left = txtFiltro(i - 1).Left + txtFiltro(i - 1).Width
                    Else
                        txtFiltro(i).Left = nPosAcum
                    End If
                End If
                nPosAcum = txtFiltro(i).Left + txtFiltro(i).Width
            End If
        End If
    Next i
    
    'CODIGO QUE CONTROLA QUE LOS TEXTOS NO SE PASEN DEL ANCHO DEL SPREAD:
    For i = MiFiltros - 1 To 0 Step -1
        If i = MiFiltros Then k = 120 Else k = 0
        If txtFiltro(i).Left + txtFiltro(i).Width > sprDatos.Width + k Then
            If sprDatos.Width - txtFiltro(i).Left + 120 > 0 Then
                txtFiltro(i).Width = sprDatos.Width - txtFiltro(i).Left + 120
            Else
                txtFiltro(i).Visible = False
            End If
        End If
    Next i
End Sub

Private Sub Refrescar()
    Screen.MousePointer = vbHourglass
    AplicaFiltros
    RedimensionaFiltros
    Screen.MousePointer = vbDefault
End Sub

Private Sub RenuevaDatos()
    Dim clsSpread As NSpread
    
    If Not bGuardarCambios Then Exit Sub
    
    Screen.MousePointer = vbHourglass

    'Configuración inicial del Spread
    With sprDatos
        .Visible = False
        .Action = 28
        GAdam.ConfiguracionSpread sprDatos
        .Row = 0
        .Col = 1: .Text = "Año"
        .Col = 2: .Text = "Mes"
        .Col = 3: .Text = "Sucursal"
        .Col = 4: .Text = "Tipo"
        .Col = 5: .Text = "Número"
        .Col = 6: .Text = "Fecha"
        ConfiguraSpreadJCL sprDatos
    End With
    
    'AplicaFiltros
    MAdo.Sql = MsSql & MsWhereAdi & MsOrden
    If Not MAdo.SendSQL Then Exit Sub
    Set clsSpread = New NSpread
    clsSpread.LlenaSpread 0, sprDatos, MAdo, MAdo.lhDbc, MAdo.lhstmt
    Set clsSpread = Nothing
    
    'Anchos de las columnas
    With sprDatos
        .ColWidth(1) = 5
        .ColWidth(2) = 4
        .ColWidth(3) = 8
        .ColWidth(4) = 5
        .ColWidth(5) = 9
        .ColWidth(6) = 8
        .Row = -1
        .Col = 1: .Lock = True
        .Col = 2: .Lock = True
        .Col = 3: .Lock = True
        .Col = 4: .Lock = True
        .Col = 5: .TypeEditLen = 10
    End With
    GAdam.AjustaSpread sprDatos, 5
    sprDatos.Visible = True
    
    Screen.MousePointer = vbDefault
End Sub

