ScenicSpotInfoServcies.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Data.SqlClient;
  5. using System.Linq;
  6. using System.Text;
  7. using Models;
  8. namespace DAL
  9. {
  10. public class ScenicSpotInfoServcies
  11. {
  12. List<ScenicSpotInfo> excuteSql(string sql, params SqlParameter[] param)
  13. {
  14. return ServiceBase<ScenicSpotInfo>.excuteSql(new ScenicSpotInfo(), "ScenicSpotInfo", sql, CommandType.Text, param);
  15. }
  16. ScenicSpotInfo excuteType(string sql, params SqlParameter[] param)
  17. {
  18. //查询结果放入对象集合
  19. List<ScenicSpotInfo> hdList = excuteSql(sql, param);
  20. //判断集合是否为空
  21. if (hdList == null || hdList.Count == 0)
  22. //返回null
  23. return null;
  24. //返回单个对象
  25. return hdList[0];
  26. }
  27. /// <summary>
  28. /// 增Add
  29. /// </summary>
  30. /// <param name="Dov"></param>
  31. /// <returns></returns>
  32. public bool Add(ScenicSpotInfo cg)
  33. {
  34. string sql = "insert into ScenicSpotInfo values(@Country,@City,@ScenicSpot,@ScenicSpotDetail,@Price,@Currency,@Rate,@Address,@Oper,@OpDate,@Isdel);SELECT @@IDENTITY";
  35. SqlParameter[] parameter = new SqlParameter[]{
  36. new SqlParameter("@Country",cg.Country),
  37. new SqlParameter("@City",cg.City),
  38. new SqlParameter("@ScenicSpot",cg.ScenicSpot),
  39. new SqlParameter("@ScenicSpotDetail",cg.ScenicSpotDetail),
  40. new SqlParameter("@Price",cg.Price),
  41. new SqlParameter("@Currency",cg.Currency),
  42. new SqlParameter("@Rate",cg.Rate),
  43. new SqlParameter("@Address",cg.Address),
  44. new SqlParameter("@Oper",cg.Oper),
  45. new SqlParameter("@OpDate",cg.OpDate),
  46. new SqlParameter("@Isdel",cg.Isdel)
  47. };
  48. if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0)
  49. return true;
  50. return false;
  51. }
  52. /// <summary>
  53. /// 修改
  54. /// </summary>
  55. /// <param name="Dov"></param>
  56. /// <returns></returns>
  57. public bool Edit(ScenicSpotInfo cg)
  58. {
  59. string sql = "update ScenicSpotInfo set Country=@Country,City=@City,ScenicSpot=@ScenicSpot ,ScenicSpotDetail=@ScenicSpotDetail,Price =@Price,"
  60. + "Currency=@Currency,Rate=@Rate,Address=@Address,Oper=@Oper,OpDate=@OpDate,Isdel=@Isdel where Id = @Id";
  61. SqlParameter[] parameter = new SqlParameter[]{
  62. new SqlParameter("@Country",cg.Country),
  63. new SqlParameter("@City",cg.City),
  64. new SqlParameter("@ScenicSpot",cg.ScenicSpot),
  65. new SqlParameter("@ScenicSpotDetail",cg.ScenicSpotDetail),
  66. new SqlParameter("@Price",cg.Price),
  67. new SqlParameter("@Currency",cg.Currency),
  68. new SqlParameter("@Rate",cg.Rate),
  69. new SqlParameter("@Address",cg.Address),
  70. new SqlParameter("@Oper",cg.Oper),
  71. new SqlParameter("@OpDate",cg.OpDate),
  72. new SqlParameter("@Isdel",cg.Isdel),
  73. new SqlParameter("@Id",cg.Id),
  74. };
  75. if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0)
  76. return true;
  77. return false;
  78. }
  79. /// <summary>
  80. /// 删
  81. /// </summary>
  82. /// <param name="id"></param>
  83. /// <returns></returns>
  84. public bool delOA(int id)
  85. {
  86. if (SqlHelper.ExecuteNonQuery("update ScenicSpotInfo set Isdel=1 where Id=@Id", CommandType.Text, new SqlParameter("@Id", id)) > 0)
  87. return true;
  88. return false;
  89. }
  90. /// <summary>
  91. /// 获取全部 - 分页
  92. /// </summary>
  93. /// <returns></returns>
  94. public List<ScenicSpotInfo> GetALL(int pageIndex, out int sumPage, out int totalRecord, string City)
  95. {
  96. string sqlwhere = "IsDel = 0";
  97. if (!string.IsNullOrEmpty(City))
  98. sqlwhere += " and City like '%" + City + "%'";
  99. return PageBase<ScenicSpotInfo>.excutePageSql(new ScenicSpotInfo(), "ScenicSpotInfo", "ScenicSpotInfo", "*", "id asc", sqlwhere, 20, pageIndex, out sumPage, out totalRecord);
  100. }
  101. /// <summary>
  102. /// 获取全部 - 分页
  103. /// </summary>
  104. /// <returns></returns>
  105. public List<ScenicSpotInfo> GetALL(int pageIndex, out int sumPage, out int totalRecord, string City,string Countrys)
  106. {
  107. string sqlwhere = "IsDel = 0";
  108. if (!string.IsNullOrEmpty(Countrys))
  109. {
  110. if (Countrys.Contains("中国"))
  111. {
  112. if (Countrys == "中国")
  113. {
  114. sqlwhere += " and Country like '%" + City + "%'";
  115. }
  116. else
  117. {
  118. sqlwhere += " and City like '%" + City + "%'";
  119. }
  120. }
  121. else
  122. {
  123. string country1 = "";
  124. string[] country = new string[] { };
  125. if (Countrys.Contains(","))
  126. country = Countrys.Split(',');
  127. else if (Countrys.Contains("、"))
  128. country = Countrys.Split('、');
  129. else if (Countrys.Contains(","))
  130. country = Countrys.Split(',');
  131. else if (Countrys.Contains(" "))
  132. country = Countrys.Split(' ');
  133. if (country.Length >= 1)
  134. {
  135. for (int i = 0; i < country.Length; i++)
  136. {
  137. if (i == country.Length - 1)
  138. country1 += " '" + country[i] + "'";
  139. else
  140. country1 += " '" + country[i] + "',";
  141. }
  142. sqlwhere += " and Country in (" + country1 + ")";
  143. }
  144. else
  145. sqlwhere += " and Country like '%" + Countrys + "%'";
  146. }
  147. }
  148. else
  149. {
  150. sqlwhere += " and City like '%" + City + "%'";
  151. }
  152. return PageBase<ScenicSpotInfo>.excutePageSql(new ScenicSpotInfo(), "ScenicSpotInfo", "ScenicSpotInfo", "*", "id asc", sqlwhere, 7, pageIndex, out sumPage, out totalRecord);
  153. }
  154. }
  155. }