HaoDaAreaCodeService.cs 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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 HaoDaAreaCodeService
  14. {
  15. static string _conn = ConfigurationManager.AppSettings["SqlConnStr"].ToString();
  16. /// <summary>
  17. /// 查询列表
  18. /// </summary>
  19. /// <param name="relationData">关联表</param>
  20. /// <param name="condition">查询条件(sql语句)</param>
  21. /// <param name="count">总数(输出)</param>
  22. /// <param name="page">页码</param>
  23. /// <param name="limit">每页条数</param>
  24. /// <returns></returns>
  25. public static List<Dictionary<string, object>> List(List<RelationData> relationData, string condition, out int count, int page = 1, int limit = 30, string orderBy = "CityName desc")
  26. {
  27. List<string> fields = new List<string>(); //要显示的列
  28. fields.Add("CityName");
  29. fields.Add("CityCode");
  30. Dictionary<string, object> obj = new DbService(AppConfig.Base.mainTables, _conn).IndexData("HaoDaAreaCode", relationData, orderBy, page, limit, condition, fields);
  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. public static List<Dictionary<string, object>> List(List<RelationData> relationData, string condition, int page = 1, int limit = 30, string orderBy = "CityName desc")
  36. {
  37. List<string> fields = new List<string>(); //要显示的列
  38. fields.Add("CityName");
  39. fields.Add("CityCode");
  40. Dictionary<string, object> obj = new DbService(AppConfig.Base.mainTables, _conn).IndexData("HaoDaAreaCode", relationData, orderBy, page, limit, condition, fields);
  41. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  42. return diclist;
  43. }
  44. public static HaoDaAreaCode Query(string condition, string fields = "*")
  45. {
  46. var HaoDaAreaCode = new DbService(AppConfig.Base.mainTables, _conn).Query(fields, "HaoDaAreaCode", condition);
  47. if (HaoDaAreaCode.Count > 0)
  48. {
  49. return Newtonsoft.Json.JsonConvert.DeserializeObject<HaoDaAreaCode>(Newtonsoft.Json.JsonConvert.SerializeObject(HaoDaAreaCode));
  50. }
  51. return new HaoDaAreaCode();
  52. }
  53. public static decimal Sum(string condition, string field)
  54. {
  55. var dt = new DbService(AppConfig.Base.mainTables, _conn).Query("Sum(" + field + ") " + field, "HaoDaAreaCode", condition);
  56. decimal amount = 0;
  57. if (dt.Count > 0)
  58. {
  59. amount = decimal.Parse(dt[field].ToString());
  60. }
  61. return amount;
  62. }
  63. /// <summary>
  64. /// 查询记录数
  65. /// </summary>
  66. /// <param name="Id">主键Id</param>
  67. /// <returns></returns>
  68. public static int Count(string condition = "", string field = "Id")
  69. {
  70. var dt = new DbService(AppConfig.Base.mainTables, _conn).Query("Count(" + field + ") " + field, "HaoDaAreaCode", condition);
  71. int result = 0;
  72. if (dt.Count > 0)
  73. {
  74. result = int.Parse(dt[field].ToString());
  75. }
  76. return result;
  77. }
  78. /// <summary>
  79. /// 查询是否存在
  80. /// </summary>
  81. /// <param name="CityName">开户行名称</param>
  82. /// <returns></returns>
  83. public static bool Exist(string CityName)
  84. {
  85. WebCMSEntities db = new WebCMSEntities();
  86. bool check = db.HaoDaAreaCode.Any(m => m.CityName == CityName);
  87. db.Dispose();
  88. return check;
  89. }
  90. /// <summary>
  91. /// 添加数据
  92. /// </summary>
  93. /// <param name="Fields">要设置的字段</param>
  94. /// <returns></returns>
  95. public static AppResultJson Add(Dictionary<string, object> fields, bool check = true)
  96. {
  97. if (check)
  98. {
  99. }
  100. int Id = new DbService(AppConfig.Base.mainTables, _conn).Add("HaoDaAreaCode", fields, 0);
  101. return new AppResultJson() { Status = "1", Data = Id };
  102. }
  103. /// <summary>
  104. /// 修改数据
  105. /// </summary>
  106. /// <param name="Fields">要设置的字段</param>
  107. /// <param name="Id">主键Id</param>
  108. public static AppResultJson Edit(Dictionary<string, object> fields, int Id, bool check = true)
  109. {
  110. if (check)
  111. {
  112. if (string.IsNullOrEmpty(fields["NickName"].ToString()))
  113. {
  114. return new AppResultJson() { Status = "-1", Info = "请填写昵称" };
  115. }
  116. }
  117. new DbService(AppConfig.Base.mainTables, _conn).Edit("HaoDaAreaCode", fields, Id);
  118. return new AppResultJson() { Status = "1", Data = Id };
  119. }
  120. /// <summary>
  121. /// 逻辑删除
  122. /// </summary>
  123. /// <param name="Id">主键Id</param>
  124. public static void Remove(int Id)
  125. {
  126. Dictionary<string, object> fields = new Dictionary<string, object>();
  127. fields.Add("Status", -1);
  128. new DbService(AppConfig.Base.mainTables, _conn).Edit("HaoDaAreaCode", fields, Id);
  129. }
  130. /// <summary>
  131. /// 删除数据
  132. /// </summary>
  133. /// <param name="Id">主键Id</param>
  134. public static void Delete(int Id)
  135. {
  136. new DbService(AppConfig.Base.mainTables, _conn).Delete("HaoDaAreaCode", Id);
  137. }
  138. /// <summary>
  139. /// 排序
  140. /// </summary>
  141. /// <param name="Id">主键Id</param>
  142. /// <param name="Sort">排序序号</param>
  143. public static void Sort(int Id, int Sort)
  144. {
  145. new DbService(AppConfig.Base.mainTables, _conn).Sort("HaoDaAreaCode", Sort, Id);
  146. }
  147. /// <summary>
  148. /// 导入数据
  149. /// </summary>
  150. /// <param name="ExcelData">json数据</param>
  151. public static void Import(string ExcelData)
  152. {
  153. WebCMSEntities db = new WebCMSEntities();
  154. JsonData list = JsonMapper.ToObject(ExcelData);
  155. for (int i = 1; i < list.Count; i++)
  156. {
  157. JsonData dr = list[i];
  158. db.HaoDaAreaCode.Add(new HaoDaAreaCode()
  159. {
  160. });
  161. db.SaveChanges();
  162. }
  163. db.Dispose();
  164. }
  165. /// <summary>
  166. /// 导出excel表格
  167. /// </summary>
  168. /// <param name="fields">查询条件(单个字段)</param>
  169. /// <param name="condition">查询条件(sql语句)</param>
  170. /// <returns></returns>
  171. // public static void ExportExcel(List<RelationData> relationData, string condition)
  172. // {
  173. // }
  174. }
  175. }