AttendanceAuditService.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 AttendanceAuditService
  14. {
  15. /// <summary>
  16. /// 查询所有
  17. /// </summary>
  18. /// <param name="sql">sql语句</param>
  19. /// <param name="param">可变参数数组</param>
  20. /// <returns>返回集合</returns>
  21. List<AttendanceAudit> excuteSql(string sql, params SqlParameter[] param)
  22. {
  23. return ServiceBase<AttendanceAudit>.excuteSql(new AttendanceAudit(), "AttendanceAudit", sql, CommandType.Text, param);
  24. }
  25. /// <summary>
  26. /// 根据条件获取数据集合 - 分页
  27. /// </summary>
  28. /// <param name="pageIndex"></param>
  29. /// <param name="sumPage"></param>
  30. /// <param name="totalRecord"></param>
  31. /// <param name="yearMonth"></param>
  32. /// <param name="isAudit"></param>
  33. /// <param name="uid"></param>
  34. /// <returns></returns>
  35. public List<AttendanceAudit> GetAll(int pageIndex, out int sumPage, out int totalRecord, string yearMonth, int isAudit, string uid,int did,int userID)
  36. {
  37. string sql = "select * from (select row_number() over(order by T.ApplicationPeriod) as rownum,T.*,u.did from v_attendanceAudit T join users u on T.UserId=u.id where YearMonth='" + yearMonth + "' and T.IsDel = 0 ";
  38. string sql1="select count(1) from v_attendanceAudit T join users u on T.UserId=u.id where YearMonth='"+yearMonth+"' and T.IsDel = 0";
  39. if (uid != "全部" && userID > 0 && userID != 21)
  40. {
  41. sql += " and uid =" + uid;
  42. sql1 += " and uid =" + uid;
  43. }
  44. if (userID == 21)
  45. {
  46. sql = sql + " and uid in (10,16,18,22,37,5,11,117)";
  47. sql1 = sql1 + " and uid in (10,16,18,22,37,5,11,117)";
  48. }
  49. if (isAudit == 0)
  50. {
  51. sql += " and (IsAudit = " + isAudit + " or IsAudit = 2)";
  52. sql1 += " and (IsAudit = " + isAudit + " or IsAudit = 2)";
  53. }
  54. else
  55. {
  56. sql += " and IsAudit = 1";
  57. sql1 += " and IsAudit = 1";
  58. }
  59. if (did != 99 && did != 3 && did!=2)
  60. {
  61. sql += "and U.Did=" + did;
  62. sql1 += "and U.Did=" + did;
  63. }
  64. sql += ") T where rownum between " + ((pageIndex - 1) * 10 + 1) + " and " + pageIndex * 10;
  65. List<AttendanceAudit> adas = new List<AttendanceAudit>();
  66. adas = excuteSql(sql, null);
  67. //查询总条数
  68. if (SqlHelper.ExecuteScalar(sql1, CommandType.Text, null) != null)
  69. {
  70. totalRecord = Convert.ToInt32(SqlHelper.ExecuteScalar(sql1, CommandType.Text, null));
  71. //计算出总页数
  72. sumPage = totalRecord % 10 == 0 ? totalRecord / 10 : totalRecord / 10 + 1;
  73. }
  74. else
  75. {
  76. totalRecord = 0;
  77. //计算出总页数
  78. sumPage = 1;
  79. }
  80. return adas;
  81. //return PageBase<AttendanceAudit>.excutePageSql(new AttendanceAudit(), "AttendanceAudit", "v_attendanceAudit", "Id,userId,Number,CnName,ApplicationPeriod,Subject,Attachment", "Id asc", sqlWhere, 10, pageIndex, out sumPage, out totalRecord);
  82. }
  83. }
  84. }