/// <summary> /// Handles the Load event of the Page control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> private void Page_Load(object sender, System.EventArgs e) { // this is necessary so the 'clever' IE will also understand what to do: the enter key will then submit the form. this.ClientScript.RegisterHiddenField("__EVENTTARGET", "btnSearch"); if (!Page.IsPostBack) { // clear tmp results in session SessionAdapter.AddSearchTermsAndResults(string.Empty, null); // Read all the current existing forums and their section names. ForumsWithSectionNameTypedList forumsWithSectionName = ForumGuiHelper.GetAllForumsWithSectionNames(); // Get a list of Forum IDs to which the user has access right. List <int> accessableForums = SessionAdapter.GetForumsWithActionRight(ActionRights.AccessForum); foreach (ForumsWithSectionNameRow currentRow in forumsWithSectionName) { // filter out forums the user doesn't have access rights for. if (accessableForums.Contains(currentRow.ForumID)) { // forum is accessable to the user ListItem newItem = new ListItem(String.Format("{0} - {1}", currentRow.SectionName, currentRow.ForumName), currentRow.ForumID.ToString()); newItem.Selected = true; lbxForums.Items.Add(newItem); } } // make listbox as high as # of forums, with a maximum of 15 and a minimum of 8 if (lbxForums.Items.Count <= 15) { if (lbxForums.Items.Count > 8) { lbxForums.Rows = lbxForums.Items.Count; } else { lbxForums.Rows = 8; } } else { lbxForums.Rows = 15; } lblNumberOfPosts.Text = MessageGuiHelper.GetTotalNumberOfMessages().ToString(); } }
private void btnSearch_ServerClick(object sender, System.EventArgs e) { if (Page.IsValid) { // grab forum id's List <int> forumIDs = new List <int>(); for (int i = 0; i < lbxForums.Items.Count; i++) { if (lbxForums.Items[i].Selected) { forumIDs.Add(Convert.ToInt32(lbxForums.Items[i].Value)); } } if (forumIDs.Count <= 0) { // no forums selected, add all of them for (int i = 0; i < lbxForums.Items.Count; i++) { forumIDs.Add(Convert.ToInt32(lbxForums.Items[i].Value)); } } SearchResultsOrderSetting orderFirstElement = (SearchResultsOrderSetting)cbxSortByFirstElement.SelectedIndex; SearchResultsOrderSetting orderSecondElement = (SearchResultsOrderSetting)cbxSortBySecondElement.SelectedIndex; SearchTarget targetToSearch = (SearchTarget)cbxElementToSearch.SelectedIndex; string searchTerms = tbxSearchString.Value; if (searchTerms.Length > 1024) { searchTerms = searchTerms.Substring(0, 1024); } // Use Full text search variant. SearchResultTypedList results = BL.Searcher.DoSearch(searchTerms, forumIDs, orderFirstElement, orderSecondElement, SessionAdapter.GetForumsWithActionRight(ActionRights.ViewNormalThreadsStartedByOthers), SessionAdapter.GetUserID(), targetToSearch); // store results in session. SessionAdapter.AddSearchTermsAndResults(searchTerms, results); // view results. Response.Redirect("SearchResults.aspx?Page=1", true); } }
private void Page_Load(object sender, System.EventArgs e) { // clear tmp results in session SessionAdapter.AddSearchTermsAndResults(string.Empty, null); // Read all accessable forums for the current user. List <int> accessableForums = SessionAdapter.GetForumsWithActionRight(ActionRights.AccessForum); string[] forumIDs = Request.QueryString.GetValues("ForumID"); List <int> forumIDsToSearchIn = new List <int>(); if (forumIDs != null) { foreach (string forumIDAsString in forumIDs) { int forumID = HnDGeneralUtils.TryConvertToInt(forumIDAsString); if (accessableForums.Contains(forumID)) { forumIDsToSearchIn.Add(forumID); } } } else { // add all forums the user has access to forumIDsToSearchIn.AddRange(accessableForums); } string searchTerms = Request.QueryString.Get("SearchTerms"); if (searchTerms.Length > 1024) { searchTerms = searchTerms.Substring(0, 1024); } SearchResultTypedList results = BL.Searcher.DoSearch(searchTerms, forumIDsToSearchIn, SearchResultsOrderSetting.ForumAscending, SearchResultsOrderSetting.LastPostDateDescending, SessionAdapter.GetForumsWithActionRight(ActionRights.ViewNormalThreadsStartedByOthers), SessionAdapter.GetUserID(), SearchTarget.MessageText); // store results in session. SessionAdapter.AddSearchTermsAndResults(searchTerms, results); // view results. Response.Redirect("SearchResults.aspx?Page=1", true); }