VERSION 5.00
Begin VB.Form FActivarDispensadores 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Activar Dispensadores (95.180.00)"
   ClientHeight    =   2220
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   7170
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MDIChild        =   -1  'True
   ScaleHeight     =   2220
   ScaleWidth      =   7170
   Begin VB.CommandButton cmdrecaltran 
      Caption         =   "Recálculo de Transacciones"
      Height          =   735
      Left            =   1560
      TabIndex        =   3
      Top             =   1080
      Visible         =   0   'False
      Width           =   1575
   End
   Begin VB.CommandButton cmdCancelar 
      Caption         =   "&Cancelar"
      Height          =   735
      Left            =   5130
      Picture         =   "9518000.frx":0000
      Style           =   1  'Graphical
      TabIndex        =   1
      Top             =   1125
      Width           =   1590
   End
   Begin VB.CommandButton cmdActivar 
      Caption         =   "&Activar"
      Height          =   735
      Left            =   3480
      Picture         =   "9518000.frx":030A
      Style           =   1  'Graphical
      TabIndex        =   0
      Top             =   1125
      Width           =   1635
   End
   Begin VB.Image Image1 
      Height          =   630
      Left            =   225
      Picture         =   "9518000.frx":0614
      Stretch         =   -1  'True
      Top             =   225
      Width           =   600
   End
   Begin VB.Label Label1 
      Caption         =   $"9518000.frx":091E
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   735
      Left            =   900
      TabIndex        =   2
      Top             =   180
      Width           =   6045
   End
   Begin VB.Shape Shape1 
      Height          =   1995
      Left            =   90
      Top             =   90
      Width           =   6945
   End
End
Attribute VB_Name = "FActivarDispensadores"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
' EDGAR MARTIN CANCHO RUIZ

Option Explicit

Public pb_editar As Boolean
Public pb_agregar As Boolean
Public pb_primerregistro As Boolean
Public pb_ultimoregistro As Boolean
Public pbderecho_agregar As Boolean
Public pbderecho_consultar As Boolean
Public pbderecho_editar As Boolean
Public pbderecho_borrar As Boolean
Public pbderecho_imprimir As Boolean
Public pbderecho_anular As Boolean
Public pbderecho_emitir As Boolean
Public pb_tiposcreen As String
 
Public GrecibeUbicacion As BookmarkEnum
Public GrecibeColumnaID As String
Public GrecibeColumnaOpcional As String

Private Mcmd As ADODB.Command
Private Mcon As ADODB.Connection
Private Mrs As ADODB.Recordset

Dim fso

Private MLibreriasFox As librerias_fox.OPERACIONES_TRAN

Public MobjDispensador As DB_UT_MANTENIMIENTOS.C_DISPENSADORES
Public MobjCorrelativo As DB_CORRELATIVO.C_Correlativos
Dim MlngCorrelativo As Long 'correlativo por usuario, que se almacenara en cada insert en temporal

Private Sub cmdActivar_Click()

On Error GoTo errhandler

Dim MrsTemporal As ADODB.Recordset
Dim MlngCantidadTransacciones As Long
Dim i As Integer
    
Set MLibreriasFox = Nothing


'Set MLibreriasFox = New librerias_fox.OPERACIONES_TRAN


    MlngCantidadTransacciones = 0
    
    If MsgBox("Está seguro de Activar los Dispensadores. ", vbQuestion + vbYesNo, "Activar") = vbNo Then
        Exit Sub
    Else
    
        Screen.MousePointer = 11
        'cmdrecaltran_Click
               
        'For i = 1 To GintCantidadCaras
            'Vaciando los Trans
            VaciarTran
            'Mid("0" & i, Len("0" & i) - 1, 2)
            'LimpiarTran Mid("0" & i, Len("0" & i) - 1, 2)
            'Next i
            
          MobjDispensador.GrabarTransaccionesAlHistorico
                
            ''ActivarMangueras
                
          Me.Hide
          MsgBox "Proceso realizado con éxito", vbInformation, "Activación de Dispensadores"
          Screen.MousePointer = 0
          Set MrsTemporal = Nothing
          Exit Sub
    End If
Unload Me
Exit Sub
errhandler:
     
    ' **********************************************************************
     Dim fso, txtfile
                          
     Set fso = CreateObject("Scripting.FileSystemObject")
     
     If Dir("c:\ControlErrores.txt") = "" Then
        Set txtfile = fso.CreateTextFile("c:\ControlErrores.txt", True, True)
     Else
        Set txtfile = fso.OpenTextFile("c:\ControlErrores.txt", 8, 0)
     End If
     
     txtfile.WriteLINE (Err.Description)
     txtfile.Close
     
    ' **********************************************************************
     
    If Err.Number = -2147352567 Or Err.Number = 70 Then
      MsgBox "Debe salir del Link y los sistemas en Playa para realizar el Proceso de Activación ", vbDefaultButton1 + vbExclamation, "Mensaje"
    Else
      MsgBox MensajedeError(Err.Number, Err.Description), vbDefaultButton1 + vbCritical, "Error"
    End If
    
    Set Mcmd = Nothing
    Set Mcon = Nothing
    Set Mrs = Nothing
    
    
    Screen.MousePointer = 0

End Sub

Private Sub cmdrecaltran_Click()
   
    Dim StrSql As String
    Dim StrSqlInsert As String
    Dim LobjProcesos As DB_UT_MANTENIMIENTOS.C_PROCESOS
    Dim i  As Integer
    
    Dim MconR As ADODB.Connection
        
    ' Para Almacenar los Datos del Archivo TRAN
         
    Dim MStrNumero As String
    Dim MDblSoles As Double
    Dim MStrProductoTran As String
    Dim MDblPrecioTran As Double
    Dim MdblGalones As Double
    Dim MStrCara As String
    Dim MStrTurno As String
    Dim mstrfecha As String
    Dim MStrHora As String
                      
    ' Final Para Almacenar los Datos del Archivo TRAN
         
    Set LobjProcesos = New DB_UT_MANTENIMIENTOS.C_PROCESOS
                  
    Set MconR = New ADODB.Connection
    MconR.ConnectionString = "FILEDSN=gasboy; Exclusive=No"
    MconR.Open
              
          
    For i = 1 To GintCantidadCaras
        Set Mrs = New ADODB.Recordset
        StrSql = "Select * FROM  tran" & Trim(Mid("0" & i, Len("0" & i) - 1, 2)) '& " WHERE ESTADO='CANCEL'"
        Mrs.Open StrSql, MconR, adOpenStatic, adLockReadOnly
            
        If Not Mrs.EOF Then
          Mrs.MoveFirst
          Do While Not Mrs.EOF
                        
                MStrNumero = Mrs!numero
                
                If GintTipoControlador = 0 Then ' Gasboy
                   MDblSoles = CDbl(Mrs!soles) / 100
                Else                            ' CEM44
                   MDblSoles = CDbl(Mrs!soles)
                End If
                
                If GintTipoControlador = 0 Then ' Gasboy
                   MStrProductoTran = Mrs!producto
                Else                            ' CEM44
                   MStrProductoTran = Format(Mrs!producto, "00")
                End If
                
                If GintTipoControlador = 0 Then ' Gasboy
                   MDblPrecioTran = CDbl(Mrs!precio) / 100
                Else                            ' CEM44
                   MDblPrecioTran = CDbl(Mrs!precio)
                End If
                
                If GintTipoControlador = 0 Then ' GASBOY
                   MdblGalones = CDbl(Mrs!galones) / 1000
                Else                            ' CEM44
                   MdblGalones = GFormatodeNumero(MDblSoles / MDblPrecioTran, 4)
                End If
                
                If GintTipoControlador = 0 Then ' GASBOY
                   MStrCara = Format(Mrs!cara, "00")
                Else                             ' CEM44
                   MStrCara = Mrs!cara
                End If
                
                mstrfecha = Mrs!fecha
                MStrHora = Mrs!hora
                
                If GintTipoControlador = 0 Then ' GASBOY
                   MStrTurno = Mrs!turno
                Else                             ' CEM44
                   MStrTurno = "1"
                End If
                                            
                                                     
                StrSqlInsert = " UT_ReprocesaTranProc '" & MStrNumero & "','" & Trim(Str(MDblSoles)) & "','" & _
                                                           MStrProductoTran & "','" & Trim(Str(MDblPrecioTran)) & "','" & _
                                                           Trim(Str(MdblGalones)) & "','" & MStrCara & "','" & mstrfecha & "','" & _
                                                           MStrHora & "','" & MStrTurno & "','CANCEL'," & Mrs!DOCUMENTO
                                
                LobjProcesos.Auxiliar1 StrSqlInsert
                 
            Mrs.MoveNext
          Loop
        End If
        Mrs.Close
        Set Mrs = Nothing
    Next
    MconR.Close
    Set MconR = Nothing
    
End Sub

Private Sub Form_Activate()
    Call gactualizaopcion(pbderecho_agregar, pbderecho_editar, pbderecho_borrar, pbderecho_imprimir)
    Call gactualiza_barra(Me)
    'lineas nuevas
    If pbderecho_consultar = False Then
        Unload Me
    End If
End Sub
Public Sub primer_registro()
End Sub
Public Sub ultimo_registro()
End Sub
Public Sub registro_anterior()
End Sub
Public Sub registro_siguiente()
End Sub

Private Sub Form_Load()
    'seguridad
    Call gseguridad(Me)
    
    If pbderecho_consultar Then

        Set MobjDispensador = New DB_UT_MANTENIMIENTOS.C_DISPENSADORES
        Set MobjCorrelativo = New DB_CORRELATIVO.C_Correlativos
      
        pb_primerregistro = True
    'lineas nuevas
    Else
        'Unload Me
        MsgBox ("No tiene Derechos de Consultar en este formulario"), vbCritical + vbDefaultButton1, "Mensaje"
    End If
    
    Me.Top = 1300
    Me.Left = (Screen.Width - Me.Width) / 2
    
    'Set Mcon = New ADODB.Connection
   
    'Mcon.Provider = "MSDASQL"
    'Mcon.ConnectionString = "Driver={Microsoft Visual FoxPro Driver (*.dbf)};UID=;SourceDB=" & GstrRutaTran & ";SourceType=DBF;Exclusive=No;BackgroundFetch=Sí;Collate=Machine;Null=Sí;Deleted=Sí;"
    
    'Mcon.ConnectionString = "FILEDSN=gasboy"
    'Mcon.Open
    
    ';SourceType=DBF;Exclusive=No;BackgroundFetch=Sí;Collate=Machine;Null=Sí;Deleted=Sí;"
    'Mrstranspend.CursorLocation = adUseClient
   
    'Set Mcmd = New ADODB.Command
    'Mcmd.ActiveConnection = Mcon
     
    'Set MLibreriasFox = New librerias_fox.OPERACIONES_TRAN
     
     
End Sub

Private Sub cmdcancelar_Click()
    Unload Me
End Sub

Private Sub Salir()
    Unload Me
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    If pb_editar Then
        If MsgBox("Desea Cancelar los Cambios", vbYesNo, "Esta Modificando un registro") = vbNo Then
            Cancel = True
        Else
            Call gdesactiva_barra
        End If
    Else
        Call gdesactiva_barra
    End If
End Sub

Private Sub Form_Unload(Cancel As Integer)
    
    Set MobjDispensador = Nothing
    Set MobjCorrelativo = Nothing
    
    Set Mcmd = Nothing
    Set Mcon = Nothing
    Set Mrs = Nothing
    
End Sub

Private Sub LimpiarTran(strCARA As String)
    Dim objFS As Object
    Set objFS = CreateObject("Scripting.FileSystemObject")
    objFS.deletefile GstrRutaTran & "Tran" & ".dbf"
    objFS.copyfile GstrRutaTranBlanco & "Tran" & ".dbf", GstrRutaTran
    Set objFS = Nothing
End Sub

Public Sub VaciarTran()

    ' Original
          
      'Dim StrSql As String
      'StrSql = "DELETE FROM  tran" & Trim(strCARA)
      'Mcmd.CommandText = StrSql
      'Mcmd.Execute
      
    ' Fin de Original

    ' Parte que Zapea los Trans

    '  MLibreriasFox.zapear_tran GstrRutaTran, "tran" & Trim(strCARA)
    
    '  If GintTipoControlador = 1 Then 'CEMM44
    '     MLibreriasFox.zapear_jtran GstrRutaJtran, "Jtran" & Trim(strCARA)
    '  End If
      
    ' Fin de Parte que zapea los Trans
        
    ' Parte que reemplazará los trans y Jtrans (si es CEMM44)
        
       If GintUser9_opsetup = 1 Then
                     
          ' Reemplazar los Trans
            If Trim(GstrRutaTran) & "ventadia.dbf" <> "" Then
               Set fso = CreateObject("Scripting.FileSystemObject")
               fso.deletefile Trim(GstrRutaTran) & "ventadia.DBF"
            End If
            
            If Trim(GstrRutaTranError) & "ventadia.dbf" <> "" Then
               Set fso = CreateObject("Scripting.FileSystemObject")
               fso.copyfile Trim(GstrRutaTranError) & "ventadia.dbf", Trim(GstrRutaTran)
            End If
            
          ' Fin de reemplazar los Trans
                        
          ' Reemplazar los Jtrans
            
            If GintTipoControlador = 1 Then
            'antes era con jtran.dbf'
               If Trim(GstrRutaJtran) & "ventadia.dbf" <> "" Then
                  Set fso = CreateObject("Scripting.FileSystemObject")
                  fso.deletefile Trim(GstrRutaJtran) & "ventadia.dbf"
               End If
            
               If Trim(GstrRutaTranError) & "ventadia.dbf" <> "" Then
                  Set fso = CreateObject("Scripting.FileSystemObject")
                  fso.copyfile Trim(GstrRutaTranError) & "ventadia.dbf", Trim(GstrRutaJtran)
               End If

            End If
                            
          ' Fin de Reemplazar los Jtrans
          
       Else
          MLibreriasFox.zapear_tran GstrRutaTran, "ventadia.dbf"
    
          If GintTipoControlador = 1 Then 'CEMM44
             MLibreriasFox.zapear_jtran GstrRutaJtran, "ventadia.dbf"
          End If
       End If
       
    ' Fin de Parte que reemplazará los trans y Jtrans (si es CEMM44)
End Sub

Private Function ListarTransacciones(strCARA As String) As ADODB.Recordset

   Dim StrSql As String
         
   Set Mrs = New ADODB.Recordset
   StrSql = " Select * FROM tran"
   Mrs.Open StrSql, Mcon, adOpenStatic
   Set ListarTransacciones = Mrs
    
End Function

Public Sub ActivarMangueras()
    
    Dim StrSql As String
    Dim Lfso, Ltxtfile
    
    
    Set Mcon = New ADODB.Connection
    ''Desactivado porque nose utiliza en esta versión de la aplicación
    ''Mcon.ConnectionString = "FILEDSN=gasboy"
    ''Mcon.Open

    ''Set Mcmd = New ADODB.Command
    ''Mcmd.ActiveConnection = Mcon
                
    If GintTipoControlador = 0 Then 'Gasboy
       ''StrSql = " Update TURNO set STOP=.F."
       ''Mcmd.CommandText = StrSql
       ''Mcmd.Execute
    Else                            'CEM44
       'Set Lfso = CreateObject("Scripting.FileSystemObject")
       'Set Ltxtfile = Lfso.OpenTextFile(GstrRutaTran & "cont.dat", 8, 0)
       'Ltxtfile.Write ("0")
       
       Open GstrRutaTran & "cont.dat" For Output As #1
       Print #1, "0"
       Close #1
        
    End If
    
    Set Mcmd = Nothing
       
    Mcon.Close
    Set Mcon = Nothing
    
    
End Sub




