ProductFareAreasService.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /*
  2. * 运费按区域
  3. */
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Data;
  8. using MySystem.Models.Main;
  9. using Library;
  10. using LitJson;
  11. namespace MySystem.Service.Main
  12. {
  13. public class ProductFareAreasService
  14. {
  15. string _conn = "";
  16. public ProductFareAreasService()
  17. {
  18. _conn = ConfigurationManager.AppSettings["SqlConnStr"].ToString();
  19. }
  20. /// <summary>
  21. /// 查询列表
  22. /// </summary>
  23. /// <param name="relationData">关联表</param>
  24. /// <param name="condition">查询条件(sql语句)</param>
  25. /// <param name="count">总数(输出)</param>
  26. /// <param name="page">页码</param>
  27. /// <param name="limit">每页条数</param>
  28. /// <returns></returns>
  29. public List<Dictionary<string, object>> List(List<RelationData> relationData, string condition, out int count, int page = 1, int limit = 30, string orderBy = "Sort desc,Id desc")
  30. {
  31. List<string> fields = new List<string>(); //要显示的列
  32. fields.Add("Id");
  33. fields.Add("CreateDate"); //添加时间
  34. fields.Add("Status"); //状态
  35. Dictionary<string, object> obj = new DbService(AppConfig.Base.mainTables, _conn).IndexData("ProductFareAreas", relationData, orderBy, page, limit, condition, fields);
  36. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  37. count = int.Parse(obj["count"].ToString());
  38. return diclist;
  39. }
  40. public List<Dictionary<string, object>> List(List<RelationData> relationData, string condition, int page = 1, int limit = 30, string orderBy = "Sort desc,Id desc")
  41. {
  42. List<string> fields = new List<string>(); //要显示的列
  43. fields.Add("Id");
  44. fields.Add("CreateDate"); //添加时间
  45. fields.Add("Status"); //状态
  46. Dictionary<string, object> obj = new DbService(AppConfig.Base.mainTables, _conn).IndexData("ProductFareAreas", relationData, orderBy, page, limit, condition, fields);
  47. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  48. return diclist;
  49. }
  50. /// <summary>
  51. /// 查询一条记录
  52. /// </summary>
  53. /// <param name="Id">主键Id</param>
  54. /// <returns></returns>
  55. public ProductFareAreas Query(int Id)
  56. {
  57. WebCMSEntities db = new WebCMSEntities();
  58. ProductFareAreas editData = db.ProductFareAreas.FirstOrDefault(m => m.Id == Id) ?? new ProductFareAreas();
  59. db.Dispose();
  60. return editData;
  61. }
  62. /// <summary>
  63. /// 查询记录数
  64. /// </summary>
  65. /// <param name="Id">主键Id</param>
  66. /// <returns></returns>
  67. public int Count(string condition = "")
  68. {
  69. int result = 0;
  70. DataTable dt = CustomerSqlConn.dtable("select count(Id) from ProductFareAreas where 1=1" + condition, _conn);
  71. if(dt.Rows.Count > 0)
  72. {
  73. result = int.Parse(function.CheckInt(dt.Rows[0][0].ToString()));
  74. }
  75. return result;
  76. }
  77. /// <summary>
  78. /// 查询是否存在
  79. /// </summary>
  80. /// <param name="Id">主键Id</param>
  81. /// <returns></returns>
  82. public bool Exist(int Id)
  83. {
  84. WebCMSEntities db = new WebCMSEntities();
  85. bool check = db.ProductFareAreas.Any(m => m.Id == Id);
  86. db.Dispose();
  87. return check;
  88. }
  89. /// <summary>
  90. /// 添加数据
  91. /// </summary>
  92. /// <param name="Fields">要设置的字段</param>
  93. /// <returns></returns>
  94. public AppResultJson Add(Dictionary<string, object> fields, bool check = true)
  95. {
  96. if(check)
  97. {
  98. }
  99. int Id = new DbService(AppConfig.Base.mainTables, _conn).Add("ProductFareAreas", fields, 0);
  100. return new AppResultJson(){ Status = "1", Data = Id };
  101. }
  102. /// <summary>
  103. /// 修改数据
  104. /// </summary>
  105. /// <param name="Fields">要设置的字段</param>
  106. /// <param name="Id">主键Id</param>
  107. public AppResultJson Edit(Dictionary<string, object> fields, int Id, bool check = true)
  108. {
  109. if(check)
  110. {
  111. }
  112. new DbService(AppConfig.Base.mainTables, _conn).Edit("ProductFareAreas", fields, Id);
  113. return new AppResultJson(){ Status = "1", Data = Id };
  114. }
  115. /// <summary>
  116. /// 逻辑删除
  117. /// </summary>
  118. /// <param name="Id">主键Id</param>
  119. public void Remove(int Id)
  120. {
  121. Dictionary<string, object> fields = new Dictionary<string, object>();
  122. fields.Add("Status", -1);
  123. new DbService(AppConfig.Base.mainTables, _conn).Edit("ProductFareAreas", fields, Id);
  124. }
  125. /// <summary>
  126. /// 删除数据
  127. /// </summary>
  128. /// <param name="Id">主键Id</param>
  129. public void Delete(int Id)
  130. {
  131. new DbService(AppConfig.Base.mainTables, _conn).Delete("ProductFareAreas", Id);
  132. }
  133. /// <summary>
  134. /// 排序
  135. /// </summary>
  136. /// <param name="Id">主键Id</param>
  137. /// <param name="Sort">排序序号</param>
  138. public void Sort(int Id, int Sort)
  139. {
  140. new DbService(AppConfig.Base.mainTables, _conn).Sort("ProductFareAreas", Sort, Id);
  141. }
  142. /// <summary>
  143. /// 导入数据
  144. /// </summary>
  145. /// <param name="ExcelData">json数据</param>
  146. public void Import(string ExcelData)
  147. {
  148. WebCMSEntities db = new WebCMSEntities();
  149. JsonData list = JsonMapper.ToObject(ExcelData);
  150. for (int i = 1; i < list.Count;i++ )
  151. {
  152. JsonData dr = list[i];
  153. db.ProductFareAreas.Add(new ProductFareAreas()
  154. {
  155. CreateDate = DateTime.Now,
  156. UpdateDate = DateTime.Now,
  157. });
  158. db.SaveChanges();
  159. }
  160. db.Dispose();
  161. }
  162. /// <summary>
  163. /// 导出excel表格
  164. /// </summary>
  165. /// <param name="fields">查询条件(单个字段)</param>
  166. /// <param name="condition">查询条件(sql语句)</param>
  167. /// <returns></returns>
  168. // public void ExportExcel(List<RelationData> relationData, string condition)
  169. // {
  170. // }
  171. }
  172. }