1

我们正在使用数字角色进行生物识别。我们已经可以保存员工 ID、员工姓名和分配的手指。我们的问题是我们不知道如何将指纹模板保存到数据库并检索它,以便生物识别扫描仪仍然可以读取和验证它。文件扩展名为“.ftp”。

代码:

Private Sub buttonRegister_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles buttonRegister.Click

        'Does user already exists
        Dim bUserExists As Boolean = _Users.UserExists(New UserID(textBoxUserName.Text))

        ' first make sure the user is created if new user
        If _ActiveUser Is Nothing Or Not bUserExists Then
            ' initialize with supplied user name
            _ActiveUser = New User(textBoxUserName.Text)
        Else
            ' update active user if not as originally selected
            If bUserExists And Not listBoxUsers.SelectedItem.ToString() = textBoxUserName.Text Then
                _ActiveUser = _Users(New UserID(textBoxUserName.Text))
            End If
        End If

        ' and check if the template already exists for the assigned finger
        If _ActiveUser.TemplateExists(_AssignedFinger) Then
            ' show message indicating template already exists for selected finger
            Dim diagResult As DialogResult = MessageBox.Show(Me, [String].Format("Oops!" + ControlChars.Cr + ControlChars.Lf + "{0} has a template enrolled to his/her {1} finger." + ControlChars.Cr + ControlChars.Lf + ControlChars.Cr + ControlChars.Lf + "Shall the old template be discarded?", _ActiveUser.ID.ToString(), _Fingers(_AssignedFinger)), "Template already assigned!", MessageBoxButtons.YesNo, MessageBoxIcon.Error)

            ' if user selected not to overwrite, then abort
            If diagResult = Windows.Forms.DialogResult.No Then
                Return
            End If
        End If

        Try
            ' attempt to read the template
            Dim templateOpened As New DPFP.Template(File.OpenRead(textBoxTemplateFilename.Text))

            ' run a template duplicate check
            IdentifyTemplate(templateOpened)

            ' remove the old template if exists
            If _ActiveUser.TemplateExists(_AssignedFinger) Then
                ' removed from assigned finger
                _ActiveUser.RemoveTemplate(_AssignedFinger)
            End If

            ' and assign it to the user as specified
            _ActiveUser.AddTemplate(templateOpened, _AssignedFinger)

            ' update collection
            If Not _Users.UserExists(_ActiveUser.ID) Then
                ' update list box
                listBoxUsers.Items.Add(_ActiveUser.ID.ToString())

                ' add user it to the user collection
                _Users.AddUser(_ActiveUser)
            End If

            ' success
            UpdateEventLog([String].Format("{0}: Template successfully assigned to {1} finger.", _ActiveUser.ID.ToString(), _AssignedFinger.ToString()))

            ' turn off groupbox
            groupAddTemplate.Visible = False

            listBoxUsers.SelectedItem = _ActiveUser.ID.ToString()

            ' sync gui
            _syncUI()

            ' view user
            _syncViewUser()

        Catch Err As DPFP.Error.SDKException
            ' log message
            UpdateEventLog(Err.ToString())
            System.Diagnostics.Trace.WriteLine(Err.ToString())
        Catch Err As System.IO.FileNotFoundException
            ' log message
            UpdateEventLog("Template file not found or is inaccessible.")
            System.Diagnostics.Trace.WriteLine(Err.ToString())
        Catch Err As Exception
            ' log message
            UpdateEventLog(Err.ToString())
            System.Diagnostics.Trace.WriteLine(Err.ToString())
        End Try

        Using conn As New MySqlConnection("Server = localhost; Username= root; Password =; Database = vb")
            Using cmd
                With cmd
                    MsgBox("Connection Established")
                    .Connection = conn
                    .Parameters.Clear()
                    'Create Insert Query
                    .CommandText = "INSERT INTO employees(UserID, Name, Finger) VALUES (@iID, @iName, @iFinger)"
                    .Parameters.Add(New MySqlParameter("@iID", ID.Text))
                    .Parameters.Add(New MySqlParameter("@iName", textBoxUserName.Text))
                    .Parameters.Add(New MySqlParameter("@iFinger", comboBoxAssignedFinger.Text))


                End With
                Try
                    'Open Connection and Execute Query
                    conn.Open()
                    cmd.ExecuteNonQuery()
                Catch ex As MySqlException
                    MsgBox(ex.Message.ToString())
                End Try
            End Using
        End Using
4

2 回答 2

2

我知道这是一篇旧帖子,但这里有一些代码块可能会有所帮助......

在保存时我使用了这个

       For Each template As DPFP.Template In Data.Templates    
            If Not template Is Nothing Then 
                cmd = New MySqlCommand("INSERT INTO employeefp " +
                                  "SET No=@No, " +
                                  "FP=@FP " +
                                  " ", conn)

                cmd.Parameters.Add(New MySqlParameter("@No", txtEmpNo.Text))
                cmd.Parameters.Add(New MySqlParameter("@FP", template.Bytes))

                cmd.ExecuteNonQuery()

            End If
        Next

在从数据库验证时,我使用了这个

  1. 加载表格时,我获取所有指纹

        Dim cmd As New MySqlCommand("SELECT * FROM employeefp  ", conn)
        Dim rdr As MySqlDataReader = cmd.ExecuteReader()
    
        While (rdr.Read())
            Dim MemStream As IO.MemoryStream
            Dim fpBytes As Byte()
    
            fpBytes = rdr("FP")
            MemStream = New IO.MemoryStream(fpBytes)
    
            Dim templa8 As DPFP.Template = New DPFP.Template()
            templa8.DeSerialize(MemStream)
    
            Dim tmpObj As New AppData
            tmpObj.No = rdr("No").ToString()
            tmpObj.Template = templa8
            FPList.Add(tmpObj)
        End While
    

注意:Dim FPList As List(Of AppData) = New List(Of AppData) //你可以在 SDK 中找到这个的定义我刚刚添加了模板(包含一个打印)除了现有的模板(包含许多打印)

  1. 比较机器的当前样品

    Sub OnComplete(ByVal Control As Object, ByVal FeatureSet As DPFP.FeatureSet, ByRef EventHandlerStatus As DPFP.Gui.EventHandlerStatus) Handles VerificationControl.OnComplete
    Dim printFound As Boolean = False
    VerifiedFPData = New AppData
    Try
        For Each FPData As AppData In FPList
            Dim tmplateData As New DPFP.Template
            tmplateData = FPData.Template
            Dim compareTo As New DPFP.FeatureSet
            compareTo = FeatureSet
    
            Dim ver As New DPFP.Verification.Verification()
            Dim res As New DPFP.Verification.Verification.Result()
    
            If Not tmplateData Is Nothing Then
                ver.Verify(FeatureSet, tmplateData, res)
    
                If res.Verified Then
                    EventHandlerStatus = DPFP.Gui.EventHandlerStatus.Success
                    printFound = True
                    VerifiedFPData = FPData
                    Exit For ' success
                End If
            End If
        Next
    Catch ex As Exception
        MessageBox.Show("verification error")
    End Try
    
    
    If printFound Then
        //TO DO 
    Else
        EventHandlerStatus = DPFP.Gui.EventHandlerStatus.Failure
        // TODO
    End If
    

    结束子

希望它可以帮助某人:)

于 2013-08-21T02:49:36.513 回答
1

There are some missing codes from the answer above. The code of the class appdata is missing.These code is error without declaring first the tmpObj in the class AppData. Dim tmpObj As New AppData tmpObj.No = rdr("No").ToString() tmpObj.Template = templa8 FPList.Add(tmpObj)

于 2014-04-07T03:21:49.677 回答