CarDataService.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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 CarDataService
  14. {
  15. /// <summary>
  16. /// 查询所有
  17. /// </summary>
  18. /// <param name="sql">sql语句</param>
  19. /// <param name="param">可变参数数组</param>
  20. /// <returns>返回集合</returns>
  21. List<CarData> excuteSql(string sql, params SqlParameter[] param)
  22. {
  23. return ServiceBase<CarData>.excuteSql(new CarData(), "CarData", 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. CarData excuteType(string sql, params SqlParameter[] param)
  32. {
  33. //查询结果放入对象集合
  34. List<CarData> ctggdList = excuteSql(sql, param);
  35. //判断集合是否为空
  36. if (ctggdList == null || ctggdList.Count == 0)
  37. //返回null
  38. return null;
  39. //返回单个对象
  40. return ctggdList[0];
  41. }
  42. /// <summary>
  43. /// 根据编号查询对象信息
  44. /// </summary>
  45. /// <param name="id">对象编号</param>
  46. /// <returns>返回空或者单个对象信息</returns>
  47. public CarData GetCarDataByID(int id)
  48. {
  49. //调用获取单个对象的方法
  50. return excuteType("select * from CarData where Id = @id and IsDel = 0", new SqlParameter("@id", id));
  51. }
  52. /// <summary>
  53. /// 获取全部
  54. /// </summary>
  55. /// <returns></returns>
  56. public List<CarData> GetAll()
  57. {
  58. return excuteSql("select * from CarData where IsDel = 0 order by id");
  59. }
  60. /// <summary>
  61. /// 查询信息
  62. /// </summary>
  63. /// <returns>返回空或者单个对象信息</returns>
  64. public List<CarData> GetCarDataUnitArea(string unitArea)
  65. {
  66. //调用获取单个对象的方法
  67. return excuteSql("select * from CarData where UnitArea like '%" + unitArea + "%'");
  68. }
  69. /// <summary>
  70. /// 查询对象信息
  71. /// </summary>
  72. /// <param name="city">所在城市</param>
  73. /// <param name="name">酒店名称</param>
  74. /// <returns>返回空或者单个对象信息</returns>
  75. public CarData GetCarData(string unitArea, string unitName)
  76. {
  77. //调用获取单个对象的方法
  78. return excuteType("select * from CarData where UnitArea = @UnitArea and UnitName = @UnitName and IsDel = 0", new SqlParameter("@UnitArea", unitArea), new SqlParameter("@UnitName", unitName));
  79. }
  80. /// <summary>
  81. /// 查询对象信息
  82. /// </summary>
  83. /// <param name="city">所在城市</param>
  84. /// <param name="name">酒店名称</param>
  85. /// <returns>返回空或者单个对象信息</returns>
  86. public CarData GetCarDataByUnitNameAndTel(string unitName, string tel)
  87. {
  88. //调用获取单个对象的方法
  89. return excuteType("select * from CarData where UnitName = @UnitName and Tel = @Tel and IsDel = 0", new SqlParameter("@UnitName", unitName), new SqlParameter("@Tel", tel));
  90. }
  91. /// <summary>
  92. /// 获取全部 - 分页
  93. /// </summary>
  94. /// <returns></returns>
  95. public List<CarData> GetCarData(int pageIndex, out int sumPage, out int totalRecord, string unitArea, string unitName, string contact, string tel)
  96. {
  97. string sqlwhere = "IsDel = 0 and UnitArea like '%" + unitArea + "%' and UnitName like '%" + unitName + "%' and Contact like '%" + contact + "%' and Tel like '%" + tel + "%'";
  98. return PageBase<CarData>.excutePageSql(new CarData(), "CarData", "CarData", "*", "id desc", sqlwhere, 20, pageIndex, out sumPage, out totalRecord);
  99. }
  100. /// <summary>
  101. /// 增加
  102. /// </summary>
  103. /// <param name="cd"></param>
  104. /// <returns></returns>
  105. public bool AddCarData(CarData ctggd)
  106. {
  107. string sql = "insert into CarData values(@UnitArea,@UnitName,@Address,@Contact,@Tel,@Email,@Fax,@CarDes,@CarAge,"
  108. + "@CarPicName,@CarPicPath,@OtherInformation,@CompanyOrGuide,@Score,@QualificationScore,@CarAgeScore,@CleanImgScore,"
  109. + "@SmellScore,@WaterPaperScore,@HardwareScore,@TimeScore,@SafetyScore,@DrivingAgeScore,@Operator,@OperatorDate,@IsDel)";
  110. SqlParameter[] parameter = new SqlParameter[]{
  111. new SqlParameter("@UnitArea",ctggd.UnitArea),
  112. new SqlParameter("@UnitName",ctggd.UnitName),
  113. new SqlParameter("@Address",ctggd.Address),
  114. new SqlParameter("@Contact",ctggd.Contact),
  115. new SqlParameter("@Tel",ctggd.Tel),
  116. new SqlParameter("@Email",ctggd.Email),
  117. new SqlParameter("@Fax",ctggd.Fax),
  118. new SqlParameter("@CarDes",ctggd.CarDes),
  119. new SqlParameter("@CarAge",ctggd.CarAge),
  120. new SqlParameter("@CarPicName",ctggd.CarPicName),
  121. new SqlParameter("@CarPicPath",ctggd.CarPicPath),
  122. new SqlParameter("@OtherInformation",ctggd.OtherInformation),
  123. new SqlParameter("@CompanyOrGuide",ctggd.CompanyOrGuide),
  124. new SqlParameter("@Score",ctggd.Score),
  125. new SqlParameter("@QualificationScore",ctggd.QualificationScore),
  126. new SqlParameter("@CarAgeScore",ctggd.CarAgeScore),
  127. new SqlParameter("@CleanImgScore",ctggd.CleanImgScore),
  128. new SqlParameter("@SmellScore",ctggd.SmellScore),
  129. new SqlParameter("@WaterPaperScore",ctggd.WaterPaperScore),
  130. new SqlParameter("@HardwareScore",ctggd.HardwareScore),
  131. new SqlParameter("@TimeScore",ctggd.TimeScore),
  132. new SqlParameter("@SafetyScore",ctggd.SafetyScore),
  133. new SqlParameter("@DrivingAgeScore",ctggd.DrivingAgeScore),
  134. new SqlParameter("@Operator",ctggd.Score),
  135. new SqlParameter("@OperatorDate",ctggd.OperatorsDate),
  136. new SqlParameter("@IsDel",ctggd.IsDel)
  137. };
  138. if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0)
  139. return true;
  140. return false;
  141. }
  142. /// <summary>
  143. /// 增加 返回id
  144. /// </summary>
  145. /// <param name="cd"></param>
  146. /// <returns></returns>
  147. public bool AddCarDataReturnId(CarData ctggd, out int id)
  148. {
  149. string sql = "insert into CarData values(@UnitArea,@UnitName,@Address,@Contact,@Tel,@Email,@Fax,@CarDes,@CarAge,"
  150. + "@CarPicName,@CarPicPath,@OtherInformation,@CompanyOrGuide,@Score,@QualificationScore,@CarAgeScore,@CleanImgScore,"
  151. + "@SmellScore,@WaterPaperScore,@HardwareScore,@TimeScore,@SafetyScore,@DrivingAgeScore,@Operator,@OperatorDate,@IsDel);SELECT @@IDENTITY";
  152. SqlParameter[] parameter = new SqlParameter[]{
  153. new SqlParameter("@UnitArea",ctggd.UnitArea),
  154. new SqlParameter("@UnitName",ctggd.UnitName),
  155. new SqlParameter("@Address",ctggd.Address),
  156. new SqlParameter("@Contact",ctggd.Contact),
  157. new SqlParameter("@Tel",ctggd.Tel),
  158. new SqlParameter("@Email",ctggd.Email),
  159. new SqlParameter("@Fax",ctggd.Fax),
  160. new SqlParameter("@CarDes",ctggd.CarDes),
  161. new SqlParameter("@CarAge",ctggd.CarAge),
  162. new SqlParameter("@CarPicName",ctggd.CarPicName),
  163. new SqlParameter("@CarPicPath",ctggd.CarPicPath),
  164. new SqlParameter("@OtherInformation",ctggd.OtherInformation),
  165. new SqlParameter("@CompanyOrGuide",ctggd.CompanyOrGuide),
  166. new SqlParameter("@Score",ctggd.Score),
  167. new SqlParameter("@QualificationScore",ctggd.QualificationScore),
  168. new SqlParameter("@CarAgeScore",ctggd.CarAgeScore),
  169. new SqlParameter("@CleanImgScore",ctggd.CleanImgScore),
  170. new SqlParameter("@SmellScore",ctggd.SmellScore),
  171. new SqlParameter("@WaterPaperScore",ctggd.WaterPaperScore),
  172. new SqlParameter("@HardwareScore",ctggd.HardwareScore),
  173. new SqlParameter("@TimeScore",ctggd.TimeScore),
  174. new SqlParameter("@SafetyScore",ctggd.SafetyScore),
  175. new SqlParameter("@DrivingAgeScore",ctggd.DrivingAgeScore),
  176. new SqlParameter("@Operator",ctggd.Operators),
  177. new SqlParameter("@OperatorDate",ctggd.OperatorsDate),
  178. new SqlParameter("@IsDel",ctggd.IsDel)
  179. };
  180. int obj = Convert.ToInt32(SqlHelper.ExecuteScalar(sql, CommandType.Text, parameter));
  181. if (obj > 0)
  182. {
  183. id = obj;
  184. return true;
  185. }
  186. else
  187. {
  188. id = 0;
  189. return false;
  190. }
  191. //if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0)
  192. // return true;
  193. //return false;
  194. }
  195. /// <summary>
  196. /// 编辑
  197. /// </summary>
  198. /// <param name="sdt"></param>
  199. /// <returns></returns>
  200. public bool EditCarData(CarData ctggd)
  201. {
  202. string sql = "update CarData set UnitArea = @UnitArea,UnitName = @UnitName,Address = @Address,Contact = @Contact,Tel = @Tel,Email = @Email,Fax = @Fax,CarDes=@CarDes,CarAge=@CarAge,"
  203. + "CarPicName=@CarPicName,CarPicPath=@CarPicPath,OtherInformation = @OtherInformation,CompanyOrGuide = @CompanyOrGuide,Score = @Score,QualificationScore=@QualificationScore,CarAgeScore=@CarAgeScore,"
  204. + "CleanImgScore=@CleanImgScore,SmellScore=@SmellScore,WaterPaperScore=@WaterPaperScore,HardwareScore=@HardwareScore,TimeScore=@TimeScore,SafetyScore=@SafetyScore,DrivingAgeScore=@DrivingAgeScore,Operator = @Operator,OperatorDate = @OperatorDate where Id = @Id";
  205. SqlParameter[] parameter = new SqlParameter[]{
  206. new SqlParameter("@UnitArea",ctggd.UnitArea),
  207. new SqlParameter("@UnitName",ctggd.UnitName),
  208. new SqlParameter("@Address",ctggd.Address),
  209. new SqlParameter("@Contact",ctggd.Contact),
  210. new SqlParameter("@Tel",ctggd.Tel),
  211. new SqlParameter("@Email",ctggd.Email),
  212. new SqlParameter("@Fax",ctggd.Fax),
  213. new SqlParameter("@CarDes",ctggd.CarDes),
  214. new SqlParameter("@CarAge",ctggd.CarAge),
  215. new SqlParameter("@CarPicName",ctggd.CarPicName),
  216. new SqlParameter("@CarPicPath",ctggd.CarPicPath),
  217. new SqlParameter("@OtherInformation",ctggd.OtherInformation),
  218. new SqlParameter("@CompanyOrGuide",ctggd.CompanyOrGuide),
  219. new SqlParameter("@Score",ctggd.Score),
  220. new SqlParameter("@QualificationScore",ctggd.QualificationScore),
  221. new SqlParameter("@CarAgeScore",ctggd.CarAgeScore),
  222. new SqlParameter("@CleanImgScore",ctggd.CleanImgScore),
  223. new SqlParameter("@SmellScore",ctggd.SmellScore),
  224. new SqlParameter("@WaterPaperScore",ctggd.WaterPaperScore),
  225. new SqlParameter("@HardwareScore",ctggd.HardwareScore),
  226. new SqlParameter("@TimeScore",ctggd.TimeScore),
  227. new SqlParameter("@SafetyScore",ctggd.SafetyScore),
  228. new SqlParameter("@DrivingAgeScore",ctggd.DrivingAgeScore),
  229. new SqlParameter("@Operator",ctggd.Operators),
  230. new SqlParameter("@OperatorDate",ctggd.OperatorsDate),
  231. new SqlParameter("@Id",ctggd.Id)
  232. };
  233. if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0)
  234. return true;
  235. return false;
  236. }
  237. /// <summary>
  238. /// 删除
  239. /// </summary>
  240. /// <param name="id"></param>
  241. /// <returns></returns>
  242. public bool DelCarData(int id)
  243. {
  244. if (SqlHelper.ExecuteNonQuery("update CarData set IsDel = 1 where Id = @Id", CommandType.Text, new SqlParameter("@Id", id)) > 0)
  245. return true;
  246. return false;
  247. }
  248. }
  249. }