示例#1
0
        public PageStu Show(Stockin person, int CurrentPage = 1, int PageSize = 10)
        {
            using (IDbConnection connection = new SqlConnection(conn.ConnectionString))
            {
                var sql = @"select * from Stockin where StockInStatus=" + person.StockInStatus;
                if (person.StockInType != "")
                {
                    sql += " and StockInType=@stockInType";
                }
                if (person.CreateDate != "" && person.ModifiedDate != "")
                {
                    sql += "and CreateDate>=@createDate and ModifiedDate<=@modifiedDate";
                }

                var     list = connection.Query <Stockin>(sql, new { stockInType = person.StockInType, createDate = person.CreateDate, modifiedDate = person.ModifiedDate }).ToList();
                PageStu ps   = new PageStu();      //实例化

                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.stockins = list.Skip(PageSize * (CurrentPage - 1)).Take(PageSize).ToList();
                return(ps);
            }
        }
示例#2
0
        // GET: api/Pingjia
        public PageStu Get(int CurrentPage = 1, int PageSize = 2)
        {
            var list = dal.Show();
            //if (timeone != null && timetwo != null)
            //{
            //    list = list.Where(s => s.Atime >= timeone && s.Atime <= timetwo).ToList();
            //}
            //if (!string.IsNullOrEmpty(names))
            //{
            //    list = list.Where(s => s.Apname.Contains(names)).ToList();
            //}
            //if (xiala != 0 && xiala != null)
            //{
            //    list = list.Where(s => s.Amessage == xiala).ToList();
            //}
            PageStu ps = new PageStu();        //实例化

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