예제 #1
0
        protected void Page_Load(object sender, System.EventArgs e)
        {
            AddNavigationItem("搜索");

            SearchSettings setting = AllSettings.Current.SearchSettings;

            if (IsLogin == false && setting.EnableGuestSearch == false)
            {
                ShowError("您是游客不允许使用搜索帖子的功能");
            }
            else if (IsLogin && setting.EnableSearch[My] == false)
            {
                ShowError("您所在的用户组不允许使用搜索帖子的功能");
            }

            canVisitForumIDs = ForumBO.Instance.GetForumIdsForVisit(My);

            if (canVisitForumIDs != null && canVisitForumIDs.Count == 0)
            {
                ShowError("您所在的用户组没有搜索帖子的权限");
            }

            //int maxResultCount = 0;

            if (IsLogin == false)
            {
                m_MaxResultCount = setting.GuestMaxResultCount;
            }
            else
            {
                m_MaxResultCount = setting.MaxResultCount[My];
            }

            if (_Request.Get("searchID", Method.Get) != null)
            {
                m_SearchID = _Request.Get <Guid>("searchID", Method.Get, Guid.Empty);
                if (m_SearchID == Guid.Empty)
                {
                    ShowError("非法的searchID");
                }
            }

            if (_Request.IsClick("SearchSubmit"))
            {
                ProcessSearch();
            }
            else
            {
                if (m_SearchID == Guid.Empty)
                {
                    mode = (SearchMode)_Request.Get <int>("Mode", Method.Get, 1);
                    string searchText = _Request.Get("SearchText", Method.Get, string.Empty, false);

                    if (mode == SearchMode.ThreadUserID || mode == SearchMode.PostUserID)
                    {
                        int userID;
                        if (int.TryParse(searchText, out userID) == false)
                        {
                            ShowError("用户ID必须为整数!");
                            return;
                        }

                        User user = UserBO.Instance.GetUser(userID);
                        if (user == null)
                        {
                            ShowError("不存在该用户!");
                            return;
                        }
                        else
                        {
                            if (mode == SearchMode.ThreadUserID)
                            {
                                mode = SearchMode.UserThread;
                            }
                            else
                            {
                                mode = SearchMode.UserPost;
                            }

                            m_SearchID = PostBOV5.Instance.SearchTopics(My, null, user.Username, mode, setting.SearchType, null, false, true, m_MaxResultCount);
                        }
                    }
                    else if (mode == SearchMode.Subject || mode == SearchMode.Content)
                    {
                        m_SearchID = PostBOV5.Instance.SearchTopics(My, null, HttpUtility.HtmlEncode(searchText), mode, setting.SearchType, null, false, true, m_MaxResultCount);
                    }
                    else if (mode == SearchMode.UserThread && searchText != string.Empty)
                    {
                        User user = UserBO.Instance.GetUser(searchText);
                        if (user == null)
                        {
                            ShowError("不存在该用户!");
                            return;
                        }
                        m_SearchID = PostBOV5.Instance.SearchTopics(My, null, searchText, mode, setting.SearchType, null, false, true, m_MaxResultCount);
                    }
                    if (m_SearchID != Guid.Empty)
                    {
                        string url = BbsUrlHelper.GetSearchIndexUrl() + "?searchID=" + m_SearchID.ToString();
                        ShowSuccess("搜索完毕, 稍后将转到搜索结果页面", url);
                    }
                }
                else
                {
                    ProcessGetThreads();
                }
            }
        }