Ejemplo n.º 1
0
        public PageSupplier SupplierShow(string Name, Nullable <DateTime> time1, Nullable <DateTime> time2, int PageSize = 5, int CurrentPage = 1)
        {
            var list = dal.SupplierShow();

            if (time1 != null && time2 != null)
            {
                list = list.Where(s => s.CreateDate >= time1 && s.CreateDate <= time2).ToList();
            }
            if (Name != null)
            {
                list = list.Where(s => s.SupplierName.Contains(Name)).ToList();
            }


            PageSupplier ps = new PageSupplier(); //实例化

            ps.TotalCount = list.Count();         //总记录数

            if (ps.TotalCount % PageSize == 0)    //计算总页数
            {
                ps.TotalPage = ps.TotalCount / PageSize;
            }
            else
            {
                ps.TotalPage = (ps.TotalCount / PageSize) + 1;
            }

            //纠正index页
            if (CurrentPage < 1)
            {
                CurrentPage = 1;
            }
            if (CurrentPage > ps.TotalPage)
            {
                CurrentPage = ps.TotalPage;
            }
            //赋值index为当前页
            ps.CurrentPage = CurrentPage;
            //linq查询
            ps.Suppliers = list.Skip(PageSize * (CurrentPage - 1)).Take(PageSize).ToList();
            return(ps);
        }