LevelService.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Models;
  6. using System.Data;
  7. using System.Data.SqlClient;
  8. namespace DAL
  9. {
  10. /// <summary>
  11. /// 等级信息数据访问层
  12. /// </summary>
  13. public class LevelService
  14. {
  15. /// <summary>
  16. /// 查询所有等级信息数据
  17. /// </summary>
  18. /// <param name="pageIndex"></param>
  19. /// <param name="sumPage"></param>
  20. /// <param name="totalRecord"></param>
  21. /// <returns></returns>
  22. public object GetAll(int pageIndex, out int sumPage, out int totalRecord,string Did,string Cid)
  23. {
  24. string sqlwhere = " Did="+Did+" and IsDel = 0 and Cid="+Cid;
  25. return PageBase<Level>.excutePageSql(new Level(), "Level", "Level", "*", "id asc", sqlwhere, 10, pageIndex, out sumPage, out totalRecord);
  26. }
  27. /// <summary>
  28. /// 新增等级信息
  29. /// </summary>
  30. /// <param name="level">等级信息实体</param>
  31. /// <returns></returns>
  32. public bool AddLevel(Level level)
  33. {
  34. string sql = "insert into Level values(@Lid,@LName,@Profit,@Rebate,@Tax,@Did,@IsDel,@Cid)";
  35. SqlParameter[] parameter = new SqlParameter[]{
  36. new SqlParameter("@Lid",level.Lid),
  37. new SqlParameter("@LName",level.LName),
  38. new SqlParameter("@Profit",level.Profit),
  39. new SqlParameter("@Rebate",level.Rebate),
  40. new SqlParameter("@Tax",level.Tax),
  41. new SqlParameter("@Did",level.Did),
  42. new SqlParameter("@IsDel",level.IsDel),
  43. new SqlParameter("@Cid",level.Cid)
  44. };
  45. if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0)
  46. return true;
  47. return false;
  48. }
  49. /// <summary>
  50. /// 根据编号查询实体
  51. /// </summary>
  52. /// <param name="id"></param>
  53. /// <returns></returns>
  54. public Level GetSetDataByID(int id)
  55. {
  56. //调用获取单个对象的方法
  57. return excuteType("select * from Level where Id = @id and IsDel = 0", new SqlParameter("@id", id));
  58. }
  59. /// <summary>
  60. /// 获取单个对象
  61. /// </summary>
  62. /// <param name="sql">sql语句</param>
  63. /// <param name="param">可变参数数组</param>
  64. /// <returns>返回空或者单个对象</returns>
  65. private Level excuteType(string sql, SqlParameter param)
  66. {
  67. //查询结果放入对象集合
  68. List<Level> LevelList = excuteSql(sql, param);
  69. //判断集合是否为空
  70. if (LevelList == null || LevelList.Count == 0)
  71. //返回null
  72. return null;
  73. //返回单个对象
  74. return LevelList[0];
  75. }
  76. /// <summary>
  77. /// 查询所有
  78. /// </summary>
  79. /// <param name="sql">sql语句</param>
  80. /// <param name="param">可变参数数组</param>
  81. /// <returns>返回集合</returns>
  82. List<Level> excuteSql(string sql, params SqlParameter[] param)
  83. {
  84. return ServiceBase<Level>.excuteSql(new Level(), "Level", sql, CommandType.Text, param);
  85. }
  86. /// <summary>
  87. /// 根据id修改level表数据
  88. /// </summary>
  89. /// <param name="level"></param>
  90. /// <returns></returns>
  91. public bool EditLevel(Level level)
  92. {
  93. string sql = "update Level set Lid = @Lid ,LName = @LName ,Profit = @Profit,Rebate = @Rebate,Tax = @Tax,Did = @Did,Cid=@Cid where Id = @Id";
  94. SqlParameter[] parameter = new SqlParameter[]{
  95. new SqlParameter("@Lid",level.Lid),
  96. new SqlParameter("@LName",level.LName),
  97. new SqlParameter("@Profit",level.Profit),
  98. new SqlParameter("@Rebate",level.Rebate),
  99. new SqlParameter("@Tax",level.Tax),
  100. new SqlParameter("@Did",level.Did),
  101. new SqlParameter("@IsDel",level.IsDel),
  102. new SqlParameter("@Id",level.Id),
  103. new SqlParameter("@Cid",level.Cid)
  104. };
  105. if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0)
  106. return true;
  107. return false;
  108. }
  109. /// <summary>
  110. /// 删除
  111. /// </summary>
  112. /// <param name="id"></param>
  113. /// <returns></returns>
  114. public bool DelSetData(int id)
  115. {
  116. if (SqlHelper.ExecuteNonQuery("update Level set IsDel = 1 where Id = @Id", CommandType.Text, new SqlParameter("@Id", id)) > 0)
  117. return true;
  118. return false;
  119. }
  120. /// <summary>
  121. /// 根据航空公司id和等级id查询等级信息
  122. /// </summary>
  123. /// <param name="p"></param>
  124. /// <returns></returns>
  125. public Level GetOfferByLid(int Lid,int Cid)
  126. {
  127. //调用获取单个对象的方法
  128. return excuteType("select * from Level where Lid = @Lid and Cid="+Cid+" and IsDel = 0", new SqlParameter("@Lid", Lid));
  129. }
  130. }
  131. }