SysAdminRoleService.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*
  2. * 后台管理员角色
  3. */
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using MySystem.BsModels;
  8. using Library;
  9. using LitJson;
  10. namespace MySystem.Service.Default
  11. {
  12. public class SysAdminRoleService
  13. {
  14. string _conn = "";
  15. public SysAdminRoleService()
  16. {
  17. _conn = ConfigurationManager.AppSettings["SqlConnStr"].ToString();
  18. }
  19. /// <summary>
  20. /// 查询列表
  21. /// </summary>
  22. /// <param name="relationData">关联表</param>
  23. /// <param name="condition">查询条件(sql语句)</param>
  24. /// <param name="count">总数(输出)</param>
  25. /// <param name="page">页码</param>
  26. /// <param name="limit">每页条数</param>
  27. /// <returns></returns>
  28. public List<Dictionary<string, object>> List(List<RelationData> relationData, string condition, out int count, int page = 1, int limit = 30)
  29. {
  30. Dictionary<string, object> obj = new DbService(AppConfig.Base.dbTables, _conn).IndexData("SysAdminRole", relationData, "SysAdminRole.Id desc", page, limit, condition, "SysAdminRole.Name,,SysAdminRole.CreateDate,SysAdminRole.Status,SysAdminRole.Id");
  31. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  32. count = int.Parse(obj["count"].ToString());
  33. return diclist;
  34. }
  35. /// <summary>
  36. /// 查询一条记录
  37. /// </summary>
  38. /// <param name="Id">主键Id</param>
  39. /// <returns></returns>
  40. public SysAdminRole Query(int Id)
  41. {
  42. WebCMSEntities db = new WebCMSEntities();
  43. SysAdminRole editData = db.SysAdminRole.FirstOrDefault(m => m.Id == Id) ?? new SysAdminRole();
  44. db.Dispose();
  45. return editData;
  46. }
  47. /// <summary>
  48. /// 添加数据
  49. /// </summary>
  50. /// <param name="Fields">要设置的字段</param>
  51. /// <returns></returns>
  52. public int Add(Dictionary<string, object> Fields)
  53. {
  54. return new DbService(AppConfig.Base.dbTables, _conn).Add("SysAdminRole", Fields, 0);
  55. }
  56. /// <summary>
  57. /// 修改数据
  58. /// </summary>
  59. /// <param name="Fields">要设置的字段</param>
  60. /// <param name="Id">主键Id</param>
  61. public void Edit(Dictionary<string, object> Fields, int Id)
  62. {
  63. new DbService(AppConfig.Base.dbTables, _conn).Edit("SysAdminRole", Fields, Id);
  64. }
  65. /// <summary>
  66. /// 删除数据
  67. /// </summary>
  68. /// <param name="Id">主键Id</param>
  69. public void Delete(int Id)
  70. {
  71. new DbService(AppConfig.Base.dbTables, _conn).Delete("SysAdminRole", Id);
  72. }
  73. /// <summary>
  74. /// 排序
  75. /// </summary>
  76. /// <param name="Id">主键Id</param>
  77. /// <param name="Sort">排序序号</param>
  78. public void Sort(int Id, int Sort)
  79. {
  80. new DbService(AppConfig.Base.dbTables, _conn).Sort("SysAdminRole", Sort, Id);
  81. }
  82. /// <summary>
  83. /// 导入数据
  84. /// </summary>
  85. /// <param name="ExcelData">json数据</param>
  86. public void Import(string ExcelData)
  87. {
  88. WebCMSEntities db = new WebCMSEntities();
  89. JsonData list = JsonMapper.ToObject(ExcelData);
  90. for (int i = 1; i < list.Count;i++ )
  91. {
  92. JsonData dr = list[i];
  93. db.SysAdminRole.Add(new SysAdminRole()
  94. {
  95. CreateDate = DateTime.Now,
  96. UpdateDate = DateTime.Now,
  97. });
  98. db.SaveChanges();
  99. }
  100. db.Dispose();
  101. }
  102. /// <summary>
  103. /// 导出excel表格
  104. /// </summary>
  105. /// <param name="fields">查询条件(单个字段)</param>
  106. /// <param name="condition">查询条件(sql语句)</param>
  107. /// <returns></returns>
  108. public Dictionary<string, object> ExportExcel(List<RelationData> relationData, string condition)
  109. {
  110. Dictionary<string, object> obj = new DbService(AppConfig.Base.dbTables, _conn).IndexData("SysAdminRole", relationData, "SysAdminRole.Id desc", 1, 20000, condition, "SysAdminRole.Name,SysAdminRole.CreateDate,SysAdminRole.Status,SysAdminRole.Id");
  111. List<SysAdminRole> diclist = obj["data"] as List<SysAdminRole>;
  112. Dictionary<string, object> result = new Dictionary<string, object>();
  113. result.Add("Status", "1");
  114. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  115. result.Add("Obj", diclist);
  116. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  117. result.Add("Fields", ReturnFields);
  118. return result;
  119. }
  120. }
  121. }