IncreasePaymentsService.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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 IncreasePaymentsService
  14. {
  15. /// <summary>
  16. /// 查询所有
  17. /// </summary>
  18. /// <param name="sql">sql语句</param>
  19. /// <param name="param">可变参数数组</param>
  20. /// <returns>返回集合</returns>
  21. List<IncreasePayments> excuteSql(string sql, params SqlParameter[] param)
  22. {
  23. return ServiceBase<IncreasePayments>.excuteSql(new IncreasePayments(), "IncreasePayments", sql, CommandType.Text, param);
  24. }
  25. /// <summary>
  26. /// 获取单个对象
  27. /// </summary>
  28. /// <param name="sql">sql语句</param>
  29. /// <param name="param">可变参数数组</param>
  30. /// <returns>返回空或者单个对象</returns>
  31. IncreasePayments excuteType(string sql, params SqlParameter[] param)
  32. {
  33. //查询结果放入对象集合
  34. List<IncreasePayments> IncreasePaymentsList = excuteSql(sql, param);
  35. //判断集合是否为空
  36. if (IncreasePaymentsList == null || IncreasePaymentsList.Count == 0)
  37. //返回null
  38. return null;
  39. //返回单个对象
  40. return IncreasePaymentsList[0];
  41. }
  42. /// <summary>
  43. /// 根据编号查询对象信息
  44. /// </summary>
  45. /// <param name="id">对象编号</param>
  46. /// <returns>返回空或者单个对象信息</returns>
  47. public IncreasePayments GetIncreasePaymentsByID(int id)
  48. {
  49. //调用获取单个对象的方法
  50. return excuteType("select * from IncreasePayments where Id = @id", new SqlParameter("@id", id));
  51. }
  52. /// <summary>
  53. /// 获取全部有效数据
  54. /// </summary>
  55. /// <returns></returns>
  56. public List<IncreasePayments> GetAll()
  57. {
  58. return excuteSql("select * from IncreasePayments Where IsDel = 0");
  59. }
  60. /// <summary>
  61. /// 获取信息
  62. /// </summary>
  63. /// <returns></returns>
  64. public double GetSumMoney(int uid, string yearMonth)
  65. {
  66. object obj = SqlHelper.ExecuteScalar("select sum([money]) from IncreasePayments where isDel = 0 and userId = " + uid + " and yearMonth = '" + yearMonth + "'", CommandType.Text);
  67. double sumMoney = 0;
  68. if(obj!=null && !string.IsNullOrEmpty(obj.ToString()))
  69. sumMoney = Convert.ToDouble(obj);
  70. //调用获取单个对象的方法
  71. return sumMoney;
  72. }
  73. /// <summary>
  74. /// 根据条件查询条件获取 - 分页
  75. /// </summary>
  76. /// <param name="pageIndex"></param>
  77. /// <param name="sumPage"></param>
  78. /// <param name="totalRecord"></param>
  79. /// <param name="dataType"></param>
  80. /// <param name="name"></param>
  81. /// <returns></returns>
  82. public List<IncreasePayments> GetAll(int pageIndex, out int sumPage, out int totalRecord, string yearMonth, string increaseType,string userId)
  83. {
  84. string sqlwhere;
  85. if (userId != "0")
  86. {
  87. sqlwhere = "YearMonth = '" + yearMonth + "' and Sid = " + increaseType + " and UserId = " + userId + " and IsDel = 0";
  88. }else
  89. {
  90. sqlwhere = "YearMonth = '" + yearMonth + "' and Sid = " + increaseType + " and IsDel = 0";
  91. }
  92. return PageBase<IncreasePayments>.excutePageSql(new IncreasePayments(), "IncreasePayments", "IncreasePayments", "*", "id desc", sqlwhere, 10, pageIndex, out sumPage, out totalRecord);
  93. }
  94. /// <summary>
  95. /// 新增
  96. /// </summary>
  97. /// <param name="sdt">对象</param>
  98. public bool AddIncreasePayments(IncreasePayments ip)
  99. {
  100. string sql = "insert into IncreasePayments values(@YearMonth,@UserId,@Sid,@OccurrenceDate,@Money,@Remark,@Operator,@OperatorDate,@IsDel)";
  101. SqlParameter[] parameter = new SqlParameter[]{
  102. new SqlParameter("@YearMonth",ip.YearMonths),
  103. new SqlParameter("@UserId",ip.UserId),
  104. new SqlParameter("@Sid",ip.Sid),
  105. new SqlParameter("@OccurrenceDate",ip.OccurrenceDate),
  106. new SqlParameter("@Money", ip.Money),
  107. new SqlParameter("@Remark",ip.Remark),
  108. new SqlParameter("@Operator",ip.Operators),
  109. new SqlParameter("@OperatorDate",ip.OperatorsDate),
  110. new SqlParameter("@IsDel",ip.IsDel)
  111. };
  112. if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0)
  113. return true;
  114. return false;
  115. }
  116. /// <summary>
  117. /// 编辑
  118. /// </summary>
  119. /// <param name="sdt"></param>
  120. /// <returns></returns>
  121. public bool EditIncreasePayments(IncreasePayments ip)
  122. {
  123. string sql = "update IncreasePayments set YearMonth = @YearMonth,UserId = @UserId,Sid = @Sid,OccurrenceDate = @OccurrenceDate,Money = @Money,Remark = @Remark,Operator = @Operator,OperatorDate = @OperatorDate where Id = @Id";
  124. SqlParameter[] parameter = new SqlParameter[]{
  125. new SqlParameter("@YearMonth",ip.YearMonths),
  126. new SqlParameter("@UserId",ip.UserId),
  127. new SqlParameter("@Sid",ip.Sid),
  128. new SqlParameter("@OccurrenceDate",ip.OccurrenceDate),
  129. new SqlParameter("@Money", ip.Money),
  130. new SqlParameter("@Remark",ip.Remark),
  131. new SqlParameter("@Operator",ip.Operators),
  132. new SqlParameter("@OperatorDate",ip.OperatorsDate),
  133. new SqlParameter("@Id",ip.Id)
  134. };
  135. if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0)
  136. return true;
  137. return false;
  138. }
  139. /// <summary>
  140. /// 删除
  141. /// </summary>
  142. /// <param name="id"></param>
  143. /// <returns></returns>
  144. public bool DelIncreasePayments(int id)
  145. {
  146. if (SqlHelper.ExecuteNonQuery("update IncreasePayments set IsDel = 1 where Id = @Id", CommandType.Text, new SqlParameter("@Id", id)) > 0)
  147. return true;
  148. return false;
  149. }
  150. }
  151. }