VERSION 5.00
Object = "{F0D2F211-CCB0-11D0-A316-00AA00688B10}#1.0#0"; "MSDATLST.OCX"
Object = "{00025600-0000-0000-C000-000000000046}#5.2#0"; "crystl32.ocx"
Begin VB.Form FProveedor 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Proveedor (01.090.00)"
   ClientHeight    =   5850
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   7785
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MDIChild        =   -1  'True
   ScaleHeight     =   5850
   ScaleWidth      =   7785
   Begin Crystal.CrystalReport crProveedor 
      Left            =   6600
      Top             =   4200
      _ExtentX        =   741
      _ExtentY        =   741
      _Version        =   348160
      PrintFileLinesPerPage=   60
   End
   Begin VB.CommandButton cmdBusTipoImpuesto 
      Height          =   375
      Left            =   7320
      MouseIcon       =   "0109000.frx":0000
      MousePointer    =   99  'Custom
      Picture         =   "0109000.frx":0152
      Style           =   1  'Graphical
      TabIndex        =   44
      ToolTipText     =   "Buscar"
      Top             =   5280
      Width           =   375
   End
   Begin MSDataListLib.DataCombo dtcTipoImpuesto 
      Height          =   315
      Left            =   5040
      TabIndex        =   43
      Top             =   5280
      Width           =   2175
      _ExtentX        =   3836
      _ExtentY        =   556
      _Version        =   393216
      Style           =   2
      Text            =   ""
   End
   Begin VB.CommandButton cmdBusTTCambio 
      Height          =   375
      Left            =   3480
      Picture         =   "0109000.frx":0684
      Style           =   1  'Graphical
      TabIndex        =   24
      Top             =   5280
      Width           =   375
   End
   Begin MSDataListLib.DataCombo dtcTTCambio 
      Height          =   315
      Left            =   1200
      TabIndex        =   23
      Top             =   5280
      Width           =   2175
      _ExtentX        =   3836
      _ExtentY        =   556
      _Version        =   393216
      Style           =   2
      Text            =   ""
   End
   Begin VB.CommandButton cmdBusMoneda 
      Height          =   375
      Left            =   7320
      MouseIcon       =   "0109000.frx":0BB6
      MousePointer    =   99  'Custom
      Picture         =   "0109000.frx":0D08
      Style           =   1  'Graphical
      TabIndex        =   22
      ToolTipText     =   "Buscar"
      Top             =   4830
      Width           =   375
   End
   Begin MSDataListLib.DataCombo dtcTipoProveedor 
      Height          =   315
      Left            =   4800
      TabIndex        =   3
      Top             =   645
      Width           =   2415
      _ExtentX        =   4260
      _ExtentY        =   556
      _Version        =   393216
      Style           =   2
      Text            =   ""
   End
   Begin VB.CommandButton cmdBuscaCondPago 
      Height          =   375
      Left            =   3480
      Picture         =   "0109000.frx":123A
      Style           =   1  'Graphical
      TabIndex        =   20
      Top             =   4800
      Width           =   375
   End
   Begin VB.CommandButton cmdBuscaDistrito 
      Height          =   375
      Left            =   7320
      Picture         =   "0109000.frx":176C
      Style           =   1  'Graphical
      TabIndex        =   12
      Top             =   2600
      Width           =   375
   End
   Begin VB.CommandButton cmdBuscaPais 
      Height          =   375
      Left            =   3240
      Picture         =   "0109000.frx":1C9E
      Style           =   1  'Graphical
      TabIndex        =   10
      Top             =   2600
      Width           =   375
   End
   Begin VB.CommandButton cmdBuscaTipoProvee 
      Height          =   375
      Left            =   7320
      Picture         =   "0109000.frx":21D0
      Style           =   1  'Graphical
      TabIndex        =   4
      Top             =   640
      Width           =   375
   End
   Begin VB.CheckBox chkStatus 
      Alignment       =   1  'Right Justify
      Caption         =   "Status"
      Height          =   255
      Left            =   6240
      TabIndex        =   16
      Top             =   3480
      Width           =   975
   End
   Begin VB.TextBox txtRuc 
      Height          =   285
      Left            =   1200
      TabIndex        =   5
      Top             =   1018
      Width           =   1935
   End
   Begin VB.TextBox txtDescripcion 
      Height          =   285
      Left            =   1200
      MaxLength       =   50
      TabIndex        =   6
      Top             =   1395
      Width           =   3735
   End
   Begin VB.TextBox txtDireccion1 
      Height          =   285
      Left            =   1200
      MaxLength       =   50
      TabIndex        =   7
      Top             =   1800
      Width           =   4935
   End
   Begin VB.TextBox txtMail 
      Height          =   285
      Left            =   1200
      TabIndex        =   18
      Top             =   4320
      Width           =   4575
   End
   Begin VB.TextBox txtSolomon 
      Height          =   285
      Left            =   1200
      TabIndex        =   2
      Top             =   641
      Width           =   1575
   End
   Begin VB.TextBox txtFax 
      Height          =   285
      Left            =   1200
      MaxLength       =   10
      TabIndex        =   15
      Top             =   3435
      Width           =   1695
   End
   Begin VB.TextBox txtTelefono1 
      Height          =   285
      Left            =   1200
      MaxLength       =   10
      TabIndex        =   13
      Top             =   3030
      Width           =   1455
   End
   Begin VB.TextBox txtTelefono2 
      Height          =   285
      Left            =   4800
      MaxLength       =   10
      TabIndex        =   14
      Top             =   3000
      Width           =   1815
   End
   Begin VB.TextBox txtCodigo 
      Height          =   285
      Left            =   1200
      MaxLength       =   20
      TabIndex        =   0
      Top             =   240
      Width           =   1935
   End
   Begin VB.TextBox txtContacto 
      Height          =   285
      Left            =   1200
      TabIndex        =   17
      Top             =   3840
      Width           =   4575
   End
   Begin VB.TextBox txtDireccion2 
      Height          =   285
      Left            =   1200
      MaxLength       =   50
      TabIndex        =   8
      Top             =   2205
      Width           =   4935
   End
   Begin VB.CommandButton cmdBuscar 
      Enabled         =   0   'False
      Height          =   375
      Left            =   3240
      Picture         =   "0109000.frx":2702
      Style           =   1  'Graphical
      TabIndex        =   1
      Top             =   240
      Width           =   375
   End
   Begin MSDataListLib.DataCombo dtcDistrito 
      Height          =   315
      Left            =   4800
      TabIndex        =   11
      Top             =   2595
      Width           =   2415
      _ExtentX        =   4260
      _ExtentY        =   556
      _Version        =   393216
      Style           =   2
      Text            =   ""
   End
   Begin MSDataListLib.DataCombo dtcPais 
      Height          =   315
      Left            =   1200
      TabIndex        =   9
      Top             =   2595
      Width           =   1935
      _ExtentX        =   3413
      _ExtentY        =   556
      _Version        =   393216
      Style           =   2
      Text            =   ""
   End
   Begin MSDataListLib.DataCombo dtcCondPago 
      Height          =   315
      Left            =   1200
      TabIndex        =   19
      Top             =   4800
      Width           =   2175
      _ExtentX        =   3836
      _ExtentY        =   556
      _Version        =   393216
      Style           =   2
      Text            =   ""
   End
   Begin MSDataListLib.DataCombo dtcMoneda 
      Height          =   315
      Left            =   5040
      TabIndex        =   21
      Top             =   4830
      Width           =   2175
      _ExtentX        =   3836
      _ExtentY        =   556
      _Version        =   393216
      Style           =   2
      Text            =   ""
   End
   Begin VB.Image Image1 
      Height          =   630
      Left            =   6450
      Picture         =   "0109000.frx":2C34
      Stretch         =   -1  'True
      Top             =   1470
      Width           =   810
   End
   Begin VB.Label lblTipoImpuesto 
      Caption         =   "Tipo de Impuesto"
      Height          =   375
      Left            =   4200
      TabIndex        =   42
      Top             =   5280
      Width           =   735
   End
   Begin VB.Label lblTTCambio 
      Caption         =   "Clase de Tipo de Cambio"
      Height          =   495
      Left            =   120
      TabIndex        =   41
      Top             =   5280
      Width           =   975
   End
   Begin VB.Label lblMoneda 
      AutoSize        =   -1  'True
      Caption         =   "Moneda"
      Height          =   195
      Left            =   4200
      TabIndex        =   40
      Top             =   4800
      Width           =   585
   End
   Begin VB.Label lblRuc 
      AutoSize        =   -1  'True
      Caption         =   "RUC"
      Height          =   195
      Left            =   120
      TabIndex        =   39
      Top             =   1027
      Width           =   345
   End
   Begin VB.Label lblCondPago 
      AutoSize        =   -1  'True
      Caption         =   "Cond. Pago"
      Height          =   195
      Left            =   120
      TabIndex        =   38
      Top             =   4830
      Width           =   840
   End
   Begin VB.Label lblTipProveedor 
      AutoSize        =   -1  'True
      Caption         =   "Tip. Proveedor"
      Height          =   195
      Left            =   3600
      TabIndex        =   37
      Top             =   645
      Width           =   1050
   End
   Begin VB.Label lblMail 
      AutoSize        =   -1  'True
      Caption         =   "E- Mail"
      Height          =   195
      Left            =   120
      TabIndex        =   36
      Top             =   4320
      Width           =   480
   End
   Begin VB.Label lblDistrito 
      AutoSize        =   -1  'True
      Caption         =   "Distrito"
      Height          =   195
      Left            =   3960
      TabIndex        =   35
      Top             =   2640
      Width           =   480
   End
   Begin VB.Label lblSolomon 
      AutoSize        =   -1  'True
      Caption         =   "Cod. Solomon"
      Height          =   195
      Left            =   120
      TabIndex        =   34
      Top             =   645
      Width           =   990
   End
   Begin VB.Label lblDireccion1 
      AutoSize        =   -1  'True
      Caption         =   "Dirección 1"
      Height          =   195
      Left            =   120
      TabIndex        =   33
      Top             =   1815
      Width           =   810
   End
   Begin VB.Label lblNombre 
      AutoSize        =   -1  'True
      Caption         =   "Nombre"
      Height          =   195
      Left            =   120
      TabIndex        =   32
      Top             =   1410
      Width           =   555
   End
   Begin VB.Label lblCodigo 
      AutoSize        =   -1  'True
      Caption         =   "Código "
      Height          =   195
      Left            =   120
      TabIndex        =   31
      Top             =   240
      Width           =   540
   End
   Begin VB.Label lblFax 
      AutoSize        =   -1  'True
      Caption         =   "Fax"
      Height          =   195
      Left            =   120
      TabIndex        =   30
      Top             =   3435
      Width           =   255
   End
   Begin VB.Label lblTelefono1 
      AutoSize        =   -1  'True
      Caption         =   "Teléfono 1"
      Height          =   195
      Left            =   120
      TabIndex        =   29
      Top             =   3030
      Width           =   765
   End
   Begin VB.Label lblTelefono2 
      AutoSize        =   -1  'True
      Caption         =   "Teléfono 2"
      Height          =   195
      Left            =   3960
      TabIndex        =   28
      Top             =   3030
      Width           =   765
   End
   Begin VB.Label lblContacto 
      AutoSize        =   -1  'True
      Caption         =   "Contacto"
      Height          =   195
      Left            =   120
      TabIndex        =   27
      Top             =   3840
      Width           =   645
   End
   Begin VB.Label lblDireccion2 
      AutoSize        =   -1  'True
      Caption         =   "Dirección 2"
      Height          =   195
      Left            =   120
      TabIndex        =   26
      Top             =   2220
      Width           =   810
   End
   Begin VB.Label lblPais 
      AutoSize        =   -1  'True
      Caption         =   "País"
      Height          =   195
      Left            =   120
      TabIndex        =   25
      Top             =   2625
      Width           =   330
   End
End
Attribute VB_Name = "FProveedor"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False


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_proveedores As ADODB.Recordset
Public objProveedor  As DB_INV_MANTENIMIENTOS.C_PROVEEDOR
Public objTipoProveedor As DB_INV_MANTENIMIENTOS.C_TIPOPROVEEDOR
Public objPais As DB_MA_MANTENIMIENTOS.C_PAIS
Public objDistrito As DB_MA_MANTENIMIENTOS.C_DISTRITO
Public objCondPago As DB_MA_MANTENIMIENTOS.C_CONDICIONPAGO
Public objMoneda As DB_MA_MANTENIMIENTOS.C_MONEDA
Public objTTCambio As DB_MA_MANTENIMIENTOS.C_TDTDCAMBIO
Public objTipoImpuesto As DB_MA_MANTENIMIENTOS.C_TIPOIMPÙESTO

Private Sub chkStatus_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Then
        txtContacto.SetFocus
    End If
End Sub

Private Sub cmdBuscaCondPago_Click()
    'Lineas que llaman al Formulario de Búsqueda
    
    Dim ArrayBusqueda(1 To 2, 1 To 3) As Variant
    ArrayBusqueda(1, 1) = "Termid"
    ArrayBusqueda(1, 2) = "Código "
    ArrayBusqueda(1, 3) = 1000
    ArrayBusqueda(2, 1) = "descr"
    ArrayBusqueda(2, 2) = "Descripción "
    ArrayBusqueda(2, 3) = 4000
      
    FBusquedasMa.GObtenerRegistros objCondPago.ListarCondicionesPagoAyuda, ArrayBusqueda, 2, 2
    FBusquedasMa.Show vbModal
    
    If GrecibeUbicacion <> 0 Then
        dtcCondPago.BoundText = GrecibeColumnaID
    End If
End Sub

Private Sub cmdBuscaDistrito_Click()
    'Lineas que llaman al Formulario de Búsqueda
    
    Dim ArrayBusqueda(1 To 2, 1 To 3) As Variant
    ArrayBusqueda(1, 1) = "Cityid"
    ArrayBusqueda(1, 2) = "Código "
    ArrayBusqueda(1, 3) = 1000
    ArrayBusqueda(2, 1) = "descr"
    ArrayBusqueda(2, 2) = "Descripción "
    ArrayBusqueda(2, 3) = 4000
      
    FBusquedasMa.GObtenerRegistros objDistrito.ListarDistritos, ArrayBusqueda, 2, 2
    FBusquedasMa.Show vbModal
    
    If GrecibeUbicacion <> 0 Then
        dtcDistrito.BoundText = GrecibeColumnaID
    End If
End Sub

Private Sub cmdBuscaPais_Click()
    'Lineas que llaman al Formulario de Búsqueda
    
    Dim ArrayBusqueda(1 To 2, 1 To 3) As Variant
    ArrayBusqueda(1, 1) = "Countryid"
    ArrayBusqueda(1, 2) = "Código "
    ArrayBusqueda(1, 3) = 1000
    ArrayBusqueda(2, 1) = "descr"
    ArrayBusqueda(2, 2) = "Descripción "
    ArrayBusqueda(2, 3) = 4000
      
    FBusquedasMa.GObtenerRegistros objPais.ListarPaises, ArrayBusqueda, 2, 2
    FBusquedasMa.Show vbModal
    
    If GrecibeUbicacion <> 0 Then
        dtcPais.BoundText = GrecibeColumnaID
    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) = "Vendidss"
    ArrayBusqueda(1, 2) = "Código "
    ArrayBusqueda(1, 3) = 1200
    ArrayBusqueda(2, 1) = "descr"
    ArrayBusqueda(2, 2) = "Descripción "
    ArrayBusqueda(2, 3) = 4000
      
          
    FBusquedasMa.GObtenerRegistros objProveedor.ListarProveedoresAyuda, ArrayBusqueda, 2, 2
    FBusquedasMa.Show vbModal
    If GrecibeUbicacion <> 0 And GrecibeUbicacion <= rs_proveedores.RecordCount Then
          rs_proveedores.AbsolutePosition = GrecibeUbicacion
          asigna_campos
          Call gestadoactualrs(Me, rs_proveedores)
          Call gactualiza_barra(Me)
    End If
  
End Sub

Private Sub cmdBuscaTipoProvee_Click()
    'Lineas que llaman al Formulario de Búsqueda
    
    Dim ArrayBusqueda(1 To 2, 1 To 3) As Variant
    ArrayBusqueda(1, 1) = "ClassVendorid"
    ArrayBusqueda(1, 2) = "Código "
    ArrayBusqueda(1, 3) = 1000
    ArrayBusqueda(2, 1) = "descr"
    ArrayBusqueda(2, 2) = "Descripción "
    ArrayBusqueda(2, 3) = 4000
      
    FBusquedasMa.GObtenerRegistros objTipoProveedor.ListarTiposProveedores, ArrayBusqueda, 2, 2
    FBusquedasMa.Show vbModal
    
    If GrecibeUbicacion <> 0 Then
        dtcTipoProveedor.BoundText = GrecibeColumnaID
    End If
End Sub

Private Sub cmdBusMoneda_Click()
    'Lineas que llaman al Formulario de Búsqueda
     
     Dim ArrayBusqueda(1 To 2, 1 To 3) As Variant
     ArrayBusqueda(1, 1) = "CuryId"
     ArrayBusqueda(1, 2) = "Código "
     ArrayBusqueda(1, 3) = 1000
     ArrayBusqueda(2, 1) = "Descr"
     ArrayBusqueda(2, 2) = "Descripción "
     ArrayBusqueda(2, 3) = 4000
       
     FBusquedasMa.GObtenerRegistros objMoneda.ListarMonedas, ArrayBusqueda, 2, 2
     FBusquedasMa.Show vbModal
     
     If GrecibeUbicacion <> 0 Then
         dtcMoneda.BoundText = GrecibeColumnaID
     End If
End Sub


Private Sub cmdBusTipoImpuesto_Click()
  Dim LArrayBusqueda(1 To 3, 1 To 3) As Variant
  LArrayBusqueda(1, 1) = "Taxid"
  LArrayBusqueda(1, 2) = "Código"
  LArrayBusqueda(1, 3) = 1000
  LArrayBusqueda(2, 1) = "descr"
  LArrayBusqueda(2, 2) = "Descripción"
  LArrayBusqueda(2, 3) = 4000
  LArrayBusqueda(3, 1) = "Value"
  LArrayBusqueda(3, 2) = "Porcentaje"
  LArrayBusqueda(3, 3) = 2000
  
  GrecibeUbicacion = 0
  GrecibeColumnaID = Empty
  GrecibeColumnaOpcional = Empty
  
    
  FBusquedasMa.GObtenerRegistros objTipoImpuesto.ListarTiposImpuestos, LArrayBusqueda, 3, 2, 7800, , , , 3
  FBusquedasMa.Show vbModal
  
  If GrecibeUbicacion <> 0 Then
    dtcTipoImpuesto.BoundText = GrecibeColumnaID
  End If
End Sub

Private Sub cmdBusTTCambio_Click()
  Dim LArrayBusqueda(1 To 2, 1 To 3) As Variant
  LArrayBusqueda(1, 1) = "Curytypeid"
  LArrayBusqueda(1, 2) = "Código"
  LArrayBusqueda(1, 3) = 1000
  LArrayBusqueda(2, 1) = "descr"
  LArrayBusqueda(2, 2) = "Descripción"
  LArrayBusqueda(2, 3) = 4000
    
  GrecibeUbicacion = 0
  GrecibeColumnaID = Empty
  GrecibeColumnaOpcional = Empty

    
  FBusquedasMa.GObtenerRegistros objTTCambio.ListarTiposdeTipodeCambio, LArrayBusqueda, 2, 2
  FBusquedasMa.Show vbModal
  
  If GrecibeUbicacion <> 0 Then
    dtcTTCambio.BoundText = GrecibeColumnaID
  End If

End Sub

Private Sub dtcCondPago_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Then
        dtcMoneda.SetFocus
    End If
End Sub

Private Sub dtcDistrito_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Then
        txtTelefono1.SetFocus
    End If
End Sub

Private Sub dtcMoneda_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Then
        dtcTTCambio.SetFocus
    End If
End Sub

Private Sub dtcPais_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Then
        dtcDistrito.SetFocus
    End If
End Sub

Private Sub dtcTipoProveedor_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Then
        txtRuc.SetFocus
    End If
End Sub

Private Sub dtcTTCambio_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Then
        dtcTipoImpuesto.SetFocus
    End If
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()
    Call Gprimer_registro(Me, rs_proveedores)
    Call asigna_campos
End Sub

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

Public Sub registro_anterior()
    Call Gregistro_anterior(Me, rs_proveedores)
    Call asigna_campos
End Sub
Public Sub registro_siguiente()
    Call Gregistro_siguiente(Me, rs_proveedores)
    Call asigna_campos
End Sub
Private Sub Form_Initialize()
    Call gHabilitarReg(Me, False)
End Sub

Private Sub Form_Load()
    'seguridad
    Call gseguridad(Me)
    If pbderecho_consultar Then
        
        Set objProveedor = New DB_INV_MANTENIMIENTOS.C_PROVEEDOR
        Set objTipoProveedor = New DB_INV_MANTENIMIENTOS.C_TIPOPROVEEDOR
        Set objPais = New DB_MA_MANTENIMIENTOS.C_PAIS
        Set objDistrito = New DB_MA_MANTENIMIENTOS.C_DISTRITO
        Set objCondPago = New DB_MA_MANTENIMIENTOS.C_CONDICIONPAGO
        Set objMoneda = New DB_MA_MANTENIMIENTOS.C_MONEDA
        Set objTTCambio = New DB_MA_MANTENIMIENTOS.C_TDTDCAMBIO
        Set objTipoImpuesto = New DB_MA_MANTENIMIENTOS.C_TIPOIMPÙESTO
    
        Call obtener_datos
        Call CargaDataCombo(dtcTipoProveedor, objTipoProveedor.ListarTiposProveedores, "ClassVendorId", "Descr")
        Call CargaDataCombo(dtcPais, objPais.ListarPaises, "CountryId", "Descr")
        Call CargaDataCombo(dtcDistrito, objDistrito.ListarDistritos, "CityId", "Descr")
        Call CargaDataCombo(dtcCondPago, objCondPago.ListarCondicionesPagoAyuda, "TermId", "Descr")
        Call CargaDataCombo(dtcMoneda, objMoneda.ListarMonedas, "CuryId", "Descr")
        Call CargaDataCombo(dtcTTCambio, objTTCambio.ListarTiposdeTipodeCambio, "CuryTypeId", "Descr")
        Call CargaDataCombo(dtcTipoImpuesto, objTipoImpuesto.ListarTiposImpuestos, "TaxId", "Descr")
        Call asigna_campos
        
        pb_primerregistro = True
    'lineas nuevas
    Else
        'Unload Me
        MsgBox ("No tiene Derechos de Consultar en este formulario"), vbCritical + vbDefaultButton1, "Mensaje"
    End If
    
    Me.Top = 100
    Me.Left = (Screen.Width - Me.Width) / 2
    
End Sub
Public Sub borrar_registro()

On Error GoTo errhandler

    objProveedor.EliminarProveedor txtCodigo
    Call gborrar_Registro(Me, rs_proveedores, txtCodigo)
    
Exit Sub
errhandler:
    MsgBox MensajedeError(ERR.Number, ERR.Description), vbDefaultButton1 + vbCritical, "Error"
    
End Sub
Function valida_datos()
    If GVDATO(txtCodigo.Text) = Empty Then
        valida_datos = False
        MsgBox "Ingrese Código de Proveedor", vbInformation, "Error"
        txtCodigo.SetFocus
        Exit Function
    End If
    
    If GVDATO(txtSolomon.Text) = Empty Then
        valida_datos = False
        MsgBox "Ingrese Código Solomon para Proveedor", vbInformation, "Error"
        txtSolomon.SetFocus
        Exit Function
    End If
    
    If GVDATO(dtcTipoProveedor.Text) = Empty Then
        valida_datos = False
        MsgBox "Ingrese Tipo de Proveedor", vbInformation, "Error"
        dtcTipoProveedor.SetFocus
        Exit Function
    End If
    
    If GVDATO(Txtdescripcion.Text) = Empty Then
        valida_datos = False
        MsgBox "Ingrese Descripción de Proveedor", vbInformation, "Error"
        Txtdescripcion.SetFocus
        Exit Function
    End If

    If GVDATO(txtDireccion1.Text) = Empty Then
        valida_datos = False
        MsgBox "Ingrese Dirección1", vbInformation, "Error"
        txtDireccion1.SetFocus
        Exit Function
    End If
    
    If GVDATO(dtcPais.Text) = Empty Then
        valida_datos = False
        MsgBox "Ingrese País", vbInformation, "Error"
        dtcPais.SetFocus
        Exit Function
    End If

    If GVDATO(dtcDistrito.Text) = Empty Then
        valida_datos = False
        MsgBox "Ingrese Distrito", vbInformation, "Error"
        dtcDistrito.SetFocus
        Exit Function
    End If
    
    If GVDATO(dtcCondPago.Text) = Empty Then
        valida_datos = False
        MsgBox "Ingrese Condición de Pago", vbInformation, "Error"
        dtcCondPago.SetFocus
        Exit Function
    End If
    
    If GVDATO(dtcMoneda.Text) = Empty Then
        valida_datos = False
        MsgBox "Ingrese Moneda del Proveedor", vbInformation, "Error"
        dtcMoneda.SetFocus
        Exit Function
    End If
    
    If GVDATO(dtcTTCambio.Text) = Empty Then
        valida_datos = False
        MsgBox "Ingrese Clase de tipo de Cambio asociada al proveedor", vbInformation, "Error"
        dtcTTCambio.SetFocus
        Exit Function
    End If
    
    If GVDATO(dtcTipoImpuesto.Text) = Empty Then
        valida_datos = False
        MsgBox "Ingrese tipo de impuesto asociado al proveedor", vbInformation, "Error"
        dtcTipoImpuesto.SetFocus
        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
            objProveedor.AgregarProveedor Trim(txtCodigo), dtcDistrito.BoundText, dtcPais.BoundText, _
                                          dtcTipoProveedor.BoundText, dtcCondPago.BoundText, Trim(txtSolomon), _
                                          GVDATO(Txtdescripcion), Trim(txtContacto), Trim(txtRuc), Trim(txtDireccion1), Trim(txtDireccion2), _
                                          Trim(txtTelefono1), Trim(txtTelefono2), Trim(txtFax), Trim(txtMail), chkStatus.Value, 0, dtcMoneda.BoundText, _
                                          dtcTTCambio.BoundText, dtcTipoImpuesto.BoundText, GCUSERID
        Else
        
            objProveedor.ActualizarProveedor txtCodigo, dtcDistrito.BoundText, dtcPais.BoundText, _
                                          dtcTipoProveedor.BoundText, dtcCondPago.BoundText, Trim(txtSolomon), _
                                          GVDATO(Txtdescripcion), Trim(txtContacto), Trim(txtRuc), Trim(txtDireccion1), Trim(txtDireccion2), _
                                          Trim(txtTelefono1), Trim(txtTelefono2), Trim(txtFax), Trim(txtMail), chkStatus.Value, 0, dtcMoneda.BoundText, _
                                          dtcTTCambio.BoundText, dtcTipoImpuesto.BoundText
    
        End If
        Call ggrabar_registro(Me)
        actualizar_registro
    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
    'MsgBox ("Registros Actualizados")
End Sub
Public Sub agregar_registro()
    Call gagregar_registro(Me, txtCodigo)
End Sub
Public Sub modificar_registro()
    Call gmodificar_registro(Me, txtCodigo)
End Sub
Public Sub descartar_registro()
    ' Revertir cambios
    'adodc1.Recordset.CancelUpdate
    Call gdescartar_registro(Me)
    Call asigna_campos
End Sub

Sub obtener_datos()
    Set rs_proveedores = objProveedor.ListarProveedores
End Sub

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

Sub asigna_campos() ' falta decidir si va ha ser public o private
    If rs_proveedores.RecordCount <> 0 Then
        txtCodigo.Text = rs_proveedores!Vendidss
        dtcDistrito.BoundText = rs_proveedores!Cityid
        dtcPais.BoundText = rs_proveedores!Countryid
        dtcTipoProveedor.BoundText = rs_proveedores!ClassVendorid
        dtcCondPago.BoundText = rs_proveedores!TermId
        txtSolomon.Text = rs_proveedores!VendorId
        Txtdescripcion.Text = rs_proveedores!DESCR
        txtContacto.Text = GValidarNulos(rs_proveedores!Contact)
        txtRuc.Text = rs_proveedores!Taxregnbr
        txtDireccion1.Text = rs_proveedores!Addres
        txtDireccion2.Text = GValidarNulos(rs_proveedores!Addres2)
        txtTelefono1.Text = GValidarNulos(rs_proveedores!Fono1)
        txtTelefono2.Text = GValidarNulos(rs_proveedores!Fono2)
        txtFax.Text = GValidarNulos(rs_proveedores!Fax)
        txtMail.Text = GValidarNulos(rs_proveedores!Mail)
        chkStatus.Value = IIf(rs_proveedores!Status, 1, 0)
        dtcMoneda.BoundText = rs_proveedores!CURYID
        dtcTTCambio.BoundText = rs_proveedores!CURYTYPEID
        dtcTipoImpuesto.BoundText = rs_proveedores!TAXID
    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
        End If
    Else
        Call gdesactiva_barra
    End If
End Sub

Public Sub CargaDataCombo(objDataCombo As DataCombo, rsSource As ADODB.Recordset, istrCampo1 As String, istrCampo2 As String)
    If rsSource.RecordCount <> 0 Then
        Set objDataCombo.DataSource = rsSource
        objDataCombo.DataField = istrCampo2
        Set objDataCombo.RowSource = rsSource
        objDataCombo.ListField = istrCampo2
        objDataCombo.BoundColumn = istrCampo1
        objDataCombo.BoundText = rsSource.Fields(istrCampo2)
    End If
End Sub

Private Sub Form_Unload(Cancel As Integer)
    Set rs_proveedores = Nothing
    Set objTipoProveedor = Nothing
    Set objProveedor = Nothing
    Set objPais = Nothing
    Set objDistrito = Nothing
    Set objCondPago = Nothing
    Set objMoneda = Nothing
    Set objTTCambio = Nothing
    Set objTipoImpuesto = Nothing
End Sub
Private Sub txtCodigo_KeyPress(KeyAscii As Integer)
    KeyAscii = GBloqueaCaracter(KeyAscii)
    If KeyAscii = 13 Then
        txtSolomon.SetFocus
    End If
End Sub

Private Sub txtContacto_KeyPress(KeyAscii As Integer)
    KeyAscii = GBloqueaCaracter(KeyAscii)
    If KeyAscii = 13 Then
        txtMail.SetFocus
    End If
End Sub

Private Sub txtDescripcion_KeyPress(KeyAscii As Integer)
    KeyAscii = GBloqueaCaracter(KeyAscii)
    If KeyAscii = 13 Then
        txtDireccion1.SetFocus
    End If
End Sub

Private Sub txtDireccion1_KeyPress(KeyAscii As Integer)
    KeyAscii = GBloqueaCaracter(KeyAscii)
    If KeyAscii = 13 Then
        txtDireccion2.SetFocus
    End If
End Sub

Private Sub txtDireccion2_KeyPress(KeyAscii As Integer)
    KeyAscii = GBloqueaCaracter(KeyAscii)
    If KeyAscii = 13 Then
        dtcPais.SetFocus
    End If
End Sub
Private Sub txtFax_KeyPress(KeyAscii As Integer)
    KeyAscii = MValidaNumeros(KeyAscii)
    If KeyAscii = 13 Then
        chkStatus.SetFocus
    End If
End Sub

Private Sub txtMail_KeyPress(KeyAscii As Integer)
    If KeyAscii = 39 Or KeyAscii = 124 Then
        KeyAscii = 0
    End If
    If KeyAscii = 13 Then
        dtcCondPago.SetFocus
    End If
End Sub

Private Sub txtRuc_KeyPress(KeyAscii As Integer)
    KeyAscii = GBloqueaCaracter(KeyAscii)
    If KeyAscii = 13 Then
        Txtdescripcion.SetFocus
    End If
End Sub

Private Sub txtSolomon_KeyPress(KeyAscii As Integer)
    KeyAscii = GBloqueaCaracter(KeyAscii)
    If KeyAscii = 13 Then
        dtcTipoProveedor.SetFocus
    End If
End Sub

Private Sub txtTelefono1_KeyPress(KeyAscii As Integer)
    KeyAscii = MValidaNumeros(KeyAscii)
    If KeyAscii = 13 Then
        txtTelefono2.SetFocus
    End If
End Sub

Private Function MValidaNumeros(KeyAscii As Integer) As Integer
    If (KeyAscii >= 48 And KeyAscii <= 57) Or KeyAscii = 13 Or KeyAscii = 8 Then
        MValidaNumeros = KeyAscii
    Else
        MValidaNumeros = 0
    End If
End Function

Sub imprimir()
 
    crProveedor.ReportFileName = GstrReportesInv + "rpt_Proveedor.rpt"
    crProveedor.WindowTitle = "Reporte de Proveedores"
    crProveedor.Formulas(1) = "formusuario=stringvar strusuario; strusuario:='" & GCUSERID & "'"
    crProveedor.Formulas(2) = "formscreen=stringvar strscreen; strscreen:='01.090.00'"
    crProveedor.WindowState = crptMaximized
    crProveedor.WindowShowPrintSetupBtn = True
    crProveedor.Action = 1
  
End Sub

Private Sub txtTelefono2_KeyPress(KeyAscii As Integer)
    KeyAscii = MValidaNumeros(KeyAscii)
    If KeyAscii = 13 Then
        txtFax.SetFocus
    End If
End Sub
