MerchantLoginInfoService.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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 MerchantLoginInfoService
  10. {
  11. string _conn = "";
  12. public MerchantLoginInfoService()
  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("MerchantLoginInfo", 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 MerchantLoginInfo Query(int Id)
  36. {
  37. WebCMSEntities db = new WebCMSEntities();
  38. MerchantLoginInfo editData = db.MerchantLoginInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantLoginInfo();
  39. db.Dispose();
  40. return editData;
  41. }
  42. public MerchantLoginInfo Query(string LoginMobile, string LoginPwd)
  43. {
  44. WebCMSEntities db = new WebCMSEntities();
  45. MerchantLoginInfo editData = db.MerchantLoginInfo.FirstOrDefault(m => m.LoginMobile == LoginMobile && m.LoginPwd == LoginPwd) ?? new MerchantLoginInfo();
  46. db.Dispose();
  47. return editData;
  48. }
  49. /// <summary>
  50. /// 添加数据
  51. /// </summary>
  52. /// <param name="Fields">要设置的字段</param>
  53. /// <returns></returns>
  54. public int Add(Dictionary<string, object> Fields)
  55. {
  56. return new DbService(AppConfig.Base.mainTables, _conn).Add("MerchantLoginInfo", Fields, 0);
  57. }
  58. /// <summary>
  59. /// 修改数据
  60. /// </summary>
  61. /// <param name="Fields">要设置的字段</param>
  62. /// <param name="Id">主键Id</param>
  63. public void Edit(Dictionary<string, object> Fields, int Id)
  64. {
  65. new DbService(AppConfig.Base.mainTables, _conn).Edit("MerchantLoginInfo", Fields, Id);
  66. }
  67. /// <summary>
  68. /// 删除数据
  69. /// </summary>
  70. /// <param name="Id">主键Id</param>
  71. public void Delete(int Id)
  72. {
  73. new DbService(AppConfig.Base.mainTables, _conn).Delete("MerchantLoginInfo", Id);
  74. }
  75. /// <summary>
  76. /// 排序
  77. /// </summary>
  78. /// <param name="Id">主键Id</param>
  79. /// <param name="Sort">排序序号</param>
  80. public void Sort(int Id, int Sort)
  81. {
  82. new DbService(AppConfig.Base.mainTables, _conn).Sort("MerchantLoginInfo", Sort, Id);
  83. }
  84. /// <summary>
  85. /// 导入数据
  86. /// </summary>
  87. /// <param name="ExcelData">json数据</param>
  88. public 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.MerchantLoginInfo.Add(new MerchantLoginInfo()
  96. {
  97. CreateDate = DateTime.Now,
  98. UpdateDate = DateTime.Now,
  99. });
  100. db.SaveChanges();
  101. }
  102. db.Dispose();
  103. }
  104. /// <summary>
  105. /// 导出excel表格
  106. /// </summary>
  107. /// <param name="fields">查询条件(单个字段)</param>
  108. /// <param name="condition">查询条件(sql语句)</param>
  109. /// <returns></returns>
  110. public Dictionary<string, object> ExportExcel(List<FieldItem> fields, string condition, string orderby = "Id desc")
  111. {
  112. Dictionary<string, object> obj = new DbService(AppConfig.Base.mainTables, _conn).IndexData("MerchantLoginInfo", fields, orderby, "0", 1, 20000, condition, "Id", false);
  113. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  114. foreach (Dictionary<string, object> dic in diclist)
  115. {
  116. }
  117. Dictionary<string, object> result = new Dictionary<string, object>();
  118. result.Add("Status", "1");
  119. result.Add("Info", "Excel报表-" + DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss") + ".xlsx");
  120. result.Add("Obj", diclist);
  121. Dictionary<string, object> ReturnFields = new Dictionary<string, object>();
  122. result.Add("Fields", ReturnFields);
  123. return result;
  124. }
  125. }
  126. }