MachineChangeDetailService.cs 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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 MachineChangeDetailService
  14. {
  15. string _conn = "";
  16. public MachineChangeDetailService()
  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. fields.Add("ChangeNo"); //订单号
  36. fields.Add("BackProductType"); //退回产品类型
  37. fields.Add("BackProductName"); //退回产品名称
  38. fields.Add("UserId"); //创客
  39. fields.Add("BackSnNo"); //设备SN编号
  40. fields.Add("BackDeviceStatus"); //设备状态
  41. fields.Add("OutProductType "); //出库产品类型
  42. fields.Add("OutProductName"); //出库产品名称
  43. fields.Add("OutSnNo"); //出库设备SN编号
  44. fields.Add("OutSnType"); //出库SN机具类型
  45. fields.Add("Remark"); //备注
  46. fields.Add("BackSnType"); //退回SN机具类型
  47. Dictionary<string, object> obj = new DbService(AppConfig.Base.dbTables, _conn).IndexData("MachineChangeDetail", relationData, orderBy, page, limit, condition, fields);
  48. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  49. count = int.Parse(obj["count"].ToString());
  50. return diclist;
  51. }
  52. public List<Dictionary<string, object>> List(List<RelationData> relationData, string condition, int page = 1, int limit = 30, string orderBy = "Sort desc,Id desc")
  53. {
  54. List<string> fields = new List<string>(); //要显示的列
  55. fields.Add("Id");
  56. fields.Add("CreateDate"); //添加时间
  57. fields.Add("Status"); //状态
  58. fields.Add("ChangeNo"); //订单号
  59. fields.Add("BackProductType"); //退回产品类型
  60. fields.Add("BackProductName"); //退回产品名称
  61. fields.Add("UserId"); //创客
  62. fields.Add("BackSnNo"); //设备SN编号
  63. fields.Add("BackDeviceStatus"); //设备状态
  64. fields.Add("OutProductType "); //出库产品类型
  65. fields.Add("OutProductName"); //出库产品名称
  66. fields.Add("OutSnNo"); //出库设备SN编号
  67. fields.Add("OutSnType"); //出库SN机具类型
  68. fields.Add("Remark"); //备注
  69. fields.Add("BackSnType"); //退回SN机具类型
  70. Dictionary<string, object> obj = new DbService(AppConfig.Base.dbTables, _conn).IndexData("MachineChangeDetail", relationData, orderBy, page, limit, condition, fields);
  71. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  72. return diclist;
  73. }
  74. /// <summary>
  75. /// 查询一条记录
  76. /// </summary>
  77. /// <param name="Id">主键Id</param>
  78. /// <returns></returns>
  79. public MachineChangeDetail Query(int Id)
  80. {
  81. WebCMSEntities db = new WebCMSEntities();
  82. MachineChangeDetail editData = db.MachineChangeDetail.FirstOrDefault(m => m.Id == Id) ?? new MachineChangeDetail();
  83. db.Dispose();
  84. return editData;
  85. }
  86. /// <summary>
  87. /// 查询记录数
  88. /// </summary>
  89. /// <param name="Id">主键Id</param>
  90. /// <returns></returns>
  91. public int Count(string condition = "")
  92. {
  93. int result = 0;
  94. DataTable dt = CustomerSqlConn.dtable("select count(Id) from MachineChangeDetail where 1=1" + condition, _conn);
  95. if(dt.Rows.Count > 0)
  96. {
  97. result = int.Parse(function.CheckInt(dt.Rows[0][0].ToString()));
  98. }
  99. return result;
  100. }
  101. /// <summary>
  102. /// 查询是否存在
  103. /// </summary>
  104. /// <param name="Id">主键Id</param>
  105. /// <returns></returns>
  106. public bool Exist(int Id)
  107. {
  108. WebCMSEntities db = new WebCMSEntities();
  109. bool check = db.MachineChangeDetail.Any(m => m.Id == Id);
  110. db.Dispose();
  111. return check;
  112. }
  113. /// <summary>
  114. /// 添加数据
  115. /// </summary>
  116. /// <param name="Fields">要设置的字段</param>
  117. /// <returns></returns>
  118. public AppResultJson Add(Dictionary<string, object> fields, bool check = true)
  119. {
  120. if(check)
  121. {
  122. }
  123. int Id = new DbService(AppConfig.Base.dbTables, _conn).Add("MachineChangeDetail", fields, 0);
  124. return new AppResultJson(){ Status = "1", Data = Id };
  125. }
  126. /// <summary>
  127. /// 修改数据
  128. /// </summary>
  129. /// <param name="Fields">要设置的字段</param>
  130. /// <param name="Id">主键Id</param>
  131. public AppResultJson Edit(Dictionary<string, object> fields, int Id, bool check = true)
  132. {
  133. if(check)
  134. {
  135. }
  136. new DbService(AppConfig.Base.dbTables, _conn).Edit("MachineChangeDetail", fields, Id);
  137. return new AppResultJson(){ Status = "1", Data = Id };
  138. }
  139. /// <summary>
  140. /// 逻辑删除
  141. /// </summary>
  142. /// <param name="Id">主键Id</param>
  143. public void Remove(int Id)
  144. {
  145. Dictionary<string, object> fields = new Dictionary<string, object>();
  146. fields.Add("Status", -1);
  147. new DbService(AppConfig.Base.dbTables, _conn).Edit("MachineChangeDetail", fields, Id);
  148. }
  149. /// <summary>
  150. /// 删除数据
  151. /// </summary>
  152. /// <param name="Id">主键Id</param>
  153. public void Delete(int Id)
  154. {
  155. new DbService(AppConfig.Base.dbTables, _conn).Delete("MachineChangeDetail", Id);
  156. }
  157. /// <summary>
  158. /// 排序
  159. /// </summary>
  160. /// <param name="Id">主键Id</param>
  161. /// <param name="Sort">排序序号</param>
  162. public void Sort(int Id, int Sort)
  163. {
  164. new DbService(AppConfig.Base.dbTables, _conn).Sort("MachineChangeDetail", Sort, Id);
  165. }
  166. /// <summary>
  167. /// 导入数据
  168. /// </summary>
  169. /// <param name="ExcelData">json数据</param>
  170. public void Import(string ExcelData)
  171. {
  172. WebCMSEntities db = new WebCMSEntities();
  173. JsonData list = JsonMapper.ToObject(ExcelData);
  174. for (int i = 1; i < list.Count;i++ )
  175. {
  176. JsonData dr = list[i];
  177. db.MachineChangeDetail.Add(new MachineChangeDetail()
  178. {
  179. CreateDate = DateTime.Now,
  180. UpdateDate = DateTime.Now,
  181. });
  182. db.SaveChanges();
  183. }
  184. db.Dispose();
  185. }
  186. /// <summary>
  187. /// 导出excel表格
  188. /// </summary>
  189. /// <param name="fields">查询条件(单个字段)</param>
  190. /// <param name="condition">查询条件(sql语句)</param>
  191. /// <returns></returns>
  192. // public void ExportExcel(List<RelationData> relationData, string condition)
  193. // {
  194. // }
  195. }
  196. }