HotelDataService.cs 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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. using System.Text.RegularExpressions;
  9. namespace DAL
  10. {
  11. /// <summary>
  12. /// 酒店资料数据访问类
  13. /// </summary>
  14. public class HotelDataService
  15. {
  16. /// <summary>
  17. /// 查询所有
  18. /// </summary>
  19. /// <param name="sql">sql语句</param>
  20. /// <param name="param">可变参数数组</param>
  21. /// <returns>返回集合</returns>
  22. List<HotelData> excuteSql(string sql, params SqlParameter[] param)
  23. {
  24. return ServiceBase<HotelData>.excuteSql(new HotelData(), "HotelData", sql, CommandType.Text, param);
  25. }
  26. /// <summary>
  27. /// 获取单个对象
  28. /// </summary>
  29. /// <param name="sql">sql语句</param>
  30. /// <param name="param">可变参数数组</param>
  31. /// <returns>返回空或者单个对象</returns>
  32. HotelData excuteType(string sql, params SqlParameter[] param)
  33. {
  34. //查询结果放入对象集合
  35. List<HotelData> hdList = excuteSql(sql, param);
  36. //判断集合是否为空
  37. if (hdList == null || hdList.Count == 0)
  38. //返回null
  39. return null;
  40. //返回单个对象
  41. return hdList[0];
  42. }
  43. /// <summary>
  44. /// 根据编号查询对象信息
  45. /// </summary>
  46. /// <param name="id">对象编号</param>
  47. /// <returns>返回空或者单个对象信息</returns>
  48. public HotelData GetHotelDataByID(int id)
  49. {
  50. //调用获取单个对象的方法
  51. return excuteType("select * from HotelData where Id = @id and IsDel = 0", new SqlParameter("@id", id));
  52. }
  53. /// <summary>
  54. /// 查询对象信息
  55. /// </summary>
  56. /// <param name="city">所在城市</param>
  57. /// <param name="name">酒店名称</param>
  58. /// <returns>返回空或者单个对象信息</returns>
  59. public HotelData GetHotelData(string city, string name)
  60. {
  61. //调用获取单个对象的方法
  62. return excuteType("select * from HotelData where City = @City and Name = @Name and IsDel = 0", new SqlParameter("@City", city), new SqlParameter("@Name", name));
  63. }
  64. /// <summary>
  65. /// 雷怡 2021-08-09 14:59
  66. /// 查询对象信息
  67. /// </summary>
  68. /// <param name="city">所在城市</param>
  69. /// <returns>返回空或者单个对象信息</returns>
  70. public List<HotelData> GetHotelDatas(string city)
  71. {
  72. string sql = "select * from HotelData where City like '%"+ city + "%' and IsDel = 0";
  73. return excuteSql(sql);
  74. }
  75. /// <summary>
  76. /// 雷怡 2021-08-09 14:59
  77. /// 查询对象信息
  78. /// </summary>
  79. /// <param name="city">所在城市</param>
  80. /// <returns>返回空或者单个对象信息</returns>
  81. public List<HotelData> GetHotelDatas(string city,string hotelName)
  82. {
  83. string sql = "select * from HotelData where City like '%" + city + "%' and Name like '%" + hotelName + "%' and IsDel = 0";
  84. return excuteSql(sql);
  85. }
  86. /// <summary>
  87. /// 查询对象信息
  88. /// </summary>
  89. /// <param name="name">酒店名称</param>
  90. /// <returns>返回空或者单个对象信息</returns>
  91. public HotelData GetHotelDataByName(string name)
  92. {
  93. //调用获取单个对象的方法
  94. return excuteType("select * from HotelData where Name = @Name and IsDel = 0", new SqlParameter("@Name", name));
  95. }
  96. /// <summary>
  97. /// 查询信息
  98. /// </summary>
  99. /// <returns>返回空或者对象信息</returns>
  100. public List<HotelData> GetHotelDataName(string name)
  101. {
  102. //调用获取单个对象的方法
  103. return excuteSql("select * from HotelData where Name like '%" + name + "%'");
  104. }
  105. /// <summary>
  106. /// 查询信息
  107. /// </summary>
  108. /// <returns>返回空或者单个对象信息</returns>
  109. public List<HotelData> GetHotelDataCity(string city)
  110. {
  111. //调用获取单个对象的方法
  112. return excuteSql("select * from HotelData where City like '%" + city + "%'");
  113. }
  114. /// <summary>
  115. /// 获取全部 - 分页
  116. /// 雷怡 2021-08-04 14:38
  117. /// 增加过河城市查询条件
  118. /// </summary>
  119. /// <returns></returns>
  120. public List<HotelData> GetHotelData(int pageIndex, out int sumPage, out int totalRecord, string city, string name, string tel, string level)
  121. {
  122. string sqlwhere = "IsDel = 0 and Name like '%" + name + "%' ";
  123. if (city.Contains(','))
  124. {
  125. city = city.Replace(',', ' ');
  126. }
  127. else if (city.Contains(','))
  128. {
  129. city = city.Replace(',', ' ');
  130. }
  131. else if (city.Contains('、'))
  132. {
  133. city = city.Replace('、', ' ');
  134. }
  135. if (city.Contains(" "))
  136. {
  137. string sqlCity = " and (";
  138. string[] sqlName = city.Split(' ');
  139. for (int i = 0,len = sqlName.Length; i < len; i++)
  140. {
  141. if (sqlName[i] != "")
  142. {
  143. if (i == len - 1)
  144. {
  145. sqlCity += " City like '%" + sqlName[i] + "%') ";
  146. }
  147. else
  148. {
  149. sqlCity += " City like '%" + sqlName[i] + "%' or";
  150. }
  151. }
  152. }
  153. sqlwhere += sqlCity;
  154. }
  155. else
  156. {
  157. sqlwhere += " and City like '%" + city + "%'";
  158. }
  159. sqlwhere += " and Tel like '%" + tel + "%'";
  160. if (!string.IsNullOrEmpty(level))
  161. sqlwhere += " and Level = '" + level + "'";
  162. return PageBase<HotelData>.excutePageSql(new HotelData(), "HotelData", "HotelData", "*", "id desc", sqlwhere, 10, pageIndex, out sumPage, out totalRecord);
  163. }
  164. /// <summary>
  165. /// 增加
  166. /// </summary>
  167. /// <param name="cd"></param>
  168. /// <returns></returns>
  169. public bool AddHotelData(HotelData hd)
  170. {
  171. string sql = "insert into HotelData values(@City,@Name,@Level,@Address,@Tel,@Fax,@Contact,@ContactPhone,@OtherInformation,@Operator,@OperatorDate,@IsDel)";
  172. SqlParameter[] parameter = new SqlParameter[]{
  173. new SqlParameter("@City",hd.City),
  174. new SqlParameter("@Name",hd.Name),
  175. new SqlParameter("@Level",hd.Level),
  176. new SqlParameter("@Address",hd.Address),
  177. new SqlParameter("@Tel",hd.Tel),
  178. new SqlParameter("@Fax",hd.Fax),
  179. new SqlParameter("@Contact",hd.Contact),
  180. new SqlParameter("@ContactPhone",hd.ContactPhone),
  181. new SqlParameter("@OtherInformation",hd.OtherInformation),
  182. new SqlParameter("@Operator",hd.Operators),
  183. new SqlParameter("@OperatorDate",hd.OperatorsDate),
  184. new SqlParameter("@IsDel",hd.IsDel)
  185. };
  186. if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0)
  187. return true;
  188. return false;
  189. }
  190. /// <summary>
  191. /// 编辑
  192. /// </summary>
  193. /// <param name="sdt"></param>
  194. /// <returns></returns>
  195. public bool EditClientData(HotelData hd)
  196. {
  197. string sql = "update HotelData set City = @City,Name = @Name,Level = @Level,Address = @Address,Tel = @Tel,Fax = @Fax,Contact=@Contact,ContactPhone=@ContactPhone,OtherInformation = @OtherInformation,Operator = @Operator,OperatorDate = @OperatorDate where Id = @Id";
  198. SqlParameter[] parameter = new SqlParameter[]{
  199. new SqlParameter("@City",hd.City),
  200. new SqlParameter("@Name",hd.Name),
  201. new SqlParameter("@Level",hd.Level),
  202. new SqlParameter("@Address",hd.Address),
  203. new SqlParameter("@Tel",hd.Tel),
  204. new SqlParameter("@Fax",hd.Fax),
  205. new SqlParameter("@Contact",hd.Contact),
  206. new SqlParameter("@ContactPhone",hd.ContactPhone),
  207. new SqlParameter("@OtherInformation",hd.OtherInformation),
  208. new SqlParameter("@Operator",hd.Operators),
  209. new SqlParameter("@OperatorDate",hd.OperatorsDate),
  210. new SqlParameter("@Id",hd.Id)
  211. };
  212. if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0)
  213. return true;
  214. return false;
  215. }
  216. /// <summary>
  217. /// 删除
  218. /// </summary>
  219. /// <param name="id"></param>
  220. /// <returns></returns>
  221. public bool DelHotelData(int id)
  222. {
  223. if (SqlHelper.ExecuteNonQuery("update HotelData set IsDel = 1 where Id = @Id", CommandType.Text, new SqlParameter("@Id", id)) > 0)
  224. return true;
  225. return false;
  226. }
  227. /// <summary>
  228. /// 查询所有
  229. /// </summary>
  230. /// <returns></returns>
  231. public List<HotelData> GetAll()
  232. {
  233. return excuteSql("select * from HotelData where IsDel=0", null);
  234. }
  235. }
  236. }