BLL_iNethinkCMS_User.cs 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. /*******************************************************************************
  2. * iNethinkCMS - 网站内容管理系统
  3. * Copyright (C) 2012-2013 inethink.com
  4. *
  5. * @author jackyang <69991000@qq.com>
  6. * @website http://cms.inethink.com
  7. * @version 1.3.6.0 (2013-08-14)
  8. *
  9. * This is licensed under the GNU LGPL, version 3.0 or later.
  10. * For details, see: http://www.gnu.org/licenses/gpl-3.0.html
  11. *******************************************************************************/
  12. using System;
  13. using System.Data;
  14. using System.Collections.Generic;
  15. using iNethinkCMS.Command;
  16. using iNethinkCMS.Model;
  17. namespace iNethinkCMS.BLL
  18. {
  19. /// <summary>
  20. /// BLL_iNethinkCMS_User
  21. /// </summary>
  22. public partial class BLL_iNethinkCMS_User
  23. {
  24. private readonly iNethinkCMS.DAL.DAL_iNethinkCMS_User dal = new iNethinkCMS.DAL.DAL_iNethinkCMS_User();
  25. public BLL_iNethinkCMS_User()
  26. {
  27. }
  28. #region Method
  29. /// <summary>
  30. /// 是否存在该记录
  31. /// </summary>
  32. public bool Exists(int ID)
  33. {
  34. return dal.Exists(ID);
  35. }
  36. /// <summary>
  37. /// 验证用户
  38. /// </summary>
  39. public bool Exists(int UserType, string UserName, string UserPass)
  40. {
  41. return dal.Exists(UserType, UserName, UserPass);
  42. }
  43. /// <summary>
  44. /// 验证Vip用户
  45. /// </summary>
  46. public bool ExistsVip(string UserName, string UserPass)
  47. {
  48. return dal.ExistsVip(UserName, UserPass);
  49. }
  50. /// <summary>
  51. /// 增加一条数据
  52. /// </summary>
  53. public int Add(iNethinkCMS.Model.Model_iNethinkCMS_User model)
  54. {
  55. return dal.Add(model);
  56. }
  57. /// <summary>
  58. /// 更新一条数据
  59. /// </summary>
  60. public bool Update(iNethinkCMS.Model.Model_iNethinkCMS_User model)
  61. {
  62. return dal.Update(model);
  63. }
  64. /// <summary>
  65. /// 删除一条数据
  66. /// </summary>
  67. public bool Delete(int ID)
  68. {
  69. return dal.Delete(ID);
  70. }
  71. /// <summary>
  72. /// 删除一条数据
  73. /// </summary>
  74. public bool DeleteList(string IDlist)
  75. {
  76. return dal.DeleteList(IDlist);
  77. }
  78. /// <summary>
  79. /// 得到一个对象实体
  80. /// </summary>
  81. public iNethinkCMS.Model.Model_iNethinkCMS_User GetModel(int ID)
  82. {
  83. return dal.GetModel(ID);
  84. }
  85. /// <summary>
  86. /// 得到一个对象实体
  87. /// </summary>
  88. public iNethinkCMS.Model.Model_iNethinkCMS_User GetModel(string UserName)
  89. {
  90. return dal.GetModel(UserName);
  91. }
  92. /// <summary>
  93. /// 得到一个对象实体,从缓存中
  94. /// </summary>
  95. public iNethinkCMS.Model.Model_iNethinkCMS_User GetModelByCache(int ID)
  96. {
  97. string CacheKey = iNethinkCMS.Command.Command_Configuration.GetConfigString("CacheKey");
  98. CacheKey = CacheKey + "_Model_iNethinkCMS_UserModel_" + ID;
  99. object objModel = iNethinkCMS.Command.Command_DataCache.GetCache(CacheKey);
  100. if (objModel == null)
  101. {
  102. try
  103. {
  104. objModel = dal.GetModel(ID);
  105. if (objModel != null)
  106. {
  107. int ModelCache = iNethinkCMS.Command.Command_Configuration.GetConfigInt("CacheTime");
  108. iNethinkCMS.Command.Command_DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddSeconds(ModelCache), TimeSpan.Zero);
  109. }
  110. }
  111. catch
  112. {
  113. }
  114. }
  115. return (iNethinkCMS.Model.Model_iNethinkCMS_User)objModel;
  116. }
  117. /// <summary>
  118. /// 获得数据列表
  119. /// </summary>
  120. public DataSet GetList(string strWhere)
  121. {
  122. return dal.GetList(strWhere);
  123. }
  124. /// <summary>
  125. /// 获得前几行数据
  126. /// </summary>
  127. public DataSet GetList(int Top, string strWhere, string filedOrder)
  128. {
  129. return dal.GetList(Top, strWhere, filedOrder);
  130. }
  131. /// <summary>
  132. /// 获得数据列表
  133. /// </summary>
  134. public List<iNethinkCMS.Model.Model_iNethinkCMS_User> GetModelList(string strWhere)
  135. {
  136. DataSet ds = dal.GetList(strWhere);
  137. return DataTableToList(ds.Tables[0]);
  138. }
  139. /// <summary>
  140. /// 获得数据列表
  141. /// </summary>
  142. public List<iNethinkCMS.Model.Model_iNethinkCMS_User> DataTableToList(DataTable dt)
  143. {
  144. List<iNethinkCMS.Model.Model_iNethinkCMS_User> modelList = new List<iNethinkCMS.Model.Model_iNethinkCMS_User>();
  145. int rowsCount = dt.Rows.Count;
  146. if (rowsCount > 0)
  147. {
  148. iNethinkCMS.Model.Model_iNethinkCMS_User model;
  149. for (int n = 0; n < rowsCount; n++)
  150. {
  151. model = new iNethinkCMS.Model.Model_iNethinkCMS_User();
  152. if (dt.Rows[n]["ID"] != null && dt.Rows[n]["ID"].ToString() != "")
  153. {
  154. model.ID = int.Parse(dt.Rows[n]["ID"].ToString());
  155. }
  156. if (dt.Rows[n]["UserType"] != null && dt.Rows[n]["UserType"].ToString() != "")
  157. {
  158. model.UserType = int.Parse(dt.Rows[n]["UserType"].ToString());
  159. }
  160. if (dt.Rows[n]["UserName"] != null && dt.Rows[n]["UserName"].ToString() != "")
  161. {
  162. model.UserName = dt.Rows[n]["UserName"].ToString();
  163. }
  164. if (dt.Rows[n]["UserPass"] != null && dt.Rows[n]["UserPass"].ToString() != "")
  165. {
  166. model.UserPass = dt.Rows[n]["UserPass"].ToString();
  167. }
  168. if (dt.Rows[n]["UserTrueName"] != null && dt.Rows[n]["UserTrueName"].ToString() != "")
  169. {
  170. model.UserName = dt.Rows[n]["UserTrueName"].ToString();
  171. }
  172. if (dt.Rows[n]["UserEmail"] != null && dt.Rows[n]["UserEmail"].ToString() != "")
  173. {
  174. model.UserName = dt.Rows[n]["UserEmail"].ToString();
  175. }
  176. if (dt.Rows[n]["UserPower"] != null && dt.Rows[n]["UserPower"].ToString() != "")
  177. {
  178. model.UserPower = dt.Rows[n]["UserPower"].ToString();
  179. }
  180. if (dt.Rows[n]["UserChannelPower"] != null && dt.Rows[n]["UserChannelPower"].ToString() != "")
  181. {
  182. model.UserChannelPower = dt.Rows[n]["UserChannelPower"].ToString();
  183. }
  184. if (dt.Rows[n]["UserRegTime"] != null && dt.Rows[n]["UserRegTime"].ToString() != "")
  185. {
  186. model.UserRegTime = DateTime.Parse(dt.Rows[n]["UserRegTime"].ToString());
  187. }
  188. if (dt.Rows[n]["SecurityCode"] != null && dt.Rows[n]["SecurityCode"].ToString() != "")
  189. {
  190. model.SecurityCode = dt.Rows[n]["SecurityCode"].ToString();
  191. }
  192. modelList.Add(model);
  193. }
  194. }
  195. return modelList;
  196. }
  197. /// <summary>
  198. /// 获得数据列表
  199. /// </summary>
  200. public DataSet GetAllList()
  201. {
  202. return GetList("");
  203. }
  204. /// <summary>
  205. /// 分页获取数据列表
  206. /// </summary>
  207. public int GetRecordCount(string strWhere)
  208. {
  209. return dal.GetRecordCount(strWhere);
  210. }
  211. /// <summary>
  212. /// 分页获取数据列表
  213. /// </summary>
  214. public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
  215. {
  216. return dal.GetListByPage(strWhere, orderby, startIndex, endIndex);
  217. }
  218. static DataTable _AllUserList = null;
  219. /// <summary>
  220. /// 获取全部用户
  221. /// </summary>
  222. public static DataTable AllUserList
  223. {
  224. get
  225. {
  226. if (_AllUserList == null)
  227. {
  228. RefreshAllUserList();
  229. }
  230. return BLL_iNethinkCMS_User._AllUserList;
  231. }
  232. }
  233. /// <summary>
  234. /// 刷新全部用户
  235. /// </summary>
  236. public static void RefreshAllUserList()
  237. {
  238. if (_AllUserList != null)
  239. {
  240. _AllUserList.Rows.Clear();
  241. _AllUserList.Dispose();
  242. _AllUserList = null;
  243. }
  244. _AllUserList = new BLL_iNethinkCMS_User().GetList("1=1").Tables[0];
  245. }
  246. /// <summary>
  247. /// 根据用户ID获取用户名
  248. /// </summary>
  249. /// <param name="byUID"></param>
  250. /// <returns></returns>
  251. public static string GetIDToUserTrueName(int byUID)
  252. {
  253. string reName = "未知用户";
  254. foreach (DataRow row in BLL_iNethinkCMS_User.AllUserList.Rows)
  255. {
  256. if (row["id"].ToString() == byUID.ToString())
  257. {
  258. reName = row["UserTrueName"].ToString();
  259. break;
  260. }
  261. }
  262. return reName;
  263. }
  264. #endregion Method
  265. }
  266. }