CarInfoService.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. public class CarInfoService
  11. {
  12. List<CarInfo> excuteSql(string sql, params SqlParameter[] param)
  13. {
  14. return ServiceBase<CarInfo>.excuteSql(new CarInfo(), "CarInfo", sql, CommandType.Text, param);
  15. }
  16. CarInfo excuteType(string sql, params SqlParameter[] param)
  17. {
  18. //查询结果放入对象集合
  19. List<CarInfo> hdList = excuteSql(sql, param);
  20. //判断集合是否为空
  21. if (hdList == null || hdList.Count == 0)
  22. //返回null
  23. return null;
  24. //返回单个对象
  25. return hdList[0];
  26. }
  27. /// <summary>
  28. /// 根据ID查询
  29. /// </summary>
  30. /// <param name="id"></param>
  31. /// <returns></returns>
  32. public CarInfo GetById(string id)
  33. {
  34. //调用获取单个对象的方法
  35. string sql = "select * from CarInfo where Id=@Id";
  36. SqlParameter[] parameter = new SqlParameter[]{
  37. new SqlParameter("@Id", id)
  38. };
  39. return excuteType(sql, parameter);
  40. }
  41. /// <summary>
  42. /// 获取全部 - 分页
  43. /// </summary>
  44. /// <returns></returns>
  45. public List<CarInfo> GetALL(int pageIndex, out int sumPage, out int totalRecord, string City)
  46. {
  47. string sqlwhere = "IsDel = 0";
  48. if (!string.IsNullOrEmpty(City))
  49. sqlwhere += " and City like '%" + City + "%'";
  50. return PageBase<CarInfo>.excutePageSql(new CarInfo(), "CarInfo", "CarInfo", "*", "City asc", sqlwhere, 10, pageIndex, out sumPage, out totalRecord);
  51. }
  52. /// <summary>
  53. /// 获取全部 - 分页
  54. /// </summary>
  55. /// <returns></returns>
  56. public List<CarInfo> GetALL(int pageIndex, out int sumPage, out int totalRecord, string City,string Countrys)
  57. {
  58. string sqlwhere = "IsDel = 0";
  59. if (!string.IsNullOrEmpty(Countrys))
  60. {
  61. if (Countrys.Contains("中国"))
  62. {
  63. if (Countrys == "中国")
  64. {
  65. sqlwhere += " and Country like '%" + City + "%'";
  66. }
  67. else
  68. {
  69. sqlwhere += " and City like '%" + City + "%'";
  70. }
  71. }
  72. else
  73. {
  74. string country1 = "";
  75. string[] country = new string[] { };
  76. if (Countrys.Contains(","))
  77. country = Countrys.Split(',');
  78. else if (Countrys.Contains("、"))
  79. country = Countrys.Split('、');
  80. else if (Countrys.Contains(","))
  81. country = Countrys.Split(',');
  82. else if (Countrys.Contains(" "))
  83. country = Countrys.Split(' ');
  84. if (country.Length >= 1)
  85. {
  86. for (int i = 0; i < country.Length; i++)
  87. {
  88. if (i == country.Length - 1)
  89. country1 += " '" + country[i] + "'";
  90. else
  91. country1 += " '" + country[i] + "',";
  92. }
  93. sqlwhere += " and Country in (" + country1 + ")";
  94. }
  95. else
  96. sqlwhere += " and Country like '%" + Countrys + "%'";
  97. }
  98. }
  99. else
  100. {
  101. sqlwhere += " and City like '%" + City + "%'";
  102. }
  103. return PageBase<CarInfo>.excutePageSql(new CarInfo(), "CarInfo", "CarInfo", "*", "City asc", sqlwhere, 10, pageIndex, out sumPage, out totalRecord);
  104. }
  105. }
  106. }