Esempio n. 1
0
        /// <summary>
        /// Returns a <see cref="T:System.Collections.Specialized.NameValueCollection" /> containing the settings for the rendering extension.
        /// </summary>
        NameValueCollection ISettings.GetSettings()
        {
            var settings = new NameValueCollection();

            if (!EmbedFonts)
            {
                settings["EmbedFonts"] = bool.FalseString;
            }
            if (StartPage != 0)
            {
                settings["StartPage"] = StartPage.ToString(CultureInfo.InvariantCulture);
            }
            if (EndPage != -1)
            {
                settings["EndPage"] = EndPage.ToString(CultureInfo.InvariantCulture);
            }
            if (Target != TargetDeviceKind.Export)
            {
                settings["Target"] = Target.ToString();
            }
            return(settings);
        }
        /// <summary>
        /// 生成页码项
        /// </summary>
        public void CreatePaginationItems()
        {
            var items = new List <PaginationItem>();

            //添加“上一页”按钮
            items.Add(new PaginationItem
            {
                Text       = PreviousText,
                TargetPage = CurrentPage - 1,
                Disabled   = CurrentPage == StartPage
            });
            //如果总页数不超过显示页数限制,则直接添加所有中间页
            if (EndPage - StartPage < ShowPageLimit)
            {
                items.AddRange(createPagenationItmeOfRange(StartPage, EndPage, CurrentPage));
            }
            else
            {
                //添加第一页
                items.Add(new PaginationItem
                {
                    Text       = StartPage.ToString(),
                    TargetPage = StartPage,
                    Active     = CurrentPage == StartPage
                });
                int limitHalf = ShowPageLimit / 2;
                if (CurrentPage - StartPage <= limitHalf) //页码较为靠前,则添加前几页
                {
                    items.AddRange(createPagenationItmeOfRange(StartPage + 1, StartPage + ShowPageLimit - 3, CurrentPage));
                    items.Add(new PaginationItem
                    {
                        Text       = "···",
                        TargetPage = null,
                        Disabled   = true
                    });
                }
                else if (EndPage - CurrentPage <= limitHalf) //页码较为靠后,则添加后几页
                {
                    items.Add(new PaginationItem
                    {
                        Text       = "···",
                        TargetPage = null,
                        Disabled   = true
                    });
                    items.AddRange(createPagenationItmeOfRange(EndPage - ShowPageLimit + 3, EndPage - 1, CurrentPage));
                }
                else
                {
                    int middleHalf = (ShowPageLimit - 4) / 2;
                    items.Add(new PaginationItem
                    {
                        Text       = "···",
                        TargetPage = null,
                        Disabled   = true
                    });
                    items.AddRange(createPagenationItmeOfRange(CurrentPage - middleHalf, CurrentPage + middleHalf, CurrentPage));
                    items.Add(new PaginationItem
                    {
                        Text       = "···",
                        TargetPage = null,
                        Disabled   = true
                    });
                }
                //添加最后一页
                items.Add(new PaginationItem
                {
                    Text       = EndPage.ToString(),
                    TargetPage = EndPage,
                    Active     = CurrentPage == EndPage
                });
            }
            //添加“下一页”按钮
            items.Add(new PaginationItem
            {
                Text       = NextText,
                TargetPage = CurrentPage + 1,
                Disabled   = CurrentPage == EndPage
            });
            this.Items = items;
        }