Пример #1
0
        /// <summary>
        /// Creates the db provider.
        /// </summary>
        /// <param name="connectionString">Name of the conn STR.</param>
        /// <returns>The db provider.</returns>
        public static DbProvider CreateDbProvider(ProviderType providerType, string connectionString)
        {
            try
            {
                string[]   assAndClass = EnumDescriptionAttribute.GetDescription(providerType).Split(',');
                DbProvider dbProvider;
                if (assAndClass.Length > 1)
                {
                    dbProvider = CreateDbProvider(assAndClass[1].Trim(), assAndClass[0].Trim(), connectionString);
                }
                else
                {
                    dbProvider = CreateDbProvider(null, assAndClass[0].Trim(), connectionString);
                }

                if (dbProvider != null)
                {
                    dbProvider.ConnectName = "Default";
                }
                return(dbProvider);
            }
            catch
            {
                throw;
            }
        }
Пример #2
0
        /// <summary>
        /// Creates the db provider.
        /// </summary>
        /// <param name="connectionString">Name of the conn STR.</param>
        /// <returns>The db provider.</returns>
        public static DbProvider CreateDbProvider(DbProviderType providerType, string connectionString)
        {
            string[] assAndClass = EnumDescriptionAttribute.GetDescription(providerType).Split(',');

            DbProvider dbProvider = null;

            if (assAndClass.Length > 1)
            {
                dbProvider = CreateDbProvider(assAndClass[0].Trim(), assAndClass[1].Trim(), connectionString);
            }
            else
            {
                dbProvider = CreateDbProvider(assAndClass[0].Trim(), null, connectionString);
            }

            return(dbProvider);
        }
Пример #3
0
        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();

            if (dataPage.CurrentPageIndex <= 0)
            {
                dataPage.CurrentPageIndex = 1;
            }
            if (dataPage.RowCount < 0)
            {
                dataPage.RowCount = 0;
            }

            int halfSize = Convert.ToInt32(Math.Floor(linkSize / 2.0));

            if (linkSize % 2 == 0)
            {
                halfSize--;
            }

            string html = string.Empty;

            //生成分页的html
            if (style == HtmlPagerStyle.Custom)
            {
                sb.Append("<div id='htmlPager' class=\"" + (pagerCss ?? EnumDescriptionAttribute.GetDescription(style)) + "\">\n");
            }
            else
            {
                sb.Append("<div id='htmlPager' class=\"" + EnumDescriptionAttribute.GetDescription(style) + "\">\n");
            }

            if (dataPage.PageCount == 0)
            {
                sb.Append("<span class=\"disabled\">上一页</span>\n");
                sb.Append("<span class=\"current\">1</span>\n");
                sb.Append("<span class=\"disabled\">下一页</span>\n");
            }
            else
            {
                if (!dataPage.IsFirstPage)
                {
                    sb.Append("<a href=\"" + GetHtmlLink(dataPage.CurrentPageIndex - 1) + "\" title=\"上一页\">" + prevPageTitle + "</a>\n");
                }
                else
                {
                    sb.Append("<span class=\"disabled\">" + prevPageTitle + "</span>\n");
                }

                int startPage = dataPage.CurrentPageIndex;
                if (startPage <= halfSize || dataPage.PageCount <= linkSize)
                {
                    startPage = halfSize + 1;
                }
                else if (startPage + halfSize >= dataPage.PageCount)
                {
                    startPage = dataPage.PageCount - halfSize;
                    if (linkSize % 2 == 0)
                    {
                        startPage--;
                    }
                }

                int beginIndex = startPage - halfSize;
                int endIndex   = startPage + halfSize;

                if (linkSize % 2 == 0)
                {
                    endIndex++;
                }

                if (beginIndex - 1 > 0)
                {
                    if (beginIndex - 1 == 1)
                    {
                        sb.Append("<a href=\"" + GetHtmlLink(1) + "\" title=\"第1页\">[1]</a>\n");
                    }
                    else
                    {
                        sb.Append("<a href=\"" + GetHtmlLink(1) + "\" title=\"第1页\">[1]</a></span>...&nbsp;\n");
                    }
                }

                for (int index = beginIndex; index <= endIndex; index++)
                {
                    if (index > dataPage.PageCount)
                    {
                        break;
                    }
                    if (index == dataPage.CurrentPageIndex)
                    {
                        sb.Append("<span class=\"current\">");
                        sb.Append(index);
                        sb.Append("</span>\n");
                    }
                    else
                    {
                        sb.Append("<a href=\"" + GetHtmlLink(index) + "\" title=\"第" + index + "页\">[" + index + "]</a>\n");
                    }
                }

                if (endIndex + 1 <= dataPage.PageCount)
                {
                    if (endIndex + 1 == dataPage.PageCount)
                    {
                        sb.Append("<a href=\"" + GetHtmlLink(endIndex + 1) + "\" title=\"第" + (endIndex + 1) + "页\">[" + (endIndex + 1) + "]</a>\n");
                    }
                    else
                    {
                        sb.Append("...&nbsp;<a href=\"" + GetHtmlLink(dataPage.PageCount) + "\" title=\"第" + dataPage.PageCount + "页\">[" + dataPage.PageCount + "]</a>\n");
                    }
                }

                if (!dataPage.IsLastPage)
                {
                    sb.Append("<a href=\"" + GetHtmlLink(dataPage.CurrentPageIndex + 1) + "\" title=\"下一页\">" + nextPageTitle + "</a>\n");
                }
                else
                {
                    sb.Append("<span class=\"disabled\">" + nextPageTitle + "</span>\n");
                }
            }

            if (showGotoPage)
            {
                sb.Append("&nbsp;/&nbsp;第&nbsp;<select id=\"pageSelect\" onchange=\"" + GetHtmlLink("this.value") + "\">\n");
                if (dataPage.PageCount == 0)
                {
                    sb.Append("<option value=\"1\" selected=\"selected\">1</option>\n");
                }
                else
                {
                    for (int index = 1; index <= dataPage.PageCount; index++)
                    {
                        if (index == dataPage.CurrentPageIndex)
                        {
                            sb.Append("<option value=\"" + index + "\" selected=\"selected\">");
                            sb.Append(index);
                            sb.Append("</option>\n");
                        }
                        else
                        {
                            sb.Append("<option value=\"" + index + "\">");
                            sb.Append(index);
                            sb.Append("</option>\n");
                        }
                    }
                }
                sb.Append("</select>&nbsp;页&nbsp;\n");
            }

            if (showRecord)
            {
                sb.Append("&nbsp;共<span class=\"red\">" + dataPage.RowCount + "</span>条&nbsp;/&nbsp;每页<span class=\"red\">" + dataPage.PageSize + "</span>条\n");
            }

            sb.Append("<input type=\"hidden\" id=\"currentPage\" value=\"" + dataPage.CurrentPageIndex + "\"/>\n");
            sb.Append("</div>\n");

            html = sb.ToString();
            if (!showBracket)
            {
                Regex reg = new Regex(@"\[([\d]+)\]");
                html = reg.Replace(html, "$1");
            }

            return(html);
        }