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

📄 searchview.cs

📁 本系统是在asp版《在线文件管理器》的基础上设计制作
💻 CS
字号:
//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
//     Copyright (c) Telligent Systems Corporation.  All rights reserved.
// </copyright> 
//------------------------------------------------------------------------------

using System;using System.Web.UI;using System.Web.UI.WebControls;using CommunityServer.Components;using CommunityServer.Controls;
using CommunityServer.Discussions.Components;

namespace CommunityServer.Discussions.Controls 
{

    // *********************************************************************
    //  SearchView
    //
    /// <summary>
    /// This server control is used to display search options and search results
    /// </summary>
    /// 
    // ********************************************************************/
    public class SearchView : SkinnedWebControl 
    {

        #region Member variables and constructor
        CSContext csContext = CSContext.Current;
        string skinFilename = "View-Search.ascx";
        ForumListBox forumList;
        Button searchKeywords;
        TextBox searchTextKeywords;
        SearchForumsRadioButtonList searchForum;
        TextBox users;
		CustomValidator validator;

        // *********************************************************************
        //  SearchView
        //
        /// <summary>
        /// The constructor simply checks for a ForumID value passed in via the
        /// HTTP POST or GET.
        /// properties.
        /// </summary>
        /// 
        // ********************************************************************/
        public SearchView() 
        {

            // Assign a default template name
            if (SkinFilename == null)
                SkinFilename = skinFilename;

        }
        #endregion

        #region Rendering
        // *********************************************************************
        //  Initializeskin
        //
        /// <summary>
        /// Initializes the user control loaded in CreateChildControls. Initialization
        /// consists of finding well known control names and wiring up any necessary events.
        /// </summary>
        /// 
        // ********************************************************************/ 
        protected override void InitializeSkin(Control skin) 
        {

			((Label) skin.FindControl("ForumName")).Text = ResourceManager.GetString("SearchViewSimple_Title");
			((Label) skin.FindControl("ForumDescription")).Text = ResourceManager.GetString("SearchViewSimple_Title");

            searchKeywords = (Button) skin.FindControl("SearchKeyWordsButton");
            searchKeywords.Click += new EventHandler(SearchKeyWords_Click);
            searchKeywords.Text = ResourceManager.GetString("Search");


            // Can we constrict by forum?
            searchForum = (SearchForumsRadioButtonList) skin.FindControl("SearchForums");
            if (searchForum != null) 
            {
                searchForum.SelectedValue = true.ToString();
                searchForum.SelectedIndexChanged += new EventHandler( SearchForums_Changed );
            }

            // Can we constrict by user?
            users = (TextBox) skin.FindControl("SearchTextByUsers");

            searchTextKeywords = (TextBox) skin.FindControl("SearchTextKeyWords");

            forumList = (ForumListBox) skin.FindControl("SearchForumList");

			validator = (CustomValidator) skin.FindControl("Validator");

        }
        #endregion

        #region Events
        public void SearchForums_Changed (object sender, EventArgs e) 
        {

            if (forumList != null)
                if (forumList.Enabled == false)
                    forumList.Enabled = true;
                else
                    forumList.Enabled = false;

        }

        public void SearchKeyWords_Click (Object sender, EventArgs e) 
        {
			try 
            {
				// Check to make sure the user has submitted something to search on
				// to avoid SQL timeouts.
				//
				if (users.Text.Length == 0 && searchTextKeywords.Text.Length == 0)
				{
					validator.ErrorMessage = ResourceManager.GetString( "SearchAdvanced_Errors_NoKeywords" );
					validator.IsValid = false;
					return;
				}

                string forumsToSearch = string.Empty;
                string usersToSearch = string.Empty;

                // Are we searching all or specific forums?
                //
                if ((searchForum != null) && (!searchForum.SearchAllForums)) 
                {
                
                    // Get a list of the forums we are searching
                    //
                    foreach (ListItem item in forumList.Items) 
                    {

                        if ( (item.Selected == true) && (item.Value.StartsWith("f")) ) 
                            forumsToSearch += item.Value.Replace("f-", "") + ",";

                        if ( (item.Selected == true) && (item.Value.StartsWith("g")) ) 
                        {
                            Group forumGroup = ForumGroups.GetForumGroup( int.Parse(item.Value.Replace("g-", "")) );

                            if(!forumGroup.HasSections)
                                forumGroup.Sections = Forums.GetForumsByForumGroupID(forumGroup.GroupID);

                            foreach (Forum f in forumGroup.Sections)
                                forumsToSearch += f.SectionID + ",";

                        }
                    }
                }

                // Are we search for posts by specific users?
                //
                if (users.Text != string.Empty) 
                {
                    string[] usernames = users.Text.Split(',');

                    foreach (string username in usernames) 
                    {

                        // Attempt to get the user
                        try 
                        {
                            User user = Users.FindUserByUsername(username.TrimStart(' ').TrimEnd(' '));
                            usersToSearch += user.UserID + ",";
                        } 
                        catch {}
                    }
                }

				// clean the strings
				forumsToSearch = forumsToSearch.TrimEnd(',');
				usersToSearch = usersToSearch.TrimEnd(',');

                // Do we need to encode the forums to search?
                //
                if (forumsToSearch != string.Empty)
                    forumsToSearch = CommunityServer.Search.ForumsToSearchEncode(forumsToSearch);

                // Do we need to encode the userid?
                //
                if (usersToSearch != string.Empty)
                    usersToSearch = CommunityServer.Search.ForumsToSearchEncode(usersToSearch);

                csContext.Context.Response.Redirect( Globals.GetSiteUrls().SearchForText( csContext.Context.Server.UrlEncode( searchTextKeywords.Text ) , forumsToSearch, usersToSearch ));
            }
            catch( Exception ex ) 
            {
                CSException fex = new CSException( CommunityServer.Components.CSExceptionType.SearchUnknownError, ex.Message, ex );
                fex.Log();
            }
        }
        #endregion
		
    }
}

⌨️ 快捷键说明

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