demo_term/demko_term/FormPersonalFileWindow.axaml.cs
2025-04-14 11:28:12 +03:00

93 lines
2.9 KiB
C#

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Interactivity;
using demko_term.Models;
using Microsoft.EntityFrameworkCore;
namespace demko_term;
public partial class FormPersonalFileWindow : Window
{
private ObservableCollection<StatementPresenter> statements = new();
private List<StatementPresenter> dataSourceStatements;
public FormPersonalFileWindow()
{
InitializeComponent();
using var context = new DemoCourseworkContext();
PersonalNumberComboBox.ItemsSource = context.Statements.Select(s => s.PersonalNumber).ToList();
DisplayStatements();
}
public class StatementPresenter : Statement
{
public string ApplicantCode { get; set; }
public string ApplicantSpecialty { get; set; }
public bool? PassportBool { get; set; }
public bool? DiplomaBool { get; set; }
public string Passport => PassportBool.HasValue ? (PassportBool.Value ? "Да" : "Нет") : "";
public string Diploma => DiplomaBool.HasValue ? (DiplomaBool.Value ? "Да" : "Нет") : "";
}
public void LoadData()
{
using var context = new DemoCourseworkContext();
dataSourceStatements = context.Statements
.Include(s => s.ApplicantCodeNavigation)
.Include(s => s.ApplicantSpecialityNavigation)
.Select(s => new StatementPresenter
{
Id = s.Id,
PersonalNumber = s.PersonalNumber,
SubmissionDate = s.SubmissionDate,
SubmissionTime = s.SubmissionTime,
ApplicantCode = s.ApplicantCodeNavigation.Code.ToString(),
ApplicantSpecialty = s.ApplicantSpecialityNavigation.Code.ToString(),
PassportBool = s.Passport,
DiplomaBool = s.Diploma,
Points = s.Points,
}).ToList();
}
private void DisplayStatements()
{
LoadData();
var temp = dataSourceStatements;
if (PersonalNumberComboBox.SelectedItem is string selectedPersonalNumber)
{
temp = temp.Where(it => it.PersonalNumber == selectedPersonalNumber).ToList();
}
statements.Clear();
foreach (var item in temp)
{
statements.Add(item);
}
StatementListBox.ItemsSource = statements;
}
public void PersonalNumberComboBox_OnSelectionChanged(object? sender, RoutedEventArgs e)
{
DisplayStatements();
}
private void ViewApplicantButton_OnClick(object? sender, RoutedEventArgs e)
{
ViewApplicantWindow viewApplicantWindow = new ViewApplicantWindow();
viewApplicantWindow.ShowDialog(this);
}
}