123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Input;
- using WpfApp2;
- using WpfApp3.Class;
- namespace WpfApp3
- {
- public partial class MainWindow : Window
- {
- private InstrumentDataManager dataManager;
- private InstrumentFilter filter;
- private string searchFilter = "";
- private bool sortAsc = true;
- public MainWindow()
- {
- InitializeComponent();
- dataManager = new InstrumentDataManager();
- filter = new InstrumentFilter();
- FilterComboBox.Items.Add("Все");
- FilterComboBox.Items.Add("Клавишные");
- FilterComboBox.Items.Add("Струнные");
- FilterComboBox.Items.Add("Ударные");
- FilterComboBox.SelectedIndex = 0;
- UpdateInstrumentList(dataManager.GetInstruments());
- }
- private void FilterComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- string selectedFilter = (string)FilterComboBox.SelectedItem;
- if (selectedFilter == "Все")
- {
- UpdateInstrumentList(filter.FilterAll(dataManager.GetInstruments()));
- }
- else
- {
- UpdateInstrumentList(filter.FilterByType(dataManager.GetInstruments(), selectedFilter));
- }
- }
- private void SearchFilter_KeyUp(object sender, KeyEventArgs e)
- {
- searchFilter = SearchFilterTextBox.Text;
- UpdateInstrumentList(dataManager.GetInstruments());
- }
- private void RadioButtonAsc_Checked(object sender, RoutedEventArgs e)
- {
- sortAsc = true;
- UpdateInstrumentList(dataManager.GetInstruments());
- }
- private void RadioButtonDesc_Checked(object sender, RoutedEventArgs e)
- {
- sortAsc = false;
- UpdateInstrumentList(dataManager.GetInstruments());
- }
- private void UpdateInstrumentList(List<MusicalInstrument> instrumentsToDisplay)
- {
- if (!string.IsNullOrEmpty(searchFilter))
- {
- instrumentsToDisplay = instrumentsToDisplay.Where(i => i.Name.IndexOf(searchFilter, StringComparison.OrdinalIgnoreCase) >= 0 ||
- i.Type.IndexOf(searchFilter, StringComparison.OrdinalIgnoreCase) >=0 ||
- i.Brand.IndexOf(searchFilter, StringComparison.OrdinalIgnoreCase) >= 0).ToList();
- }
- if (sortAsc)
- {
- instrumentsToDisplay = instrumentsToDisplay.OrderBy(i => i.Price).ToList();
- }
- else
- {
- instrumentsToDisplay = instrumentsToDisplay.OrderByDescending(i => i.Price).ToList();
- }
- InstrumentListView.ItemsSource = instrumentsToDisplay;
- }
- private void ExitButton_Click(object sender, RoutedEventArgs e)
- {
- Application.Current.Shutdown();
- }
- }
- }
|