DailyFeePaymentContentService.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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. /// /// <summary>
  12. /// 日常费用付款申请详细数据访问类
  13. /// </summary>
  14. /// </summary>
  15. public class DailyFeePaymentContentService
  16. {
  17. /// <summary>
  18. /// 查询所有
  19. /// </summary>
  20. /// <param name="sql">sql语句</param>
  21. /// <param name="param">可变参数数组</param>
  22. /// <returns>返回集合</returns>
  23. List<DailyFeePaymentContent> excuteSql(string sql, params SqlParameter[] param)
  24. {
  25. return ServiceBase<DailyFeePaymentContent>.excuteSql(new DailyFeePaymentContent(), "DailyFeePaymentContent", sql, CommandType.Text, param);
  26. }
  27. /// <summary>
  28. /// 获取单个对象
  29. /// </summary>
  30. /// <param name="sql">sql语句</param>
  31. /// <param name="param">可变参数数组</param>
  32. /// <returns>返回空或者单个对象</returns>
  33. DailyFeePaymentContent excuteType(string sql, params SqlParameter[] param)
  34. {
  35. //查询结果放入对象集合
  36. List<DailyFeePaymentContent> cdList = excuteSql(sql, param);
  37. //判断集合是否为空
  38. if (cdList == null || cdList.Count == 0)
  39. //返回null
  40. return null;
  41. //返回单个对象
  42. return cdList[0];
  43. }
  44. /// <summary>
  45. /// 根据编号查询对象信息
  46. /// </summary>
  47. /// <param name="id">对象编号</param>
  48. /// <returns>返回空或者单个对象信息</returns>
  49. public DailyFeePaymentContent GetDailyFeePaymentContentByID(int id)
  50. {
  51. //调用获取单个对象的方法
  52. return excuteType("select * from DailyFeePaymentContent where Id = @id", new SqlParameter("@id", id));
  53. }
  54. /// <summary>
  55. /// 根据编号查询对象信息
  56. /// </summary>
  57. /// <param name="id">对象编号</param>
  58. /// <returns>返回空或者单个对象信息</returns>
  59. public List<DailyFeePaymentContent> GetDailyFeePaymentContentByDFPID(int DFPID)
  60. {
  61. //调用获取单个对象的方法
  62. return excuteSql("select * from DailyFeePaymentContent where DFPID = @DFPID ORDER BY ID", new SqlParameter("@DFPID", DFPID));
  63. }
  64. /// <summary>
  65. /// 增加
  66. /// </summary>
  67. /// <param name="dfpc"></param>
  68. /// <returns></returns>
  69. public bool AddDailyFeePaymentContent(List<DailyFeePaymentContent> list)
  70. {
  71. SqlCommand cmd = SqlHelper.createCon().CreateCommand();
  72. cmd.Connection.Open();
  73. SqlTransaction trans = cmd.Connection.BeginTransaction();
  74. try
  75. {
  76. foreach (DailyFeePaymentContent dfpc in list)
  77. {
  78. cmd.CommandText = "insert into DailyFeePaymentContent values(" + dfpc.DFPID + ",'" + dfpc.PriceName + "'," + dfpc.Count + "," + dfpc.Price + "," + dfpc.ItemSumPrice + ",'" + dfpc.Remark + "')";
  79. cmd.ExecuteNonQuery();
  80. }
  81. trans.Commit();
  82. cmd.Connection.Close();
  83. return true;
  84. }
  85. catch
  86. {
  87. trans.Rollback();
  88. cmd.Connection.Close();
  89. return false;
  90. }
  91. }
  92. /// <summary>
  93. /// 编辑
  94. /// </summary>
  95. /// <param name="sdt"></param>
  96. /// <returns></returns>
  97. public bool EditDailyFeePaymentContent(DailyFeePaymentContent dfpc)
  98. {
  99. string sql = "update DailyFeePaymentContent set PriceName = @PriceName,Count = @Count,Price = @Price,ItemSumPrice = @ItemSumPrice,Remark = @Remark where Id = @Id";
  100. SqlParameter[] parameter = new SqlParameter[] {
  101. new SqlParameter("@PriceName",dfpc.PriceName),
  102. new SqlParameter("@Count",dfpc.Count),
  103. new SqlParameter("@Price",dfpc.Price),
  104. new SqlParameter("@ItemSumPrice",dfpc.ItemSumPrice),
  105. new SqlParameter("@Remark",dfpc.Remark),
  106. new SqlParameter("@Id",dfpc.Id)
  107. };
  108. if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0)
  109. return true;
  110. return false;
  111. }
  112. /// <summary>
  113. /// 删除
  114. /// </summary>
  115. /// <param name="id"></param>
  116. /// <returns></returns>
  117. public bool DelDailyFeePaymentContent(int id)
  118. {
  119. if (SqlHelper.ExecuteNonQuery("delete DailyFeePaymentContent where Id = @Id", CommandType.Text, new SqlParameter("@Id", id)) > 0)
  120. return true;
  121. return false;
  122. }
  123. /// <summary>
  124. /// 删除
  125. /// </summary>
  126. /// <param name="id"></param>
  127. /// <returns></returns>
  128. public bool DelDailyFeePaymentContentByDFPID(int DFPID)
  129. {
  130. if (SqlHelper.ExecuteNonQuery("delete DailyFeePaymentContent where DFPID = @DFPID", CommandType.Text, new SqlParameter("@DFPID", DFPID)) > 0)
  131. return true;
  132. return false;
  133. }
  134. /// <summary>
  135. /// LiuChengYi 2014/4/25
  136. /// 日常支付金额
  137. /// </summary>
  138. /// <param name="startTime"></param>
  139. /// <param name="endTime"></param>
  140. /// <returns></returns>
  141. public Double DelDailyFeePaymentContentByDateTime(string startTime, string endTime)
  142. {
  143. double DailyExpensesMoney;
  144. SqlParameter[] pars =
  145. {
  146. new SqlParameter("@startTime",startTime),
  147. new SqlParameter("@endTime",endTime)
  148. };
  149. DataTable dt = SqlHelper.TransferProcedure("dailyFeePaymentContent_Report", CommandType.StoredProcedure, pars);
  150. if (dt.Rows.Count > 0)
  151. {
  152. if (dt.Rows[0][0].ToString() != null && dt.Rows[0][0].ToString() != "")
  153. {
  154. DailyExpensesMoney = Convert.ToDouble(dt.Rows[0][0].ToString());
  155. }
  156. else
  157. {
  158. DailyExpensesMoney = 0;
  159. }
  160. }
  161. else
  162. {
  163. DailyExpensesMoney = 0;
  164. }
  165. return DailyExpensesMoney;
  166. }
  167. }
  168. }