123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using Models;
- using System.Data.SqlClient;
- using System.Data;
- using System.Text.RegularExpressions;
- namespace DAL
- {
- /// <summary>
- /// 酒店资料数据访问类
- /// </summary>
- public class HotelDataService
- {
- /// <summary>
- /// 查询所有
- /// </summary>
- /// <param name="sql">sql语句</param>
- /// <param name="param">可变参数数组</param>
- /// <returns>返回集合</returns>
- List<HotelData> excuteSql(string sql, params SqlParameter[] param)
- {
- return ServiceBase<HotelData>.excuteSql(new HotelData(), "HotelData", sql, CommandType.Text, param);
- }
- /// <summary>
- /// 获取单个对象
- /// </summary>
- /// <param name="sql">sql语句</param>
- /// <param name="param">可变参数数组</param>
- /// <returns>返回空或者单个对象</returns>
- HotelData excuteType(string sql, params SqlParameter[] param)
- {
- //查询结果放入对象集合
- List<HotelData> hdList = excuteSql(sql, param);
- //判断集合是否为空
- if (hdList == null || hdList.Count == 0)
- //返回null
- return null;
- //返回单个对象
- return hdList[0];
- }
- /// <summary>
- /// 根据编号查询对象信息
- /// </summary>
- /// <param name="id">对象编号</param>
- /// <returns>返回空或者单个对象信息</returns>
- public HotelData GetHotelDataByID(int id)
- {
- //调用获取单个对象的方法
- return excuteType("select * from HotelData where Id = @id and IsDel = 0", new SqlParameter("@id", id));
- }
- /// <summary>
- /// 查询对象信息
- /// </summary>
- /// <param name="city">所在城市</param>
- /// <param name="name">酒店名称</param>
- /// <returns>返回空或者单个对象信息</returns>
- public HotelData GetHotelData(string city, string name)
- {
- //调用获取单个对象的方法
- return excuteType("select * from HotelData where City = @City and Name = @Name and IsDel = 0", new SqlParameter("@City", city), new SqlParameter("@Name", name));
- }
- /// <summary>
- /// 雷怡 2021-08-09 14:59
- /// 查询对象信息
- /// </summary>
- /// <param name="city">所在城市</param>
- /// <returns>返回空或者单个对象信息</returns>
- public List<HotelData> GetHotelDatas(string city)
- {
- string sql = "select * from HotelData where City like '%"+ city + "%' and IsDel = 0";
-
- return excuteSql(sql);
- }
- /// <summary>
- /// 雷怡 2021-08-09 14:59
- /// 查询对象信息
- /// </summary>
- /// <param name="city">所在城市</param>
- /// <returns>返回空或者单个对象信息</returns>
- public List<HotelData> GetHotelDatas(string city,string hotelName)
- {
- string sql = "select * from HotelData where City like '%" + city + "%' and Name like '%" + hotelName + "%' and IsDel = 0";
- return excuteSql(sql);
- }
- /// <summary>
- /// 查询对象信息
- /// </summary>
- /// <param name="name">酒店名称</param>
- /// <returns>返回空或者单个对象信息</returns>
- public HotelData GetHotelDataByName(string name)
- {
- //调用获取单个对象的方法
- return excuteType("select * from HotelData where Name = @Name and IsDel = 0", new SqlParameter("@Name", name));
- }
- /// <summary>
- /// 查询信息
- /// </summary>
- /// <returns>返回空或者对象信息</returns>
- public List<HotelData> GetHotelDataName(string name)
- {
- //调用获取单个对象的方法
- return excuteSql("select * from HotelData where Name like '%" + name + "%'");
- }
- /// <summary>
- /// 查询信息
- /// </summary>
- /// <returns>返回空或者单个对象信息</returns>
- public List<HotelData> GetHotelDataCity(string city)
- {
- //调用获取单个对象的方法
- return excuteSql("select * from HotelData where City like '%" + city + "%'");
- }
- /// <summary>
- /// 获取全部 - 分页
- /// 雷怡 2021-08-04 14:38
- /// 增加过河城市查询条件
- /// </summary>
- /// <returns></returns>
- public List<HotelData> GetHotelData(int pageIndex, out int sumPage, out int totalRecord, string city, string name, string tel, string level)
- {
- string sqlwhere = "IsDel = 0 and Name like '%" + name + "%' ";
- if (city.Contains(','))
- {
- city = city.Replace(',', ' ');
- }
- else if (city.Contains(','))
- {
- city = city.Replace(',', ' ');
- }
- else if (city.Contains('、'))
- {
- city = city.Replace('、', ' ');
- }
- if (city.Contains(" "))
- {
- string sqlCity = " and (";
- string[] sqlName = city.Split(' ');
- for (int i = 0,len = sqlName.Length; i < len; i++)
- {
- if (sqlName[i] != "")
- {
- if (i == len - 1)
- {
- sqlCity += " City like '%" + sqlName[i] + "%') ";
- }
- else
- {
- sqlCity += " City like '%" + sqlName[i] + "%' or";
- }
- }
-
- }
- sqlwhere += sqlCity;
- }
- else
- {
- sqlwhere += " and City like '%" + city + "%'";
- }
- sqlwhere += " and Tel like '%" + tel + "%'";
- if (!string.IsNullOrEmpty(level))
- sqlwhere += " and Level = '" + level + "'";
- return PageBase<HotelData>.excutePageSql(new HotelData(), "HotelData", "HotelData", "*", "id desc", sqlwhere, 10, pageIndex, out sumPage, out totalRecord);
- }
- /// <summary>
- /// 增加
- /// </summary>
- /// <param name="cd"></param>
- /// <returns></returns>
- public bool AddHotelData(HotelData hd)
- {
- string sql = "insert into HotelData values(@City,@Name,@Level,@Address,@Tel,@Fax,@Contact,@ContactPhone,@OtherInformation,@Operator,@OperatorDate,@IsDel)";
- SqlParameter[] parameter = new SqlParameter[]{
- new SqlParameter("@City",hd.City),
- new SqlParameter("@Name",hd.Name),
- new SqlParameter("@Level",hd.Level),
- new SqlParameter("@Address",hd.Address),
- new SqlParameter("@Tel",hd.Tel),
- new SqlParameter("@Fax",hd.Fax),
- new SqlParameter("@Contact",hd.Contact),
- new SqlParameter("@ContactPhone",hd.ContactPhone),
- new SqlParameter("@OtherInformation",hd.OtherInformation),
- new SqlParameter("@Operator",hd.Operators),
- new SqlParameter("@OperatorDate",hd.OperatorsDate),
- new SqlParameter("@IsDel",hd.IsDel)
- };
- if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0)
- return true;
- return false;
- }
- /// <summary>
- /// 编辑
- /// </summary>
- /// <param name="sdt"></param>
- /// <returns></returns>
- public bool EditClientData(HotelData hd)
- {
- 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";
- SqlParameter[] parameter = new SqlParameter[]{
- new SqlParameter("@City",hd.City),
- new SqlParameter("@Name",hd.Name),
- new SqlParameter("@Level",hd.Level),
- new SqlParameter("@Address",hd.Address),
- new SqlParameter("@Tel",hd.Tel),
- new SqlParameter("@Fax",hd.Fax),
- new SqlParameter("@Contact",hd.Contact),
- new SqlParameter("@ContactPhone",hd.ContactPhone),
- new SqlParameter("@OtherInformation",hd.OtherInformation),
- new SqlParameter("@Operator",hd.Operators),
- new SqlParameter("@OperatorDate",hd.OperatorsDate),
- new SqlParameter("@Id",hd.Id)
- };
- if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0)
- return true;
- return false;
- }
- /// <summary>
- /// 删除
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- public bool DelHotelData(int id)
- {
- if (SqlHelper.ExecuteNonQuery("update HotelData set IsDel = 1 where Id = @Id", CommandType.Text, new SqlParameter("@Id", id)) > 0)
- return true;
- return false;
- }
- /// <summary>
- /// 查询所有
- /// </summary>
- /// <returns></returns>
- public List<HotelData> GetAll()
- {
- return excuteSql("select * from HotelData where IsDel=0", null);
- }
- }
- }
|