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 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(); } } }