UploadParamsService.cs 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /*
  2. * 上传配置项
  3. */
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Data;
  8. using MySystem.Models.Operate;
  9. using Library;
  10. using LitJson;
  11. namespace MySystem.Service.Operate
  12. {
  13. public class UploadParamsService
  14. {
  15. string _conn = "";
  16. public UploadParamsService()
  17. {
  18. _conn = ConfigurationManager.AppSettings["OpSqlConnStr"].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("TableName"); //表名
  36. fields.Add("ColumnName"); //字段名
  37. fields.Add("ColumnEnName"); //字段英文明
  38. fields.Add("ParamString"); //参数
  39. fields.Add("TableEnName"); //表英文名
  40. Dictionary<string, object> obj = new DbService(AppConfig.Base.dbTables, _conn).IndexData("UploadParams", relationData, orderBy, page, limit, condition, fields);
  41. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  42. count = int.Parse(obj["count"].ToString());
  43. return diclist;
  44. }
  45. public List<Dictionary<string, object>> List(List<RelationData> relationData, string condition, int page = 1, int limit = 30, string orderBy = "Sort desc,Id desc")
  46. {
  47. List<string> fields = new List<string>(); //要显示的列
  48. fields.Add("Id");
  49. fields.Add("CreateDate"); //添加时间
  50. fields.Add("Status"); //状态
  51. fields.Add("TableName"); //表名
  52. fields.Add("ColumnName"); //字段名
  53. fields.Add("ColumnEnName"); //字段英文明
  54. fields.Add("ParamString"); //参数
  55. fields.Add("TableEnName"); //表英文名
  56. Dictionary<string, object> obj = new DbService(AppConfig.Base.dbTables, _conn).IndexData("UploadParams", relationData, orderBy, page, limit, condition, fields);
  57. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  58. return diclist;
  59. }
  60. /// <summary>
  61. /// 查询一条记录
  62. /// </summary>
  63. /// <param name="Id">主键Id</param>
  64. /// <returns></returns>
  65. public UploadParams Query(int Id)
  66. {
  67. WebCMSEntities db = new WebCMSEntities();
  68. UploadParams editData = db.UploadParams.FirstOrDefault(m => m.Id == Id) ?? new UploadParams();
  69. db.Dispose();
  70. return editData;
  71. }
  72. /// <summary>
  73. /// 查询记录数
  74. /// </summary>
  75. /// <param name="Id">主键Id</param>
  76. /// <returns></returns>
  77. public int Count(string condition = "")
  78. {
  79. int result = 0;
  80. DataTable dt = CustomerSqlConn.dtable("select count(Id) from UploadParams where 1=1" + condition, _conn);
  81. if(dt.Rows.Count > 0)
  82. {
  83. result = int.Parse(function.CheckInt(dt.Rows[0][0].ToString()));
  84. }
  85. return result;
  86. }
  87. /// <summary>
  88. /// 查询是否存在
  89. /// </summary>
  90. /// <param name="Id">主键Id</param>
  91. /// <returns></returns>
  92. public bool Exist(int Id)
  93. {
  94. WebCMSEntities db = new WebCMSEntities();
  95. bool check = db.UploadParams.Any(m => m.Id == Id);
  96. db.Dispose();
  97. return check;
  98. }
  99. /// <summary>
  100. /// 添加数据
  101. /// </summary>
  102. /// <param name="Fields">要设置的字段</param>
  103. /// <returns></returns>
  104. public AppResultJson Add(Dictionary<string, object> fields, bool check = true)
  105. {
  106. if(check)
  107. {
  108. }
  109. int Id = new DbService(AppConfig.Base.dbTables, _conn).Add("UploadParams", fields, 0);
  110. return new AppResultJson(){ Status = "1", Data = Id };
  111. }
  112. /// <summary>
  113. /// 修改数据
  114. /// </summary>
  115. /// <param name="Fields">要设置的字段</param>
  116. /// <param name="Id">主键Id</param>
  117. public AppResultJson Edit(Dictionary<string, object> fields, int Id, bool check = true)
  118. {
  119. if(check)
  120. {
  121. }
  122. new DbService(AppConfig.Base.dbTables, _conn).Edit("UploadParams", fields, Id);
  123. return new AppResultJson(){ Status = "1", Data = Id };
  124. }
  125. /// <summary>
  126. /// 逻辑删除
  127. /// </summary>
  128. /// <param name="Id">主键Id</param>
  129. public void Remove(int Id)
  130. {
  131. Dictionary<string, object> fields = new Dictionary<string, object>();
  132. fields.Add("Status", -1);
  133. new DbService(AppConfig.Base.dbTables, _conn).Edit("UploadParams", fields, Id);
  134. }
  135. /// <summary>
  136. /// 删除数据
  137. /// </summary>
  138. /// <param name="Id">主键Id</param>
  139. public void Delete(int Id)
  140. {
  141. new DbService(AppConfig.Base.dbTables, _conn).Delete("UploadParams", Id);
  142. }
  143. /// <summary>
  144. /// 排序
  145. /// </summary>
  146. /// <param name="Id">主键Id</param>
  147. /// <param name="Sort">排序序号</param>
  148. public void Sort(int Id, int Sort)
  149. {
  150. new DbService(AppConfig.Base.dbTables, _conn).Sort("UploadParams", Sort, Id);
  151. }
  152. /// <summary>
  153. /// 导入数据
  154. /// </summary>
  155. /// <param name="ExcelData">json数据</param>
  156. public void Import(string ExcelData)
  157. {
  158. WebCMSEntities db = new WebCMSEntities();
  159. JsonData list = JsonMapper.ToObject(ExcelData);
  160. for (int i = 1; i < list.Count;i++ )
  161. {
  162. JsonData dr = list[i];
  163. db.UploadParams.Add(new UploadParams()
  164. {
  165. CreateDate = DateTime.Now,
  166. UpdateDate = DateTime.Now,
  167. });
  168. db.SaveChanges();
  169. }
  170. db.Dispose();
  171. }
  172. /// <summary>
  173. /// 导出excel表格
  174. /// </summary>
  175. /// <param name="fields">查询条件(单个字段)</param>
  176. /// <param name="condition">查询条件(sql语句)</param>
  177. /// <returns></returns>
  178. // public void ExportExcel(List<RelationData> relationData, string condition)
  179. // {
  180. // }
  181. }
  182. }