TravelListService.cs 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. using Models;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.Data.SqlClient;
  6. using System.Linq;
  7. using System.Text;
  8. namespace DAL
  9. {
  10. public class TravelListService
  11. {
  12. /// <summary>
  13. /// 查询所有
  14. /// </summary>
  15. /// <param name="sql">sql语句</param>
  16. /// <param name="param">可变参数数组</param>
  17. /// <returns>返回集合</returns>
  18. List<TravelList> excuteSql(string sql, params SqlParameter[] param)
  19. {
  20. return ServiceBase<TravelList>.excuteSql(new TravelList(), "TravelList", sql, CommandType.Text, param);
  21. }
  22. /// <summary>
  23. /// 获取单个对象
  24. /// </summary>
  25. /// <param name="sql">sql语句</param>
  26. /// <param name="param">可变参数数组</param>
  27. /// <returns>返回空或者单个对象</returns>
  28. TravelList excuteType(string sql, params SqlParameter[] param)
  29. {
  30. //查询结果放入对象集合
  31. List<TravelList> hdList = excuteSql(sql, param);
  32. //判断集合是否为空
  33. if (hdList == null || hdList.Count == 0)
  34. //返回null
  35. return null;
  36. //返回单个对象
  37. return hdList[0];
  38. }
  39. /// <summary>
  40. /// 根据编号查询对象信息
  41. /// </summary>
  42. /// <param name="id">对象编号</param>
  43. /// <returns>返回空或者单个对象信息</returns>
  44. public TravelList GetById(int id)
  45. {
  46. //调用获取单个对象的方法
  47. return excuteType("select * from TravelList where Id = @id", new SqlParameter("@id", id));
  48. }
  49. /// <summary>
  50. /// 根据团组编号查询信息
  51. /// </summary>
  52. /// <returns>返回空或者对象信息</returns>
  53. public List<TravelList> GetByDiid(int Diid)
  54. {
  55. //调用获取单个对象的方法
  56. return excuteSql("select * from TravelList where Diid =" + Diid + " and Isdel=0 order by Id");
  57. }
  58. public List<TravelList> GetByDiidandGroup(int Diid,int diffgroup)
  59. {
  60. return excuteSql($" select * from TravelList where Diid ={Diid} and diffgroup = {diffgroup} and Isdel=0 order by Id");
  61. }
  62. /// <summary>
  63. /// 获取全部
  64. /// </summary>
  65. /// <returns></returns>
  66. public List<TravelList> GetAll()
  67. {
  68. return excuteSql("select * from TravelList where Isdel=0");
  69. }
  70. /// <summary>
  71. /// 增加
  72. /// </summary>
  73. /// <param name="cd"></param>
  74. /// <returns></returns>
  75. public bool AddTravelList(TravelList hd)
  76. {
  77. string sql = "insert into TravelList values(@Diid,@Days,@Date,@WeekDay,@Traffic_First,@Traffic_Second,@Trip,@OPer,@issel,@diffgroup,@OPdate,@Isdel)";
  78. SqlParameter[] parameter = new SqlParameter[]{
  79. new SqlParameter("@Diid",hd.Diid),
  80. new SqlParameter("@Days",hd.Days),
  81. new SqlParameter("@Date",hd.Date),
  82. new SqlParameter("@WeekDay",hd.WeekDay),
  83. new SqlParameter("@Traffic_First",hd.Traffic_First),
  84. new SqlParameter("@Traffic_Second",hd.Traffic_Second),
  85. new SqlParameter("@Trip",hd.Trip),
  86. new SqlParameter("@OPer",hd.OPer),
  87. new SqlParameter("@OPdate",hd.OPdate),
  88. new SqlParameter("@issel",hd.issel),
  89. new SqlParameter("@diffgroup",hd.diffgroup),
  90. new SqlParameter("@Isdel",hd.Isdel),
  91. };
  92. if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0)
  93. return true;
  94. return false;
  95. }
  96. /// <summary>
  97. /// 编辑
  98. /// </summary>
  99. /// <param name="sdt"></param>
  100. /// <returns></returns>
  101. public bool EditTravelList(TravelList hd)
  102. {
  103. string sql = "update TravelList set Diid=@Diid,Days = @Days,Date = @Date,WeekDay = @WeekDay,Traffic_First = @Traffic_First,"
  104. + "Traffic_Second = @Traffic_Second,Trip = @Trip,OPer = @OPer,OPdate = @OPdate,Isdel = @Isdel where Id = @Id";
  105. SqlParameter[] parameter = new SqlParameter[]{
  106. new SqlParameter("@Diid",hd.Diid),
  107. new SqlParameter("@Days",hd.Days),
  108. new SqlParameter("@Date",hd.Date),
  109. new SqlParameter("@WeekDay",hd.WeekDay),
  110. new SqlParameter("@Traffic_First",hd.Traffic_First),
  111. new SqlParameter("@Traffic_Second",hd.Traffic_Second),
  112. new SqlParameter("@Trip",hd.Trip),
  113. new SqlParameter("@OPer",hd.OPer),
  114. new SqlParameter("@OPdate",hd.OPdate),
  115. new SqlParameter("@Isdel",hd.Isdel),
  116. new SqlParameter("@Id",hd.Id)
  117. };
  118. if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0)
  119. return true;
  120. return false;
  121. }
  122. /// <summary>
  123. /// 20210818 贾文滔
  124. /// 根据ID执行delete操作
  125. /// </summary>
  126. /// <param name="id"></param>
  127. /// <returns></returns>
  128. public bool DelTravelList(int id)
  129. {
  130. if (SqlHelper.ExecuteNonQuery("delete TravelList where Id = @Id", CommandType.Text, new SqlParameter("@Id", id)) > 0)
  131. return true;
  132. return false;
  133. }
  134. /// <summary>
  135. /// 20210818 贾文滔
  136. /// 根据id执行清空"trip" 字段操作
  137. /// </summary>
  138. /// <param name="id"></param>
  139. /// <returns></returns>
  140. public bool Clean(int id)
  141. {
  142. if (SqlHelper.ExecuteNonQuery("update TravelList set Trip='' where Id = @Id", CommandType.Text, new SqlParameter("@Id", id)) > 0)
  143. return true;
  144. return false;
  145. }
  146. /// <summary>
  147. /// 20210818 贾文滔
  148. /// 根据团号和ID范围执行delete操作
  149. /// </summary>
  150. /// <param name="Diid"></param>
  151. /// <param name="start"></param>
  152. /// <param name="end"></param>
  153. /// <returns></returns>
  154. public bool DelOld(int Diid, int start, int end)
  155. {
  156. if (SqlHelper.ExecuteNonQuery("delete from TravelList where Diid=" + Diid + " and ( Id>=" + start + " and Id<=" + end + ")", CommandType.Text) > 0)
  157. return true;
  158. return false;
  159. }
  160. /// <summary>
  161. /// 20210818
  162. /// 根据团号diid 执行更新ISDEL=1的删除操作
  163. /// </summary>
  164. /// <param name="diid"></param>
  165. /// <returns></returns>
  166. public bool DelByDiid(int diid)
  167. {
  168. if (SqlHelper.ExecuteNonQuery("update TravelList set Isdel=1 where Diid=" + diid, CommandType.Text) > 0)
  169. return true;
  170. return false;
  171. }
  172. /// <summary>
  173. /// 设置一个行程为最终行程
  174. /// </summary>
  175. /// <param name="diid"></param>
  176. /// <param name="diffgroup"></param>
  177. /// <returns></returns>
  178. public bool UpdateSelbydiffGroupandDiid(int diid,int diffgroup)
  179. {
  180. bool istrue = SqlHelper.ExecuteNonQuery($"update TravelList set issel = 0 where Diid ={diid} and Isdel=0 ", CommandType.Text, null) > 0;
  181. if (istrue)
  182. {
  183. istrue = SqlHelper.ExecuteNonQuery($"update TravelList set issel = 1 where Diid ={diid} and Isdel=0 and diffgroup = {diffgroup}", CommandType.Text, null) > 0;
  184. }
  185. return istrue;
  186. }
  187. }
  188. public class tempTData
  189. {
  190. /// <summary>
  191. /// TravelList 表数据的再分组
  192. /// </summary>
  193. public int diffgroup { get; set; }
  194. /// <summary>
  195. /// 团组id
  196. /// </summary>
  197. public int diid { get; set; }
  198. /// <summary>
  199. /// 团组名称
  200. /// </summary>
  201. public string TeamName { get; set; }
  202. }
  203. }