VERSION 5.00
Object = "{F0D2F211-CCB0-11D0-A316-00AA00688B10}#1.0#0"; "MSDATLST.OCX"
Object = "{86CF1D34-0C5F-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCT2.OCX"
Object = "{69F9D01E-F1DE-11D4-9536-002018603DA2}#7.0#0"; "ControlNumber.ocx"
Begin VB.Form FTipoCambio 
   BorderStyle     =   3  'Fixed Dialog
   Caption         =   "Mantenimiento de Tipo de Cambio (95.060.00)"
   ClientHeight    =   4185
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   6810
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MDIChild        =   -1  'True
   ScaleHeight     =   4185
   ScaleWidth      =   6810
   ShowInTaskbar   =   0   'False
   Begin VB.Timer tmrHora 
      Left            =   4770
      Top             =   540
   End
   Begin VB.CommandButton cmdBusquedaRapida 
      Caption         =   "Búsqueda Rápida"
      Enabled         =   0   'False
      Height          =   780
      Left            =   675
      Picture         =   "9506000.frx":0000
      Style           =   1  'Graphical
      TabIndex        =   13
      Top             =   225
      Width           =   1740
   End
   Begin VB.ComboBox cmboperador 
      Height          =   315
      ItemData        =   "9506000.frx":030A
      Left            =   2475
      List            =   "9506000.frx":0314
      Style           =   2  'Dropdown List
      TabIndex        =   7
      Top             =   3420
      Width           =   915
   End
   Begin MiControl.CtrlNumber ctrlMtoTipoCambio 
      Height          =   375
      Left            =   2475
      TabIndex        =   6
      Top             =   2985
      Width           =   1410
      _ExtentX        =   2487
      _ExtentY        =   661
      BackColor       =   -2147483643
      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
   End
   Begin MSDataListLib.DataCombo dtcMdaHasta 
      Height          =   315
      Left            =   2475
      TabIndex        =   5
      Top             =   2520
      Width           =   2175
      _ExtentX        =   3836
      _ExtentY        =   556
      _Version        =   393216
      Style           =   2
      Text            =   "DataCombo3"
   End
   Begin MSDataListLib.DataCombo dtcMdaDesde 
      Height          =   315
      Left            =   2475
      TabIndex        =   4
      Top             =   2070
      Width           =   2175
      _ExtentX        =   3836
      _ExtentY        =   556
      _Version        =   393216
      Style           =   2
      Text            =   "DataCombo2"
   End
   Begin MSComCtl2.DTPicker dtpFecha 
      Height          =   330
      Left            =   2475
      TabIndex        =   3
      Top             =   1620
      Width           =   1455
      _ExtentX        =   2566
      _ExtentY        =   582
      _Version        =   393216
      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
      Format          =   60948481
      CurrentDate     =   37606
   End
   Begin VB.CommandButton cmdBuscar 
      Height          =   375
      Left            =   5895
      MouseIcon       =   "9506000.frx":031E
      MousePointer    =   99  'Custom
      Picture         =   "9506000.frx":0470
      Style           =   1  'Graphical
      TabIndex        =   2
      ToolTipText     =   "Buscar Documento"
      Top             =   1125
      Width           =   375
   End
   Begin MSDataListLib.DataCombo dtcTipoCambio 
      Height          =   315
      Left            =   2475
      TabIndex        =   1
      Top             =   1170
      Width           =   3345
      _ExtentX        =   5900
      _ExtentY        =   556
      _Version        =   393216
      Style           =   2
      Text            =   "DataCombo1"
   End
   Begin VB.Label lblhora 
      BorderStyle     =   1  'Fixed Single
      Caption         =   "10:00 a.m."
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   9.75
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   330
      Left            =   3915
      TabIndex        =   14
      Top             =   1620
      Visible         =   0   'False
      Width           =   1140
   End
   Begin VB.Shape Shape1 
      Height          =   3885
      Left            =   180
      Top             =   90
      Width           =   6450
   End
   Begin VB.Label Label7 
      Alignment       =   1  'Right Justify
      Caption         =   "Operador :"
      Height          =   285
      Left            =   630
      TabIndex        =   12
      Top             =   3510
      Width           =   1725
   End
   Begin VB.Label Label6 
      Alignment       =   1  'Right Justify
      Caption         =   "Monto de Tipo de Cambio :"
      Height          =   285
      Left            =   360
      TabIndex        =   11
      Top             =   3060
      Width           =   1995
   End
   Begin VB.Label Label5 
      Alignment       =   1  'Right Justify
      Caption         =   "A moneda :"
      Height          =   240
      Left            =   495
      TabIndex        =   10
      Top             =   2610
      Width           =   1815
   End
   Begin VB.Label Label4 
      Alignment       =   1  'Right Justify
      Caption         =   "Desde Moneda :"
      Height          =   285
      Left            =   495
      TabIndex        =   9
      Top             =   2115
      Width           =   1860
   End
   Begin VB.Label Label2 
      Alignment       =   1  'Right Justify
      Caption         =   "Fecha :"
      Height          =   195
      Left            =   495
      TabIndex        =   8
      Top             =   1710
      Width           =   1860
   End
   Begin VB.Label Label1 
      Caption         =   "Clase de Tipo de Cambio :"
      Height          =   285
      Left            =   495
      TabIndex        =   0
      Top             =   1215
      Width           =   1860
   End
End
Attribute VB_Name = "FTipoCambio"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'PROGRAMADOR: JOE GERARDO BREÑA HUACHIN

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 pb_tiposcreen As String

Public GrecibeUbicacion As BookmarkEnum
Public GrecibeColumnaID As String
Public GrecibeColumnaOpcional As String

Public rs_Cambios As ADODB.Recordset
Public rs_CMBTipoCambio As ADODB.Recordset

Public objTipoCambio As DB_UT_MANTENIMIENTOS.C_TIPOCAMBIO

Dim LblnFlag As Boolean

Private Sub cmbOperador_KeyPress(KeyAscii As Integer)
On Error Resume Next
    If KeyAscii = 13 Then
        Me.dtcTipoCambio.SetFocus
    End If
End Sub

Private Sub cmdBuscar_Click()
    'Lineas que llaman al Formulario de Búsqueda
    
    Dim ArrayBusqueda(1 To 2, 1 To 3) As Variant
    ArrayBusqueda(1, 1) = "CURYTYPEID"
    ArrayBusqueda(1, 2) = "Código "
    ArrayBusqueda(1, 3) = 1000
    ArrayBusqueda(2, 1) = "descr"
    ArrayBusqueda(2, 2) = "Descripción "
    ArrayBusqueda(2, 3) = 4000
      
          
    FBusquedasUt.GObtenerRegistros objTipoCambio.ListarTipoCambioAyuda, ArrayBusqueda, 2, 2
    FBusquedasUt.Show vbModal
    If GrecibeUbicacion <> 0 And GrecibeUbicacion <= rs_Cambios.RecordCount Then
          rs_CMBTipoCambio.AbsolutePosition = GrecibeUbicacion
          'asigna_campos
          Call muestra_tipo_sel
          Call gestadoactualrs(Me, rs_Cambios)
          Call gactualiza_barra(Me)
    End If
End Sub

Sub muestra_tipo_sel()
    Me.dtcTipoCambio.BoundText = Me.rs_CMBTipoCambio!CURYTYPEID
End Sub

Private Sub cmdBusquedaRapida_Click()
    FBusquedaCambios.Show vbModal
End Sub

Private Sub ctrlMtoTipoCambio_KeyPress(KeyAscii As Integer)
On Error Resume Next
    If KeyAscii = 13 Then
        Me.cmboperador.SetFocus
    End If
End Sub

Private Sub dtcMdaDesde_KeyPress(KeyAscii As Integer)
On Error Resume Next
    If KeyAscii = 13 Then
        Me.dtcMdaHasta.SetFocus
    End If
End Sub

Private Sub dtcMdaHasta_KeyPress(KeyAscii As Integer)
On Error Resume Next
    If KeyAscii = 13 Then
        Me.ctrlMtoTipoCambio.SetFocus
    End If
End Sub

Private Sub dtcTipoCambio_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Then
        dtpFecha.SetFocus
    End If
End Sub

Private Sub dtpFecha_KeyDown(KeyCode As Integer, Shift As Integer)
On Error Resume Next
    If KeyCode = 13 Then
        Me.dtcMdaDesde.SetFocus
    End If
End Sub

Private Sub Form_Activate()

    Call gactualizaopcion(pbderecho_agregar, pbderecho_editar, pbderecho_borrar, pbderecho_imprimir)
    Call gactualiza_barra(Me)
    habilita_btnbusqueda (False)
    'lineas nuevas
    If pbderecho_consultar = False Then
        Unload Me
    End If

End Sub

Public Sub primer_registro()
    Call Gprimer_registro(Me, rs_Cambios)
    Call asigna_campos
End Sub

Public Sub ultimo_registro()
    Call Gultimo_registro(Me, rs_Cambios)
    Call asigna_campos
End Sub

Public Sub registro_anterior()
    Call Gregistro_anterior(Me, rs_Cambios)
    Call asigna_campos
End Sub
Public Sub registro_siguiente()
    Call Gregistro_siguiente(Me, rs_Cambios)
    Call asigna_campos
End Sub
Private Sub Form_Load()
    'seguridad
    Call gseguridad(Me)
    
    If pbderecho_consultar Then
        Dim numreg As Long
        Set objTipoCambio = New DB_UT_MANTENIMIENTOS.C_TIPOCAMBIO
        Call LlenaDataCombos
        Call obtener_datos
        Call asigna_campos
        pb_primerregistro = True
        Call gHabilitarReg(Me, False)
    Else
        MsgBox ("No tiene Derechos de Consultar en este formulario"), vbCritical + vbDefaultButton1, "Mensaje"
    End If
     Me.Top = 1300
     Me.Left = (Screen.Width - Me.Width) / 2
End Sub
Public Sub borrar_registro()
On Error GoTo errhandler
    objTipoCambio.EliminarTipoCambio Me.dtcTipoCambio.BoundText, _
    Me.dtcMdaDesde.BoundText, Me.dtcMdaHasta.BoundText, Me.dtpFecha.Value & " " & lblhora.Caption
    
    Call gborrar_Registro(Me, rs_Cambios, dtcTipoCambio)
    
    rs_Cambios.Close
    
    Call obtener_datos
    Call asigna_campos
Exit Sub

errhandler:
    MsgBox MensajedeError(Err.Number, Err.Description), vbDefaultButton1 + vbCritical, "Error"

End Sub
Function valida_datos() As Boolean
    If Trim(Me.dtcTipoCambio.Text) = Empty Then
        valida_datos = False
        MsgBox "Ingrese el tipo de cambio", vbInformation, "Error"
        Exit Function
    End If
    If Trim(Me.dtcMdaDesde.Text) = Empty Then
        valida_datos = False
        MsgBox "Ingrese la moneda de inicio", vbInformation, "Error"
        Exit Function
    End If
    If Trim(Me.dtcMdaHasta.Text) = Empty Then
        valida_datos = False
        MsgBox "Ingrese la moneda final", vbInformation, "Error"
        Exit Function
    End If
    If Trim(Me.dtcMdaDesde.Text) = Trim(Me.dtcMdaHasta.Text) Then
        valida_datos = False
        MsgBox "Las monedas de inicio y final deben ser diferentes", vbInformation, "Error"
        Exit Function
    End If
    If Val(Me.ctrlMtoTipoCambio.Text) = 0 Then
        valida_datos = False
        MsgBox "El monto de tipo de cambio debe ser mayor a cero", vbInformation, "Error"
        Exit Function
    End If
    If Trim(Me.cmboperador.Text) = Empty Then
        valida_datos = False
        MsgBox "Ingrese operador de tipo de cambio", vbInformation, "Error"
        Exit Function
    End If
        
    valida_datos = True
End Function
Public Sub grabar_registro()

On Error GoTo errhandler
    If valida_datos() = True Then
        ' llamada al proc de grabacion
        If pb_agregar Then
'            objTipoCambio.AgregarTipoCambio Trim(Me.dtcTipoCambio.BoundText), Trim(Me.dtcMdaDesde.BoundText), _
            Trim(Me.dtcMdaHasta.BoundText), Me.dtpFecha.Value & " " & lblhora.Caption, Me.ctrlMtoTipoCambio.Text, Me.cmboperador.Text, GCUSERID
            objTipoCambio.AgregarTipoCambio Trim(Me.dtcTipoCambio.BoundText), Trim(Me.dtcMdaDesde.BoundText), _
            Trim(Me.dtcMdaHasta.BoundText), Me.dtpFecha.Value, Me.ctrlMtoTipoCambio.Text, Me.cmboperador.Text, GCUSERID
        Else
'            objTipoCambio.ActualizarTipoCambio Trim(Me.dtcTipoCambio.BoundText), Trim(Me.dtcMdaDesde.BoundText), _
            Trim(Me.dtcMdaHasta.BoundText), Me.dtpFecha.Value & " " & lblhora.Caption, Me.ctrlMtoTipoCambio.Text, Me.cmboperador.Text, GCUSERID
            objTipoCambio.ActualizarTipoCambio Trim(Me.dtcTipoCambio.BoundText), Trim(Me.dtcMdaDesde.BoundText), _
            Trim(Me.dtcMdaHasta.BoundText), Me.dtpFecha.Value, Me.ctrlMtoTipoCambio.Text, Me.cmboperador.Text, GCUSERID
        End If
        
        Call ggrabar_registro(Me)
        Call actualizar_registro
        'Call correr_hora(False)
        Call habilita_para_busqueda
    End If
Exit Sub
errhandler:
    MsgBox MensajedeError(Err.Number, Err.Description), vbDefaultButton1 + vbCritical, "Error"
End Sub
Public Sub actualizar_registro()
    'llamar al procedimiento de carga
    Call obtener_datos
    Call asigna_campos
    habilita_btnbusqueda (False)
    'Call correr_hora(True)
    'MsgBox ("Registros Actualizados")
End Sub

Sub correr_hora(valor As Boolean)
    tmrHora.Interval = 1000
    tmrHora.Enabled = valor
End Sub

Public Sub agregar_registro()
    Call gagregar_registro(Me, dtcTipoCambio)
    'dtpFecha.Value = Date
    'lblHora.Caption = Time
    Call Me.habilitar_registros_nuevo(True)
    Call habilita_btnbusqueda(True)
    'Call correr_hora(True)
End Sub
Public Sub modificar_registro()
    Call gmodificar_registro(Me, dtcTipoCambio)
    Call habilitar_registros_modificar(False)
    'habilita_btnbusqueda (False)
End Sub

Sub habilita_btnbusqueda(valor As Boolean)
    Me.cmdBuscar.Enabled = valor
End Sub

Public Sub descartar_registro()
    ' Revertir cambios
    'adodc1.Recordset.CancelUpdate
    Call gdescartar_registro(Me)
    Call asigna_campos
    Call habilita_para_busqueda
    Call habilita_btnbusqueda(False)
    'Call correr_hora(False)
End Sub

Sub obtener_datos()
    Set rs_Cambios = objTipoCambio.ListarCambios
    Set rs_CMBTipoCambio = objTipoCambio.ListarTiposCambio
End Sub

Sub salir_formulario()
    ' validar que no haya procesos pendientes
    ' si no hay problemas
    MDIFUtilitarios.Toolbar1.Buttons(18).Caption = "Salir"    ' boton salir
    Unload Me
End Sub

Sub asigna_campos() ' falta decidir si va ha ser public o private
    Dim i As Integer
    
    Me.ctrlMtoTipoCambio.Decimales = GintDecPrecio
    Me.ctrlMtoTipoCambio.Enteros = 5
    
    If rs_Cambios.RecordCount <> 0 Then
        Me.dtcTipoCambio.BoundText = rs_Cambios!CURYTYPEID
        Me.dtpFecha.Value = Format(rs_Cambios!CURYDATE, "dd/MM/yyyy")
        Me.lblhora.Caption = IIf(Format(rs_Cambios!CURYDATE, "HH:mm") = "00.00", "00:00", Hour(rs_Cambios!CURYDATE) & ":" & Minute(rs_Cambios!CURYDATE))
        Me.dtcMdaDesde.BoundText = rs_Cambios!FROMCURYID
        Me.dtcMdaHasta.BoundText = rs_Cambios!TOCURYID
        Me.ctrlMtoTipoCambio.Text = Format(rs_Cambios!Rate, GMascara(GintDecPrecio))
        Me.cmboperador.Text = rs_Cambios!OPERADOR
        For i = 0 To Me.cmboperador.ListCount - 1
            If Me.cmboperador.List(i) = rs_Cambios!OPERADOR Then
                Me.cmboperador.ListIndex = i
                Exit For
            End If
        Next
    End If
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
            pb_editar = False
        End If
    Else
        Call gdesactiva_barra
    End If
End Sub

Private Sub Form_Unload(Cancel As Integer)
    Set objTipoCambio = Nothing
    Set rs_Cambios = Nothing
End Sub


'Private Sub txtCodigo_KeyPress(KeyAscii As Integer)
'    KeyAscii = GBloqueaCaracter(KeyAscii)
'    If KeyAscii = 13 Then
'        txtDescripcion.SetFocus
'    End If
'End Sub

Sub imprimir()
'    crBancos.ReportFileName = GstrReportesInv + "rpt_bancos.rpt"
'    crBancos.WindowTitle = "Reporte de Tipo de Cambio"
'    crBancos.Formulas(1) = "formusuario=stringvar strusuario; strusuario:='" & GCUSERID & "'"
'    crBancos.Formulas(2) = "formscreen=stringvar strscreen; strscreen:='01.117.00'"
'    crBancos.WindowState = crptMaximized
'    crBancos.WindowShowPrintSetupBtn = True
'    crBancos.Action = 1
    
End Sub

Private Sub txtDescripcion_KeyPress(KeyAscii As Integer)
    KeyAscii = GBloqueaCaracter(KeyAscii)
End Sub

Private Sub LlenaDataCombos()
    Call CargaDataCombo(Me.dtcTipoCambio, objTipoCambio.ListarTiposCambio, "CURYTYPEID", "Descr")
    Call CargaDataCombo(Me.dtcMdaDesde, objTipoCambio.ListarMonedas, "CURYID", "Descr")
    Call CargaDataCombo(Me.dtcMdaHasta, objTipoCambio.ListarMonedas, "CURYID", "Descr")
End Sub

' si es para un registro nuevo
Sub habilitar_registros_nuevo(valor As Boolean)
    Me.dtcTipoCambio.Enabled = valor
    Me.dtpFecha.Value = Date
    Me.dtpFecha.Enabled = valor
    Me.dtcMdaDesde.Enabled = valor
    Me.dtcMdaHasta.Enabled = valor
    Me.ctrlMtoTipoCambio.Enabled = valor
    Me.cmboperador.Enabled = valor
    Call Me.habilita_btnbusqueda(True)
End Sub

' si es para modificar un registro
Sub habilitar_registros_modificar(valor As Boolean)
    Me.dtcTipoCambio.Enabled = valor
    Me.dtpFecha.Enabled = valor

    Me.dtcMdaDesde.Enabled = valor
    Me.dtcMdaHasta.Enabled = valor
    Me.ctrlMtoTipoCambio.Enabled = Not valor
    Me.cmboperador.Enabled = valor
    Call Me.habilita_btnbusqueda(False)
End Sub

Sub habilita_para_busqueda()
    Me.dtcTipoCambio.Enabled = False
    Me.dtpFecha.Enabled = False
    Me.dtcMdaDesde.Enabled = False
    Me.dtcMdaHasta.Enabled = False
    Me.ctrlMtoTipoCambio.Enabled = False
    Me.cmboperador.Enabled = False
    Call Me.habilita_btnbusqueda(False)
End Sub

Private Sub tmrHora_Timer()
'    lblhora.Caption = Hour(Time) & ":" & Minute(Time)
End Sub

Sub CargaDatos(StrTipoCambio As String, StrFecha As String, StrMonDesde As String, _
                StrMonHasta As String, dblMonto As Double, StrOPerador As String)
    Dim i As Integer
    
    Me.dtcTipoCambio.BoundText = StrTipoCambio
    Me.dtpFecha.Value = Format(StrFecha, "dd/MM/yyyy")
    Me.lblhora.Caption = IIf(Hour(StrFecha) = 0, "00", Hour(StrFecha)) & ":" & IIf(Minute(StrFecha) = 0, "00", Minute(StrFecha))
    Me.dtcMdaDesde.BoundText = StrMonDesde
    Me.dtcMdaHasta.BoundText = StrMonHasta
    Me.ctrlMtoTipoCambio.Text = Format(dblMonto, GMascara(2))
    For i = 0 To cmboperador.ListCount - 1
        If cmboperador.List(i) = StrOPerador Then
            cmboperador.ListIndex = i
            Exit For
        End If
    Next
End Sub

