ProceedsReceivedService.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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 ProceedsReceivedService
  14. {
  15. /// <summary>
  16. /// 查询所有
  17. /// </summary>
  18. /// <param name="sql">sql语句</param>
  19. /// <param name="param">可变参数数组</param>
  20. /// <returns>返回集合</returns>
  21. List<ProceedsReceived> excuteSql(string sql, params SqlParameter[] param)
  22. {
  23. return ServiceBase<ProceedsReceived>.excuteSql(new ProceedsReceived(), "ProceedsReceived", 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. ProceedsReceived excuteType(string sql, params SqlParameter[] param)
  32. {
  33. //查询结果放入对象集合
  34. List<ProceedsReceived> ioaList = excuteSql(sql, param);
  35. //判断集合是否为空
  36. if (ioaList == null || ioaList.Count == 0)
  37. //返回null
  38. return null;
  39. //返回单个对象
  40. return ioaList[0];
  41. }
  42. /// <summary>
  43. /// 根据编号查询对象信息
  44. /// </summary>
  45. /// <param name="id">对象编号</param>
  46. /// <returns>返回空或者单个对象信息</returns>
  47. public ProceedsReceived GetProceedsReceivedByDIId(int DIId)
  48. {
  49. //调用获取单个对象的方法
  50. return excuteType("select * from ProceedsReceived where DIId = @DIId", new SqlParameter("@DIId", DIId));
  51. }
  52. /// <summary>
  53. /// 根据编号查询对象信息
  54. /// </summary>
  55. /// <param name="id">对象编号</param>
  56. /// <returns>返回空或者单个对象信息</returns>
  57. public ProceedsReceived GetProceedsReceivedById(int id)
  58. {
  59. //调用获取单个对象的方法
  60. return excuteType("select * from ProceedsReceived where Id = @Id and isdel = 0", new SqlParameter("@Id", id));
  61. }
  62. /// <summary>
  63. /// 根据编号查询对象信息 - 集合
  64. /// </summary>
  65. /// <param name="id">对象编号</param>
  66. /// <returns>返回空或者对象集合信息</returns>
  67. public List<ProceedsReceived> GetAllByDIId(int DIId)
  68. {
  69. //调用获取单个对象的方法
  70. return excuteSql("select * from ProceedsReceived where DIId = @DIId and isdel = 0", new SqlParameter("@DIId", DIId));
  71. }
  72. /// <summary>
  73. /// 批量添加方法
  74. /// </summary>
  75. /// <param name="list"></param>
  76. /// <returns></returns>
  77. public bool AddUpCardAuditContent(List<ProceedsReceived> list)
  78. {
  79. SqlCommand cmd = SqlHelper.createCon().CreateCommand();
  80. cmd.Connection.Open();
  81. //SqlTransaction trans = cmd.Connection.BeginTransaction();
  82. try
  83. {
  84. foreach (ProceedsReceived pr in list)
  85. {
  86. cmd.CommandText = "insert into ProceedsReceived values(" + pr.DIID + ",'" + pr.SectionTime + "'," + pr.Price + "," + pr.Currency + ","
  87. + pr.ReceivablesType + ",'" + pr.Client + "','" + pr.Remark + "'," + pr.Operators + ",'"
  88. + pr.OperatorsDate + "'," + pr.IsDel + "," + pr.FID + ")";
  89. cmd.ExecuteNonQuery();
  90. }
  91. //trans.Commit();
  92. cmd.Connection.Close();
  93. return true;
  94. }
  95. catch
  96. {
  97. //trans.Rollback();
  98. cmd.Connection.Close();
  99. return false;
  100. }
  101. }
  102. /// <summary>
  103. /// 删除
  104. /// </summary>
  105. /// <param name="id"></param>
  106. /// <returns></returns>
  107. public bool DelProceedsReceived(int DIId)
  108. {
  109. if (SqlHelper.ExecuteNonQuery("delete ProceedsReceived where DIId = @DIId", CommandType.Text, new SqlParameter("@DIId", DIId)) > 0)
  110. return true;
  111. return false;
  112. }
  113. public object GetSumByDIId(int diid)
  114. {
  115. //调用获取单个对象的方法
  116. //return excuteSql("select * from ProceedsReceived where DIId = @DIId", new SqlParameter("@DIId", DIId));
  117. return SqlHelper.ExecuteScalar("select sum(Price) from ProceedsReceived where DIId = @DIId and isdel=0", CommandType.Text, new SqlParameter("@DIId", diid));
  118. }
  119. /// <summary>
  120. /// 根据收款账单id查询已收款项
  121. /// </summary>
  122. /// <param name="p"></param>
  123. /// <returns></returns>
  124. public ProceedsReceived GetProceedsReceivedByFId(int FID)
  125. {
  126. //调用获取单个对象的方法
  127. return excuteType("select * from ProceedsReceived where FID = @FID", new SqlParameter("@FID", FID));
  128. }
  129. public DataTable getAllProceedsReceivedByPro(int diid)
  130. {
  131. DataTable dt = SqlHelper.TransferProcedure("[dbo].[exec_ReceviedAccount_Recevied]", CommandType.StoredProcedure, new SqlParameter("@diid", diid));
  132. if (dt != null)
  133. return dt;
  134. return null;
  135. }
  136. }
  137. }