Exemplo n.º 1
0
        public static DataTable QueryByDividPage(ref Common.DividPage page, string sql)
        {
            if (page == null)
            {
                page = new Common.DividPage();
            }
            if (page.CurrentPageNumber == 0)
            {
                page.CurrentPageNumber = 1;
            }
            int RecordCounts = 0;

            int TopNumber   = page.CurrentPageShowCounts * page.CurrentPageNumber;
            int WhereNumber = (page.CurrentPageNumber - 1) * page.CurrentPageShowCounts;

            string strSqlRecordCounts = "select count(*) as recordcounts  from (" + sql + ")";

            using (OracleDataReader dr = OracleDBHelper.ExecuteReader(strSqlRecordCounts))
            {
                if (dr.Read())
                {
                    RecordCounts = int.Parse(dr["recordcounts"].ToString());
                }
            }
            //string strSql = "Select * From (Select ROW_NUMBER() OVER(@Sort) AS PageRowNumber , *  From  (@Tables) ) Where PageRowNumber <= @TopNumber And PageRowNumber > @WhereNumber ";
            string strSql = "Select * From (@Tables) Where PageRowNumber <= @TopNumber And PageRowNumber > @WhereNumber ";

            strSql = strSql.Replace("@TopNumber", TopNumber.ToString());
            //strSql = strSql.Replace("@Sort", Sort.ToString());
            //strSql = strSql.Replace("@Fields", Fields.ToString());
            strSql = strSql.Replace("@Tables", sql.ToString());
            //strSql = strSql.Replace("@Filter", Filter.ToString());
            strSql = strSql.Replace("@WhereNumber", WhereNumber.ToString());

            DataTable dt = OracleDBHelper.ExecuteDataSet(CommandType.Text, strSql).Tables[0];

            page.RecordCounts = RecordCounts;
            if (page.RecordCounts > 0)
            {
                page.PagesCount = (RecordCounts + page.CurrentPageShowCounts - 1) / page.CurrentPageShowCounts;
            }
            else
            {
                page.PagesCount = 0;
                page.CurrentPageRecordCounts = 0;
            }

            return(dt);
        }