示例#1
0
        /// <summary>
        /// Ask what the user wants to search for
        /// </summary>
        private void AskForSearchParameters()
        {
            // Loops
            do
            {
                // Clears the Console
                Console.Clear();

                // Ask the user if he wants a specific type of ordering
                Console.WriteLine("Do you want a specific order? (y/n)");

                // If so...
                if ((pressedKey = Console.ReadKey().Key) == ConsoleKey.Y)
                {
                    // Let the user choose how the search results will be ordered
                    searchSettings.SetSearchParameters();
                }

                // Until the user selects an option of yes or no for the order by
            } while (pressedKey != ConsoleKey.Y && pressedKey != ConsoleKey.N);


            // Loops
            do
            {
                // Clears the Console
                Console.Clear();

                // Ask the user if he wants a specific type of ordering
                Console.WriteLine("Do you want to add filters? (y/n)");

                // If so...
                if ((pressedKey = Console.ReadKey().Key) == ConsoleKey.Y)
                {
                    // Ask the user what search filters he wants to use (Can be none)
                    AskForSearchFilters();
                }

                // Until the user selects an option of yes or no for the order by
            } while (pressedKey != ConsoleKey.Y && pressedKey != ConsoleKey.N);

            // Clears the Console
            Console.Clear();

            // Ask the user to search for what he wants
            Console.WriteLine("Search IMDB Input:");

            // Save what the user wants to search for
            searchString = Console.ReadLine();

            // Fill the list based on the search string
            TitleBasics.FillList(searchString);

            // Filter the list
            TitleBasics = listFilter.FilterTitles(searchSettings, TitleBasics);

            // Displays the Filtered title list
            DisplayFilteredList();
        }
示例#2
0
        /// <summary>
        /// The Class Empty Constructor
        /// </summary>
        public Menus()
        {
            // Initialize the Search Settings passing a reference to this script
            searchSettings = new SearchSettings(this);

            // Initialize the list filter
            listFilter = new ListFilter();

            // Initialise the TitleBasics
            TitleBasics = new ImdbTable();
        }
示例#3
0
        /// <summary>
        /// Filters the list with the given filters
        /// </summary>
        /// <param name="searchSet">Reference to the searchSettings</param>
        /// <param name="titleBasics">Main list with all the titles</param>
        /// <returns>A completly filtered list</returns>
        public ImdbTable FilterTitles(SearchSettings searchSet, ImdbTable titleBasics)
        {
            // Initialize a new filter to reduce the length of code
            TitleFilters filter = searchSet.TFilters;

            // Go through all the titles in the list
            for (int i = 0; i < titleBasics.Count; i++)
            {
                // If it's not null and is of type TitleBasics
                if (titleBasics[i] != null && titleBasics[i] is TitleBasics)
                {
                    // Add it to the temporary list
                    basicsTemp.Add((TitleBasics)titleBasics[i]);
                }
            }

            // Filters the temporary list using the filter parameters selected by the user
            basicsTemp = basicsTemp.Where(title =>
                                          (title.TitleType == filter.Type.ToString() || filter.Type == TitleType.none) &&
                                          (title.PrimaryTitle == filter.PrimaryTitle || filter.PrimaryTitle == null) &&
                                          (title.IsAdult == filter.Adult || filter.Adult == null) &&
                                          (title.StartYear == filter.StartDate || filter.StartDate == null) &&
                                          (title.EndYear == filter.EndDate || filter.EndDate == null) &&
                                          (filter.Genre == null ||
                                           ((title.Genres.Contains(filter.Genre[0].ToString().Contains("_") ?
                                                                   filter.Genre[0].ToString().Replace('_', '-') : filter.Genre[0].ToString()) ||
                                             filter.Genre[0] == null) &&
                                            (title.Genres.Contains(filter.Genre[1].ToString().Contains("_") ?
                                                                   filter.Genre[1].ToString().Replace('_', '-') : filter.Genre[1].ToString()) ||
                                             filter.Genre[1] == null) &&
                                            (title.Genres.Contains(filter.Genre[2].ToString().Contains("_") ?
                                                                   filter.Genre[2].ToString().Replace('_', '-') : filter.Genre[2].ToString()) ||
                                             filter.Genre[2] == null)))).ToList();

            // Clears the main title list
            titleBasics.Clear();

            // Goes through all the titles
            for (int i = 0; i < basicsTemp.Count; i++)
            {
                // Add it to the main titles list
                titleBasics.Add(basicsTemp[i]);
            }

            // Calls the SortList to return the fully filtered and ordered list
            return(SortList(searchSet, titleBasics));
        }
示例#4
0
        /// <summary>
        /// Responsible for sorting all titles acording to the selected sort method
        /// </summary>
        public ImdbTable SortList(SearchSettings searchSet, ImdbTable titleBasics)
        {
            // Clear the temporary list
            basicsTemp.Clear();

            // Go through all the titles in the list
            for (int i = 0; i < titleBasics.Count; i++)
            {
                // If it's not null and is of type TitleBasics
                if (titleBasics[i] != null && titleBasics[i] is TitleBasics)
                {
                    // Add it to the temporary list
                    basicsTemp.Add((TitleBasics)titleBasics[i]);
                }
            }

            switch (searchSet.TOrderBy)
            {
            // Sorts by Title name in alphabetical order
            case TitlesOrderBy.PrimaryTitle:
                basicsTemp = basicsTemp.OrderBy(title => title.PrimaryTitle).ToList();
                break;

            // Sorts by the type of title in alphabetical order
            case TitlesOrderBy.Type:
                basicsTemp = basicsTemp.OrderBy(title => title.TitleType).ToList();
                break;

            // Sorts by if is Adult
            case TitlesOrderBy.IsAdult:
                basicsTemp = basicsTemp.OrderBy(title => title.IsAdult == true).ToList();
                break;

            // Sorts by the Release Date
            case TitlesOrderBy.BeginingDate:
                basicsTemp = basicsTemp.OrderBy(title => title.StartYear).ToList();
                break;

            // Sorts by End Date
            case TitlesOrderBy.EndDate:
                basicsTemp = basicsTemp.OrderBy(title => title.EndYear != null).ToList();
                break;

            // Sorts by number of Owners Descending
            default:
                return(titleBasics);
            }

            // Clears the main titles list
            titleBasics.Clear();

            // Goes through all the titles
            for (int i = 0; i < basicsTemp.Count; i++)
            {
                // Add it to the main titles list
                titleBasics.Add(basicsTemp[i]);
            }

            // Returns the fully filtered and ordered list
            return(titleBasics);
        }