Nav apraksta

jgrebnev 92dcfc82e8 2comm 6 mēneši atpakaļ
WpfApp1 92dcfc82e8 2comm 6 mēneši atpakaļ
img 92dcfc82e8 2comm 6 mēneši atpakaļ
.gitignore.txt 62ee81afd3 1st commit 9 mēneši atpakaļ
readme.md 92dcfc82e8 2comm 6 mēneši atpakaļ

readme.md

namespace WpfApp2.model
{
    public class Spares
    {
        public string name { get; set; }
        public int price { get; set; }
        public string detail { get; set; }
        public string type { get; set; }
        public List<SparesDetail> SparesDetailList { get; set; }
        public List<SparesPrice> SparesPriceList { get; set; }
        public List<SparesType> SparesTypeList { get; set; }

    }
}
namespace WpfApp2.model
{
    class Globals
    {
        public static IDataProvider dataProvider;
    }
}
namespace WpfApp2.model
{
    public class SparesDetail
    {
        public string title { get; set; }
    }
    public class SparesPrice
    {
        public string title { get; set; }
        public int PriceFrom { get; set; }
        public int PriceTo { get; set; }
    }

    public class SparesType
    {
        public string title { get; set; }
    }
}

Mainwindow.xaml

<Window x:Class="WpfApp2.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:WpfApp2"
        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="3.jpg" 
        Grid.RowSpan="2" HorizontalAlignment="Right"/>
        <DataGrid
    Grid.Row="1"
    Grid.Column="1"
    CanUserAddRows="False"
    AutoGenerateColumns="False"
    ItemsSource="{Binding SparesList}">
            <DataGrid.Columns>
                <DataGridTextColumn
Header=" "
Binding="{Binding name}"/>
                <DataGridTextColumn
Header=""
Binding="{Binding price}"/>
                <DataGridTextColumn
Header=" "
Binding="{Binding detail}"/>
                <DataGridTextColumn
Header=" "
Binding="{Binding type}"/>
            </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="DetailFilterComboBox"
    SelectionChanged="DetailFilterComboBox_SelectionChanged_1"
    VerticalAlignment="Center"
    MinWidth="100"
    SelectedIndex="0"
    ItemsSource="{Binding SparesDetailList}">

                <ComboBox.ItemTemplate>
                    <DataTemplate>
                        <Label 
                Content="{Binding title}"/>
                    </DataTemplate>
                </ComboBox.ItemTemplate>
            </ComboBox>
            <Label 
Content=":"
VerticalAlignment="Center"/>
            <ComboBox
Name="PriceFilterComboBox"
SelectionChanged="PriceFilterComboBox_SelectionChanged_2"
VerticalAlignment="Center"
MinWidth="100"
SelectedIndex="0"
ItemsSource="{Binding SparesPriceList}">

                <ComboBox.ItemTemplate>
                    <DataTemplate>
                        <Label 
            Content="{Binding title}"/>
                    </DataTemplate>
                </ComboBox.ItemTemplate>
            </ComboBox>
            <Label 
Content=" "
VerticalAlignment="Center"/>
            <ComboBox
Name="TypeFilterComboBox"
SelectionChanged="TypeFilterComboBox_SelectionChanged_3"
VerticalAlignment="Center"
MinWidth="100"
SelectedIndex="0"
ItemsSource="{Binding SparesTypeList}">

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

Mainwindow.xaml.cs

using System.ComponentModel;
using System.Windows;
using WpfApp2.model;

namespace WpfApp2
{
    /// <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("SparesList"));
        }
        public string selectedDetail = "";
        public SparesPrice? selectedPrice = null;
        public string selectedType = " ";

        private IEnumerable<Spares> _SparesList;
        public IEnumerable<Spares> SparesList
        {
            get
            {
                return _SparesList
                    .Where(c => (c.detail == selectedDetail || selectedDetail == ""))
                    .Where(c => (selectedPrice == null || (c.price >= selectedPrice.PriceFrom && c.price < selectedPrice.PriceTo)))
                    .Where(c => (c.type == selectedType || selectedType == " "));
            }
            set
            {
                _SparesList = value;
            }
        }
        
        public List<SparesDetail> SparesDetailList { get; set; }
        public List<SparesPrice> SparesPriceList { get; set; }
        public List<SparesType> SparesTypeList { get; set; }
        public MainWindow()
        {
            InitializeComponent();
            DataContext = this;
            Globals.dataProvider = new LocalDataProvider();
            SparesList = Globals.dataProvider.getSpares();
            SparesDetailList = Globals.dataProvider.getDetail().ToList();
            SparesDetailList.Insert(0, new SparesDetail { title = "" });
            SparesPriceList = Globals.dataProvider.getPrice().ToList();
            SparesTypeList = Globals.dataProvider.getType().ToList();
            SparesTypeList.Insert(0, new SparesType { title = " " });
        }

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

        }

        private void DetailFilterComboBox_SelectionChanged_1(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
        {
            selectedDetail = (DetailFilterComboBox.SelectedItem as SparesDetail).title;
            Invalidate();
        }
        private void PriceFilterComboBox_SelectionChanged_2(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
        {
            selectedPrice = PriceFilterComboBox.SelectedItem as SparesPrice;
            Invalidate();
        }
        private void TypeFilterComboBox_SelectionChanged_3(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
        {
            selectedType = (TypeFilterComboBox.SelectedItem as SparesType).title;
            Invalidate();
        }
    }

    interface IDataProvider
    {
        IEnumerable<Spares> getSpares();
        IEnumerable<SparesDetail> getDetail();
        IEnumerable<SparesPrice> getPrice();
        IEnumerable<SparesType> getType();
    }

    public class LocalDataProvider : IDataProvider
    {
        public IEnumerable<SparesDetail> getDetail()
        {
            return new SparesDetail[]
            {
                new SparesDetail()
                {
                    title=""
                },
                new SparesDetail()
                {
                    title=""
                },
                new SparesDetail()
                {
                    title=""
                },
                new SparesDetail()
                {
                    title=""
                },
                new SparesDetail()
                {
                    title=""
                },
            };
        }
        public IEnumerable<SparesPrice> getPrice()
        {
            return new SparesPrice[]
            {
                new SparesPrice()
                {
                    title=" ",
                    PriceFrom=0,
                    PriceTo=99999999

                },
                new SparesPrice()
                {
                    title="",
                    PriceFrom=0,
                    PriceTo=10000

                },
                new SparesPrice()
                {
                    title="",
                    PriceFrom=10000,
                    PriceTo=20000

                },
                new SparesPrice()
                {
                    title="",
                    PriceFrom=20000,
                    PriceTo=50000

                },
                new SparesPrice()
                {
                    title="",
                    PriceFrom=50000,
                    PriceTo=99999999
                }

            };

        }
        public IEnumerable<SparesType> getType()
        {
            return new SparesType[]
            {
                new SparesType()
                {
                    title=""
                },
                new SparesType()
                {
                    title=""
                },
            };
        }
        public IEnumerable<Spares> getSpares()
        {
            return new Spares[]{
            new Spares{
                type="",
                name=" 140(2281.4)",
                price = 72000,
                detail=""},
            new Spares{
                type="",
                name=" 5- -",
                price = 20000,
                detail=""},
            new Spares{
                type="",
                name=" 1337",
                price = 15000,
                detail=""},
             new Spares{
                type="",
                name=" 15-",
                price = 3000,
                detail=""},
              new Spares{
                type="",
                name="  150",
                price = 40000,
                detail=""},

        };
        }
    }
    
}