VERSION 5.00
Object = "{86CF1D34-0C5F-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCT2.OCX"
Object = "{F0D2F211-CCB0-11D0-A316-00AA00688B10}#1.0#0"; "MSDATLST.OCX"
Object = "{CDE57A40-8B86-11D0-B3C6-00A0C90AEA82}#1.0#0"; "MSDATGRD.OCX"
Object = "{00025600-0000-0000-C000-000000000046}#5.2#0"; "crystl32.ocx"
Object = "{69F9D01E-F1DE-11D4-9536-002018603DA2}#7.0#0"; "ControlNumber.ocx"
Begin VB.Form FCtrlPreciosCompetencia 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Control de Precios de la Competencia (05.058.00)"
   ClientHeight    =   5670
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   6375
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MDIChild        =   -1  'True
   ScaleHeight     =   5670
   ScaleWidth      =   6375
   Begin MiControl.CtrlNumber ctnPrecio 
      Height          =   330
      Left            =   4725
      TabIndex        =   7
      Top             =   5220
      Width           =   1500
      _ExtentX        =   2646
      _ExtentY        =   582
      BackColor       =   -2147483643
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
   End
   Begin VB.CommandButton cmdBusCompetencia 
      Enabled         =   0   'False
      Height          =   375
      Left            =   4950
      MouseIcon       =   "0505800.frx":0000
      MousePointer    =   99  'Custom
      Picture         =   "0505800.frx":0152
      Style           =   1  'Graphical
      TabIndex        =   3
      ToolTipText     =   "Buscar Competencia"
      Top             =   765
      Width           =   375
   End
   Begin MSDataListLib.DataCombo dtcCompetencia 
      Height          =   315
      Left            =   1305
      TabIndex        =   2
      Top             =   765
      Width           =   3570
      _ExtentX        =   6297
      _ExtentY        =   556
      _Version        =   393216
      Enabled         =   0   'False
      Style           =   2
      Text            =   ""
   End
   Begin VB.CommandButton cmdConfirmar 
      Caption         =   "Confirmar"
      Enabled         =   0   'False
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   12
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   2745
      TabIndex        =   5
      Top             =   1260
      Width           =   1500
   End
   Begin VB.CommandButton cmdBuscar 
      Height          =   465
      Left            =   5625
      MouseIcon       =   "0505800.frx":0684
      MousePointer    =   99  'Custom
      Picture         =   "0505800.frx":07D6
      Style           =   1  'Graphical
      TabIndex        =   8
      ToolTipText     =   "Buscar Registro de Control de Precios de Competencia"
      Top             =   180
      Width           =   645
   End
   Begin VB.CommandButton cmdBusAlmacen 
      Enabled         =   0   'False
      Height          =   375
      Left            =   4950
      MouseIcon       =   "0505800.frx":0D08
      MousePointer    =   99  'Custom
      Picture         =   "0505800.frx":0E5A
      Style           =   1  'Graphical
      TabIndex        =   1
      ToolTipText     =   "Buscar Almacén"
      Top             =   315
      Width           =   375
   End
   Begin Crystal.CrystalReport crContometro 
      Left            =   2610
      Top             =   855
      _ExtentX        =   741
      _ExtentY        =   741
      _Version        =   348160
      PrintFileLinesPerPage=   60
   End
   Begin MSDataGridLib.DataGrid DBDetalle 
      Height          =   3165
      Left            =   135
      TabIndex        =   6
      Top             =   1980
      Width           =   6120
      _ExtentX        =   10795
      _ExtentY        =   5583
      _Version        =   393216
      BackColor       =   16777152
      ForeColor       =   0
      HeadLines       =   1
      RowHeight       =   15
      BeginProperty HeadFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Caption         =   "Seleccione y presione Enter para editar el precio"
      ColumnCount     =   2
      BeginProperty Column00 
         DataField       =   ""
         Caption         =   ""
         BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
            Type            =   0
            Format          =   ""
            HaveTrueFalseNull=   0
            FirstDayOfWeek  =   0
            FirstWeekOfYear =   0
            LCID            =   10250
            SubFormatType   =   0
         EndProperty
      EndProperty
      BeginProperty Column01 
         DataField       =   ""
         Caption         =   ""
         BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
            Type            =   0
            Format          =   ""
            HaveTrueFalseNull=   0
            FirstDayOfWeek  =   0
            FirstWeekOfYear =   0
            LCID            =   10250
            SubFormatType   =   0
         EndProperty
      EndProperty
      SplitCount      =   1
      BeginProperty Split0 
         BeginProperty Column00 
         EndProperty
         BeginProperty Column01 
         EndProperty
      EndProperty
   End
   Begin MSDataListLib.DataCombo dtcAlmacen 
      Height          =   315
      Left            =   1305
      TabIndex        =   0
      Top             =   330
      Width           =   3600
      _ExtentX        =   6350
      _ExtentY        =   556
      _Version        =   393216
      Enabled         =   0   'False
      Style           =   2
      Text            =   ""
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
   End
   Begin MSComCtl2.DTPicker dtpFechaProc 
      Height          =   315
      Left            =   1305
      TabIndex        =   4
      Top             =   1260
      Width           =   1335
      _ExtentX        =   2355
      _ExtentY        =   556
      _Version        =   393216
      Enabled         =   0   'False
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      CalendarBackColor=   16777152
      Format          =   48627713
      CurrentDate     =   37567
   End
   Begin VB.Label lblPrecio 
      Caption         =   "PRECIO :"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   9.75
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   285
      Left            =   3510
      TabIndex        =   12
      Top             =   5220
      Width           =   1140
   End
   Begin VB.Label lblCompetencia 
      Caption         =   "Competencia"
      Height          =   285
      Left            =   315
      TabIndex        =   11
      Top             =   765
      Width           =   960
   End
   Begin VB.Label lblAlmacen 
      AutoSize        =   -1  'True
      Caption         =   "Almacen"
      Height          =   195
      Left            =   330
      TabIndex        =   10
      Top             =   330
      Width           =   615
   End
   Begin VB.Label lblFechaInicio 
      Caption         =   "Fecha Proceso"
      Height          =   435
      Left            =   360
      TabIndex        =   9
      Top             =   1215
      Width           =   720
   End
   Begin VB.Shape Shape1 
      Height          =   1770
      Left            =   135
      Top             =   90
      Width           =   5385
   End
   Begin VB.Image Image1 
      Height          =   465
      Left            =   4905
      Picture         =   "0505800.frx":138C
      Stretch         =   -1  'True
      Top             =   1305
      Width           =   465
   End
End
Attribute VB_Name = "FCtrlPreciosCompetencia"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
' Programador: Edgar Cancho Ruiz
' Empresa Texaco
' Modulo de Registro de Control de Precios de Competencia


Option Explicit

'*************************************
'Variables para el Control de la Barra General
 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
'*******************************************************************************************************************
' Variables para las ayudas
Public GrecibeUbicacion As BookmarkEnum
Public GrecibeColumnaID As String
Public GrecibeColumnaOpcional As String
Public GrecibeColumnaOpcional2 As String
Public GrecibeColumnaOpcional3 As String
'*************************************
' Objetos para cargar las ayudas

Private objAlmacen As DB_INV_MANTENIMIENTOS.C_ALMACEN
Private ObjCtrlPrecios As DB_OP_MANTENIMIENTOS.C_PRECIOS_COMP

Private objCompetencias As DB_MA_MANTENIMIENTOS.C_COMPETITION

'*******************************************************************************

Dim objCorrelativo As DB_CORRELATIVO.C_Correlativos

Dim lngCorrelativo As Long 'correlativo por usuario, que se almacenara en cada insert en temporal
Dim lngNumeroContometro As Long  'almacenara el correlativo del contómetro de precio obtenido de In_Setup
Dim lngSecuencia As Long ' guardara el número de Item del detalle


Dim blnModificando As Boolean ' flag para controlar la modificación de un registro
Dim blnEditando As Boolean ' flag para controlar si se esta editando un registro
Dim intCancelar As Integer
Dim blnDatosOK As Boolean
Dim intErr As Integer

Public Sub actualizar_registro()
End Sub


Private Sub cmdBusAlmacen_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
      
    FBusquedasVta.GObtenerRegistros objAlmacen.ListarAlmacenesPorStatus(1), ArrayBusqueda, 2, 2
    FBusquedasVta.Show vbModal
    
    If GrecibeUbicacion <> 0 Then
        dtcAlmacen.BoundText = GrecibeColumnaID
    End If
End Sub

Private Sub cmdBuscar_Click()
    FBuscarPreciosComp.Show vbModal
End Sub

Private Sub cancelarIngreso()
        blnEditando = False
        
        Call Limpiar
        Call HabilitaCampos(False)
        Call HabilitaBotones(True)

End Sub

Private Sub cmdImprimir_Click()
    'Call Imprimir_Reporte
End Sub

Private Sub Nuevo_Registro()
    blnEditando = True
        
    Call HabilitaCampos(True)
    Call HabilitaBotones(False)
    Call Limpiar
    
    'dtcAlmacen.SetFocus
End Sub

Private Sub Salir()
    Unload Me
End Sub

Public Sub CargaDatos(strSITEID As String, datFECHA As Date, strCOMPETENCIA As String)
On Error GoTo trataerror
    Call Limpiar
    
    dtcAlmacen.BoundText = strSITEID
    dtpFechaProc.Value = datFECHA
    dtcCompetencia.BoundText = strCOMPETENCIA


    ' CARGO EL GRID
    Set DBDetalle.DataSource = ObjCtrlPrecios.SeleccionaEnOriginal(strSITEID, datFECHA, strCOMPETENCIA)
    Call FormatoGrilla
    DBDetalle.Refresh
    
    Exit Sub
    
trataerror:
    Call Limpiar
    MsgBox "Nro de Ingreso no Registrado en Almacen Seleccionado", vbExclamation, "Error en Consulta"
End Sub



Private Sub cmdBusCompetencia_Click()
    'Lineas que llaman al Formulario de Búsqueda
    
    Dim ArrayBusqueda(1 To 2, 1 To 3) As Variant
    ArrayBusqueda(1, 1) = "COMPETITIONID"
    ArrayBusqueda(1, 2) = "Código "
    ArrayBusqueda(1, 3) = 1000
    ArrayBusqueda(2, 1) = "COMPETITIONNAME"
    ArrayBusqueda(2, 2) = "Descripción "
    ArrayBusqueda(2, 3) = 4000
      
    FBusquedasVta.GObtenerRegistros objCompetencias.ListarCompetencias, ArrayBusqueda, 2, 2
    FBusquedasVta.Show vbModal
    
    If GrecibeUbicacion <> 0 Then
        dtcCompetencia.BoundText = GrecibeColumnaID
    End If
End Sub

Private Sub cmdConfirmar_Click()
On Error GoTo trataerror
    If GVDATO(dtcCompetencia.BoundText) = Empty Then
        MsgBox "Ingrese Competencia", vbExclamation, "Mensaje"
        Exit Sub
    End If
    
    If ObjCtrlPrecios.ExisteRegistro(dtcAlmacen.BoundText, dtpFechaProc.Value, dtcCompetencia.BoundText) Then
        MsgBox "Ya existen datos para esta Estación en la fecha seleccionada ", vbExclamation, "Mensaje"
        Exit Sub
    End If

    Screen.MousePointer = 11
    lngCorrelativo = objCorrelativo.ObtenerCorrelativo(GCUSERID)
    ObjCtrlPrecios.AgregaAlTemporal lngCorrelativo, dtcAlmacen.BoundText, dtpFechaProc.Value, dtcCompetencia.BoundText
    CargaGrid lngCorrelativo
    cmdConfirmar.Enabled = False
    dtcAlmacen.Enabled = False
    cmdBusAlmacen.Enabled = False
    dtpFechaProc.Enabled = False
    dtcCompetencia.Enabled = False
    cmdBusCompetencia.Enabled = False
    Screen.MousePointer = 0
    Exit Sub
trataerror:
    Screen.MousePointer = 0
End Sub

Private Sub ctnPrecio_GotFocus()
    ctnPrecio.BackColor = GC_ColorEnfoque
End Sub

Private Sub ctnPrecio_KeyPress(KeyAscii As Integer)
On Error GoTo errhandler
    If KeyAscii = 13 Then
        If DBDetalle.Bookmark <> 0 Or Not IsNull(DBDetalle.Bookmark) Then
            ObjCtrlPrecios.ActualizaTemporal lngCorrelativo, dtcAlmacen.BoundText, dtpFechaProc.Value, _
                                            dtcCompetencia.BoundText, DBDetalle.Columns(0).Text, GFormatodeNumero(CDbl(ctnPrecio.Text), GintDecPrecio)
            CargaGrid lngCorrelativo
        End If
    End If

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

Private Sub ctnPrecio_LostFocus()
    ctnPrecio.BackColor = GC_ColorDefecto
End Sub

Private Sub DBDetalle_KeyUp(KeyCode As Integer, Shift As Integer)
If pb_editar Then ' si se esta editando
    If KeyCode = 13 Then
        ctnPrecio.SetFocus
    End If
End If
End Sub

Private Sub DBDetalle_RowColChange(LastRow As Variant, ByVal LastCol As Integer)
On Error Resume Next
    ctnPrecio.Text = DBDetalle.Columns(2).Text
End Sub

Private Sub dtcAlmacen_GotFocus()
dtcAlmacen.BackColor = GC_ColorEnfoque
End Sub

Private Sub dtcAlmacen_LostFocus()
dtcAlmacen.BackColor = GC_ColorDefecto
End Sub

Private Sub Form_Activate()

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

End Sub

Private Sub Form_Load()
Screen.MousePointer = 11
 '********************************************************************************
 'Código que se Tiene que Copiar para Invocar a la Rutina de Seguridad para poder
  Call gseguridad(Me)
  If pbderecho_consultar Then
         Call InstanciaObjetos
         Call CargaGrid(-1)

         dtpFechaProc.Value = Now

         Call HabilitaCampos(False)
         Call HabilitaBotones(True)
         Call LlenaDataCombos
         intErr = 0
        
  Else
     MsgBox ("No tiene Derechos de Consultar en este formulario"), vbCritical + vbDefaultButton1, "Mensaje"
     Screen.MousePointer = 0
     Exit Sub
  End If
 '********************************************************************************
        Me.Top = 100
        Me.Left = (Screen.Width - Me.Width) / 2
        ctnPrecio.Enteros = 4
        ctnPrecio.Decimales = GintDecPrecio
        ctnPrecio.ValorPorDefecto
        ctnPrecio.Enabled = False
Screen.MousePointer = 0
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    If blnEditando Then
        If MsgBox("Desea Salir y Cancelar el registro de Contómetro actual? ", vbQuestion + vbYesNo, "Salir") = vbNo Then
            Cancel = 1
        Else
            Cancel = 0
            blnEditando = False
            pb_agregar = False
            pb_editar = False
            Call gdesactiva_barra
        End If
    Else
        pb_editar = False
        Call gdesactiva_barra
    End If
End Sub

Private Sub Form_Unload(Cancel As Integer)
    Call DestruyeObjetos
End Sub

' Procedimiento para cargar DataCombos
Public Sub CargaDataCombo(objDataCombo As DataCombo, rsSource As Recordset, istrCampo1 As String, istrCampo2 As String)

    Set objDataCombo.DataSource = rsSource
    objDataCombo.DataField = istrCampo2
    Set objDataCombo.RowSource = rsSource
    objDataCombo.ListField = istrCampo2
    objDataCombo.BoundColumn = istrCampo1
    
    If Not rsSource.EOF Then
        objDataCombo.BoundText = rsSource.Fields(istrCampo2)
    End If

End Sub

' Procedimiento de carga de los DataCombos del formulario
Private Sub LlenaDataCombos()
    Call CargaDataCombo(dtcAlmacen, objAlmacen.ListarAlmacenesPorStatus(1), "SiteId", "Name")
    Call CargaDataCombo(dtcCompetencia, objCompetencias.ListarCompetencias, "COMPETITIONID", "COMPETITIONNAME")
End Sub

Private Sub InstanciaObjetos()
    Set ObjCtrlPrecios = New DB_OP_MANTENIMIENTOS.C_PRECIOS_COMP
    Set objAlmacen = New DB_INV_MANTENIMIENTOS.C_ALMACEN
    Set objCorrelativo = New DB_CORRELATIVO.C_Correlativos
    Set objCompetencias = New DB_MA_MANTENIMIENTOS.C_COMPETITION
End Sub

Private Sub DestruyeObjetos()
    Set ObjCtrlPrecios = Nothing
    Set objAlmacen = Nothing
    Set objCorrelativo = Nothing
    Set objCompetencias = Nothing
End Sub

Private Sub HabilitaCampos(blnValor As Boolean)
    ctnPrecio.Enabled = blnValor
End Sub

Private Sub HabilitaBotones(blnValor As Boolean)
'    If blnValor Then
'
'        cmdImprimir.Enabled = pbderecho_imprimir
'
'    Else
'
'        cmdImprimir.Enabled = blnValor
'
'    End If
End Sub
Private Sub Limpiar()
'funcionabilidad    : pone en blanco todos los controles de un formulario

Dim curcontrol As Control
    With Me
    For Each curcontrol In .Controls
        If TypeOf curcontrol Is TextBox Then
                curcontrol.Text = ""
        End If
         If TypeOf curcontrol Is DataCombo Then
                 curcontrol.Text = ""
        End If
         If TypeOf curcontrol Is ComboBox Then
            If curcontrol.Style <> 2 Then
                curcontrol.Text = ""
            End If
        End If
        If TypeOf curcontrol Is CtrlNumber Then
              curcontrol.ValorPorDefecto
        End If
        If TypeOf curcontrol Is CheckBox Then
              curcontrol.Value = 0
        End If
        
        If TypeOf curcontrol Is DTPicker Then
              curcontrol.Value = Now
        End If
    
    Next
    End With
    
    'dtpFechaProceso.Value = GDatFechaProceso
    
    Call CargaGrid(-1)
    Call LlenaDataCombos
    
End Sub

Private Sub CargaGrid(lngId As Long)
    
    'Set DBDetalle.DataSource = ObjCtrlPrecios.SeleccionaEnTemporal(lngId, GintDecPrecio)
    'Call FormatoGrilla
    'DBDetalle.Refresh
    
    Dim strsql As String
    
    strsql = " SELECT T.INVTIDSKU AS Cod,I.DESCR as Descripcion,T.SLS_PRICE as Precio " & _
             " FROM TMP_IN_COMPETITIONPRICEDET AS T JOIN IN_INVENTORY AS I " & _
             " ON T.INVTIDSKU=I.INVTIDSKU " & _
             " WHERE CORRNBR=" & lngId & " ORDER BY T.INVTIDSKU "
             
    Dim Lutilsetup As UTIL_SETUP.C_SETUP
    Dim Lrstemp As ADODB.Recordset
    Set Lutilsetup = New UTIL_SETUP.C_SETUP
    Set Lrstemp = Lutilsetup.Auxiliar3(strsql)
    Set DBDetalle.DataSource = Lrstemp
    
    Call FormatoGrilla
    DBDetalle.Refresh

    
    
    
End Sub
Private Sub FormatoGrilla()
    DBDetalle.Columns(0).Width = 500
    DBDetalle.Columns(0).Visible = False
    
    DBDetalle.Columns(1).Width = 3000
    DBDetalle.Columns(2).Width = 2000
    DBDetalle.Columns(2).Alignment = dbgRight
    DBDetalle.Columns(2).NumberFormat = GMascara(GintDecPrecio)


End Sub

Private Sub GrabaRegistros()
On Error GoTo errhandler
    
    
    If ValidaDatos = True Then 'si los datos se ingresaron correctamente
        If MsgBox("Desea Grabar datos de Control de Precios de Competencia? ", vbQuestion + vbYesNo, "Confirmar Grabación") = vbNo Then
            Call cancelarIngreso
            Exit Sub
        End If
        
        If blnEditando Then 'SI SE ESTA AGREGANDO
            'ObjCtrlPrecios.AgregarRegistro lngCorrelativo
            Dim strsql As String
            strsql = " EXEC IN_COMPETITIONPRICEDETInsProc " & lngCorrelativo
            
            Dim LutMant As DB_UT_MANTENIMIENTOS.C_PROCESOS
            Set LutMant = New DB_UT_MANTENIMIENTOS.C_PROCESOS
            LutMant.Auxiliar1 strsql
                        
        Else
            ObjCtrlPrecios.ModificarRegistros dtcAlmacen.BoundText, dtpFechaProc.Value, dtcCompetencia.BoundText, lngCorrelativo
        End If
        
        blnEditando = False
        MsgBox "Registro de Control de Precios de Competencia grabado Correctamente", vbInformation, "Mensaje"
        
SALTO:

        Call HabilitaCampos(False)
        Call HabilitaBotones(True)
        
    End If

Exit Sub

errhandler:
    MsgBox MensajedeError(Err.Number, Err.Description), vbDefaultButton1 + vbCritical, "Advertencia"
    intErr = 1

End Sub

Private Function ValidaDatos() As Boolean
ValidaDatos = True
blnDatosOK = True
    If Not (ValidaDatosCab) Then
        ValidaDatos = False
        blnDatosOK = False
        Exit Function
    End If
    If Not (ValidaDatosDet) Then
        ValidaDatos = False
        blnDatosOK = False
        Exit Function
    End If
End Function

Private Function ValidaDatosCab() As Boolean
ValidaDatosCab = True

If DBDetalle.Bookmark = 0 Or IsNull(DBDetalle.Bookmark) Then
    If GVDATO(dtcAlmacen.Text) = Empty Then
        MsgBox "Ingrese Almacen", vbExclamation, "Mensaje"
        dtcAlmacen.SetFocus
        GoTo final
    End If
End If
    Exit Function
    
final:
    ValidaDatosCab = False
        
End Function

Private Function ValidaDatosDet() As Boolean
ValidaDatosDet = True

    If IsNull(DBDetalle.Bookmark) Then
        MsgBox "Debe existir al menos un registro en detalle de documento", vbExclamation, "Mensaje"
        ValidaDatosDet = False
    End If
    
End Function

Public Sub agregar_registro()
    Call Nuevo_Registro
    pb_agregar = True
    pb_editar = True
    Call gagregar_registro(Me, dtcAlmacen)
    cmdConfirmar.Enabled = True
    dtcAlmacen.BoundText = GstrSiteProce
    cmdBusAlmacen.Enabled = True
    dtpFechaProc.Enabled = True
    ctnPrecio.Enabled = True
    
End Sub

Public Sub descartar_registro()
    ' Revertir cambios
    cancelarIngreso
    Call gdescartar_registro(Me)
    cmdBuscar.Enabled = True
    cmdConfirmar.Enabled = False
    dtcAlmacen.Enabled = False
    cmdBusAlmacen.Enabled = False
    dtpFechaProc.Enabled = False
    ctnPrecio.Enabled = False
End Sub

Public Sub modificar_registro()
    If DBDetalle.Bookmark <> 0 Or Not IsNull(DBDetalle.Bookmark) Then
        
        'blnEditando = True

        Call HabilitaBotones(False)
        Call DesabilitaCabecera
        
    
        lngCorrelativo = objCorrelativo.ObtenerCorrelativo(GCUSERID)
        Call ObjCtrlPrecios.CopiarOriginalAlTemporal(dtcAlmacen.BoundText, dtpFechaProc.Value, dtcCompetencia.BoundText, lngCorrelativo)
        Call CargaGrid(lngCorrelativo)
        
    
        pb_agregar = True
        pb_editar = True
        Call gactualiza_barra(Me)
        
    Else
        MsgBox "Seleccione un Registros que desee Modificar", vbExclamation, "Contómetros Manuales"
    End If
    
Exit Sub

errhandler:
    MsgBox MensajedeError(Err.Number, Err.Description), vbDefaultButton1 + vbCritical, "Advertencia"
               
End Sub

Public Sub grabar_registro()
    Call GrabaRegistros
    If intErr = 0 Then
        If blnDatosOK Then
            pb_agregar = False
            pb_editar = False
            Call gactualizaopcion(pbderecho_agregar, pbderecho_editar, pbderecho_borrar, pbderecho_imprimir)
            Call gactualiza_barra(Me)
            cmdBuscar.Enabled = True
        End If
    Else
        intErr = 0
    End If
End Sub

Public Sub salir_formulario()
    Salir
End Sub

Private Sub DesabilitaCabecera()
    dtcAlmacen.Enabled = False
    cmdBusAlmacen.Enabled = False
    dtpFechaProc.Enabled = False
    cmdConfirmar.Enabled = False
    ctnPrecio.Enabled = True
End Sub

Public Sub imprimir()
    cmdImprimir_Click
End Sub





