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 FCO1050 
   Caption         =   "Definicion de Reportes"
   ClientHeight    =   3255
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   6660
   BeginProperty Font 
      Name            =   "Arial"
      Size            =   8.25
      Charset         =   0
      Weight          =   400
      Underline       =   0   'False
      Italic          =   0   'False
      Strikethrough   =   0   'False
   EndProperty
   Icon            =   "Definicion de reportes ala.frx":0000
   KeyPreview      =   -1  'True
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MDIChild        =   -1  'True
   ScaleHeight     =   3255
   ScaleWidth      =   6660
   Begin FPSpread.vaSpread sprDatos 
      Height          =   2385
      Left            =   120
      TabIndex        =   0
      Top             =   120
      Width           =   6315
      _Version        =   131077
      _ExtentX        =   11139
      _ExtentY        =   4207
      _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  =   "Definicion de reportes ala.frx":030A
   End
   Begin ActiveBarLibraryCtl.ActiveBar abToolbar 
      Left            =   195
      Top             =   2535
      _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           =   "Definicion de reportes ala.frx":0463
   End
End
Attribute VB_Name = "FCO1050"
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 Micx As Integer 'Conexión
Private MiX As Integer 'Ancho de la forma
Private MiY As Integer 'Alta de la forma
Private MSSql As String
Private MsOrden 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 "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
    
    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 = 6780
        MiY = 3660
        Me.Width = MiX
        Me.Height = MiY
    End If
    
    Caption = GsDsn & " / " & GsAbreviaturaCia & " - Reportes de A.L.A."
    AsignaIconos abToolbar, 3, LALTA, LBAJA, LTRABAJA, LORDENA, LRENUEVA, LGUARDA, LSALIDA
    ToolInicioGrupo abToolbar, 3, True, 3, 6
    
    MsOrden = ""
    CreaBitacora
    MSSql = "SELECT codigo, nombre FROM fco_reportes_ala"
    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 FCO1050 = Nothing
End Sub

Private Sub Form_Resize()
    On Error Resume Next
    If Me.WindowState <> 1 Then
        GAdam.MaximizaControles Me, 1, 2, 6780, 3660, 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 sprDatos_DblClick(ByVal Col As Long, ByVal Row As Long)
    TrabajarCon
End Sub

Private Sub Altas()
    GsLlave = "A"
    FCO1050A.Caption = GsDsn & " / " & GsAbreviaturaCia & " - Alta Reportes ALA"
    FCO1050A.Show 1
    RenuevaDatos
    
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) = 10
        .SetText 1, 0, "Codigo"
        .SetText 2, 0, "Nombre Reporte"
        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 1, "sp_fco_baja_reportes_ala", 1
   objBitacora.mColNoNulls 1, 2
End Sub

Private Sub GuardaCambios()
    If sprDatos.MaxRows = 0 Then Exit Sub
    Screen.MousePointer = vbHourglass
    GbRen = objBitacora.mActualizaBD
    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
    MsOrden = " 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 & MsOrden
    If Not Mado.SendSQL Then Exit Sub
    clsSpread.LlenaSpread 0, sprDatos, Mado, Mado.lhDbc, Mado.lhstmt
    With sprDatos
        .Col = -1: .Row = -1: .Lock = True
        .ScrollBars = ScrollBarsBoth
    End With
    GAdam.AjustaSpread sprDatos, 2
End Sub

Private Sub TrabajarCon()
    Dim Aux As Variant
    
    If sprDatos.ActiveRow < 0 Then Exit Sub
    Screen.MousePointer = vbHourglass
    sprDatos.GetText 1, sprDatos.ActiveRow, Aux
    GsLlave = CStr(Aux)
    FCO1050A.Caption = GsDsn & " / " & GsAbreviaturaCia & " - Trabajar Con Reportes ALA"
    FCO1050A.Show 1
    RenuevaDatos
End Sub

