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 { /// /// 酒店资料数据访问类 /// public class HotelDataService { /// /// 查询所有 /// /// sql语句 /// 可变参数数组 /// 返回集合 List excuteSql(string sql, params SqlParameter[] param) { return ServiceBase.excuteSql(new HotelData(), "HotelData", sql, CommandType.Text, param); } /// /// 获取单个对象 /// /// sql语句 /// 可变参数数组 /// 返回空或者单个对象 HotelData excuteType(string sql, params SqlParameter[] param) { //查询结果放入对象集合 List hdList = excuteSql(sql, param); //判断集合是否为空 if (hdList == null || hdList.Count == 0) //返回null return null; //返回单个对象 return hdList[0]; } /// /// 根据编号查询对象信息 /// /// 对象编号 /// 返回空或者单个对象信息 public HotelData GetHotelDataByID(int id) { //调用获取单个对象的方法 return excuteType("select * from HotelData where Id = @id and IsDel = 0", new SqlParameter("@id", id)); } /// /// 查询对象信息 /// /// 所在城市 /// 酒店名称 /// 返回空或者单个对象信息 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)); } /// /// 雷怡 2021-08-09 14:59 /// 查询对象信息 /// /// 所在城市 /// 返回空或者单个对象信息 public List GetHotelDatas(string city) { string sql = "select * from HotelData where City like '%"+ city + "%' and IsDel = 0"; return excuteSql(sql); } /// /// 雷怡 2021-08-09 14:59 /// 查询对象信息 /// /// 所在城市 /// 返回空或者单个对象信息 public List GetHotelDatas(string city,string hotelName) { string sql = "select * from HotelData where City like '%" + city + "%' and Name like '%" + hotelName + "%' and IsDel = 0"; return excuteSql(sql); } /// /// 查询对象信息 /// /// 酒店名称 /// 返回空或者单个对象信息 public HotelData GetHotelDataByName(string name) { //调用获取单个对象的方法 return excuteType("select * from HotelData where Name = @Name and IsDel = 0", new SqlParameter("@Name", name)); } /// /// 查询信息 /// /// 返回空或者对象信息 public List GetHotelDataName(string name) { //调用获取单个对象的方法 return excuteSql("select * from HotelData where Name like '%" + name + "%'"); } /// /// 查询信息 /// /// 返回空或者单个对象信息 public List GetHotelDataCity(string city) { //调用获取单个对象的方法 return excuteSql("select * from HotelData where City like '%" + city + "%'"); } /// /// 获取全部 - 分页 /// 雷怡 2021-08-04 14:38 /// 增加过河城市查询条件 /// /// public List 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.excutePageSql(new HotelData(), "HotelData", "HotelData", "*", "id desc", sqlwhere, 10, pageIndex, out sumPage, out totalRecord); } /// /// 增加 /// /// /// 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; } /// /// 编辑 /// /// /// 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; } /// /// 删除 /// /// /// 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; } /// /// 查询所有 /// /// public List GetAll() { return excuteSql("select * from HotelData where IsDel=0", null); } } }