123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- 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
- {
- /// <summary>
- /// 存储所有用户信息,key为用户指纹模板,value为用户实体
- /// </summary>
- public static Dictionary<byte[], user> userDic = new Dictionary<byte[], user>();
- private static UserSvc svc = new UserSvc();
- private UserSvc()
- {
- }
- public static UserSvc GetUserSvc()
- {
- return svc;
- }
- /// <summary>
- /// 管理员登录验证
- /// </summary>
- /// <param name="mDBHandle">验证句柄</param>
- /// <param name="fingerTemp">输入的指纹</param>
- /// <returns></returns>
- public bool AdminUserCheck(IntPtr mDBHandle, byte[] fingerTemp)
- {
- bool IsCheckSuccess = false;
- foreach (KeyValuePair<byte[], user> kv in userDic)
- {
- int checkScore = zkfp2.DBMatch(mDBHandle, fingerTemp, kv.Key);
- if (checkScore > 0)
- {
- if (kv.Value.user_name == "admin")
- {
- IsCheckSuccess = true;
- }
- }
- }
- return IsCheckSuccess;
- }
- /// <summary>
- /// 登录验证
- /// </summary>
- /// <param name="mDBHandle">句柄</param>
- /// <param name="fingerTemp">输入指纹</param>
- /// <returns>符合输入指纹的用户</returns>
- public user LoginUserCheck(IntPtr mDBHandle, byte[] fingerTemp)
- {
- user loginUser = null;
- foreach (KeyValuePair<byte[], user> kv in userDic)
- {
- int checkScore = zkfp2.DBMatch(mDBHandle, fingerTemp, kv.Key);
- if (checkScore > 0)
- {
- loginUser = kv.Value;
- break;
- }
- }
- return loginUser;
- }
- /// <summary>
- /// 用户初始化(将关系库中所有的用户添加到缓存)
- /// </summary>
- public void InitUser()
- {
- Dictionary<byte[], user> dic = new Dictionary<byte[], user>();
- using (wisdom_cs_entity ctx = new wisdom_cs_entity())
- {
- IList<user> 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;
- }
- }
- /// <summary>
- /// 注册用户
- /// </summary>
- /// <param name="user"></param>
- /// <returns></returns>
- 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;
- }
- }
- }
- }
|