SchoolSignInRecordService.cs 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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 SchoolSignInRecordService
  14. {
  15. string _conn = "";
  16. public SchoolSignInRecordService()
  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("UserId"); //创客
  36. Dictionary<string, object> obj = new DbService(AppConfig.Base.dbTables, _conn).IndexData("SchoolSignInRecord", 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 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. Dictionary<string, object> obj = new DbService(AppConfig.Base.dbTables, _conn).IndexData("SchoolSignInRecord", relationData, orderBy, page, limit, condition, fields);
  49. List<Dictionary<string, object>> diclist = obj["data"] as List<Dictionary<string, object>>;
  50. return diclist;
  51. }
  52. /// <summary>
  53. /// 查询一条记录
  54. /// </summary>
  55. /// <param name="Id">主键Id</param>
  56. /// <returns></returns>
  57. public SchoolSignInRecord Query(int Id)
  58. {
  59. WebCMSEntities db = new WebCMSEntities();
  60. SchoolSignInRecord editData = db.SchoolSignInRecord.FirstOrDefault(m => m.Id == Id) ?? new SchoolSignInRecord();
  61. db.Dispose();
  62. return editData;
  63. }
  64. /// <summary>
  65. /// 查询记录数
  66. /// </summary>
  67. /// <param name="Id">主键Id</param>
  68. /// <returns></returns>
  69. public int Count(string condition = "")
  70. {
  71. int result = 0;
  72. DataTable dt = CustomerSqlConn.dtable("select count(Id) from SchoolSignInRecord where 1=1" + condition, _conn);
  73. if(dt.Rows.Count > 0)
  74. {
  75. result = int.Parse(function.CheckInt(dt.Rows[0][0].ToString()));
  76. }
  77. return result;
  78. }
  79. /// <summary>
  80. /// 查询是否存在
  81. /// </summary>
  82. /// <param name="Id">主键Id</param>
  83. /// <returns></returns>
  84. public bool Exist(int Id)
  85. {
  86. WebCMSEntities db = new WebCMSEntities();
  87. bool check = db.SchoolSignInRecord.Any(m => m.Id == Id);
  88. db.Dispose();
  89. return check;
  90. }
  91. /// <summary>
  92. /// 添加数据
  93. /// </summary>
  94. /// <param name="Fields">要设置的字段</param>
  95. /// <returns></returns>
  96. public AppResultJson Add(Dictionary<string, object> fields, bool check = true)
  97. {
  98. if(check)
  99. {
  100. }
  101. int Id = new DbService(AppConfig.Base.dbTables, _conn).Add("SchoolSignInRecord", fields, 0);
  102. return new AppResultJson(){ Status = "1", Data = Id };
  103. }
  104. /// <summary>
  105. /// 修改数据
  106. /// </summary>
  107. /// <param name="Fields">要设置的字段</param>
  108. /// <param name="Id">主键Id</param>
  109. public AppResultJson Edit(Dictionary<string, object> fields, int Id, bool check = true)
  110. {
  111. if(check)
  112. {
  113. }
  114. new DbService(AppConfig.Base.dbTables, _conn).Edit("SchoolSignInRecord", fields, Id);
  115. return new AppResultJson(){ Status = "1", Data = Id };
  116. }
  117. /// <summary>
  118. /// 逻辑删除
  119. /// </summary>
  120. /// <param name="Id">主键Id</param>
  121. public void Remove(int Id)
  122. {
  123. Dictionary<string, object> fields = new Dictionary<string, object>();
  124. fields.Add("Status", -1);
  125. new DbService(AppConfig.Base.dbTables, _conn).Edit("SchoolSignInRecord", fields, Id);
  126. }
  127. /// <summary>
  128. /// 删除数据
  129. /// </summary>
  130. /// <param name="Id">主键Id</param>
  131. public void Delete(int Id)
  132. {
  133. new DbService(AppConfig.Base.dbTables, _conn).Delete("SchoolSignInRecord", Id);
  134. }
  135. /// <summary>
  136. /// 排序
  137. /// </summary>
  138. /// <param name="Id">主键Id</param>
  139. /// <param name="Sort">排序序号</param>
  140. public void Sort(int Id, int Sort)
  141. {
  142. new DbService(AppConfig.Base.dbTables, _conn).Sort("SchoolSignInRecord", Sort, Id);
  143. }
  144. /// <summary>
  145. /// 导入数据
  146. /// </summary>
  147. /// <param name="ExcelData">json数据</param>
  148. public void Import(string ExcelData)
  149. {
  150. WebCMSEntities db = new WebCMSEntities();
  151. JsonData list = JsonMapper.ToObject(ExcelData);
  152. for (int i = 1; i < list.Count;i++ )
  153. {
  154. JsonData dr = list[i];
  155. db.SchoolSignInRecord.Add(new SchoolSignInRecord()
  156. {
  157. CreateDate = DateTime.Now,
  158. UpdateDate = DateTime.Now,
  159. });
  160. db.SaveChanges();
  161. }
  162. db.Dispose();
  163. }
  164. /// <summary>
  165. /// 导出excel表格
  166. /// </summary>
  167. /// <param name="fields">查询条件(单个字段)</param>
  168. /// <param name="condition">查询条件(sql语句)</param>
  169. /// <returns></returns>
  170. // public void ExportExcel(List<RelationData> relationData, string condition)
  171. // {
  172. // }
  173. }
  174. }