ViewCarDataAndGuideService.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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 ViewCarDataAndGuideService
  11. {
  12. /// <summary>
  13. /// 查询所有
  14. /// </summary>
  15. /// <param name="sql">sql语句</param>
  16. /// <param name="param">可变参数数组</param>
  17. /// <returns>返回集合</returns>
  18. List<ViewCarDataAndGuide> excuteSql(string sql, params SqlParameter[] param)
  19. {
  20. return ServiceBase<ViewCarDataAndGuide>.excuteSql(new ViewCarDataAndGuide(), "ViewCarDataAndGuide", 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. ViewCarDataAndGuide excuteType(string sql, params SqlParameter[] param)
  29. {
  30. //查询结果放入对象集合
  31. List<ViewCarDataAndGuide> cList = excuteSql(sql, param);
  32. //判断集合是否为空
  33. if (cList == null || cList.Count == 0)
  34. //返回null
  35. return null;
  36. //返回单个对象
  37. return cList[0];
  38. }
  39. /// <summary>
  40. /// 查询信息
  41. ///--TouristGuideGroundData导游地接表 comanyorguide=2
  42. /// </summary>
  43. /// <returns>返回空或者单个对象信息</returns>
  44. public List<ViewCarDataAndGuide> getBy(string unitArea, string unitName, string contact, string tel)
  45. {
  46. string sqlWhere = "";
  47. if (unitArea != "")
  48. {
  49. if (unitArea.Contains(','))
  50. unitArea = unitArea.Replace(',', ' ');
  51. else if (unitArea.Contains(','))
  52. unitArea = unitArea.Replace(',', ' ');
  53. else if (unitArea.Contains('、'))
  54. unitArea = unitArea.Replace('、', ' ');
  55. if (unitArea.Contains(" "))
  56. {
  57. string sqlCity = " and (";
  58. string[] sqlName = unitArea.Split(' ');
  59. for (int i = 0, len = sqlName.Length; i < len; i++)
  60. {
  61. if (sqlName[i] != "")
  62. {
  63. if (i == len - 1)
  64. sqlCity += " UnitArea like '%" + sqlName[i] + "%') ";
  65. else
  66. sqlCity += " UnitArea like '%" + sqlName[i] + "%' or";
  67. }
  68. }
  69. sqlWhere += sqlCity;
  70. }
  71. else
  72. {
  73. sqlWhere += " and UnitArea like '%" + unitArea + "%'";
  74. }
  75. }
  76. if (unitName != "")
  77. sqlWhere += " and UnitName like '%" + unitName + "%'";
  78. if (contact != "")
  79. sqlWhere += " and Contact like '%" + contact + "%'";
  80. if (tel != "")
  81. sqlWhere += " and Tel like '%" + tel + "%'";
  82. else
  83. sqlWhere += "";
  84. //调用获取单个对象的方法
  85. return excuteSql("select a.id,a.UnitArea,a.UnitName,a.Contact,a.Tel,a.Score,a.OperatorDate,b.Price,b.Currency from TouristGuideGroundData a join CarCompanyAndTouristGuide b on a.Id = b.CGID where a.IsDel = 0 " + sqlWhere + " order by a.OperatorDate desc");
  86. }
  87. /// <summary>
  88. /// 查询车公司
  89. /// --CarData车公司表 comanyorguide=1
  90. /// </summary>
  91. /// <returns>返回空或者单个对象信息</returns>
  92. public List<ViewCarDataAndGuide> getByCarType(string unitArea, string unitName, string contact, string tel,string cartype)
  93. {
  94. string sqlWhere = "";
  95. if (unitArea != "")
  96. sqlWhere += " and UnitArea like '%" + unitArea + "%'";
  97. if (unitName != "")
  98. sqlWhere += " and UnitName like '%" + unitName + "%'";
  99. if (contact != "")
  100. sqlWhere += " and Contact like '%" + contact + "%'";
  101. if (tel != "")
  102. sqlWhere += " and Tel like '%" + tel + "%'";
  103. if (cartype != "")
  104. sqlWhere += " and CarType like '%" + tel + "%'";
  105. else
  106. sqlWhere += "";
  107. //调用获取单个对象的方法
  108. return excuteSql("select a.id,a.UnitArea,a.UnitName,a.Contact,a.Tel,a.Score,a.OperatorDate,b.Price,b.Currency from CarData a join CarCompanyAndTouristGuide b on a.Id = b.CGID where a.IsDel = 0 " + sqlWhere + " order by a.OperatorDate desc");
  109. }
  110. }
  111. }