123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239 |
- 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<string> faultSendList = new List<string>();//发送失败的风机集合
- private UserSvc userSvc;
- private string describeString;
- private IList<WindturbineCmdInfo> cmdInfoList;
- private Confirm confirmForm;
- public Auth(Confirm confirm, IList<WindturbineCmdInfo> 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();
- }
- /// <summary>
- /// 初始化指纹设备
- /// </summary>
- 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("指纹输入设备初始化失败,请检查指纹刷是否连接");
- }
- }
- /// <summary>
- /// 打开扫描
- /// </summary>
- 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;
- }
- /// <summary>
- /// 指纹扫描线程
- /// </summary>
- 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<string> faultSendList = new List<string>();
- 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;
- }
- }
- }
|