VERSION 5.00
Begin VB.Form Principal 
   Caption         =   "Demo CashKeeper V2"
   ClientHeight    =   8925
   ClientLeft      =   9840
   ClientTop       =   2775
   ClientWidth     =   9360
   BeginProperty Font 
      Name            =   "Arial"
      Size            =   12
      Charset         =   0
      Weight          =   400
      Underline       =   0   'False
      Italic          =   0   'False
      Strikethrough   =   0   'False
   EndProperty
   Icon            =   "Principal.frx":0000
   KeyPreview      =   -1  'True
   LinkTopic       =   "Form1"
   ScaleHeight     =   8925
   ScaleWidth      =   9360
   Begin VB.CommandButton cmdVersiones 
      Caption         =   "Versions"
      Height          =   360
      Left            =   7470
      TabIndex        =   45
      Top             =   1710
      Width           =   1680
   End
   Begin VB.Frame FraOperaciones 
      Caption         =   "Operations"
      Height          =   1995
      Left            =   7470
      TabIndex        =   35
      Top             =   4110
      Width           =   1755
      Begin VB.OptionButton OptOP 
         Caption         =   "8"
         Height          =   435
         Index           =   8
         Left            =   1200
         Style           =   1  'Graphical
         TabIndex        =   44
         Top             =   1410
         Width           =   465
      End
      Begin VB.OptionButton OptOP 
         Caption         =   "7"
         Height          =   435
         Index           =   7
         Left            =   660
         Style           =   1  'Graphical
         TabIndex        =   43
         Top             =   1410
         Width           =   465
      End
      Begin VB.OptionButton OptOP 
         Caption         =   "6"
         Height          =   435
         Index           =   6
         Left            =   120
         Style           =   1  'Graphical
         TabIndex        =   42
         Top             =   1410
         Width           =   465
      End
      Begin VB.OptionButton OptOP 
         Caption         =   "5"
         Height          =   435
         Index           =   5
         Left            =   1200
         Style           =   1  'Graphical
         TabIndex        =   41
         Top             =   900
         Width           =   465
      End
      Begin VB.OptionButton OptOP 
         Caption         =   "4"
         Height          =   435
         Index           =   4
         Left            =   660
         Style           =   1  'Graphical
         TabIndex        =   40
         Top             =   900
         Width           =   465
      End
      Begin VB.OptionButton OptOP 
         Caption         =   "3"
         Height          =   435
         Index           =   3
         Left            =   120
         Style           =   1  'Graphical
         TabIndex        =   39
         Top             =   900
         Width           =   465
      End
      Begin VB.OptionButton OptOP 
         Caption         =   "2"
         Height          =   435
         Index           =   2
         Left            =   1200
         Style           =   1  'Graphical
         TabIndex        =   38
         Top             =   390
         Width           =   465
      End
      Begin VB.OptionButton OptOP 
         Caption         =   "1"
         Height          =   435
         Index           =   1
         Left            =   660
         Style           =   1  'Graphical
         TabIndex        =   37
         Top             =   390
         Width           =   465
      End
      Begin VB.OptionButton OptOP 
         Caption         =   "0"
         Height          =   435
         Index           =   0
         Left            =   120
         Style           =   1  'Graphical
         TabIndex        =   36
         Top             =   390
         Value           =   -1  'True
         Width           =   465
      End
   End
   Begin VB.Frame FraCambio 
      Caption         =   "Exchange"
      Height          =   1515
      Left            =   7470
      TabIndex        =   32
      Top             =   2280
      Visible         =   0   'False
      Width           =   1755
      Begin VB.CommandButton cmdAsignar 
         Caption         =   "Assign"
         Height          =   360
         Left            =   180
         TabIndex        =   34
         Top             =   900
         Width           =   1335
      End
      Begin VB.TextBox txtCambio 
         Alignment       =   1  'Right Justify
         Height          =   390
         Left            =   180
         TabIndex        =   33
         Text            =   "0"
         Top             =   420
         Width           =   1335
      End
   End
   Begin VB.Frame FraUtilidades 
      Caption         =   "Utils"
      Height          =   2595
      Left            =   5850
      TabIndex        =   23
      Top             =   6150
      Width           =   3375
      Begin VB.Frame frmBB 
         BackColor       =   &H0000FF00&
         BorderStyle     =   0  'None
         Height          =   600
         Left            =   210
         TabIndex        =   30
         Top             =   360
         Visible         =   0   'False
         Width           =   2940
         Begin VB.Label lblBillete 
            Alignment       =   2  'Center
            BackStyle       =   0  'Transparent
            Caption         =   "Note on Bezel"
            BeginProperty Font 
               Name            =   "Arial"
               Size            =   12
               Charset         =   0
               Weight          =   700
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   285
            Left            =   60
            TabIndex        =   31
            Top             =   150
            Width           =   2835
         End
      End
      Begin VB.CommandButton cmdLimpiezaMonedas 
         Caption         =   "Clean Coin Validator"
         Height          =   810
         Left            =   180
         TabIndex        =   29
         Top             =   1590
         Width           =   1410
      End
      Begin VB.CommandButton cmdReset 
         BackColor       =   &H000000FF&
         Caption         =   "Reset"
         Height          =   360
         Left            =   180
         Style           =   1  'Graphical
         TabIndex        =   28
         Top             =   1140
         Width           =   1410
      End
      Begin VB.CommandButton cmdOpciones 
         Caption         =   "Options"
         Height          =   360
         Left            =   1740
         TabIndex        =   25
         Top             =   1140
         Width           =   1410
      End
      Begin VB.CommandButton cmdForzarNiveles 
         Caption         =   "Force Coin Levels"
         Height          =   810
         Left            =   1740
         TabIndex        =   24
         Top             =   1590
         Width           =   1410
      End
   End
   Begin VB.Frame FraVaciados 
      Caption         =   "Empties"
      Height          =   2595
      Left            =   3870
      TabIndex        =   17
      Top             =   6150
      Width           =   1815
      Begin VB.CommandButton cmdRecaudación 
         Caption         =   "CashBox"
         Height          =   360
         Left            =   150
         TabIndex        =   22
         Top             =   2040
         Width           =   1485
      End
      Begin VB.TextBox txtCB 
         Alignment       =   1  'Right Justify
         Height          =   390
         Left            =   150
         Locked          =   -1  'True
         TabIndex        =   20
         TabStop         =   0   'False
         Text            =   "0"
         Top             =   660
         Width           =   1485
      End
      Begin VB.CommandButton cmdCompleto 
         Caption         =   "Complete"
         Height          =   360
         Left            =   150
         TabIndex        =   19
         Top             =   1590
         Width           =   1485
      End
      Begin VB.CommandButton cmdParcial 
         Caption         =   "Parcial"
         Height          =   360
         Left            =   150
         TabIndex        =   18
         Top             =   1140
         Width           =   1485
      End
      Begin VB.Label lblImporte 
         AutoSize        =   -1  'True
         BackStyle       =   0  'Transparent
         Caption         =   "Amount"
         Height          =   270
         Index           =   1
         Left            =   150
         TabIndex        =   21
         Top             =   330
         Width           =   795
      End
   End
   Begin VB.CommandButton cmdInhibits 
      Caption         =   "Inhibits"
      Height          =   360
      Left            =   7470
      TabIndex        =   15
      Top             =   1230
      Width           =   1680
   End
   Begin VB.CommandButton cmdMínimos 
      Caption         =   "Minims"
      Height          =   360
      Left            =   7470
      TabIndex        =   14
      Top             =   780
      Width           =   1680
   End
   Begin VB.CommandButton cmdMáximos 
      Caption         =   "Maxims"
      Height          =   360
      Left            =   7470
      TabIndex        =   13
      Top             =   330
      Width           =   1680
   End
   Begin VB.Frame FraCobrosPagos 
      Caption         =   "Charge / Payments"
      Height          =   2595
      Left            =   180
      TabIndex        =   6
      Top             =   6150
      Width           =   3555
      Begin VB.CommandButton cmdDeshabilitar 
         Caption         =   "Disable"
         Height          =   360
         Left            =   1860
         TabIndex        =   27
         Top             =   1590
         Width           =   1485
      End
      Begin VB.CommandButton cmdHabilitar 
         Caption         =   "Enable"
         Height          =   360
         Left            =   1860
         TabIndex        =   26
         Top             =   1140
         Width           =   1485
      End
      Begin VB.CommandButton cmdPagoDetall 
         Caption         =   "Pay Denom"
         Height          =   360
         Left            =   240
         TabIndex        =   16
         Top             =   2040
         Width           =   1485
      End
      Begin VB.TextBox txtVal 
         Alignment       =   1  'Right Justify
         Height          =   390
         Left            =   1860
         Locked          =   -1  'True
         TabIndex        =   11
         TabStop         =   0   'False
         Text            =   "0"
         Top             =   660
         Width           =   1485
      End
      Begin VB.CommandButton cmdPagar 
         Caption         =   "Pay"
         Height          =   360
         Left            =   240
         TabIndex        =   10
         Top             =   1590
         Width           =   1485
      End
      Begin VB.CommandButton cmdCobrar 
         Caption         =   "Charge"
         Height          =   360
         Left            =   240
         TabIndex        =   9
         Top             =   1140
         Width           =   1485
      End
      Begin VB.TextBox txtImp 
         Alignment       =   1  'Right Justify
         Height          =   390
         Left            =   240
         TabIndex        =   8
         Text            =   "0"
         Top             =   660
         Width           =   1485
      End
      Begin VB.Label lblActual 
         AutoSize        =   -1  'True
         BackStyle       =   0  'Transparent
         Caption         =   "Actual"
         Height          =   270
         Left            =   1860
         TabIndex        =   12
         Top             =   330
         Width           =   780
      End
      Begin VB.Label lblImporte 
         AutoSize        =   -1  'True
         BackStyle       =   0  'Transparent
         Caption         =   "Amount"
         Height          =   270
         Index           =   0
         Left            =   240
         TabIndex        =   7
         Top             =   330
         Width           =   795
      End
   End
   Begin VB.Frame FraMostrar 
      Caption         =   "Show"
      Height          =   765
      Left            =   3300
      TabIndex        =   3
      Top             =   60
      Width           =   4035
      Begin VB.OptionButton OptCashBox 
         Caption         =   "CashBox"
         Height          =   435
         Left            =   2520
         Style           =   1  'Graphical
         TabIndex        =   5
         Top             =   240
         Width           =   1335
      End
      Begin VB.OptionButton OptCambio 
         Caption         =   "Change"
         Height          =   435
         Left            =   1290
         Style           =   1  'Graphical
         TabIndex        =   4
         Top             =   240
         Value           =   -1  'True
         Width           =   1095
      End
   End
   Begin VB.ListBox lstDenoms 
      BeginProperty Font 
         Name            =   "Courier New"
         Size            =   12
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   5190
      Left            =   180
      TabIndex        =   2
      TabStop         =   0   'False
      Top             =   870
      Width           =   7125
   End
   Begin VB.ComboBox cboMoneda 
      Height          =   390
      ItemData        =   "Principal.frx":3452
      Left            =   1350
      List            =   "Principal.frx":3454
      Style           =   2  'Dropdown List
      TabIndex        =   1
      TabStop         =   0   'False
      Top             =   240
      Width           =   1695
   End
   Begin VB.Label lblMoneda 
      AutoSize        =   -1  'True
      BackStyle       =   0  'Transparent
      Caption         =   "Currency"
      Height          =   270
      Left            =   210
      TabIndex        =   0
      Top             =   330
      Width           =   930
   End
End
Attribute VB_Name = "Principal"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

#Const DEBUGPRINT = True

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Private WithEvents CKEvents As CKeeperLibV2.CKeeper
Attribute CKEvents.VB_VarHelpID = -1

Private once As Boolean
Private CBDisplay As Boolean

Private Sub cboMoneda_Click()
    Dim canvi As Long
    
    If Not SetCC(cboMoneda.List(cboMoneda.ListIndex)) Then
        Exit Sub
    End If
    cmdMáximos.Enabled = (CurCC = MainCC) And (OptCambio.Value = True)
    cmdMínimos.Enabled = (CurCC = MainCC) And (OptCambio.Value = True)
    cmdPagoDetall.Enabled = MainCC = CurCC
    cmdParcial.Enabled = MainCC = CurCC
    cmdForzarNiveles.Enabled = MainCC = CurCC
    CarregaDenominacions
    If CurCC = MainCC Then
        FraCambio.Visible = False
    Else
        If CK.GetCCChange(CurCC, canvi) Then
            txtCambio.text = canvi
        Else
            txtCambio.text = 0
        End If
        FraCambio.Visible = True
    End If
End Sub

Private Sub CarregaDenominacions()
    If LoadCurrentValues Then
        OptCambio.Value = True
        MostraDenominacions
    End If
End Sub

Private Sub CKEvents_BarCodeRead(ByVal code As String)
#If DEBUGPRINT Then
    Debug.Print "BarCodeRead Code = " & code
#End If
    'If MsgBox("Codigo de Barras " & code & " Leido." & vbCrLf & "¿Desea aceptarlo?", vbYesNo + vbQuestion) = vbYes Then
    If MsgBox("BarCode " & code & " Leido." & vbCrLf & "Do you want to accept?", vbYesNo + vbQuestion) = vbYes Then
        CK.AcceptPending
    Else
        CK.RejectPending
    End If
End Sub

Private Sub CKEvents_BarCodeStored(ByVal code As String)
#If DEBUGPRINT Then
    Debug.Print "BarCodeStored Code = " & code
#End If
End Sub

Private Sub CKEvents_Disabled(ByVal ErrorCode As Long, ByVal ErrorDescription As String, ByVal CurrentValue As Long, ByVal TargetValue As Long, ByVal State As Byte, ByVal Operation As Byte)
    If ErrorCode <> 0 Then
#If DEBUGPRINT Then
        Debug.Print "Error " & CStr(ErrorCode) & "-" & ErrorDescription & vbCrLf & "Current: " & CStr(CurrentValue) & ", Target: " & CStr(TargetValue) & ", State: " & CStr(State) & ", Operation: " & CStr(Operation)
#End If
        If ErrorCode <> 0 Then
            MsgBox "CashKeeper Error " & CStr(ErrorCode) & "-" & ErrorDescription & vbCrLf & "Current: " & CStr(CurrentValue) & ", Target: " & CStr(TargetValue) & ", State: " & CStr(State) & ", Operation: " & CStr(Operation)
        End If
    End If
    CBDisplay = False
End Sub

Private Sub CKEvents_LowLevel(ByVal ValuesInfo As String, ByVal LevelsInfo As String)
#If DEBUGPRINT Then
    Debug.Print "LowLevel ValuesInfo ='" & ValuesInfo & "', LevelsInfo = '" & LevelsInfo & "'"
#End If
    'MsgBox "LowLevel Denomimaciones debajo del minimo establecido." & vbCrLf & ValuesInfo & vbCrLf & LevelsInfo
    MsgBox "Denominations level under established minimum." & vbCrLf & ValuesInfo & vbCrLf & LevelsInfo
End Sub

Private Sub CKEvents_MaxCoinsWarning(ByVal ValuesInfo As String, ByVal NumberInfo As String)
#If DEBUGPRINT Then
    Debug.Print "MaxCoinsWarning ValuesInfo = '" & ValuesInfo & "', NumberInfo = '" & NumberInfo & "'"
#End If
    'If MsgBox("Devolverá muchas monedas." & vbCrLf & ValuesInfo & vbCrLf & NumberInfo & vbCrLf & "¿Desea continuear con el pago?", vbYesNo + vbQuestion) = vbYes Then
    If MsgBox("Too much Coins." & vbCrLf & ValuesInfo & vbCrLf & NumberInfo & vbCrLf & "Do you want to pay anyway?", vbYesNo + vbQuestion) = vbYes Then
        CK.AcceptPending
    Else
        CK.RejectPending
    End If
End Sub

Private Sub CKEvents_NoteHeldInBezel(ByVal NotePresent As Boolean)
#If DEBUGPRINT Then
    Debug.Print "NoteHeldInBezel NotePresent = " & CStr(NotePresent)
#End If
    frmBB.Visible = NotePresent
End Sub

Private Sub CKEvents_ProcessInterrupted(ByVal State As Byte, ByVal Value As Long, ByVal target As Long, ByVal Operation As Byte)
#If DEBUGPRINT Then
    Debug.Print "ProcessInterrupted State = " & CStr(State) & ", Value = " & CStr(Value) & ", Target = " & CStr(target) & ", Operation = " & CStr(Operation)
#End If
End Sub

Private Sub CKEvents_PropertiesChangedRemotely()
#If DEBUGPRINT Then
    Debug.Print "PropertiesChangedRemotely"
#End If
End Sub

Private Sub CKEvents_ProtectedValueNote(ByVal Value As Long, ByVal PayoutNeeds As Long, ByVal TotalChange As Long, ByVal Operation As Byte)
#If DEBUGPRINT Then
    Debug.Print "ProtectedValueNote Value = " & CStr(Value) & ", PayoutNeeds = " & CStr(PayoutNeeds) & ", TotalChange = " & CStr(TotalChange) & ", Operation = " & CStr(Operation)
#End If
    'If MsgBox("Billete mayor de lo permitido (" & (Value \ 100) & "). " & vbCrLf & "Desea aceptar el billete ?", vbYesNo + vbQuestion) = vbYes Then
    If MsgBox("Bank Note bellow the maximum allowed (" & (Value \ 100) & "). " & vbCrLf & "Do you want to accept the note?", vbYesNo + vbQuestion) = vbYes Then
        CK.AcceptPending
    Else
        CK.RejectPending
    End If
End Sub

Private Sub CKEvents_StateChange(ByVal CurrentState As Byte, ByVal OldState As Byte)
#If DEBUGPRINT Then
    Debug.Print "StateChange CurrentState = " & CStr(CurrentState) & ", OldState = " & CStr(OldState)
#End If
    'State = CurrentState
    Select Case CurrentState
        Case 0
            cmdCobrar.Enabled = False
            cmdPagar.Enabled = False
            cmdPagoDetall.Enabled = False
            cmdParcial.Enabled = False
            cmdCompleto.Enabled = False
            cmdLimpiezaMonedas.Enabled = False
            cmdRecaudación.Enabled = False
            cmdHabilitar.Enabled = False
            cmdDeshabilitar.Enabled = False
            cmdForzarNiveles.Enabled = False
            FraOperaciones.Enabled = False
            cmdVersiones.Enabled = False
            FraVaciados.Enabled = False
            FraCobrosPagos.Enabled = False
            cmdReset.Enabled = False
            cmdLimpiezaMonedas.Enabled = False
        Case 1
            cmdCobrar.Enabled = True
            cmdPagar.Enabled = True
            If OldState > 1 Then
                CarregaDenominacions
            End If
            cmdPagoDetall.Enabled = MainCC = CurCC
            cmdParcial.Enabled = MainCC = CurCC
            cmdCompleto.Enabled = True
            cmdLimpiezaMonedas.Enabled = True
            cmdRecaudación.Enabled = True
            cmdHabilitar.Enabled = True
            cmdDeshabilitar.Enabled = False
            cmdForzarNiveles.Enabled = MainCC = CurCC And CMode = HostMachine
            FraOperaciones.Enabled = CMode = HostMachine
            cmdVersiones.Enabled = True
            FraVaciados.Enabled = CMode = HostMachine
            FraCobrosPagos.Enabled = CMode = HostMachine
            cmdReset.Enabled = CMode = HostMachine
            cmdLimpiezaMonedas.Enabled = CMode = HostMachine
        Case 2
            cmdCobrar.Enabled = True
            cmdPagar.Enabled = False
            cmdPagoDetall.Enabled = False
            cmdParcial.Enabled = False
            cmdCompleto.Enabled = False
            cmdLimpiezaMonedas.Enabled = True
            cmdRecaudación.Enabled = False
            cmdHabilitar.Enabled = False
            cmdDeshabilitar.Enabled = True
            cmdForzarNiveles.Enabled = False
            FraOperaciones.Enabled = CMode = HostMachine
            If OldState = 7 Then
                CarregaDenominacions
            End If
            cmdVersiones.Enabled = True
            FraVaciados.Enabled = False
            FraCobrosPagos.Enabled = CMode = HostMachine
            cmdReset.Enabled = CMode = HostMachine
            cmdLimpiezaMonedas.Enabled = CMode = HostMachine
        Case 3
            cmdCobrar.Enabled = False
            cmdPagar.Enabled = False
            cmdPagoDetall.Enabled = False
            cmdParcial.Enabled = False
            cmdCompleto.Enabled = False
            cmdLimpiezaMonedas.Enabled = False
            cmdRecaudación.Enabled = False
            cmdHabilitar.Enabled = False
            cmdDeshabilitar.Enabled = False
            cmdForzarNiveles.Enabled = False
            FraOperaciones.Enabled = False
            cmdVersiones.Enabled = True
            FraVaciados.Enabled = False
            FraCobrosPagos.Enabled = False
            cmdReset.Enabled = CMode = HostMachine
            cmdLimpiezaMonedas.Enabled = False
        Case 4
            CBDisplay = True
            cmdCobrar.Enabled = False
            cmdPagar.Enabled = False
            cmdPagoDetall.Enabled = False
            cmdParcial.Enabled = False
            cmdCompleto.Enabled = False
            cmdLimpiezaMonedas.Enabled = False
            cmdRecaudación.Enabled = False
            cmdHabilitar.Enabled = False
            cmdDeshabilitar.Enabled = False
            cmdForzarNiveles.Enabled = False
            FraOperaciones.Enabled = False
            cmdVersiones.Enabled = True
            FraVaciados.Enabled = False
            FraCobrosPagos.Enabled = False
            cmdReset.Enabled = CMode = HostMachine
            cmdLimpiezaMonedas.Enabled = False
        Case 5
            CBDisplay = True
            cmdCobrar.Enabled = False
            cmdPagar.Enabled = False
            cmdPagoDetall.Enabled = False
            cmdParcial.Enabled = False
            cmdCompleto.Enabled = False
            cmdLimpiezaMonedas.Enabled = False
            cmdRecaudación.Enabled = False
            cmdHabilitar.Enabled = False
            cmdDeshabilitar.Enabled = False
            cmdForzarNiveles.Enabled = False
            FraOperaciones.Enabled = False
            cmdVersiones.Enabled = True
            FraVaciados.Enabled = False
            FraCobrosPagos.Enabled = False
            cmdReset.Enabled = CMode = HostMachine
            cmdLimpiezaMonedas.Enabled = False
        Case 6
            cmdCobrar.Enabled = False
            cmdPagar.Enabled = False
            cmdPagoDetall.Enabled = False
            cmdParcial.Enabled = False
            cmdCompleto.Enabled = False
            cmdLimpiezaMonedas.Enabled = False
            cmdRecaudación.Enabled = False
            cmdHabilitar.Enabled = False
            cmdDeshabilitar.Enabled = False
            cmdForzarNiveles.Enabled = False
            FraOperaciones.Enabled = False
            cmdVersiones.Enabled = True
            FraVaciados.Enabled = False
            FraCobrosPagos.Enabled = False
            cmdReset.Enabled = CMode = HostMachine
            cmdLimpiezaMonedas.Enabled = False
        Case 7
            cmdCobrar.Enabled = True
            cmdPagar.Enabled = False
            cmdPagoDetall.Enabled = False
            cmdParcial.Enabled = False
            cmdCompleto.Enabled = False
            cmdLimpiezaMonedas.Enabled = False
            cmdRecaudación.Enabled = False
            cmdHabilitar.Enabled = False
            cmdDeshabilitar.Enabled = False
            cmdForzarNiveles.Enabled = False
            FraOperaciones.Enabled = False
            cmdVersiones.Enabled = True
            FraVaciados.Enabled = False
            FraCobrosPagos.Enabled = CMode = HostMachine
            cmdReset.Enabled = CMode = HostMachine
            cmdLimpiezaMonedas.Enabled = CMode = HostMachine
    End Select
End Sub

Private Sub CKEvents_ValueIN(ByVal CurrentValue As Long, ByVal target As Long, ByVal Operation As Byte)
#If DEBUGPRINT Then
    Debug.Print "ValueIN CurrentValue = " & CStr(CurrentValue) & ", Target = " & CStr(target) & ", Operation = " & CStr(Operation)
#End If
    txtVal.text = Format$(CCur(Replace(CurrentValue, ".", ",")) / 100, "standard")
End Sub

Private Sub CKEvents_ValueOUT(ByVal CurrentValue As Long, ByVal target As Long, ByVal Operation As Byte)
#If DEBUGPRINT Then
    Debug.Print "ValueOUT CurrentValue = " & CStr(CurrentValue) & ", Target = " & CStr(target) & ", Operation = " & CStr(Operation)
#End If
    txtVal.text = Format$(CCur(Replace(CurrentValue, ".", ",")) / 100, "standard")
End Sub

Private Sub CKEvents_ValueToCashBox(ByVal CurrentValue As Long, ByVal target As Long, ByVal Operation As Byte)
    Dim Line1 As String
    Dim Line2 As String
    
#If DEBUGPRINT Then
    Debug.Print "ValueToCashBox CurrentValue = " & CStr(CurrentValue) & ", Target = " & CStr(target) & ", Operation = " & CStr(Operation)
#End If
    If CBDisplay Then
        Line1 = Format$(target / 100, "standard")
        Line1 = "Total:" & Space$(20 - 6 - Len(Line1)) & Line1
        Line2 = Format$(CurrentValue / 100, "standard")
        'Line2 = "Vaciado:" & Space$(20 - 8 - Len(Line2)) & Line2
        Line2 = "Emptied:" & Space$(20 - 8 - Len(Line2)) & Line2
        CK.Display Line1, Line2
    End If
    txtCB.text = Format$(CCur(Replace(CurrentValue, ".", ",")) / 100, "standard")
End Sub

Private Sub CKEvents_Warning(ByVal code As Long, ByVal Description As String)
#If DEBUGPRINT Then
    Debug.Print "Warning " & CStr(code) & "-" & Description
#End If
    MsgBox CStr(code) & "-" & Description, vbExclamation + vbOKOnly
End Sub

Private Sub cmdAsignar_Click()
    Dim canvi As Long
    
    canvi = CLng(txtCambio.text)
    If Not CK.SetCCChange(CurCC, canvi) Then
        MsgBox "Error: " & CK.ErrorCode & "-" & CK.ErrorDescription
    End If
End Sub

Private Sub cmdCobrar_Click()
    Dim t As Long
    'If CK.State = 1 Then
    '    txtVal.text = Format$(0, "standard")
    'End If
    If Not CK.Totalize(CCur(txtImp.text) * 100, True) Then
        MsgBox "Error: " & CK.ErrorCode & "-" & CK.ErrorDescription
        
    Else
        CK.ValueIN t
        txtVal.text = Format$(CCur(t) / 100, "standard")
    End If
End Sub

Private Sub cmdCompleto_Click()
    Dim frm As New frmEmpty
    
    txtCB.text = Format$(0, "standard")
    Load frm
    frm.CB = False
    frm.Show vbModal
    'Unload frm
    'MostraDenominacions
    
    'If Not CK.EmptyDevice(LCCB_All) Then
    '    MsgBox "error EmptyDevice"
    'End If
    'CBDisplay = True
End Sub

Private Sub cmdDeshabilitar_Click()
    Dim Devolver As Boolean
    Dim val As Long
    
    If Not CK.ValueIN(val) Then
        MsgBox "Error: " & CK.ErrorCode & "-" & CK.ErrorDescription
    End If
    If val > 0 Then
        'Devolver = MsgBox("¿Desea devolver el importe introducido?", vbQuestion + vbYesNo) = vbYes
        Devolver = MsgBox("Do you want to pay back the introduced amount?", vbQuestion + vbYesNo) = vbYes
    End If
    If Not CK.Disable(Devolver) Then
        MsgBox "Error: " & CK.ErrorCode & "-" & CK.ErrorDescription
    End If
End Sub

Private Sub cmdForzarNiveles_Click()
    Dim frm As New frmFCL
    
    Load frm
    frm.ShowFCL
    frm.Show vbModal
    Unload frm
    CarregaDenominacions
End Sub

Private Sub cmdHabilitar_Click()
    Dim t As Long
    
    If Not CK.Enable() Then
        MsgBox "Error: " & CK.ErrorCode & "-" & CK.ErrorDescription
        txtImp.text = 0
        txtVal.text = 0
    Else
        CK.TargetValue t
        txtImp.text = Format$(CCur(t) / 100, "standard")
        CK.ValueIN t
        txtVal.text = Format$(CCur(t) / 100, "standard")
    End If
End Sub

Private Sub cmdInhibits_Click()
    Dim frm As New frmInh
    
    Load frm
    frm.ShowInh
    frm.Show vbModal
    Unload frm
    MostraDenominacions
End Sub

Private Sub cmdLimpiezaMonedas_Click()
    Dim ok As Boolean
    
    'If MsgBox("¿Desea realizar una limpieza completa?", vbQuestion + vbYesNo + vbDefaultButton1) = vbYes Then
    If MsgBox("Do you want to do a complete cleanning?", vbQuestion + vbYesNo + vbDefaultButton1) = vbYes Then
        ok = CK.CleanBulk(True)
    Else
        ok = CK.CleanBulk(False)
    End If
    If Not ok Then
        MsgBox "Error CleanBulk"
    End If
End Sub

Private Sub cmdMáximos_Click()
    Dim frm As New frmMax
    
    Load frm
    frm.ShowMax
    frm.Show vbModal
    Unload frm
    MostraDenominacions
End Sub

Private Sub cmdMínimos_Click()
    Dim frm As New frmMin
    
    Load frm
    frm.ShowMin
    frm.Show vbModal
    Unload frm
    MostraDenominacions
End Sub

Private Sub cmdOpciones_Click()
    Dim frm As New frmOpt
    
    Load frm
    'frm.ShowPay
    frm.Show vbModal
    Unload frm
    'MostraDenominacions
End Sub

Private Sub cmdPagar_Click()
    If Not CK.Pay(CLng(CCur(txtImp.text) * 100)) Then
        If CK.ErrorCode <> 23 Then
            MsgBox "Error " & CK.ErrorCode & "-" & CK.ErrorDescription
        End If
    Else
        txtVal.text = Format$(0, "standard")
    End If
End Sub

Private Sub cmdPagoDetall_Click()
    Dim frm As New frmPaySpecific
    
    Load frm
    frm.ShowPay
    frm.Show vbModal
    Unload frm
    If CK.State > 1 Then
        txtVal.text = Format$(0, "standard")
    End If
    MostraDenominacions
End Sub

Private Sub cmdParcial_Click()
    Dim frm As New frmPaySpecific
    
    txtCB.text = Format$(0, "standard")
    Load frm
    frm.NotPay = True
    frm.ShowPay
    frm.Show vbModal
    Unload frm
    MostraDenominacions
End Sub

Private Sub cmdRecaudación_Click()
    Dim frm As New frmEmpty
    
    Load frm
    frm.CB = True
    frm.Show vbModal
    If OptCashBox.Value = True Then
        OptCashBox_Click
    End If
End Sub

Private Sub cmdReset_Click()
    cmdReset.BackColor = vbGreen
    Me.Enabled = False
    CK.Reset
    Me.Enabled = True
    cmdReset.BackColor = vbRed
End Sub

Private Sub cmdVersiones_Click()
    Dim st1 As String
    Dim st2 As String
    Dim st3 As String
    
    If CK.GetFirmWareVersion(LCLD_CoinValidator, st1, st3) Then
        'st2 = "Validador monedas " & vbTab & vbTab & "Firmware" & vbTab & ": " & st1
        st2 = "Coins Validator  " & vbTab & vbTab & "Firmware" & vbTab & ": " & st1
        If CK.GetFirmWareVersion(LCLD_CoinDispenser, st1, st3) Then
            'st2 = st2 & vbCrLf & "Reciclador monedas " & vbTab & "Firmware" & vbTab & ": " & st1 & vbCrLf & vbTab & vbTab & vbTab & "DataSet" & vbTab & ": " & st3
            st2 = st2 & vbCrLf & "Coins Recycler" & vbTab & vbTab & "Firmware" & vbTab & ": " & st1 & vbCrLf & vbTab & vbTab & vbTab & "DataSet" & vbTab & ": " & st3
            If CK.GetFirmWareVersion(LCLD_NoteRecycler, st1, st3) Then
                'st2 = st2 & vbCrLf & "Reciclador billetes " & vbTab & vbTab & "Firmware" & vbTab & ": " & st1 & vbCrLf & vbTab & vbTab & vbTab & "DataSet" & vbTab & ": " & st3
                st2 = st2 & vbCrLf & "Bank Notes Recycler" & vbTab & vbTab & "Firmware" & vbTab & ": " & st1 & vbCrLf & vbTab & vbTab & vbTab & "DataSet" & vbTab & ": " & st3
                MsgBox st2, vbInformation + vbOKOnly
            End If
        End If
    End If
End Sub

Private Sub Form_Activate()
    Dim OtherCC As String
    
    If Not once Then
        once = True
        If Not CK.GetCountryCodes(MainCC, OtherCC) Then
            MsgBox "GetCountryCodes falla"
            Unload Me
            Exit Sub
        End If
        cboMoneda.AddItem MainCC
        If Len(OtherCC) > 0 Then
            Dim arr As Variant
            Dim i As Integer
            
            arr = Split(OtherCC, ",")
            For i = LBound(arr) To UBound(arr)
                cboMoneda.AddItem arr(i)
            Next i
        End If
        cboMoneda.ListIndex = 0
        CKEvents_StateChange 1, 0
    End If
End Sub

Private Sub Form_Initialize()
    Set CKEvents = CK
    ReDim CCC(0)
    LBCCC = LBound(CCC)
    UBCCC = UBound(CCC)
    ReDim CCN(0)
    LBCCN = LBound(CCN)
    UBCCN = UBound(CCN)
End Sub

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    Dim ti As LC_Smart_Devices
    Dim ok As Boolean
    Dim fw As String
    Dim ds As String
    Dim nomFic As String
    
    On Error GoTo fin
    If KeyCode = vbKeyU And Shift = 7 Then
        nomFic = LKCommon("A")
        If Len(nomFic) > 0 Then
            ok = CK.CheckSmartFirmwareFile(nomFic, ti, fw, ds)
            If ok Then
                CKEvents_StateChange 6, 1
                ok = CK.UpdateSmartFirmware(nomFic, ti)
                Sleep 3000
                ok = CK.StartUp(CK.ConfigID)
                once = False
                cboMoneda.Clear
                Form_Activate
            End If
        End If
    End If
fin:
End Sub

Private Sub Form_Load()
    Dim filtre As String
    
    CentraForm Me
    filtre = "All Firmware Files|*.bv1;*.bin|Smart Hopper|*SH*.bv1|Smart Payout|*NV0200*.bv1|Note Float|*NV0009*.bv1|PCB|*.bin"
    PreparaOpenDialog "A", Me, "Log Analizer", filtre, "", "", False
End Sub

Private Sub MostraDenominacions()
    Dim i As Integer
    
    lstDenoms.Clear
    If CurCC = MainCC Then
        'lstDenoms.AddItem "Monedas"
        lstDenoms.AddItem "Coins"
        'lstDenoms.AddItem "       Valor Mínimo Máximo Inhibición Actual"
        lstDenoms.AddItem "       Value  Minim  Maxim  Inhibit  Current"
        For i = LBCCC To UBCCC
            lstDenoms.AddItem JustificaD(Formateja(CCC(i).Valor), 12) & JustificaD(CStr(CCC(i).low), 7) & JustificaD(CStr(CCC(i).max), 7) & _
            JustificaD(CStr(CCC(i).Inhibit), 6) & JustificaD(CStr(CCC(i).current), 12)
        Next i
    End If
    If UBCCN > 0 Then
        'lstDenoms.AddItem "Billetes"
        lstDenoms.AddItem "Bank Notes"
        'lstDenoms.AddItem "       Valor Mínimo Máximo Inhibición Actual"
        lstDenoms.AddItem "       Value  Minim  Maxim  Inhibit  Current"
        For i = LBCCN To UBCCN
            lstDenoms.AddItem JustificaD(Formateja(CCN(i).Valor), 12) & JustificaD(CStr(CCN(i).low), 7) & JustificaD(CStr(CCN(i).max), 7) & _
            JustificaD(CStr(CCN(i).Inhibit), 6) & JustificaD(CStr(CCN(i).current), 12)
        Next i
    End If
End Sub

Private Function Formateja(ByVal impo As Long) As String
    Formateja = Format$(CCur(impo) / 100, "standard")
End Function

Private Function JustificaD(ByVal text As String, ByVal tam As Integer) As String
    If Len(text) > tam Then
        JustificaD = Right$(Space$(tam) & " ...", tam)
    Else
        JustificaD = Right$(Space$(tam) & text, tam)
    End If
End Function

Private Function JustificaE(ByVal text As String, ByVal tam As Integer) As String
    If Len(text) > tam Then
        JustificaE = left$("..." & Space$(tam), tam)
    Else
        JustificaE = left$(text & Space$(tam), tam)
    End If
End Function

Private Sub Form_Unload(Cancel As Integer)
    If CK.State <> 0 Then
        CK.Terminate
    End If
    Set CK = Nothing
    Set CKEvents = Nothing
End Sub

Private Sub OptCambio_Click()
    cmdMáximos.Enabled = (CurCC = MainCC) And (OptCambio.Value = True)
    cmdMínimos.Enabled = (CurCC = MainCC) And (OptCambio.Value = True)
    MostraDenominacions
End Sub

Private Sub OptCashBox_Click()
    Dim i As Integer
    Dim CCA As Variant
    Dim ValA As Variant
    Dim QtyA As Variant
    Dim CCs As String
    Dim val As String
    Dim qty As String
    Dim totals As New Collection
    'Dim l As Long
    Dim cbi As CBDenom
    
    cmdMáximos.Enabled = (CurCC = MainCC) And (OptCambio.Value = True)
    cmdMínimos.Enabled = (CurCC = MainCC) And (OptCambio.Value = True)
    If Not CK.GetCashBoxLevel(CCs, val, qty) Then
        'MsgBox "GetCashBoxLevel falla"
        MsgBox "GetCashBoxLevel fail"
        Exit Sub
    End If
    lstDenoms.Clear
    If Len(CCs) = 0 Then
        'lstDenoms.AddItem "CashBox vacio"
        lstDenoms.AddItem "CashBox empty"
        Exit Sub
    End If
    CCA = Split(CCs, ",")
    ValA = Split(val, ",")
    QtyA = Split(qty, ",")
    'lstDenoms.AddItem "Moneda  Valor Contenido"
    lstDenoms.AddItem "Currency Value  Quantity"
    For i = LBound(CCA) To UBound(CCA)
        Set cbi = ColIteExist(totals, CStr(CCA(i)))
        cbi.Valor = cbi.Valor + (CLng(ValA(i)) * CInt(QtyA(i)))
        lstDenoms.AddItem JustificaE(CCA(i), 3) & JustificaD(Formateja(ValA(i)), 11) & JustificaD(QtyA(i), 10)
    Next i
    'lstDenoms.AddItem "Totales   Moneda Contenido"
    lstDenoms.AddItem " Totals   Currency  Amount"
    For Each cbi In totals
        lstDenoms.AddItem Space$(10) & JustificaE(cbi.CC, 6) & JustificaD(Formateja(cbi.Valor), 10)
    Next
End Sub

Private Function ColIteExist(ByRef col As Collection, ByVal clau As String) As CBDenom
    'Dim ok As Variant
    Dim ret As CBDenom
    
    Err.Clear
    On Error Resume Next
    Set ret = col.Item(clau)
    If Err.Number <> 0 Then
        Set ret = New CBDenom
        ret.CC = clau
        ret.Valor = 0
        col.Add ret, clau
    End If
    Set ColIteExist = ret
End Function

Private Sub OptOP_Click(Index As Integer)
    Dim Valor As Long
    
    If Not CK.AlternateOperation(Index) Then
        MsgBox "Error " & CK.ErrorCode & "-" & CK.ErrorDescription
    Else
        If Not CK.ValueIN(Valor) Then
            MsgBox "Error " & CK.ErrorCode & "-" & CK.ErrorDescription
        Else
            txtVal.text = Format$(CCur(Valor) / 100, "standard")
        End If
        If Not CK.TargetValue(Valor) Then
            MsgBox "Error " & CK.ErrorCode & "-" & CK.ErrorDescription
        Else
            txtImp.text = Format$(CCur(Valor) / 100, "standard")
        End If
    End If
End Sub

Private Sub txtImp_GotFocus()
    txtImp.SelStart = 0
    txtImp.SelLength = Len(txtImp.text)
End Sub

Private Sub txtImp_LostFocus()
    Dim s As String
    
    s = txtImp.text
    If Len(s) = 0 Then
        s = "0,00"
    Else
        s = Replace(s, ".", ",")
        If Not IsNumeric(s) Then
            s = "0,00"
        Else
            s = Format$(CCur(s), "standard")
        End If
    End If
    txtImp.text = s
End Sub

Private Sub txtImp_Validate(Cancel As Boolean)
    Dim s As String
    
    s = txtImp.text
    If Len(s) = 0 Then
        Cancel = False
    ElseIf Not IsNumeric(Replace(s, ".", ",")) Then
        Cancel = True
    End If
End Sub
