SysContext.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. using System.Collections.Generic;
  2. //using Liger.Common.Extensions;
  3. using System;
  4. namespace LigerRM.Common
  5. {
  6. public sealed class SysContext
  7. {
  8. public static void SetCurrent(int userid)
  9. {
  10. CurrentUserID = userid.ToString();
  11. }
  12. public static void ClearUserStatus()
  13. {
  14. CookieHelper.SetCookie("CurrentUserID", "0", DateTime.Now);
  15. }
  16. /// <summary>
  17. /// 当前用户角色 多个用逗号隔开
  18. /// </summary>
  19. public static string CurrentRoleID
  20. {
  21. get
  22. {
  23. try
  24. {
  25. return CookieHelper.GetCookieValue("CurrentRoleID").ToString();
  26. }
  27. catch
  28. {
  29. return "0";
  30. }
  31. }
  32. set
  33. {
  34. var cookie = CookieHelper.GetCookie("CurrentRoleID");
  35. if (cookie != null)
  36. {
  37. CookieHelper.SetCookie("CurrentRoleID", value, DateTime.Now.AddHours(1));
  38. }
  39. else
  40. {
  41. //有效期,一个钟头
  42. CookieHelper.AddCookie("CurrentRoleID", value, DateTime.Now.AddHours(1));
  43. }
  44. }
  45. }
  46. /// <summary>
  47. /// 当前用户部门
  48. /// </summary>
  49. public static string CurrentDeptID
  50. {
  51. get
  52. {
  53. try
  54. {
  55. return CookieHelper.GetCookieValue("CurrentDeptID").ToString();
  56. }
  57. catch
  58. {
  59. return "0";
  60. }
  61. }
  62. set
  63. {
  64. var cookie = CookieHelper.GetCookie("CurrentDeptID");
  65. if (cookie != null)
  66. {
  67. CookieHelper.SetCookie("CurrentDeptID", value.ToString(), DateTime.Now.AddHours(1));
  68. }
  69. else
  70. {
  71. //有效期,一个钟头
  72. CookieHelper.AddCookie("CurrentDeptID", value.ToString(), DateTime.Now.AddHours(1));
  73. }
  74. }
  75. }
  76. /// <summary>
  77. /// 供应商ID 如果当前用户是供应商,需要这个
  78. /// </summary>
  79. public static string CurrentSupplierID
  80. {
  81. get
  82. {
  83. try
  84. {
  85. return CookieHelper.GetCookieValue("CurrentSupplierID").ToString();
  86. }
  87. catch
  88. {
  89. return "0";
  90. }
  91. }
  92. set
  93. {
  94. var cookie = CookieHelper.GetCookie("CurrentSupplierID");
  95. if (cookie != null)
  96. {
  97. CookieHelper.SetCookie("CurrentSupplierID", value.ToString(), DateTime.Now.AddHours(1));
  98. }
  99. else
  100. {
  101. //有效期,一个钟头
  102. CookieHelper.AddCookie("CurrentSupplierID", value.ToString(), DateTime.Now.AddHours(1));
  103. }
  104. }
  105. }
  106. /// <summary>
  107. /// 用户ID
  108. /// </summary>
  109. public static string CurrentUserID
  110. {
  111. get
  112. {
  113. try
  114. {
  115. return CookieHelper.GetCookieValue("CurrentUserID").ToString();
  116. }
  117. catch
  118. {
  119. return "0";
  120. }
  121. }
  122. set
  123. {
  124. var cookie = CookieHelper.GetCookie("CurrentUserID");
  125. if (cookie != null)
  126. {
  127. CookieHelper.SetCookie("CurrentUserID", value.ToString(), DateTime.Now.AddHours(1));
  128. }
  129. else
  130. {
  131. //有效期,一个钟头
  132. CookieHelper.AddCookie("CurrentUserID", value.ToString(), DateTime.Now.AddHours(1));
  133. }
  134. }
  135. }
  136. public static string CurrentEmployeeID
  137. {
  138. get
  139. {
  140. try
  141. {
  142. return CookieHelper.GetCookieValue("CurrentEmployeeID").ToString();
  143. }
  144. catch
  145. {
  146. return "0";
  147. }
  148. }
  149. set
  150. {
  151. var cookie = CookieHelper.GetCookie("CurrentEmployeeID");
  152. if (cookie != null)
  153. {
  154. CookieHelper.SetCookie("CurrentEmployeeID", value.ToString(), DateTime.Now.AddHours(1));
  155. }
  156. else
  157. {
  158. //有效期,一个钟头
  159. CookieHelper.AddCookie("CurrentEmployeeID", value.ToString(), DateTime.Now.AddHours(1));
  160. }
  161. }
  162. }
  163. /// <summary>
  164. /// 上次登录时间
  165. /// </summary>
  166. public static string CurrentUserLastLoginTime
  167. {
  168. get
  169. {
  170. return CookieHelper.GetCookieValue("CurrentUserLastLoginTime");
  171. }
  172. set
  173. {
  174. var cookie = CookieHelper.GetCookie("CurrentUserLastLoginTime");
  175. if (cookie != null)
  176. {
  177. CookieHelper.SetCookie("CurrentUserLastLoginTime", value.ToString(), DateTime.Now.AddHours(1));
  178. }
  179. else
  180. {
  181. //有效期,一个钟头
  182. CookieHelper.AddCookie("CurrentUserLastLoginTime", value.ToString(), DateTime.Now.AddHours(1));
  183. }
  184. }
  185. }
  186. public static string CurrentUserTitle
  187. {
  188. get
  189. {
  190. try
  191. {
  192. return CookieHelper.GetCookieValue("CurrentUserTitle").ToString();
  193. }
  194. catch
  195. {
  196. return "0";
  197. }
  198. }
  199. set
  200. {
  201. var cookie = CookieHelper.GetCookie("CurrentUserTitle");
  202. if (cookie != null)
  203. {
  204. CookieHelper.SetCookie("CurrentUserTitle", value, DateTime.Now.AddHours(1));
  205. }
  206. else
  207. {
  208. //有效期,一个钟头
  209. CookieHelper.AddCookie("CurrentUserTitle", value, DateTime.Now.AddHours(1));
  210. }
  211. }
  212. }
  213. }
  214. }