using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.IO; using System.Linq; using System.Text.RegularExpressions; using Avalonia.Controls; using Avalonia.Input; using Avalonia.Interactivity; using Avalonia.Media.Imaging; using demo4_true.Models; using demo4_true.ModelsMy; namespace demo4_true; public partial class MainWindow : Window { ObservableCollection events = new ObservableCollection(); List dataSourceEvent; ObservableCollection authClients = new ObservableCollection(); List dataSourceClient; public List DirectionsList { get; } public List DatesList { get; } public static ObservableCollection ClientAuthList { get; set; } public MainWindow() { InitializeComponent(); using var context = new Demo4Context(); dataSourceEvent = context.Events.Select(it => new EventPresenter { Sobitie = it.Sobitie, Date = it.Date, Days = it.Days, City = it.City, Photopath = it.Photopath, DirectionId = it.DirectionId, }).ToList(); EventListBox.ItemsSource = events; dataSourceClient = context.Clients.Select(it => new ClientAuth { Id = it.Id, Password = it.Password, Role = it.Role, FIO = it.Fio, PhotoPath = it.Photopath, }).ToList(); DirectionsList = context.Directions.Select(it => it.Name).ToList(); DirectionComboBox.ItemsSource = DirectionsList; DatesList = dataSourceEvent.Select(s => s.Date).ToList(); DateComboBox.ItemsSource = DatesList; DisplayServices(); } public class EventPresenter() : Event { Bitmap? Image { get { try { string absolutePath = Path.Combine(AppContext.BaseDirectory, Photopath); return new Bitmap(absolutePath); } catch { return null; } } } } public void DisplayServices() { var temp = dataSourceEvent; var temp2 = dataSourceClient; events.Clear(); if (DirectionComboBox != null) { temp = temp.Where(it => it.Direction == DirectionComboBox.SelectedItem).ToList(); } if (DateComboBox.SelectedItem != null) { DateTime selectedDate = (DateTime)DateComboBox.SelectedItem; temp = temp.Where(it => it.Date.Date == selectedDate.Date).ToList(); } foreach (var item in temp) { events.Add(item); } foreach (var item in temp2) { authClients.Add(item); } ClientAuthList = authClients; } private void AuthButton_OnClick(object? sender, RoutedEventArgs e) { Auth auth = new Auth(); auth.ShowDialog(this); } private void DirectionComboBox_OnSelectionChanged(object? sender, SelectionChangedEventArgs e) { DisplayServices(); } private void DateComboBox_OnSelectionChanged(object? sender, SelectionChangedEventArgs e) { DisplayServices(); } }