using System; using System.Collections.Generic; using System.Linq; using System.Web; using MySystem.BsModels; namespace MySystem { public sealed class DictionaryClass { static BsModels.WebCMSEntities bsdb = new BsModels.WebCMSEntities(); #region Col字典 public Dictionary getColDic(string ColId = "") { List ColList = bsdb.Col.Where(m => m.ColId.StartsWith(ColId)).OrderBy(m => m.ColId).ToList(); Dictionary ColDic = new Dictionary(); foreach (BsModels.Col subCol in ColList) { ColDic.Add(subCol.ColId.ToString(), subCol.ColName.ToString()); } return ColDic; } public Dictionary getColDicForInt(string ColId = "") { List ColList = bsdb.Col.Where(m => m.ColId.StartsWith(ColId)).OrderBy(m => m.ColId).ToList(); Dictionary ColDic = new Dictionary(); foreach (BsModels.Col subCol in ColList) { ColDic.Add(subCol.Id, subCol.ColName.ToString()); } return ColDic; } #endregion #region 角色字典 public Dictionary getRoleDic() { List List = bsdb.SysAdminRole.ToList(); Dictionary ColDic = new Dictionary(); foreach (BsModels.SysAdminRole sub in List) { ColDic.Add(sub.Id.ToString(), sub.Name.ToString()); } return ColDic; } #endregion #region 后台管理员角色字典 public Dictionary getSysAdminRoleDic() { List SysAdminRoleList = bsdb.SysAdminRole.ToList(); Dictionary SysAdminRoleDic = new Dictionary(); foreach (BsModels.SysAdminRole subSysAdminRole in SysAdminRoleList) { SysAdminRoleDic.Add(subSysAdminRole.Id.ToString(), subSysAdminRole.Name.ToString()); } return SysAdminRoleDic; } public Dictionary getSysAdminRoleNewDic() { List SysAdminRoleNewList = bsdb.SysAdminRoleNew.ToList(); Dictionary SysAdminRoleNewDic = new Dictionary(); foreach (BsModels.SysAdminRoleNew subSysAdminRoleNew in SysAdminRoleNewList) { SysAdminRoleNewDic.Add(subSysAdminRoleNew.Id.ToString(), subSysAdminRoleNew.Name.ToString()); } return SysAdminRoleNewDic; } #endregion #region 后台管理员字典 public Dictionary getSysAdminDic() { List SysAdminList = bsdb.SysAdmin.ToList(); Dictionary SysAdminDic = new Dictionary(); foreach (SysAdmin subSysAdmin in SysAdminList) { SysAdminDic.Add(subSysAdmin.Id.ToString(), subSysAdmin.AdminName.ToString()); } return SysAdminDic; } #endregion #region 根据字典key获取字典值 public string getDictionaryNameByKey(Dictionary data, string key) { if (data.ContainsKey(key)) { return data[key]; } return ""; } public string getDictionaryNameById(Dictionary data, int key) { if (data.ContainsKey(key)) { return data[key]; } return ""; } public string getDictionaryNamesByKeys(Dictionary data, string keys) { string result = ""; string[] keylist = keys.Split(','); foreach (string subkey in keylist) { if (data.ContainsKey(subkey)) { result += data[subkey] + ","; } } return result.TrimEnd(','); } #endregion } }