예제 #1
0
        public PageWarehouse ShowWarehouse(string name = "", int CurrentPage = 1, int Pagesize = 5)
        {
            var list = warehouseDAL.ShowWarehouse();

            //if (time1 != null && time2 != null)
            //{
            //    list = list.Where(s => s.CreateDate >= time1 && s.CreateDate <= time2).ToList();
            //}
            if (!string.IsNullOrEmpty(name))
            {
                list = list.Where(s => s.WarehouseName.Contains(name)).ToList();
            }

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

            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.warehouses = list.Skip(Pagesize * (CurrentPage - 1)).Take(Pagesize).ToList();
            return(ps);
        }