StaffDal.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using Cksoft.Data;
  2. using Cksoft.Unity;
  3. using DllEapEntity;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. namespace DllEapDal
  8. {
  9. public class StaffDal
  10. {
  11. private IDatabase CurrDb = null;
  12. public StaffDal(IDatabase db)
  13. {
  14. CurrDb = db;
  15. }
  16. public Staff Login(Staff staff, ref string errorinfo)
  17. {
  18. try
  19. {
  20. if (string.IsNullOrEmpty(staff.FCode))
  21. {
  22. errorinfo = "用户名为空";
  23. return null;
  24. }
  25. if (string.IsNullOrEmpty(staff.Password))
  26. {
  27. errorinfo = "密码为空";
  28. return null;
  29. }
  30. List<Staff> obj = CurrDb.FindListForCondition<Staff>($" and a.fcode='{staff.FCode}'", ref errorinfo).ToList();
  31. if (obj == null)
  32. {
  33. errorinfo = $"用户代码={staff.FCode}不存在,异常错误:"+errorinfo;
  34. return null;
  35. }
  36. if(obj.Count<=0)
  37. {
  38. errorinfo = $"用户代码={staff.FCode}不存在";
  39. return null;
  40. }
  41. var pass = new Md5Helper().EnCrypt(staff.Password);
  42. if (obj[0].Password != pass)
  43. {
  44. errorinfo = "用户名或密码不正确";
  45. return null;
  46. }
  47. return obj[0];
  48. }
  49. catch (Exception e)
  50. {
  51. errorinfo = e.Message;
  52. return null;
  53. }
  54. }
  55. }
  56. }