/// <summary> /// 获取总条目数. /// </summary> /// <param name="storeType">分页设置的存储方式.</param> /// <param name="storeKey">分页设置的存储关键字.</param> /// <returns>总条目数.</returns> public static int GetItemCount(PagerStoreType storeType, string storeKey) { if (string.IsNullOrEmpty(storeKey)) { return(0); } switch (storeType) { case PagerStoreType.Cookie: try { return(Convert.ToInt32(HttpContext.Current.Request.Cookies[makeItemCountStoreKey(storeKey)].Value)); } catch { return(0); } case PagerStoreType.Session: try { return(Convert.ToInt32(HttpContext.Current.Session[makeItemCountStoreKey(storeKey)])); } catch { return(0); } case PagerStoreType.Query: try { return(Convert.ToInt32(HttpContext.Current.Request[makeItemCountStoreKey(storeKey)])); } catch { return(0); } default: return(0); } }
/// <summary> /// 创建一个分页设置. /// </summary> /// <param name="storeType">分页设置的存储方式.</param> /// <param name="storeKey">分页设置的存储关键字.</param> /// <param name="paginalCount">每页包含的数据条数, 如果小于等于 0, 则默认为 20.</param> public PagerSetting(PagerStoreType storeType, string storeKey, int paginalCount) : base(PagerBuilder.GetIndex(storeType, storeKey), paginalCount) { if (string.IsNullOrEmpty(storeKey)) { throw new ArgumentNullException("storeKey", "分页设置的存储关键字不能为空"); } this.storeType = storeType; this.storeKey = storeKey; this.ItemCount = PagerBuilder.GetItemCount(storeType, storeKey); }