Geen omschrijving

Капралов Александр Викторович 21dbe86568 Обновить 'readme.md' 6 maanden geleden
bin 48c4a0639b lab 6 maanden geleden
img 48c4a0639b lab 6 maanden geleden
model 48c4a0639b lab 6 maanden geleden
obj 48c4a0639b lab 6 maanden geleden
App.xaml 48c4a0639b lab 6 maanden geleden
App.xaml.cs 48c4a0639b lab 6 maanden geleden
AssemblyInfo.cs 48c4a0639b lab 6 maanden geleden
MainWindow.xaml 48c4a0639b lab 6 maanden geleden
MainWindow.xaml.cs 48c4a0639b lab 6 maanden geleden
WpfApp4.csproj 48c4a0639b lab 6 maanden geleden
WpfApp4.csproj.user 48c4a0639b lab 6 maanden geleden
readme.md 21dbe86568 Обновить 'readme.md' 6 maanden geleden

readme.md

Поиск, сортировка

Сортировка

MainWindow.xaml.cs

using System.ComponentModel;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

using WpfApp4.model;
using System.Threading.Tasks;
using System;
using WpfApp4.model;

namespace WpfApp4
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>

    public partial class MainWindow : Window, INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;
        private void Invalidate()
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs("HeroList"));
        }
        public string selectedPower = "Мощь";
        public HeroAge? selectedAge = null;
        public string selectedRace = "Раса";

        private IEnumerable<Hero> _HeroList;
        public IEnumerable<Hero> HeroList
        {
            get
            {
                var res = _HeroList;

                res = res
                    .Where(c => (c.power == selectedPower || selectedPower == "Мощь"))
                    .Where(c => (selectedAge == null || (c.Age >= selectedAge.AgeFrom && c.Age < selectedAge.AgeTo)))
                    .Where(c => (c.race == selectedRace || selectedRace == "Раса"));
                if (searchFilter != "")
                    res = res.Where(c => c.name.IndexOf(
                        searchFilter,
                        StringComparison.OrdinalIgnoreCase) >= 0);
                if (sortAsc) res = res.OrderBy(c => c.Age);
                else res = res.OrderByDescending(c => c.Age);

                return res;

            }
            set
            {
                _HeroList = value;
            }
        }

        public List<HeroPower> HeroPowerList { get; set; }
        public List<HeroAge> HeroAgeList { get; set; }
        public List<HeroRace> HeroRaceList { get; set; }
        public MainWindow()
        {
            InitializeComponent();
            DataContext = this;
            Globals.dataProvider = new LocalDataProvider();
            HeroList = Globals.dataProvider.getHero();
            HeroPowerList = Globals.dataProvider.getPower().ToList();
            HeroPowerList.Insert(0, new HeroPower { title = "Мощь" });
            HeroAgeList = Globals.dataProvider.getAge().ToList();
            HeroRaceList = Globals.dataProvider.getRace().ToList();
            HeroRaceList.Insert(0, new HeroRace { title = "Раса" });
        }

        private void ExitButton_Click(object sender, RoutedEventArgs e)
        {
            Application.Current.Shutdown();

        }

        private void powerFilterComboBox_SelectionChanged_1(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
        {
            selectedPower = (powerFilterComboBox.SelectedItem as HeroPower).title;
            Invalidate();
        }
        private void AgeFilterComboBox_SelectionChanged_2(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
        {
            selectedAge = AgeFilterComboBox.SelectedItem as HeroAge;
            Invalidate();
        }
        private void RaceFilterComboBox_SelectionChanged_3(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
        {
            selectedRace = (RaceFilterComboBox.SelectedItem as HeroRace).title;
            Invalidate();
        }
        private string searchFilter = "";

        private void SearchFilter_KeyUp(object sender, KeyEventArgs e)
        {
            searchFilter = SearchFilterTextBox.Text;
            Invalidate();
        }
        private bool sortAsc = true;

        private void RadioButton_Checked(object sender, RoutedEventArgs e)
        {
            sortAsc = (sender as RadioButton).Tag.ToString() == "1";
            Invalidate();
        }
    }
    interface IDataProvider
    {
        IEnumerable<Hero> getHero();
        IEnumerable<HeroPower> getPower();
        IEnumerable<HeroAge> getAge();
        IEnumerable<HeroRace> getRace();
    }


    public class LocalDataProvider : IDataProvider
    {
        public IEnumerable<HeroPower> getPower()
        {
            return new HeroPower[]
            {
                new HeroPower()
                {
                    title="1/10"

                },
                new HeroPower()
                {
                    title="2/10"
                },
                new HeroPower()
                {
                    title="3/10"

                },
                new HeroPower()
                {
                    title="4/10"

                },
                new HeroPower()
                {
                    title="5/10"

                },
                new HeroPower()
                {
                    title="6/10"

                },
                new HeroPower()
                {
                    title="7/10"

                },
                new HeroPower()
                {
                    title="8/10"

                },
                new HeroPower()
                {
                    title="9/10"

                },
                new HeroPower()
                {
                    title="10/10"

                },

            };
        }
        public IEnumerable<HeroAge> getAge()
        {
            return new HeroAge[]
            {
                new HeroAge()
                {
                    title="Все возраста",
                    AgeFrom=0,
                    AgeTo=2000

                },
                new HeroAge()
                {
                    title="Дети",
                    AgeFrom=1,
                    AgeTo=100

                },
                new HeroAge()
                {
                    title="Подростки",
                    AgeFrom=100,
                    AgeTo=500

                },
                new HeroAge()
                {
                    title="Молодые",
                    AgeFrom=500,
                    AgeTo=700

                },
                new HeroAge()
                {
                    title="Старики",
                    AgeFrom=700,
                    AgeTo=2000

                }

            };

        }
        public IEnumerable<HeroRace> getRace()
        {
            return new HeroRace[]
            {
                new HeroRace()
                {
                    title="Человек"
                },
                new HeroRace()
                {
                    title="Дракон"
                },
                new HeroRace()
                {
                    title="Фея"
                },
                new HeroRace()
                {
                    title="Огр"
                },
                new HeroRace()
                {
                    title="Рыба"
                },
                new HeroRace()
                {
                    title="Селёдка"
                },
                new HeroRace()
                {
                    title="Камень"
                },
                new HeroRace()
                {
                    title="Гоблин"
                },
            };
        }
        public IEnumerable<Hero> getHero()
        {
            return new Hero[]{
            new Hero{
                race="Человек",
                name="Invoker",
                Age=1000,
                power="10/10"},
            new Hero{
                race="Человек",
                name="Juggernaut",
                Age=450,
                power="9/10"},
            new Hero{
                race="Человек",
                name="lina",
                Age = 300,
                power="8/10"},
            new Hero{
                race="Огр",
                name="Troll Warloard",
                Age = 100,
                power="7/10"},
            new Hero{
                race="Рыба",
                name="Slark",
                Age = 120,
                power="6/10"},
            new Hero{
                race="Селёдка",
                name="Slardar",
                Age = 200,
                power="5/10"},
            new Hero{
                race="Камень",
                name="Tiny",
                Age = 20000,
                power="4/10"},
            new Hero{
                race="Фея",
                name="Dark Willow",
                Age = 700,
                power="3/10"},
            new Hero{
                race="Огр",
                name="Orge Magi",
                Age = 1400,
                power="2/10"},
            new Hero{
                race="Дракон",
                name="Viper",
                Age = 1900,
                power="1/10"},

        };


        }


    }

}