TicketService.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Models;
  6. using System.Data.SqlClient;
  7. using System.Data;
  8. namespace DAL
  9. {
  10. public class TicketService
  11. {
  12. /// <summary>
  13. /// 查询所有
  14. /// </summary>
  15. /// <param name="sql">sql语句</param>
  16. /// <param name="param">可变参数数组</param>
  17. /// <returns>返回集合</returns>
  18. List<Ticket> excuteSql(string sql, params SqlParameter[] param)
  19. {
  20. return ServiceBase<Ticket>.excuteSql(new Ticket(), "Ticket", sql, CommandType.Text, param);
  21. }
  22. /// <summary>
  23. /// 获取单个对象
  24. /// </summary>
  25. /// <param name="sql">sql语句</param>
  26. /// <param name="param">可变参数数组</param>
  27. /// <returns>返回空或者单个对象</returns>
  28. Ticket excuteType(string sql, params SqlParameter[] param)
  29. {
  30. //查询结果放入对象集合
  31. List<Ticket> vList = excuteSql(sql, param);
  32. //判断集合是否为空
  33. if (vList == null || vList.Count == 0)
  34. //返回null
  35. return null;
  36. //返回单个对象
  37. return vList[0];
  38. }
  39. /// <summary>
  40. /// 增加
  41. /// </summary>
  42. /// <returns></returns>
  43. public bool AddTicketInfo(Ticket r)
  44. {
  45. string sql = "insert into Ticket values(@Country,@Area,@ScenicSpot,@Address,@Contact,@Price,@Currency,@Star,@StartDate,@Remark,@IsDel)";
  46. SqlParameter[] parameter = new SqlParameter[]{
  47. new SqlParameter("@Country",r.Country),
  48. new SqlParameter("@Area",r.Area),
  49. new SqlParameter("@ScenicSpot",r.ScenicSpot),
  50. new SqlParameter("@Address",r.Address),
  51. new SqlParameter("@Contact",r.Contact),
  52. new SqlParameter("@Price",r.Price),
  53. new SqlParameter("@Currency",r.Currency),
  54. new SqlParameter("@Star",r.Star),
  55. new SqlParameter("@StartDate",r.StartDate),
  56. new SqlParameter("@Remark",r.Remark),
  57. new SqlParameter("@IsDel",r.IsDel)
  58. };
  59. if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0)
  60. return true;
  61. return false;
  62. }
  63. /// <summary>
  64. /// 获取全部 - 分页
  65. /// </summary>
  66. /// <returns></returns>
  67. public List<Ticket> GetTicketInfo(int pageIndex, out int sumPage, out int totalRecord, string txtWhere)
  68. {
  69. string sqlwhere = null;
  70. if (txtWhere == null || txtWhere == "")
  71. {
  72. sqlwhere = " IsDel = 0";
  73. }
  74. else
  75. {
  76. sqlwhere = " IsDel = 0 or Country like '%" + txtWhere + "%' or Area like '%" + txtWhere + "%' or ScenicSpot like '%" + txtWhere + "%'";
  77. }
  78. return PageBase<Ticket>.excutePageSql(new Ticket(), "Ticket", "Ticket", "*", "Star desc", sqlwhere, 20, pageIndex, out sumPage, out totalRecord);
  79. }
  80. public bool Del(int id)
  81. {
  82. if (SqlHelper.ExecuteNonQuery("update Ticket set IsDel = 1 where Id = @Id", CommandType.Text, new SqlParameter("@Id", id)) >0)
  83. return true;
  84. return false;
  85. }
  86. /// <summary>
  87. /// 编辑
  88. /// </summary>
  89. /// <returns></returns>
  90. public bool EditTicket(Ticket r)
  91. {
  92. string sql = "update Ticket set Country = @Country,Area = @Area,ScenicSpot = @ScenicSpot,Address = @Address,Contact = @Contact,Price = @Price,Currency = @Currency,Star = @Star,StartDate = @StartDate,Remark = @Remark where Id = @Id";
  93. SqlParameter[] parameter = new SqlParameter[]{
  94. new SqlParameter("@Country",r.Country),
  95. new SqlParameter("@Area",r.Area),
  96. new SqlParameter("@ScenicSpot",r.ScenicSpot),
  97. new SqlParameter("@Address",r.Address),
  98. new SqlParameter("@Contact",r.Contact),
  99. new SqlParameter("@Price",r.Price),
  100. new SqlParameter("@Currency",r.Currency),
  101. new SqlParameter("@Star",r.Star),
  102. new SqlParameter("@StartDate",r.StartDate),
  103. new SqlParameter("@Remark",r.Remark),
  104. new SqlParameter("@Id",r.Id)
  105. };
  106. if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0)
  107. return true;
  108. return false;
  109. }
  110. public Ticket GetTicketByID(int id)
  111. {
  112. //调用获取单个对象的方法
  113. return excuteType("select * from Ticket where Id = @id and isdel=0", new SqlParameter("@id", id));
  114. }
  115. }
  116. }