OfferServices.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Models;
  6. using System.Data.SqlClient;
  7. using System.Data;
  8. namespace DAL
  9. {
  10. /// <summary>
  11. /// 生成报价数据访问层
  12. /// </summary>
  13. public class OfferServices
  14. {
  15. /// <summary>
  16. /// 查询所有—分页
  17. /// </summary>
  18. /// <param name="pageIndex"></param>
  19. /// <param name="sumPage"></param>
  20. /// <param name="totalRecord"></param>
  21. /// <param name="company"></param>
  22. /// <param name="Uname"></param>
  23. /// <param name="ProCode"></param>
  24. /// <returns></returns>
  25. public DataTable GetAll(int pageIndex, out int sumPage, out int totalRecord, int company,string Uname,string Projects,int Cid,string proCode)
  26. {
  27. SqlParameter[] parameter = new SqlParameter[]{
  28. new SqlParameter("@pageIndex", pageIndex),
  29. new SqlParameter("@pageSize", 10),
  30. new SqlParameter("@Uname", Uname),
  31. new SqlParameter("@Projects", Projects),
  32. new SqlParameter("@Cid", Cid),
  33. new SqlParameter("@proCode", proCode)
  34. };
  35. //查询总条数
  36. totalRecord = Convert.ToInt32(SqlHelper.ExecuteScalar("select count(1) from dbo.Offer T left join clientdata C on T.Uid=C.id left join setData SC on T.Cid=SC.id left join setData SP on T.Pid=SP.id left join OfferData O on SC.id=O.Cid and SP.id=O.Pid where T.IsDel <> 1 and C.IsDel<>1 and SC.IsDel<>1 and SP.IsDel<>1 and C.UnitName like '%"+Uname+"%' and Projects like '%"+Projects+"%' and T.Cid="+Cid+" and T.ProCode like '%"+proCode+"%'", CommandType.Text, null));
  37. //计算出总页数
  38. sumPage = totalRecord % 10 == 0 ? totalRecord / 10 : totalRecord / 10 + 1;
  39. return SqlHelper.TransferProcedure("[exec_Offer_Query]", CommandType.StoredProcedure, parameter);
  40. }
  41. /// <summary>
  42. /// 添加报价单
  43. /// </summary>
  44. /// <param name="o"></param>
  45. /// <returns></returns>
  46. public bool AddOffer(Offer o)
  47. {
  48. string sql = "insert into Offer values(@Uid,@Projects,@Cid,@Pid,@Discount,@SalePrice,@Profit,@Version,@IsNew,@IsDel,@InputTime,@ProCode)";
  49. SqlParameter[] parameter = new SqlParameter[]
  50. {
  51. new SqlParameter("@Uid",o.Uid),
  52. new SqlParameter("@Projects",o.Projects),
  53. new SqlParameter("@Cid",o.Cid),
  54. new SqlParameter("@Pid",o.Pid),
  55. new SqlParameter("@Discount",o.Discount),
  56. new SqlParameter("@SalePrice",o.SalePrice),
  57. new SqlParameter("@Profit",o.Profit),
  58. new SqlParameter("@Version",o.Version),
  59. new SqlParameter("@IsNew",o.IsNew),
  60. new SqlParameter("@IsDel",o.IsDel),
  61. new SqlParameter("@InputTime",o.InputTime),
  62. new SqlParameter("@ProCode",o.ProCode)
  63. };
  64. if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0)
  65. return true;
  66. return false;
  67. }
  68. /// <summary>
  69. /// 根据项目编号查询该企业该项目生成报价单数量
  70. /// </summary>
  71. /// <param name="id"></param>
  72. /// <returns></returns>
  73. public int GetOfferCount(string ProCode)
  74. {
  75. return Convert.ToInt32(SqlHelper.ExecuteScalar("select max(Version) from Offer where ProCode=@ProCode", CommandType.Text, new SqlParameter("@ProCode", ProCode)));
  76. }
  77. /// <summary>
  78. /// 查询最大项目编号
  79. /// </summary>
  80. /// <returns></returns>
  81. public string GetMaxCode()
  82. {
  83. return SqlHelper.ExecuteScalar("select max(ProCode) from Offer", CommandType.Text, null).ToString();
  84. }
  85. /// <summary>
  86. /// 根据id查询offer实体
  87. /// </summary>
  88. /// <param name="p"></param>
  89. /// <returns></returns>
  90. public Offer GetOfferById(int id)
  91. {
  92. //调用获取单个对象的方法
  93. return excuteType("select * from Offer where Id = @id and IsDel = 0", new SqlParameter("@id", id));
  94. }
  95. /// <summary>
  96. /// 获取单个对象
  97. /// </summary>
  98. /// <param name="sql">sql语句</param>
  99. /// <param name="param">可变参数数组</param>
  100. /// <returns>返回空或者单个对象</returns>
  101. Offer excuteType(string sql, params SqlParameter[] param)
  102. {
  103. //查询结果放入对象集合
  104. List<Offer> offerList = excuteSql(sql, param);
  105. //判断集合是否为空
  106. if (offerList == null || offerList.Count == 0)
  107. //返回null
  108. return null;
  109. //返回单个对象
  110. return offerList[0];
  111. }
  112. /// <summary>
  113. /// 查询所有
  114. /// </summary>
  115. /// <param name="sql">sql语句</param>
  116. /// <param name="param">可变参数数组</param>
  117. /// <returns>返回集合</returns>
  118. List<Offer> excuteSql(string sql, params SqlParameter[] param)
  119. {
  120. return ServiceBase<Offer>.excuteSql(new Offer(), "Offer", sql, CommandType.Text, param);
  121. }
  122. /// <summary>
  123. /// 根据项目编号获得所有该项目的报价单
  124. /// </summary>
  125. /// <param name="p"></param>
  126. /// <returns></returns>
  127. public List<Offer> GetOfferByProCode(string ProCode)
  128. {
  129. return excuteSql("select * from Offer where ProCode=@ProCode", new SqlParameter("@ProCode", ProCode));
  130. }
  131. /// <summary>
  132. /// 删除
  133. /// </summary>
  134. /// <param name="id"></param>
  135. /// <returns></returns>
  136. public bool DelOffer(int id)
  137. {
  138. if (SqlHelper.ExecuteNonQuery("update Offer set IsDel=1 where id=@id", CommandType.Text, new SqlParameter("@id", id)) > 0)
  139. return true;
  140. return false;
  141. }
  142. /// <summary>
  143. /// 根据项目编号和版本号查询信息
  144. /// </summary>
  145. /// <param name="proCode"></param>
  146. /// <param name="version"></param>
  147. /// <returns></returns>
  148. public DataTable GetOfferByProCodeAndVersion(string proCode, int version)
  149. {
  150. return SqlHelper.TransferProcedure("exec_Offer_QueryByProCodeAndVersion", CommandType.StoredProcedure, new SqlParameter("@ProCode", proCode), new SqlParameter("@Version", version));
  151. }
  152. public List<Offer> GetAll(string startTime, string endTime)
  153. {
  154. string sql="select * from Offer where 1=1 ";
  155. if(startTime!="")
  156. sql+=" and InputTime >='"+startTime+"'";
  157. if(endTime!="")
  158. sql+=" and InputTime <='"+endTime+"'";
  159. return excuteSql(sql, null);
  160. }
  161. }
  162. }