using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using EntityDataSet;
using libzkfpcsharp;
namespace IntelligentControlForsx.Service.FingerSvc
{
public class UserSvc
{
///
/// 存储所有用户信息,key为用户指纹模板,value为用户实体
///
public static Dictionary userDic = new Dictionary();
private static UserSvc svc = new UserSvc();
private UserSvc()
{
}
public static UserSvc GetUserSvc()
{
return svc;
}
///
/// 管理员登录验证
///
/// 验证句柄
/// 输入的指纹
///
public bool AdminUserCheck(IntPtr mDBHandle, byte[] fingerTemp)
{
bool IsCheckSuccess = false;
foreach (KeyValuePair kv in userDic)
{
int checkScore = zkfp2.DBMatch(mDBHandle, fingerTemp, kv.Key);
if (checkScore > 0)
{
if (kv.Value.user_name == "admin")
{
IsCheckSuccess = true;
}
}
}
return IsCheckSuccess;
}
///
/// 登录验证
///
/// 句柄
/// 输入指纹
/// 符合输入指纹的用户
public user LoginUserCheck(IntPtr mDBHandle, byte[] fingerTemp)
{
user loginUser = null;
foreach (KeyValuePair kv in userDic)
{
int checkScore = zkfp2.DBMatch(mDBHandle, fingerTemp, kv.Key);
if (checkScore > 0)
{
loginUser = kv.Value;
break;
}
}
return loginUser;
}
///
/// 用户初始化(将关系库中所有的用户添加到缓存)
///
public void InitUser()
{
Dictionary dic = new Dictionary();
using (wisdom_cs_entity ctx = new wisdom_cs_entity())
{
IList list = ctx.user.Select(s => s).ToList();
for (int i = 0; i < list.Count; i++)
{
if (list[i].finger1_template != null)
dic.Add(list[i].finger1_template, list[i]);
if (list[i].finger2_template != null)
dic.Add(list[i].finger2_template, list[i]);
if (list[i].finger3_template != null)
dic.Add(list[i].finger3_template, list[i]);
if (list[i].finger4_template != null)
dic.Add(list[i].finger4_template, list[i]);
if (list[i].finger5_template != null)
dic.Add(list[i].finger5_template, list[i]);
if (list[i].finger6_template != null)
dic.Add(list[i].finger6_template, list[i]);
if (list[i].finger7_template != null)
dic.Add(list[i].finger7_template, list[i]);
if (list[i].finger8_template != null)
dic.Add(list[i].finger8_template, list[i]);
if (list[i].finger9_template != null)
dic.Add(list[i].finger9_template, list[i]);
if (list[i].finger10_template != null)
dic.Add(list[i].finger10_template, list[i]);
}
userDic = dic;
}
}
///
/// 注册用户
///
///
///
public int RegisterUser(user user)
{
using (wisdom_cs_entity ctx = new wisdom_cs_entity())
{
ctx.Entry(user).State = EntityState.Added;
int count = ctx.SaveChanges();
return count;
}
}
}
}