using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using Avalonia; using Avalonia.Controls; using Avalonia.Interactivity; using Avalonia.Markup.Xaml; using kursovaya.Models; namespace kursovaya; public partial class AdminWindow : Window { List Disciplines = new List(); List Groups = new List(); List Teachers = new List(); ObservableCollection DisciplineGroupTeachers = new ObservableCollection(); public AdminWindow() { InitializeComponent(); var ctx = new DatabaseContext(); Disciplines = ctx.Disciplines.ToList(); Groups = ctx.Groups.ToList(); Teachers = ctx.Teachers.ToList(); var disciplineTeachers = ctx.DisciplineTeachers.ToList(); foreach (DisciplineTeacher disciplineTeacher in disciplineTeachers) { var teacher = ctx.Teachers.FirstOrDefault(t => t.Id == disciplineTeacher.IdTeacher); var discipline = ctx.Disciplines.FirstOrDefault(d => d.Id == disciplineTeacher.IdDiscipline); var groups = ctx.Groups.Where(g => ctx.Attestations.Any(at => ctx.Students.Any(s => s.Id == at.IdUser && s.IdGroup == g.Id) && at.IdDiscipline == discipline.Id)); foreach (Group group in groups) { DisciplineGroupTeachers.Add(new DisciplineGroupTeacher(){Teacher = teacher, Discipline = discipline, Group = group}); } } MultComboBox.ItemsSource = DisciplineGroupTeachers.Select(dg => dg.NameComboBox).ToList(); FlatGrid.ItemsSource = DisciplineGroupTeachers; } public class DisciplineGroupTeacher() { public Group Group { get; set; } public Discipline Discipline { get; set; } public Teacher Teacher { get; set; } public string DisciplineName { get => Discipline.Name; } public int GroupId { get => Group.Id; } public string TeacherFio { get => Teacher.Fio; } public string NameComboBox { get { return $"{Discipline.Name} - {Group.Id} - {Teacher.Fio}"; } } } public void Display() { if (MultComboBox.SelectionBoxItem != null) { var selectedDiscGroupTeacher = DisciplineGroupTeachers.FirstOrDefault(dg => dg.NameComboBox == MultComboBox.SelectedItem.ToString()); var filteredData = DisciplineGroupTeachers.Where(dg => dg.Discipline.Name == selectedDiscGroupTeacher.Discipline.Name && dg.Group.Id == selectedDiscGroupTeacher.Group.Id && dg.Teacher.Fio == selectedDiscGroupTeacher.Teacher.Fio).ToList(); FlatGrid.ItemsSource = filteredData; } } private void ButtonBack_OnClick(object? sender, RoutedEventArgs e) { Close(); } private void ButtonCheck_OnClick(object? sender, RoutedEventArgs e) { Display(); } private void ButtonCheckGroups_OnClick(object? sender, RoutedEventArgs e) { GroupsFromAdminWindow groupsFromAdminWindow = new GroupsFromAdminWindow(); groupsFromAdminWindow.ShowDialog(this); } private void ButtonCheckStudents_OnClick(object? sender, RoutedEventArgs e) { StudentsFromAdminWindow studentsFromAdminWindow = new StudentsFromAdminWindow(); studentsFromAdminWindow.ShowDialog(this); } private async void ButtonCheckTeachers_OnClick(object? sender, RoutedEventArgs e) { // TeachersFromAdminWindow teachersFromAdminWindow = new TeachersFromAdminWindow(); // teachersFromAdminWindow.ShowDialog(this); TeachersFromAdminWindow teachersFromAdminWindow = new TeachersFromAdminWindow(); var result = await teachersFromAdminWindow.ShowDialog(this); if (result == true) { Display(); } } private void ButtonCheckDiscipline_OnClick(object? sender, RoutedEventArgs e) { AddDiscipline addDiscipline = new AddDiscipline(); addDiscipline.ShowDialog(this); } }