public PageResultSet ListPages(PageSearchOptions options) { using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Suppress)) { using (SqlConnection conn = new SqlConnection(DatabaseManager.DatabaseEngine.ConnectionString)) { conn.Open(); SqlCommand cmd = new SqlCommand(ReplacePageSortOrder("ListPages", options.PageOrder), conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(NewParameter("@Hidden", options.Hidden, DbType.Boolean)); cmd.Parameters.Add(NewParameter("@Deleted", options.Deleted, DbType.Boolean)); cmd.Parameters.Add(NewParameter("@Draft", options.Draft, DbType.Boolean)); cmd.Parameters.Add(NewParameter("@Offset", Math.Max((options.PageNumber - 1) * options.PageSize, 0), DbType.Int64)); cmd.Parameters.Add(NewParameter("@PageSize", options.PageSize <= 0 ? -1 : options.PageSize, DbType.Int64)); cmd.Parameters.Add(NewParameter("@CategorySetName", options.CategorySetName, DbType.String)); cmd.Parameters.Add(NewParameter("@CategoryName", options.CategoryName, DbType.String)); using (SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection)) { reader.Read(); long totalResults = Convert.ToInt64(reader[0]); reader.NextResult(); List <Page> list = new List <Page>(); while (reader.Read()) { list.Add(new Page(reader)); } reader.Close(); return(new PageResultSet(list, totalResults, options.PageSize, options.PageNumber, options.PageOrder)); } } } }
public object Evaluate(Token contextToken, List<ExpressionArgument> args, ExecutionState state) { string catset = (args[0].Expression.Evaluate(state, args[0].Token) ?? "").ToString(); string catname = (args[1].Expression.Evaluate(state, args[1].Token) ?? "").ToString(); int pageSize = Convert.ToInt32(TokenParser.VerifyUnderlyingType(args[2].Expression.Evaluate(state, args[2].Token)) ?? 0); int pageNumber = Convert.ToInt32(TokenParser.VerifyUnderlyingType(args[3].Expression.Evaluate(state, args[3].Token)) ?? 0); string sort = (args[4].Expression.Evaluate(state, args[4].Token) ?? "").ToString(); PageResultSetOrder pageOrder; switch (sort) { case "random": pageOrder = PageResultSetOrder.Random; break; case "publishdate ascending": pageOrder = PageResultSetOrder.PublishDateAscending; break; default: pageOrder = PageResultSetOrder.PublishDateDescending; break; } PageSearchOptions options = new PageSearchOptions(); options.Draft = false; options.Deleted = false; options.Hidden = false; options.PageSize = pageSize; options.PageNumber = pageNumber; options.PageOrder = pageOrder; options.SetCategory(catset, catname); PageResultSet pages = ContentManager.Instance.DataProvider.ListPages(options); pages.LoadContentForPages(); return pages; }
/// <summary> /// 分页查询 /// </summary> /// <typeparam name="T">查询类型</typeparam> /// <param name="options">分页查询条件</param> /// <returns>返回PageView<T></returns> public static PageView <T> GetPageList <T>(PageSearchOptions options) { const string pageProcedureName = "Proc_GetPageData"; //构造参数,存储过程固定 var p = new DynamicParameters(); p.Add("TableName", options.TableName); p.Add("PrimaryKey", options.PrimaryKey); p.Add("Fields", options.Fields); p.Add("Condition", options.Condition); p.Add("CurrentPage", options.PageIndex); p.Add("PageSize", options.PageSize); p.Add("Sort", options.Sort); p.Add("RecordCount", dbType: DbType.Int32, direction: ParameterDirection.Output); var pageData = new PageView <T>(options.PageIndex, options.PageSize); if (HasDangerousContents(options.Condition)) { return(pageData); } pageData.List = DBHelper.Query <T>(pageProcedureName, p, CommandType.StoredProcedure); pageData.TotalCount = p.Get <int>("RecordCount"); return(pageData); }
public object Evaluate(Token contextToken, List <ExpressionArgument> args, ExecutionState state) { string catset = (args[0].Expression.Evaluate(state, args[0].Token) ?? "").ToString(); string catname = (args[1].Expression.Evaluate(state, args[1].Token) ?? "").ToString(); int pageSize = Convert.ToInt32(TokenParser.VerifyUnderlyingType(args[2].Expression.Evaluate(state, args[2].Token)) ?? 0); int pageNumber = Convert.ToInt32(TokenParser.VerifyUnderlyingType(args[3].Expression.Evaluate(state, args[3].Token)) ?? 0); string sort = (args[4].Expression.Evaluate(state, args[4].Token) ?? "").ToString(); PageResultSetOrder pageOrder; switch (sort) { case "random": pageOrder = PageResultSetOrder.Random; break; case "publishdate ascending": pageOrder = PageResultSetOrder.PublishDateAscending; break; default: pageOrder = PageResultSetOrder.PublishDateDescending; break; } PageSearchOptions options = new PageSearchOptions(); options.Draft = false; options.Deleted = false; options.Hidden = false; options.PageSize = pageSize; options.PageNumber = pageNumber; options.PageOrder = pageOrder; options.SetCategory(catset, catname); PageResultSet pages = ContentManager.Instance.DataProvider.ListPages(options); pages.LoadContentForPages(); return(pages); }
public PageResultSet ListPages(PageSearchOptions options) { using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Suppress)) { using (SQLiteConnection conn = new SQLiteConnection(DatabaseManager.DatabaseEngine.ConnectionString)) { conn.Open(); SQLiteCommand cmd = new SQLiteCommand(ReplacePageSortOrder(Procedures["List Pages"], options.PageOrder), conn); cmd.Parameters.Add(NewParameter("@Hidden", options.Hidden, DbType.Boolean)); cmd.Parameters.Add(NewParameter("@Deleted", options.Deleted, DbType.Boolean)); cmd.Parameters.Add(NewParameter("@Draft", options.Draft, DbType.Boolean)); cmd.Parameters.Add(NewParameter("@Offset", Math.Max((options.PageNumber - 1) * options.PageSize, 0), DbType.Int64)); cmd.Parameters.Add(NewParameter("@PageSize", options.PageSize <= 0 ? -1 : options.PageSize, DbType.Int64)); cmd.Parameters.Add(NewParameter("@CategorySetName", options.CategorySetName, DbType.String)); cmd.Parameters.Add(NewParameter("@CategoryName", options.CategoryName, DbType.String)); using (SQLiteDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection)) { reader.Read(); long totalResults = Convert.ToInt64(reader[0]); reader.NextResult(); List<Page> list = new List<Page>(); while (reader.Read()) list.Add(new Page(reader)); reader.Close(); return new PageResultSet(list, totalResults, options.PageSize, options.PageNumber, options.PageOrder); } } } }