OfferDataService.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Data;
  6. using System.Data.SqlClient;
  7. namespace DAL
  8. {
  9. /// <summary>
  10. /// 报价基础信息数据访问类
  11. /// </summary>
  12. public class OfferDataService
  13. {
  14. /// <summary>
  15. /// 查询所有—分页
  16. /// </summary>
  17. /// <param name="pageIndex"></param>
  18. /// <param name="sumPage"></param>
  19. /// <param name="totalRecord"></param>
  20. /// <returns></returns>
  21. public DataTable GetAll(int pageIndex, out int sumPage, out int totalRecord,int Cid,int pageSize)
  22. {
  23. SqlParameter[] parameter = new SqlParameter[]{
  24. new SqlParameter("@pageIndex", pageIndex),
  25. new SqlParameter("@pageSize", pageSize),
  26. new SqlParameter("@Cid",Cid)
  27. };
  28. //查询总条数
  29. totalRecord = Convert.ToInt32(SqlHelper.ExecuteScalar("select count(1) from dbo.OfferData T left join setData S on T.Pid=S.id where T.IsDel <> 1 and S.IsDel <> 1 and Cid="+Cid, CommandType.Text, null));
  30. //计算出总页数
  31. sumPage = totalRecord%10==0?totalRecord/10:totalRecord/10+1;
  32. return SqlHelper.TransferProcedure("[exec_OfferData_Query]", CommandType.StoredProcedure, parameter);
  33. }
  34. public bool AddOfferData(OfferData od)
  35. {
  36. string sql = "insert into OfferData values(@PId,@Cid,@PublishedPrice,@BasePrice,@AddedTax,@IsDel)";
  37. SqlParameter[] parameter = new SqlParameter[]{
  38. new SqlParameter("@PId",od.PId),
  39. new SqlParameter("@Cid",od.Cid),
  40. new SqlParameter("@PublishedPrice",od.PublishedPrice),
  41. new SqlParameter("@BasePrice",od.BasePrice),
  42. new SqlParameter("@AddedTax",od.AddedTax),
  43. new SqlParameter("@IsDel",od.IsDel)
  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 bool DelOfferData(int id)
  55. {
  56. if (SqlHelper.ExecuteNonQuery("update OfferData set IsDel = 1 where Id = @Id", CommandType.Text, new SqlParameter("@Id", id)) > 0)
  57. return true;
  58. return false;
  59. }
  60. /// <summary>
  61. /// 根据编号查询信息
  62. /// </summary>
  63. /// <param name="id"></param>
  64. /// <returns></returns>
  65. public List<OfferData> GetOfferDataByID(int id)
  66. {
  67. //调用获取单个对象的方法
  68. return excuteSql("select T.*,S.Name from OfferData T left join setData S on T.Pid=S.id where T.Id = @id and T.IsDel = 0", new SqlParameter("@id", id));
  69. }
  70. /// <summary>
  71. /// 获取单个对象
  72. /// </summary>
  73. /// <param name="sql">sql语句</param>
  74. /// <param name="param">可变参数数组</param>
  75. /// <returns>返回空或者单个对象</returns>
  76. OfferData excuteType(string sql, params SqlParameter[] param)
  77. {
  78. //查询结果放入对象集合
  79. List<OfferData> setDataList = excuteSql(sql, param);
  80. //判断集合是否为空
  81. if (setDataList == null || setDataList.Count == 0)
  82. //返回null
  83. return null;
  84. //返回单个对象
  85. return setDataList[0];
  86. }
  87. /// <summary>
  88. /// 查询所有
  89. /// </summary>
  90. /// <param name="sql">sql语句</param>
  91. /// <param name="param">可变参数数组</param>
  92. /// <returns>返回集合</returns>
  93. List<OfferData> excuteSql(string sql, params SqlParameter[] param)
  94. {
  95. return ServiceBase<OfferData>.excuteSql(new OfferData(), "OfferData", sql, CommandType.Text, param);
  96. }
  97. /// <summary>
  98. /// 修改
  99. /// </summary>
  100. /// <param name="od"></param>
  101. /// <returns></returns>
  102. public bool EditSetData(OfferData od)
  103. {
  104. string sql = "update OfferData set PublishedPrice = @PublishedPrice ,BasePrice = @BasePrice,AddedTax=@AddedTax where id=@id";
  105. SqlParameter[] parameter = new SqlParameter[] {
  106. new SqlParameter("@PublishedPrice",od.PublishedPrice),
  107. new SqlParameter("@BasePrice",od.BasePrice),
  108. new SqlParameter("@AddedTax",od.AddedTax),
  109. new SqlParameter("@id",od.Id)
  110. };
  111. if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter)>0)
  112. return true;
  113. return false;
  114. }
  115. }
  116. }