DictionaryClass.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using MySystem.BsModels;
  6. namespace MySystem
  7. {
  8. public sealed class DictionaryClass
  9. {
  10. static BsModels.WebCMSEntities bsdb = new BsModels.WebCMSEntities();
  11. #region Col字典
  12. public Dictionary<string, string> getColDic(string ColId = "")
  13. {
  14. List<BsModels.Col> ColList = bsdb.Col.Where(m => m.ColId.StartsWith(ColId)).OrderBy(m => m.ColId).ToList();
  15. Dictionary<string, string> ColDic = new Dictionary<string, string>();
  16. foreach (BsModels.Col subCol in ColList)
  17. {
  18. ColDic.Add(subCol.ColId.ToString(), subCol.ColName.ToString());
  19. }
  20. return ColDic;
  21. }
  22. public Dictionary<int, string> getColDicForInt(string ColId = "")
  23. {
  24. List<BsModels.Col> ColList = bsdb.Col.Where(m => m.ColId.StartsWith(ColId)).OrderBy(m => m.ColId).ToList();
  25. Dictionary<int, string> ColDic = new Dictionary<int, string>();
  26. foreach (BsModels.Col subCol in ColList)
  27. {
  28. ColDic.Add(subCol.Id, subCol.ColName.ToString());
  29. }
  30. return ColDic;
  31. }
  32. #endregion
  33. #region 角色字典
  34. public Dictionary<string, string> getRoleDic()
  35. {
  36. List<BsModels.SysAdminRole> List = bsdb.SysAdminRole.ToList();
  37. Dictionary<string, string> ColDic = new Dictionary<string, string>();
  38. foreach (BsModels.SysAdminRole sub in List)
  39. {
  40. ColDic.Add(sub.Id.ToString(), sub.Name.ToString());
  41. }
  42. return ColDic;
  43. }
  44. #endregion
  45. #region 后台管理员角色字典
  46. public Dictionary<string, string> getSysAdminRoleDic()
  47. {
  48. List<BsModels.SysAdminRole> SysAdminRoleList = bsdb.SysAdminRole.ToList();
  49. Dictionary<string, string> SysAdminRoleDic = new Dictionary<string, string>();
  50. foreach (BsModels.SysAdminRole subSysAdminRole in SysAdminRoleList)
  51. {
  52. SysAdminRoleDic.Add(subSysAdminRole.Id.ToString(), subSysAdminRole.Name.ToString());
  53. }
  54. return SysAdminRoleDic;
  55. }
  56. public Dictionary<string, string> getSysAdminRoleNewDic()
  57. {
  58. List<BsModels.SysAdminRoleNew> SysAdminRoleNewList = bsdb.SysAdminRoleNew.ToList();
  59. Dictionary<string, string> SysAdminRoleNewDic = new Dictionary<string, string>();
  60. foreach (BsModels.SysAdminRoleNew subSysAdminRoleNew in SysAdminRoleNewList)
  61. {
  62. SysAdminRoleNewDic.Add(subSysAdminRoleNew.Id.ToString(), subSysAdminRoleNew.Name.ToString());
  63. }
  64. return SysAdminRoleNewDic;
  65. }
  66. #endregion
  67. #region 后台管理员字典
  68. public Dictionary<string, string> getSysAdminDic()
  69. {
  70. List<SysAdmin> SysAdminList = bsdb.SysAdmin.ToList();
  71. Dictionary<string, string> SysAdminDic = new Dictionary<string, string>();
  72. foreach (SysAdmin subSysAdmin in SysAdminList)
  73. {
  74. SysAdminDic.Add(subSysAdmin.Id.ToString(), subSysAdmin.AdminName.ToString());
  75. }
  76. return SysAdminDic;
  77. }
  78. #endregion
  79. #region 根据字典key获取字典值
  80. public string getDictionaryNameByKey(Dictionary<string, string> data, string key)
  81. {
  82. if (data.ContainsKey(key))
  83. {
  84. return data[key];
  85. }
  86. return "";
  87. }
  88. public string getDictionaryNameById(Dictionary<int, string> data, int key)
  89. {
  90. if (data.ContainsKey(key))
  91. {
  92. return data[key];
  93. }
  94. return "";
  95. }
  96. public string getDictionaryNamesByKeys(Dictionary<string, string> data, string keys)
  97. {
  98. string result = "";
  99. string[] keylist = keys.Split(',');
  100. foreach (string subkey in keylist)
  101. {
  102. if (data.ContainsKey(subkey))
  103. {
  104. result += data[subkey] + ",";
  105. }
  106. }
  107. return result.TrimEnd(',');
  108. }
  109. #endregion
  110. }
  111. }