PosMachinesFeeChangeRecordService.cs 10 KB

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