using Models; using System; using System.Collections.Generic; using System.Data.SqlClient; using System.Data; using System.Linq; using System.Text; using System.Threading.Tasks; namespace DAL { public class hotelidbreakfastService { List excuteSql(string sql, params SqlParameter[] param) { return ServiceBase.excuteSql(new hotelidbreakfast(), "hotelidbreakfast", sql, CommandType.Text, param); } hotelidbreakfast excuteType(string sql, params SqlParameter[] param) { //查询结果放入对象集合 List hdList = excuteSql(sql, param); //判断集合是否为空 if (hdList == null || hdList.Count == 0) { return null; } //返回单个对象 return hdList[0]; } /// /// //增Add /// /// 添加酒店早餐信息 /// public bool Add(hotelidbreakfast obj, out int bid) { string sql = "insert into hotelidbreakfast values(@hotelid,@breakfastPrice,@isdel,@diid);SELECT @@IDENTITY"; SqlParameter[] parameter = new SqlParameter[]{ new SqlParameter("@hotelid",obj.Hotelid), new SqlParameter("@breakfastPrice",obj.BreakfastPrice), new SqlParameter("@isdel",obj.Isdel), new SqlParameter("@diid",obj.Diid), }; int obj2 = Convert.ToInt32(SqlHelper.ExecuteScalar(sql, CommandType.Text, parameter)); if (obj2 > 0) { bid = obj2; return true; } bid = 0; return false; } /// /// //改Update /// /// /// public bool Update(hotelidbreakfast obj) { string sql = @"update hotelidbreakfast set breakfastPrice = @breakfastPrice,isdel = @isdel where hotelid = @hotelid "; SqlParameter[] parameter = new SqlParameter[]{ new SqlParameter("@breakfastPrice",obj.BreakfastPrice), new SqlParameter("@isdel",obj.Isdel), new SqlParameter("@hotelid",obj.Hotelid) }; if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0) return true; return false; } /// /// 根据酒店id查询数据 /// /// public List GetAllByhotelidID(string hotelidID) { return excuteSql("select * from [dbo].[hotelidbreakfast] where hotelid = " + hotelidID ); } /// /// 根据编号查询对象信息 /// /// 对象编号 /// 返回空或者单个对象信息 public hotelidbreakfast GetHotelidbreakfastByID(int id) { //调用获取单个对象的方法 return excuteType("select * from hotelidbreakfast where tId = @id and isdel=0", new SqlParameter("@id", id)); } /// /// 根据酒店id删除酒店早餐表数据 /// /// /// public bool DelByHotelid(int hotelid,int diid) { string sql = "update hotelidbreakfast set isdel = @isdel where hotelid = @hotelid and diid = @diid "; SqlParameter[] parameter = new SqlParameter[]{ new SqlParameter("@isdel",1), new SqlParameter("@hotelid",hotelid), new SqlParameter("@diid",diid) }; if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0) return true; return false; } /// /// 根据酒店id和团组id查询数据 /// /// public hotelidbreakfast GetAllByhotelidIDAndDiid(string hotelidID,string groupid) { return excuteType($"select * from [dbo].[hotelidbreakfast] where hotelid = {hotelidID} and diid = {groupid} and isdel = 0 "); } } }