CzBll.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. using CP.Cache;
  2. using CP.Model;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Web.Mvc;
  9. namespace CP.Business
  10. {
  11. public class CzBll : DataConnect
  12. {
  13. /// <summary>
  14. /// 缓存
  15. /// </summary>
  16. static WMCache cache = WMCache.GetCacheService();
  17. public static List<Cz> GetList()
  18. {
  19. string key = string.Format(CacheKeys.SYSTEM_CZCLASS);
  20. List<Cz> list = cache.GetObject<List<Cz>>(key) as List<Cz>;
  21. if (list == null)
  22. {
  23. var dc = new DataConnect();
  24. list = dc.db.Fetch<Cz>("where state=1 order by seq asc");
  25. //list = dc.db.Fetch<Cz>("where state>-1 order by seq asc");
  26. cache.AddObject(key, list, (int)CacheTime.System);
  27. }
  28. return list;
  29. }
  30. public static List<Cz> GetAllList()
  31. {
  32. string key = string.Format(CacheKeys.CzAll);
  33. List<Cz> list = cache.GetObject<List<Cz>>(key) as List<Cz>;
  34. if (list == null)
  35. {
  36. var dc = new DataConnect();
  37. list = dc.db.Fetch<Cz>("where 1=1 order by seq asc");
  38. //list = dc.db.Fetch<Cz>("where state>-1 order by seq asc");
  39. cache.AddObject(key, list, (int)CacheTime.System);
  40. }
  41. return list;
  42. }
  43. public static Cz GetCz(int cid)
  44. {
  45. var list = GetList();
  46. return list.FirstOrDefault(m => m.cid == cid) ?? new Cz();
  47. }
  48. public static Cz GetCz(string ename)
  49. {
  50. var list = GetList();
  51. return list.FirstOrDefault(m => m.ename == ename) ?? new Cz();
  52. }
  53. /// <summary>
  54. /// 获取全部彩种list
  55. /// </summary>
  56. /// <param name="tip"></param>
  57. /// <returns></returns>
  58. public static SelectList DropDownList(string tip = "")
  59. {
  60. var list = GetList();
  61. List<SelectListItem> datas = new List<SelectListItem>();
  62. if (!string.IsNullOrWhiteSpace(tip))
  63. {
  64. datas.Add(new SelectListItem() { Text = tip, Value = "0" });
  65. }
  66. if (list != null && list.Count > 0)
  67. {
  68. foreach (var cz in list)
  69. {
  70. datas.Add(new SelectListItem() { Text = cz.name, Value = cz.cid.ToString() });
  71. }
  72. }
  73. return new SelectList(datas, "Value", "Text");
  74. }
  75. public static List<Cz> GetCzTypeList(int type)
  76. {
  77. var list = GetList();
  78. return list.Where(m => m.type == type).ToList() ?? new List<Cz>();
  79. }
  80. }
  81. }