对结果集进行分页显示

 

步骤:

1 有一个方法调用处。

2 处理的Request实例中page属性是指当前页,pageSize属性石指一页显示多少条。

3 编写递归方法

3 计算当page * pageSize 是否小于Request的总数量OrderTotal。

if (recursive && page * pageSize < response.OrderSearch.OrderTotal)

 

代码实例

        #region 订单列表示例
        /// <summary>
        /// 获取订单列表
        /// </summary>
        /// <param name="startDate">开始时间</param>
        /// <param name="endDate">结束的时间</param>
        /// <param name="orderState">订单状态</param>
        /// <returns>京东平台线上商品列表结果集</returns>
        public List<OrderInfo> GetOrderList(DateTime startDate, DateTime endDate, string orderState)
        {
            Int32 totalCount;
            string newApiOrderStates = "WAIT_SELLER_STOCK_OUT,WAIT_SELLER_DELIVERY,TRADE_CANCELED,WAIT_BUYER_PAY,FINISHED_L";
            if (newApiOrderStates.IndexOf(orderState, StringComparison.InvariantCultureIgnoreCase) >= 0)
            {
                return GetOrderList(startDate, endDate, orderState, 1, 100, out totalCount, true);
            }
            else
            {
                totalCount = 0;
                return new List<OrderInfo>();
            }
        }
        #endregion


递归方法

       #region 获取京东平台线上商品列表
        /// <summary>
        /// 获取京东平台线上商品列表
        /// </summary>
        /// <param name="startDate">开始时间</param>
        /// <param name="endDate">结束的时间</param>
        /// <param name="orderState">订单状态</param>
        /// <param name="page">当前页</param>
        /// <param name="pageSize">一页显示几条记录</param>
        /// <param name="totalCount">总记录数</param>
        /// <param name="recursive">是否回归的标识</param>
        /// <returns>京东平台线上商品列表结果集</returns>
        private List<OrderInfo> GetOrderList(DateTime startDate, DateTime endDate, string orderState, int page, int pageSize, out Int32 totalCount, bool recursive)
        {
            List<OrderInfo> list = new List<OrderInfo>();
            try
            {
                OrderSearchRequest request = new OrderSearchRequest();
                request.StartDate = startDate; //开始时间
                request.EndDate = endDate; //结束时间
                request.OrderState = orderState;
                request.Page = page; //当前页
                request.PageSize = pageSize; //一页显示几条记录
                OrderSearchResponse response = Client.Execute(request, Shop.SessionKey);
                if (!response.IsError)
                {
                    
                    if (response.OrderSearch == null || response.OrderSearch.OrderInfoList == null || response.OrderSearch.OrderInfoList.Count == 0)
                    {
                        totalCount = 0;
                        return list;
                    }

                    list.AddRange(response.OrderSearch.OrderInfoList);

                    totalCount = response.OrderSearch.OrderTotal;

                    if (recursive && page * pageSize < response.OrderSearch.OrderTotal)
                    {
                        list.AddRange(GetOrderList(startDate, endDate, orderState, ++page, pageSize, out totalCount, true));
                    }

                    return list;
                }
                else
                {
                    throw new Exception(response.ErrCode + "" + response.ErrMsg);
                }
            }
            catch (Exception ex)
            {
                OD.BLL.ErrorLogBll.ErrorLOG("OD.Jingdong.JDGetNewTrade", 71, DateTime.Now.ToString(), "获取京东平台线上商品列表" + ex.Message.ToString());
                throw ex;
            }
        }
        #endregion

 

 

 

 

 

posted @ 2012-11-03 12:02  杨斌_济南  阅读(878)  评论(0编辑  收藏  举报