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 FCO1045 
   Caption         =   "Centros de Trabajo"
   ClientHeight    =   4995
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   7155
   BeginProperty Font 
      Name            =   "Arial"
      Size            =   8.25
      Charset         =   0
      Weight          =   400
      Underline       =   0   'False
      Italic          =   0   'False
      Strikethrough   =   0   'False
   EndProperty
   Icon            =   "FCO1045 Centros Trabajo.frx":0000
   KeyPreview      =   -1  'True
   LinkTopic       =   "Form1"
   MDIChild        =   -1  'True
   ScaleHeight     =   4995
   ScaleWidth      =   7155
   Begin FPSpread.vaSpread sprDatos 
      Height          =   4290
      Left            =   150
      TabIndex        =   0
      Top             =   120
      Width           =   6105
      _Version        =   131077
      _ExtentX        =   10769
      _ExtentY        =   7567
      _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  =   "FCO1045 Centros Trabajo.frx":030A
   End
   Begin ActiveBarLibraryCtl.ActiveBar abToolbar 
      Left            =   375
      Top             =   4500
      _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           =   "FCO1045 Centros Trabajo.frx":0463
   End
End
Attribute VB_Name = "FCO1045"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private MoBitacora As New ADAMBitacora.Bitacora
Private MAdo As ODBC.ODBCDirecto
Private Micx As Integer 'Conexión
Private MsSql As String
Private MSOrder As String
Private MbOrdenAsc As Boolean
Private MsAntOrden As String

Private Sub abToolbar_Click(ByVal Tool As ActiveBarLibraryCtl.Tool)
    Select Case LCase(Tool.Name)
        Case "tlalta": Altas
        Case "tlbaja": Bajas
        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
    
    '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
    
    GAdam.ObtieneColores
    
    'Tamaño de la forma
    Width = 7230
    Height = 5400
    
    Caption = GsDsn & " / " & GsAbreviaturaCia & " - Centros de Trabajo"
    AsignaIconos abToolbar, 3, LALTA, LBAJA, LORDENA, LRENUEVA, LGUARDA, LSALIDA
    ToolInicioGrupo abToolbar, 3, True, 2, 5
    
    MSOrder = " ORDER BY 1"
    CreaBitacora
    MsSql = "SELECT centro_trabajo, descripcion, codigo_reporte, tarifa" & _
    " FROM vw_fco_centros_trabajo WHERE compania = '" & GsCveCia & "'"
    
    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 MoBitacora = Nothing
    Gtc(Micx).ihijas = Gtc(Micx).ihijas - 1
    Set FCO1045 = Nothing
End Sub

Private Sub Form_Resize()
    sprDatos.Width = Width - 440
    sprDatos.Height = Height - 1215
End Sub

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

Private Sub Altas()
    Dim sAgr As String
    Dim sDes As String
    Dim bValida As Boolean
    
    bValida = True
    sAgr = sParametroFDT(MAdo, "autoliq", "COL", 24)
    If sAgr = "" Then
        bValida = False
    Else
        MAdo.Sql = "SELECT 1 FROM rel_agr_companias WHERE compania = '" & GsCveCia & "' AND agrupacion = '" & sAgr & "'"
        MAdo.SendSQL
        If MAdo.EOF Then bValida = False
    End If
    
    If Not bValida Then
        clsMsgbox.Mensaje "Falta llenar la secuencia 24 de los parámetros de autoliquidación o el dato que allí existe no es válido", mAceptar, minforma, GsTitMsg
    Else
        MAdo.Sql = "SELECT descripcion FROM agrupaciones_trab WHERE agrupacion = '" & sAgr & "'"
        MAdo.SendSQL
        If Not MAdo.EOF Then
            sDes = Trim("" & MAdo.GetField(1))
        End If
        clsMsgbox.Mensaje "Para crear un nuevo centro de trabajo, primero debe agregarlo como un dato de la agrupación " & vbCrLf & sAgr & " - """ & sDes & """" & vbCrLf & "y aparecerá automáticamente aquí para complementar su información", mAceptar, minforma, GsTitMsg
    End If
End Sub

Private Sub Bajas()
    Dim sAgr As String
    Dim sDes As String
    Dim bValida As Boolean
    
    bValida = True
    sAgr = sParametroFDT(MAdo, "autoliq", "COL", 24)
    If sAgr = "" Then
        bValida = False
    Else
        MAdo.Sql = "SELECT 1 FROM rel_agr_companias WHERE compania = '" & GsCveCia & "' AND agrupacion = '" & sAgr & "'"
        MAdo.SendSQL
        If MAdo.EOF Then bValida = False
    End If
    
    If Not bValida Then
        clsMsgbox.Mensaje "Falta llenar la secuencia 24 de los parámetros de autoliquidación o el dato que allí existe no es válido", mAceptar, minforma, GsTitMsg
    Else
        MAdo.Sql = "SELECT descripcion FROM agrupaciones_trab WHERE agrupacion = '" & sAgr & "'"
        MAdo.SendSQL
        If Not MAdo.EOF Then
            sDes = Trim("" & MAdo.GetField(1))
        End If
        clsMsgbox.Mensaje "Para eliminar un centro de trabajo, primero debe eliminarlo de los datos de la agrupación " & vbCrLf & sAgr & " - """ & sDes & """" & vbCrLf & vbCrLf, mAceptar, minforma, GsTitMsg
    End If
End Sub

Private Sub ConfiguraSpread()
    With sprDatos
        .Visible = False
        .Action = 28
        GAdam.ConfiguracionSpread sprDatos
        .ColWidth(1) = 8
        .ColWidth(2) = 30
        .ColWidth(3) = 10
        .ColWidth(4) = 8
        .SetText 1, 0, "Código"
        .SetText 2, 0, "Descripcion"
        .SetText 3, 0, "Cod.Reporte"
        .SetText 4, 0, "Tarifa"
        ConfiguraSpreadJCL sprDatos
    End With
End Sub

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

Private Sub GuardaCambios()
    If sprDatos.MaxRows = 0 Then Exit Sub
    Screen.MousePointer = vbHourglass
    GbRen = MoBitacora.mActualizaBD
    MoBitacora.mVaciaBuffer
    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 MoBitacora.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
             MoBitacora.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()
    Dim clsSpread As NSpread
    If iDeseaGuardar = vbCancel Then Exit Sub
    Set clsSpread = New NSpread
    ConfiguraSpread
    MAdo.Sql = MsSql & MSOrder
    If Not MAdo.SendSQL Then Exit Sub
    clsSpread.LlenaSpread 0, sprDatos, MAdo, MAdo.lhDbc, MAdo.lhstmt
    Set clsSpread = Nothing
    With sprDatos
        .Row = -1
        .Col = 1: .TypeEditLen = 10: .Lock = True
        .Col = 2: .TypeEditLen = 60
        .Col = 3: .CellType = 2: .TypeFloatDecimalPlaces = 0: .TypeFloatMax = 999999999: .TypeFloatMin = 0
        .Col = 4: .CellType = 2: .TypeFloatDecimalPlaces = 5: .TypeFloatMax = 1: .TypeFloatMin = 0
        .ScrollBars = ScrollBarsBoth
    End With
End Sub
