ForeignReceivablesService.cs 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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 ForeignReceivablesService
  14. {
  15. /// <summary>
  16. /// 查询所有
  17. /// </summary>
  18. /// <param name="sql">sql语句</param>
  19. /// <param name="param">可变参数数组</param>
  20. /// <returns>返回集合</returns>
  21. List<ForeignReceivables> excuteSql(string sql, params SqlParameter[] param)
  22. {
  23. return ServiceBase<ForeignReceivables>.excuteSql(new ForeignReceivables(), "ForeignReceivables", 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. ForeignReceivables excuteType(string sql, params SqlParameter[] param)
  32. {
  33. //查询结果放入对象集合
  34. List<ForeignReceivables> 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 ForeignReceivables GetForeignReceivablesByDIId(int DIId)
  48. {
  49. //调用获取单个对象的方法
  50. return excuteType("select * from ForeignReceivables where DIId = @DIId and isdel = 0", new SqlParameter("@DIId", DIId));
  51. }
  52. /// <summary>
  53. /// 根据编号和添加模块 查询对象信息
  54. /// </summary>
  55. /// <param name="id">对象编号</param>
  56. /// <returns>返回空或者单个对象信息</returns>
  57. public ForeignReceivables GetForeignReceivablesByDIId(int DIId,int AddingWay)
  58. {
  59. //调用获取单个对象的方法
  60. return excuteType("select * from ForeignReceivables where DIId = @DIId and AddingWay = @AddingWay and isdel = 0", new SqlParameter("@DIId", DIId), new SqlParameter("@AddingWay", AddingWay));
  61. }
  62. /// <summary>
  63. /// 根据编号查询对象信息 - 集合
  64. /// </summary>
  65. /// <param name="id">对象编号</param>
  66. /// <returns>返回空或者对象集合信息</returns>
  67. public List<ForeignReceivables> GetAllByDIId(int DIId)
  68. {
  69. //调用获取单个对象的方法
  70. return excuteSql("select * from ForeignReceivables where DIId = @DIId", new SqlParameter("@DIId", DIId));
  71. }
  72. /// <summary>
  73. /// 批量添加方法
  74. /// </summary>
  75. /// <param name="list"></param>
  76. /// <returns></returns>
  77. public bool AddUpCardAuditContent(List<ForeignReceivables> list)
  78. {
  79. SqlCommand cmd = SqlHelper.createCon().CreateCommand();
  80. cmd.Connection.Open();
  81. //SqlTransaction trans = cmd.Connection.BeginTransaction();
  82. try
  83. {
  84. foreach (ForeignReceivables fr in list)
  85. {
  86. cmd.CommandText = "insert into ForeignReceivables values("+fr.Id+"," + fr.DIId + ",'" + fr.PriceName + "'," + fr.Price + "," + fr.Count + ",'" + fr.Unit + "'," + fr.ItemSumPrice + ",'" + fr.To + "','" + fr.ToTel + "','" + fr.PayDate + "','" + fr.Attention + "'," + fr.Operators + ",'" + fr.OperatorsDate + "'," + fr.IsDel +","+fr.Rate+",'"+fr.Currency+ "','" + fr.AddingWay + "')";
  87. cmd.ExecuteNonQuery();
  88. }
  89. //trans.Commit();
  90. cmd.Connection.Close();
  91. return true;
  92. }
  93. catch
  94. {
  95. //trans.Rollback();
  96. cmd.Connection.Close();
  97. return false;
  98. }
  99. }
  100. /// <summary>
  101. /// 删除
  102. /// </summary>
  103. /// <param name="id"></param>
  104. /// <returns></returns>
  105. public bool DelForeignReceivables(int DIId)
  106. {
  107. if (SqlHelper.ExecuteNonQuery("delete ForeignReceivables where DIId = @DIId", CommandType.Text, new SqlParameter("@DIId", DIId)) > 0)
  108. return true;
  109. return false;
  110. }
  111. public float GetSumForForeignReceivables(int diid)
  112. {
  113. object o=SqlHelper.ExecuteScalar("select sum(ItemSumPrice) from ForeignReceivables where isdel = 0 and diid="+diid,CommandType.Text,null);
  114. if (o != null && o.ToString()!="")
  115. return float.Parse(o.ToString());
  116. else
  117. return 0;
  118. }
  119. /// <summary>
  120. /// 获取所有收款信息(应收、已收)
  121. /// </summary>
  122. /// <param name="p"></param>
  123. /// <returns></returns>
  124. public DataTable getAllForReceivables(int diid)
  125. {
  126. DataTable dt = SqlHelper.TransferProcedure("[dbo].[exec_ReceviedAccount]", CommandType.StoredProcedure, new SqlParameter("@diid", diid));
  127. if (dt != null)
  128. return dt;
  129. return null;
  130. }
  131. /// <summary>
  132. /// 查询应收款项最大id
  133. /// </summary>
  134. /// <returns></returns>
  135. public int GetMaxID()
  136. {
  137. object result = SqlHelper.ExecuteScalar("select max(id) from ForeignReceivables", CommandType.Text, null);
  138. if (result != null)
  139. return Convert.ToInt32(result);
  140. else
  141. return 0;
  142. }
  143. }
  144. }