using System; using System.Collections.Generic; using System.Linq; using System.Text; using Models; using System.Data.SqlClient; using System.Data; namespace DAL { /// /// 考勤审核多表联查数据访问类 /// public class AttendanceAuditService { /// /// 查询所有 /// /// sql语句 /// 可变参数数组 /// 返回集合 List excuteSql(string sql, params SqlParameter[] param) { return ServiceBase.excuteSql(new AttendanceAudit(), "AttendanceAudit", sql, CommandType.Text, param); } /// /// 根据条件获取数据集合 - 分页 /// /// /// /// /// /// /// /// public List GetAll(int pageIndex, out int sumPage, out int totalRecord, string yearMonth, int isAudit, string uid,int did,int userID) { 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 "; string sql1="select count(1) from v_attendanceAudit T join users u on T.UserId=u.id where YearMonth='"+yearMonth+"' and T.IsDel = 0"; if (uid != "全部" && userID > 0 && userID != 21) { sql += " and uid =" + uid; sql1 += " and uid =" + uid; } if (userID == 21) { sql = sql + " and uid in (10,16,18,22,37,5,11,117)"; sql1 = sql1 + " and uid in (10,16,18,22,37,5,11,117)"; } if (isAudit == 0) { sql += " and (IsAudit = " + isAudit + " or IsAudit = 2)"; sql1 += " and (IsAudit = " + isAudit + " or IsAudit = 2)"; } else { sql += " and IsAudit = 1"; sql1 += " and IsAudit = 1"; } if (did != 99 && did != 3 && did!=2) { sql += "and U.Did=" + did; sql1 += "and U.Did=" + did; } sql += ") T where rownum between " + ((pageIndex - 1) * 10 + 1) + " and " + pageIndex * 10; List adas = new List(); adas = excuteSql(sql, null); //查询总条数 if (SqlHelper.ExecuteScalar(sql1, CommandType.Text, null) != null) { totalRecord = Convert.ToInt32(SqlHelper.ExecuteScalar(sql1, CommandType.Text, null)); //计算出总页数 sumPage = totalRecord % 10 == 0 ? totalRecord / 10 : totalRecord / 10 + 1; } else { totalRecord = 0; //计算出总页数 sumPage = 1; } return adas; //return PageBase.excutePageSql(new AttendanceAudit(), "AttendanceAudit", "v_attendanceAudit", "Id,userId,Number,CnName,ApplicationPeriod,Subject,Attachment", "Id asc", sqlWhere, 10, pageIndex, out sumPage, out totalRecord); } } }