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 FCO1020 
   Caption         =   "Mto EPS"
   ClientHeight    =   5205
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   10350
   Icon            =   "Administradoras.frx":0000
   KeyPreview      =   -1  'True
   LinkTopic       =   "Form1"
   MDIChild        =   -1  'True
   ScaleHeight     =   5205
   ScaleWidth      =   10350
   Begin FPSpread.vaSpread sprDatos 
      Height          =   4425
      Left            =   120
      TabIndex        =   0
      Top             =   120
      Width           =   9735
      _Version        =   131077
      _ExtentX        =   17171
      _ExtentY        =   7805
      _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  =   "Administradoras.frx":030A
   End
   Begin VB.Image imgListaAdm 
      Height          =   480
      Left            =   9960
      Picture         =   "Administradoras.frx":0463
      Top             =   240
      Width           =   480
   End
   Begin ActiveBarLibraryCtl.ActiveBar abToolbar 
      Left            =   240
      Top             =   4560
      _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           =   "Administradoras.frx":076D
   End
End
Attribute VB_Name = "FCO1020"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private objBitacora As New ADAMBitacora.Bitacora
Private WithEvents clsSpread As NSpread
Attribute clsSpread.VB_VarHelpID = -1
Private Mado As ODBC.ODBCDirecto
Private MsSql As String
Private MSOrder As String
Private MsCodAgr As String
Private MiCx As Integer 'Conexión
Private MiX As Integer 'Ancho de la forma
Private MiY As Integer 'Alta de la forma

Private MbOrdenAsc As Boolean
Private MsAntOrden As String
Private MbAlta As Boolean

Private Sub abToolbar_Click(ByVal Tool As ActiveBarLibraryCtl.Tool)
    Select Case LCase(Tool.Name)
        Case "tlalta": Altas
        Case "tlbaja": Bajas
        Case "tltrabaja": TrabajarCon
        Case "tlordena": OrdenarDatos
        Case "tlrenueva": RenuevaDatos
        Case "tlguarda": GuardaCambios
        Case "tlsalida": Unload Me
    End Select
End Sub

Private Sub abToolbar_PreCustomizeMenu(ByVal Cancel As ActiveBarLibraryCtl.ReturnBool)
    Cancel = True
End Sub

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    Select Case KeyCode
        Case vbKeyF3: Unload Me
        Case vbKeyF5: RenuevaDatos
        Case vbKeyF6: Altas
        Case vbKeyF7: Bajas
        Case vbKeyF11: GuardaCambios
        Case vbKeyF12: abToolbar.Bands(1).TrackPopup -1, -1
    End Select
End Sub

Private Sub Form_Load()
    GbAError = False
    Me.Tag = GiVenMax%
    Gven(Val(Me.Tag)).icx = Gicx%
    MiCx = Gven(Val(Me.Tag)).icx
    Set Mado = Gtc(MiCx).Ado
    Me.Icon = LoadPicture(sIconoForma)
    
    'Checa 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
    
    'Inicio clase para el llenado de los Spread's
    Set clsSpread = New NSpread
    GAdam.ObtieneColores
    
    If Not MDIChild Then
        WindowState = 0
        Move (Screen.Width - Width) \ 2, (Screen.Height - Height) \ 2
        Screen.MousePointer = vbDefault
    End If
    
    'Tamaño de la forma
    If Me.WindowState = 0 Then
        MiX = 10470
        MiY = 5610
        Me.Width = MiX
        Me.Height = MiY
    End If
    
    Select Case GsTipo
        Case "EPS"
            Caption = GsDsn & " / " & GsAbreviaturaCia & " - Entidades Promotoras de Salud"
            MsCodAgr = sParametroFDT(Mado, "autoliq", "COL", 21)
        Case "AFP"
            Caption = GsDsn & " / " & GsAbreviaturaCia & " - Administradoras de Fondos de Pensiones"
            MsCodAgr = sParametroFDT(Mado, "autoliq", "COL", 22)
        Case "CCF"
            Caption = GsDsn & " / " & GsAbreviaturaCia & " - Cajas de Compensación Familiar"
            MsCodAgr = sParametroFDT(Mado, "parafiscal", "COL", 1)
    End Select
    AsignaIconos abToolbar, 3, LALTA, LBAJA, LTRABAJA, LORDENA, LRENUEVA, LGUARDA, LSALIDA
    ToolInicioGrupo abToolbar, 3, True, 3, 6
    
    MbAlta = False
    
    MSOrder = ""
    CreaBitacora
    MsSql = _
    " SELECT codigo, descripcion, registro_fiscal," & _
    " digito_verificacion dv, direccion, telefono," & _
    " cod_super, departamento, municipio" & _
    " FROM vw_fco_administradoras" & _
    " WHERE compania = '" & GsCveCia & "'" & _
    " AND tipo = '" & GsTipo & "'"
    RenuevaDatos
End Sub

Private Sub Form_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
    If Button = 2 Then abToolbar.Bands(1).TrackPopup -1, -1
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    If iDeseaGuardar = vbCancel Then Cancel = True
    Set Mado = Nothing
    Set objBitacora = Nothing
    Set clsSpread = Nothing
    Gtc(MiCx).ihijas = Gtc(MiCx).ihijas - 1
    Set FCO1020 = Nothing
End Sub

Private Sub Form_Resize()
    On Error Resume Next
    If Me.WindowState <> 1 Then
        GAdam.MaximizaControles Me, 1, 2, 10470, 5610, MiX, MiY, False, True, True, -1
    End If
End Sub

Private Sub Form_Unload(Cancel As Integer)
    If GbExterno Then End
End Sub

Private Sub imgListaAdm_Click()

If MbAlta Then
  Screen.MousePointer = vbHourglass
  With sprDatos
      GsParamIN(0) = "SELECT dato, descripcion FROM datos_agr_trab WHERE agrupacion='" & MsCodAgr & "'"
      GsParamIN(1) = "dato"
      GsParamIN(2) = "descripcion"
      Select Case GsTipo
      Case "EPS"
        GsParamIN(3) = "EPS"
        GsParamIN(5) = "EPS"
      Case "AFP"
        GsParamIN(3) = "FPO"
        GsParamIN(5) = "FPO"
      Case "CCF"
        GsParamIN(3) = "CCF"
        GsParamIN(5) = "CCF"
      End Select
      GsParamIN(4) = "Nombre"
      GsParamIN(6) = ""
      frmLista.Show 1
      
     .Col = 1: .Row = .ActiveRow: .Text = GsParamOUT(0)
     .Col = 2: .Row = .ActiveRow: .Text = GsParamOUT(1)
      
  End With
  Screen.MousePointer = vbDefault
End If

    If sprDatos.ActiveCol <> 7 And sprDatos.ActiveCol <> 8 And sprDatos.ActiveCol <> 9 Then Exit Sub
    Dim Aux As Variant
    
    GsParamIN(1) = "codigo"
    GsParamIN(2) = "nombre"
    GsParamIN(3) = "Codigo"
    GsParamIN(4) = "Nombre"
    GsParamIN(6) = ""
    Select Case sprDatos.ActiveCol
        Case 7
            GsParamIN(0) = "SELECT super, nombre" & _
            " FROM fco_super WHERE tipo = '" & GsTipo & "'"
            GsParamIN(5) = GsTipo
        Case 8
            GsParamIN(0) = "SELECT codigo, nombre" & _
            " FROM fco_departamentos WHERE 1=1"
            GsParamIN(5) = "Departamentos"
        Case 9
            sprDatos.GetText 8, sprDatos.ActiveRow, Aux
            GsParamIN(0) = "SELECT codigo, nombre" & _
            " FROM fco_ciudades" & _
            IIf(Trim(Aux) = "", " WHERE 1=1", " WHERE cod_dpto='" & Trim(Aux) & "'")
            GsParamIN(5) = "Municipios"
    End Select
    frmLista.Show 1
    If Trim(GsParamOUT(0)) <> "" Then
        sprDatos.Row = sprDatos.ActiveRow
        sprDatos.Col = sprDatos.ActiveCol
        If sprDatos.ActiveCol = 7 Then
            sprDatos.Text = GsParamOUT(0)
            If clsMsgbox.Mensaje("¿Desea traer todos los datos encontrados para esta entidad?", mSiNoCancelar, mConfirma, GsTitMsg) = vbYes Then
                Mado.Sql = "SELECT nit, dv, departamento, municipio FROM fco_super WHERE tipo = '" & GsTipo & "' AND super = '" & GsParamOUT(0) & "'"
                Mado.SendSQL
                If Not Mado.EOF Then
                    With sprDatos
                        .Col = 3: .Text = Mado.GetField(1)
                        .Col = 4: .Text = Mado.GetField(2)
                        .Col = 8: .Text = Mado.GetField(3)
                        .Col = 9: .Text = Mado.GetField(4)
                    End With
                End If
            End If
        Else
            sprDatos.Text = GsParamOUT(0)
        End If
        objBitacora.mCambia
    End If
End Sub

Private Sub sprDatos_Change(ByVal Col As Long, ByVal Row As Long)
    Dim vAux As Variant
    
    objBitacora.mCambia
    If Col = 7 Then
        sprDatos.GetText Col, Row, vAux
        Mado.Sql = "SELECT super FROM fco_super WHERE tipo = '" & GsTipo & "' AND ltrim(rtrim(super)) = '" & Trim(vAux) & "'"
        If Mado.SendSQL Then
            If Mado.EOF Then
                clsMsgbox.Mensaje "El código super digitado no es valido", mAceptar, mAdvierte, GsTitMsg
                sprDatos.SetText Col, Row, ""
            End If
        End If
    End If
End Sub

Private Sub sprDatos_KeyPress(KeyAscii As Integer)
    If sprDatos.ActiveCol = 7 Then
        KeyAscii = Asc(UCase(Chr(KeyAscii)))
    End If
End Sub

Private Sub sprDatos_KeyUp(KeyCode As Integer, Shift As Integer)
    If KeyCode = vbKeyF4 Then imgListaAdm_Click
End Sub

Private Sub Altas()
    objBitacora.mAgrega
    MbAlta = True
End Sub

Private Sub Bajas()
    If sprDatos.VirtualMaxRows <= 0 Then Exit Sub
    objBitacora.mBorra
End Sub

Private Sub ConfiguraSpread()
    With sprDatos
        .Visible = False
        .Action = 28
        GAdam.ConfiguracionSpread sprDatos
        .ColWidth(1) = 5
        .ColWidth(2) = 25
        .ColWidth(3) = 8
        .ColWidth(4) = 3
        .ColWidth(5) = 15
        .ColWidth(6) = 6
        .ColWidth(7) = 5
        .ColWidth(8) = 3
        .ColWidth(9) = 5
        .SetText 1, 0, "Cod."
        .SetText 2, 0, "Nombre"
        .SetText 3, 0, "NIT"
        .SetText 4, 0, "DV"
        .SetText 5, 0, "Direccion"
        .SetText 6, 0, "Telefono"
        .SetText 7, 0, "Super."
        .SetText 8, 0, "Dpto."
        .SetText 9, 0, "Munic."
        ConfiguraSpreadJCL sprDatos
    End With
End Sub

Private Sub CreaBitacora()
    objBitacora.mCreaBitacora sprDatos, Mado.lhEnv, Mado.lhDbc, Mado.lhstmt, Mado
    objBitacora.p_ConfirmaBaja = True
    objBitacora.mDefineLlave 1
    objBitacora.mTablaSPInfo 0, "sp_fco_alta_administradora", 1, 3, 4, 5, 6, 7, "''", "'" & GsTipo & "'", "'" & MsCodAgr & "'", "'U'", 2, 8, 9
    objBitacora.mTablaSPInfo 1, "sp_fco_baja_administradora", 1, "'" & GsTipo & "'", "'" & MsCodAgr & "'"
    objBitacora.mTablaSPInfo 2, "sp_fco_alta_administradora", 1, 3, 4, 5, 6, 7, "''", "'" & GsTipo & "'", "'" & MsCodAgr & "'", "'U'", 2, 8, 9
    objBitacora.mColNoNulls 1, 2
End Sub

Private Sub GuardaCambios()
    If sprDatos.MaxRows = 0 Then Exit Sub
    Screen.MousePointer = vbHourglass
    GbRen = objBitacora.mActualizaBD
    objBitacora.mVaciaBuffer
    MbAlta = False
    Screen.MousePointer = vbDefault
End Sub

Private Function iDeseaGuardar() As Integer
    ' Descripción : Devuelve el valor de la opción seleccionada en la clsMsgBox
    ' Uso : iDeseaGuardarCambios
    ' Regresa : Un Entero , dependiendo de la respuesta en clsMsgBox
    If objBitacora.pTransActual > 0 Then
       iDeseaGuardar = clsMsgbox.Mensaje("¿Desea guardar los cambios?", mSiNoCancelar, mConfirma, GsTitMsg)
       Select Case iDeseaGuardar
          Case vbYes
             GuardaCambios
             If GbRen = 0 Then iDeseaGuardar = 2
          Case vbNo
             objBitacora.mVaciaBuffer 'Vacía el Buffer de la Bitácora
       End Select
    Else
        iDeseaGuardar = 1
    End If
End Function

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

Private Sub RenuevaDatos()
    If iDeseaGuardar = vbCancel Then Exit Sub
    ConfiguraSpread
    Mado.Sql = MsSql & MSOrder
    If Not Mado.SendSQL Then Exit Sub
    clsSpread.LlenaSpread 0, sprDatos, Mado, Mado.lhDbc, Mado.lhstmt
    With sprDatos
        .Col = 1: .Row = -1: .Lock = True
        .Col = 3: .Row = -1: .TypeEditLen = 9
        .Col = 4: .Row = -1: .TypeEditLen = 1
        .Col = 7: .Row = -1: .TypeEditLen = 6
        .Col = 8: .Row = -1: .Lock = True
        .Col = 9: .Row = -1: .Lock = True
        .ScrollBars = ScrollBarsBoth
    End With
    GAdam.AjustaSpread sprDatos, 5
End Sub

Private Sub TrabajarCon()
    If sprDatos.ActiveRow > 0 Then
        sprDatos.Row = sprDatos.ActiveRow
        sprDatos.Col = 1
        GsDatoAux = sprDatos.Text
        sprDatos.Col = 2
        FCO1020T.lblTitulo = Trim(GsDatoAux) & "   " & Trim(sprDatos.Text)
        FCO1020T.Show 1
    End If
End Sub

