GuidesInfoServcies.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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 GuidesInfoServcies
  11. {
  12. List<GuidesInfo> excuteSql(string sql, params SqlParameter[] param)
  13. {
  14. return ServiceBase<GuidesInfo>.excuteSql(new GuidesInfo(), "GuidesInfo", sql, CommandType.Text, param);
  15. }
  16. GuidesInfo excuteType(string sql, params SqlParameter[] param)
  17. {
  18. //查询结果放入对象集合
  19. List<GuidesInfo> 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. /// 根据ID查询
  29. /// </summary>
  30. /// <param name="id"></param>
  31. /// <returns></returns>
  32. public GuidesInfo GetById(string id)
  33. {
  34. //调用获取单个对象的方法
  35. string sql = "select * from GuidesInfo where Id=@Id and isdel = 0";
  36. SqlParameter[] parameter = new SqlParameter[]{
  37. new SqlParameter("@Id", id)
  38. };
  39. return excuteType(sql, parameter);
  40. }
  41. /// <summary>
  42. /// 增Add
  43. /// </summary>
  44. /// <param name="Dov"></param>
  45. /// <returns></returns>
  46. public bool Add(GuidesInfo cg)
  47. {
  48. string sql = "insert into GuidesInfo values(@Country,@City,@ServiceType,@Price,@TranslationPrice,@Currency,@Remark,@Oper,@OpDate,@Isdel);SELECT @@IDENTITY";
  49. SqlParameter[] parameter = new SqlParameter[]{
  50. new SqlParameter("@Country",cg.Country),
  51. new SqlParameter("@City",cg.City),
  52. new SqlParameter("@ServiceType",cg.ServiceType),
  53. new SqlParameter("@Price",cg.Price),
  54. new SqlParameter("@TranslationPrice",cg.TranslationPrice),
  55. new SqlParameter("@Currency",cg.Currency),
  56. new SqlParameter("@Remark",cg.Remark),
  57. new SqlParameter("@Oper",cg.Oper),
  58. new SqlParameter("@OpDate",cg.OpDate),
  59. new SqlParameter("@Isdel",cg.Isdel)
  60. };
  61. if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0)
  62. return true;
  63. return false;
  64. }
  65. /// <summary>
  66. /// 修改
  67. /// </summary>
  68. /// <param name="Dov"></param>
  69. /// <returns></returns>
  70. public bool Edit(GuidesInfo cg)
  71. {
  72. string sql = "update GuidesInfo set Country=@Country,City=@City,ServiceType=@ServiceType,Price=@Price,TranslationPrice=@TranslationPrice,"
  73. + "Currency=@Currency,Remark=@Remark,Oper=@Oper,OpDate=@OpDate,Isdel=@Isdel where Id = @Id";
  74. SqlParameter[] parameter = new SqlParameter[]{
  75. new SqlParameter("@Country",cg.Country),
  76. new SqlParameter("@City",cg.City),
  77. new SqlParameter("@ServiceType",cg.ServiceType),
  78. new SqlParameter("@Price",cg.Price),
  79. new SqlParameter("@TranslationPrice",cg.TranslationPrice),
  80. new SqlParameter("@Currency",cg.Currency),
  81. new SqlParameter("@Remark",cg.Remark),
  82. new SqlParameter("@Oper",cg.Oper),
  83. new SqlParameter("@OpDate",cg.OpDate),
  84. new SqlParameter("@Isdel",cg.Isdel),
  85. new SqlParameter("@Id",cg.Id),
  86. };
  87. if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0)
  88. return true;
  89. return false;
  90. }
  91. /// <summary>
  92. /// 删
  93. /// </summary>
  94. /// <param name="id"></param>
  95. /// <returns></returns>
  96. public bool delOA(int id)
  97. {
  98. if (SqlHelper.ExecuteNonQuery("update GuidesInfo set Isdel=1 where Id=@Id", CommandType.Text, new SqlParameter("@Id", id)) > 0)
  99. return true;
  100. return false;
  101. }
  102. /// <summary>
  103. /// 获取全部 - 分页
  104. /// </summary>
  105. /// <returns></returns>
  106. public List<GuidesInfo> GetALL(int pageIndex, out int sumPage, out int totalRecord, string City)
  107. {
  108. string sqlwhere = "IsDel = 0";
  109. if (!string.IsNullOrEmpty(City))
  110. sqlwhere += " and City like '%" + City + "%'";
  111. return PageBase<GuidesInfo>.excutePageSql(new GuidesInfo(), "GuidesInfo", "GuidesInfo", "*", "id asc", sqlwhere, 10, pageIndex, out sumPage, out totalRecord);
  112. }/// <summary>
  113. /// 获取全部 - 分页
  114. /// </summary>
  115. /// <returns></returns>
  116. public List<GuidesInfo> GetALL(int pageIndex, out int sumPage, out int totalRecord, string City,string Countrys)
  117. {
  118. string sqlwhere = "IsDel = 0";
  119. if (!string.IsNullOrEmpty(Countrys))
  120. {
  121. if (Countrys.Contains("中国"))
  122. {
  123. if (Countrys == "中国")
  124. {
  125. sqlwhere += " and Country like '%" + City + "%'";
  126. }
  127. else
  128. {
  129. sqlwhere += " and City like '%" + City + "%'";
  130. }
  131. }
  132. else
  133. {
  134. string country1 = "";
  135. string[] country = new string[] { };
  136. if (Countrys.Contains(","))
  137. country = Countrys.Split(',');
  138. else if (Countrys.Contains("、"))
  139. country = Countrys.Split('、');
  140. else if (Countrys.Contains(","))
  141. country = Countrys.Split(',');
  142. else if (Countrys.Contains(" "))
  143. country = Countrys.Split(' ');
  144. if (country.Length >= 1)
  145. {
  146. for (int i = 0; i < country.Length; i++)
  147. {
  148. if (i == country.Length - 1)
  149. country1 += " '" + country[i] + "'";
  150. else
  151. country1 += " '" + country[i] + "',";
  152. }
  153. sqlwhere += " and Country in (" + country1 + ")";
  154. }
  155. else
  156. sqlwhere += " and Country like '%" + Countrys + "%'";
  157. }
  158. }
  159. else
  160. {
  161. sqlwhere += " and City like '%" + City + "%'";
  162. }
  163. return PageBase<GuidesInfo>.excutePageSql(new GuidesInfo(), "GuidesInfo", "GuidesInfo", "*", "id asc", sqlwhere, 10, pageIndex, out sumPage, out totalRecord);
  164. }
  165. }
  166. }