zoukankan      html  css  js  c++  java
  • C# 分页方法

        /// <summary>
        /// 分页实体
        /// </summary>
        public class PageInfo
        {
            private int iPage;
            /// <summary>
            /// 当前页码
            /// </summary>
            public int IPage
            {
                get { return iPage; }
                set { iPage = value; }
            }
            private int iPageSize;
            /// <summary>
            /// 每页条数
            /// </summary>
            public int IPageSize
            {
                get { return iPageSize; }
                set { iPageSize = value; }
            }
            private string strTable;
            /// <summary>
            /// 查询的表
            /// </summary>
            public string StrTable
            {
                get { return strTable; }
                set { strTable = value; }
            }
            private string strText;
            /// <summary>
            /// 查询的字段
            /// </summary>
            public string StrText
            {
                get { return strText; }
                set { strText = value; }
            }
            private string strWhere;
            /// <summary>
            /// 查询的条件
            /// </summary>
            public string StrWhere
            {
                get { return strWhere; }
                set { strWhere = value; }
            }
            private string strIndex;
            /// <summary>
            /// 索引
            /// </summary>
            public string StrIndex
            {
                get { return strIndex; }
                set { strIndex = value; }
            }
            private string strOrder;
            /// <summary>
            /// 排序字段
            /// </summary>
            public string StrOrder
            {
                get { return strOrder; }
                set { strOrder = value; }
            }
        }

    SqlServer

            /// <summary>
            /// 分页方法
            /// </summary>
            /// <param name="p">分页实体</param>
            /// <param name="parameters">查询参数</param>
            /// <param name="outCount">数据总数</param>
            /// <returns></returns>
            public static DataTable Page(PageInfo p, SqlParameter[] parameters, out int outCount)
            {
                string SqlCount, Sql, TempOrder;
                if (p.StrOrder != "")
                { TempOrder = " order by " + p.StrOrder; }
                else
                { TempOrder = ""; }
                if (p.IPage == 1)
                {
                    Sql = "select top " + p.IPageSize + " " + p.StrText + " from " + p.StrTable + " where 1=1 " + p.StrWhere +
                      TempOrder;
                }
                else
                {
                    Sql = "select top " + p.IPageSize + " " + p.StrText + " from " + p.StrTable + " where " + p.StrIndex +
                      " not in (select top " + (p.IPageSize * (p.IPage - 1)) + " " + p.StrIndex + " from " + p.StrTable +
                      " where 1=1 " + p.StrWhere + TempOrder + ") " + p.StrWhere + TempOrder;
                }
                SqlCount = "select isnull(count(*),10000)   from " + p.StrTable + "  where 1=1 " + p.StrWhere;
                string ls_Temp = SqlHelper.ExecuteScalar(SqlCount, parameters);
                try
                { outCount = Convert.ToInt32(ls_Temp); }
                catch { outCount = 0; }
                DataTable dt = SqlHelper.ExecuteDataTable(CommandType.Text, Sql, parameters);
                return dt;
            }

    MySQL

            /// <summary>
            /// 分页方法
            /// </summary>
            /// <param name="p">分页实体</param>
            /// <param name="parameters">查询参数</param>
            /// <param name="outCount">数据总数</param>
            /// <returns></returns>
            public static DataTable Page(PageInfo p, SqlParameter[] parameters, out int outCount)
            {
                string SqlCount, Sql, TempOrder;
                if (p.StrOrder != "")
                { TempOrder = " order by " + p.StrOrder; }
                else
                { TempOrder = ""; }
                if (p.IPage == 1)
                {
                    Sql = "select " + p.StrText + " from " + p.StrTable + " where 1=1 " + p.StrWhere +
                      TempOrder + " limit 0," + p.IPageSize;
                }
                else
                {
                    Sql = "select " + p.StrText + " from " + p.StrTable + " where 1=1 " + p.StrWhere +
                      TempOrder + " limit " + (p.IPageSize * (p.IPage - 1)) + "," + p.IPageSize;
                }
                SqlCount = "select ifnull(count(*),10000)   from " + p.StrTable + "  where 1=1 " + p.StrWhere;
                string ls_Temp = SqlHelper.ExecuteScalar(SqlCount, parameters);
                try
                { outCount = Convert.ToInt32(ls_Temp); }
                catch { outCount = 0; }
                DataTable dt = SqlHelper.ExecuteDataTable(CommandType.Text, Sql, parameters);
                return dt;
            }
  • 相关阅读:
    POJ C程序设计进阶 编程题#4:Tomorrow never knows?
    POJ C程序设计进阶 编程题#3: 发票统计
    深度学习笔记(10)- 控制中心之电源管理、鼠标和触控板、键盘和语言
    深度学习笔记(09)- 控制中心之时间设置
    深度学习笔记(08)- 控制中心之网络设置
    深度学习笔记(07)- 控制中心之声音设置
    深度学习笔记(06)- 控制中心之个性化设置
    深度学习笔记(05)- 控制中心之显示与默认程序
    深度学习笔记(04)- 控制中心之首页与用户管理
    深度学习笔记(03)- 启动器
  • 原文地址:https://www.cnblogs.com/bo10296/p/5139451.html
Copyright © 2011-2022 走看看