⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 filethreadquerybuilder.cs

📁 community server 源码
💻 CS
字号:
//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
//     Copyright (c) Telligent Systems Corporation.  All rights reserved.
// </copyright> 
//------------------------------------------------------------------------------

using CommunityServer.Components;
using CommunityServer.Files.Components;
using System.Collections;
using System.Text;

namespace CommunityServer.SqlDataProvider
{
	/// <summary>
	/// Summary description for FileThreadQueryBuild.
	/// </summary>
	public class FileThreadQueryBuilder : BaseThreadQueryBuilder
	{
		private FileGalleryThreadQuery query;
		public FileThreadQueryBuilder(ThreadQuery query, string databaseOwner): base(query, databaseOwner)
		{
			this.query = (FileGalleryThreadQuery)query;
		}

		#region QueryBulder Overrides

		/// <summary>
		/// ORDER BY, HAVING and GROUP BY objects appended after the WHERE clause
		/// </summary>
		protected override void ApplySort()
		{
			string order = "desc";
			if(query.SortOrder == SortOrder.Ascending)
				order = "asc";

			// Sort by
			string groupBy = string.Empty;
			string orderBy = string.Empty;
			switch(query.SortBy)
			{
				case EntriesSortBy.Author:
					orderBy = " order by P.PostAuthor";
					groupBy = "P.PostAuthor";
					break;
				case EntriesSortBy.Comments:
					orderBy = " order by T.TotalReplies";
					groupBy = "T.TotalReplies";
					break;
				case EntriesSortBy.Rating:
					orderBy = " order by case when T.TotalRatings > 0 then (convert(decimal,T.RatingSum) / convert(decimal,T.TotalRatings)) else 0 end" ;
					groupBy = "T.TotalRatings, T.RatingSum";
					break;
				case EntriesSortBy.Subject:
					orderBy = " order by P.Subject";
					groupBy = "P.Subject";
					break;
				case EntriesSortBy.Views:
					orderBy = " order by T.TotalViews";
					groupBy = "T.TotalViews";
					break;
				case EntriesSortBy.Downloads:
					orderBy = " order by (SELECT COUNT(fD.UserID) FROM files_Downloads fD (nolock) WHERE fD.PostID = P.PostID)";
					break;
				default:
				case EntriesSortBy.PostDate:
					orderBy = " order by P.PostDate";
					groupBy = "P.PostDate";
					break;
			}

			// Add group by and having if necessary, then order by
			if(query.UncategorizedOnly)
			{
				sb.Append(" group by P.PostID, " + groupBy);
				sb.Append(" having count(PC.CategoryID) = 0");
			}
			sb.Append(orderBy + " " + order);
		}

		/// <summary>
		/// WHERE clause element to specify the valid IsApproved / PostDate values
		/// </summary>
		protected override void ApplyPublished()
		{
			//Do we care if the post has been publshied
			if(query.OnlyApproved)
			{
				sb.Append(" and P.IsApproved = 1 and P.PostDate <= getdate() ");
			}
			else if (query.OnlyUnapproved)
			{
				sb.Append(" and P.IsApproved = 0 and P.PostDate <= getdate() ");
			}
		}

		/// <summary>
		/// WHERE clause element to speficy the ApplicationPostType to return (bitwise comparison)
		/// </summary>
		protected override void ApplyPostType()
		{
			sb.AppendFormat(" and P.ApplicationPostType & {0} <> 0 ", (int) query.ApplicationPostType);
			//sb.AppendFormat(" and P.ApplicationPostType = {0} ", (int)query.PostType);
		}

		/// <summary>
		/// WHERE clause elemenet to apply values set in the FilterKey
		/// The base only runs this if the key length is greater than zero
		/// </summary>
		protected override void ApplyFilterKey()
		{
			sb.AppendFormat(" and S.SectionID in ({0}) ", query.FilterKey);
		}

		protected override string GetSectionIDList()
		{
			ArrayList folders = Folders.GetFolders();
			if (folders.Count > 0)
			{
				StringBuilder list = new StringBuilder();
				foreach (Folder f in folders)
				{
					if (list.Length > 0)
						list.Append(",");

					list.Append(f.SectionID);
				}

				return list.ToString();
			}
			else
				return "null";
		}


		#endregion
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -