UpCardAuditService.cs 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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 UpCardAuditService
  14. {
  15. /// <summary>
  16. /// 查询所有
  17. /// </summary>
  18. /// <param name="sql">sql语句</param>
  19. /// <param name="param">可变参数数组</param>
  20. /// <returns>返回集合</returns>
  21. List<UpCardAudit> excuteSql(string sql, params SqlParameter[] param)
  22. {
  23. return ServiceBase<UpCardAudit>.excuteSql(new UpCardAudit(), "UpCardAudit", 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. UpCardAudit excuteType(string sql, params SqlParameter[] param)
  32. {
  33. //查询结果放入对象集合
  34. List<UpCardAudit> ucaList = excuteSql(sql, param);
  35. //判断集合是否为空
  36. if (ucaList == null || ucaList.Count == 0)
  37. //返回null
  38. return null;
  39. //返回单个对象
  40. return ucaList[0];
  41. }
  42. /// <summary>
  43. /// 根据编号查询对象信息
  44. /// </summary>
  45. /// <param name="id">对象编号</param>
  46. /// <returns>返回空或者单个对象信息</returns>
  47. public List<UpCardAudit> GetUpCardAuditByYearMonth(int uid, string YearMonth)
  48. {
  49. //调用获取单个对象的方法
  50. return excuteSql("select * from UpCardAudit where uid = @uid and YearMonth = @YearMonth and IsDel = 0 order by Id", new SqlParameter("@uid", uid), new SqlParameter("@YearMonth", YearMonth));
  51. }
  52. /// <summary>
  53. /// 根据编号查询对象信息
  54. /// </summary>
  55. /// <param name="id">对象编号</param>
  56. /// <returns>返回空或者单个对象信息</returns>
  57. public List<UpCardAudit> GetYearMonth()
  58. {
  59. //调用获取单个对象的方法
  60. return excuteSql("select * from UpCardAudit where IsDel = 0 order by Id desc");
  61. }
  62. /// <summary>
  63. /// 根据编号查询对象信息
  64. /// </summary>
  65. /// <param name="id">对象编号</param>
  66. /// <returns>返回空或者单个对象信息</returns>
  67. public UpCardAudit GetUpCardAuditByID(int id)
  68. {
  69. //调用获取单个对象的方法
  70. return excuteType("select * from UpCardAudit where Id = @id and IsDel = 0", new SqlParameter("@id", id));
  71. }
  72. /// <summary>
  73. /// 根据条件获取数据集合
  74. /// </summary>
  75. /// <param name="yearMonth"></param>
  76. /// <param name="isAudit"></param>
  77. /// <param name="userid"></param>
  78. /// <returns></returns>
  79. public List<UpCardAudit> GetUpCardAudit(int pageIndex, out int sumPage, out int totalRecord, string yearMonth, string isAudit, string userid)
  80. {
  81. string sqlwhere = "YearMonth = '" + yearMonth + "' and IsDel = 0 and uid = " + userid + "";
  82. if (isAudit == "0")
  83. sqlwhere += " and (IsAudit = " + isAudit + " or IsAudit = 2)";
  84. else
  85. sqlwhere += " and IsAudit = 1";
  86. return PageBase<UpCardAudit>.excutePageSql(new UpCardAudit(), "UpCardAudit", "UpCardAudit", "*", "id desc", sqlwhere, 15, pageIndex, out sumPage, out totalRecord);
  87. }
  88. /// <summary>
  89. /// 新增
  90. /// </summary>
  91. /// <param name="sdt">对象</param>
  92. public bool AddUpCardAudit(UpCardAudit u, out int id)
  93. {
  94. string sql = "insert into UpCardAudit([Uid],[YearMonth],[ApplicationPeriod],[Attachment],[Subject],[IsAudit],[IsDel]) values(" + u.Uid + ",'" + u.YearMonth + "','" + u.ApplicationPeriod + "','" + u.Attachment + "','" + u.Subject + "'," + u.IsAudit + "," + u.IsDel + ");SELECT @@IDENTITY";
  95. int obj = Convert.ToInt32(SqlHelper.ExecuteScalar(sql, CommandType.Text));
  96. if (obj > 0)
  97. {
  98. id = obj;
  99. return true;
  100. }
  101. id = 0;
  102. return false;
  103. }
  104. /// <summary>
  105. /// 编辑
  106. /// </summary>
  107. /// <param name="uca"></param>
  108. /// <returns></returns>
  109. public bool UpdateUpCardAudit(UpCardAudit uca)
  110. {
  111. string Attachment = "";
  112. if (!string.IsNullOrEmpty(uca.Attachment))
  113. Attachment = ", Attachment = '" + uca.Attachment + "'";
  114. string sql = "update UpCardAudit set ApplicationPeriod = @ApplicationPeriod " + Attachment + " , Subject = @Subject where id = @Id";
  115. if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, new SqlParameter("@ApplicationPeriod", uca.ApplicationPeriod), new SqlParameter("@Subject", uca.Subject), new SqlParameter("@Id", uca.Id)) > 0)
  116. return true;
  117. return false;
  118. }
  119. /// <summary>
  120. /// 删除
  121. /// </summary>
  122. /// <param name="id"></param>
  123. /// <returns></returns>
  124. public bool DelUpCardAudit(int id)
  125. {
  126. if (SqlHelper.ExecuteNonQuery("update UpCardAudit set IsDel = 1 where Id = @Id", CommandType.Text, new SqlParameter("@Id", id)) > 0)
  127. return true;
  128. return false;
  129. }
  130. /// <summary>
  131. /// 更改审核状态
  132. /// </summary>
  133. /// <param name="isAudit"></param>
  134. /// <param name="auditRemark"></param>
  135. /// <param name="Operate"></param>
  136. /// <param name="OperateTime"></param>
  137. /// <param name="id"></param>
  138. /// <returns></returns>
  139. public bool UpdeteIsAudit(int isAudit, string auditRemark, int operate, string operateTime, int id)
  140. {
  141. string sql = "update UpCardAudit set IsAudit = @IsAudit,AuditRemark=@AuditRemark,Operate=@Operate,OperateTime=@OperateTime where Id = @Id";
  142. SqlParameter[] parameter = new SqlParameter[]{
  143. new SqlParameter("@IsAudit",isAudit),
  144. new SqlParameter("@AuditRemark",auditRemark),
  145. new SqlParameter("@Operate",operate),
  146. new SqlParameter("@OperateTime",operateTime),
  147. new SqlParameter("@Id",id)
  148. };
  149. if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0)
  150. return true;
  151. return false;
  152. }
  153. public List<UpCardAudit> GetError(int userId, string yearMonth)
  154. {
  155. string sql = "select * from UpCardAudit where uid = " + userId + " and YearMonth = '" + yearMonth + "' and Isdel=0 "
  156. + "AND Id NOT IN (select UCAid from UpCardAuditContent where Isdel=0 "
  157. + "AND UCAid IN (select Id from UpCardAudit where uid = " + userId + " and YearMonth = '" + yearMonth + "' and IsDel = 0))";
  158. return excuteSql(sql);
  159. }
  160. }
  161. }