Exemplo n.º 1
0
        /// <summary>
        /// 为 StoreType 属性为 Query 的 PagerSetting 生成分页的 HTML 代码.
        /// </summary>
        /// <param name="htmlTemplate">HTML 模板.</param>
        /// <param name="pagerSetting">分页设置.</param>
        /// <param name="actionType">分页操作的类型.</param>
        /// <param name="querySettings">查询条件设置列表.</param>
        /// <returns>分页 HTML 代码.</returns>
        public static string MakePagerHTML(string htmlTemplate, PagerSetting pagerSetting, PagerActionType actionType, IList <QuerySetting> querySettings)
        {
            if (string.IsNullOrEmpty(htmlTemplate) || null == pagerSetting || pagerSetting.StoreType != PagerStoreType.Query)
            {
                return(string.Empty);
            }

            string query = string.Empty;

            switch (actionType)
            {
            case PagerActionType.First:
                query = string.Format("{0}=1&{1}={2}", makeIndexStoreKey(pagerSetting.StoreKey), makeItemCountStoreKey(pagerSetting.StoreKey), pagerSetting.ItemCount);
                break;

            case PagerActionType.Last:
                query = string.Format("{0}={1}&{2}={3}", makeIndexStoreKey(pagerSetting.StoreKey), pagerSetting.Count, makeItemCountStoreKey(pagerSetting.StoreKey), pagerSetting.ItemCount);
                break;

            case PagerActionType.Next:
                query = string.Format("{0}={1}&{2}={3}", makeIndexStoreKey(pagerSetting.StoreKey), pagerSetting.Index + 1, makeItemCountStoreKey(pagerSetting.StoreKey), pagerSetting.ItemCount);
                break;

            case PagerActionType.Prev:
                query = string.Format("{0}={1}&{2}={3}", makeIndexStoreKey(pagerSetting.StoreKey), pagerSetting.Index - 1, makeItemCountStoreKey(pagerSetting.StoreKey), pagerSetting.ItemCount);
                break;
            }

            query += QueryBuilder.MakeQueryString(querySettings);

            return(string.Format(htmlTemplate, query));
        }
Exemplo n.º 2
0
        /// <summary>
        /// 存储分页的设置.
        /// </summary>
        /// <param name="pagerSetting">分页设置.</param>
        public static void SetPagerSetting(PagerSetting pagerSetting)
        {
            if (null == pagerSetting)
            {
                return;
            }

            switch (pagerSetting.StoreType)
            {
            case PagerStoreType.Cookie:

                try
                {
                    HttpContext.Current.Response.Cookies.Set(new HttpCookie(makeIndexStoreKey(pagerSetting.StoreKey), pagerSetting.Index.ToString( )));

                    HttpContext.Current.Response.Cookies.Set(new HttpCookie(makeItemCountStoreKey(pagerSetting.StoreKey), pagerSetting.ItemCount.ToString( )));
                }
                catch
                { }

                break;

            case PagerStoreType.Session:

                try
                {
                    HttpContext.Current.Session[makeIndexStoreKey(pagerSetting.StoreKey)] = pagerSetting.Index;

                    HttpContext.Current.Session[makeItemCountStoreKey(pagerSetting.StoreKey)] = pagerSetting.ItemCount;
                }
                catch
                { }

                break;

            case PagerStoreType.Query:
                break;
            }
        }