This commit is contained in:
1eG0ist 2025-03-04 11:01:22 +03:00
parent 9adf371994
commit 13cb67d3a6
21 changed files with 316 additions and 76 deletions

View File

@ -16,5 +16,6 @@
<Application.Styles>
<FluentTheme />
<StyleInclude Source="avares://Avalonia.Controls.DataGrid/Themes/Fluent.xaml"/>
</Application.Styles>
</Application>

View File

@ -0,0 +1,8 @@
namespace IposiGospodDemo.Dtos;
public class SponsorshipOverViewCharityDto
{
public string CharityName { get; set; }
public string? CharityLogo { get; set; }
public decimal SponsorshipAmount { get; set; }
}

View File

@ -14,6 +14,7 @@
<ItemGroup>
<PackageReference Include="Avalonia" Version="11.2.1"/>
<PackageReference Include="Avalonia.Controls.DataGrid" Version="11.2.1" />
<PackageReference Include="Avalonia.Desktop" Version="11.2.1"/>
<PackageReference Include="Avalonia.ReactiveUI" Version="11.2.1" />
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.2.1"/>

View File

@ -1,4 +1,5 @@
using System;
using System.Runtime.CompilerServices;
using IposiGospodDemo.Context;
namespace IposiGospodDemo;
@ -11,7 +12,9 @@ public static class Session
public static readonly String Data = "Вторник 1 апреля 2025";
public static String RemainingTime = CalculateRemaningTime();
public static string AssetsPath = null!;
public static User User = null;
public static Runner Runner = null;
public static String CalculateRemaningTime()
{
@ -20,4 +23,10 @@ public static class Session
? $"{timeLeft.Days} д. {timeLeft.Hours} ч. {timeLeft.Minutes} мин. до старта марафона"
: "Марафон уже начался!";
}
public static void Logout()
{
User = null;
Runner = null;
}
}

View File

@ -1,5 +1,11 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using IposiGospodDemo.Context;
using IposiGospodDemo.Helpers;
using Microsoft.EntityFrameworkCore;
using Npgsql;
using ReactiveUI;
namespace IposiGospodDemo.ViewModels;
@ -7,16 +13,34 @@ namespace IposiGospodDemo.ViewModels;
public class MySponsorshipWindowViewModel : ViewModelBase
{
private ObservableCollection<Registration> _registrations;
private ObservableCollection<Sponsorship> _sponsorships;
public ObservableCollection<Registration> Registrations
public ObservableCollection<Sponsorship> Sponsorships
{
get => _registrations;
set => this.RaiseAndSetIfChanged(ref _registrations, value);
get => _sponsorships;
set => this.RaiseAndSetIfChanged(ref _sponsorships, value);
}
public Charity RunnerCharity { get; set; }
public decimal TotalAmount { get; set; }
public MySponsorshipWindowViewModel()
{
Sponsorships = new(DbHelper.Database.Sponsorships
.Include(s => s.Registration)
.Where(s => s.Registration.RunnerId == Session.Runner.RunnerId).ToList());
TotalAmount = Sponsorships?.Sum(s => s.Amount) ?? 0;
List<Registration> regs = new (DbHelper.Database.Registrations.Where(r => r.RunnerId == Session.Runner.RunnerId));
Console.WriteLine(regs.Count);
Console.WriteLine(regs);
var registration = DbHelper.Database.Registrations
.Include(r => r.Charity) // Убедитесь, что Charity загружается
.FirstOrDefault(r => r.RunnerId == Session.Runner.RunnerId);
RunnerCharity = registration?.Charity; // Предотвращаем NullReferenceException
Console.WriteLine("Runner Charity = " + RunnerCharity.CharityName);
}
}

View File

@ -0,0 +1,47 @@
using System;
using System.Collections.ObjectModel;
using System.Linq;
using IposiGospodDemo.Dtos;
using IposiGospodDemo.Helpers;
using ReactiveUI;
namespace IposiGospodDemo.ViewModels;
public class SponsorshipOverviewWindowViewModel : ViewModelBase
{
private ObservableCollection<SponsorshipOverViewCharityDto> _charities;
public ObservableCollection<SponsorshipOverViewCharityDto> Charities
{
get => _charities;
set => this.RaiseAndSetIfChanged(ref _charities, value);
}
private decimal _charitiesSum;
public decimal CharitiesSum
{
get => _charitiesSum;
set => this.RaiseAndSetIfChanged(ref _charitiesSum, value);
}
public SponsorshipOverviewWindowViewModel()
{
LoadData();
}
private void LoadData()
{
Charities = new(DbHelper.Database.Charities
.Select(c => new SponsorshipOverViewCharityDto
{
CharityName = c.CharityName,
CharityLogo = c.CharityLogo,
SponsorshipAmount = c.Registrations
.SelectMany(r => r.Sponsorships)
.Sum(s => s.Amount)
})
.ToList());
CharitiesSum = Charities.Sum(c => c.SponsorshipAmount);
Console.WriteLine(Charities.Count);
}
}

View File

@ -20,7 +20,7 @@ public partial class AdministratorMenuWindow : Window
private void Logout_OnClick(object? sender, RoutedEventArgs e)
{
Session.User = null;
Session.Logout();
new MainWindow().Show();
Close();
}

View File

@ -13,7 +13,7 @@
<TextBlock Text="{Binding Name}" HorizontalAlignment="Center" FontSize="18" FontWeight="Bold"/>
<Border Height="100" ClipToBounds="True">
<Image Source="{Binding ImagePath, Converter={StaticResource ImageConverter}}" Stretch="UniformToFill"/>
<Image Source="{Binding ImagePath, Converter={StaticResource ImageConverter}}" Stretch="Uniform"/>
</Border>
<TextBlock Text="{Binding Description}" TextWrapping="WrapWithOverflow" TextAlignment="Center" Width="400"/>

View File

@ -20,9 +20,22 @@
</Border>
<StackPanel Grid.Row="1" Orientation="Vertical">
</StackPanel>
<DockPanel Grid.Row="1">
<TextBlock Text="Меню коориднатора" DockPanel.Dock="Top" HorizontalAlignment="Center" TextAlignment="Center"
FontSize="32" Margin="0 0 0 100"/>
<StackPanel HorizontalAlignment="Center" DockPanel.Dock="Top" Spacing="20">
<Button Padding="20" HorizontalAlignment="Center" Click="SwapToRunnersWindow_OnClick"
Background="LightGray" BorderThickness="1" BorderBrush="Black"
FontSize="24" CornerRadius="15" MinWidth="450" HorizontalContentAlignment="Center">
Бегуны
</Button>
<Button Padding="20" HorizontalAlignment="Center" Click="SwapToSponsorshipOverviewWindow_OnClick"
Background="LightGray" BorderThickness="1" BorderBrush="Black"
FontSize="24" CornerRadius="15" MinWidth="450" HorizontalContentAlignment="Center">
Спонсоры
</Button>
</StackPanel>
</DockPanel>
<StackPanel Grid.Row="2" Orientation="Vertical" Background="DarkGray" VerticalAlignment="Center">
<TextBlock Text="{x:Static local:Session.RemainingTime}" FontSize="20" HorizontalAlignment="Center"

View File

@ -20,8 +20,19 @@ public partial class CoordinatorMenuWindow : Window
private void Logout_OnClick(object? sender, RoutedEventArgs e)
{
Session.User = null;
Session.Logout();
new MainWindow().Show();
Close();
}
private void SwapToRunnersWindow_OnClick(object? sender, RoutedEventArgs e)
{
}
private void SwapToSponsorshipOverviewWindow_OnClick(object? sender, RoutedEventArgs e)
{
new SponsorshipOverviewWindow().Show();
Close();
}
}

View File

@ -20,7 +20,7 @@ public partial class EditRunnerProfileWindow : Window
private void Logout_OnClick(object? sender, RoutedEventArgs e)
{
Session.User = null;
Session.Logout();
new MainWindow().Show();
Close();
}

View File

@ -31,7 +31,7 @@
<DataTemplate>
<Border HorizontalAlignment="Left">
<StackPanel Orientation="Horizontal" Spacing="10" HorizontalAlignment="Left" Width="800">
<Image MaxHeight="100" MaxWidth="100" Stretch="UniformToFill" HorizontalAlignment="Left"
<Image MaxHeight="100" MaxWidth="100" Stretch="Uniform" HorizontalAlignment="Left"
Source="{Binding CharityLogo, Converter={StaticResource ImageConverter}}"
VerticalAlignment="Center"/>
<StackPanel Orientation="Vertical" Spacing="10" Width="700">

View File

@ -32,10 +32,11 @@ public partial class LoginWindow : Window
PasswordBox.Text != null && u.Password == PasswordBox.Text.Trim());
Session.User = user;
Console.WriteLine("USERROLEID: " + user.Role.RoleId.ToString());
switch (user.Role.RoleId)
{
case 'R':
Session.Runner = DbHelper.Database.Runners.Single(r => r.EmailNavigation.Email == user.Email);
new RunnerMenuWindow().Show();
break;
case 'C':
@ -46,35 +47,6 @@ public partial class LoginWindow : Window
break;
}
Close();
// try
// {
// User user = DbHelper.Database.Users
// .Include(u => u.Role)
// .Single(u =>
// EmailBox.Text != null && u.Email == EmailBox.Text.Trim() &&
// PasswordBox.Text != null && u.Password == PasswordBox.Text.Trim());
//
// Session.User = user;
// Console.WriteLine("USERROLEID: " + user.Role.RoleId.ToString());
// switch (user.Role.RoleId)
// {
// case 'R':
// new RunnerMenuWindow().Show();
// break;
// case 'C':
// new CoordinatorMenuWindow().Show();
// break;
// case 'A':
// new AdministratorMenuWindow().Show();
// break;
// }
// Close();
// }
// catch (Exception exception)
// {
// Console.WriteLine("Unlucky");
// Console.WriteLine(exception.Message);
// }
}
private void Cancel_OnClick(object? sender, RoutedEventArgs e)

View File

@ -20,7 +20,7 @@ public partial class MyResultsWindow : Window
private void Logout_OnClick(object? sender, RoutedEventArgs e)
{
Session.User = null;
Session.Logout();
new MainWindow().Show();
Close();
}

View File

@ -2,38 +2,85 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="using:IposiGospodDemo.ViewModels"
xmlns:local="using:IposiGospodDemo"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="IposiGospodDemo.Views.MySponsorshipWindow"
Title="MySponsorshipWindow">
x:DataType="vm:MySponsorshipWindowViewModel"
Title="MySponsorshipWindow" Padding="10">
<Grid RowDefinitions="Auto * Auto">
<Border Grid.Row="0" Background="DarkGray" Padding="10">
<DockPanel VerticalAlignment="Center">
<StackPanel DockPanel.Dock="Left" Orientation="Horizontal" Spacing="10">
<Button Content="Назад" Click="GoBack_OnClick"/>
<TextBlock Text="{x:Static local:Session.Title}" VerticalAlignment="Center"
FontSize="24" FontWeight="Bold" Foreground="White"/>
</StackPanel>
<Button Content="Logout" VerticalAlignment="Center" HorizontalAlignment="Right" DockPanel.Dock="Right"
Click="Logout_OnClick"/>
</DockPanel>
</Border>
<DockPanel Grid.Row="1">
<TextBlock DockPanel.Dock="Top" Text="Мои спонсоры" HorizontalAlignment="Center" FontSize="24" Margin="0 20"/>
<TextBlock DockPanel.Dock="Top" Text="Здесь показаны все ваши спонсоры в Marathon Skills 2016"
HorizontalAlignment="Center" Margin="0 0 0 20"/>
<StackPanel Orientation="Vertical" DockPanel.Dock="Right">
<DataGrid>
</DataGrid>
</StackPanel>
</DockPanel>
<StackPanel Grid.Row="2" Orientation="Vertical" Background="DarkGray" VerticalAlignment="Center">
<TextBlock Text="{x:Static local:Session.RemainingTime}" FontSize="20" HorizontalAlignment="Center"
VerticalAlignment="Center" Foreground="White"/>
</StackPanel>
</Grid>
<Border Grid.Row="0" Background="DarkGray" Padding="10">
<DockPanel VerticalAlignment="Center">
<StackPanel DockPanel.Dock="Left" Orientation="Horizontal" Spacing="10">
<Button Content="Назад" Click="GoBack_OnClick"/>
<TextBlock Text="{x:Static local:Session.Title}" VerticalAlignment="Center"
FontSize="24" FontWeight="Bold" Foreground="White"/>
</StackPanel>
<Button Content="Logout" VerticalAlignment="Center" HorizontalAlignment="Right" DockPanel.Dock="Right"
Click="Logout_OnClick"/>
</DockPanel>
</Border>
<DockPanel Grid.Row="1">
<TextBlock DockPanel.Dock="Top" Text="Мои спонсоры" HorizontalAlignment="Center" FontSize="24" Margin="0 20"/>
<TextBlock DockPanel.Dock="Top" Text="Здесь показаны все ваши спонсоры в Marathon Skills 2016"
HorizontalAlignment="Center" Margin="0 0 0 20"/>
<StackPanel Orientation="Vertical" DockPanel.Dock="Left" Spacing="10" Width="400" Margin="0 0 50 0">
<TextBlock HorizontalAlignment="Center" FontSize="24" Text="{Binding RunnerCharity.CharityName}"
TextAlignment="Center" TextWrapping="Wrap"/>
<Image Width="200" Stretch="Uniform" HorizontalAlignment="Center"
Source="{Binding RunnerCharity.CharityLogo, Converter={StaticResource ImageConverter}}"
VerticalAlignment="Center"/>
<TextBlock Text="{Binding RunnerCharity.CharityDescription}"
TextWrapping="Wrap"/>
</StackPanel>
<StackPanel Orientation="Vertical" DockPanel.Dock="Right" IsVisible="{Binding Sponsorships.Count}">
<!-- Заголовки -->
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBlock Text="Спонсор" Grid.Column="0" HorizontalAlignment="Left"/>
<TextBlock Text="Взнос" Grid.Column="1" HorizontalAlignment="Right"/>
</Grid>
<!-- Список -->
<ListBox ItemsSource="{Binding Sponsorships}" Height="200">
<ListBox.ItemTemplate>
<DataTemplate>
<Border Padding="5">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBlock Text="{Binding SponsorName}" Grid.Column="0" HorizontalAlignment="Left"/>
<TextBlock Text="{Binding Amount}" Grid.Column="1" HorizontalAlignment="Right"/>
</Grid>
</Border>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<Border Height="2" Background="Black"/>
<!-- Итог -->
<TextBlock HorizontalAlignment="Right" Margin="0 10 0 0">
<Run Text="Всего $" />
<Run Text="{Binding TotalAmount}" />
</TextBlock>
</StackPanel>
<StackPanel Orientation="Vertical" IsVisible="{Binding Sponsorships.Count}">
<TextBlock Text="Нет пожертвований" VerticalAlignment="Center" HorizontalAlignment="Center"/>
</StackPanel>
</DockPanel>
<StackPanel Grid.Row="2" Orientation="Vertical" Background="DarkGray" VerticalAlignment="Center">
<TextBlock Text="{x:Static local:Session.RemainingTime}" FontSize="20" HorizontalAlignment="Center"
VerticalAlignment="Center" Foreground="White"/>
</StackPanel>
</Grid>
</Window>

View File

@ -2,6 +2,7 @@ using Avalonia;
using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Markup.Xaml;
using IposiGospodDemo.ViewModels;
namespace IposiGospodDemo.Views;
@ -10,6 +11,7 @@ public partial class MySponsorshipWindow : Window
public MySponsorshipWindow()
{
InitializeComponent();
DataContext = new MySponsorshipWindowViewModel();
}
private void GoBack_OnClick(object? sender, RoutedEventArgs e)
@ -20,7 +22,7 @@ public partial class MySponsorshipWindow : Window
private void Logout_OnClick(object? sender, RoutedEventArgs e)
{
Session.User = null;
Session.Logout();
new MainWindow().Show();
Close();
}

View File

@ -20,7 +20,7 @@ public partial class RegistrationForAnEventWindow : Window
private void Logout_OnClick(object? sender, RoutedEventArgs e)
{
Session.User = null;
Session.Logout();
new MainWindow().Show();
Close();
}

View File

@ -20,7 +20,7 @@ public partial class RunnerMenuWindow : Window
private void Logout_OnClick(object? sender, RoutedEventArgs e)
{
Session.User = null;
Session.Logout();
new MainWindow().Show();
Close();
}

View File

@ -88,6 +88,7 @@ public partial class SponsorARunnerWindow : Window
newSponsorship.Registration = _viewModel.SelectedRunner.Registrations.FirstOrDefault()!;
newSponsorship.Amount = _viewModel.Sum;
DbHelper.Database.Sponsorships.Add(newSponsorship);
DbHelper.Database.SaveChanges();
new SponsorshipConfirmationWindow(_viewModel.SelectedRunner.EmailNavigation, _viewModel.Sum, _viewModel.SelectedCharity.CharityName).Show();
Close();

View File

@ -0,0 +1,75 @@
<Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="using:IposiGospodDemo.ViewModels"
xmlns:local="using:IposiGospodDemo"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="IposiGospodDemo.Views.SponsorshipOverviewWindow"
x:DataType="vm:SponsorshipOverviewWindowViewModel"
Title="SponsorshipOverviewWindow">
<Grid RowDefinitions="Auto * Auto">
<Border Grid.Row="0" Background="DarkGray" Padding="10">
<DockPanel VerticalAlignment="Center">
<StackPanel DockPanel.Dock="Left" Orientation="Horizontal" Spacing="10">
<Button Content="Назад" Click="GoBack_OnClick"/>
<TextBlock Text="{x:Static local:Session.Title}" VerticalAlignment="Center"
FontSize="24" FontWeight="Bold" Foreground="White"/>
</StackPanel>
<Button Content="Logout" VerticalAlignment="Center" HorizontalAlignment="Right" DockPanel.Dock="Right"
Click="Logout_OnClick"/>
</DockPanel>
</Border>
<DockPanel Grid.Row="1">
<Grid HorizontalAlignment="Stretch">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!-- Заголовки -->
<StackPanel Orientation="Vertical" HorizontalAlignment="Center" Grid.Row="0">
<TextBlock FontSize="20" FontWeight="Bold" HorizontalAlignment="Center">
<Run Text="Благотворительные организации: "/>
<Run Text="{Binding Charities.Count}"/>
</TextBlock>
<TextBlock FontSize="20" FontWeight="Bold" HorizontalAlignment="Center" Margin="0,0,0,10">
<Run Text="Всего спонсорских взносов: "/>
<Run Text="{Binding CharitiesSum, StringFormat=N0}"/>
</TextBlock>
</StackPanel>
<!-- DataGrid -->
<DataGrid Grid.Row="1" ItemsSource="{Binding Charities}" AutoGenerateColumns="False"
HeadersVisibility="Column" GridLinesVisibility="All"
HorizontalAlignment="Stretch" MinWidth="600" Height="400">
<DataGrid.Columns>
<DataGridTemplateColumn Header="Логотип" Width="Auto">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Border Height="100" ClipToBounds="True">
<Image Source="{Binding CharityLogo, Converter={StaticResource ImageConverter}}"
Stretch="Uniform"/>
</Border>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Header="Наименование" Binding="{Binding CharityName}" Width="*"/>
<DataGridTextColumn Header="Сумма" Binding="{Binding SponsorshipAmount, StringFormat=' $#,##0'}" Width="Auto"/>
</DataGrid.Columns>
</DataGrid>
</Grid>
</DockPanel>
<StackPanel Grid.Row="2" Orientation="Vertical" Background="DarkGray" VerticalAlignment="Center">
<TextBlock Text="{x:Static local:Session.RemainingTime}" FontSize="20" HorizontalAlignment="Center"
VerticalAlignment="Center" Foreground="White"/>
</StackPanel>
</Grid>
</Window>

View File

@ -0,0 +1,29 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Markup.Xaml;
using IposiGospodDemo.ViewModels;
namespace IposiGospodDemo.Views;
public partial class SponsorshipOverviewWindow : Window
{
public SponsorshipOverviewWindow()
{
InitializeComponent();
DataContext = new SponsorshipOverviewWindowViewModel();
}
private void GoBack_OnClick(object? sender, RoutedEventArgs e)
{
new CoordinatorMenuWindow().Show();
Close();
}
private void Logout_OnClick(object? sender, RoutedEventArgs e)
{
Session.Logout();
new MainWindow().Show();
Close();
}
}