ab56a9bcf7
SVN-Revision: r240
176 lines
5.1 KiB
C#
176 lines
5.1 KiB
C#
using libzkfpcsharp;
|
|
using Lskj.Core;
|
|
using Lskj.Model;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Windows.Media.Imaging;
|
|
|
|
namespace Lskj.Control.ZKFinger
|
|
{
|
|
public class FingerHelper
|
|
{
|
|
public bool IsInit = false;
|
|
public bool IsOpen = false;
|
|
public int DeviceCount = 0;
|
|
public IntPtr mDevHandle = IntPtr.Zero;
|
|
public IntPtr mDBHandle = IntPtr.Zero;
|
|
public IntPtr FormHandle = IntPtr.Zero;
|
|
public bool bIsTimeToDie = false;
|
|
public bool IsRegister = false;
|
|
public bool bIdentify = true;
|
|
public byte[] FPBuffer;
|
|
public int RegisterCount = 0;
|
|
public const int REGISTER_FINGER_COUNT = 3;
|
|
public byte[][] RegTmps = new byte[3][];
|
|
public byte[] RegTmp = new byte[2048];
|
|
public byte[] CapTmp = new byte[2048];
|
|
public int cbCapTmp = 2048;
|
|
public int cbRegTmp = 0;
|
|
public int iFid = 1;
|
|
|
|
public int mfpWidth = 0;
|
|
public int mfpHeight = 0;
|
|
public FingerHelper()
|
|
{
|
|
if (!IsInit)
|
|
{
|
|
InitFinger();
|
|
}
|
|
if (IsInit && !IsOpen)
|
|
{
|
|
OpenFinger();
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 初始化识别器
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public bool InitFinger()
|
|
{
|
|
try
|
|
{
|
|
int ret = zkfperrdef.ZKFP_ERR_OK;
|
|
if ((ret = zkfp2.Init()) == zkfperrdef.ZKFP_ERR_OK)
|
|
{
|
|
DeviceCount = zkfp2.GetDeviceCount();
|
|
if (DeviceCount > 0)
|
|
{
|
|
IsInit = true;
|
|
}
|
|
else
|
|
{
|
|
zkfp2.Terminate();
|
|
}
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
}
|
|
return IsInit;
|
|
}
|
|
/// <summary>
|
|
/// 打开识别器
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public bool OpenFinger()
|
|
{
|
|
try
|
|
{
|
|
int ret = zkfp.ZKFP_ERR_OK;
|
|
if (IntPtr.Zero == (mDevHandle = zkfp2.OpenDevice(DeviceCount - 1)))
|
|
{
|
|
return IsOpen;
|
|
}
|
|
if (IntPtr.Zero == (mDBHandle = zkfp2.DBInit()))
|
|
{
|
|
zkfp2.CloseDevice(mDevHandle);
|
|
mDevHandle = IntPtr.Zero;
|
|
return IsOpen;
|
|
}
|
|
RegisterCount = 0;
|
|
cbRegTmp = 0;
|
|
iFid = 1;
|
|
for (int i = 0; i < 3; i++)
|
|
{
|
|
RegTmps[i] = new byte[2048];
|
|
}
|
|
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];
|
|
IsOpen = true;
|
|
}
|
|
catch (Exception)
|
|
{
|
|
}
|
|
return IsOpen;
|
|
}
|
|
public void Close()
|
|
{
|
|
try
|
|
{
|
|
IsInit = false;
|
|
IsOpen = false;
|
|
RegisterCount = 0;
|
|
Thread.Sleep(1000);
|
|
zkfp2.CloseDevice(mDevHandle);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
}
|
|
}
|
|
public static void FreeSensor()
|
|
{
|
|
try
|
|
{
|
|
zkfp2.Terminate();
|
|
//cbRegTmp = 0;
|
|
}
|
|
catch (Exception)
|
|
{
|
|
}
|
|
}
|
|
public string Compare()
|
|
{
|
|
string employeeid = "";
|
|
try
|
|
{
|
|
string selectSql = string.Format("select EmployeeId,FingerBuffer from P_EmployeeTab where FingerBuffer is not null", ERPInfo.Instance.UserId);
|
|
DataTable bufferDataTab = SqlHelper.ExecuteDataTable(selectSql);
|
|
if (bufferDataTab == null && bufferDataTab.Rows.Count == 0)
|
|
{
|
|
return employeeid;
|
|
}
|
|
else
|
|
{
|
|
foreach (DataRow row in bufferDataTab.Rows)
|
|
{
|
|
byte[] q_Finger = (byte[])row["FingerBuffer"];
|
|
int ret = zkfp2.DBMatch(mDBHandle, CapTmp, q_Finger);
|
|
if (0 < ret)
|
|
{
|
|
employeeid = row["EmployeeId"] + "";
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
}
|
|
return employeeid;
|
|
}
|
|
}
|
|
} |