Fix task-20.11 folder

This commit is contained in:
328p
2026-11-20 15:41:46 +03:00
parent c82286f90c
commit 7aa7e6b2b1
17 changed files with 396 additions and 1 deletions
+10
View File
@@ -0,0 +1,10 @@
<Application xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="DemoCats.App"
RequestedThemeVariant="Default">
<!-- "Default" ThemeVariant follows system theme variant. "Dark" or "Light" are other available options. -->
<Application.Styles>
<FluentTheme />
</Application.Styles>
</Application>
+23
View File
@@ -0,0 +1,23 @@
using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml;
namespace DemoCats;
public partial class App : Application
{
public override void Initialize()
{
AvaloniaXamlLoader.Load(this);
}
public override void OnFrameworkInitializationCompleted()
{
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
desktop.MainWindow = new MainWindow();
}
base.OnFrameworkInitializationCompleted();
}
}
+20
View File
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<Nullable>enable</Nullable>
<ApplicationManifest>app.manifest</ApplicationManifest>
<RootNamespace>DemoCatas</RootNamespace>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="12.1.4"/>
<PackageReference Include="Avalonia.Desktop" Version="12.1.4"/>
<PackageReference Include="Avalonia.Themes.Fluent" Version="12.1.4"/>
<PackageReference Include="Avalonia.Fonts.Inter" Version="12.1.4"/>
<PackageReference Include="AvaloniaUI.DiagnosticsSupport" Version="2.2.3">
<IncludeAssets Condition="'$(Configuration)' != 'Debug'">None</IncludeAssets>
<PrivateAssets Condition="'$(Configuration)' != 'Debug'">All</PrivateAssets>
</PackageReference>
</ItemGroup>
</Project>
+19
View File
@@ -0,0 +1,19 @@
<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"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="DemoCats.MainWindow"
Title="DemoCat">
<StackPanel Spacing="5" HorizontalAlignment="Center" VerticalAlignment="Center" Orientation="Vertical">
<TextBlock Text="Введите логин"/>
<TextBox Name="LoginBox"/>
<TextBlock Text="Введите пароль"/>
<TextBox Name="PasswordBox"/>
<TextBlock Name="Error"/>
<StackPanel Orientation="Horizontal">
<Button Content="Войти" Click="LoginButton_OnClick"/>
<Button Content="Войти как гость" Click="GuestButton_OnClick"/>
</StackPanel>
</StackPanel>
</Window>
+44
View File
@@ -0,0 +1,44 @@
using System.Linq;
using Avalonia.Controls;
using Avalonia.Interactivity;
namespace DemoCats;
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void LoginButton_OnClick(object? sender, RoutedEventArgs e)
{
var email = LoginBox.Text;
var password = PasswordBox.Text;
if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password))
{
Error.Text = "Пароль или логин пустые";
return;
}
var user = Users._users.FirstOrDefault(i => i.Email == email);
if (user == null)
{
Error.Text = "Пользователь не найден";
return;
}
if (user.Password != password)
{
Error.Text = "Неправильный пароль";
return;
}
new UsersWindow(user).Show();
Close();
}
private void GuestButton_OnClick(object? sender, RoutedEventArgs e)
{
new UsersWindow(null).Show();
}
}
+24
View File
@@ -0,0 +1,24 @@
using Avalonia;
using System;
namespace DemoCats;
class Program
{
// Initialization code. Don't use any Avalonia, third-party APIs or any
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized
// yet and stuff might break.
[STAThread]
public static void Main(string[] args) => BuildAvaloniaApp()
.StartWithClassicDesktopLifetime(args);
// Avalonia configuration, don't remove; also used by visual designer.
public static AppBuilder BuildAvaloniaApp()
=> AppBuilder.Configure<App>()
.UsePlatformDetect()
#if DEBUG
.WithDeveloperTools()
#endif
.WithInterFont()
.LogToTrace();
}
+15
View File
@@ -0,0 +1,15 @@
using System.Collections.Generic;
namespace DemoCats;
public class Users
{
public static List<User> _users = [
new User(1, "Кошка Кошковна", "koshka@mur.ru", "meow123", "admin"),
new User(2, "Киса Мурлыковна", "kisa@meow.com", "purrfect99", "manager"),
new User(3, "Кот Матроскин", "matroskin@prostokvasha.ru", "milk_lover", "user"),
new User(4, "Мурка Цараповна", "murka@scratch.net", "fish_stealer", "user"),
new User(5, "Барсик Пушистович", "barsik@fluffy.org", "sleep_all_day", "user"),
new User(6, "Васька Сметанович", "vasya@sourcream.ru", "tasty_cream7", "admin")
];
}
+41
View File
@@ -0,0 +1,41 @@
<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"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
xmlns:model ="clr-namespace:DemoCats"
x:Class="DemoCats.UsersWindow"
Title="UsersWindow">
<Grid RowDefinitions="Auto, *, Auto">
<StackPanel Orientation="Horizontal">
<TextBox TextChanged="SearchBox_OnTextChanged" Width="300" Name="SearchBox"/>
<ComboBox SelectionChanged="FilterBox_OnSelectionChanged" Width="200" Name="FilterBox">
<ComboBoxItem>Без фильтрации</ComboBoxItem>
<ComboBoxItem>.com</ComboBoxItem>
<ComboBoxItem>.ru</ComboBoxItem>
<ComboBoxItem>.net</ComboBoxItem>
<ComboBoxItem>.org</ComboBoxItem>
</ComboBox>
<ComboBox SelectionChanged="SortBox_OnSelectionChanged" Width="200" Name="SortBox">
<ComboBoxItem>Без сортировки</ComboBoxItem>
<ComboBoxItem>По убыванию</ComboBoxItem>
<ComboBoxItem>По возрастанию</ComboBoxItem>
</ComboBox>
</StackPanel>
<ListBox Name="UserListBox" Grid.Row="1">
<ListBox.ItemTemplate>
<DataTemplate DataType="model:User">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Id}"/>
<StackPanel>
<TextBlock Text="{Binding Name}"/>
<TextBlock Text="{Binding Email}"/>
<TextBlock Text="{Binding Password}"/>
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<TextBlock Grid.Row="2" Name="UserProfile"/>
</Grid>
</Window>
+102
View File
@@ -0,0 +1,102 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
namespace DemoCats;
public record User(int Id, string Name, string Email, string Password, string Role);
public partial class UsersWindow : Window
{
// Наблюдаемая коллекция, которая автоматически уведомляет интерфейс (ListBox) при изменении элементов
private ObservableCollection<User> UsersCollecction = new();
public UsersWindow(User? user)
{
InitializeComponent();
// Привязка коллекции UsersCollecction как источника данных для элемента списка UserListBox
UserListBox.ItemsSource = UsersCollecction;
ShowUsers();
switch (user?.Role)
{
case "admin":
{
UserProfile.Text = $"{user.Name} - Администратор";
break;
}
case "user":
{
UserProfile.Text = $"{user.Name} - Ползователь";
GuestOrUserView();
break;
}
case "manger":
{
UserProfile.Text = $"{user.Name} - Менеджер";
break;
}
default:
{
UserProfile.Text = $"Вы зашли как гость";
GuestOrUserView();
break;
}
}
}
// Метод, который делает неактивными фильтр, сортировку и поиск
private void GuestOrUserView()
{
FilterBox.IsEnabled = false;
SortBox.IsEnabled = false;
SearchBox.IsEnabled = false;
}
// Главный метод
private void ShowUsers()
{
IEnumerable<User> users = Users._users;
var filterItem = FilterBox.SelectionBoxItem as string;
if (!string.IsNullOrWhiteSpace(filterItem) && filterItem != "Без фильтрации")
{
users = users.Where(u => u.Email.EndsWith(filterItem));
}
// Проверяем, введено ли что-то в строку поиска
var search = SearchBox.Text;
if (!string.IsNullOrWhiteSpace(search))
{
// Оставляем только тех, у кого в почте есть введенные буквы
users = users.Where(u => u.Email.Contains(search));
}
// Смотрим, какая выбрана сортировка, и меняем порядок пользователей по почте
var sort = SortBox.SelectionBoxItem as string;
switch (sort)
{
case "По возрастанию": users = users.OrderBy(u => u.Email); break;
case "По убыванию": users = users.OrderByDescending(u => u.Email); break;
}
// Очищаем старый список на экране
UsersCollecction.Clear();
// Заполняем экран новым, уже отфильтрованным списком
foreach (var user in users) UsersCollecction.Add(user);
}
private void FilterBox_OnSelectionChanged(object? sender, SelectionChangedEventArgs e)
{
ShowUsers();
}
private void SortBox_OnSelectionChanged(object? sender, SelectionChangedEventArgs e)
{
ShowUsers();
}
private void SearchBox_OnTextChanged(object? sender, TextChangedEventArgs e)
{
ShowUsers();
}
}
+18
View File
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<!-- This manifest is used on Windows only.
Don't remove it as it might cause problems with window transparency and embedded controls.
For more details visit https://learn.microsoft.com/en-us/windows/win32/sbscs/application-manifests -->
<assemblyIdentity version="1.0.0.0" name="DemoCatas.Desktop"/>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- A list of the Windows versions that this application has been tested on
and is designed to work with. Uncomment the appropriate elements
and Windows will automatically select the most compatible environment. -->
<!-- Windows 10 -->
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />
</application>
</compatibility>
</assembly>