PosMachinesTwoService.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  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 PosMachinesTwoService
  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("BindingState"); //绑定状态
  32. fields.Add("BindingTime"); //绑定时间
  33. fields.Add("ActivationState"); //激活状态
  34. fields.Add("ActivationTime"); //激活时间
  35. fields.Add("TransferTime"); //划拨时间
  36. fields.Add("RecycStartDate"); //循环开始时间
  37. fields.Add("RecycEndDate"); //循环截止时间
  38. fields.Add("SeoKeyword"); //实际押金
  39. fields.Add("PrizeParams"); //设置押金
  40. fields.Add("UserId"); //所属创客
  41. fields.Add("PosSn"); //SN编号
  42. fields.Add("BuyUserId"); //购买人
  43. fields.Add("BrandId"); //产品类型
  44. fields.Add("ActivityList"); //参加活动
  45. fields.Add("BindMerchantId"); //绑定商户
  46. fields.Add("PosSnType"); //机具类型
  47. fields.Add("DeviceType"); //设备类型
  48. fields.Add("SourceStoreId"); //源仓库
  49. fields.Add("StoreId"); //s仓库
  50. fields.Add("PreUserId"); //预发人
  51. fields.Add("LeaderUserId"); //大盟主
  52. fields.Add("IsFirst"); //是否首台
  53. fields.Add("UpFeeFlag"); //费率调升标记
  54. fields.Add("DownFeeFlag"); //费率调降标记
  55. fields.Add("UpFeeDate"); //费率调升时间
  56. fields.Add("DownFeeDate"); //费率调降标记
  57. fields.Add("UpFeeMan"); //费率调升人
  58. fields.Add("DownFeeMan"); //费率调降人
  59. fields.Add("OpReserve1"); //运营中心额度1
  60. fields.Add("OpReserve2"); //运营中心额度2
  61. fields.Add("OpReserve3"); //运营中心额度3
  62. fields.Add("OpId"); //运营中心
  63. Dictionary<string, object> obj = new DbService(AppConfig.Base.mainTables, _conn).IndexData("PosMachinesTwo", relationData, orderBy, page, limit, condition, fields);
  64. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  65. count = int.Parse(obj["count"].ToString());
  66. return diclist;
  67. }
  68. public static List<Dictionary<string, object>> List(List<RelationData> relationData, string condition, int page = 1, int limit = 30, string orderBy = "Sort desc,Id desc")
  69. {
  70. List<string> fields = new List<string>(); //要显示的列
  71. fields.Add("Id");
  72. fields.Add("CreateDate"); //添加时间
  73. fields.Add("Status"); //状态
  74. fields.Add("BindingState"); //绑定状态
  75. fields.Add("ActivationState"); //激活状态
  76. fields.Add("UserId"); //所属创客
  77. fields.Add("PosSn"); //SN编号
  78. fields.Add("BuyUserId"); //购买人
  79. fields.Add("BrandId"); //产品类型
  80. fields.Add("ActivityList"); //参加活动
  81. fields.Add("BindMerchantId"); //绑定商户
  82. fields.Add("PosSnType"); //机具类型
  83. fields.Add("DeviceType"); //设备类型
  84. fields.Add("SourceStoreId"); //源仓库
  85. fields.Add("PreUserId"); //预发人
  86. fields.Add("LeaderUserId"); //大盟主
  87. fields.Add("IsFirst"); //是否首台
  88. fields.Add("UpFeeFlag"); //费率调升标记
  89. fields.Add("DownFeeFlag"); //费率调降标记
  90. fields.Add("UpFeeDate"); //费率调升时间
  91. fields.Add("DownFeeDate"); //费率调降标记
  92. fields.Add("UpFeeMan"); //费率调升人
  93. fields.Add("DownFeeMan"); //费率调降人
  94. fields.Add("OpReserve1"); //运营中心额度1
  95. fields.Add("OpReserve2"); //运营中心额度2
  96. fields.Add("OpReserve3"); //运营中心额度3
  97. Dictionary<string, object> obj = new DbService(AppConfig.Base.mainTables, _conn).IndexData("PosMachinesTwo", relationData, orderBy, page, limit, condition, fields);
  98. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  99. return diclist;
  100. }
  101. /// <summary>
  102. /// 查询一条记录
  103. /// </summary>
  104. /// <param name="Id">主键Id</param>
  105. /// <returns></returns>
  106. public static PosMachinesTwo Query(int Id)
  107. {
  108. WebCMSEntities db = new WebCMSEntities();
  109. PosMachinesTwo editData = db.PosMachinesTwo.FirstOrDefault(m => m.Id == Id) ?? new PosMachinesTwo();
  110. db.Dispose();
  111. return editData;
  112. }
  113. public static PosMachinesTwo Query(string condition, string fields = "*")
  114. {
  115. // DataTable dt = new DbService(AppConfig.Base.mainTables, _conn).QueryDetail(fields, "PosMachinesTwo", condition);
  116. // if (dt.Rows.Count > 0)
  117. // {
  118. // Dictionary<string, object> row = new Dictionary<string, object>();
  119. // foreach (DataColumn dc in dt.Columns)
  120. // {
  121. // row.Add(dc.ColumnName, dt.Rows[0][dc.ColumnName].ToString());
  122. // }
  123. // return Newtonsoft.Json.JsonConvert.DeserializeObject<PosMachinesTwo>(Newtonsoft.Json.JsonConvert.SerializeObject(row));
  124. // }
  125. var posMachinesTwo = new DbService(AppConfig.Base.mainTables, _conn).Query(fields, "PosMachinesTwo", condition);
  126. if (posMachinesTwo.Count > 0)
  127. {
  128. return Newtonsoft.Json.JsonConvert.DeserializeObject<PosMachinesTwo>(Newtonsoft.Json.JsonConvert.SerializeObject(posMachinesTwo));
  129. }
  130. return new PosMachinesTwo();
  131. }
  132. public static decimal Sum(string condition, string field)
  133. {
  134. // DataTable dt = new DbService(AppConfig.Base.mainTables, _conn).QueryDetail("Sum(" + field + ")", "PosMachinesTwo", condition);
  135. // decimal amount = 0;
  136. // if (dt.Rows.Count > 0)
  137. // {
  138. // amount = decimal.Parse(dt.Rows[0][0].ToString());
  139. // }
  140. var dt = new DbService(AppConfig.Base.mainTables, _conn).Query("Sum(" + field + ") " + field, "PosMachinesTwo", condition);
  141. decimal amount = 0;
  142. if (dt.Count > 0)
  143. {
  144. amount = decimal.Parse(dt[field].ToString());
  145. }
  146. return amount;
  147. }
  148. /// <summary>
  149. /// 查询记录数
  150. /// </summary>
  151. /// <param name="Id">主键Id</param>
  152. /// <returns></returns>
  153. public static int Count(string condition = "", string field = "Id")
  154. {
  155. // int result = 0;
  156. // DataTable dt = new DbService(AppConfig.Base.mainTables, _conn).QueryDetail("count(" + field + ")", "PosMachinesTwo", condition);
  157. // if (dt.Rows.Count > 0)
  158. // {
  159. // result = int.Parse(function.CheckInt(dt.Rows[0][0].ToString()));
  160. // }
  161. var dt = new DbService(AppConfig.Base.mainTables, _conn).Query("Count(" + field + ") " + field, "PosMachinesTwo", condition);
  162. int result = 0;
  163. if (dt.Count > 0)
  164. {
  165. result = int.Parse(dt[field].ToString());
  166. }
  167. return result;
  168. }
  169. /// <summary>
  170. /// 查询是否存在
  171. /// </summary>
  172. /// <param name="Id">主键Id</param>
  173. /// <returns></returns>
  174. public static bool Exist(int Id)
  175. {
  176. WebCMSEntities db = new WebCMSEntities();
  177. bool check = db.PosMachinesTwo.Any(m => m.Id == Id);
  178. db.Dispose();
  179. return check;
  180. }
  181. /// <summary>
  182. /// 添加数据
  183. /// </summary>
  184. /// <param name="Fields">要设置的字段</param>
  185. /// <returns></returns>
  186. public static AppResultJson Add(Dictionary<string, object> fields, bool check = true)
  187. {
  188. if (check)
  189. {
  190. if (string.IsNullOrEmpty(fields["PosSn"].ToString()))
  191. {
  192. return new AppResultJson() { Status = "-1", Info = "请填写SN编号" };
  193. }
  194. if (string.IsNullOrEmpty(fields["BuyUserId"].ToString()))
  195. {
  196. return new AppResultJson() { Status = "-1", Info = "请填写购买人" };
  197. }
  198. }
  199. int Id = new DbService(AppConfig.Base.mainTables, _conn).Add("PosMachinesTwo", fields, 0);
  200. return new AppResultJson() { Status = "1", Data = Id };
  201. }
  202. /// <summary>
  203. /// 修改数据
  204. /// </summary>
  205. /// <param name="Fields">要设置的字段</param>
  206. /// <param name="Id">主键Id</param>
  207. public static AppResultJson Edit(Dictionary<string, object> fields, int Id, bool check = true)
  208. {
  209. // if (check)
  210. // {
  211. // if (string.IsNullOrEmpty(fields["PosSn"].ToString()))
  212. // {
  213. // return new AppResultJson() { Status = "-1", Info = "请填写SN编号" };
  214. // }
  215. // if (string.IsNullOrEmpty(fields["BuyUserId"].ToString()))
  216. // {
  217. // return new AppResultJson() { Status = "-1", Info = "请填写购买人" };
  218. // }
  219. // }
  220. new DbService(AppConfig.Base.mainTables, _conn).Edit("PosMachinesTwo", fields, Id);
  221. return new AppResultJson() { Status = "1", Data = Id };
  222. }
  223. /// <summary>
  224. /// 逻辑删除
  225. /// </summary>
  226. /// <param name="Id">主键Id</param>
  227. public static void Remove(int Id)
  228. {
  229. Dictionary<string, object> fields = new Dictionary<string, object>();
  230. fields.Add("Status", -1);
  231. new DbService(AppConfig.Base.mainTables, _conn).Edit("PosMachinesTwo", fields, Id);
  232. }
  233. /// <summary>
  234. /// 删除数据
  235. /// </summary>
  236. /// <param name="Id">主键Id</param>
  237. public static void Delete(int Id)
  238. {
  239. new DbService(AppConfig.Base.mainTables, _conn).Delete("PosMachinesTwo", Id);
  240. }
  241. /// <summary>
  242. /// 排序
  243. /// </summary>
  244. /// <param name="Id">主键Id</param>
  245. /// <param name="Sort">排序序号</param>
  246. public static void Sort(int Id, int Sort)
  247. {
  248. new DbService(AppConfig.Base.mainTables, _conn).Sort("PosMachinesTwo", Sort, Id);
  249. }
  250. /// <summary>
  251. /// 导入数据
  252. /// </summary>
  253. /// <param name="ExcelData">json数据</param>
  254. public static void Import(string ExcelData)
  255. {
  256. WebCMSEntities db = new WebCMSEntities();
  257. JsonData list = JsonMapper.ToObject(ExcelData);
  258. for (int i = 1; i < list.Count; i++)
  259. {
  260. JsonData dr = list[i];
  261. db.PosMachinesTwo.Add(new PosMachinesTwo()
  262. {
  263. CreateDate = DateTime.Now,
  264. UpdateDate = DateTime.Now,
  265. });
  266. db.SaveChanges();
  267. }
  268. db.Dispose();
  269. }
  270. /// <summary>
  271. /// 导出excel表格
  272. /// </summary>
  273. /// <param name="fields">查询条件(单个字段)</param>
  274. /// <param name="condition">查询条件(sql语句)</param>
  275. /// <returns></returns>
  276. // public static void ExportExcel(List<RelationData> relationData, string condition)
  277. // {
  278. // }
  279. }
  280. }