No Description

aleukhin bd8df25503 1st com 6 months ago
.vs 4c683e1d66 1st com 6 months ago
WpfApp1 4c683e1d66 1st com 6 months ago
img 4c683e1d66 1st com 6 months ago
WpfApp1.sln 4c683e1d66 1st com 6 months ago
readme.md bd8df25503 1st com 6 months ago

readme.md

Табличка

#c l1

using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static WpfApp1.model.Globals;
using System.Threading.Tasks;

namespace WpfApp1.model
{
    public class Worker
    {
        public string name { get; set; }
        public int Age { get; set; }
        public string Pos { get; set; }
        public string Sex { get; set; }
        public List<WorkerPos> WorkerPosList { get; set; }
        public List<WorkerAge> WorkerAgeList { get; set; }
        public List<WorkerSex> WorkerSexList { get; set; }

    }
}

cl2

using System.Collections.Generic;
using System.Linq;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading.Tasks;

namespace WpfApp1.model
{
    class Globals
    {
        public static IDataProvider dataProvider;
        IEnumerable<WorkerPos> getWorkerPos()
        {
            return new WorkerPos[] {
                new WorkerPos { title = "Уборщик"},
                new WorkerPos { title = "Директор"},
                new WorkerPos { title = "Мастер"},
                new WorkerPos { title = "Стажер"},
                new WorkerPos { title = "Оператор"}
            };
        }
        IEnumerable<WorkerAge> getWorkerAge()
        {
            return new WorkerAge[] {
                new WorkerAge{title="Все возраста", AgeFrom=0, AgeTo=110},
                new WorkerAge{title="Дети", AgeFrom=1, AgeTo=100},
                new WorkerAge{title="Подростки", AgeFrom=100, AgeTo = 500},
                new WorkerAge{title="Мужчины", AgeFrom=500, AgeTo=700},
                new WorkerAge{title="Старики", AgeFrom=700, AgeTo=200}
            };
        }
        IEnumerable<WorkerSex> getWorkerSex()
        {
            return new WorkerSex[] {
                new WorkerSex { title = "Мужской"},
                new WorkerSex { title = "Женский"}
            };
        }
    }
}

cl3

using System;
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WpfApp1.model
{
    public class WorkerPos
    {
        public string title { get; set; }
    }
    public class WorkerAge
    {
        public string title { get; set; }
        public int AgeFrom { get; set; }
        public int AgeTo { get; set; }
    }

    public class WorkerSex
    {
        public string title { get; set; }
        public string Sex { get; set; }
    }
}

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 WpfApp1.model;
using System.Threading.Tasks;
using System;
using WpfApp1.model;
using WpfApp1.model;
using WpfApp1.model;

namespace WpfApp1
{
    /// <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("WorkerList"));
        }
        public string selectedPos = "Должность";
        public WorkerAge? selectedAge = null;
        public string selectedSex = "Пол";

        private IEnumerable<Worker> _WorkerList;
        public IEnumerable<Worker> WorkerList
        {
            get
            {
                var res = _WorkerList;

                res = res
                    .Where(c => (c.Pos == selectedPos || selectedPos == "Должность"))
                    .Where(c => (selectedAge == null || (c.Age >= selectedAge.AgeFrom && c.Age < selectedAge.AgeTo)))
                    .Where(c => (c.Sex == selectedSex || selectedSex == "Пол"));
                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
            {
                _WorkerList = value;
            }
        }

        public List<WorkerPos> WorkerPosList { get; set; }
        public List<WorkerAge> WorkerAgeList { get; set; }
        public List<WorkerSex> WorkerSexList { get; set; }
        public MainWindow()
        {
            InitializeComponent();
            DataContext = this;
            Globals.dataProvider = new LocalDataProvider();
            WorkerList = Globals.dataProvider.getWorker();
            WorkerPosList = Globals.dataProvider.getPos().ToList();
            WorkerPosList.Insert(0, new WorkerPos { title = "Должность" });
            WorkerAgeList = Globals.dataProvider.getAge().ToList();
            WorkerSexList = Globals.dataProvider.getSex().ToList();
            WorkerSexList.Insert(0, new WorkerSex { title = "Пол" });
        }

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

        }

        private void PosFilterComboBox_SelectionChanged_1(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
        {
            selectedPos = (PosFilterComboBox.SelectedItem as WorkerPos).title;
            Invalidate();
        }
        private void AgeFilterComboBox_SelectionChanged_2(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
        {
            selectedAge = (AgeFilterComboBox.SelectedItem as WorkerAge);
            Invalidate();
        }
        private void SexFilterComboBox_SelectionChanged_3(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
        {
            selectedSex = (SexFilterComboBox.SelectedItem as WorkerSex).title;
            Invalidate();
        }
        private string searchFilter = "";

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

        private void RadioButton_Checked(object sender, RoutedEventArgs e)
        {
            sortAsc = (sender as RadioButton).Tag.ToString() == "1";
            Invalidate();
        }
    }
    interface IDataProvider
    {
        IEnumerable<Worker> getWorker();
        IEnumerable<WorkerPos> getPos();
        IEnumerable<WorkerAge> getAge();
        IEnumerable<WorkerSex> getSex();
    }


    public class LocalDataProvider : IDataProvider
    {
        public IEnumerable<WorkerPos> getPos()
        {
            return new WorkerPos[]
            {
                new WorkerPos()
                {
                    title="Директор"

                },
                new WorkerPos()
                {
                    title="Продавец"
                },
                new WorkerPos()
                {
                    title="Механик"

                },
                new WorkerPos()
                {
                    title="Уборщик"

                },
                new WorkerPos()
                {
                    title="Стажер"

                },
                new WorkerPos()
                {
                    title="Оператор"

                },

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

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

                },
                new WorkerAge()
                {
                    title="Подростки",
                    AgeFrom=7,
                    AgeTo=21

                },
                new WorkerAge()
                {
                    title="Молодые",
                    AgeFrom=22,
                    AgeTo=50

                },
                new WorkerAge()
                {
                    title="Старики",
                    AgeFrom=51,
                    AgeTo=110

                }

            };

        }
        public IEnumerable<WorkerSex> getSex()
        {
            return new WorkerSex[]
            {
                new WorkerSex()
                {
                    title="Человек"
                },
                new WorkerSex()
                {
                    title="Женщина"
                }
            };
        }
        public IEnumerable<Worker> getWorker()
        {
            return new Worker[]{
            new Worker{
                Sex="Человек",
                name="Вася",
                Age=25,
                Pos="Директор"},
            new Worker{
                Sex="Человек",
                name="Петя",
                Age=45,
                Pos="Продавец"},
            new Worker{
                Sex="Человек",
                name="Степа",
                Age = 30,
                Pos="Механик"},
            new Worker{
                Sex="Человек",
                name="Миша",
                Age = 100,
                Pos="Стажер"},
            new Worker{
                Sex="Женщина",
                name="Лена",
                Age = 12,
                Pos="Оператор"}

        };


        }


    }

}

xaml

<Window x:Class="WpfApp1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfApp1"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    <Grid ShowGridLines="True">
        <Grid.RowDefinitions>
            <RowDefinition Height="auto"/>
            <RowDefinition />
            <RowDefinition Height="auto"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="200"/>
            <ColumnDefinition/>
        </Grid.ColumnDefinitions>

        <Image 
        Source="1.jpeg" 
        Grid.RowSpan="2" HorizontalAlignment="Right"/>
        <DataGrid
    Grid.Row="1"
    Grid.Column="1"
    CanUserAddRows="False"
    AutoGenerateColumns="False"
    ItemsSource="{Binding WorkerList}">
            <DataGrid.Columns>
                <DataGridTextColumn
Header="Имя"
Binding="{Binding name}"/>
                <DataGridTextColumn
Header="Возраст"
Binding="{Binding Age}"/>
                <DataGridTextColumn
Header="Должность"
Binding="{Binding Pos}"/>
                <DataGridTextColumn
Header="Пол"
Binding="{Binding Sex}"/>
            </DataGrid.Columns>
        </DataGrid>
        <StackPanel 
        Orientation="Vertical"
        Grid.RowSpan="3"
        VerticalAlignment="Bottom">
            <Button 
            x:Name="ExitButton"
            Content="Выход" 
            Click="ExitButton_Click"
            Height="50"/>
        </StackPanel>

        <WrapPanel
        Orientation="Horizontal"
        Grid.Column="1"
        MinHeight="50">
            <Label 
    Content="Должность:"
    VerticalAlignment="Center"/>

            <ComboBox
    Name="PosFilterComboBox"
    SelectionChanged="PosFilterComboBox_SelectionChanged_1"
    VerticalAlignment="Center"
    MinWidth="100"
    SelectedIndex="0"
    ItemsSource="{Binding WorkerPosList}">

                <ComboBox.ItemTemplate>
                    <DataTemplate>
                        <Label 
                Content="{Binding title}"/>
                    </DataTemplate>
                </ComboBox.ItemTemplate>
            </ComboBox>
            <Label 
Content="Возраст:"
VerticalAlignment="Center"/>
            <ComboBox
Name="AgeFilterComboBox"
SelectionChanged="AgeFilterComboBox_SelectionChanged_2"
VerticalAlignment="Center"
MinWidth="100"
SelectedIndex="0"
ItemsSource="{Binding WorkerAgeList}">

                <ComboBox.ItemTemplate>
                    <DataTemplate>
                        <Label 
            Content="{Binding title}"/>
                    </DataTemplate>
                </ComboBox.ItemTemplate>
            </ComboBox>
            <Label 
Content="Пол"
VerticalAlignment="Center"/>
            <ComboBox
Name="SexFilterComboBox"
SelectionChanged="SexFilterComboBox_SelectionChanged_3"
VerticalAlignment="Center"
MinWidth="100"
SelectedIndex="0"
ItemsSource="{Binding WorkerSexList}">

                <ComboBox.ItemTemplate>
                    <DataTemplate>
                        <Label 
            Content="{Binding title}"/>
                    </DataTemplate>
                </ComboBox.ItemTemplate>
            </ComboBox>
        </WrapPanel>
    </Grid>
</Window>