コード例 #1
0
        /// <summary>
        /// 获取分页对象
        /// </summary>
        /// <typeparam name="E">需要返回的集合泛型</typeparam>
        /// <param name="ds">使用SQL Server分页存储过程后返回的对象</param>
        /// <param name="pager">分页对象 为空时,不分页返回</param>
        /// <returns></returns>
        protected virtual Task <PagerDataEntity <E> > GetPagerDataAsync <E>(DataSet ds, PagerInfo pager)
        {
            return(Task.Run(() =>
            {
                int dataIndex = 0;   //数据Index
                int total = 0;       //总页数
                int recordCount = 0; //总记录数
                if (pager == null)
                {
                    //不分页处理
                    total = -1;
                    recordCount = ds.Tables[0].Rows.Count;
                }
                else
                {
                    //分页处理
                    dataIndex = 1;
                    total = Convert.ToInt32(ds.Tables[2].Rows[0]["pagecount"]);
                    recordCount = Convert.ToInt32(ds.Tables[2].Rows[0]["recordcount"]);
                }

                var data = new PagerDataEntity <E>
                {
                    rows = JsonAppHelper.ToList <E>(ds.Tables[dataIndex]),
                    total = total,
                    page = -1,
                    records = recordCount
                };
                return data;
            }));
        }
コード例 #2
0
        /// <summary>
        /// 获取分页对象
        /// </summary>
        /// <typeparam name="E">需要返回的集合泛型</typeparam>
        /// <param name="dt">数据集合datatable</param>
        /// <param name="recordcount">记录总数</param>
        /// <param name="pager">分页对象 为空时,不分页返回</param>
        /// <returns></returns>
        protected virtual Task <PagerDataEntity <E> > GetPagerDataAysnc <E>(DataTable dt, int recordcount, PagerInfo pager)
        {
            return(Task.Run(() =>
            {
                int total = 0;       //总页数
                int recordCount = 0; //总记录数
                if (pager == null)
                {
                    //不分页处理
                    total = -1;
                    recordCount = dt.Rows.Count;
                }
                else
                {
                    //分页处理
                    total = recordcount / pager.PageSize == 0 ? 1 : (recordcount % pager.PageSize == 0 ? recordcount / pager.PageSize : recordcount / pager.PageSize + 1);

                    recordCount = recordcount;
                }

                var data = new PagerDataEntity <E>
                {
                    rows = JsonAppHelper.ToList <E>(dt),
                    total = total,
                    page = -1,
                    records = recordCount
                };


                return data;
            }));
        }
コード例 #3
0
 /// <summary>
 /// 获取分页对象
 /// </summary>
 /// <typeparam name="E">需要返回的集合泛型</typeparam>
 /// <param name="list">返回的集合</param>
 /// <param name="pager">分页对象 为空时,不分页返回</param>
 /// <returns></returns>
 protected virtual Task <PagerDataEntity <E> > GetPagerDataAsync <E>(List <E> list, PagerInfo pager)
 {
     return(Task.Run(() =>
     {
         if (pager == null)
         {
             var data = new PagerDataEntity <E>
             {
                 rows = list,
                 total = -1,
                 page = -1,
                 records = list.Count
             };
             return data;
         }
         else
         {
             int total = pager.RecordCount / pager.PageSize == 0 ? 1 : (pager.RecordCount % pager.PageSize == 0 ? pager.RecordCount / pager.PageSize : pager.RecordCount / pager.PageSize + 1);
             var data = new PagerDataEntity <E>
             {
                 rows = list,
                 total = total,
                 page = pager.CurrenetPageIndex,
                 records = pager.RecordCount
             };
             return data;
         }
     }));
 }