hotelidbreakfastService.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. using Models;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data.SqlClient;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. namespace DAL
  10. {
  11. public class hotelidbreakfastService
  12. {
  13. List<hotelidbreakfast> excuteSql(string sql, params SqlParameter[] param)
  14. {
  15. return ServiceBase<hotelidbreakfast>.excuteSql(new hotelidbreakfast(), "hotelidbreakfast", sql, CommandType.Text, param);
  16. }
  17. hotelidbreakfast excuteType(string sql, params SqlParameter[] param)
  18. {
  19. //查询结果放入对象集合
  20. List<hotelidbreakfast> hdList = excuteSql(sql, param);
  21. //判断集合是否为空
  22. if (hdList == null || hdList.Count == 0)
  23. {
  24. return null;
  25. }
  26. //返回单个对象
  27. return hdList[0];
  28. }
  29. /// <summary>
  30. /// //增Add
  31. /// </summary>
  32. /// <param name="aai">添加酒店早餐信息</param>
  33. /// <returns></returns>
  34. public bool Add(hotelidbreakfast obj, out int bid)
  35. {
  36. string sql = "insert into hotelidbreakfast values(@hotelid,@breakfastPrice,@isdel,@diid);SELECT @@IDENTITY";
  37. SqlParameter[] parameter = new SqlParameter[]{
  38. new SqlParameter("@hotelid",obj.Hotelid),
  39. new SqlParameter("@breakfastPrice",obj.BreakfastPrice),
  40. new SqlParameter("@isdel",obj.Isdel),
  41. new SqlParameter("@diid",obj.Diid),
  42. };
  43. int obj2 = Convert.ToInt32(SqlHelper.ExecuteScalar(sql, CommandType.Text, parameter));
  44. if (obj2 > 0)
  45. {
  46. bid = obj2;
  47. return true;
  48. }
  49. bid = 0;
  50. return false;
  51. }
  52. /// <summary>
  53. /// //改Update
  54. /// </summary>
  55. /// <param name="aai"></param>
  56. /// <returns></returns>
  57. public bool Update(hotelidbreakfast obj)
  58. {
  59. string sql = @"update hotelidbreakfast set
  60. breakfastPrice = @breakfastPrice,isdel = @isdel where hotelid = @hotelid ";
  61. SqlParameter[] parameter = new SqlParameter[]{
  62. new SqlParameter("@breakfastPrice",obj.BreakfastPrice),
  63. new SqlParameter("@isdel",obj.Isdel),
  64. new SqlParameter("@hotelid",obj.Hotelid)
  65. };
  66. if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0)
  67. return true;
  68. return false;
  69. }
  70. /// <summary>
  71. /// 根据酒店id查询数据
  72. /// </summary>
  73. /// <returns></returns>
  74. public List<hotelidbreakfast> GetAllByhotelidID(string hotelidID)
  75. {
  76. return excuteSql("select * from [dbo].[hotelidbreakfast] where hotelid = " + hotelidID );
  77. }
  78. /// <summary>
  79. /// 根据编号查询对象信息
  80. /// </summary>
  81. /// <param name="id">对象编号</param>
  82. /// <returns>返回空或者单个对象信息</returns>
  83. public hotelidbreakfast GetHotelidbreakfastByID(int id)
  84. {
  85. //调用获取单个对象的方法
  86. return excuteType("select * from hotelidbreakfast where tId = @id and isdel=0", new SqlParameter("@id", id));
  87. }
  88. /// <summary>
  89. /// 根据酒店id删除酒店早餐表数据
  90. /// </summary>
  91. /// <param name="hotelid"></param>
  92. /// <returns></returns>
  93. public bool DelByHotelid(int hotelid,int diid)
  94. {
  95. string sql = "update hotelidbreakfast set isdel = @isdel where hotelid = @hotelid and diid = @diid ";
  96. SqlParameter[] parameter = new SqlParameter[]{
  97. new SqlParameter("@isdel",1),
  98. new SqlParameter("@hotelid",hotelid),
  99. new SqlParameter("@diid",diid)
  100. };
  101. if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0)
  102. return true;
  103. return false;
  104. }
  105. /// <summary>
  106. /// 根据酒店id和团组id查询数据
  107. /// </summary>
  108. /// <returns></returns>
  109. public hotelidbreakfast GetAllByhotelidIDAndDiid(string hotelidID,string groupid)
  110. {
  111. return excuteType($"select * from [dbo].[hotelidbreakfast] where hotelid = {hotelidID} and diid = {groupid} and isdel = 0 ");
  112. }
  113. }
  114. }