如何使用digitalpersona SDK直接保存的指纹数据库 [英] How to save a fingerprint directly in the database using digitalpersona sdk

查看:831
本文介绍了如何使用digitalpersona SDK直接保存的指纹数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我下载了一个样品招生code我digitalPersona设备使用。它可能已注册和验证的指纹,但问题是,它保存其指纹.FPT文件一个文件夹中。我想把它保存在数据库中。

I downloaded an Enrollment Sample Code for my digitalPersona device to use. It could already register and verify fingerprints but the problem is that it save its fingerprint .fpt file in a folder. I want to save it in the database.

这是我已经到目前为止已经试过。

This is what I already tried so far.

private void SaveButton_Click(object sender, EventArgs e)
        {
            SaveFileDialog save = new SaveFileDialog();
            save.Filter = "Fingerprint Template File (*.fpt)|*.fpt";
            if (save.ShowDialog() == DialogResult.OK)

                using (FileStream fs = File.Open(save.FileName, FileMode.Create, FileAccess.Write))
                {
                    Template.Serialize(fs);

                    fs.Close();

                //Read the file and convert it to byte array
                string filePath = save.FileName;
                string filename = Path.GetFileName(filePath);
                FileStream fst = new FileStream(filePath, FileMode.Open, FileAccess.Read);
                BinaryReader br = new BinaryReader(fst);
                Byte[] bytes = br.ReadBytes((Int32)fst.Length);
                br.Close();
                fst.Close();


                //Insert the file into database
                SqlConnection cn = new SqlConnection("Data Source=10.115.5.3; Initial Catalog=EnrollmentSampledb;Integrated Security=SSPI;");
                SqlCommand cmd = new SqlCommand("INSERT INTO tblUser VALUES(@ID_NUMBER, @FIRSTNAME, @LASTNAME, @FINGERPRINT, @DATE_ADDED, @DATE_MODIFIED)", cn);
                cmd.Parameters.Add("ID_NUMBER", SqlDbType.NVarChar).Value = tboxIdNum.Text;
                cmd.Parameters.Add("FIRSTNAME", SqlDbType.NVarChar).Value = tboxFname.Text;
                cmd.Parameters.Add("LASTNAME", SqlDbType.NVarChar).Value = tboxLname.Text;
                cmd.Parameters.Add("FINGERPRINT", SqlDbType.Image).Value = bytes;
                cmd.Parameters.Add("DATE_ADDED", SqlDbType.DateTime).Value = DateTime.Now;
                cmd.Parameters.Add("DATE_MODIFIED", SqlDbType.DateTime).Value = DateTime.Now;

                cn.Open(); cmd.ExecuteNonQuery();
                cn.Close();

            }

            tboxIdNum.Text = "";
            tboxFname.Text = "";
            tboxLname.Text = "";
        }   

这一次在数据库中保存的指纹文件,但它首先需要将其保存的文件夹。我想直接保存在数据库中,但我有点搞不清怎么办呢。我无法找到该文件进行保存。 T_T对不起有点小白。之前有没有人做呢?

This one saves a fingerprint file in the database but it need first to save it in a folder. I want to save it directly in the database but I'm a little confuse how to do it. I can't locate the file to save. T_T I'm sorry a little bit noob. Has anyone has done this before?

推荐答案

没测试过,但我相信code应该是这样的。基本上,我们替换成的MemoryStream 和指纹数据写入到它,以便以后设置它的位置返回到 0 数据都可以读出并格式化存储,留下圆通code的剩余部分(除为名称变更)

Not tested, but I believe the code should look like this. Basically, we substitute a MemoryStream and set its position back to 0 after writing the fingerprint data into it so that the data may be read back and formatted for storage, leaving the rest of the code in tact (excepting for the name change)

private void SaveButton_Click(object sender, EventArgs e)
{
    MemoryStream fingerprintData = new MemoryStream();
    Template.Serialize(fingerprintData);
    fingerprintData.Position = 0;
    BinaryReader br = new BinaryReader(fingerprintData);
    Byte[] bytes = br.ReadBytes((Int32)fingerprintData.Length);

    //Insert the file into database
    SqlConnection cn = new SqlConnection("Data Source=10.115.5.3; Initial Catalog=EnrollmentSampledb;Integrated Security=SSPI;");
    SqlCommand cmd = new SqlCommand("INSERT INTO tblUser VALUES(@ID_NUMBER, @FIRSTNAME, @LASTNAME, @FINGERPRINT, @DATE_ADDED, @DATE_MODIFIED)", cn);
    cmd.Parameters.Add("ID_NUMBER", SqlDbType.NVarChar).Value = tboxIdNum.Text;
    cmd.Parameters.Add("FIRSTNAME", SqlDbType.NVarChar).Value = tboxFname.Text;
    cmd.Parameters.Add("LASTNAME", SqlDbType.NVarChar).Value = tboxLname.Text;
    cmd.Parameters.Add("FINGERPRINT", SqlDbType.Image).Value = bytes;
    cmd.Parameters.Add("DATE_ADDED", SqlDbType.DateTime).Value = DateTime.Now;
    cmd.Parameters.Add("DATE_MODIFIED", SqlDbType.DateTime).Value = DateTime.Now;

    cn.Open();
    cmd.ExecuteNonQuery();
    cn.Close();

    tboxIdNum.Text = "";
    tboxFname.Text = "";
    tboxLname.Text = "";
}   

这篇关于如何使用digitalpersona SDK直接保存的指纹数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆