Классы
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="Стекла"},
};
}
}
}
Скрины работы