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"
Begin VB.Form FContometrosM 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Registro Contometros Manuales (05.060.00)"
   ClientHeight    =   4995
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   11610
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MDIChild        =   -1  'True
   ScaleHeight     =   4995
   ScaleWidth      =   11610
   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          =   420
      Left            =   6615
      MaskColor       =   &H00E0E0E0&
      Picture         =   "0506000.frx":0000
      TabIndex        =   6
      Top             =   1575
      Width           =   1695
   End
   Begin VB.CommandButton cmdBusAlmacen 
      Enabled         =   0   'False
      Height          =   375
      Left            =   5040
      MouseIcon       =   "0506000.frx":030A
      MousePointer    =   99  'Custom
      Picture         =   "0506000.frx":045C
      Style           =   1  'Graphical
      TabIndex        =   1
      ToolTipText     =   "Buscar Almacén"
      Top             =   1035
      Width           =   375
   End
   Begin VB.ComboBox cmbTurnos 
      BackColor       =   &H00FFFFFF&
      Enabled         =   0   'False
      Height          =   315
      Left            =   8730
      Style           =   2  'Dropdown List
      TabIndex        =   3
      Top             =   1035
      Width           =   1215
   End
   Begin VB.CommandButton cmdBusVendedor 
      Enabled         =   0   'False
      Height          =   375
      Left            =   5040
      MouseIcon       =   "0506000.frx":098E
      MousePointer    =   99  'Custom
      Picture         =   "0506000.frx":0AE0
      Style           =   1  'Graphical
      TabIndex        =   5
      ToolTipText     =   "Buscar Vendedor"
      Top             =   1530
      Width           =   375
   End
   Begin VB.CommandButton cmdBuscar 
      Height          =   465
      Left            =   4440
      MouseIcon       =   "0506000.frx":1012
      MousePointer    =   99  'Custom
      Picture         =   "0506000.frx":1164
      Style           =   1  'Graphical
      TabIndex        =   8
      ToolTipText     =   "Buscar Registro de Contómetros"
      Top             =   300
      Width           =   645
   End
   Begin Crystal.CrystalReport crContometro 
      Left            =   6960
      Top             =   360
      _ExtentX        =   741
      _ExtentY        =   741
      _Version        =   348160
      PrintFileLinesPerPage=   60
   End
   Begin MSDataGridLib.DataGrid DBDetalle 
      Height          =   2490
      Left            =   135
      TabIndex        =   7
      Top             =   2385
      Width           =   11415
      _ExtentX        =   20135
      _ExtentY        =   4392
      _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 un registro"
      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 dtcVendedor 
      Height          =   315
      Left            =   1200
      TabIndex        =   4
      Top             =   1530
      Width           =   3735
      _ExtentX        =   6588
      _ExtentY        =   556
      _Version        =   393216
      Enabled         =   0   'False
      Style           =   2
      Text            =   ""
   End
   Begin MSDataListLib.DataCombo dtcAlmacen 
      Height          =   315
      Left            =   1200
      TabIndex        =   0
      Top             =   1050
      Width           =   3735
      _ExtentX        =   6588
      _ExtentY        =   556
      _Version        =   393216
      Enabled         =   0   'False
      Style           =   2
      Text            =   ""
   End
   Begin MSComCtl2.DTPicker dtpFechaProc 
      Height          =   315
      Left            =   6615
      TabIndex        =   2
      Top             =   1035
      Width           =   1335
      _ExtentX        =   2355
      _ExtentY        =   556
      _Version        =   393216
      Enabled         =   0   'False
      CalendarBackColor=   16777152
      Format          =   61931521
      CurrentDate     =   37567
   End
   Begin VB.Image Image1 
      Height          =   465
      Left            =   10215
      Picture         =   "0506000.frx":1696
      Stretch         =   -1  'True
      Top             =   1845
      Width           =   555
   End
   Begin VB.Label lblEstado 
      Appearance      =   0  'Flat
      AutoSize        =   -1  'True
      BackColor       =   &H80000004&
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   9.75
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H80000002&
      Height          =   120
      Left            =   5430
      TabIndex        =   16
      Top             =   480
      Width           =   75
   End
   Begin VB.Shape Shape1 
      Height          =   1455
      Left            =   120
      Top             =   855
      Width           =   9975
   End
   Begin VB.Label lblFechaInicio 
      Caption         =   "Fecha Proceso"
      Height          =   435
      Left            =   5760
      TabIndex        =   15
      Top             =   1050
      Width           =   720
   End
   Begin VB.Label lblAlmacen 
      AutoSize        =   -1  'True
      Caption         =   "Almacen"
      Height          =   195
      Left            =   360
      TabIndex        =   14
      Top             =   1050
      Width           =   615
   End
   Begin VB.Label lblTurno 
      Caption         =   "Turno"
      Height          =   255
      Left            =   8145
      TabIndex        =   13
      Top             =   1050
      Width           =   615
   End
   Begin VB.Label lblVendecor 
      AutoSize        =   -1  'True
      Caption         =   "Vendedor"
      Height          =   195
      Left            =   360
      TabIndex        =   12
      Top             =   1530
      Width           =   690
   End
   Begin VB.Label lblNumero 
      Alignment       =   2  'Center
      BorderStyle     =   1  'Fixed Single
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   285
      Left            =   2760
      TabIndex        =   11
      Top             =   360
      Width           =   1575
   End
   Begin VB.Label lblNroLista 
      AutoSize        =   -1  'True
      Caption         =   "Nro. Contómetro :"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   12
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H8000000D&
      Height          =   300
      Left            =   600
      TabIndex        =   10
      Top             =   300
      Width           =   2145
   End
   Begin VB.Label lblEtiqueta 
      AutoSize        =   -1  'True
      Caption         =   "NUEVO REGISTRO DE CONTOMETRO MANUAL"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   9.75
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H8000000D&
      Height          =   240
      Left            =   960
      TabIndex        =   9
      Top             =   300
      Width           =   5070
   End
End
Attribute VB_Name = "FContometrosM"
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 Contómetros Manuales
' Fecha : 08/11/2002

Option Explicit

'************************************
' Variables que almacenan la ubicacion
' de los Items en los Datacombos cuando
' se cambia de Screen

'Dim MstrTipoMovimiento As String
'Dim MstrAlmacen As String
'Dim MstrProveedor As String
'Dim MstrTipoDoc As String
'Dim MstrMoneda As String
'Dim MstrArticulo As String

'*************************************
'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 ObjContometro As DB_OP_MANTENIMIENTOS.C_CONTOMETROM

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

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


Private Sub cmbTurnos_Change()
    Call CargaDataCombo(dtcVendedor, ObjContometro.CargaVendedores(dtcAlmacen.BoundText, dtpFechaProc.Value, cmbTurnos.ListIndex + 1), "SALESPERID", "SALESPERNAME")
End Sub

Private Sub cmbTurnos_Click()
    Call CargaDataCombo(dtcVendedor, ObjContometro.CargaVendedores(dtcAlmacen.BoundText, dtpFechaProc.Value, cmbTurnos.ListIndex + 1), "SALESPERID", "SALESPERNAME")
End Sub

Public Sub actualizar_registro()
End Sub

Private Sub cmbTurnos_GotFocus()
cmbTurnos.BackColor = GC_ColorEnfoque
End Sub

Private Sub cmbTurnos_LostFocus()
cmbTurnos.BackColor = GC_ColorDefecto
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()
    FBuscarContometro.Show vbModal
End Sub

Private Sub cmdBusVendedor_Click()
    'Lineas que llaman al Formulario de Búsqueda
    
    Dim ArrayBusqueda(1 To 2, 1 To 3) As Variant
    ArrayBusqueda(1, 1) = "SALESPERID"
    ArrayBusqueda(1, 2) = "Código "
    ArrayBusqueda(1, 3) = 1200
    ArrayBusqueda(2, 1) = "SALESPERNAME"
    ArrayBusqueda(2, 2) = "Nombre "
    ArrayBusqueda(2, 3) = 4000
      
    FBusquedasVta.GObtenerRegistros ObjContometro.CargaVendedores(dtcAlmacen.BoundText, dtpFechaProc.Value, cmbTurnos.ListIndex + 1), ArrayBusqueda, 2, 2
    FBusquedasVta.Show vbModal
    
    If GrecibeUbicacion <> 0 Then
        dtcVendedor.BoundText = GrecibeColumnaID
    End If
End Sub

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

End Sub


Private Sub cmdConfirmar_Click()
    Dim MnumeroContometro As Long
    If ValidaDatosCab Then
        MnumeroContometro = ObjContometro.ExisteRegistro(dtcAlmacen.BoundText, dtpFechaProc.Value, cmbTurnos.ListIndex + 1, dtcVendedor.BoundText)
    
        If MnumeroContometro = 0 Then
            ObjContometro.CopiarAlTemporal lngCorrelativo, dtcAlmacen.BoundText, dtpFechaProc.Value, cmbTurnos.ListIndex + 1, dtcVendedor.BoundText
            CargaGrid lngCorrelativo
            DesabilitaCabecera
        Else
            MsgBox "Datos ya registrados en el Contómetro Nro : " & MnumeroContometro, vbExclamation, "Contómetro Manual"
            Exit Sub
        End If
    End If
End Sub

Private Sub cmdImprimir_Click()

End Sub

Private Sub Nuevo_Registro()
    blnEditando = True
        
    Call HabilitaCampos(True)
    Call HabilitaBotones(False)
    Call Limpiar
    
    ' SE OBTIENE EL NUMERO DE CORRELATIVO INDENTIFICADOR POR USUARIO
    lngCorrelativo = objCorrelativo.ObtenerCorrelativo(GCUSERID)
   
    'dtcAlmacen.SetFocus
End Sub


Private Sub Salir()
    Unload Me
End Sub

Public Sub CargaDatos(strSITEID As String, strBATNBRTURN As String)
On Error GoTo TrataError
    Call Limpiar
    Dim rsTemporal As ADODB.Recordset
    Set rsTemporal = ObjContometro.SeleccionaEnCabecera(strSITEID, strBATNBRTURN)
    
    ' CARGO LA CABECERA
    lblNumero.Caption = rsTemporal!BATNBRTURN

    
    dtcAlmacen.BoundText = rsTemporal!SITEID
    dtpFechaProc.Value = rsTemporal!DATEPROCES
    cmbTurnos.ListIndex = rsTemporal!NBRTUR - 1
    cmbTurnos_Change
    dtcVendedor.BoundText = rsTemporal!SALESPERID

    If rsTemporal!Status Then
        lblEstado.Caption = "CERRADO"
    Else
        lblEstado.Caption = "NO CERRADO"
    End If
 

    ' CARGO EL DETALLE
    Set DBDetalle.DataSource = ObjContometro.SeleccionaEnDetalle(strSITEID, strBATNBRTURN)
    Call FormatoGrilla
    DBDetalle.Refresh
    
    Set rsTemporal = Nothing
    
    
    Exit Sub
    
TrataError:
    Call Limpiar
    MsgBox "Nro de Ingreso no Registrado en Almacen Seleccionado", vbExclamation, "Error en Consulta"
End Sub



Private Sub DBDETALLE_KeyDown(KeyCode As Integer, Shift As Integer)

    If pb_editar Then ' si se esta editando
        If KeyCode = 13 Then
            If DBDetalle.Bookmark <> 0 Or Not IsNull(DBDetalle.Bookmark) Then
                If Not cmdConfirmar.Enabled Then
                    FEditarContometro.MlngCorrelativo = lngCorrelativo
                    FEditarContometro.MintNro_Cara = DBDetalle.Columns(0).Text
                    FEditarContometro.MintNro_Manguera = CInt(DBDetalle.Columns(1).Text)
                    If CDbl(DBDetalle.Columns(3).Text) = 0 Then
                        FEditarContometro.MdblInicial = ObtieneLectutaInicial
                    Else
                        FEditarContometro.MdblInicial = CDbl(DBDetalle.Columns(3).Text)
                    End If
                    FEditarContometro.MdblFinal = CDbl(DBDetalle.Columns(4).Text)
                    FEditarContometro.MdblVenta = CDbl(DBDetalle.Columns(5).Text)
                    FEditarContometro.MdblSerafin = CDbl(DBDetalle.Columns(6).Text)
                    FEditarContometro.MdblOtros = CDbl(DBDetalle.Columns(7).Text)
                    FEditarContometro.MdblTotal = CDbl(DBDetalle.Columns(8).Text)
                    FEditarContometro.Show vbModal
                    CargaGrid lngCorrelativo
                    Exit Sub
                Else
                    MsgBox "Confirme antes de editar", vbExclamation, "Mensaje"
                    Exit Sub
                End If
            End If
        End If
    End If
End Sub

Private Sub dtcAlmacen_Change()
    Call CargaDataCombo(dtcVendedor, ObjContometro.CargaVendedores(dtcAlmacen.BoundText, dtpFechaProc.Value, cmbTurnos.ListIndex + 1), "SALESPERID", "SALESPERNAME")
End Sub

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

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

Private Sub dtcVendedor_Click(Area As Integer)
    Set DBDetalle.DataSource = ObjContometro.SeleccionTemporal(dtcAlmacen.BoundText, dtpFechaProc.Value, cmbTurnos.ListIndex + 1, dtcVendedor.BoundText)
    Call FormatoGrilla
    DBDetalle.Refresh
End Sub

Private Sub dtcVendedor_GotFocus()
dtcVendedor.BackColor = GC_ColorEnfoque
End Sub

Private Sub dtcVendedor_LostFocus()
dtcVendedor.BackColor = GC_ColorDefecto
End Sub

Private Sub dtpFechaProc_Change()
    Call CargaDataCombo(dtcVendedor, ObjContometro.CargaVendedores(dtcAlmacen.BoundText, dtpFechaProc.Value, cmbTurnos.ListIndex + 1), "SALESPERID", "SALESPERNAME")
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
        
       ' Call gHabilitarReg(Me, False)
        CargaTurnos
  
  
  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
    
      
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(dtcVendedor, ObjContometro.CargaVendedores(dtcAlmacen.BoundText, "01/01/1900", 0), "SALESPERID", "SALESPERNAME")
    Call CargaDataCombo(dtcAlmacen, objAlmacen.ListarAlmacenesPorStatus(1), "SiteId", "Name")
End Sub

Private Sub InstanciaObjetos()
    Set ObjContometro = New DB_OP_MANTENIMIENTOS.C_CONTOMETROM
    Set objAlmacen = New DB_INV_MANTENIMIENTOS.C_ALMACEN
    Set objCorrelativo = New DB_CORRELATIVO.C_Correlativos
End Sub

Private Sub DestruyeObjetos()
    Set ObjContometro = Nothing
    Set objAlmacen = Nothing
    Set objCorrelativo = Nothing
    Set ObjContometro = Nothing
End Sub

Private Sub HabilitaCampos(blnValor As Boolean)


    lblNroLista.Visible = Not blnValor
    lblNumero.Visible = Not blnValor
    cmdBuscar.Visible = Not blnValor
    lblEtiqueta.Visible = 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
    

    lblNumero.Caption = Empty
    lblEstado.Caption = Empty

    Call CargaGrid(-1)
    Call LlenaDataCombos
    
End Sub

Private Sub CargaGrid(lngId As Long)
    
    Set DBDetalle.DataSource = ObjContometro.SeleccionaEnTemporalDetControlTurno(lngId)
    Call FormatoGrilla
    DBDetalle.Refresh
    
End Sub
Private Sub FormatoGrilla()
    DBDetalle.Columns(0).Width = 500
    DBDetalle.Columns(1).Width = 800
    DBDetalle.Columns(2).Width = 2700
    DBDetalle.Columns(3).Width = 1200
    DBDetalle.Columns(3).Alignment = dbgRight
    DBDetalle.Columns(3).NumberFormat = GMascara(GintDecStock)
    DBDetalle.Columns(4).Width = 1200
    DBDetalle.Columns(4).Alignment = dbgRight
    DBDetalle.Columns(4).NumberFormat = GMascara(GintDecStock)
    DBDetalle.Columns(5).Width = 1200
    DBDetalle.Columns(5).Alignment = dbgRight
    DBDetalle.Columns(5).NumberFormat = GMascara(GintDecStock)
    DBDetalle.Columns(6).Width = 1000
    DBDetalle.Columns(6).Alignment = dbgRight
    DBDetalle.Columns(6).NumberFormat = GMascara(GintDecStock)
    DBDetalle.Columns(7).Width = 1000
    DBDetalle.Columns(7).Alignment = dbgRight
    DBDetalle.Columns(7).NumberFormat = GMascara(GintDecStock)
    DBDetalle.Columns(8).Width = 1200
    DBDetalle.Columns(8).Alignment = dbgRight
    DBDetalle.Columns(8).NumberFormat = GMascara(GintDecStock)
End Sub

Private Sub GrabaContometro()
On Error GoTo errhandler
    
    
    If ValidaDatos = True Then 'si los datos se ingresaron correctamente
        If MsgBox("Desea Grabar datos de Contómetro? ", vbQuestion + vbYesNo, "Confirmar Grabación") = vbNo Then
            Call cancelarIngreso
            Exit Sub
        End If

        
        If blnEditando Then 'SI SE ESTA AGREGANDO
            lngNumeroContometro = ObjContometro.AgregarContometro(dtcAlmacen.BoundText, dtpFechaProc.Value, CStr(cmbTurnos.ListIndex + 1), dtcVendedor.BoundText, GCUSERID, lngCorrelativo)
            
            lblNumero.Caption = lngNumeroContometro ' se asigna el valor del numero de movimiento
            lblEstado.Caption = "NO CERRADO"
        Else
            ObjContometro.ModificarContometro CLng(lblNumero.Caption), dtcAlmacen.BoundText, lngCorrelativo
        End If
        
        blnEditando = False
        If MsgBox("Registro de Contómetro grabado Correctamente.Desea Imprimir? ", vbQuestion + vbYesNo, "Contómetro Manual Nro: " & lblNumero.Caption) = vbNo Then
           GoTo SALTO
        Else
             'Call cmdImprimir_Click
        End If
        
SALTO:

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

Exit Sub

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

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
    If GVDATO(cmbTurnos.Text) = Empty Then
        MsgBox "Ingrese Turno", vbExclamation, "Mensaje"
        cmbTurnos.SetFocus
        GoTo Final
    End If
    If GVDATO(dtcVendedor.Text) = Empty Then
        MsgBox "Seleccione un vendedor", vbExclamation, "Mensaje"
        dtcVendedor.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)
    
End Sub

Public Sub descartar_registro()
    ' Revertir cambios
    cancelarIngreso
    Call gdescartar_registro(Me)
    cmdBuscar.Enabled = True
End Sub

Public Sub modificar_registro()
    If lblNumero.Caption <> Empty Then
        If lblEstado.Caption = "CERRADO" Then
            MsgBox "No se puede Modificar una Registro de Contómetro que esta Cerrado", vbExclamation, "Contómetros Manuales"
            Exit Sub
        End If
        
        'blnEditando = True

        Call HabilitaBotones(False)
        Call DesabilitaCabecera
        
    
        lngCorrelativo = objCorrelativo.ObtenerCorrelativo(GCUSERID)
        Call ObjContometro.CopiarOriginalAlTemporal(CLng(lblNumero.Caption), dtcAlmacen.BoundText, lngCorrelativo)
        Call CargaGrid(lngCorrelativo)
    
        pb_agregar = True
        pb_editar = True
        Call gactualiza_barra(Me)

    Else
        MsgBox "Seleccione un Registro de Contómetro 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 GrabaContometro
    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
End Sub


Public Sub salir_formulario()
    Salir
End Sub

Private Sub DesabilitaCabecera()
    dtcAlmacen.Enabled = False
    cmdBusAlmacen.Enabled = False
    dtpFechaProc.Enabled = False
    cmdBusVendedor.Enabled = False
    dtcVendedor.Enabled = False
    cmbTurnos.Enabled = False
    cmdConfirmar.Enabled = False
End Sub

Public Sub imprimir()
    cmdImprimir_Click
End Sub

Private Sub CargaTurnos()
    Dim I As Integer
    For I = 1 To GintCantidadTurnos
        cmbTurnos.AddItem "Turno " & I
    Next
End Sub

Private Function ObtieneLectutaInicial() As Double
Dim NroTurno As Integer
Dim Fecha As Date

If cmbTurnos.ListIndex = 0 Then
    NroTurno = cmbTurnos.ListCount
    Fecha = dtpFechaProc - 1
Else
    NroTurno = cmbTurnos.ListIndex
End If

ObtieneLectutaInicial = ObjContometro.ObtieneLecturaInicial(dtcAlmacen.BoundText, Fecha, NroTurno, DBDetalle.Columns(0).Text, CInt(DBDetalle.Columns(1).Text))

End Function


