示例#1
0
        public static PageDataResult ExecuteDataSetPage(string connectionString, PageDataArg args)
        {
            try
            {
                args.SQL   = args.SQL.ToUpper();
                args.Order = args.Order.ToUpper();

                string            strSql = "";
                string            strCol = "";
                DataRowCollection rows;
                #region
                if (args.SQL.StartsWith("SELECT", StringComparison.InvariantCultureIgnoreCase))
                {
                    int index = args.SQL.IndexOf("FROM", StringComparison.InvariantCultureIgnoreCase);
                    strCol   = args.SQL.Substring(6, index - 6);
                    args.SQL = " " + args.SQL.Substring(index);
                }
                else
                {
                    strCol   = "*";
                    args.SQL = " FROM " + args.SQL;
                }
                if (args.Count < 1)
                {
                    strSql = "SELECT COUNT(1) AS Cnt" + args.SQL;
                    rows   = MrDBAccess.ExecuteDataSet(connectionString, strSql).Tables[0].Rows;
                    if (rows.Count == 0)
                    {
                        args.Count = 0;
                    }
                    else
                    {
                        args.Count = DataBase.ObjectToInt(rows[0]["Cnt"]);
                    }
                }
                if (!string.IsNullOrEmpty(args.TurnPageKey) && !string.IsNullOrEmpty(args.TurnPageValue))
                {
                    int iNextID = 0;
                    args.Page = GetPage(connectionString, args.TurnPageKey, args.SQL, strCol, args.Order, args.TurnPageValue, args.PerPage, ref iNextID);
                }
                #endregion
                args.AllPage = DataBase.ObjectToInt((args.Count / args.PerPage) + (args.Count % args.PerPage != 0 ? 1 : 0));
                if (args.Page > args.AllPage)
                {
                    args.Page = args.AllPage;
                }
                if (args.Page < 1)
                {
                    args.Page = 1;
                }
                strSql = "BEGIN SELECT IDENTITY(INT,1,1) ROWNUM," + strCol + " INTO #TEMP" + args.SQL + " ORDER BY " + args.Order + ";SELECT * FROM #TEMP WHERE ROWNUM>" + (args.PerPage * (args.Page - 1)) + " AND ROWNUM<=" + (args.PerPage * args.Page) + ";DROP TABLE #TEMP;END;";
                rows   = MrDBAccess.ExecuteDataSet(connectionString, strSql).Tables[0].Rows;
                return(new PageDataResult()
                {
                    Count = args.Count, AllPage = args.AllPage, Page = args.Page, Data = rows
                });
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message, ex);
            }
        }
示例#2
0
 public static PageDataResult ExecuteDataSetPage(PageDataArg args)
 {
     return(ExecuteDataSetPage(ConnectionString(), args));
 }