PosMachinesTwoDbconn.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using MySystem.MainModels;
  5. namespace MySystem
  6. {
  7. public class PosMachinesTwoDbconn
  8. {
  9. public readonly static PosMachinesTwoDbconn Instance = new PosMachinesTwoDbconn();
  10. #region 获取单个字段
  11. public PosMachinesTwo Get(int Id)
  12. {
  13. // string key = "PosMachinesTwo:" + Id;
  14. // if (RedisDbconn.Instance.Exists(key))
  15. // {
  16. // PosMachinesTwo obj = RedisDbconn.Instance.Get<PosMachinesTwo>(key);
  17. // if (obj != null)
  18. // {
  19. // return obj;
  20. // }
  21. // }
  22. WebCMSEntities db = new WebCMSEntities();
  23. PosMachinesTwo order = db.PosMachinesTwo.FirstOrDefault(m => m.Id == Id);
  24. if (order != null)
  25. {
  26. // RedisDbconn.Instance.Set(key, order);
  27. // RedisDbconn.Instance.SetExpire(key, Library.function.get_Random(1800, 5400));
  28. }
  29. db.Dispose();
  30. return order;
  31. }
  32. public PosMachinesTwo Get(string PosSn)
  33. {
  34. string key = "PosMachinesTwo:" + PosSn;
  35. if (RedisDbconn.Instance.Exists(key))
  36. {
  37. PosMachinesTwo obj = RedisDbconn.Instance.Get<PosMachinesTwo>(key);
  38. if (obj != null)
  39. {
  40. return obj;
  41. }
  42. }
  43. WebCMSEntities db = new WebCMSEntities();
  44. PosMachinesTwo order = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == PosSn);
  45. if (order != null)
  46. {
  47. RedisDbconn.Instance.Set(key, order);
  48. RedisDbconn.Instance.SetExpire(key, Library.function.get_Random(1800, 5400));
  49. }
  50. return order;
  51. }
  52. #endregion
  53. }
  54. }