示例#1
0
        private Filtr GetFiltrationValues()
        {
            Filtr filtrObj = new Filtr();

            var itemSelected = GenreList.SelectedIndex > -1;

            filtrObj.Genre = itemSelected ? GenreList.SelectedItem.ToString() : "";

            itemSelected            = LevelOfInterests.SelectedIndex > -1;
            filtrObj.InterestsLevel = itemSelected ? LevelOfInterests.SelectedItem.ToString() : "";

            itemSelected     = Countries.SelectedIndex > -1;
            filtrObj.Country = itemSelected ? Countries.SelectedItem.ToString() : "";

            int n;

            var isNumeric = int.TryParse(YearSince.Text, out n);

            filtrObj.SinceYear = isNumeric ? YearSince.Text : "";

            isNumeric       = int.TryParse(YearTo.Text, out n);
            filtrObj.ToYear = isNumeric ? YearTo.Text : "";

            float d;
            var   isFloat = float.TryParse(RateSince.Text, out d);

            filtrObj.SinceRate = isFloat ? RateSince.Text : "";

            isFloat         = float.TryParse(RateTo.Text, out d);
            filtrObj.ToRate = isFloat ? RateTo.Text : "";

            return(filtrObj);
        }
示例#2
0
        private void Filtration_Click(object sender, EventArgs e)
        {
            Filtr filtr = new Filtr();

            filtr = GetFiltrationValues();

            actualList = MoviesList.ToList();

            if (filtr.Genre != "")
            {
                List <Movie> genresFiltr = MoviesList.Where(q => q.Genre.Contains(filtr.Genre)).ToList();
                actualList = actualList.Intersect(genresFiltr).ToList();
            }

            if (filtr.SinceYear != "")
            {
                List <Movie> yearSinceFiltr = MoviesList.Where(q => Int32.Parse(q.Year) >= Int32.Parse(filtr.SinceYear)).ToList();
                actualList = actualList.Intersect(yearSinceFiltr).ToList();
            }

            if (filtr.ToYear != "")
            {
                List <Movie> yearToFiltr = MoviesList.Where(q => Int32.Parse(q.Year) <= Int32.Parse(filtr.ToYear)).ToList();
                actualList = actualList.Intersect(yearToFiltr).ToList();
            }

            if (MainWindow.LoadRates())
            {
                if (filtr.SinceRate != "")
                {
                    List <Movie> rateSinceFiltr = MoviesList.Where(q => q.Rate != "" && ((float.Parse(q.Rate) >= float.Parse(filtr.SinceRate))))
                                                  .ToList();
                    actualList = actualList.Intersect(rateSinceFiltr).ToList();
                }
                if (filtr.ToRate != "")
                {
                    List <Movie> rateToFiltr = MoviesList.Where(q => q.Rate != "" && (float.Parse(q.Rate) <= float.Parse(filtr.ToRate))).ToList();
                    actualList = actualList.Intersect(rateToFiltr).ToList();
                }
            }

            if (filtr.Country != "")
            {
                List <Movie> countriesFiltr = MoviesList.Where(q => q.Country.Contains(filtr.Country)).ToList();
                actualList = actualList.Intersect(countriesFiltr).ToList();
            }

            if (filtr.InterestsLevel != "")
            {
                List <Movie> interestsFiltr = MoviesList.Where(q => q.HowMuchWantSee.Contains(filtr.InterestsLevel)).ToList();
                actualList = actualList.Intersect(interestsFiltr).ToList();
            }


            SetGridValues(actualList);
        }