Exemplo n.º 1
0
        /////
        #region 2.0 返回分页数据 +ActionResult GetPageData()
        /// <summary>
        /// 2.0 返回分页数据
        /// </summary>
        /// <returns></returns>
        public ActionResult GetPageData()
        {
            //页码
            int pageIndex = int.Parse(Request.Params["pageIndex"]);
            //页容量
            int pageSize = int.Parse(Request.Params["pageSize"]);
            //总页数
            int pageCount = 0;
            //总记录条数
            int recordCount = 0;
            //获取分页数据
            List <MODEL.T_Paper> list =
                OperateContext.Current.BLLSession.IPaperBLL
                .GetPagedList(pageIndex, pageSize, q => q.IsDel == false, qb => qb.ID).ToList();
            //转为DTOModel
            List <MODEL.DTOModel.T_PaperDTO> listDTO = new List <MODEL.DTOModel.T_PaperDTO>();

            foreach (MODEL.T_Paper p in list)
            {
                //限制试卷名称长度
                //if (p.PaperName.Length > 28)
                //{
                //    p.PaperName = p.PaperName.Substring(0, 40) + "...";
                //}
                MODEL.DTOModel.T_PaperDTO pDTO = new MODEL.DTOModel.T_PaperDTO();
                pDTO = p.ToDTO();
                //查找试卷对应出卷人ID的姓名
                //pDTO.PaperProducerName =
                //    OperateContext.Current.BLLSession.ITeacherInfoBLL.GetListBy(ti => ti.ID == pDTO.PaperProducerID)
                //    .Select(ti => ti.Name).FirstOrDefault();
                listDTO.Add(pDTO);
            }
            //计算总页数和总记录条数
            list =
                OperateContext.Current.BLLSession.IPaperBLL.GetListBy(q => q.IsDel == false).ToList();
            recordCount = list.Count;
            if (recordCount % pageSize == 0)
            {
                pageCount = recordCount / pageSize;
            }
            else
            {
                pageCount = recordCount / pageSize + 1;
            }
            //封装为Json数据
            MODEL.FormatModel.AjaxPagedModel jsonData = new MODEL.FormatModel.AjaxPagedModel()
            {
                Data        = listDTO,
                BackUrl     = null,
                Msg         = "ok",
                Statu       = "ok",
                PageCount   = pageCount,
                RecordCount = recordCount
            };

            return(Json(jsonData, JsonRequestBehavior.AllowGet));
        }
        /// <summary>
        /// 2.0 返回分页数据
        /// </summary>
        /// <returns></returns>
        public ActionResult GetPageData()
        {
            //页码
            int pageIndex = int.Parse(Request.Params["pageIndex"]);
            //页容量
            int pageSize = int.Parse(Request.Params["pageSize"]);
            //总页数
            int pageCount = 0;
            //总记录条数
            int recordCount = 0;
            //获取分页数据
            List<MODEL.T_Paper> list =
                OperateContext.Current.BLLSession.IPaperBLL
                .GetPagedList(pageIndex, pageSize, q => q.IsDel == false, qb => qb.ID).ToList();
            //转为DTOModel
            List<MODEL.DTOModel.T_PaperDTO> listDTO = new List<MODEL.DTOModel.T_PaperDTO>();

            foreach (MODEL.T_Paper p in list)
            {
                //限制试卷名称长度
                //if (p.PaperName.Length > 28)
                //{
                //    p.PaperName = p.PaperName.Substring(0, 40) + "...";
                //}
                MODEL.DTOModel.T_PaperDTO pDTO = new MODEL.DTOModel.T_PaperDTO();
                pDTO = p.ToDTO();
                //查找试卷对应出卷人ID的姓名
                //pDTO.PaperProducerName =
                //    OperateContext.Current.BLLSession.ITeacherInfoBLL.GetListBy(ti => ti.ID == pDTO.PaperProducerID)
                //    .Select(ti => ti.Name).FirstOrDefault();
                listDTO.Add(pDTO);
            }
            //计算总页数和总记录条数
            list =
                OperateContext.Current.BLLSession.IPaperBLL.GetListBy(q => q.IsDel == false).ToList();
            recordCount = list.Count;
            if (recordCount % pageSize == 0)
                pageCount = recordCount / pageSize;
            else
                pageCount = recordCount / pageSize + 1;
            //封装为Json数据
            MODEL.FormatModel.AjaxPagedModel jsonData = new MODEL.FormatModel.AjaxPagedModel()
            {
                Data = listDTO,
                BackUrl = null,
                Msg = "ok",
                Statu = "ok",
                PageCount = pageCount,
                RecordCount = recordCount
            };

            return Json(jsonData, JsonRequestBehavior.AllowGet);
        }