using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.IO; using System.Linq; using System.Text; using System.Threading; using System.Windows.Forms; using EntityDataSet; using IntelligentControlForsx.Service.FingerSvc; using IntelligentControlForsx.Service.WindturbineControl.Domain.Cmd; using IntelligentControlForsx.Service.WindturbineControl.IntPtrSvc; using libzkfpcsharp; namespace Gyee_Control.View { public partial class Auth : Form { #region 指纹读取常用量 bool bIsTimeToDie = false; IntPtr mDevHandle = IntPtr.Zero; IntPtr mDBHandle = IntPtr.Zero; IntPtr FormHandle = IntPtr.Zero; const int MESSAGE_CAPTURED_OK = 0x0400 + 6; byte[] FPBuffer;//返回图像 private byte[] fingerTemp = new byte[2048];//指纹模板 int fingerTempLength = 2048;//实际返回指纹模板长度 private int mfpWidth = 0;//图片宽度 private int mfpHeight = 0;//图片高度 #endregion IList faultSendList = new List();//发送失败的风机集合 private UserSvc userSvc; private string describeString; private IList cmdInfoList; private Confirm confirmForm; public Auth(Confirm confirm, IList infoList, string describe) { InitializeComponent(); confirmForm = confirm; describeString = describe; cmdInfoList = infoList; string windturbineName = String.Join(",", infoList.Select(s => s.WindturbineId).ToArray()); string cmdString = ""; switch (infoList[0].CmdType) { case CmdType.Start: cmdString = "启动操作"; break; case CmdType.Stop: cmdString = "停止操作"; break; case CmdType.Reset: cmdString = "复位操作"; break; case CmdType.Maintain: cmdString = "维护操作"; break; case CmdType.UnMaintain: cmdString = "取消维护操作"; break; } this.lblWaringInfo.Text = cmdString; this.passed = false; userSvc = UserSvc.GetUserSvc(); userSvc.InitUser(); FingerInit(); StartsScanning(); } /// /// 初始化指纹设备 /// private void FingerInit() { int ret = zkfperrdef.ZKFP_ERR_OK; if ((ret = zkfp2.Init()) == zkfperrdef.ZKFP_ERR_OK) { int nCount = zkfp2.GetDeviceCount(); if (nCount <= 0) { zkfp2.Terminate(); MessageBox.Show("找不到设备,请检查指纹刷是否连接"); } } else { MessageBox.Show("指纹输入设备初始化失败,请检查指纹刷是否连接"); } } /// /// 打开扫描 /// private void StartsScanning() { Console.WriteLine("设备初始化"); int ret = zkfp.ZKFP_ERR_OK; if (IntPtr.Zero == (mDevHandle = zkfp2.OpenDevice(0))) { MessageBox.Show("打开扫描失败"); return; } if (IntPtr.Zero == (mDBHandle = zkfp2.DBInit())) { MessageBox.Show("打开扫描失败"); zkfp2.CloseDevice(mDevHandle); mDevHandle = IntPtr.Zero; return; } byte[] paramValue = new byte[4]; int size = 4; zkfp2.GetParameters(mDevHandle, 1, paramValue, ref size); zkfp2.ByteArray2Int(paramValue, ref mfpWidth); size = 4; zkfp2.GetParameters(mDevHandle, 2, paramValue, ref size); zkfp2.ByteArray2Int(paramValue, ref mfpHeight); FPBuffer = new byte[mfpWidth * mfpHeight]; Thread captureThread = new Thread(new ThreadStart(DoCapture)); captureThread.IsBackground = true; captureThread.Start(); bIsTimeToDie = false; } /// /// 指纹扫描线程 /// private void DoCapture() { while (!bIsTimeToDie) { int ret = zkfp2.AcquireFingerprint(mDevHandle, FPBuffer, fingerTemp, ref fingerTempLength); if (ret == zkfp.ZKFP_ERR_OK) { FingerReadSvc.SendMessage(FormHandle, MESSAGE_CAPTURED_OK, IntPtr.Zero, IntPtr.Zero); } Thread.Sleep(200); } } protected override void DefWndProc(ref Message m) { switch (m.Msg) { case MESSAGE_CAPTURED_OK: { MemoryStream ms = new MemoryStream(); BitmapFormat.GetBitmap(FPBuffer, mfpWidth, mfpHeight, ref ms); BitmapFormat.WriteBitmap(FPBuffer, mfpWidth, mfpHeight); Bitmap bmp = new Bitmap(ms); //this.picFingerPhoto.Image = bmp; user user = UserSvc.GetUserSvc().LoginUserCheck(mDBHandle, fingerTemp); if (user == null) { lblInfo.Text = "验证失败,请重试!"; } else { //发送控制命令 try { ControlSvc controlSvc = ControlSvc.GetControlSvc(); IList faultSendList = new List(); bool isSend = controlSvc.SendCmdByWindturbineIdList(cmdInfoList.Select(s => s.WindturbineId).ToList(), "SBQ_FDC", cmdInfoList[0].CmdType, out faultSendList, describeString, user); if (isSend) { MessageBox.Show("命令发送成功"); this.Close(); this.passed = false; zkfp2.Terminate(); zkfp2.CloseDevice(mDevHandle); zkfp2.CloseDevice(mDBHandle); } else { string windturbineIds = ""; for (int i = 0; i < faultSendList.Count; i++) { windturbineIds = windturbineIds + faultSendList[i] + ","; } MessageBox.Show("命令发送失败的风机有:" + windturbineIds); } } catch (Exception ex) { Console.WriteLine(ex.Message); } } } break; default: base.DefWndProc(ref m); break; } } private void lblClose_Click(object sender, EventArgs e) { this.passed = false; zkfp2.Terminate(); zkfp2.CloseDevice(mDevHandle); zkfp2.CloseDevice(mDBHandle); this.Close(); } private void Auth_Load(object sender, EventArgs e) { FormHandle = this.Handle; } } }