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 FAlmacen 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Almacen (01.080.00)"
   ClientHeight    =   4095
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   5535
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MDIChild        =   -1  'True
   ScaleHeight     =   4095
   ScaleWidth      =   5535
   Begin Crystal.CrystalReport cralmacenes 
      Left            =   4560
      Top             =   2160
      _ExtentX        =   741
      _ExtentY        =   741
      _Version        =   348160
      PrintFileLinesPerPage=   60
   End
   Begin VB.TextBox txtFax 
      Height          =   285
      Left            =   1320
      MaxLength       =   10
      TabIndex        =   11
      Top             =   3200
      Width           =   1455
   End
   Begin VB.TextBox txtTelefono2 
      Height          =   285
      Left            =   3960
      MaxLength       =   10
      TabIndex        =   10
      Top             =   2800
      Width           =   1455
   End
   Begin VB.TextBox txtTelefono1 
      Height          =   285
      Left            =   1320
      MaxLength       =   10
      TabIndex        =   9
      Top             =   2800
      Width           =   1455
   End
   Begin VB.CheckBox chkStatus 
      Alignment       =   1  'Right Justify
      Caption         =   "Status"
      Height          =   255
      Left            =   4320
      TabIndex        =   12
      Top             =   3240
      Width           =   855
   End
   Begin VB.CommandButton cmdBuscaPais 
      Height          =   375
      Left            =   3120
      Picture         =   "0108000.frx":0000
      Style           =   1  'Graphical
      TabIndex        =   6
      Top             =   1950
      Width           =   375
   End
   Begin MSDataListLib.DataCombo dtcDistrito 
      Height          =   315
      Left            =   1320
      TabIndex        =   7
      Top             =   2370
      Width           =   1695
      _ExtentX        =   2990
      _ExtentY        =   556
      _Version        =   393216
      Style           =   2
      Text            =   ""
   End
   Begin MSDataListLib.DataCombo dtcPais 
      Height          =   315
      Left            =   1320
      TabIndex        =   5
      Top             =   1930
      Width           =   1695
      _ExtentX        =   2990
      _ExtentY        =   556
      _Version        =   393216
      Style           =   2
      Text            =   ""
   End
   Begin VB.CommandButton cmdBuscaDistrito 
      Height          =   375
      Left            =   3120
      Picture         =   "0108000.frx":0532
      Style           =   1  'Graphical
      TabIndex        =   8
      Top             =   2370
      Width           =   375
   End
   Begin VB.CommandButton cmdBuscar 
      Enabled         =   0   'False
      Height          =   375
      Left            =   2400
      Picture         =   "0108000.frx":0A64
      Style           =   1  'Graphical
      TabIndex        =   1
      Top             =   240
      Width           =   375
   End
   Begin VB.TextBox txtDireccion2 
      Height          =   285
      Left            =   1320
      MaxLength       =   50
      TabIndex        =   4
      Top             =   1560
      Width           =   3975
   End
   Begin VB.TextBox txtResponsable 
      Height          =   285
      Left            =   1320
      TabIndex        =   13
      Top             =   3600
      Width           =   3975
   End
   Begin VB.TextBox txtcodigo 
      Height          =   285
      Left            =   1320
      MaxLength       =   5
      TabIndex        =   0
      Top             =   240
      Width           =   975
   End
   Begin VB.TextBox txtDescripcion 
      Height          =   285
      Left            =   1320
      MaxLength       =   50
      TabIndex        =   2
      Top             =   750
      Width           =   3135
   End
   Begin VB.TextBox txtDireccion1 
      Height          =   285
      Left            =   1320
      MaxLength       =   50
      TabIndex        =   3
      Top             =   1155
      Width           =   3975
   End
   Begin VB.Image Image1 
      Height          =   630
      Left            =   4590
      Picture         =   "0108000.frx":0F96
      Stretch         =   -1  'True
      Top             =   300
      Width           =   585
   End
   Begin VB.Label lblDistrito 
      AutoSize        =   -1  'True
      Caption         =   "Distrito"
      Height          =   195
      Left            =   240
      TabIndex        =   23
      Top             =   2385
      Width           =   480
   End
   Begin VB.Label lblPais 
      AutoSize        =   -1  'True
      Caption         =   "País"
      Height          =   195
      Left            =   240
      TabIndex        =   22
      Top             =   1980
      Width           =   330
   End
   Begin VB.Label lblDireccion2 
      AutoSize        =   -1  'True
      Caption         =   "Dirección 2"
      Height          =   195
      Left            =   240
      TabIndex        =   21
      Top             =   1575
      Width           =   810
   End
   Begin VB.Label lblResponsable 
      AutoSize        =   -1  'True
      Caption         =   "Responsable :"
      Height          =   195
      Left            =   240
      TabIndex        =   20
      Top             =   3600
      Width           =   1020
   End
   Begin VB.Label lblTelefono2 
      AutoSize        =   -1  'True
      Caption         =   "Teléfono 2"
      Height          =   195
      Left            =   3000
      TabIndex        =   19
      Top             =   2790
      Width           =   765
   End
   Begin VB.Label lblTelefono1 
      AutoSize        =   -1  'True
      Caption         =   "Teléfono 1"
      Height          =   195
      Left            =   240
      TabIndex        =   18
      Top             =   2790
      Width           =   765
   End
   Begin VB.Label lblFax 
      AutoSize        =   -1  'True
      Caption         =   "Fax"
      Height          =   195
      Left            =   240
      TabIndex        =   17
      Top             =   3195
      Width           =   255
   End
   Begin VB.Label lblCodigo 
      AutoSize        =   -1  'True
      Caption         =   "Código :"
      Height          =   195
      Left            =   240
      TabIndex        =   16
      Top             =   240
      Width           =   585
   End
   Begin VB.Label lblNombre 
      AutoSize        =   -1  'True
      Caption         =   "Nombre"
      Height          =   195
      Left            =   240
      TabIndex        =   15
      Top             =   765
      Width           =   555
   End
   Begin VB.Label lblDireccion1 
      AutoSize        =   -1  'True
      Caption         =   "Dirección 1"
      Height          =   195
      Left            =   240
      TabIndex        =   14
      Top             =   1170
      Width           =   810
   End
End
Attribute VB_Name = "FAlmacen"
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_Almacenes As ADODB.Recordset
Public objAlmacen As DB_INV_MANTENIMIENTOS.C_ALMACEN
Public objPais As DB_MA_MANTENIMIENTOS.C_PAIS
Public objDistrito As DB_MA_MANTENIMIENTOS.C_DISTRITO

Private Sub chkStatus_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Then
        txtResponsable.SetFocus
    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) = "siteid"
    ArrayBusqueda(1, 2) = "Código "
    ArrayBusqueda(1, 3) = 1000
    ArrayBusqueda(2, 1) = "Name"
    ArrayBusqueda(2, 2) = "Descripción "
    ArrayBusqueda(2, 3) = 4000
      
          
    FBusquedasMa.GObtenerRegistros objAlmacen.ListarAlmacenesAyuda, ArrayBusqueda, 2, 2
    FBusquedasMa.Show vbModal
    If GrecibeUbicacion <> 0 And GrecibeUbicacion <= rs_Almacenes.RecordCount Then
        rs_Almacenes.AbsolutePosition = GrecibeUbicacion
        asigna_campos
        Call gestadoactualrs(Me, rs_Almacenes)
        Call gactualiza_barra(Me)
    End If

End Sub

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

Private Sub dtcPais_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Then
        dtcDistrito.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_Almacenes)
    Call asigna_campos
End Sub

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

Public Sub registro_anterior()
    Call Gregistro_anterior(Me, rs_Almacenes)
    Call asigna_campos
End Sub
Public Sub registro_siguiente()
    Call Gregistro_siguiente(Me, rs_Almacenes)
    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
        Dim numreg As Long
        Set objAlmacen = New DB_INV_MANTENIMIENTOS.C_ALMACEN
        Set objPais = New DB_MA_MANTENIMIENTOS.C_PAIS
        Set objDistrito = New DB_MA_MANTENIMIENTOS.C_DISTRITO
        Call obtener_datos
        Call GCargaDataCombo(dtcPais, objPais.ListarPaises, "Countryid", "descr")
        Call GCargaDataCombo(dtcDistrito, objDistrito.ListarDistritos, "Cityid", "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
    objAlmacen.EliminarAlmacen txtcodigo
    Call gborrar_Registro(Me, rs_Almacenes, txtcodigo)
Exit Sub
errhandler:
    MsgBox MensajedeError(ERR.Number, ERR.Description), vbDefaultButton1 + vbCritical, "Advertencia"
    
End Sub
Function valida_datos()
    If GVDATO(txtcodigo.Text) = Empty Then
        valida_datos = False
        MsgBox "Ingrese Código de Almacén", vbInformation, "Error"
        txtcodigo.SetFocus
        Exit Function
    End If
    
    If GVDATO(txtDescripcion.Text) = Empty Then
        valida_datos = False
        MsgBox "Ingrese Descripción del Almacén", 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(txtResponsable.Text) = Empty Then
        valida_datos = False
        MsgBox "Ingrese Responsable", vbInformation, "Error"
        txtResponsable.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
            objAlmacen.AgregarAlmacen Trim(txtcodigo), Trim(txtDescripcion), Trim(txtDireccion1), _
                                      Trim(txtDireccion2), dtcDistrito.BoundText, dtcPais.BoundText, _
                                      Trim(txtTelefono1), Trim(txtTelefono2), Trim(txtFax), IIf(chkStatus.Value, 1, 0), _
                                      "01/01/1900", "01/01/1900", "0", Trim(txtResponsable), GCUSERID
        Else
            objAlmacen.ActualizarAlmacen txtcodigo, Trim(txtDescripcion), Trim(txtDireccion1), _
                                      Trim(txtDireccion2), dtcDistrito.BoundText, dtcPais.BoundText, _
                                      Trim(txtTelefono1), Trim(txtTelefono2), Trim(txtFax), IIf(chkStatus.Value, 1, 0), _
                                      GValidarNulos(rs_Almacenes!StartDateInven), GValidarNulos(rs_Almacenes!EndDateInven), GValidarNulos(rs_Almacenes!Adjust), Trim(txtResponsable), GCUSERID
        End If
        Call ggrabar_registro(Me)
        actualizar_registro
    End If
    
Exit Sub
errhandler:
    MsgBox MensajedeError(ERR.Number, ERR.Description), vbDefaultButton1 + vbCritical, "Advertencia"
    
End Sub
Public Sub actualizar_registro()
    'llamar al procedimiento de carga
    Call obtener_datos
    Call asigna_campos
    MsgBox ("Registros Actualizados"), vbDefaultButton1 + vbInformation, "Mensaje"
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_Almacenes = objAlmacen.ListarAlmacenes
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_Almacenes.RecordCount <> 0 Then
        txtcodigo.Text = rs_Almacenes!SITEID
        txtDescripcion.Text = rs_Almacenes!Name
        txtDireccion1.Text = rs_Almacenes!Addr1
        txtDireccion2.Text = GValidarNulos(rs_Almacenes!Addr2)
        dtcPais.BoundText = rs_Almacenes!Countryid
        dtcDistrito.BoundText = rs_Almacenes!Cityid
        txtTelefono1.Text = GValidarNulos(rs_Almacenes!Fono1)
        txtTelefono2.Text = GValidarNulos(rs_Almacenes!Fono2)
        txtFax.Text = GValidarNulos(rs_Almacenes!Fax)
        chkStatus.Value = IIf(rs_Almacenes!Status, 1, 0)
        txtResponsable.Text = rs_Almacenes!ATTN
    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 GCargaDataCombo(objDataCombo As DataCombo, rsSource As 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 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

Private Sub txtCodigo_KeyPress(KeyAscii As Integer)
    KeyAscii = GBloqueaCaracter(KeyAscii)
    If KeyAscii = 13 Then
        txtDescripcion.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 txtResponsable_KeyPress(KeyAscii As Integer)
    KeyAscii = GBloqueaCaracter(KeyAscii)
End Sub

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

Private Sub txtTelefono2_KeyPress(KeyAscii As Integer)
    KeyAscii = MValidaNumeros(KeyAscii)
    If KeyAscii = 13 Then
        txtFax.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

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