/// <summary> /// Method used to query database for English language results. This will return the /// data in XML format. There is no way to create an additional WebGet so that we /// can return the same data in JSON format. /// </summary> /// <param name="language">The language needed to do the lookup</param> /// <param name="criteria">The partial text used to query the database</param> /// <param name="maxRows">The maximum number of rows that the database will return. a value of zero will return the entire set</param> /// <param name="contains">Indicator on whether the text is to be search from the beginning of the text or anywhere in the string</param> /// <param name="dictionary">Which Term dicitonary to search - Cancer.gov or Genetics</param> /// <param name="audience">Definition audience - Patient or Health professional</param> /// <returns>Returns the search results</returns> private TermDictionaryServiceCollection Search(string language, string criteria, int maxRows, bool contains, string dictionary, string audience) { // create the collection variable TermDictionaryServiceCollection sc = new TermDictionaryServiceCollection(); try { // language passed to an enum DisplayLanguage displayLanguage = (DisplayLanguage)Enum.Parse(typeof(DisplayLanguage), language); // Call the database query TermDictionaryCollection dc = TermDictionaryManager.Search(language, criteria, maxRows, contains, dictionary, audience); // Use Linq to extract the data from the business layer and create // the service data objects var collection = dc.ConvertAll(entry => new TermDictionaryServiceItem( entry.GlossaryTermID, entry.TermName, string.Empty )); sc.AddRange(collection); } catch (Exception ex) { // Log the error that occured CancerGovError.LogError("TermDictionary", 2, ex); } return(sc); }
/// <summary> /// This methods filters the information passed to it in order to refine the query /// that will be called in the database layer. /// </summary> /// <param name="language">enumeration indicating language</param> /// <param name="criteria">The partial text used to query the database</param> /// <param name="maxRows">The maximum number of rows that the database will return. a value of zero will return the entire set</param> /// <param name="contains">indicator as to whether the text is to be searched starting from the beginning or anywhere /// in the string</param> /// <param name="pageNumber">The page for which the records should be returned.The records returned /// will always equal maxRows in every page.</param> /// <returns>Returns the search results</returns> public static TermDictionaryCollection GetTermDictionaryList(string language, string criteria, bool contains, int maxRows, int pageNumber, ref int totalRecordCount) { TermDictionaryCollection dc = new TermDictionaryCollection(); totalRecordCount = 0; // Find out how we should search for the string if (Strings.Clean(criteria) != null) { // replace any '[' with '[[]' //criteria = criteria.Replace("[", "[[]"); // put the '%' at the end to indicate that the search starts // with the criteria passed. criteria += "%"; // put the '%' at the beginning to indicate that the search // data contains the criteria passed if (contains) { criteria = "%" + criteria; } // Find out the field we need to get to build our list string fieldName = "TermName"; if (language == "Spanish") { fieldName = language.ToString() + fieldName; } try { // Call the database layer and get data DataTable dt = TermDictionaryQuery.GetTermDictionaryList( language.ToString(), criteria, maxRows, pageNumber, ref totalRecordCount); // use Linq to move information from the dataTable // into the TermDictionaryCollection dc.AddRange( from entry in dt.AsEnumerable() select GetEntryFromDR(entry) ); } catch (Exception ex) { CancerGovError.LogError("TermDictionatyManager", 2, ex); throw ex; } } return(dc); }
/// <summary> /// Returns a TermDictionaryServiceList which contains a collection of Term Dictionary /// items and the total number of records. /// </summary> /// <param name="language"></param> /// <param name="criteria"></param> /// <param name="contains"></param> /// <param name="maxRows">Maxrows is treated as recordPerPage or the topN records. /// Used for records per page when pagenumber is 0 or greater than 0. /// If pagenumber is -1 number records returned is specified by maxRows. /// If maxRows=0 and pageNumber=-1 all records are returned.</param> /// <param name="pageNumber">Specifies the pagenumber for which the records should be returned. /// If pagenumber is -1 number records returned is specified by maxRows. /// If maxRows=0 and pageNumber=-1 all records are returned.</param> /// <returns></returns> private TermDictionaryServiceList getTermDictionaryList(string language, string criteria, bool contains, int maxRows, int pageNumber) { TermDictionaryServiceList sc = new TermDictionaryServiceList(); sc.TermDictionaryServiceCollection = new TermDictionaryServiceCollection(); sc.TotalRecordCount = 0; try { int totalRecordCount = 0; // No criteria specified if (string.IsNullOrEmpty(criteria)) { return(sc); } // if maxrows is 0 and pagenumber is > 0 then return empty. if ((maxRows == 0 && pageNumber >= 0) || (maxRows < 0)) { return(sc); } if (pageNumber == 0) { pageNumber = 1; } // language passed to an enum DisplayLanguage displayLanguage = (DisplayLanguage)Enum.Parse(typeof(DisplayLanguage), language); // Call the database query TermDictionaryCollection dc = TermDictionaryManager.GetTermDictionaryList(language, criteria, contains, maxRows, pageNumber, ref totalRecordCount); // Use Linq to extract the data from the business layer and create // the service data objects sc.TermDictionaryServiceCollection.AddRange( from entry in dc select createTermDictionarySvcItem(entry) ); sc.TotalRecordCount = totalRecordCount; } catch (Exception ex) { // Log the error that occured CancerGovError.LogError("TermDictionary", 2, ex); } return(sc); }
protected void Page_Load(object sender, EventArgs e) { // Dictionary query parameters string expandParam = Strings.Clean(Request.QueryString["expand"], "A"); //string languageParam = Strings.Clean(Request.QueryString["language"]); string languageParam = ""; //disable language selection by query parameter SearchString = Strings.Clean(Request.QueryString["search"]); //Create a safe search string to be passed to the URL string _safeSearchString = System.Web.HttpContext.Current.Server.UrlEncode(SearchString); _term = Strings.Clean(Request.QueryString["term"]); _version = Strings.Clean(Request.QueryString["version"]); if (!String.IsNullOrEmpty(SearchString)) { SearchString = SearchString.Replace("[", "[[]"); } // Pager query parameter variables _currentPage = Strings.ToInt(Request.Params["PageNum"], 1); _recordsPerPage = Strings.ToInt(Request.Params["RecordsPerPage"], 10); _offSet = Strings.ToInt(Request.Params["OffSet"], 0); //Determine Language - set language related values string pageTitle; string buttonText; string language; string reDirect; MobileTermDictionary.DetermineLanguage(languageParam, out language, out pageTitle, out buttonText, out reDirect); _language = language; _dictionaryURL = PageAssemblyContext.Current.PageAssemblyInstruction.GetUrl("CurrentUrl").ToString(); litPageUrl.Text = _dictionaryURL; litSearchBlock.Text = MobileTermDictionary.SearchBlock(_dictionaryURL, SearchString, language, pageTitle, buttonText, true); // Setup Pager variables int pager_StartRecord = 0; int pager_EndRecord = 0; int pager_MaxRows = 0; int pager_RowsPerPage = 10; TermDictionaryCollection dataCollection = null; if (!String.IsNullOrEmpty(SearchString)) // SearchString provided, do a term search { PageAssemblyContext.Current.PageAssemblyInstruction.AddUrlFilter(PageAssemblyInstructionUrls.AltLanguage, (name, url) => { url.QueryParameters.Add("search", _safeSearchString); }); PageAssemblyContext.Current.PageAssemblyInstruction.AddUrlFilter("CurrentUrl", (name, url) => { url.QueryParameters.Add("search", _safeSearchString); }); dataCollection = TermDictionaryManager.GetTermDictionaryList(language, SearchString, false, pager_RowsPerPage, _currentPage, ref pager_MaxRows); } else if (!String.IsNullOrEmpty(Term)) { DisplayLanguage dl; if (Language.ToLower().Trim() == "spanish") { dl = DisplayLanguage.Spanish; } else { dl = DisplayLanguage.English; } TermDictionaryDataItem di = TermDictionaryManager.GetDefinitionByTermName(dl, Term, Version, 2); string itemDefinitionUrl = DictionaryURL + "?cdrid=" + di.GlossaryTermID; Page.Response.Redirect(itemDefinitionUrl); } else if (!String.IsNullOrEmpty(expandParam)) // A-Z expand provided - do an A-Z search { _showDefinition = false; _expand = true; if (expandParam.Length > 0) { _expandText = expandParam.Substring(0, 1); if (_expandText == "#") { _expandText = "[0-9]"; } } else { _expandText = ""; } PageAssemblyContext.Current.PageAssemblyInstruction.AddUrlFilter(PageAssemblyInstructionUrls.AltLanguage, (name, url) => { url.QueryParameters.Add("expand", _expandText); }); PageAssemblyContext.Current.PageAssemblyInstruction.AddUrlFilter("CurrentUrl", (name, url) => { url.QueryParameters.Add("expand", _expandText); }); dataCollection = TermDictionaryManager.GetTermDictionaryList(language, _expandText.Trim().ToUpper(), false, pager_RowsPerPage, _currentPage, ref pager_MaxRows); } if (dataCollection != null) { if (dataCollection.Count == 1 && !Expand) //if there is only 1 record - go directly to definition view { //string itemDefinitionUrl = DictionaryURL + "?cdrid=" + dataCollection[0].GlossaryTermID + "&language=" + Language; string itemDefinitionUrl = DictionaryURL + "?cdrid=" + dataCollection[0].GlossaryTermID; Page.Response.Redirect(itemDefinitionUrl); } else // bind results { resultListView.DataSource = dataCollection; resultListView.DataBind(); } SimplePager.GetFirstItemLastItem(_currentPage, pager_RowsPerPage, pager_MaxRows, out pager_StartRecord, out pager_EndRecord); spPager.RecordCount = pager_MaxRows; spPager.RecordsPerPage = pager_RowsPerPage; spPager.CurrentPage = _currentPage; if (Expand) { spPager.BaseUrl = DictionaryURL + "?expand=" + _expandText; } else { spPager.BaseUrl = DictionaryURL + "?search=" + _safeSearchString; } if (IsSpanish) { spPager.PagerStyleSettings.NextPageText = "Siguiente >"; spPager.PagerStyleSettings.PrevPageText = "< Anterior"; } } }