/// <summary> /// 显示确认窗口 这个函数将来要加到ShowConfirmBoxDelegate上 /// </summary> /// <param name="text"></param> /// <returns></returns> public static DialogResult ShowConfirmBox(string text) { var dialogResault = DialogResult.OK; waitForm.Invoke(new MethodInvoker(() => { dialogResault = ConfirmBox.ShowConfirmBoxDialog(text); })); return(dialogResault); }
/// <summary> /// 一个大循环 用来操作指纹仪. /// 这个函数要放到一个线程里来执行 /// </summary> /// <param name="studentList"></param> /// <param name="updateUserInterfaceDelegate">用来操作UI的委托</param> public static void Enroll(List <Student> studentList, UpdateUserInterfaceDelegate updateUserInterfaceDelegate) { FingerPrintHandle = HdFingerprintHelper.FpOpenUsb(0xFFFFFFFF, 1000); // 打开指纹仪驱动 //while (FingerPrintHandle == IntPtr.Zero) { // var confirmResault = ShowConfirmBox ( "指纹仪初始化失败 \n是否重新初始化指纹仪?" ); // if (confirmResault == DialogResult.OK) { // FingerPrintHandle = HdFingerprintHelper.FpOpenUsb ( 0xFFFFFFFF, 1000 ); // } else { // ShowMsgBox ( "当前指纹仪无法工作,请使用手动考勤." ); // return; // } //} //如果打不开 就只能手动签到了 //上面的这些已经注释了. 因为在switch那边有对错误的处理. var acceptPlayer = new SoundPlayer(Resources.Accept); var rejectPlayer = new SoundPlayer(Resources.Reject); var fingerprintImagePath = GlobalParams.RootDir + "/fingerprint.bmp"; while (IsRollCalling) { UInt16 fingerprintid = 1000; UInt16 similarity = 0; var fingerPrintStat = HdFingerprintHelper.StartVerify(FingerPrintHandle, fingerprintImagePath, ref fingerprintid, ref similarity, 3000); if (!IsRollCalling) { return; // 如果结束点名了 这个函数直接返回即可 } switch (fingerPrintStat) { case 0: { acceptPlayer.Play(); var index = studentList.FindIndex(s => s.FingerprintId == fingerprintid); if (index == -1) { continue; } var student = studentList[index]; student.SignIn(DateTime.Now); //var fingerprintImage = new File(GlobalParams.RootDir+@"/fingerprint.bmp") var fileInfo = new FileInfo(fingerprintImagePath); Image fingerprintImage; if (fileInfo.Length != 0) { var stream = File.Open(fingerprintImagePath, FileMode.Open); fingerprintImage = Image.FromStream(stream); stream.Close(); } else { fingerprintImage = null; } var normalStudentNum = CountNormalStudent(studentList); var absentStudentNum = CountAbsentStudent(studentList); var lateStudentNum = CountLateStudent(studentList); var askForLeaveStudentNum = CountAskForLeaveStudent(studentList); var leaveEarlyStudentNum = CountLeaveEarlyStudent(studentList); var expectedStudentNum = studentList.Count; var course = new CourseInfo(expectedStudentNum: expectedStudentNum, didNotSubmitStudentNum: absentStudentNum, actualStudentNum: normalStudentNum, askForLeaveStudentNum: askForLeaveStudentNum); updateUserInterfaceDelegate(fingerprintImage, course, student); CopyOfStudentList = studentList; break; } case 9: { //这里会出现文件占用的问题. 文件->流->图片 var fileInfo = new FileInfo(fingerprintImagePath); Image fingerprintImage; if (fileInfo.Length != 0) { var stream = File.Open(fingerprintImagePath, FileMode.Open); fingerprintImage = Image.FromStream(stream); stream.Close(); } else { fingerprintImage = null; } updateUserInterfaceDelegate(fingerprintImage, null); rejectPlayer.Play(); break; } default: { var confirmResault = ConfirmBox.ShowConfirmBoxDialog(string.Format("指纹仪故障 故障代码:{0}\n 是否重新打开指纹仪", fingerPrintStat)); if (confirmResault == DialogResult.Cancel) { IsRollCalling = false; return; // 如果点了否 就结束指纹仪点名. 点是 重新初始化. 手动签到那里要判断一下(不用判断了 在switch的入口那边加了一个对IsrollCalling的一个判断.) } else { FingerPrintHandle = HdFingerprintHelper.FpOpenUsb(0xFFFFFFFF, 1000); // 重新初始化指纹仪 } break; } } } }