コード例 #1
0
ファイル: PagerBuilder.cs プロジェクト: vbea/Java21.NET
        internal MvcHtmlString RenderPager()
        {
            if (this._totalPageCount <= 1 && this._pagerOptions.AutoHide)
            {
                return(MvcHtmlString.Create("\r\n<!--Vbe Studio(http://www.vbes.pw)-->\r\n"));
            }
            if ((this._pageIndex > this._totalPageCount && this._totalPageCount > 0) || this._pageIndex < 1)
            {
                return(MvcHtmlString.Create(string.Format("{0}<div style=\"color:red;font-weight:bold\">{1}</div>{0}", "", this._pagerOptions.PageIndexOutOfRangeErrorMessage)));
            }
            List <PagerItem> list = new List <PagerItem>();

            if (this._pagerOptions.ShowFirstLast)
            {
                this.AddFirst(list);
            }
            if (this._pagerOptions.ShowPrevNext)
            {
                this.AddPrevious(list);
            }
            if (this._pagerOptions.ShowNumericPagerItems)
            {
                if (this._pagerOptions.AlwaysShowFirstLastPageNumber && this._startPageIndex > 1)
                {
                    list.Add(new PagerItem("1", 1, false, PagerItemType.NumericPage));
                }
                if (this._pagerOptions.ShowMorePagerItems && ((!this._pagerOptions.AlwaysShowFirstLastPageNumber && this._startPageIndex > 1) || (this._pagerOptions.AlwaysShowFirstLastPageNumber && this._startPageIndex > 2)))
                {
                    this.AddMoreBefore(list);
                }
                this.AddPageNumbers(list);
                if (this._pagerOptions.ShowMorePagerItems && ((!this._pagerOptions.AlwaysShowFirstLastPageNumber && this._endPageIndex < this._totalPageCount) || (this._pagerOptions.AlwaysShowFirstLastPageNumber && this._totalPageCount > this._endPageIndex + 1)))
                {
                    this.AddMoreAfter(list);
                }
                if (this._pagerOptions.AlwaysShowFirstLastPageNumber && this._endPageIndex < this._totalPageCount)
                {
                    list.Add(new PagerItem(this._totalPageCount.ToString(CultureInfo.InvariantCulture), this._totalPageCount, false, PagerItemType.NumericPage));
                }
            }
            if (this._pagerOptions.ShowPrevNext)
            {
                this.AddNext(list);
            }
            if (this._pagerOptions.ShowFirstLast)
            {
                this.AddLast(list);
            }
            StringBuilder stringBuilder = new StringBuilder();

            if (this._ajaxPagingEnabled)
            {
                using (List <PagerItem> .Enumerator enumerator = list.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        PagerItem current = enumerator.Current;
                        stringBuilder.Append(this.GenerateAjaxPagerElement(current));
                    }
                    goto IL_245;
                }
            }
            foreach (PagerItem current2 in list)
            {
                stringBuilder.Append(this.GeneratePagerElement(current2));
            }
IL_245:
            TagBuilder tagBuilder = new TagBuilder(this._pagerOptions.ContainerTagName);

            if (!string.IsNullOrEmpty(this._pagerOptions.Id))
            {
                tagBuilder.GenerateId(this._pagerOptions.Id);
            }
            if (!string.IsNullOrEmpty(this._pagerOptions.CssClass))
            {
                tagBuilder.AddCssClass(this._pagerOptions.CssClass);
            }
            if (!string.IsNullOrEmpty(this._pagerOptions.HorizontalAlign))
            {
                string text = "text-align:" + this._pagerOptions.HorizontalAlign.ToLower();
                if (this._htmlAttributes == null)
                {
                    this._htmlAttributes = new RouteValueDictionary
                    {
                        {
                            "style",
                            text
                        }
                    };
                }
                else
                {
                    if (this._htmlAttributes.Keys.Contains("style"))
                    {
                        IDictionary <string, object> htmlAttributes;
                        (htmlAttributes = this._htmlAttributes)["style"] = htmlAttributes["style"] + ";" + text;
                    }
                }
            }
            tagBuilder.MergeAttributes <string, object>(this._htmlAttributes, true);
            if (this._ajaxPagingEnabled)
            {
                IDictionary <string, object> dictionary = this._ajaxOptions.ToUnobtrusiveHtmlAttributes();
                dictionary.Remove("data-ajax-url");
                dictionary.Remove("data-ajax-mode");
                if (this._ajaxOptions.EnablePartialLoading)
                {
                    dictionary.Add("data-ajax-partialloading", "true");
                }
                if (this._pageIndex > 1)
                {
                    dictionary.Add("data-ajax-currentpage", this._pageIndex);
                }
                if (!string.IsNullOrWhiteSpace(this._ajaxOptions.DataFormId))
                {
                    dictionary.Add("data-ajax-dataformid", "#" + this._ajaxOptions.DataFormId);
                }
                this.AddDataAttributes(dictionary);
                tagBuilder.MergeAttributes <string, object>(dictionary, true);
            }
            if (this._pagerOptions.ShowPageIndexBox)
            {
                if (!this._ajaxPagingEnabled)
                {
                    Dictionary <string, object> dictionary2 = new Dictionary <string, object>();
                    this.AddDataAttributes(dictionary2);
                    tagBuilder.MergeAttributes <string, object>(dictionary2, true);
                }
                stringBuilder.Append(this.BuildGoToPageSection());
            }
            else
            {
                stringBuilder.Length -= this._pagerOptions.PagerItemsSeperator.Length;
            }
            tagBuilder.InnerHtml = stringBuilder.ToString();
            return(MvcHtmlString.Create("" + tagBuilder.ToString(TagRenderMode.Normal) + ""));
        }