UserSwapWhiteService.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * 循环返风控白名单
  3. */
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Data;
  8. using MySystem.MainModels;
  9. using Library;
  10. using LitJson;
  11. namespace MySystem.Service
  12. {
  13. public class UserSwapWhiteService
  14. {
  15. static string _conn = ConfigurationManager.AppSettings["SqlConnStr"].ToString();
  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 static 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("UserSwapWhite", 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 static UserSwapWhite Query(int Id)
  36. {
  37. WebCMSEntities db = new WebCMSEntities();
  38. UserSwapWhite editData = db.UserSwapWhite.FirstOrDefault(m => m.Id == Id) ?? new UserSwapWhite();
  39. db.Dispose();
  40. return editData;
  41. }
  42. public static UserSwapWhite QueryByUserId(int UserId)
  43. {
  44. WebCMSEntities db = new WebCMSEntities();
  45. UserSwapWhite editData = db.UserSwapWhite.FirstOrDefault(m => m.UserId == UserId) ?? new UserSwapWhite();
  46. db.Dispose();
  47. return editData;
  48. }
  49. /// <summary>
  50. /// 添加数据
  51. /// </summary>
  52. /// <param name="Fields">要设置的字段</param>
  53. /// <returns></returns>
  54. public static int Add(Dictionary<string, object> Fields)
  55. {
  56. return new DbService(AppConfig.Base.mainTables, _conn).Add("UserSwapWhite", Fields, 0);
  57. }
  58. /// <summary>
  59. /// 修改数据
  60. /// </summary>
  61. /// <param name="Fields">要设置的字段</param>
  62. /// <param name="Id">主键Id</param>
  63. public static void Edit(Dictionary<string, object> Fields, int Id)
  64. {
  65. new DbService(AppConfig.Base.mainTables, _conn).Edit("UserSwapWhite", Fields, Id);
  66. }
  67. /// <summary>
  68. /// 删除数据
  69. /// </summary>
  70. /// <param name="Id">主键Id</param>
  71. public static void Delete(int Id)
  72. {
  73. new DbService(AppConfig.Base.mainTables, _conn).Delete("UserSwapWhite", Id);
  74. }
  75. /// <summary>
  76. /// 排序
  77. /// </summary>
  78. /// <param name="Id">主键Id</param>
  79. /// <param name="Sort">排序序号</param>
  80. public static void Sort(int Id, int Sort)
  81. {
  82. new DbService(AppConfig.Base.mainTables, _conn).Sort("UserSwapWhite", Sort, Id);
  83. }
  84. /// <summary>
  85. /// 导入数据
  86. /// </summary>
  87. /// <param name="ExcelData">json数据</param>
  88. public static void Import(string ExcelData)
  89. {
  90. WebCMSEntities db = new WebCMSEntities();
  91. JsonData list = JsonMapper.ToObject(ExcelData);
  92. for (int i = 1; i < list.Count;i++ )
  93. {
  94. JsonData dr = list[i];
  95. db.UserSwapWhite.Add(new UserSwapWhite()
  96. {
  97. CreateDate = DateTime.Now,
  98. UpdateDate = DateTime.Now,
  99. });
  100. db.SaveChanges();
  101. }
  102. db.Dispose();
  103. }
  104. }
  105. }