Example #1
0
        static public string[,] Search(string column, string searchString, bool considerCase, bool matchWhole)
        {
            try
            {
                List <string> foundItems_Speaker = new List <string>();
                List <string> foundItems_Title   = new List <string>();
                List <string> foundItems_ID      = new List <string>();

                Database.Sermon        dummy   = new Database.Sermon();
                List <Database.Sermon> sermons = dummy.SelectAll();

                if (!considerCase)//considerCase == false: do not match case
                {
                    if (matchWhole)
                    {
                        foreach (Database.Sermon sermon in sermons)
                        {
                            if (SermonSwitch(sermon, column).ToLower() == searchString.ToLower())
                            {
                                SearchGetValues(ref foundItems_ID, ref foundItems_Speaker, ref foundItems_Title, sermon);
                            }
                        }
                    }
                    else
                    {
                        foreach (Database.Sermon sermon in sermons)
                        {
                            if (StringSearch.AllExist_InOrder(SermonSwitch(sermon, column).ToLower(), searchString.ToLower()))
                            {
                                SearchGetValues(ref foundItems_ID, ref foundItems_Speaker, ref foundItems_Title, sermon);
                            }
                        }
                    }
                }
                else//considerCase == true: match case
                {
                    if (matchWhole)
                    {
                        foreach (Database.Sermon sermon in sermons)
                        {
                            if (SermonSwitch(sermon, column) == searchString)
                            {
                                SearchGetValues(ref foundItems_ID, ref foundItems_Speaker, ref foundItems_Title, sermon);
                            }
                        }
                    }
                    else
                    {
                        foreach (Database.Sermon sermon in sermons)
                        {
                            if (StringSearch.AllExist_InOrder(SermonSwitch(sermon, column), searchString))
                            {
                                SearchGetValues(ref foundItems_ID, ref foundItems_Speaker, ref foundItems_Title, sermon);
                            }
                        }
                    }
                }
                string[,] foundItems = new string[3, foundItems_Title.Count];
                for (int i = 0; i < foundItems_ID.Count; i++)
                {
                    foundItems[0, i] = foundItems_Title[i];
                    foundItems[1, i] = foundItems_Speaker[i];
                    foundItems[2, i] = foundItems_ID[i];
                }
                return(foundItems);
            }
            catch
            {
                return(null);
            }
        }
Example #2
0
        /// <summary>
        /// Ascertains the presence of the Bible book in the search string passed to it.
        /// </summary>
        /// <param name="search">String containing the book to be confirmed.</param>
        /// <returns></returns>
        private static string ConfirmBibleBookName(string search)
        {
            if (!string.IsNullOrEmpty(search))
            {
                search = search.Trim();
                try
                {
                    /* Best search:
                     * Entire search string occurs as it is i.e.
                     *  searchedString == searchString
                     */
                    foreach (XmlElement XMLElement in BibleBookNames.ChildNodes)
                    {
                        if (XMLElement.Attributes["abbr"].Value.ToLower() == search.ToLower())
                        {
                            return(XMLElement.Attributes["c"].Value);
                        }
                        else if (XMLElement.Attributes["short"].Value.ToLower() == search.ToLower())
                        {
                            return(XMLElement.Attributes["c"].Value);
                        }
                    }

                    /* 2nd best search:
                     * First letter match
                     * searchedString contains the searchString in order i.e.
                     *  searchedString == searchStringxyzabc
                     */
                    foreach (XmlElement XMLElement in BibleBookNames.ChildNodes)
                    {
                        if (StringSearch.AllExist_InOrder(XMLElement.Attributes["abbr"].Value.ToLower(), search.ToLower()) &&
                            XMLElement.Attributes["abbr"].Value.ToLower()[0] == search.ToLower()[0])
                        {
                            return(XMLElement.Attributes["c"].Value);
                        }
                        else if (StringSearch.AllExist_InOrder(XMLElement.Attributes["short"].Value.ToLower(), search.ToLower()) &&
                                 XMLElement.Attributes["short"].Value.ToLower()[0] == search.ToLower()[0])
                        {
                            return(XMLElement.Attributes["c"].Value);
                        }
                    }

                    /* 3rd best search:
                     * searchedString contains the searchString in order i.e.
                     *  searchedString == abcsearchStringxyz
                     */
                    foreach (XmlElement XMLElement in BibleBookNames.ChildNodes)
                    {
                        if (StringSearch.AllExist_InOrder(XMLElement.Attributes["abbr"].Value.ToLower(), search.ToLower()))
                        {
                            return(XMLElement.Attributes["c"].Value);
                        }
                        else if (StringSearch.AllExist_InOrder(XMLElement.Attributes["short"].Value.ToLower(), search.ToLower()))
                        {
                            return(XMLElement.Attributes["c"].Value);
                        }
                    }

                    /* Worst search
                     * searchedString contains the searchString in whichever order of occurrence of letters
                     */
                    foreach (XmlElement XMLElement in BibleBookNames.ChildNodes)
                    {
                        if (StringSearch.AllExist(XMLElement.Attributes["abbr"].Value.ToLower(), search.ToLower()))
                        {
                            return(XMLElement.Attributes["c"].Value);
                        }
                        else if (StringSearch.AllExist(XMLElement.Attributes["short"].Value.ToLower(), search.ToLower()))
                        {
                            return(XMLElement.Attributes["c"].Value);
                        }
                    }
                    return(null);
                }
                catch
                {
                    return(null);
                }
            }
            else
            {
                return(null);
            }
        }