UserLevelSetService.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  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 UserLevelSetService
  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 = "Sort desc,Id desc")
  26. {
  27. List<string> fields = new List<string>(); //要显示的列
  28. fields.Add("Id");
  29. fields.Add("CreateDate"); //添加时间
  30. fields.Add("Status"); //状态
  31. fields.Add("Name"); //等级名称
  32. fields.Add("UpLevelDays"); //升级天数
  33. fields.Add("UpLevelIntegral"); //升级需要积分值
  34. fields.Add("UpLevelGrowth"); //升级需要成长值
  35. Dictionary<string, object> obj = new DbService(AppConfig.Base.mainTables, _conn).IndexData("UserLevelSet", 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 static 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. fields.Add("Name"); //等级名称
  47. fields.Add("UpLevelDays"); //升级天数
  48. fields.Add("UpLevelIntegral"); //升级需要积分值
  49. fields.Add("UpLevelGrowth"); //升级需要成长值
  50. Dictionary<string, object> obj = new DbService(AppConfig.Base.mainTables, _conn).IndexData("UserLevelSet", relationData, orderBy, page, limit, condition, fields);
  51. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  52. return diclist;
  53. }
  54. /// <summary>
  55. /// 查询一条记录
  56. /// </summary>
  57. /// <param name="Id">主键Id</param>
  58. /// <returns></returns>
  59. public static UserLevelSet Query(int Id)
  60. {
  61. WebCMSEntities db = new WebCMSEntities();
  62. UserLevelSet editData = db.UserLevelSet.FirstOrDefault(m => m.Id == Id) ?? new UserLevelSet();
  63. db.Dispose();
  64. return editData;
  65. }
  66. public static UserLevelSet Query(string condition, string fields = "*")
  67. {
  68. DataTable dt = new DbService(AppConfig.Base.mainTables, _conn).QueryDetail(fields, "UserLevelSet", condition);
  69. if (dt.Rows.Count > 0)
  70. {
  71. Dictionary<string, object> row = new Dictionary<string, object>();
  72. foreach (DataColumn dc in dt.Columns)
  73. {
  74. row.Add(dc.ColumnName, dt.Rows[0][dc.ColumnName].ToString());
  75. }
  76. return Newtonsoft.Json.JsonConvert.DeserializeObject<UserLevelSet>(Newtonsoft.Json.JsonConvert.SerializeObject(row));
  77. }
  78. return new UserLevelSet();
  79. }
  80. public static decimal Sum(string condition, string field)
  81. {
  82. DataTable dt = new DbService(AppConfig.Base.mainTables, _conn).QueryDetail("Sum(" + field + ")", "UserLevelSet", condition);
  83. decimal amount = 0;
  84. if (dt.Rows.Count > 0)
  85. {
  86. amount = decimal.Parse(dt.Rows[0][0].ToString());
  87. }
  88. return amount;
  89. }
  90. /// <summary>
  91. /// 查询记录数
  92. /// </summary>
  93. /// <param name="Id">主键Id</param>
  94. /// <returns></returns>
  95. public static int Count(string condition = "", string field = "Id")
  96. {
  97. int result = 0;
  98. DataTable dt = new DbService(AppConfig.Base.mainTables, _conn).QueryDetail("count(" + field + ")", "UserLevelSet", condition);
  99. if (dt.Rows.Count > 0)
  100. {
  101. result = int.Parse(function.CheckInt(dt.Rows[0][0].ToString()));
  102. }
  103. return result;
  104. }
  105. /// <summary>
  106. /// 查询是否存在
  107. /// </summary>
  108. /// <param name="Id">主键Id</param>
  109. /// <returns></returns>
  110. public static bool Exist(int Id)
  111. {
  112. WebCMSEntities db = new WebCMSEntities();
  113. bool check = db.UserLevelSet.Any(m => m.Id == Id);
  114. db.Dispose();
  115. return check;
  116. }
  117. /// <summary>
  118. /// 添加数据
  119. /// </summary>
  120. /// <param name="Fields">要设置的字段</param>
  121. /// <returns></returns>
  122. public static AppResultJson Add(Dictionary<string, object> fields, bool check = true)
  123. {
  124. if (check)
  125. {
  126. if (string.IsNullOrEmpty(fields["UpLevelDays"].ToString()))
  127. {
  128. return new AppResultJson() { Status = "-1", Info = "请填写升级天数" };
  129. }
  130. if (!function.IsInt(fields["UpLevelDays"].ToString()))
  131. {
  132. return new AppResultJson() { Status = "-1", Info = "请填写正确的升级天数" };
  133. }
  134. if (string.IsNullOrEmpty(fields["UpLevelIntegral"].ToString()))
  135. {
  136. return new AppResultJson() { Status = "-1", Info = "请填写升级需要积分值" };
  137. }
  138. if (!function.IsNum(fields["UpLevelIntegral"].ToString()))
  139. {
  140. return new AppResultJson() { Status = "-1", Info = "请填写正确的升级需要积分值" };
  141. }
  142. if (string.IsNullOrEmpty(fields["UpLevelGrowth"].ToString()))
  143. {
  144. return new AppResultJson() { Status = "-1", Info = "请填写升级需要成长值" };
  145. }
  146. if (!function.IsInt(fields["UpLevelGrowth"].ToString()))
  147. {
  148. return new AppResultJson() { Status = "-1", Info = "请填写正确的升级需要成长值" };
  149. }
  150. }
  151. int Id = new DbService(AppConfig.Base.mainTables, _conn).Add("UserLevelSet", fields, 0);
  152. return new AppResultJson() { Status = "1", Data = Id };
  153. }
  154. /// <summary>
  155. /// 修改数据
  156. /// </summary>
  157. /// <param name="Fields">要设置的字段</param>
  158. /// <param name="Id">主键Id</param>
  159. public static AppResultJson Edit(Dictionary<string, object> fields, int Id, bool check = true)
  160. {
  161. if (check)
  162. {
  163. if (string.IsNullOrEmpty(fields["UpLevelDays"].ToString()))
  164. {
  165. return new AppResultJson() { Status = "-1", Info = "请填写升级天数" };
  166. }
  167. if (!function.IsInt(fields["UpLevelDays"].ToString()))
  168. {
  169. return new AppResultJson() { Status = "-1", Info = "请填写正确的升级天数" };
  170. }
  171. if (string.IsNullOrEmpty(fields["UpLevelIntegral"].ToString()))
  172. {
  173. return new AppResultJson() { Status = "-1", Info = "请填写升级需要积分值" };
  174. }
  175. if (!function.IsNum(fields["UpLevelIntegral"].ToString()))
  176. {
  177. return new AppResultJson() { Status = "-1", Info = "请填写正确的升级需要积分值" };
  178. }
  179. if (string.IsNullOrEmpty(fields["UpLevelGrowth"].ToString()))
  180. {
  181. return new AppResultJson() { Status = "-1", Info = "请填写升级需要成长值" };
  182. }
  183. if (!function.IsInt(fields["UpLevelGrowth"].ToString()))
  184. {
  185. return new AppResultJson() { Status = "-1", Info = "请填写正确的升级需要成长值" };
  186. }
  187. }
  188. new DbService(AppConfig.Base.mainTables, _conn).Edit("UserLevelSet", fields, Id);
  189. return new AppResultJson() { Status = "1", Data = Id };
  190. }
  191. /// <summary>
  192. /// 逻辑删除
  193. /// </summary>
  194. /// <param name="Id">主键Id</param>
  195. public static void Remove(int Id)
  196. {
  197. Dictionary<string, object> fields = new Dictionary<string, object>();
  198. fields.Add("Status", -1);
  199. new DbService(AppConfig.Base.mainTables, _conn).Edit("UserLevelSet", fields, Id);
  200. }
  201. /// <summary>
  202. /// 删除数据
  203. /// </summary>
  204. /// <param name="Id">主键Id</param>
  205. public static void Delete(int Id)
  206. {
  207. new DbService(AppConfig.Base.mainTables, _conn).Delete("UserLevelSet", Id);
  208. }
  209. /// <summary>
  210. /// 排序
  211. /// </summary>
  212. /// <param name="Id">主键Id</param>
  213. /// <param name="Sort">排序序号</param>
  214. public static void Sort(int Id, int Sort)
  215. {
  216. new DbService(AppConfig.Base.mainTables, _conn).Sort("UserLevelSet", Sort, Id);
  217. }
  218. /// <summary>
  219. /// 导入数据
  220. /// </summary>
  221. /// <param name="ExcelData">json数据</param>
  222. public static void Import(string ExcelData)
  223. {
  224. WebCMSEntities db = new WebCMSEntities();
  225. JsonData list = JsonMapper.ToObject(ExcelData);
  226. for (int i = 1; i < list.Count; i++)
  227. {
  228. JsonData dr = list[i];
  229. db.UserLevelSet.Add(new UserLevelSet()
  230. {
  231. CreateDate = DateTime.Now,
  232. UpdateDate = DateTime.Now,
  233. });
  234. db.SaveChanges();
  235. }
  236. db.Dispose();
  237. }
  238. /// <summary>
  239. /// 导出excel表格
  240. /// </summary>
  241. /// <param name="fields">查询条件(单个字段)</param>
  242. /// <param name="condition">查询条件(sql语句)</param>
  243. /// <returns></returns>
  244. // public static void ExportExcel(List<RelationData> relationData, string condition)
  245. // {
  246. // }
  247. }
  248. }