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 FCO2020B 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Configuracion Oficinas"
   ClientHeight    =   3000
   ClientLeft      =   45
   ClientTop       =   435
   ClientWidth     =   5505
   Icon            =   "Configuracion Oficinas Embargos.frx":0000
   KeyPreview      =   -1  'True
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   3000
   ScaleWidth      =   5505
   StartUpPosition =   3  'Windows Default
   Begin FPSpread.vaSpread sprDatos 
      Bindings        =   "Configuracion Oficinas Embargos.frx":030A
      Height          =   2145
      Left            =   240
      TabIndex        =   0
      Top             =   240
      Width           =   5055
      _Version        =   131077
      _ExtentX        =   8916
      _ExtentY        =   3784
      _StockProps     =   64
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      MaxCols         =   1
      MaxRows         =   1
      SpreadDesigner  =   "Configuracion Oficinas Embargos.frx":0320
   End
   Begin ActiveBarLibraryCtl.ActiveBar abToolbar 
      Left            =   0
      Top             =   0
      _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           =   "Configuracion Oficinas Embargos.frx":049B
   End
End
Attribute VB_Name = "FCO2020B"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private WithEvents clsSpread As NSpread
Attribute clsSpread.VB_VarHelpID = -1
Private Mado As ODBC.ODBCDirecto
Private Micx As Integer 'Conexión
Private MiX As Integer 'Ancho de la forma
Private MiY As Integer 'Alta de la forma
Private MBitacora As New ADAMBitacora.Bitacora

Private MbFirst As Boolean

Private MbRenovar As Boolean
Private MSSql As String
Private MbOrdenAsc As Boolean
Private MsAntOrden As String
Private MSOrder As String

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

Private Sub Form_Load()
    MbFirst = True
    GbAError = False
    Me.Tag = GiVenMax%
    Gven(Val(Me.Tag)).icx = Gicx%
    Micx = Gven(Val(Me.Tag)).icx
    Set Mado = Gtc(Micx).Ado
    If GbSinRegistrar Then RegistraVersion Mado
    Caption = GsDsn & " / " & GsAbreviaturaCia & " - Oficina Embargos"

    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 = 5595
        MiY = 3480
        Me.Width = MiX
        Me.Height = MiY
    End If
    
    Set clsSpread = New NSpread
    GAdam.ObtieneColores
    
    AsignaIconos abToolbar, 3, LALTA, LBAJA, LORDENA, LRENUEVA, LGUARDA, LSALIDA
    ToolInicioGrupo abToolbar, 3, True, 2, 5
        
    CreaBitacora
    
    MSSql = " SELECT cod_oficina, descripcion_oficina" & _
    " FROM fdt_embargos_oficinas" & _
    " WHERE compania = '" & GsCveCia & "'"
    MSOrder = " Order By 1 DESC"

    RenuevaDatos
    Screen.MousePointer = vbDefault
End Sub

Private Sub RenuevaDatos()
    ConfiguraSpread
    
    Mado.SQL = MSSql & MSOrder
    If Not Mado.SendSQL Then Exit Sub
        
    clsSpread.LlenaSpread 0, sprDatos, Mado, Mado.lhDbc, Mado.lhstmt

    With sprDatos
        .ColWidth(1) = 8
        .ColWidth(2) = 24
    End With
    GAdam.AjustaSpread sprDatos, 2
End Sub

Private Sub ConfiguraSpread()
    sprDatos.VisibleCols = 2
    With sprDatos
        .Visible = False
        .Action = 28
        GAdam.ConfiguracionSpread sprDatos
    
        .Row = 0:
        .Col = 1: .Text = "Codigo"
        .Col = 2: .Text = "Descripcion"
        .Col = 2
        .DataFillEvent = True
        .Col = 1: .Row = -1: .Lock = True
    End With
    ConfiguraSpreadJCL sprDatos
End Sub

Private Sub CreaBitacora()
    MBitacora.mCreaBitacora sprDatos, Mado.lhEnv, Mado.lhDbc, Mado.lhstmt, Mado
    MBitacora.p_ConfirmaBaja = True
    MBitacora.mDefineLlave 2
    MBitacora.mTablaSPInfo 0, "sp_fdt_alta_oficinas_embargos", "'" & GsCveCia & "'", 1, 2
    MBitacora.mTablaSPInfo 1, "sp_fdt_baja_oficinas_embargos", "'" & GsCveCia & "'", 1, 2
    MBitacora.mTablaSPInfo 2, "sp_fdt_alta_oficinas_embargos", "'" & GsCveCia & "'", 1, 2
    MBitacora.mColNoNulls 1, 2
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

Private Sub Altas()
    With sprDatos
        .VirtualMode = True
        MBitacora.mAgrega
        .VirtualMode = False
    End With
End Sub

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

Private Sub GuardaCambios()
    If sprDatos.MaxRows = 0 Then Exit Sub
    Screen.MousePointer = vbHourglass
    MbRenovar = MBitacora.mActualizaBD
    MBitacora.mVaciaBuffer
    Screen.MousePointer = vbDefault
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
            Screen.MousePointer = vbHourglass
            MBitacora.mBorra
            Screen.MousePointer = vbDefault
        Case vbKeyF11: GuardaCambios
        Case vbKeyF12: abToolbar.Bands(1).TrackPopup -1, -1
    End Select
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 iDeseaGuardarCambios = 2 Then Cancel = True
End Sub

Private Function iDeseaGuardarCambios() 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 MBitacora.pTransActual > 0 Then
       iDeseaGuardarCambios = clsMsgbox.Mensaje("¿Desea guardar los cambios?", mSiNoCancelar, mConfirma, GsTitMsg)
       Select Case iDeseaGuardarCambios
          Case 6
             GuardaCambios
             If MbRenovar = 0 Then iDeseaGuardarCambios = 2
          Case 7
             MBitacora.mVaciaBuffer 'Vacía el Buffer de la Bitácora
       End Select
    Else
        iDeseaGuardarCambios = 1
    End If
End Function

Private Sub Form_Unload(Cancel As Integer)
    Set clsSpread = Nothing
    Set MBitacora = Nothing
    Set Mado = Nothing
    Gtc(Micx).ihijas = Gtc(Micx).ihijas - 1
    Set FCO2020B = Nothing
End Sub

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

Private Sub sprDatos_EditMode(ByVal Col As Long, ByVal Row As Long, ByVal Mode As Integer, ByVal ChangeMade As Boolean)
    MBitacora.mCambia
End Sub

