UserLevelSetService.cs 4.7 KB

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