UpCardAuditContentService.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. public class UpCardAuditContentService
  11. {
  12. /// <summary>
  13. /// 查询所有
  14. /// </summary>
  15. /// <param name="sql">sql语句</param>
  16. /// <param name="param">可变参数数组</param>
  17. /// <returns>返回集合</returns>
  18. List<UpCardAuditContent> excuteSql(string sql, params SqlParameter[] param)
  19. {
  20. return ServiceBase<UpCardAuditContent>.excuteSql(new UpCardAuditContent(), "UpCardAuditContent", sql, CommandType.Text, param);
  21. }
  22. /// <summary>
  23. /// 获取单个对象
  24. /// </summary>
  25. /// <param name="sql">sql语句</param>
  26. /// <param name="param">可变参数数组</param>
  27. /// <returns>返回空或者单个对象</returns>
  28. UpCardAuditContent excuteType(string sql, params SqlParameter[] param)
  29. {
  30. //查询结果放入对象集合
  31. List<UpCardAuditContent> cList = excuteSql(sql, param);
  32. //判断集合是否为空
  33. if (cList == null || cList.Count == 0)
  34. //返回null
  35. return null;
  36. //返回单个对象
  37. return cList[0];
  38. }
  39. /// <summary>
  40. /// 根据编号查询对象信息
  41. /// </summary>
  42. /// <param name="id">对象编号</param>
  43. /// <returns>返回空或者单个对象信息</returns>
  44. public UpCardAuditContent GetUpCardAuditContentByID(int id)
  45. {
  46. //调用获取单个对象的方法
  47. return excuteType("select * from UpCardAuditContent where Id = @id and IsDel = 0", new SqlParameter("@id", id));
  48. }
  49. /// <summary>
  50. /// 根据外键编号查询数据集合
  51. /// </summary>
  52. /// <param name="uCAid"></param>
  53. /// <returns></returns>
  54. public List<UpCardAuditContent> GetUpCardAuditContent(int uCAid)
  55. {
  56. return excuteSql("select * from UpCardAuditContent where IsDel = 0 and UCAid = @UCAid", new SqlParameter("@UCAid", uCAid));
  57. }
  58. /// <summary>
  59. /// 根据外键编号查询数据集合
  60. /// </summary>
  61. /// <param name="uCAid"></param>
  62. /// <returns></returns>
  63. public UpCardAuditContent GetByUCAID(int uCAid)
  64. {
  65. return excuteType("select * from UpCardAuditContent where IsDel = 0 and UCAid = @UCAid", new SqlParameter("@UCAid", uCAid));
  66. }
  67. /// <summary>
  68. /// 根据条件查询数据
  69. /// </summary>
  70. /// <param name="upCardDate"></param>
  71. /// <returns></returns>
  72. public UpCardAuditContent GetUpCardAuditContent(string upCardDate)
  73. {
  74. return excuteType("select * from UpCardAuditContent where IsDel = 0 and UpCardDate = @upCardDate", new SqlParameter("@UpCardDate", upCardDate));
  75. }
  76. /// <summary>
  77. /// 根据条件查询数据集合
  78. /// </summary>
  79. /// <param name="upCardDate"></param>
  80. /// <returns></returns>
  81. public List<UpCardAuditContent> GetUpCardAuditContentList(string upCardDate)
  82. {
  83. return excuteSql("select * from UpCardAuditContent where IsDel = 0 and UpCardDate = @upCardDate", new SqlParameter("@UpCardDate", upCardDate));
  84. }
  85. /// <summary>
  86. /// 根据条件查询数据集合
  87. /// </summary>
  88. /// <param name="upCardDate"></param>
  89. /// <returns></returns>
  90. public List<UpCardAuditContent> GetContentList(string yearmonth, string number,string date)
  91. {
  92. return excuteSql("SELECT ucc.* FROM UpCardAuditContent ucc JOIN UpCardAudit uc ON ucc.UCAid=uc.Id JOIN Users us ON us.Id=uc.uid where ucc.IsDel=0 AND uc.IsDel=0 and us.Number=" + number + " AND uc.YearMonth='" + yearmonth + "' And ucc.UpCardDate='" + date + "' ORDER BY ucc.UpCardDate");
  93. }
  94. /// <summary>
  95. /// 批量添加方法
  96. /// </summary>
  97. /// <param name="list"></param>
  98. /// <returns></returns>
  99. public bool AddUpCardAuditContent(List<UpCardAuditContent> list)
  100. {
  101. SqlCommand cmd = SqlHelper.createCon().CreateCommand();
  102. cmd.Connection.Open();
  103. SqlTransaction trans = cmd.Connection.BeginTransaction();
  104. try
  105. {
  106. foreach (UpCardAuditContent u in list)
  107. {
  108. cmd.CommandText = "insert into UpCardAuditContent values(" + u.UCAid + "," + u.Did + ",'" + u.UpCardDate + "','" + u.UpCardPeriod + "'," + u.UpCardHours + "," + u.IsDel + ")";
  109. cmd.ExecuteNonQuery();
  110. }
  111. trans.Commit();
  112. cmd.Connection.Close();
  113. return true;
  114. }
  115. catch
  116. {
  117. trans.Rollback();
  118. cmd.Connection.Close();
  119. return false;
  120. }
  121. }
  122. /// <summary>
  123. /// 批量编辑方法
  124. /// </summary>
  125. /// <param name="list"></param>
  126. /// <returns></returns>
  127. public bool UpdateUpCardAuditContent(List<UpCardAuditContent> list)
  128. {
  129. SqlCommand cmd = SqlHelper.createCon().CreateCommand();
  130. cmd.Connection.Open();
  131. SqlTransaction trans = cmd.Connection.BeginTransaction();
  132. try
  133. {
  134. foreach (UpCardAuditContent u in list)
  135. {
  136. cmd.CommandText = "update UpCardAuditContent set Did = " + u.Did + " , UpCardDate = '" + u.UpCardDate + "' , UpCardPeriod = '" + u.UpCardPeriod + "' , UpCardHours= " + u.UpCardHours + " where id = " + u.Id + "";
  137. cmd.ExecuteNonQuery();
  138. }
  139. trans.Commit();
  140. cmd.Connection.Close();
  141. return true;
  142. }
  143. catch
  144. {
  145. trans.Rollback();
  146. cmd.Connection.Close();
  147. return false;
  148. }
  149. }
  150. /// <summary>
  151. /// 删除方法
  152. /// </summary>
  153. /// <param name="id"></param>
  154. /// <returns></returns>
  155. public bool DelUpcardAuditContent(int id)
  156. {
  157. if (SqlHelper.ExecuteNonQuery("update UpcardAuditContent set IsDel = 1 where Id = @Id", CommandType.Text, new SqlParameter("@Id", id)) > 0)
  158. return true;
  159. return false;
  160. }
  161. public bool add(UpCardAuditContent u)
  162. {
  163. if (SqlHelper.ExecuteNonQuery("insert into UpCardAuditContent values(" + u.UCAid + "," + u.Did + ",'" + u.UpCardDate + "','" + u.UpCardPeriod + "'," + u.UpCardHours + "," + u.IsDel + ")", CommandType.Text) > 0)
  164. return true;
  165. return false;
  166. }
  167. }
  168. }