ThreeCodeServices.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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 ThreeCodeServices
  11. {
  12. List<ThreeCode> excuteSql(string sql, params SqlParameter[] param)
  13. {
  14. return ServiceBase<ThreeCode>.excuteSql(new ThreeCode(), "ThreeCode", sql, CommandType.Text, param);
  15. }
  16. ThreeCode excuteType(string sql, params SqlParameter[] param)
  17. {
  18. //查询结果放入对象集合
  19. List<ThreeCode> hdList = excuteSql(sql, param);
  20. //判断集合是否为空
  21. if (hdList == null || hdList.Count == 0)
  22. //返回null
  23. return null;
  24. //返回单个对象
  25. return hdList[0];
  26. }
  27. public ThreeCode getByThree(string three)
  28. {
  29. return this.excuteType("select * from ThreeCode where Isdel=0 and Three=@Three", new SqlParameter("@Three", three.ToUpper()));
  30. }
  31. //public ThreeCode getByCountry(string country)
  32. //{
  33. // return this.excuteType("select * from ThreeCode where Isdel=0 and country='"+country+"'");
  34. //}
  35. public List<ThreeCode> getByCountry(string country)
  36. {
  37. return this.excuteSql("select * from ThreeCode where Isdel=0 and country='" + country + "'");
  38. }
  39. public List<ThreeCode> getByCity(string city)
  40. {
  41. return this.excuteSql("select * from ThreeCode where Isdel=0 and City='" + city + "'");
  42. }
  43. public ThreeCode getById(string Id)
  44. {
  45. return this.excuteType("select * from ThreeCode where Isdel=0 and Id=" + Id);
  46. }
  47. /// <summary>
  48. /// 查找所有数据 - 分页
  49. /// </summary>
  50. /// <returns></returns>
  51. public List<ThreeCode> GetAll(int pageIndex, out int sumPage, out int totalRecord, string Three,string City)
  52. {
  53. string sqlwhere = "IsDel = 0 and Three like '%" + Three + "%'"+ "and City like '%" + City + "%'";
  54. return PageBase<ThreeCode>.excutePageSql(new ThreeCode(), "ThreeCode", "ThreeCode", "*", "id asc", sqlwhere, 10, pageIndex, out sumPage, out totalRecord);
  55. }
  56. /// <summary>
  57. /// 查找所有数据 - 国家
  58. /// </summary>
  59. /// <returns></returns>
  60. public List<ThreeCode> GetAllCountry()
  61. {
  62. return excuteSql("select * from ThreeCode where IsDel = 0");
  63. }
  64. /// <summary>
  65. /// 增加
  66. /// </summary>
  67. /// <param name="cd"></param>
  68. /// <returns></returns>
  69. public bool Add(ThreeCode hd)
  70. {
  71. string sql = "insert into ThreeCode values(@Three,@Four,@Country,@City,@AirPort,@AirPort_En,@OPer,@OPDate,@Isdel)";
  72. SqlParameter[] parameter = new SqlParameter[]{
  73. new SqlParameter("@Three",hd.Three),
  74. new SqlParameter("@Four",hd.Four),
  75. new SqlParameter("@Country",hd.Country),
  76. new SqlParameter("@City",hd.City),
  77. new SqlParameter("@AirPort",hd.AirPort),
  78. new SqlParameter("@AirPort_En",hd.AirPort_En),
  79. new SqlParameter("@OPer",hd.OPer),
  80. new SqlParameter("@OPDate",hd.OPDate),
  81. new SqlParameter("@Isdel",hd.Isdel)
  82. };
  83. if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0)
  84. return true;
  85. return false;
  86. }
  87. /// <summary>
  88. /// 编辑
  89. /// </summary>
  90. /// <param name="sdt"></param>
  91. /// <returns></returns>
  92. public bool Edit(ThreeCode hd)
  93. {
  94. string sql = "update ThreeCode set Three=@Three,Four=@Four,Country=@Country,City=@City,AirPort=@AirPort,"
  95. + "AirPort_En=@AirPort_En,OPer=@OPer,OPDate=@OPDate,Isdel=@Isdel where Id = @Id";
  96. SqlParameter[] parameter = new SqlParameter[]{
  97. new SqlParameter("@Three",hd.Three),
  98. new SqlParameter("@Four",hd.Four),
  99. new SqlParameter("@Country",hd.Country),
  100. new SqlParameter("@City",hd.City),
  101. new SqlParameter("@AirPort",hd.AirPort),
  102. new SqlParameter("@AirPort_En",hd.AirPort_En),
  103. new SqlParameter("@OPer",hd.OPer),
  104. new SqlParameter("@OPDate",hd.OPDate),
  105. new SqlParameter("@Isdel",hd.Isdel),
  106. new SqlParameter("@Id",hd.Id)
  107. };
  108. if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0)
  109. return true;
  110. return false;
  111. }
  112. /// <summary>
  113. /// 删除
  114. /// </summary>
  115. /// <param name="id"></param>
  116. /// <returns></returns>
  117. public bool Del(int id)
  118. {
  119. if (SqlHelper.ExecuteNonQuery("update ThreeCode set IsDel = 1 where Id = @Id", CommandType.Text, new SqlParameter("@Id", id)) > 0)
  120. return true;
  121. return false;
  122. }
  123. }
  124. }