Exemplo n.º 1
0
        private bool EnrollImport()
        {
            int vnRet;

            vnRet = ObjFpReader.pisClearTptArray(contextId);
            if (vnRet != ObjFpReader.PISFP_OK)
            {
                ErrorDescription(ObjFpReader.INIT_PROC, ObjFpReader.CLEAR_TPT_ARRAY_FUNC, vnRet);
                ObjFpReader.pisDestroyContext(contextId);
                return(false);
            }

            for (int i = 0; i < fpDataList.Count; i++)
            {
                int identifiedID = i + 1;
                vnRet = ObjFpReader.pisAddTptArray(contextId, identifiedID, fpDataList[i]);
                if (vnRet != ObjFpReader.PISFP_OK)
                {
                    ErrorDescription(ObjFpReader.INIT_PROC, ObjFpReader.ADD_TPT_ARRAY_FUNC, vnRet);
                    ObjFpReader.pisDestroyContext(contextId);
                    return(false);
                }
            }
            return(true);
        }
Exemplo n.º 2
0
        private bool Init()
        {
            devIdList.Clear();
            cbbDevice.Items.Clear();

            for (int i = 0; i < ObjFpReader.PISFP_MAX_DEVICE_COUNTS; i++)
            {
                byte[] vstrDeviceDescription = new byte[1024];
                byte[] vstrDevId             = new byte[1024];

                if (ObjFpReader.pisEnumerateDevice(i, vstrDevId, vstrDeviceDescription) == ObjFpReader.PISFP_OK)
                {
                    string str = Encoding.UTF8.GetString(vstrDeviceDescription, 0, vstrDeviceDescription.Length);
                    cbbDevice.Items.Add(str);
                    devIdList.Add(Encoding.UTF8.GetString(vstrDevId, 0, vstrDevId.Length));
                }
            }

            if (cbbDevice.Items.Count > 0)
            {
                InitFlag = true;
                cbbDevice.SelectedIndex = 0;
                InitFlag = false;
                Application.DoEvents();
                return(true);
            }

            return(false);
        }
Exemplo n.º 3
0
        private bool GetDbFingerData(string EmpNo, string FingerNo)
        {
            fpDataList.Clear();
            string    sql = "SELECT * FROM VRS_EmpFingerInfo WHERE EmpNo='" + EmpNo + "' AND FingerBkNo BETWEEN 0 AND 9 ORDER BY FingerBkNo";
            DataTable dt  = new DataTable();

            try
            {
                if (!db.IsOpen)
                {
                    db.Open(SystemInfo.ConnStr);
                }
                dt = db.GetDataTable(sql);
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    byte[] buff     = (byte[])dt.Rows[i]["FingerTemplate"];
                    byte[] buffConv = new byte[1680];
                    byte[] fpdata   = new byte[1600];
                    ObjFpReader.ConvEnrollData(buff, ref buffConv, 1680);
                    Array.Copy(buffConv, 80, fpdata, 0, 1600);
                    fpDataList.Add(fpdata);
                }

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Exemplo n.º 4
0
        private bool SaveFpDataToDB(byte[] FpData)
        {
            List <string> sql = new List <string>();

            byte[] buff       = new byte[1680];
            byte[] FpDataConv = new byte[1680];
            byte[] header     = { 0x45, 0x4e, 0x52, 0x4f, 0x4c, 0x4c, 0x46, 0x50, 0x01, 0x28 };
            Array.Copy(header, 0, FpDataConv, 0, header.Length); //Add Fixed Header
            Array.Copy(FpData, 0, FpDataConv, 80, FpData.Length);
            ObjFpReader.ConvEnrollData(FpDataConv, ref buff, 1680);

            //Update RS_Emp、VRS_EmpFingerInfo Table
            string EmpNo          = txtEmpNo.Text;
            string EnrollNumber   = txtFingerNo.Text;
            int    BackupNumber   = fpDataList.Count;
            int    EmpFingerCount = fpDataList.Count + 1;

            try
            {
                string sqls = "SELECT * FROM RS_EmpCard WHERE CardFingerNo=" + EnrollNumber + "";
                if (!db.IsOpen)
                {
                    db.Open(SystemInfo.ConnStr);
                }
                DataTableReader dr = db.GetDataReader(sqls);
                if (dr.Read())
                {
                    Int32.TryParse(dr["EmpFingerCount"].ToString(), out BackupNumber);
                    EmpFingerCount = BackupNumber + 1;
                }
                if (EmpFingerCount > 9)
                {
                    txtInfo.Text = Pub.GetResText(formCode, "MsgOverRegister", "");
                    return(false);
                }

                sql.Add("UPDATE RS_EmpCard SET EmpFingerCount=" + EmpFingerCount.ToString() + " WHERE CardFingerNo=" + EnrollNumber + "");
                if (EmpFingerCount == 1)
                {
                    sql.Add(Pub.GetSQL(DBCode.DB_006001, new string[] { "49", SystemInfo.MacTypeID.ToString(),
                                                                        EnrollNumber, fpDataList.Count.ToString(), "NULL" }));
                }

                if (db.ExecSQL(sql) == 0)
                {
                    db.UpdateByteData(Pub.GetSQL(DBCode.DB_006001, new string[] { "51", SystemInfo.MacTypeID.ToString(),
                                                                                  EnrollNumber, BackupNumber.ToString() }), "FingerTemplate", buff);
                }
                return(true);
            }
            catch
            {
                return(false);
            }
        }
Exemplo n.º 5
0
 private void btnClearFpData_Click(object sender, EventArgs e)
 {
     if (Pub.MessageBoxShowQuestion(Pub.GetResText(formCode, "MsgClearRequest", "")))
     {
         return;
     }
     fpDataList.Clear();
     if (ClearFpDataToDB(txtEmpNo.Text, txtFingerNo.Text))
     {
         ObjFpReader.pisClearTptArray(contextId);
         txtInfo.Text = string.Format(Pub.GetResText(formCode, "MsgClearComplete", ""), txtEmpNo.Text);
     }
 }
Exemplo n.º 6
0
        private void Exit()
        {
            StopFlag = true;

            if (deviceCompany == ObjFpReader.PRODUCT_HYSOON || deviceCompany == ObjFpReader.PRODUCT_TAIWAN)
            {
                ObjFpReader.pisLedControl(contextId, ObjFpReader.PISFP_BKLED, ObjFpReader.PISFP_LED_OFF);
            }

            ObjFpReader.pisCloseDevice(contextId);
            ObjFpReader.pisDestroyContext(contextId);
            gbxFpReader.Enabled = false;
            btnInit.Enabled     = true;
            cbbDevice.Enabled   = true;
        }
Exemplo n.º 7
0
        private void Enroll()
        {
            //超过 10 枚指纹,不再注册
            if (fpDataList.Count > 9)
            {
                txtInfo.Text = Pub.GetResText(formCode, "MsgOverRegister", "");
                return;
            }

            int vnRet;
            int flag = 1;
            //控制设备灯
            int temp_DeviceCompany = deviceCompany;

            if (temp_DeviceCompany == ObjFpReader.PRODUCT_HYSOON)
            {
                ObjFpReader.pisLedControl(contextId, ObjFpReader.PISFP_ALLLED, ObjFpReader.PISFP_LED_OFF);
                ObjFpReader.pisLedControl(contextId, ObjFpReader.PISFP_BKLED, ObjFpReader.PISFP_LED_ON);
            }
            else if (temp_DeviceCompany == ObjFpReader.PRODUCT_TAIWAN)
            {
                ObjFpReader.pisLedControl(contextId, ObjFpReader.PISFP_BKLED, ObjFpReader.PISFP_LED_ON);
            }

            if (StopFlag)
            {
                StopFlag = false;
            }
            int  isCheckFp = 0, fpArea = 0;
            int  fpExtractCount        = 0;
            int  continuosFpPressCount = 0;
            bool doubleCheckFlag       = true;

            ObjFpReader.CaptureFpStatus capFpStatus = ObjFpReader.CaptureFpStatus.CapFp_Init;
            while (!StopFlag)
            {
                Application.DoEvents();
                vnRet = ObjFpReader.pisCapture(contextId, imageBuffer);
                if (vnRet == ObjFpReader.PISFP_ERR_NOT_CONNECT_DEV)
                {
                    ErrorDescription(ObjFpReader.ENROLL_PROC, ObjFpReader.CAPTURE_FUNC, vnRet);

                    ObjFpReader.pisCloseDevice(contextId);

                    vnRet = ObjFpReader.pisOpenDevice(contextId, devIdList[cbbDevice.SelectedIndex]);
                    System.Threading.Thread.Sleep(1000);
                    continue;
                }
                else if (vnRet != ObjFpReader.PISFP_OK)
                {
                    ErrorDescription(ObjFpReader.ENROLL_PROC, ObjFpReader.CAPTURE_FUNC, vnRet);
                    ObjFpReader.pisLedControl(contextId, ObjFpReader.PISFP_ALLLED, ObjFpReader.PISFP_LED_OFF);
                    return;
                }

                DrawFpImage();

                vnRet = ObjFpReader.pisCheckFp(contextId, imageBuffer, imageWidth, imageHeight, imageRes, ref isCheckFp, ref fpArea);

                //初始化
                if (capFpStatus == ObjFpReader.CaptureFpStatus.CapFp_Init)
                {
                    if (isCheckFp != 0)
                    {
                        txtInfo.Text = Pub.GetResText(formCode, "MsgLeaveFinger", "");;
                        continue;
                    }
                    else
                    {
                        capFpStatus           = ObjFpReader.CaptureFpStatus.CapFp_WaitPressFinger;
                        continuosFpPressCount = 0;
                    }
                }

                //等待手指按下时的操作
                if (capFpStatus == ObjFpReader.CaptureFpStatus.CapFp_WaitPressFinger)
                {
                    if (isCheckFp == 0)
                    {
                        promptPressFinger(fpExtractCount + 1);
                        if (continuosFpPressCount < 2)
                        {
                            continuosFpPressCount = 0;
                            continue;
                        }
                    }

                    continuosFpPressCount++;
                    if (fpArea > 80 && continuosFpPressCount > maxContinuosFpPressCount)
                    {
                        capFpStatus = ObjFpReader.CaptureFpStatus.CapFp_GoodFpCaptured;
                    }
                }

                //处理获取到的图片
                if (capFpStatus == ObjFpReader.CaptureFpStatus.CapFp_GoodFpCaptured)
                {
                    // 使用最大指纹图像提取指纹
                    if (ObjFpReader.pisProcess(contextId, imageBuffer, imageWidth, imageHeight, imageRes,
                                               feature[fpExtractCount]) != ObjFpReader.PISFP_OK)
                    {
                        ErrorDescription(ObjFpReader.ENROLL_PROC, ObjFpReader.PROCESS_FUNC, vnRet);
                        //
                        return;
                    }


                    //检查指纹数据是否已经存在
                    if (doubleCheckFlag == true)
                    {
                        int identifiedID = 0;
                        vnRet = ObjFpReader.pisIdentify(contextId, feature[fpExtractCount],
                                                        ref identifiedID, updatedTemplate, ref updatedFlag);

                        if (vnRet == ObjFpReader.PISFP_OK)
                        {
                            txtInfo.Text = string.Format(Pub.GetResText(formCode, "MsgExist", ""), txtEmpNo.Text, identifiedID);
                            return;
                        }
                    }

                    fpExtractCount++;


                    continuosFpPressCount = 0;

                    if (flag >= 3)
                    {
                        flag = 1;
                    }
                    if (fpExtractCount == 3)
                    {
                        break;
                    }
                    else
                    {
                        capFpStatus = ObjFpReader.CaptureFpStatus.CapFp_PromptTakeoffFinger;
                    }
                }

                //获取图片后手指的操作提示
                if (capFpStatus == ObjFpReader.CaptureFpStatus.CapFp_PromptTakeoffFinger)
                {
                    //检测指纹是否合格

                    int sum = 0;
                    for (int i = 0; i < 57344; i++)
                    {
                        sum += int.Parse(imageBuffer[i].ToString());
                    }

                    if (isCheckFp != 0)
                    {
                        txtInfo.Text = Pub.GetResText(formCode, "MsgLeaveFinger", "");
                        capFpStatus  = ObjFpReader.CaptureFpStatus.CapFp_Init;
                        continue;
                    }

                    // capFpStatus = ObjFpReader.CaptureFpStatus.CapFp_WaitPressFinger;
                }
            }

            if (temp_DeviceCompany == ObjFpReader.PRODUCT_HYSOON || temp_DeviceCompany == ObjFpReader.PRODUCT_TAIWAN)
            {
                ObjFpReader.pisLedControl(contextId, ObjFpReader.PISFP_BKLED, ObjFpReader.PISFP_LED_OFF);
            }

            if (StopFlag == true)
            {
                txtInfo.Text = Pub.GetResText(formCode, "MsgStop", "");

                return;
            }

            //生成模板
            vnRet = ObjFpReader.pisCreateTemplate(contextId, feature[0], feature[1], feature[2], template);
            if (vnRet != ObjFpReader.PISFP_OK)
            {
                ErrorDescription(ObjFpReader.ENROLL_PROC, ObjFpReader.CREATE_TEMPLATE_FUNC, vnRet);
                //txtInfo.Text = Pub.GetResText(formCode, "MsgCreateTemplate", "");
                return;
            }

            ////写出到文件
            //using (var fs = new FileStream(string.Format("{0}.dat", txtEmpNo.Text), FileMode.Create))
            //{
            //    fs.Write(template, 0, template.Length);
            //}

            //添加进识别
            vnRet = ObjFpReader.pisAddTptArray(contextId, fpDataList.Count + 1, template);
            if (vnRet != ObjFpReader.PISFP_OK)
            {
                ErrorDescription(ObjFpReader.ENROLL_PROC, ObjFpReader.ADD_TPT_ARRAY_FUNC, vnRet);
                return;
            }

            //保存到数据库
            if (SaveFpDataToDB(template))
            {
                fpDataList.Add(template);
            }

            txtInfo.Text = string.Format(Pub.GetResText(formCode, "MsgRegisterSuccess", ""), txtEmpNo.Text, fpDataList.Count);
        }
Exemplo n.º 8
0
        private void OpenDev(int index)
        {
            string vDevId = string.Empty;
            int    vnRet;

            if (!GetDevIdFromListIndex(index, ref vDevId))
            {
                MessageBox.Show(Pub.GetResText(formCode, "MsgNoDevice", ""));
            }
            vnRet = ObjFpReader.pisCreateContext(ref contextId);
            if (vnRet != ObjFpReader.PISFP_OK)
            {
                ErrorDescription(ObjFpReader.INIT_PROC, ObjFpReader.CREATE_CONTEXT_FUNC, vnRet);
            }

            txtInfo.Text = Pub.GetResText(formCode, "MsgOpenDevice", "");

            vnRet = ObjFpReader.pisOpenDevice(contextId, vDevId);
            if (vnRet != ObjFpReader.PISFP_OK)
            {
                ObjFpReader.pisDestroyContext(contextId);
                ErrorDescription(ObjFpReader.INIT_PROC, ObjFpReader.OPEN_DEVICE_FUNC, vnRet);
                return;
            }

            vnRet = ObjFpReader.pisGetDeviceInfo(contextId, ObjFpReader.PISFP_PARAM_KIND_COMPANY, ref deviceCompany);
            if (vnRet != ObjFpReader.PISFP_OK)
            {
                deviceCompany = ObjFpReader.PRODUCT_PEFIS;
            }

            fpAreaTh       = 18;
            noCheckCountTh = 20;
            int temp_DeviceCompany = deviceCompany;

            if (temp_DeviceCompany == ObjFpReader.PRODUCT_HYSOON || temp_DeviceCompany == ObjFpReader.PRODUCT_TAIWAN)
            {
                ObjFpReader.pisLedControl(contextId, ObjFpReader.PISFP_BKLED, ObjFpReader.PISFP_LED_ON);
                fpAreaTh       = 17;
                noCheckCountTh = 20;
            }


            byte[] engineInfo = new byte[1024];
            vnRet = ObjFpReader.pisGetInfo(contextId, ref engineInfo[0], ref imageWidth, ref imageHeight, ref imageRes,
                                           ref featureSize, ref templateSize);

            if (temp_DeviceCompany == ObjFpReader.PRODUCT_HYSOON || temp_DeviceCompany == ObjFpReader.PRODUCT_TAIWAN)
            {
                ObjFpReader.pisLedControl(contextId, ObjFpReader.PISFP_BKLED, ObjFpReader.PISFP_LED_OFF);
            }

            if (vnRet != ObjFpReader.PISFP_OK)
            {
                ObjFpReader.pisDestroyContext(contextId);
                ErrorDescription(ObjFpReader.INIT_PROC, ObjFpReader.GET_INFO_FUNC, vnRet);
                return;
            }

            picFpImage.Width  = imageWidth;
            picFpImage.Height = imageHeight;
            picFpImage.Image  = null;

            imageBuffer     = new byte[picFpImage.Width * picFpImage.Height];
            feature[0]      = new byte[featureSize];
            feature[1]      = new byte[featureSize];
            feature[2]      = new byte[featureSize];
            template        = new byte[templateSize];
            updatedTemplate = new byte[templateSize];
            rawImgBuffer    = new byte[ObjFpReader.IMPORT_RAW_IMAGE_WIDTH * ObjFpReader.IMPORT_RAW_IMAGE_HEIGHT];

            memset(imageBuffer, 0x55, picFpImage.Width * picFpImage.Height);

            vnRet = ObjFpReader.pisSetMatchParameter(contextId, ObjFpReader.PISFP_DEFAULT_ROTATION_RANGE, ObjFpReader.PISFP_DEFAULT_THRESHOLD);
            if (vnRet != ObjFpReader.PISFP_OK)
            {
                ObjFpReader.pisDestroyContext(contextId);
                ErrorDescription(ObjFpReader.INIT_PROC, ObjFpReader.GET_INFO_FUNC, vnRet);
                return;
            }

            StopFlag            = true;
            gbxFpReader.Enabled = true;

            GetDbFingerData(txtEmpNo.Text, txtFingerNo.Text);
            EnrollImport();
            txtInfo.Text    = Pub.GetResText(formCode, "MsgInitSuccess", "");
            btnInit.Enabled = false;
        }
Exemplo n.º 9
0
        private void Verify()
        {
            int vnRet;
            //控制设备灯
            int temp_DeviceCompany = deviceCompany;

            if (temp_DeviceCompany == ObjFpReader.PRODUCT_HYSOON)
            {
                ObjFpReader.pisLedControl(contextId, ObjFpReader.PISFP_ALLLED, ObjFpReader.PISFP_LED_OFF);
                ObjFpReader.pisLedControl(contextId, ObjFpReader.PISFP_BKLED, ObjFpReader.PISFP_LED_ON);
            }
            else if (temp_DeviceCompany == ObjFpReader.PRODUCT_TAIWAN)
            {
                ObjFpReader.pisLedControl(contextId, ObjFpReader.PISFP_BKLED, ObjFpReader.PISFP_LED_ON);
            }

            if (StopFlag)
            {
                StopFlag = false;
            }
            int  isCheckFp = 0, fpArea = 0;
            bool doubleCheckFlag = true;

            ObjFpReader.CaptureFpStatus capFpStatus = ObjFpReader.CaptureFpStatus.CapFp_Init;
            while (!StopFlag)
            {
                Application.DoEvents();
                memset(feature[0], 0x00, featureSize);
                memset(updatedTemplate, 0x00, templateSize);

                vnRet = ObjFpReader.pisCapture(contextId, imageBuffer);
                if (vnRet == ObjFpReader.PISFP_ERR_NOT_CONNECT_DEV)
                {
                    ErrorDescription(ObjFpReader.VERIFY_PROC, ObjFpReader.CAPTURE_FUNC, vnRet);

                    ObjFpReader.pisCloseDevice(contextId);

                    vnRet = ObjFpReader.pisOpenDevice(contextId, devIdList[cbbDevice.SelectedIndex]);
                    System.Threading.Thread.Sleep(1000);
                    continue;
                }
                else if (vnRet != ObjFpReader.PISFP_OK)
                {
                    ErrorDescription(ObjFpReader.VERIFY_PROC, ObjFpReader.CAPTURE_FUNC, vnRet);
                    ObjFpReader.pisLedControl(contextId, ObjFpReader.PISFP_ALLLED, ObjFpReader.PISFP_LED_OFF);
                    return;
                }

                DrawFpImage();

                vnRet        = ObjFpReader.pisCheckFp(contextId, imageBuffer, imageWidth, imageHeight, imageRes, ref isCheckFp, ref fpArea);
                txtInfo.Text = string.Empty;
                //初始化
                if (capFpStatus == ObjFpReader.CaptureFpStatus.CapFp_Init)
                {
                    if (isCheckFp != 0)
                    {
                        txtInfo.Text = Pub.GetResText(formCode, "MsgLeaveFinger", "");
                        continue;
                    }
                    else
                    {
                        capFpStatus = ObjFpReader.CaptureFpStatus.CapFp_WaitPressFinger;
                    }
                }

                //等待手指按下时的操作
                if (capFpStatus == ObjFpReader.CaptureFpStatus.CapFp_WaitPressFinger)
                {
                    if (isCheckFp == 0)
                    {
                        continue;
                    }

                    if (fpArea > 80)
                    {
                        capFpStatus = ObjFpReader.CaptureFpStatus.CapFp_GoodFpCaptured;
                    }
                }

                //处理获取到的图片
                if (capFpStatus == ObjFpReader.CaptureFpStatus.CapFp_GoodFpCaptured)
                {
                    // 使用最大指纹图像提取指纹
                    if (ObjFpReader.pisProcess(contextId, imageBuffer, imageWidth, imageHeight, imageRes,
                                               feature[0]) != ObjFpReader.PISFP_OK)
                    {
                        continue;
                    }

                    //检查fpdata是否已经存在
                    if (doubleCheckFlag == true)
                    {
                        int identifiedID = 0;
                        vnRet = ObjFpReader.pisIdentify(contextId, feature[0],
                                                        ref identifiedID, updatedTemplate, ref updatedFlag);

                        if (vnRet == ObjFpReader.PISFP_OK)
                        {
                            txtInfo.Text = string.Format("{0} - {1}", txtEmpNo.Text, identifiedID);
                        }
                        else
                        {
                            if (isCheckFp != 0)
                            {
                                txtInfo.Text = Pub.GetResText(formCode, "MsgFPunregistered", "");
                            }
                        }
                        //txtInfo.Text = string.Empty;
                        if (isCheckFp == 0)
                        {
                            capFpStatus = ObjFpReader.CaptureFpStatus.CapFp_Init;
                        }
                        continue;
                    }
                }
            }

            if (temp_DeviceCompany == ObjFpReader.PRODUCT_HYSOON || temp_DeviceCompany == ObjFpReader.PRODUCT_TAIWAN)
            {
                ObjFpReader.pisLedControl(contextId, ObjFpReader.PISFP_BKLED, ObjFpReader.PISFP_LED_OFF);
            }

            if (StopFlag == true)
            {
                txtInfo.Text = Pub.GetResText(formCode, "MsgStop", "");

                return;
            }
        }