CodeManage.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Data.Entity;
  6. using Central.Control.Domain;
  7. using Ant.Service.Common;
  8. namespace MES.Production.Service.ServiceImp
  9. {
  10. /// <summary>
  11. /// Service层代码配置
  12. /// add 作者: 季健国 QQ:181589805 by 2016-05-22
  13. /// </summary>
  14. public class CodeManage : RepositoryBase<SYS_CODE>,IService.ICodeManage
  15. {
  16. /// <summary>
  17. /// 根据编码类型获取编码集合
  18. /// </summary>
  19. public List<SYS_CODE> GetCode(string codetype, params string[] codevalue)
  20. {
  21. var predicate = PredicateBuilder.True<SYS_CODE>();
  22. predicate = predicate.And(p => p.CODETYPE == codetype);
  23. if (codevalue != null && codevalue.Length > 0)
  24. {
  25. var str = codevalue.ToList();
  26. predicate = predicate.And(p => str.Contains(p.CODEVALUE));
  27. }
  28. return this.LoadAll(predicate).OrderBy(p => p.SHOWORDER).ToList();
  29. }
  30. /// <summary>
  31. /// 通过系统字典获取编码值
  32. /// </summary>
  33. public IQueryable<SYS_CODE> GetDicType()
  34. {
  35. Dictionary<string, string> code = Ant.Service.Common.Enums.ClsDic.DicCodeType;
  36. string dic = code.Aggregate(string.Empty, (current, item) => current + (item.Value + ",")).TrimEnd(',');
  37. return this.LoadAll(p => dic.Contains(p.CODETYPE)).OrderBy(p => p.SHOWORDER);
  38. }
  39. /// <summary>
  40. /// 根据字典ID与类型获取一条数据
  41. /// </summary>
  42. public string GetCodeByID(int id,string codetype)
  43. {
  44. return (this.Get(p => p.ID == id) ?? new SYS_CODE()).NAMETEXT;
  45. }
  46. /// <summary>
  47. /// 根据字典编码值与类型获取一条数据
  48. /// </summary>
  49. public string GetCodeNameByCodeValue(string codeType, string codevalue)
  50. {
  51. if (string.IsNullOrEmpty(codevalue))
  52. return "";
  53. var entity= this.Get(p => p.CODETYPE == codeType && p.CODEVALUE == codevalue);
  54. if (entity == null) return "";
  55. return entity.NAMETEXT;
  56. }
  57. }
  58. }