CommissionService.cs 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. using Models;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Data.SqlClient;
  5. using Models;
  6. namespace DAL
  7. {
  8. /// <summary>
  9. /// 提成数据访问层
  10. /// </summary>
  11. public class CommissionService
  12. {
  13. /// <summary>
  14. /// 返回多个obj
  15. /// </summary>
  16. /// <param name="sql"></param>
  17. /// <param name="param"></param>
  18. /// <returns></returns>
  19. List<Commission> excuteSql(string sql, params SqlParameter[] param)
  20. {
  21. return ServiceBase<Commission>.excuteSql(new Commission(), "Commission", sql, CommandType.Text, param);
  22. }
  23. /// <summary>
  24. /// 返回单个obj
  25. /// </summary>
  26. /// <param name="sql"></param>
  27. /// <param name="param"></param>
  28. /// <returns></returns>
  29. Commission excuteType(string sql, params SqlParameter[] param)
  30. {
  31. //查询结果放入对象集合
  32. List<Commission> hdList = excuteSql(sql, param);
  33. Commission com = new Commission();
  34. //判断集合是否为空
  35. if (hdList == null || hdList.Count == 0)
  36. {
  37. //返回null
  38. return null;
  39. }
  40. //返回单个对象
  41. return hdList[0];
  42. }
  43. /// <summary>
  44. /// 增
  45. /// </summary>
  46. /// <param name="com"></param>
  47. /// <returns></returns>
  48. public bool ADD(Commission com)
  49. {
  50. string sql = "insert into Commission values(@Personnel,@Diid,@GroupDate,@GroupLvl,@NetProfit,@Balance,@Detail,@Money," +
  51. "@WageYearMonth,@IsMakeLoss,@IsLoss,@OPer,@OPDate,@IsDel);SELECT @@IDENTITY";
  52. SqlParameter[] parameter = new SqlParameter[]{
  53. new SqlParameter("@Personnel",com.Personnel),
  54. new SqlParameter("@Diid",com.Diid),
  55. new SqlParameter("@GroupDate",com.GroupDate),
  56. new SqlParameter("@GroupLvl",com.GroupLvl),
  57. new SqlParameter("@NetProfit",com.NetProfit),
  58. new SqlParameter("@Balance",com.Balance),
  59. new SqlParameter("@Detail",com.Detail),
  60. new SqlParameter("@Money",com.Money),
  61. new SqlParameter("@WageYearMonth",com.WageYearMonth),
  62. new SqlParameter("@IsMakeLoss",com.IsMakeLoss),
  63. new SqlParameter("@IsLoss",com.IsLoss),
  64. new SqlParameter("@OPer",com.OPer),
  65. new SqlParameter("@OPDate",com.OPDate),
  66. new SqlParameter("@IsDel",com.IsDel)
  67. };
  68. if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0)
  69. return true;
  70. return false;
  71. }
  72. //改
  73. public bool Edit(Commission com)
  74. {
  75. string sql = "update Commission set Personnel=@Personnel,Diid=@Diid,GroupDate=@GroupDate,GroupLvl=@GroupLvl,NetProfit=@NetProfit,Balance=@Balance" +
  76. "Detail=@Detail,Money=@Money,WageYearMonth=@WageYearMonth,IsMakeLoss=@IsMakeLoss,IsLoss=@IsLoss,OPer=@OPer," +
  77. "OPDate=@OPDate,IsDel=@IsDel where Id = @Id";
  78. SqlParameter[] parameter = new SqlParameter[]{
  79. new SqlParameter("@Personnel",com.Personnel),
  80. new SqlParameter("@Diid",com.Diid),
  81. new SqlParameter("@GroupDate",com.GroupDate),
  82. new SqlParameter("@GroupLvl",com.GroupLvl),
  83. new SqlParameter("@NetProfit",com.NetProfit),
  84. new SqlParameter("@Balance",com.Balance),
  85. new SqlParameter("@Detail",com.Detail),
  86. new SqlParameter("@Money",com.Money),
  87. new SqlParameter("@WageYearMonth",com.WageYearMonth),
  88. new SqlParameter("@IsMakeLoss",com.IsMakeLoss),
  89. new SqlParameter("@IsLoss",com.IsLoss),
  90. new SqlParameter("@OPer",com.OPer),
  91. new SqlParameter("@OPDate",com.OPDate),
  92. new SqlParameter("@IsDel",com.IsDel),
  93. new SqlParameter("@Id",com.Id)
  94. };
  95. if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0)
  96. return true;
  97. return false;
  98. }
  99. //删
  100. public bool del(int id)
  101. {
  102. if (SqlHelper.ExecuteNonQuery("update Commission set Isdel=1 where Id=@Id", CommandType.Text, new SqlParameter("@Id", id)) > 0)
  103. return true;
  104. return false;
  105. }
  106. /// <summary>
  107. /// 查找所有数据 - 分页
  108. /// </summary>
  109. /// <returns></returns>
  110. public List<Commission> GetAllAndPage(int pageIndex, out int sumPage, out int totalRecord, int Personnel, string startDate, string EndDate, string YearMonth)
  111. {
  112. string sqlwhere = "IsDel = 0 and Personnel = " + Personnel + " and ( GroupDate Between '" + startDate + "' and '" + EndDate + "' )";
  113. if (YearMonth != "全部月份")
  114. sqlwhere += " and WageYearMonth ='" + YearMonth + "'";
  115. return PageBase<Commission>.excutePageSql(new Commission(), "Commission", "Commission", "*", "GroupDate asc", sqlwhere, 10, pageIndex, out sumPage, out totalRecord);
  116. }
  117. /// <summary>
  118. /// 查找所有数据
  119. /// </summary>
  120. /// <param name="Personnel"></param>
  121. /// <param name="startDate"></param>
  122. /// <param name="EndDate"></param>
  123. /// <returns></returns>
  124. public List<Commission> GetAll(int Personnel, string startDate, string EndDate)
  125. {
  126. string sqlwhere = "select * from Commission where IsDel = 0 and Personnel = " + Personnel + " and(GroupDate Between '" + startDate + "' and '" + EndDate + "')";
  127. return excuteSql(sqlwhere);
  128. }
  129. /// <summary>
  130. /// 根据月份查找数据
  131. /// </summary>
  132. /// <param name="Personnel"></param>
  133. /// <param name="startDate"></param>
  134. /// <param name="EndDate"></param>
  135. /// <returns></returns>
  136. public List<Commission> GetByYearMonth(int Personnel, string WageYearMonth)
  137. {
  138. string sqlwhere = "select * from Commission where IsDel = 0 and Personnel = " + Personnel + " and WageYearMonth='" + WageYearMonth + "'";
  139. return excuteSql(sqlwhere);
  140. }
  141. /// <summary>
  142. ///根据ID查找
  143. /// </summary>
  144. /// <param name="id"></param>
  145. /// <returns></returns>
  146. public Commission GetByID(int id)
  147. {
  148. return excuteType("select * from Commission where Isdel=0 and Id=@id", new SqlParameter("@id", id));
  149. }
  150. /// <summary>
  151. /// 雷怡 2021-09-23 17:36
  152. ///根据团组编号查找
  153. /// </summary>
  154. /// <param name="Diid"></param>
  155. /// <returns></returns>
  156. public List<Commission> GetByDiid(int Diid)
  157. {
  158. return excuteSql("select * from Commission where Isdel=0 and Diid=@Diid", new SqlParameter("@Diid", Diid));
  159. }
  160. /// <summary>
  161. /// 雷怡 2021-09-24 17:36
  162. /// 查询去重团组编号
  163. /// </summary>
  164. /// <returns></returns>
  165. public List<Commission> GetDiidAllPage(int pageIndex, out int sumPage, out int totalRecord, string startDate, string EndDate)
  166. {
  167. string sqlwhere = " id in (select max(id) from Commission group by Diid) and IsDel = 0 ";
  168. if (!string.IsNullOrEmpty(startDate) && !string.IsNullOrEmpty(EndDate))
  169. sqlwhere += " and (GroupDate Between '" + startDate + "' and '" + EndDate + "')";
  170. return PageBase<Commission>.excutePageSql(new Commission(), "Commission", "Commission", "*", "GroupDate asc", sqlwhere, 10, pageIndex, out sumPage, out totalRecord);
  171. }
  172. }
  173. }