VERSION 5.00
Object = "{F0D2F211-CCB0-11D0-A316-00AA00688B10}#1.0#0"; "msdatlst.ocx"
Begin VB.Form frmParametros 
   Caption         =   "Parametros"
   ClientHeight    =   2325
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   4980
   Icon            =   "frmParametros.frx":0000
   LinkTopic       =   "Form3"
   MaxButton       =   0   'False
   ScaleHeight     =   2325
   ScaleWidth      =   4980
   StartUpPosition =   2  'CenterScreen
   Begin VB.TextBox txtServicio 
      Height          =   285
      Left            =   1560
      TabIndex        =   12
      Top             =   1200
      Width           =   2895
   End
   Begin VB.CheckBox chkAlmacen 
      Caption         =   "Check1"
      Height          =   255
      Left            =   4560
      TabIndex        =   7
      Top             =   720
      Width           =   255
   End
   Begin VB.CommandButton cmdCerrar 
      Caption         =   "Cerrar"
      Height          =   375
      Left            =   3600
      TabIndex        =   5
      Top             =   1800
      Width           =   1095
   End
   Begin VB.CommandButton cmdGrabar 
      Caption         =   "Grabar"
      Height          =   375
      Left            =   240
      TabIndex        =   4
      Top             =   1800
      Width           =   1095
   End
   Begin VB.CheckBox chkNumeracion 
      Caption         =   "Check1"
      Height          =   255
      Left            =   4560
      TabIndex        =   3
      Top             =   240
      Width           =   255
   End
   Begin VB.TextBox txtNumeracion 
      Enabled         =   0   'False
      Height          =   285
      Left            =   1560
      TabIndex        =   1
      Top             =   240
      Width           =   2895
   End
   Begin MSDataListLib.DataCombo dcbAlmacen 
      Height          =   315
      Left            =   1560
      TabIndex        =   6
      Top             =   720
      Width           =   2895
      _ExtentX        =   5106
      _ExtentY        =   556
      _Version        =   393216
      Enabled         =   0   'False
      Style           =   2
      Text            =   "DataCombo1"
   End
   Begin VB.Label Label6 
      Alignment       =   2  'Center
      Caption         =   ":"
      Height          =   255
      Left            =   1320
      TabIndex        =   11
      Top             =   1200
      Width           =   135
   End
   Begin VB.Label Label5 
      Caption         =   "% Servicio"
      Height          =   255
      Left            =   240
      TabIndex        =   10
      Top             =   1200
      Width           =   1095
   End
   Begin VB.Label Label4 
      Alignment       =   2  'Center
      Caption         =   ":"
      Height          =   255
      Left            =   1320
      TabIndex        =   9
      Top             =   720
      Width           =   135
   End
   Begin VB.Label Label3 
      Caption         =   "Almacén"
      Height          =   255
      Left            =   240
      TabIndex        =   8
      Top             =   720
      Width           =   975
   End
   Begin VB.Label Label2 
      Alignment       =   2  'Center
      Caption         =   ":"
      Height          =   255
      Left            =   1320
      TabIndex        =   2
      Top             =   240
      Width           =   135
   End
   Begin VB.Label Label1 
      Caption         =   "Numeración"
      Height          =   255
      Left            =   240
      TabIndex        =   0
      Top             =   240
      Width           =   975
   End
End
Attribute VB_Name = "frmParametros"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim bOK As Boolean

Private Sub chkAlmacen_Click()
  dcbAlmacen.Enabled = chkAlmacen.Value
End Sub

Private Sub chkNumeracion_Click()
  txtNumeracion.Enabled = chkNumeracion.Value
End Sub

Private Sub cmdCerrar_Click()
  Unload Me
End Sub

Private Sub cmdGrabar_Click()
  bOK = True
  
  If chkNumeracion.Value = 1 Then
    Call GrabarNumeracion
  End If
  
  If bOK And chkAlmacen.Value = 1 Then
    Call GrabarAlmacen
  End If
  
  If bOK Then
    Call GrabarServicio
  End If
  
  If bOK Then
    MsgBox "Se guardó la configuración satisfactoriamente"
    Unload Me
  End If
End Sub

Private Sub Form_Load()
  Dim sSQL As String
  Dim ADORS As ADODB.Recordset
   
  sSQL = " SELECT cCodAlmac, vDscAlmac FROM Almacen ORDER BY vDscAlmac "
  
  If Not oDBAdmin.EjecutarConsulta(ADOCnnSQL, sSQL, ADORS) Then GoTo Salir
  
  Set dcbAlmacen.RowSource = ADORS
  dcbAlmacen.BoundColumn = "cCodAlmac"
  dcbAlmacen.ListField = "vDscAlmac"
        
  dcbAlmacen.BoundText = kPAR_ALMACEN
  
  txtServicio.Text = kPAR_PORCSERV
  bOK = True
  
  Exit Sub
  
Salir:
  MsgBox Err.Description, vbInformation + vbOKOnly
  Set ADORS = Nothing
End Sub

Private Sub txtNumeracion_KeyPress(KeyAscii As Integer)
  On Error GoTo LineaError
  
  Call ValidKeyPress(KeyAscii, kVKP_NUMERIC_INTEGER_ONLY)
  
  Exit Sub
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation
End Sub

Private Sub txtServicio_KeyPress(KeyAscii As Integer)
  On Error GoTo LineaError
  
  Call ValidKeyPress(KeyAscii, kVKP_NUMERIC_INTEGER_ONLY)
  
  Exit Sub
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation
End Sub

Private Function EsValido() As Boolean
  EsValido = True
    
  If Trim(Me.txtNumeracion.Text) = "" Then
    EsValido = False
    MsgBox "Debe de ingresar un número para inicializar el comprobante"
    Exit Function
  End If
   
  If val(Trim(Me.txtNumeracion.Text)) <= 0 Then
    EsValido = False
    MsgBox "El numero ingresado en Numeración no puede ser menor o igual que cero"
    Exit Function
  End If
   
  If ExisteOperacion(Trim(Me.txtNumeracion.Text)) = True Then
    EsValido = False
    MsgBox "El número con el que desea inicializar es menor o igual que el maximo valor de los comprobantes existentes"
    Exit Function
  End If
End Function

Private Function ExisteOperacion(strCodigoOperacion As String) As Boolean
  On Error GoTo LineaError

  Screen.MousePointer = vbHourglass
  
  Dim sSQL As String
  Dim ADORS As ADODB.Recordset
  
  ExisteOperacion = False
  
  sSQL = " SELECT max(cOperCode) as Maximo FROM Operacion "
  
  If Not oDBAdmin.EjecutarConsulta(ADOCnn, sSQL, ADORS) Then GoTo Salir
  
  If val("0" + LeerCampo(ADORS!Maximo)) >= val(strCodigoOperacion) Then
    ExisteOperacion = True
  End If
  
  GoTo Salir
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation
  Screen.MousePointer = vbDefault

Salir:
  Set ADORS = Nothing
  Screen.MousePointer = vbDefault

End Function

Private Sub InicializarNumeracion(strCodigoOperacion As String)
  On Error GoTo LineaError

  Screen.MousePointer = vbHourglass
  
  Dim sSQL As String
  Dim ADORS As ADODB.Recordset
  Dim intCodigoMaximo As Long
  
  'Verificamos si existe el numero de comprobante anterior
  sSQL = " SELECT cOperCode " & _
         "   FROM Operacion " & _
         "  WHERE cOperCode = " & val(strCodigoOperacion) - 1
       
  If Not oDBAdmin.EjecutarConsulta(ADOCnn, sSQL, ADORS) Then GoTo Salir
  If ADORS.EOF Then     'No existe, entonces creamos uno ficticio
  
    sSQL = " INSERT INTO Operacion(cOperCode)" & _
           " VALUES ('" & val(strCodigoOperacion) - 1 & "')"
    If Not oDBAdmin.EjecutarSentencia(ADOCnn, sSQL) Then GoTo Salir
  End If
  
  GoTo Salir
  
LineaError:
  MsgBox Err.Description, vbOKOnly + vbInformation
  Screen.MousePointer = vbDefault
  bOK = False

Salir:
  Set ADORS = Nothing
  Screen.MousePointer = vbDefault
End Sub

Public Sub GrabarNumeracion()
  bOK = False
  If EsValido = True Then
    bOK = True
    InicializarNumeracion (val(Trim(Me.txtNumeracion.Text)))
  End If
End Sub

Public Sub GrabarAlmacen()
  On Error GoTo MERROR

  EscribirCfg "PARAMETROS", "Almacen", psArchivoCfg, dcbAlmacen.BoundText
  kPAR_ALMACEN = dcbAlmacen.BoundText

  Dim sSQL As String
  sSQL = "UPDATE Producto set cAlmaCode='" & dcbAlmacen.BoundText & "'"
  ADOCnn.Execute sSQL
  
  bOK = True
  
  Exit Sub
  
MERROR:
  MsgBox Err.Description
  bOK = False
End Sub


Public Sub GrabarServicio()
  On Error GoTo MERROR
  
  If Trim(Me.txtServicio.Text) = "" Then
    bOK = False
    MsgBox "Debe de ingresar un número grabar el % Servicio"
    Exit Sub
  End If
   
  If val(Trim(Me.txtServicio.Text)) <= 0 Then
    bOK = False
    MsgBox "El numero ingresado en % Servicio no puede ser menor o igual que cero"
    Exit Sub
  End If
  
  EscribirCfg "PARAMETROS", "PorcServ", psArchivoCfg, txtServicio.Text
  kPAR_PORCSERV = txtServicio.Text

  bOK = True
  
  Exit Sub
  
MERROR:
  MsgBox Err.Description
  bOK = False
End Sub
