StrokeService.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Models;
  6. using System.Data.SqlClient;
  7. using System.Data;
  8. namespace DAL
  9. {
  10. /// <summary>
  11. /// 行程数据访问类
  12. /// </summary>
  13. public class StrokeService
  14. {
  15. /// <summary>
  16. /// 查询所有
  17. /// </summary>
  18. /// <param name="sql">sql语句</param>
  19. /// <param name="param">可变参数数组</param>
  20. /// <returns>返回集合</returns>
  21. List<Stroke> excuteSql(string sql, params SqlParameter[] param)
  22. {
  23. return ServiceBase<Stroke>.excuteSql(new Stroke(), "Stroke", sql, CommandType.Text, param);
  24. }
  25. /// <summary>
  26. /// 获取单个对象
  27. /// </summary>
  28. /// <param name="sql">sql语句</param>
  29. /// <param name="param">可变参数数组</param>
  30. /// <returns>返回空或者单个对象</returns>
  31. Stroke excuteType(string sql, params SqlParameter[] param)
  32. {
  33. //查询结果放入对象集合
  34. List<Stroke> sList = excuteSql(sql, param);
  35. //判断集合是否为空
  36. if (sList == null || sList.Count == 0)
  37. //返回null
  38. return null;
  39. //返回单个对象
  40. return sList[0];
  41. }
  42. /// <summary>
  43. /// 根据编号查询对象信息
  44. /// </summary>
  45. /// <param name="id">对象编号</param>
  46. /// <returns>返回空或者单个对象信息</returns>
  47. public Stroke GetStrokeByDIId(int DIId)
  48. {
  49. //调用获取单个对象的方法
  50. return excuteType("select * from Stroke where DIId = @DIId", new SqlParameter("@DIId", DIId));
  51. }
  52. /// <summary>
  53. /// 根据编号查询对象信息
  54. /// </summary>
  55. /// <param name="id">对象编号</param>
  56. /// <returns>返回空或者单个对象信息</returns>
  57. public Stroke GetStrokeByID(int id)
  58. {
  59. //调用获取单个对象的方法
  60. return excuteType("select * from Stroke where Id = @id and IsDel = 0", new SqlParameter("@id", id));
  61. }
  62. /// <summary>
  63. /// 获取全部 - 分页
  64. /// </summary>
  65. /// <returns></returns>
  66. public List<Stroke> GetStroke(int pageIndex, out int sumPage, out int totalRecord, string tourCode, string arrayUsersId)
  67. {
  68. string sqlwhere = "IsDel = 0 and DIId = '" + tourCode + "' and Operator in (" + arrayUsersId + ")";
  69. return PageBase<Stroke>.excutePageSql(new Stroke(), "Stroke", "Stroke", "*", "id desc", sqlwhere, 10, pageIndex, out sumPage, out totalRecord);
  70. }
  71. /// <summary>
  72. /// 增加
  73. /// </summary>
  74. /// <param name="cd"></param>
  75. /// <returns></returns>
  76. public bool AddStroke(Stroke s)
  77. {
  78. string sql = "insert into Stroke values(@DIId,@StrokeName,@WayCity,@Days,@PNumber,@Remark,@Operator,@OperatorDate,@IsDel)";
  79. SqlParameter[] parameter = new SqlParameter[]{
  80. new SqlParameter("@DIId",s.DIId),
  81. new SqlParameter("@StrokeName",s.StrokeName),
  82. new SqlParameter("@WayCity",s.WayCity),
  83. new SqlParameter("@Days",s.Days),
  84. new SqlParameter("@PNumber",s.PNumber),
  85. new SqlParameter("@Remark",s.Remark),
  86. new SqlParameter("@Operator",s.Operators),
  87. new SqlParameter("@OperatorDate",s.OperatorsDate),
  88. new SqlParameter("@IsDel",s.IsDel)
  89. };
  90. if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0)
  91. return true;
  92. return false;
  93. }
  94. /// <summary>
  95. /// 编辑
  96. /// </summary>
  97. /// <param name="cd"></param>
  98. /// <returns></returns>
  99. public bool EditStroke(Stroke s)
  100. {
  101. string sql = "update Stroke set StrokeName=@StrokeName,WayCity = @WayCity,Days = @Days,PNumber = @PNumber,Remark = @Remark,Operator = @Operator,OperatorDate = @OperatorDate where Id = @Id";
  102. SqlParameter[] parameter = new SqlParameter[]{
  103. new SqlParameter("@StrokeName",s.StrokeName),
  104. new SqlParameter("@WayCity",s.WayCity),
  105. new SqlParameter("@Days",s.Days),
  106. new SqlParameter("@PNumber",s.PNumber),
  107. new SqlParameter("@Remark",s.Remark),
  108. new SqlParameter("@Operator",s.Operators),
  109. new SqlParameter("@OperatorDate",s.OperatorsDate),
  110. new SqlParameter("@Id",s.Id)
  111. };
  112. if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0)
  113. return true;
  114. return false;
  115. }
  116. /// <summary>
  117. /// 删除
  118. /// </summary>
  119. /// <param name="id"></param>
  120. /// <returns></returns>
  121. public bool DelStroke(int id)
  122. {
  123. if (SqlHelper.ExecuteNonQuery("update Stroke set IsDel = 1 where Id = @Id", CommandType.Text, new SqlParameter("@Id", id)) > 0)
  124. return true;
  125. return false;
  126. }
  127. }
  128. }