CarGuidesServcies.cs 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Data.SqlClient;
  5. using System.Linq;
  6. using System.Text;
  7. using Models;
  8. namespace DAL
  9. {
  10. /// <summary>
  11. /// 车兼导数据访问层
  12. /// </summary>
  13. public class CarGuidesServcies
  14. {
  15. List<CarGuides> excuteSql(string sql, params SqlParameter[] param)
  16. {
  17. return ServiceBase<CarGuides>.excuteSql(new CarGuides(), "CarGuides", sql, CommandType.Text, param);
  18. }
  19. CarGuides excuteType(string sql, params SqlParameter[] param)
  20. {
  21. //查询结果放入对象集合
  22. List<CarGuides> hdList = excuteSql(sql, param);
  23. //判断集合是否为空
  24. if (hdList == null || hdList.Count == 0)
  25. //返回null
  26. return null;
  27. //返回单个对象
  28. return hdList[0];
  29. }
  30. /// <summary>
  31. /// 增Add
  32. /// </summary>
  33. /// <param name="Dov"></param>
  34. /// <returns></returns>
  35. public bool Add(CarGuides cg)
  36. {
  37. string sql = "insert into AirGoods values(@Country,@City,@ServiceType,@CarType,@Offer,@CGCost,@RuningTime,@OvertimeFee,@CGOvertimeFee,@Currency,@Remark,@Oper,@OpDate,@Isdel);SELECT @@IDENTITY";
  38. SqlParameter[] parameter = new SqlParameter[]{
  39. new SqlParameter("@Country",cg.Country),
  40. new SqlParameter("@City",cg.City),
  41. new SqlParameter("@ServiceType",cg.ServiceType),
  42. new SqlParameter("@CarType",cg.CarType),
  43. new SqlParameter("@Offer",cg.Offer),
  44. new SqlParameter("@CGCost",cg.CGCost),
  45. new SqlParameter("@RuningTime",cg.RuningTime),
  46. new SqlParameter("@OvertimeFee",cg.OvertimeFee),
  47. new SqlParameter("@CGOvertimeFee",cg.CGOvertimeFee),
  48. new SqlParameter("@Currency",cg.Currency),
  49. new SqlParameter("@Remark",cg.Remark),
  50. new SqlParameter("@Oper",cg.Oper),
  51. new SqlParameter("@OpDate",cg.OpDate),
  52. new SqlParameter("@Isdel",cg.Isdel)
  53. };
  54. if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0)
  55. return true;
  56. return false;
  57. }
  58. /// <summary>
  59. /// 修改
  60. /// </summary>
  61. /// <param name="Dov"></param>
  62. /// <returns></returns>
  63. public bool Edit(CarGuides cg)
  64. {
  65. string sql = "update CarGuides set Country=@Country,City=@City,ServiceType=@ServiceType,Offer=@Offer,CGCost=@CGCost,RuningTime=@RuningTime,OvertimeFee=@OvertimeFee,"
  66. + "CGOvertimeFee=@CGOvertimeFee,Currency=@Currency,Remark=@Remark,Oper=@Oper,OpDate=@OpDate,Isdel=@Isdel where Id = @Id";
  67. SqlParameter[] parameter = new SqlParameter[]{
  68. new SqlParameter("@Country",cg.Country),
  69. new SqlParameter("@City",cg.City),
  70. new SqlParameter("@ServiceType",cg.ServiceType),
  71. new SqlParameter("@Offer",cg.Offer),
  72. new SqlParameter("@CGCost",cg.CGCost),
  73. new SqlParameter("@RuningTime",cg.RuningTime),
  74. new SqlParameter("@OvertimeFee",cg.OvertimeFee),
  75. new SqlParameter("@CGOvertimeFee",cg.CGOvertimeFee),
  76. new SqlParameter("@Currency",cg.Currency),
  77. new SqlParameter("@Remark",cg.Remark),
  78. new SqlParameter("@Oper",cg.Oper),
  79. new SqlParameter("@OpDate",cg.OpDate),
  80. new SqlParameter("@Isdel",cg.Isdel),
  81. new SqlParameter("@Id",cg.Id),
  82. };
  83. if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0)
  84. return true;
  85. return false;
  86. }
  87. /// <summary>
  88. /// 删
  89. /// </summary>
  90. /// <param name="id"></param>
  91. /// <returns></returns>
  92. public bool delOA(int id)
  93. {
  94. if (SqlHelper.ExecuteNonQuery("update CarGuides set Isdel=1 where Id=@Id", CommandType.Text, new SqlParameter("@Id", id)) > 0)
  95. return true;
  96. return false;
  97. }
  98. /// <summary>
  99. /// 根据ID查询
  100. /// </summary>
  101. /// <param name="id"></param>
  102. /// <returns></returns>
  103. public CarGuides GetById(string id)
  104. {
  105. //调用获取单个对象的方法
  106. string sql = "select * from CarGuides where Id=@Id";
  107. SqlParameter[] parameter = new SqlParameter[]{
  108. new SqlParameter("@Id", id)
  109. };
  110. return excuteType(sql, parameter);
  111. }
  112. /// <summary>
  113. /// 车兼导 查询
  114. /// </summary>
  115. /// <param name="City"> 城市</param>
  116. /// <param name="ServiceType"> 服务类型</param>
  117. /// <param name="CarType">车类型</param>
  118. /// <returns>sql</returns>
  119. public CarGuides GetByCarTypeAndCarCost(string City,string ServiceType, string CarType)
  120. {
  121. //调用获取单个对象的方法
  122. string sql = "select * from CarGuides where City=@City and ServiceType=@ServiceType and CarType like '%CarType=@carType%'";
  123. SqlParameter[] parameter = new SqlParameter[]{
  124. new SqlParameter("@City", City),
  125. new SqlParameter("@ServiceType", ServiceType),
  126. new SqlParameter("@CarType", CarType)
  127. };
  128. return excuteType(sql, parameter);
  129. }
  130. /// <summary>
  131. /// 获取全部 - 分页
  132. /// </summary>
  133. /// <returns></returns>
  134. public List<CarGuides> GetALL(int pageIndex, out int sumPage, out int totalRecord, string City)
  135. {
  136. string sqlwhere = "IsDel = 0";
  137. if (!string.IsNullOrEmpty(City))
  138. sqlwhere += " and City like '%" + City + "%'";
  139. return PageBase<CarGuides>.excutePageSql(new CarGuides(), "CarGuides", "CarGuides", "*", "id asc", sqlwhere, 10, pageIndex, out sumPage, out totalRecord);
  140. }
  141. /// <summary>
  142. /// 获取全部 - 分页
  143. /// </summary>
  144. /// <returns></returns>
  145. public List<CarGuides> GetALL(int pageIndex, out int sumPage, out int totalRecord, string City, string Countrys)
  146. {
  147. string sqlwhere = "IsDel = 0";
  148. if (!string.IsNullOrEmpty(Countrys))
  149. {
  150. if (Countrys.Contains("中国"))
  151. {
  152. if (Countrys == "中国")
  153. {
  154. sqlwhere += " and Country like '%" + City + "%'";
  155. }
  156. else
  157. {
  158. sqlwhere += " and City like '%" + City + "%'";
  159. }
  160. }
  161. else
  162. {
  163. string country1 = "";
  164. string[] country = new string[] { };
  165. if (Countrys.Contains(","))
  166. country = Countrys.Split(',');
  167. else if (Countrys.Contains("、"))
  168. country = Countrys.Split('、');
  169. else if (Countrys.Contains(","))
  170. country = Countrys.Split(',');
  171. else if (Countrys.Contains(" "))
  172. country = Countrys.Split(' ');
  173. if (country.Length >= 1)
  174. {
  175. for (int i = 0; i < country.Length; i++)
  176. {
  177. if (i == country.Length - 1)
  178. country1 += " '" + country[i] + "'";
  179. else
  180. country1 += " '" + country[i] + "',";
  181. }
  182. sqlwhere += " and Country in (" + country1 + ")";
  183. }
  184. else
  185. sqlwhere += " and Country like '%" + Countrys + "%'";
  186. }
  187. }
  188. else
  189. {
  190. sqlwhere += " and City like '%" + City + "%'";
  191. }
  192. return PageBase<CarGuides>.excutePageSql(new CarGuides(), "CarGuides", "CarGuides", "*", "id asc", sqlwhere, 10, pageIndex, out sumPage, out totalRecord);
  193. }
  194. }
  195. }