ApprovalTravelService.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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 ApprovalTravelService
  11. {
  12. /// <summary>
  13. /// 查询所有
  14. /// </summary>
  15. /// <param name="sql">sql语句</param>
  16. /// <param name="param">可变参数数组</param>
  17. /// <returns>返回集合</returns>
  18. List<ApprovalTravel> excuteSql(string sql, params SqlParameter[] param)
  19. {
  20. return ServiceBase<ApprovalTravel>.excuteSql(new ApprovalTravel(), "ApprovalTravel", 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. ApprovalTravel excuteType(string sql, params SqlParameter[] param)
  29. {
  30. //查询结果放入对象集合
  31. List<ApprovalTravel> 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 ApprovalTravel GetById(int id)
  45. {
  46. //调用获取单个对象的方法
  47. return excuteType("select * from ApprovalTravel where Id = @id", new SqlParameter("@id", id));
  48. }
  49. /// <summary>
  50. /// 根据团组编号查询信息
  51. /// </summary>
  52. /// <returns>返回空或者对象信息</returns>
  53. public List<ApprovalTravel> GetByDiid(int Diid)
  54. {
  55. //调用获取单个对象的方法
  56. return excuteSql("select * from ApprovalTravel where Diid =" + Diid + " and Isdel=0 order by Id");
  57. }
  58. /// <summary>
  59. /// 获取全部
  60. /// </summary>
  61. /// <returns></returns>
  62. public List<ApprovalTravel> GetAll()
  63. {
  64. return excuteSql("select * from ApprovalTravel where Isdel=0");
  65. }
  66. /// <summary>
  67. /// 增加
  68. /// </summary>
  69. /// <param name="cd"></param>
  70. /// <returns></returns>
  71. public bool AddApprovalTravel(ApprovalTravel hd)
  72. {
  73. string sql = "insert into ApprovalTravel values(@Diid,@Date,@Time,@Detail,@OPer,@OPdate,@Isdel)";
  74. SqlParameter[] parameter = new SqlParameter[]{
  75. new SqlParameter("@Diid",hd.Diid),
  76. new SqlParameter("@Date",hd.Date),
  77. new SqlParameter("@Time",hd.Time),
  78. new SqlParameter("@Detail",hd.Detail),
  79. new SqlParameter("@OPer",hd.OPer),
  80. new SqlParameter("@OPdate",hd.OPdate),
  81. new SqlParameter("@Isdel",hd.Isdel)
  82. };
  83. if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0)
  84. return true;
  85. return false;
  86. }
  87. public bool AddApprovalTravelReturnID(ApprovalTravel hd, out int id)
  88. {
  89. string sql = "insert into ApprovalTravel values(@Diid,@Date,@Time,@Detail,@OPer,@OPdate,@Isdel);SELECT @@IDENTITY ";
  90. SqlParameter[] parameter = new SqlParameter[]{
  91. new SqlParameter("@Diid",hd.Diid),
  92. new SqlParameter("@Date",hd.Date),
  93. new SqlParameter("@Time",hd.Time),
  94. new SqlParameter("@Detail",hd.Detail),
  95. new SqlParameter("@OPer",hd.OPer),
  96. new SqlParameter("@OPdate",hd.OPdate),
  97. new SqlParameter("@Isdel",hd.Isdel)
  98. };
  99. int obj = Convert.ToInt32(SqlHelper.ExecuteScalar(sql, CommandType.Text, parameter));
  100. if (obj > 0)
  101. {
  102. id = obj;
  103. return true;
  104. }
  105. else
  106. {
  107. id = 0;
  108. return false;
  109. }
  110. }
  111. /// <summary>
  112. /// 编辑
  113. /// </summary>
  114. /// <param name="sdt"></param>
  115. /// <returns></returns>
  116. public bool EditApprovalTravel(ApprovalTravel hd)
  117. {
  118. string sql = "update ApprovalTravel set Diid=@Diid,Date = @Date,Time = @Time,Detail=@Detail,OPer = @OPer,OPdate = @OPdate,Isdel = @Isdel where Id = @Id";
  119. SqlParameter[] parameter = new SqlParameter[]{
  120. new SqlParameter("@Diid",hd.Diid),
  121. new SqlParameter("@Date",hd.Date),
  122. new SqlParameter("@Time",hd.Time),
  123. new SqlParameter("@Detail",hd.Detail),
  124. new SqlParameter("@OPer",hd.OPer),
  125. new SqlParameter("@OPdate",hd.OPdate),
  126. new SqlParameter("@Isdel",hd.Isdel),
  127. new SqlParameter("@Id",hd.Id)
  128. };
  129. if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0)
  130. return true;
  131. return false;
  132. }
  133. /// <summary>
  134. /// 删除
  135. /// </summary>s
  136. /// <returns></returns>
  137. public bool DelApprovalTravel(int id)
  138. {
  139. if (SqlHelper.ExecuteNonQuery("delete ApprovalTravel where Id = @Id", CommandType.Text, new SqlParameter("@Id", id)) > 0)
  140. return true;
  141. return false;
  142. }
  143. /// <summary>
  144. /// 删除范围
  145. /// </summary>
  146. /// <param name="Diid"></param>
  147. /// <param name="start"></param>
  148. /// <param name="end"></param>
  149. /// <returns></returns>
  150. public bool DelOld(int Diid, int start, int end)
  151. {
  152. if (SqlHelper.ExecuteNonQuery("delete from ApprovalTravel where Diid=" + Diid + " and ( Id>=" + start + " and Id<=" + end + ")", CommandType.Text) > 0)
  153. return true;
  154. return false;
  155. }
  156. /// <summary>
  157. /// 20210901
  158. /// 根据团号diid 执行更新ISDEL=1的删除操作
  159. /// </summary>
  160. /// <param name="diid"></param>
  161. /// <returns></returns>
  162. public bool DelByDiid(int diid)
  163. {
  164. if (SqlHelper.ExecuteNonQuery("update ApprovalTravel set Isdel=1 where Diid=" + diid, CommandType.Text) > 0)
  165. return true;
  166. return false;
  167. }
  168. }
  169. }