using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.IO; using System.Linq; using Avalonia.Controls; using Avalonia.Interactivity; using Avalonia.Media.Imaging; using demo_2023.Models; namespace demo_2023 { public partial class MainWindow : Window { private ObservableCollection events = new ObservableCollection(); private List dataSourceEvent; private bool isAscending = true; // Флаг для сортировки public MainWindow() { InitializeComponent(); using var context = new User15Context(); dataSourceEvent = context.Events.Select(it => new EventPresenter { Sobitie = it.Sobitie, Date = it.Date, Days = it.Days, City = it.City, Photo = it.Photo }).ToList(); EventListBox.ItemsSource = events; ApplySortingAndFiltering(); } private void ApplySortingAndFiltering() { var temp = dataSourceEvent; if (DateComboBox.SelectedItem is DateTime selectedDateTime) { temp = temp.Where(it => it.Date.Date == selectedDateTime.Date).ToList(); } temp = isAscending ? temp.OrderBy(it => it.Date).ToList() : temp.OrderByDescending(it => it.Date).ToList(); events.Clear(); foreach (var item in temp) { events.Add(item); } } public class EventPresenter : Event { public Bitmap? Image { get { try { string absolutePath = Path.Combine(AppContext.BaseDirectory, Photo); return File.Exists(absolutePath) ? new Bitmap(absolutePath) : null; } catch { return null; } } } } private void DateComboBox_SelectionChanged(object? sender, SelectionChangedEventArgs e) { isAscending = !isAscending; ApplySortingAndFiltering(); } private void Jury_reg(object? sender, RoutedEventArgs e) { new Additem().ShowDialog(this); } } }