Nessuna descrizione

T_Sys_DictionaryValue.cs 9.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. using System;
  2. using System.Data;
  3. using System.Collections.Generic;
  4. using CallCenterApi.Model;
  5. using CallCenter.Utility;
  6. namespace CallCenterApi.BLL
  7. {
  8. /// <summary>
  9. /// 1
  10. /// </summary>
  11. public partial class T_Sys_DictionaryValue
  12. {
  13. private readonly CallCenterApi.DAL.T_Sys_DictionaryValue dal = new CallCenterApi.DAL.T_Sys_DictionaryValue();
  14. public T_Sys_DictionaryValue()
  15. { }
  16. #region Method
  17. /// <summary>
  18. /// 是否存在该记录
  19. /// </summary>
  20. public bool Exists(int F_ValueId)
  21. {
  22. return dal.Exists(F_ValueId);
  23. }
  24. /// <summary>
  25. /// 增加一条数据
  26. /// </summary>
  27. public int Add(CallCenterApi.Model.T_Sys_DictionaryValue model)
  28. {
  29. OutRedis();
  30. return dal.Add(model);
  31. }
  32. /// <summary>
  33. /// 更新一条数据
  34. /// </summary>
  35. public bool Update(CallCenterApi.Model.T_Sys_DictionaryValue model)
  36. {
  37. OutRedis();
  38. return dal.Update(model);
  39. }
  40. /// <summary>
  41. /// 删除一条数据
  42. /// </summary>
  43. public bool Delete(int F_ValueId)
  44. {
  45. OutRedis();
  46. return dal.Delete(F_ValueId);
  47. }
  48. /// <summary>
  49. /// 删除一条数据
  50. /// </summary>
  51. public bool DeleteList(string F_ValueIdlist)
  52. {
  53. OutRedis();
  54. return dal.DeleteList(F_ValueIdlist);
  55. }
  56. public bool DeleteList1(string F_ValueIdlist)
  57. {
  58. OutRedis();
  59. return dal.DeleteList1(F_ValueIdlist);
  60. }
  61. /// <summary>
  62. /// 得到一个对象实体
  63. /// </summary>
  64. public CallCenterApi.Model.T_Sys_DictionaryValue GetModel(int F_ValueId)
  65. {
  66. var dt = GetRedis();
  67. if (dt != null)
  68. {
  69. var dr = dt.Select("F_ValueId=" + F_ValueId);
  70. if (dr != null && dr.Length > 0)
  71. {
  72. return dal.DataRowToModel(dr[0]);
  73. }
  74. else
  75. {
  76. return null;
  77. }
  78. }
  79. else
  80. {
  81. return dal.GetModel(F_ValueId);
  82. }
  83. }
  84. /// <summary>
  85. /// 得到一个对象实体,从缓存中
  86. /// </summary>
  87. //public CallCenterApi.Model.T_Sys_DictionaryValue GetModelByCache(int F_ValueId)
  88. //{
  89. // string CacheKey = "T_Sys_DictionaryValueModel-" + F_ValueId;
  90. // object objModel = SZRX.Common.DataCache.GetCache(CacheKey);
  91. // if (objModel == null)
  92. // {
  93. // try
  94. // {
  95. // objModel = dal.GetModel(F_ValueId);
  96. // if (objModel != null)
  97. // {
  98. // int ModelCache = SZRX.Common.ConfigHelper.GetConfigInt("ModelCache");
  99. // SZRX.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
  100. // }
  101. // }
  102. // catch{}
  103. // }
  104. // return (CallCenterApi.Model.T_Sys_DictionaryValue)objModel;
  105. //}
  106. /// <summary>
  107. /// 获得数据列表
  108. /// </summary>
  109. public DataSet GetList(string strWhere, string filedOrder = "")
  110. {
  111. var dt = GetRedis();
  112. if (dt != null)
  113. {
  114. var ds = new DataSet();
  115. var drs = dt.Select(strWhere, filedOrder);
  116. if (drs.Length > 0)
  117. {
  118. ds.Tables.Add(drs.CopyToDataTable());
  119. }
  120. else
  121. {
  122. ds.Tables.Add(new DataTable());
  123. }
  124. return ds;
  125. }
  126. else
  127. {
  128. return dal.GetList(strWhere);
  129. }
  130. }
  131. /// <summary>
  132. /// 获得数据列表
  133. /// </summary>
  134. public DataSet GetListNoCache(string strWhere)
  135. {
  136. return dal.GetList(strWhere);
  137. }
  138. /// <summary>
  139. /// 获得前几行数据
  140. /// </summary>
  141. public DataSet GetList(int Top, string strWhere, string filedOrder)
  142. {
  143. return dal.GetList(Top, strWhere, filedOrder);
  144. }
  145. /// <summary>
  146. /// 获得数据列表
  147. /// </summary>
  148. public List<CallCenterApi.Model.T_Sys_DictionaryValue> GetModelList(string strWhere, string filedOrder = "")
  149. {
  150. var dt = GetRedis();
  151. if (dt != null)
  152. {
  153. var dtnew = new DataTable();
  154. var drs = dt.Select(strWhere, filedOrder);
  155. if (drs.Length > 0)
  156. {
  157. dtnew = drs.CopyToDataTable();
  158. }
  159. return DataTableToList(dtnew);
  160. }
  161. else
  162. {
  163. DataSet ds = dal.GetList(strWhere, filedOrder);
  164. return DataTableToList(ds.Tables[0]);
  165. }
  166. }
  167. /// <summary>
  168. /// 获得数据列表
  169. /// </summary>
  170. public List<CallCenterApi.Model.T_Sys_DictionaryValue> GetModelListNoCache(string strWhere, string filedOrder = "")
  171. {
  172. DataSet ds = dal.GetList(strWhere, filedOrder);
  173. return DataTableToList(ds.Tables[0]);
  174. }
  175. /// <summary>
  176. /// 获得数据列表
  177. /// </summary>
  178. public List<CallCenterApi.Model.T_Sys_DictionaryValue> DataTableToList(DataTable dt)
  179. {
  180. List<CallCenterApi.Model.T_Sys_DictionaryValue> modelList = new List<CallCenterApi.Model.T_Sys_DictionaryValue>();
  181. int rowsCount = dt.Rows.Count;
  182. if (rowsCount > 0)
  183. {
  184. CallCenterApi.Model.T_Sys_DictionaryValue model;
  185. for (int n = 0; n < rowsCount; n++)
  186. {
  187. model = new CallCenterApi.Model.T_Sys_DictionaryValue();
  188. if (dt.Rows[n]["F_ValueId"] != null && dt.Rows[n]["F_ValueId"].ToString() != "")
  189. {
  190. model.F_ValueId = int.Parse(dt.Rows[n]["F_ValueId"].ToString());
  191. }
  192. if (dt.Rows[n]["F_ItemId"] != null && dt.Rows[n]["F_ItemId"].ToString() != "")
  193. {
  194. model.F_ItemId = int.Parse(dt.Rows[n]["F_ItemId"].ToString());
  195. }
  196. if (dt.Rows[n]["F_Value"] != null && dt.Rows[n]["F_Value"].ToString() != "")
  197. {
  198. model.F_Value = dt.Rows[n]["F_Value"].ToString();
  199. }
  200. if (dt.Rows[n]["F_PrentId"] != null && dt.Rows[n]["F_PrentId"].ToString() != "")
  201. {
  202. model.F_PrentId = int.Parse(dt.Rows[n]["F_PrentId"].ToString());
  203. }
  204. if (dt.Rows[n]["F_Layer"] != null && dt.Rows[n]["F_Layer"].ToString() != "")
  205. {
  206. model.F_Layer = int.Parse(dt.Rows[n]["F_Layer"].ToString());
  207. }
  208. if (dt.Rows[n]["F_IsLeaf"] != null && dt.Rows[n]["F_IsLeaf"].ToString() != "")
  209. {
  210. if ((dt.Rows[n]["F_IsLeaf"].ToString() == "1") || (dt.Rows[n]["F_IsLeaf"].ToString().ToLower() == "true"))
  211. {
  212. model.F_IsLeaf = true;
  213. }
  214. else
  215. {
  216. model.F_IsLeaf = false;
  217. }
  218. }
  219. modelList.Add(model);
  220. }
  221. }
  222. return modelList;
  223. }
  224. /// <summary>
  225. /// 获得数据列表
  226. /// </summary>
  227. public DataSet GetAllList()
  228. {
  229. return GetList("");
  230. }
  231. /// <summary>
  232. /// 分页获取数据列表
  233. /// </summary>
  234. //public DataSet GetList(int PageSize,int PageIndex,string strWhere)
  235. //{
  236. //return dal.GetList(PageSize,PageIndex,strWhere);
  237. //}
  238. #endregion Method
  239. private DataTable GetRedis()
  240. {
  241. var strList = RedisHelper1.StringGet("T_Sys_DictionaryValue");
  242. if (strList != null)
  243. {
  244. return strList.ToString().ToObject<DataTable>();
  245. }
  246. else
  247. {
  248. return InRedis();
  249. }
  250. }
  251. private DataTable InRedis()
  252. {
  253. var dt = dal.GetList("").Tables[0];
  254. RedisHelper1.StringSet("T_Sys_DictionaryValue", dt.ToJson(), new TimeSpan(24, 0, 0));
  255. return dt;
  256. }
  257. private void OutRedis()
  258. {
  259. RedisHelper1.KeyDelete("T_Sys_DictionaryValue");
  260. RedisHelper1.KeyDelete("ztree_38");
  261. RedisHelper.KeyDelete("ztree_38new");
  262. RedisHelper1.KeyDelete("key_38");
  263. RedisHelper1.KeyDelete("ZTreeList_0");
  264. RedisHelper1.KeyDelete("ztreeDic_38new");
  265. RedisHelper1.KeyDelete("dickey_38");
  266. }
  267. }
  268. }