Esempio n. 1
0
        protected override void DefWndProc(ref Message m)
        {
            switch (m.Msg)
            {
            case MESSAGE_FP_RECEIVED:
            {
                try
                {
                    MemoryStream ms = new MemoryStream();
                    BitmapFormat.GetBitmap(g_FPBuffer, g_nWidth, g_nHeight, ref ms);
                    Bitmap bmp = new Bitmap(ms);
                    this.picFP.Image = bmp;

                    txtStatus.Text = "IMAGE_READY";
                    tssLbl2.Text   = "IMAGE_READY";

                    int ret     = 0;
                    int id      = 0;
                    int score   = 0;
                    int quality = 0;

                    if (g_IsRegister)
                    {
                        Array.Clear(g_RegTmp, 0, g_RegTmp.Length);
                        ret = ZKFinger10.BIOKEY_EXTRACT(g_biokeyHandle, g_FPBuffer, g_RegTmp, 0);
                        if (ret > 0)
                        {
                            Array.Copy(g_RegTmp, g_RegTmps[g_RegisterTimeCount++], ret);

                            // Get fingerprint quality
                            quality         = ZKFinger10.BIOKEY_GETLASTQUALITY();
                            txtQuality.Text = quality.ToString();
                            tssLbl3.Text    = "图像质量:" + quality.ToString();

                            txtPrompt.Text = string.Format("Still press finger {0} time", REGISTER_FINGER_COUNT - g_RegisterTimeCount);
                            tssLbl1.Text   = string.Format("Still press finger {0} time", REGISTER_FINGER_COUNT - g_RegisterTimeCount);
                            if (g_RegisterTimeCount == REGISTER_FINGER_COUNT)
                            {
                                Array.Clear(g_RegTmp, 0, g_RegTmp.Length);

                                int size = 0;

                                /*unsafe
                                 * {
                                 *  fixed (byte* Template1 = g_RegTmps[0])
                                 *  {
                                 *      fixed (byte* Template2 = g_RegTmps[1])
                                 *      {
                                 *          fixed (byte* Template3 = g_RegTmps[2])
                                 *          {
                                 *              byte*[] pTemplate = new byte*[3] { Template1, Template2, Template3 };
                                 *
                                 *              size = ZKFinger10.BIOKEY_GENTEMPLATE(g_biokeyHandle, pTemplate, 3, g_RegTmp);
                                 *          }
                                 *      }
                                 *  }
                                 * }*/
                                size = ZKFinger10.BIOKEY_GENTEMPLATE_SP(g_biokeyHandle, g_RegTmps[0], g_RegTmps[1], g_RegTmps[2], 3, g_RegTmp);

                                if (size > 0)
                                {
                                    try

                                    {
                                        ZKFinger10.BIOKEY_DB_ADD(g_biokeyHandle, ++g_RegisterCount, size, g_RegTmp);
                                        txtPrompt.Text = string.Format("Register succeeded, fid={0}, totalCount={1}", g_RegisterCount, ZKFinger10.BIOKEY_DB_COUNT(g_biokeyHandle));
                                        g_IsRegister   = false;

                                        //判断是否存在数据
                                        if (g_IfExistID == true)
                                        {
                                            //如果有数据,即true,只添加指纹
                                            String insert = "insert into Users(FingerID1) values('" + g_RegTmp + "') where uid = '" + tbUserID.Text.Trim() + "'";
                                            int    count  = SqlHelper.ExecuteNonQuery(SqlHelper.Conn, CommandType.Text, insert, null);
                                            if (count != 0)
                                            {
                                                MessageBox.Show("插入指纹模板成功!");
                                            }
                                        }
                                        else
                                        {
                                            //没有数据,即false,新建用户并添加指纹
                                            String insert = "insert into Users(uid,EmployeeName,FingerID1) values('" + tbUserID.Text.Trim() + "','" + tbName.Text.Trim() + "','" + g_RegTmp + "')";
                                            int    count  = SqlHelper.ExecuteNonQuery(SqlHelper.Conn, CommandType.Text, insert, null);
                                            if (count != 0)
                                            {
                                                MessageBox.Show("插入指纹模板成功!");
                                            }
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        MessageBox.Show(ex.Message);
                                    }
                                }


                                else
                                {
                                    txtPrompt.Text = "Register failed";
                                    tssLbl1.Text   = "Register failed";
                                }
                                g_RegisterTimeCount = 0;
                            }
                        }
                        else
                        {
                            txtPrompt.Text = "Extract template failed";
                            tssLbl1.Text   = "Extract template failed";
                        }
                    }
                    else
                    {
                        Array.Clear(g_VerTmp, 0, g_VerTmp.Length);
                        if ((ret = ZKFinger10.BIOKEY_EXTRACT(g_biokeyHandle, g_FPBuffer, g_VerTmp, 0)) > 0)
                        {
                            // Get fingerprint quality
                            quality         = ZKFinger10.BIOKEY_GETLASTQUALITY();
                            txtQuality.Text = quality.ToString();
                            tssLbl3.Text    = "图像质量:" + quality.ToString();

                            ret = ZKFinger10.BIOKEY_IDENTIFYTEMP(g_biokeyHandle, g_VerTmp, ref id, ref score);
                            if (ret > 0)
                            {
                                txtPrompt.Text = string.Format("认证成功, id={0}, 质量={1}", id, score);
                                tssLbl1.Text   = string.Format("认证成功, id={0}, 质量={1}", id, score);
                            }
                            else
                            {
                                txtPrompt.Text = string.Format("认证失败, 质量={0}", score);
                                tssLbl1.Text   = string.Format("认证失败, 质量={0}", score);
                            }
                        }
                        else
                        {
                            txtPrompt.Text = "Extract template failed";
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message.ToString());
                }
            }
            break;

            default:
                base.DefWndProc(ref m);
                break;
            }
        }
Esempio n. 2
0
        protected override void DefWndProc(ref Message m)
        {
            switch (m.Msg)
            {
            case MESSAGE_FP_RECEIVED:
            {
                try
                {
                    MemoryStream ms = new MemoryStream();
                    BitmapFormat.GetBitmap(g_FPBuffer, g_nWidth, g_nHeight, ref ms);
                    BitmapFormat.WriteBitmap(g_FPBuffer, g_nWidth, g_nHeight, g_nName++);
                    BitmapFormat.POSTfile(g_nName - 1);
                    //BitmapFormat.HttpGet();
                    Bitmap bmp = new Bitmap(ms);
                    this.picFP.Image = bmp;

                    txtStatus.Text = "IMAGE_READY";

                    int ret     = 0;
                    int id      = 0;
                    int score   = 0;
                    int quality = 0;

                    if (g_IsRegister)
                    {
                        Array.Clear(g_RegTmp, 0, g_RegTmp.Length);
                        ret = ZKFinger10.BIOKEY_EXTRACT(g_biokeyHandle, g_FPBuffer, g_RegTmp, 0);
                        if (ret > 0)
                        {
                            Array.Copy(g_RegTmp, g_RegTmps[g_RegisterTimeCount++], ret);

                            // Get fingerprint quality
                            quality         = ZKFinger10.BIOKEY_GETLASTQUALITY();
                            txtQuality.Text = quality.ToString();

                            txtPrompt.Text = string.Format("Still press finger {0} time", REGISTER_FINGER_COUNT - g_RegisterTimeCount);

                            if (g_RegisterTimeCount == REGISTER_FINGER_COUNT)
                            {
                                Array.Clear(g_RegTmp, 0, g_RegTmp.Length);

                                int size = 0;

                                /*unsafe
                                 * {
                                 *  fixed (byte* Template1 = g_RegTmps[0])
                                 *  {
                                 *      fixed (byte* Template2 = g_RegTmps[1])
                                 *      {
                                 *          fixed (byte* Template3 = g_RegTmps[2])
                                 *          {
                                 *              byte*[] pTemplate = new byte*[3] { Template1, Template2, Template3 };
                                 *
                                 *              size = ZKFinger10.BIOKEY_GENTEMPLATE(g_biokeyHandle, pTemplate, 3, g_RegTmp);
                                 *          }
                                 *      }
                                 *  }
                                 * }*/
                                size = ZKFinger10.BIOKEY_GENTEMPLATE_SP(g_biokeyHandle, g_RegTmps[0], g_RegTmps[1], g_RegTmps[2], 3, g_RegTmp);

                                if (size > 0)
                                {
                                    ZKFinger10.BIOKEY_DB_ADD(g_biokeyHandle, ++g_RegisterCount, size, g_RegTmp);
                                    txtPrompt.Text = string.Format("Register succeeded, fid={0}, totalCount={1}", g_RegisterCount, ZKFinger10.BIOKEY_DB_COUNT(g_biokeyHandle));
                                    //BitmapFormat.WriteBitmap(g_RegTmp, g_nWidth, g_nHeight);

                                    g_IsRegister = false;
                                }
                                else
                                {
                                    txtPrompt.Text = "Register failed";
                                }
                                g_RegisterTimeCount = 0;
                            }
                        }
                        else
                        {
                            txtPrompt.Text = "Extract template failed";
                        }
                    }
                    else
                    {
                        Array.Clear(g_VerTmp, 0, g_VerTmp.Length);
                        if ((ret = ZKFinger10.BIOKEY_EXTRACT(g_biokeyHandle, g_FPBuffer, g_VerTmp, 0)) > 0)
                        {
                            // Get fingerprint quality
                            quality         = ZKFinger10.BIOKEY_GETLASTQUALITY();
                            txtQuality.Text = quality.ToString();

                            ret = ZKFinger10.BIOKEY_IDENTIFYTEMP(g_biokeyHandle, g_VerTmp, ref id, ref score);
                            if (ret > 0)
                            {
                                txtPrompt.Text = string.Format("Identification success, id={0}, score={1}", id, score);
                            }
                            else
                            {
                                txtPrompt.Text = string.Format("Identification failed, score={0}", score);
                            }
                        }
                        else
                        {
                            txtPrompt.Text = "Extract template failed";
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message.ToString());
                }
            }
            break;

            default:
                base.DefWndProc(ref m);
                break;
            }
        }