コード例 #1
0
        public static DbQueryResult PagingByRownumber(int pageIndex, int pageSize, string sortBy, SortAction sortOrder, bool isCount, string table, string string_0, string filter, string selectFields, int partitionSize)
        {
            DbQueryResult result;

            if (string.IsNullOrEmpty(table))
            {
                result = null;
            }
            else
            {
                if (string.IsNullOrEmpty(sortBy) && string.IsNullOrEmpty(string_0))
                {
                    result = null;
                }
                else
                {
                    if (string.IsNullOrEmpty(selectFields))
                    {
                        selectFields = "*";
                    }
                    string        text          = DataHelper.BuildRownumberQuery(sortBy, sortOrder, isCount, table, string_0, filter, selectFields, partitionSize);
                    int           num           = (pageIndex - 1) * pageSize + 1;
                    int           num2          = num + pageSize - 1;
                    DbQueryResult dbQueryResult = new DbQueryResult();
                    Database      database      = DatabaseFactory.CreateDatabase();
                    System.Data.Common.DbCommand sqlStringCommand = database.GetSqlStringCommand(text);
                    database.AddInParameter(sqlStringCommand, "StartNumber", System.Data.DbType.Int32, num);
                    database.AddInParameter(sqlStringCommand, "EndNumber", System.Data.DbType.Int32, num2);
                    using (System.Data.IDataReader dataReader = database.ExecuteReader(sqlStringCommand))
                    {
                        dbQueryResult.Data = DataHelper.ConverDataReaderToDataTable(dataReader);
                        if (isCount && partitionSize == 0 && dataReader.NextResult())
                        {
                            dataReader.Read();
                            dbQueryResult.TotalRecords = dataReader.GetInt32(0);
                        }
                    }
                    result = dbQueryResult;
                }
            }
            return(result);
        }
コード例 #2
0
        public static DbQueryResult PagingByRownumber(int pageIndex, int pageSize, string sortBy, SortAction sortOrder, bool isCount, string table, string pk, string filter, string selectFields, int partitionSize)
        {
            if (string.IsNullOrEmpty(table))
            {
                return(null);
            }
            if (string.IsNullOrEmpty(sortBy) && string.IsNullOrEmpty(pk))
            {
                return(null);
            }
            if (string.IsNullOrEmpty(selectFields))
            {
                selectFields = "*";
            }
            string        query         = DataHelper.BuildRownumberQuery(sortBy, sortOrder, isCount, table, pk, filter, selectFields, partitionSize);
            int           num           = (pageIndex - 1) * pageSize + 1;
            int           num2          = num + pageSize - 1;
            DbQueryResult dbQueryResult = new DbQueryResult();

            try
            {
                Database  database         = DatabaseFactory.CreateDatabase();
                DbCommand sqlStringCommand = database.GetSqlStringCommand(query);
                database.AddInParameter(sqlStringCommand, "StartNumber", DbType.Int32, num);
                database.AddInParameter(sqlStringCommand, "EndNumber", DbType.Int32, num2);
                using (IDataReader dataReader = database.ExecuteReader(sqlStringCommand))
                {
                    dbQueryResult.Data = DataHelper.ConverDataReaderToDataTable(dataReader);
                    if (isCount && partitionSize == 0 && dataReader.NextResult())
                    {
                        dataReader.Read();
                        dbQueryResult.TotalRecords = dataReader.GetInt32(0);
                    }
                }
            }
            catch (Exception ex)
            {
                HttpContext.Current.Response.Write(selectFields + "<br>" + ex.Message);
            }
            return(dbQueryResult);
        }
コード例 #3
0
        public static PageModel <T> PagingByRownumber <T>(int pageIndex, int pageSize, string sortBy, SortAction sortOrder, bool isCount, string table, string key, string filter, string selectFields) where T : new()
        {
            PageModel <T> pageModel = new PageModel <T>();
            IList <T>     models    = null;

            if (string.IsNullOrEmpty(table))
            {
                return(null);
            }
            if (string.IsNullOrEmpty(key))
            {
                return(null);
            }
            if (string.IsNullOrEmpty(selectFields))
            {
                selectFields = "*";
            }
            string    query            = DataHelper.BuildRownumberQuery(sortBy, sortOrder, isCount, table, key, filter, selectFields, 0);
            int       num              = (pageIndex - 1) * pageSize + 1;
            int       num2             = num + pageSize - 1;
            Database  database         = DatabaseFactory.CreateDatabase();
            DbCommand sqlStringCommand = database.GetSqlStringCommand(query);

            database.AddInParameter(sqlStringCommand, "StartNumber", DbType.Int32, num);
            database.AddInParameter(sqlStringCommand, "EndNumber", DbType.Int32, num2);
            using (IDataReader dataReader = database.ExecuteReader(sqlStringCommand))
            {
                models = DataHelper.ReaderToList <T>(dataReader);
                if (isCount && dataReader.NextResult())
                {
                    dataReader.Read();
                    pageModel.Total = dataReader.GetInt32(0);
                }
            }
            pageModel.Models = models;
            return(pageModel);
        }