Restaurant_OPService.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. using Models;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.Data.SqlClient;
  6. using System.Linq;
  7. using System.Text;
  8. namespace DAL
  9. {
  10. public class Restaurant_OPService
  11. {
  12. List<Restaurant_OP> excuteSql(string sql, params SqlParameter[] param)
  13. {
  14. return ServiceBase<Restaurant_OP>.excuteSql(new Restaurant_OP(), "Restaurant_OP", sql, CommandType.Text, param);
  15. }
  16. Restaurant_OP excuteType(string sql, params SqlParameter[] param)
  17. {
  18. //查询结果放入对象集合
  19. List<Restaurant_OP> hdList = excuteSql(sql, param);
  20. //判断集合是否为空
  21. if (hdList == null || hdList.Count == 0)
  22. //返回null
  23. return null;
  24. //返回单个对象
  25. return hdList[0];
  26. }
  27. //增Add
  28. public bool Add(Restaurant_OP Dov)
  29. {
  30. string sql = "insert into Restaurant_OP values(@Country,@City,@Name,@SpecialDishes,@Address,@Standard,@Currency,@PrivateRoom,@Remark,@OPer,@OPdate,@Isdel);SELECT @@IDENTITY";
  31. SqlParameter[] parameter = new SqlParameter[]{
  32. new SqlParameter("@Country",Dov.Country),
  33. new SqlParameter("@City",Dov.City),
  34. new SqlParameter("@Name",Dov.Name),
  35. new SqlParameter("@SpecialDishes",Dov.SpecialDishes),
  36. new SqlParameter("@Address",Dov.Address),
  37. new SqlParameter("@Standard",Dov.Standard),
  38. new SqlParameter("@Currency",Dov.Currency),
  39. new SqlParameter("@PrivateRoom",Dov.PrivateRoom),
  40. new SqlParameter("@Remark",Dov.Remark),
  41. new SqlParameter("@OPer",Dov.OPer),
  42. new SqlParameter("@OPdate",Dov.OPdate),
  43. new SqlParameter("@Isdel",Dov.Isdel)
  44. };
  45. if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0)
  46. return true;
  47. return false;
  48. }
  49. //改Update
  50. public bool Edit(Restaurant_OP Dov)
  51. {
  52. string sql = "update Restaurant_OP set Country=@Country,City=@City,Name=@Name,SpecialDishes=@SpecialDishes,Address=@Address,Standard=@Standard,"
  53. + "Currency=@Currency,PrivateRoom=@PrivateRoom,Remark=@Remark,OPer=@OPer,OPdate=@OPdate,Isdel=@Isdel where Id = @Id";
  54. SqlParameter[] parameter = new SqlParameter[]{
  55. new SqlParameter("@Country",Dov.Country),
  56. new SqlParameter("@City",Dov.City),
  57. new SqlParameter("@Name",Dov.Name),
  58. new SqlParameter("@SpecialDishes",Dov.SpecialDishes),
  59. new SqlParameter("@Address",Dov.Address),
  60. new SqlParameter("@Standard",Dov.Standard),
  61. new SqlParameter("@Currency",Dov.Currency),
  62. new SqlParameter("@PrivateRoom",Dov.PrivateRoom),
  63. new SqlParameter("@Remark",Dov.Remark),
  64. new SqlParameter("@OPer",Dov.OPer),
  65. new SqlParameter("@OPdate",Dov.OPdate),
  66. new SqlParameter("@Isdel",Dov.Isdel),
  67. new SqlParameter("@Id",Dov.Id)
  68. };
  69. if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0)
  70. return true;
  71. return false;
  72. }
  73. //删
  74. public bool delOA(int id)
  75. {
  76. if (SqlHelper.ExecuteNonQuery("update Restaurant_OP set Isdel=1 where Id=@Id", CommandType.Text, new SqlParameter("@Id", id)) > 0)
  77. return true;
  78. return false;
  79. }
  80. /// <summary>
  81. /// 查找所有数据 - 分页
  82. /// </summary>
  83. /// <returns></returns>
  84. public List<Restaurant_OP> GetAllRestaurant_OP(int pageIndex, out int sumPage, out int totalRecord, string Country, string City, string RestaurantName)
  85. {
  86. string sqlwhere = "IsDel = 0 and Country like '%" + Country + "%' and City like '%" + City + "%' and Name like '%" + RestaurantName + "%' ";
  87. return PageBase<Restaurant_OP>.excutePageSql(new Restaurant_OP(), "Restaurant_OP", "Restaurant_OP", "*", "id asc", sqlwhere, 10, pageIndex, out sumPage, out totalRecord);
  88. }
  89. public Restaurant_OP getById(int id)
  90. {
  91. return excuteType("select * from Restaurant_OP where Isdel=0 and Id=@id", new SqlParameter("@id", id));
  92. }
  93. public List<Restaurant_OP> getByIdlist(string id)
  94. {
  95. return excuteSql("select * from Restaurant_OP where Isdel=0 and Id in (" + id + ") order by Country", new SqlParameter("@id", id));
  96. }
  97. }
  98. }