/// <summary> /// 加载指纹dat文件 /// </summary> /// <param name="entity"></param> private void LoadFingerDat(CmcsFinger entity) { if (!IsConnect) { ShowInfomation("请先打开设备..."); return; } ret = Fingerdll.ZAZDownCharFromFile(hHandle, nDevAddr, 1, entity.FingerUrl); ret = Fingerdll.ZAZDownCharFromFile(hHandle, nDevAddr, 2, entity.FingerUrl); if (ret == 0) { byte[] ImgData = new byte[ImageSize]; int[] ImgLen = new int[1]; ret = Fingerdll.ZAZUpImage(hHandle, nDevAddr, ImgData, ImgLen); //上传图象 if (ret != 0) { ShowInfomation(Fingerdll.ZAZErr2Strt(ret)); return; } strFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ZAZFinger.bmp"); ret = Fingerdll.ZAZImgData2BMP(ImgData, strFile); if (ret != 0) { ShowInfomation(Fingerdll.ZAZErr2Strt(ret), eOutputType.Error); return; } ShowImage(strFile); } }
/// <summary> /// 登陆 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnLogin_Click(object sender, EventArgs e) { #region 验证 if (cmbUserAccount.SelectedItem == null) { ShowToolTip("请选择用户"); return; } if (string.IsNullOrEmpty(txtUserPassword.Text)) { ShowToolTip("请输入密码"); return; } #endregion user = commonDao.Login(eUserRoleCodes.化验员.ToString(), cmbUserAccount.SelectedValue.ToString(), MD5Util.Encrypt(txtUserPassword.Text)); if (user != null) { if (user.UserAccount == GlobalVars.AdminAccount) { LoginSuccess(); return; } if (FingerCheckCount == 1) //用户1 { finger = commonDao.SelfDber.Entities <CmcsFinger>("where UserId=:UserId", new { Userid = user.PartyId }); if (finger == null || finger.Count == 0) { ShowToolTip("未注册指纹"); return; } } if (Fingerdll.ZAZOpenDeviceEx(ref hHandle, 2, 0, 0, 2, 0) == 0) { GrossCheck = false; timer_Finger.Enabled = true; } else { ShowToolTip("指纹设备未连接"); return; } } else { ShowToolTip("帐号或密码错误,请重新输入!"); txtUserPassword.ResetText(); txtUserPassword.Focus(); } }
/// <summary> /// 开始指纹检测 /// </summary> public void StartCheck() { GrossCheck = false; if (GetFinger(1) == 1) { if (FingerCheckCount == 2) { finger = commonDao.SelfDber.Entities <CmcsFinger>("where UserId!=:UserId", new { UserId = SelfVars.LoginUser.PartyId }); } foreach (CmcsFinger item in finger) { Fingerdll.ZAZDownCharFromFile(hHandle, nDevAddr, 2, item.FingerUrl); int[] nScore = new int[1]; ret = Fingerdll.ZAZMatch(hHandle, nDevAddr, nScore); //比对模板 if (nScore[0] > 50) { if (FingerCheckCount == 1) { ShowToolTip("匹配成功,监督人进行指纹验证"); SelfVars.LoginUser = user; GrossCheck = true; FingerCheckCount = 2; break; } else if (FingerCheckCount == 2) { SelfVars.LoginUser2 = commonDao.SelfDber.Get <User>(item.UserId); if (SelfVars.LoginUser2.UserName == SelfVars.LoginUser.UserName) { ShowToolTip("指纹不能与登录人一样"); break; } GrossCheck = true; taskSimpleScheduler.Cancal(); InvokeEx(() => { if (GrossCheck) { ShowToolTip("指纹匹配成功..."); LoginSuccess(); } }); break; } } } if (!GrossCheck) { ShowToolTip("指纹不匹配..."); } } }
/// <summary> /// 关闭设备 /// </summary> public void CloseHardware() { int ret = 0; ret = Fingerdll.ZAZCloseDeviceEx(hHandle); if (ret == 0) { this.IsConnect = true; ShowInfomation("设备关闭成功"); } else { this.IsConnect = false; ShowInfomation(Fingerdll.ZAZErr2Strt(ret)); } }
/// <summary> /// 初始化外接设备 /// </summary> public void InitHardware() { int ret = 0; ret = Fingerdll.ZAZOpenDeviceEx(ref hHandle, 2, 0, 0, 2, 0); if (ret == 0) { this.IsConnect = true; ShowInfomation("设备打开成功"); btn_eroll_Click(null, null); } else { this.IsConnect = false; ShowInfomation(Fingerdll.ZAZErr2Strt(ret)); } }
/// <summary> /// 获取指纹 /// </summary> /// <param name="buffer">指纹在设备中临时存放位置 1 2</param> /// <returns></returns> int GetFinger(int buffer) { TimeOut = 20; int ret = 0; byte[] ImgData = new byte[ImageSize]; int[] ImgLen = new int[1]; int iBuffer = buffer; BEIG1: ret = Fingerdll.ZAZGetImage(hHandle, nDevAddr); //获取图象 if (ret == 0) { ShowInfomation("获取图像成功..."); } else if (ret == 2) { //超时判断 ShowInfomation("等待手指平放在传感器上-" + TimeOut.ToString() + "秒"); if (TimeOut < 0) { ShowInfomation("等待超时"); return(0); } TimeOut--; Thread.Sleep(1000); goto BEIG1; } else { ShowInfomation(Fingerdll.ZAZErr2Strt(ret)); return(0); } ////////////////////////////////////////////////////////////////////////// //不涉及图像,下面可以省略 /****************上传图像*********/ ShowInfomation("正在上传图像请等待..."); ret = Fingerdll.ZAZUpImage(hHandle, nDevAddr, ImgData, ImgLen); //上传图象 if (ret != 0) { ShowInfomation(Fingerdll.ZAZErr2Strt(ret)); return(0); } //strFile = System.Windows.Forms.Application.StartupPath + "\\ZAZFinger.bmp"; strFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ZAZFinger.bmp"); ret = Fingerdll.ZAZImgData2BMP(ImgData, strFile); if (ret != 0) { ShowInfomation(Fingerdll.ZAZErr2Strt(ret)); return(0); } ShowImage(strFile); //ret = Fingerdll.ZAZShowFingerData(fpbmp.Handle, ref ImgData[0]); ////////////////////////////////////////////////////////////////////////// /****************生成特征 *********/ ret = Fingerdll.ZAZGenChar(hHandle, nDevAddr, iBuffer); //生成模板 if (ret != 0) { ShowInfomation(Fingerdll.ZAZErr2Strt(ret)); return(0); } else { ShowInfomation("生成指纹特征" + buffer.ToString()); } Thread.Sleep(10); BEIG2: if (ret == 0) { ret = Fingerdll.ZAZGetImage(hHandle, nDevAddr); //获取图象 ShowInfomation("等待手指拿开-"); goto BEIG2; } else if (ret == 1) { ShowInfomation(Fingerdll.ZAZErr2Strt(ret)); return(0); } return(1); }
/// <summary> /// 注册指纹 /// </summary> private void RegistFinger() { if (!IsConnect) { ShowInfomation("请先打开设备..."); return; } //生成特征A if (GetFinger(1) != 1) { return; } Thread.Sleep(200); //生成特征B if (GetFinger(2) != 1) { return; } Thread.Sleep(200); /****************合成模板*********/ ret = Fingerdll.ZAZRegModule(hHandle, nDevAddr); //合并特征 if (ret != 0) { ShowInfomation(Fingerdll.ZAZErr2Strt(ret)); return; } else { ShowInfomation("合成指纹模板成功"); } Thread.Sleep(200); //本例以存在在指纹设备库中进行 //ret = Fingerdll.ZAZStoreChar(hHandle, nDevAddr, 1, FingerIndex); //存放模板 //StrFile = System.Windows.Forms.Application.StartupPath + "\\FTmpelet.dat"; #region 存储指纹到服务器 CmcsFinger userfinger = new CmcsFinger(); InvokeEx(() => { StrFile = commonDAO.GetCommonAppletConfigString("指纹识别数据存放路径"); userfinger = fingerIdentifyDAO.GetFinerByFingerName(this.User.PartyId, cmbFingerName.Text); if (userfinger == null) { userfinger = new CmcsFinger(); userfinger.FingerName = cmbFingerName.Text; } StrFile = Path.Combine(StrFile, this.User.UserAccount); if (!File.Exists(StrFile)) { Directory.CreateDirectory(StrFile); } StrFile = Path.Combine(StrFile, userfinger.Id + ".dat"); userfinger.FingerUrl = StrFile; #endregion //将指纹信息写入到dat文件 ret = Fingerdll.ZAZUpChar2File(hHandle, nDevAddr, 1, strFile); if (ret != 0) { ShowInfomation(Fingerdll.ZAZErr2Strt(ret)); return; } else { if (fingerIdentifyDAO.InsertFinger(this.User, userfinger) && File.Exists(StrFile)) { ShowInfomation("存储指纹成功"); //showFpdb();显示当前设备指纹存储信息 FingerIndex++; BindData(); return; } } }); }
/// <summary> /// 获取指纹 /// </summary> /// <param name="buffer">指纹在设备中临时存放位置 1 2</param> /// <returns></returns> int GetFinger(int buffer) { TimeOut = 20; int ret = 0; byte[] ImgData = new byte[ImageSize]; int[] ImgLen = new int[1]; int iBuffer = 1; BEIG1: ret = Fingerdll.ZAZGetImage(hHandle, nDevAddr); //获取图象 if (ret == 0) { ShowToolTip("获取图像成功..."); } else if (ret == 2) { //超时判断 ShowToolTip("等待手指平放在传感器上-" + TimeOut.ToString() + "秒"); if (TimeOut < 0) { ShowToolTip("等待超时"); return(0); } TimeOut--; Thread.Sleep(1000); goto BEIG1; } else { //ShowToolTip(Fingerdll.ZAZErr2Strt(ret)); return(0); } ////////////////////////////////////////////////////////////////////////// //不涉及图像,下面可以省略 /****************上传图像*********/ ShowToolTip("正在上传图像请等待..."); ret = Fingerdll.ZAZUpImage(hHandle, nDevAddr, ImgData, ImgLen); //上传图象 if (ret != 0) { ShowToolTip(Fingerdll.ZAZErr2Strt(ret)); return(0); } ret = Fingerdll.ZAZGenChar(hHandle, nDevAddr, iBuffer); //生成模板 if (ret != 0) { ShowToolTip(Fingerdll.ZAZErr2Strt(ret)); return(0); } else { ShowToolTip("生成指纹特征" + buffer.ToString()); return(1); } BEIG2: if (ret == 0) { ret = Fingerdll.ZAZGetImage(hHandle, nDevAddr); //获取图象 ShowToolTip("等待手指拿开-"); goto BEIG2; } else if (ret == 1) { ShowToolTip(Fingerdll.ZAZErr2Strt(ret)); return(0); } return(1); }