检索指纹模板时出现问题

时间:2018-10-10 05:57:12

标签: c#

我正在使用数字角色和One Touch SDK,我设法将指纹模板保存到数据库中,但是真正的问题是我不知道如何检索和匹配指纹。...

保存模板的代码。

private void saveprints(Byte[] array)
{
    conn = new SqlConnection(constring);
    try
    {
        SqlCommand cmd = new SqlCommand("insert into Finger (Fingerprint)values(@img)", conn);


        cmd.Parameters.Add(new SqlParameter("@img", array));
        if (conn.State == System.Data.ConnectionState.Closed)
        {
            conn.Open();
        }
        cmd.ExecuteNonQuery();
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
    }
}



private void btnSave_Click(object sender, EventArgs e)
{
    //Image Properties
    MemoryStream ms = new MemoryStream();
    Bitmap bmpImage = new Bitmap(picProfile.Image);

    MemoryStream fingerData = new MemoryStream();
    Template.Serialize(fingerData);
    fingerData.Position = 0;
    BinaryReader br = new BinaryReader(fingerData);
    Byte[] bytes = br.ReadBytes((Int32)fingerData.Length);


    bmpImage.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
    byte[] data = ms.GetBuffer();

    if (prints.Count != 0)
    {
        foreach (byte[] b in prints) {
            saveprints(b);
        }
    }
    else {
        MessageBox.Show("Please Scan your Finger", "Fingerprint Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
    }
    //if the texbox field is blank
    if (txtIDnum.Text == "" || txtFullname.Text == "" || txtContactNumber.Text == "" || txtCourseYear.Text == "" || txtDateregister.Text == "")
    {
        MessageBox.Show("Specify the Textbox Field!", "Information Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
    }
    else
    {
        //database code here
        using (conn = new SqlConnection(constring))
        {
            conn.Open();
            bool idCheck = false;
            //check if the ID is already in used
            using(cmd = new SqlCommand("select count(*) from [student] where ID=@id",conn))
            {
                cmd.Parameters.AddWithValue("id", txtIDnum.Text);
                idCheck = (int)cmd.ExecuteScalar() > 0;
            }
            if (idCheck)
            {
                MessageBox.Show("The ID '" + txtIDnum.Text + "' is Already used by Another User!, Enter New ID or Delete in the Student Data", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else {
                using(cmd = new SqlCommand("insert into [student] values (@ID,@FN,@CY,@CN,@DR,@IMG,@FINGER)",conn))
                 {
                    cmd.Parameters.AddWithValue("ID",txtIDnum.Text);
                    cmd.Parameters.AddWithValue("FN", txtFullname.Text);
                    cmd.Parameters.AddWithValue("CY", txtCourseYear.Text);
                    cmd.Parameters.AddWithValue("CN", txtContactNumber.Text);
                    cmd.Parameters.AddWithValue("DR", txtDateregister.Text);
                    cmd.Parameters.AddWithValue("@FINGER", bytes);
                    //cmd.Parameters.Add(new SqlParameter("@IMG", save()));
                    SqlParameter p = new SqlParameter("@IMG", SqlDbType.Image);
                    p.Value = data;
                    cmd.Parameters.Add(p);

                    cmd.ExecuteNonQuery();

                    MessageBox.Show("Data Successfully Saved to Database", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            conn.Close();

        }

有没有人知道如何从数据库中检索和匹配指纹???请帮忙!

0 个答案:

没有答案