VERSION 5.00
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
Object = "{6B7E6392-850A-101B-AFC0-4210102A8DA7}#1.3#0"; "COMCTL32.OCX"
Begin VB.Form frmMain 
   BorderStyle     =   3  '크기 고정 대화 상자
   Caption         =   "UCBioBSPCOM FastSearchDemo for VB"
   ClientHeight    =   8595
   ClientLeft      =   45
   ClientTop       =   345
   ClientWidth     =   7245
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   8595
   ScaleWidth      =   7245
   ShowInTaskbar   =   0   'False
   StartUpPosition =   3  'Windows 기본값
   Begin VB.CommandButton btnClose 
      Caption         =   "Close"
      Height          =   375
      Left            =   5400
      TabIndex        =   11
      Top             =   8040
      Width           =   1575
   End
   Begin MSComDlg.CommonDialog CommonDialog 
      Left            =   120
      Top             =   7920
      _ExtentX        =   847
      _ExtentY        =   847
      _Version        =   393216
   End
   Begin VB.Frame Frame3 
      Caption         =   "3) Identify (1:N)"
      Height          =   1935
      Left            =   120
      TabIndex        =   14
      Top             =   5880
      Width           =   6975
      Begin VB.TextBox txtMaxtime 
         Height          =   375
         Left            =   3000
         TabIndex        =   8
         Text            =   "Text1"
         Top             =   360
         Width           =   855
      End
      Begin VB.CommandButton cmdIdentify 
         Caption         =   "Identify fingerprint from DB"
         Height          =   375
         Left            =   4080
         TabIndex        =   9
         Top             =   360
         Width           =   2535
      End
      Begin ComctlLib.ListView ListResult 
         Height          =   735
         Left            =   240
         TabIndex        =   10
         Top             =   960
         Width           =   6495
         _ExtentX        =   11456
         _ExtentY        =   1296
         View            =   3
         LabelWrap       =   -1  'True
         HideSelection   =   -1  'True
         _Version        =   327682
         ForeColor       =   -2147483640
         BackColor       =   -2147483643
         BorderStyle     =   1
         Appearance      =   1
         NumItems        =   3
         BeginProperty ColumnHeader(1) {0713E8C7-850A-101B-AFC0-4210102A8DA7} 
            Key             =   ""
            Object.Tag             =   ""
            Text            =   "UserID"
            Object.Width           =   3352
         EndProperty
         BeginProperty ColumnHeader(2) {0713E8C7-850A-101B-AFC0-4210102A8DA7} 
            SubItemIndex    =   1
            Key             =   ""
            Object.Tag             =   ""
            Text            =   "Finger ID"
            Object.Width           =   2999
         EndProperty
         BeginProperty ColumnHeader(3) {0713E8C7-850A-101B-AFC0-4210102A8DA7} 
            SubItemIndex    =   2
            Key             =   ""
            Object.Tag             =   ""
            Text            =   "Sample Num"
            Object.Width           =   2999
         EndProperty
      End
      Begin VB.Label Label3 
         Alignment       =   2  '가운데 맞춤
         Caption         =   "(0 = No timeout)"
         Height          =   255
         Left            =   360
         TabIndex        =   16
         Top             =   600
         Width           =   2415
      End
      Begin VB.Label Label2 
         Caption         =   "Max identification time (sec):"
         Height          =   255
         Left            =   360
         TabIndex        =   15
         Top             =   360
         Width           =   2655
      End
   End
   Begin VB.Frame Frame2 
      Caption         =   "2) Fast search DB"
      Height          =   4335
      Left            =   120
      TabIndex        =   13
      Top             =   1320
      Width           =   6975
      Begin VB.CommandButton cmdLoad 
         Caption         =   "Load DB"
         Height          =   375
         Left            =   5280
         TabIndex        =   7
         Top             =   3720
         Width           =   1335
      End
      Begin VB.CommandButton cmdSave 
         Caption         =   "Save DB"
         Height          =   375
         Left            =   3600
         TabIndex        =   6
         Top             =   3720
         Width           =   1335
      End
      Begin VB.CommandButton cmdDelete 
         Caption         =   "Delete Data"
         Height          =   375
         Left            =   1920
         TabIndex        =   5
         Top             =   3720
         Width           =   1335
      End
      Begin VB.CommandButton cmdClear 
         Caption         =   "Clear DB"
         Height          =   375
         Left            =   360
         TabIndex        =   4
         Top             =   3720
         Width           =   1215
      End
      Begin ComctlLib.ListView ListSearchDB 
         Height          =   3255
         Left            =   240
         TabIndex        =   3
         Top             =   360
         Width           =   6495
         _ExtentX        =   11456
         _ExtentY        =   5741
         View            =   3
         LabelWrap       =   -1  'True
         HideSelection   =   -1  'True
         _Version        =   327682
         ForeColor       =   -2147483640
         BackColor       =   -2147483643
         BorderStyle     =   1
         Appearance      =   1
         NumItems        =   3
         BeginProperty ColumnHeader(1) {0713E8C7-850A-101B-AFC0-4210102A8DA7} 
            Key             =   ""
            Object.Tag             =   ""
            Text            =   "UserID"
            Object.Width           =   3352
         EndProperty
         BeginProperty ColumnHeader(2) {0713E8C7-850A-101B-AFC0-4210102A8DA7} 
            SubItemIndex    =   1
            Key             =   ""
            Object.Tag             =   ""
            Text            =   "Finger ID"
            Object.Width           =   2999
         EndProperty
         BeginProperty ColumnHeader(3) {0713E8C7-850A-101B-AFC0-4210102A8DA7} 
            SubItemIndex    =   2
            Key             =   ""
            Object.Tag             =   ""
            Text            =   "Sample Num"
            Object.Width           =   2999
         EndProperty
      End
   End
   Begin VB.Frame Frame1 
      Caption         =   "1) Enrollment"
      Height          =   975
      Left            =   120
      TabIndex        =   0
      Top             =   120
      Width           =   6975
      Begin VB.CommandButton cmdEnroll 
         Caption         =   "Enroll fingerprint to DB"
         Height          =   375
         Left            =   3840
         TabIndex        =   2
         Top             =   360
         Width           =   2655
      End
      Begin VB.TextBox txtUserID 
         Height          =   375
         Left            =   1800
         TabIndex        =   1
         Text            =   "Text1"
         Top             =   360
         Width           =   1575
      End
      Begin VB.Label Label1 
         Caption         =   "User ID:"
         Height          =   375
         Left            =   720
         TabIndex        =   12
         Top             =   480
         Width           =   855
      End
   End
End
Attribute VB_Name = "frmMain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
' Declaration global variables
Dim WithEvents objUCBioBSP As UCBioBSPCOMLib.UCBioBSP
Attribute objUCBioBSP.VB_VarHelpID = -1

Dim objDevice As IDevice                ' Device object
Dim objExtraction As IExtraction        ' Extraction object
Dim objFastSearch As IFastSearch        ' FastSearch object

Dim szTextFIR As String

Private Sub btnClose_Click()
    End
End Sub

Private Sub cmdClear_Click()
    ' Clear ListView of SearchDB
    Call ListSearchDB.ListItems.Clear

    ' Clear FastSearchDB
    Call objFastSearch.ClearDB
End Sub

Private Sub cmdDelete_Click()
    Dim nUserID, nFingerID, nSampleNumber As Long

    If ListSearchDB.ListItems.Count <= 0 Then
        Exit Sub
    End If

    If ListSearchDB.SelectedItem.Selected = False Then
        MsgBox "Select item ...", vbOKOnly, "Error"
        Exit Sub
    End If

    nUserID = CLng(ListSearchDB.SelectedItem.Text)
    nFingerID = CLng(ListSearchDB.SelectedItem.SubItems(1))
    nSampleNumber = CLng(ListSearchDB.SelectedItem.SubItems(2))

    Call objFastSearch.RemoveFp(nUserID, nFingerID, nSampleNumber)

    If objUCBioBSP.ErrorCode = 0 Then
        Call ListSearchDB.ListItems.Remove(ListSearchDB.SelectedItem.Index)
        If ListSearchDB.ListItems.Count > 0 Then
            ListSearchDB.SelectedItem.Selected = False
        End If
        MsgBox "Succeeded to delete data!", vbOKOnly, "Success"
    Else
        MsgBox objUCBioBSP.ErrorDescription & " [" & objUCBioBSP.ErrorCode & "]", vbOKOnly, "Error"
    End If
End Sub

Private Sub cmdEnroll_Click()
    Dim i, j As Integer
    Dim nUserID As Long
    Dim szFir As String
    Dim ListItem As ListItem
    
    Dim objAddedFpInfo As ITemplateInfo         ' TemplateInfo object
    
    nUserID = 0
    szFir = ""
    
    ' Get User ID
    If Not IsNumeric(txtUserID.Text) Then
        MsgBox "User ID must be have numeric type and greater than 0.", vbOKOnly, "Error"
        Exit Sub
    End If

    nUserID = CInt(txtUserID.Text)
    
    ' Open Device
    Call objDevice.Open(&HFF)    ' 0xFF : Auto detect to device ID
    
    ' Get FIR data
    Call objExtraction.Enroll(Null)
    If objUCBioBSP.ErrorCode = 0 Then
        szFir = objExtraction.TextFIR
    
        ' Regist FIR to FastSearch DB
        Call objFastSearch.AddFIR(szFir, nUserID)
        If objUCBioBSP.ErrorCode = 0 Then
            ' Add item to list of SearchDB
            j = objFastSearch.AddedFpCount

            For i = 0 To (j - 1)
                Set objAddedFpInfo = objFastSearch.AddedFpInfo(i)
                If objUCBioBSP.ErrorCode = 0 Then
                    Set ListItem = ListSearchDB.ListItems.Add
                    ListItem.Text = objAddedFpInfo.UserID
                    ListItem.SubItems(1) = objAddedFpInfo.FingerID
                    ListItem.SubItems(2) = objAddedFpInfo.SampleNumber
                    Set ListItem = Nothing
                End If
            Next
                
            txtUserID.Text = CInt(txtUserID.Text) + 1
            ListSearchDB.SelectedItem.Selected = False
        Else
            MsgBox objUCBioBSP.ErrorDescription & " [" & objUCBioBSP.ErrorCode & "]"
        End If
    Else
        MsgBox objUCBioBSP.ErrorDescription & " [" & objUCBioBSP.ErrorCode & "]"
    End If
    
    ' Close Device
    Call objDevice.Close(&HFF)   ' 0xFF : Auto detect to device ID
End Sub

Private Sub cmdIdentify_Click()
    Dim i As Integer
    Dim szTextFIR As String
    Dim ListItem As ListItem
    Dim objMatchedFpInfo As ITemplateInfo
    
    ' Get MaxTime
    If Not IsNumeric(txtMaxtime.Text) Then
        MsgBox "The value of the max identification time must be have numeric type and greater than 0.", vbOKOnly, "Error"
        Exit Sub
    End If

    ' Set MaxTime for IdentifyUser
    objFastSearch.MaxSearchTime = CInt(txtMaxtime.Text) * 1000  ' Convert millisec to second..
        
    nUserID = 0
    szTextFIR = ""
    Call ListResult.ListItems.Clear
    
    ' Get FIR data
    Call objDevice.Open(&HFF)    ' 0xFF : Auto detect to device ID
    Call objExtraction.Capture(2)   ' 2 : Capture for identify purpose
    If objUCBioBSP.ErrorCode = 0 Then
        szTextFIR = objExtraction.TextFIR
    
        ' Identify FIR to IndexSearch DB
        Call objFastSearch.IdentifyUser(szTextFIR, 5) ' 5 : Normal security level..
    
        If objUCBioBSP.ErrorCode = 0 Then
            Set objMatchedFpInfo = objFastSearch.MatchedFpInfo
            If objUCBioBSP.ErrorCode = 0 Then
                ' Add item to list of result
                Set ListItem = ListResult.ListItems.Add
                ListItem.Text = objMatchedFpInfo.UserID
                ListItem.SubItems(1) = objMatchedFpInfo.FingerID
                ListItem.SubItems(2) = objMatchedFpInfo.SampleNumber
                Set ListItem = Nothing
            End If
        Else
            MsgBox objUCBioBSP.ErrorDescription & " [" & objUCBioBSP.ErrorCode & "]", vbOKOnly, "Error"
        End If
    Else
        MsgBox objUCBioBSP.ErrorDescription & " [" & objUCBioBSP.ErrorCode & "]"
    End If

    Call objDevice.Close(&HFF)   ' 0xFF : Auto detect to device ID
End Sub

Private Sub cmdLoad_Click()
    Dim i, nTmp As Integer
    Dim val
    Dim szTemp As String
    Dim szFileName As String
    Dim nUserID, nFingerID, nSampleNumber As Long
    Dim objFpInfo As ITemplateInfo

    i = MsgBox("If you load database from file, existing memory database will be cleared!" + Chr(13) + "Are you sure you want to load database?", vbYesNo Or vbQuestion)
    If i <> VbMsgBoxResult.vbYes Then
        Exit Sub
    End If
    
    CommonDialog.CancelError = True
    CommonDialog.Filter = "UFS Files (*.UFS)|*.UFS|All Files|*.*||"
    On Error Resume Next
    CommonDialog.ShowOpen
    
    If Err.Number = cdlCancel Then
        On Error GoTo 0
        Exit Sub
    End If
        
        
    ' Clear ListView of SearchDB
    Call ListSearchDB.ListItems.Clear
    ' Clear FastSearchDB
    Call objFastSearch.ClearDB
        
    
    szFileName = ""
    szFileName = CommonDialog.FileName
    If szFileName <> "" Then

        ' Load SearchDB from File
        Call objFastSearch.LoadDBFromFile(szFileName)

        If objUCBioBSP.ErrorCode <> 0 Then
            MsgBox objUCBioBSP.ErrorDescription & " [" & objUCBioBSP.ErrorCode & "]", vbOKOnly, "Error"
            Exit Sub
        End If

        ' Read fp info
        
        ' We support three different way to read fp info..
        '
        ' 1)
        '   nTmp = objFastSearch.FpCount
        '   For i = 0 To (nTmp - 1)
        '     Set objFpInfo = objFastSearch.FpInfo(i)
        '     If objUCBioBSP.ErrorCode = 0 Then
        '         Set ListItem = ListSearchDB.ListItems.Add
        '         ListItem.Text = objFpInfo.UserID
        '         ListItem.SubItems(1) = objFpInfo.FingerID
        '         ListItem.SubItems(2) = objFpInfo.SampleNumber
        '         Set ListItem = Nothing
        '     End If
        '   Next
        '
        ' 2)
        '   nTmp = objFastSearch.FpCount
        '   For i = 0 To (nTmp - 1)
        '     Set objFpInfo = objFastSearch(i)   ' <-- different point between 1) and 2)
        '     If objUCBioBSP.ErrorCode = 0 Then
        '         Set ListItem = ListSearchDB.ListItems.Add
        '         ListItem.Text = objFpInfo.UserID
        '         ListItem.SubItems(1) = objFpInfo.FingerID
        '         ListItem.SubItems(2) = objFpInfo.SampleNumber
        '         Set ListItem = Nothing
        '     End If
        '   Next
        '
        ' 3)
        '   For Each objFpInfo In objFastSearch   ' <-- different point between 1), 2) and 3)
        '     Set ListItem = ListSearchDB.ListItems.Add
        '     ListItem.Text = objFpInfo.UserID
        '     ListItem.SubItems(1) = objFpInfo.FingerID
        '     ListItem.SubItems(2) = objFpInfo.SampleNumber
        '     Set ListItem = Nothing
        '   Next
        
        ' In this sample, we used 3) way to read fp info..
        For Each objFpInfo In objFastSearch
            Set ListItem = ListSearchDB.ListItems.Add
            ListItem.Text = objFpInfo.UserID
            ListItem.SubItems(1) = objFpInfo.FingerID
            ListItem.SubItems(2) = objFpInfo.SampleNumber
            Set ListItem = Nothing
        Next

        MsgBox "Succeeded to load FastSearchDB from file!", vbOKOnly, "Success"
    Else
        MsgBox "You must enter filename!", vbOKOnly, "Error"
    End If
End Sub

Private Sub cmdSave_Click()
    Dim i
    Dim szFileName As String
    Dim nUserID, nFingerID, nSampleNumber As Long
    
    CommonDialog.CancelError = True
    CommonDialog.Filter = "UFS Files (*.UFS)|*.UFS|All Files|*.*||"
    On Error Resume Next
    CommonDialog.ShowSave
    
    If Err.Number = cdlCancel Then
        On Error GoTo 0
        Exit Sub
    End If
    
    szFileName = ""
    szFileName = CommonDialog.FileName
    If szFileName <> "" Then
    
        ' Save SearchDB to File
        Call objFastSearch.SaveDBToFile(szFileName)
    
        If objUCBioBSP.ErrorCode <> 0 Then
            MsgBox objUCBioBSP.ErrorDescription & " [" & objUCBioBSP.ErrorCode & "]", vbOKOnly, "Error"
            Exit Sub
        End If
        
        MsgBox "Succeeded to save FastSearchDB to file!", vbOKOnly, "Success"
    Else
        MsgBox "You must enter filename!", vbOKOnly, "Error"
    End If
End Sub

Private Sub Form_Load()
    ' Set default value
    szTextFIR = ""
    txtUserID.Text = 1
    txtMaxtime = 0  ' 0 : No timeout..
    
    ListSearchDB.ListItems.Clear
    
    ' Create UCBioBSP object
    Set objUCBioBSP = New UCBioBSPCOMLib.UCBioBSP
    Set objDevice = objUCBioBSP.Device
    Set objExtraction = objUCBioBSP.Extraction
    Set objFastSearch = objUCBioBSP.FastSearch
    
    ' Check initialize object
    If objUCBioBSP.ErrorCode = 0 Then
        ' Get UCBioBSP version
        frmMain.Caption = "UCBioBSPCOM_FastSearchDemo Demo for VB - UCBioBSP Version : " & objUCBioBSP.MajorVersion & "." & objUCBioBSP.MinorVersion
    Else
        MsgBox objUCBioBSP.ErrorDescription & " [" & objUCBioBSP.ErrorCode & "]", vbOKOnly
    End If
End Sub
