private void txt_Search_TextChanged(object sender, EventArgs e) { if (txt_Search.Text == "" && ColumnHeaderMouseClickEventOn == false) { comboBox1.Text = "All Components"; foreach (Projects P in Projects.ProjectList) { if (txt_projectName.Text == P.ProjectName) { dataGridView1.DataSource = P.ProjectDT; break; } } } else if (txt_Search.Text != "" && ColumnHeaderMouseClickEventOn == false) { DynamicSearch D = new DynamicSearch(); D.TextChanged += D.Sort1; D.TextChanged += D.Sort2; D.TextChanged += D.Sort3; D.TextChanged += D.Sort4; D.TextChanged += D.Sort5; D.TextChanged += D.Sort6; D.TextChanged += D.Sort7; D.TextChanged += D.Sort8; //Subscribe all the sorts to the one event D.InvokeDynamicSearch(txt_Search.Text); List <DataTable> ListToDisplay = new List <DataTable>(); ListToDisplay.Add(D.Sort1(txt_Search.Text)); ListToDisplay.Add(D.Sort2(txt_Search.Text)); ListToDisplay.Add(D.Sort3(txt_Search.Text)); ListToDisplay.Add(D.Sort4(txt_Search.Text)); ListToDisplay.Add(D.Sort5(txt_Search.Text)); ListToDisplay.Add(D.Sort6(txt_Search.Text)); ListToDisplay.Add(D.Sort7(txt_Search.Text)); ListToDisplay.Add(D.Sort8(txt_Search.Text)); var dataTable = from T in ListToDisplay orderby T.Rows.Count descending select T; List <DataTable> SortedDataTableList = new List <DataTable>(dataTable); dataGridView1.DataSource = SortedDataTableList[0]; } else if (txt_Search.Text != "" && ColumnHeaderMouseClickEventOn == true) { DynamicSearch D = new DynamicSearch(); dataGridView1.DataSource = D.SortSingleColumn(txt_Search.Text, clickedColumnIndex); } else if (txt_Search.Text == "" && ColumnHeaderMouseClickEventOn == true) { comboBox1.Text = "All Components"; foreach (Projects P in Projects.ProjectList) { if (txt_projectName.Text == P.ProjectName) { dataGridView1.DataSource = P.ProjectDT; break; } } } }
private void processData() { try { if (this.SearchList != null) { // Validate(); int actualMaxResult = this.SearchList.MaxResults; DateTime startDate = StartDate, endDate = EndDate; string keyWord = KeyWords; string siteName = SiteName; if (this.SearchList.SearchType == "keyword") { startDate = DateTime.MinValue; endDate = DateTime.MaxValue; } else if (this.SearchList.SearchType == "date") { keyWord = string.Empty; } int year = 0; Dictionary <string, string> filters = GetUrlFilters(); if (startDate == DateTime.MinValue && endDate == DateTime.MaxValue && filters.ContainsKey("year")) { try { year = Int32.Parse(filters["year"]); if (filters.ContainsKey("month")) { try { int month = Int32.Parse(filters["month"]); int lastDay = DateTime.DaysInMonth(year, month); startDate = new DateTime(year, month, 1); endDate = new DateTime(year, month, lastDay); } catch { NCI.Web.CDE.Application.ErrorPageDisplayer.RaisePageByCode("BaseSearchSnippet", 404, "Invalid month parameter in dynamic list filter"); } } else { startDate = new DateTime(year, 1, 1); endDate = new DateTime(year, 12, 31); } } catch { NCI.Web.CDE.Application.ErrorPageDisplayer.RaisePageByCode("BaseSearchSnippet", 404, "Invalid year parameter in dynamic list filter"); } } if (startDate == DateTime.MinValue && endDate == DateTime.MaxValue && filters.ContainsKey("month") && !filters.ContainsKey("year")) { NCI.Web.CDE.Application.ErrorPageDisplayer.RaisePageByCode("BaseSearchSnippet", 404, "Invalid parameter in dynamic list filter: cannot have month without year"); } List <TaxonomyFilter> filtersForSql = new List <TaxonomyFilter>(this.SearchList.SearchFilters.TaxonomyFilters.Where(filter => filter.Taxons.Count() > 0)); foreach (KeyValuePair <string, string> entry in filters) { if (entry.Key != "year" && entry.Key != "month") { bool contains = filtersForSql.Any(filter => filter.TaxonomyName == entry.Key); if (!contains) { TaxonomyFilter newFilter = new TaxonomyFilter(); newFilter.TaxonomyName = entry.Key; List <int> taxonIDs = entry.Value.Split(',').Select(Int32.Parse).ToList(); List <Taxon> newTaxons = new List <Taxon>(); foreach (int ID in taxonIDs) { Taxon newTaxon = new Taxon(); newTaxon.ID = ID; newTaxons.Add(newTaxon); } newFilter.Taxons = newTaxons.ToArray <Taxon>(); filtersForSql.Add(newFilter); } } } // Call the datamanger to perform the search ICollection <SearchResult> searchResults = SearchDataManager.Execute(CurrentPage, startDate, endDate, keyWord, ReturnTaxonomySqlParam(filtersForSql), this.SearchList.RecordsPerPage, this.SearchList.MaxResults, this.SearchList.SearchFilter, this.SearchList.ExcludeSearchFilter, this.SearchList.ResultsSortOrder, this.SearchList.Language, Settings.IsLive, out actualMaxResult, siteName); DynamicSearch dynamicSearch = new DynamicSearch(); dynamicSearch.Results = searchResults; dynamicSearch.StartDate = String.Format("{0:MM/dd/yyyy}", startDate); dynamicSearch.EndDate = String.Format("{0:MM/dd/yyyy}", endDate); dynamicSearch.KeyWord = keyWord; dynamicSearch.SiteName = siteName; dynamicSearch.DisqusShortname = this.SearchList.DisqusShortname; dynamicSearch.SearchTitle = this.SearchList.SearchTitle; // check if the site is in production bool isProd = PageAssemblyContext.Current.IsProd; // append a shortname prefix based on the production state dynamicSearch.DisqusShortname = dynamicSearch.DisqusShortname + (isProd ? "-prod" : "-dev"); this.PageInstruction.AddUrlFilter("Print", (name, url) => { if (url.QueryParameters.ContainsKey("keyword") == false) { url.QueryParameters.Add("keyword", keyWord); } if (!((dynamicSearch.StartDate == "01/01/0001") || (dynamicSearch.EndDate == "12/31/9999"))) { url.QueryParameters.Add("startmonth", startDate.Month.ToString()); url.QueryParameters.Add("startyear", startDate.Year.ToString()); url.QueryParameters.Add("endmonth", endDate.Month.ToString()); url.QueryParameters.Add("endyear", endDate.Year.ToString()); } }); if (actualMaxResult > 0) { if (CurrentPage > 1) { dynamicSearch.StartCount = (this.SearchList.RecordsPerPage * (CurrentPage - 1)) + 1; } else { dynamicSearch.StartCount = 1; } if (CurrentPage == 1) { dynamicSearch.EndCount = this.SearchList.RecordsPerPage; if (searchResults.Count < this.SearchList.RecordsPerPage) { dynamicSearch.EndCount = actualMaxResult; } } else { dynamicSearch.EndCount = dynamicSearch.StartCount + this.SearchList.RecordsPerPage - 1; if (searchResults.Count < this.SearchList.RecordsPerPage) { dynamicSearch.EndCount = actualMaxResult; } } } int recCount = 0; foreach (SearchResult sr in searchResults) { sr.RecNumber = dynamicSearch.StartCount + recCount++; } int validCount = this.SearchList.MaxResults; if (actualMaxResult < this.SearchList.MaxResults || this.SearchList.MaxResults == 0) { validCount = actualMaxResult; } else { validCount = this.SearchList.MaxResults; } dynamicSearch.ResultCount = validCount; LiteralControl ltl = new LiteralControl(VelocityTemplate.MergeTemplateWithResultsByFilepath(this.SearchList.ResultsTemplate, dynamicSearch)); Controls.Add(ltl); if (this.SearchList.ResultsTemplate.Contains("Blog")) { SetupBlogPager(this.SearchList.RecordsPerPage, validCount, filters); } else { SetupPager(this.SearchList.RecordsPerPage, validCount, filters); } } } catch (ThreadAbortException) { throw; } catch (Exception ex) { log.Error("this.SearchListSnippet:processData", ex); } }