This commit is contained in:
328p
2026-10-21 14:46:20 +03:00
parent a1fd4bc4fc
commit 0a7b800883
50 changed files with 1053 additions and 0 deletions
@@ -0,0 +1,16 @@
Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AvaloniaPostrgresApp", "AvaloniaPostrgresApp\AvaloniaPostrgresApp.csproj", "{2D67BF53-BE3F-4118-8095-57A478E04588}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{2D67BF53-BE3F-4118-8095-57A478E04588}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2D67BF53-BE3F-4118-8095-57A478E04588}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2D67BF53-BE3F-4118-8095-57A478E04588}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2D67BF53-BE3F-4118-8095-57A478E04588}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
@@ -0,0 +1,10 @@
<Application xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="AvaloniaPostrgresApp.App"
RequestedThemeVariant="Default">
<!-- "Default" ThemeVariant follows system theme variant. "Dark" or "Light" are other available options. -->
<Application.Styles>
<FluentTheme />
</Application.Styles>
</Application>
@@ -0,0 +1,23 @@
using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml;
namespace AvaloniaPostrgresApp;
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();
}
}
@@ -0,0 +1,31 @@
using AvaloniaPostrgresApp.Models;
using Microsoft.EntityFrameworkCore;
namespace AvaloniaPostrgresApp;
public class AppDbContext : DbContext
{
public DbSet<UserInfo> Users { get; set; } = null!;
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
string connectionString = "Host=127.0.0.1;Port=5432;Database=postgres;Username=postgres;Password=mysecretpassword;Timeout=15;Command Timeout=15;Trust Server Certificate=true;SSL Mode=Prefer";
optionsBuilder.UseNpgsql(connectionString);
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<UserInfo>().ToTable("UserInfo");
modelBuilder.Entity<UserInfo>().Property(u => u.Id).HasColumnName("id");
modelBuilder.Entity<UserInfo>().Property(u => u.Fio).HasColumnName("fio");
modelBuilder.Entity<UserInfo>().Property(u => u.Login).HasColumnName("login");
modelBuilder.Entity<UserInfo>().Property(u => u.Password).HasColumnName("password");
modelBuilder.Entity<UserInfo>().Property(u => u.RoleId).HasColumnName("role_id");
modelBuilder.Entity<UserInfo>().Ignore(u => u.Orders);
modelBuilder.Entity<UserInfo>().Ignore(u => u.Role);
}
}
@@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<Nullable>enable</Nullable>
<ApplicationManifest>app.manifest</ApplicationManifest>
</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>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="10.*">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="10.*" />
</ItemGroup>
</Project>
@@ -0,0 +1,30 @@
<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="AvaloniaPostrgresApp.MainWindow"
Title="Вход" Width="300" Height="250">
<StackPanel Margin="20" Spacing="10">
<TextBlock Text="Логин:" />
<TextBox Name="LoginInput" />
<TextBlock Text="Пароль:" />
<TextBox Name="PasswordInput" PasswordChar="*" />
<Button Content="Войти"
Click="SignInClick"
HorizontalAlignment="Stretch"
HorizontalContentAlignment="Center"/>
<Button Content="Войти как гость"
Click="GuestSignInClick"
HorizontalAlignment="Stretch"
HorizontalContentAlignment="Center"/>
<TextBlock Name="StatusText" Foreground="Blue" HorizontalAlignment="Center"/>
</StackPanel>
</Window>
@@ -0,0 +1,70 @@
using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Media;
using AvaloniaPostrgresApp.Models;
using System.Linq;
namespace AvaloniaPostrgresApp;
using Microsoft.EntityFrameworkCore;
using Npgsql;
using System;
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private async void SignInClick(object sender, RoutedEventArgs e)
{
string login = LoginInput.Text ?? string.Empty;
string password = PasswordInput.Text ?? string.Empty;
if (string.IsNullOrWhiteSpace(login) || string.IsNullOrWhiteSpace(password))
{
StatusText.Text = "Заполните все поля!";
StatusText.Foreground = Brushes.Red;
return;
}
try
{
using (var db = new PostgresContext())
{
UserInfo? user = await db.UserInfos
.FirstOrDefaultAsync(u => u.Login == login && u.Password == password);
if (user != null)
{
StatusText.Text = $"Успешно! Добро пожаловать, {user.Fio}.";
StatusText.Foreground = Brushes.Green;
}
else
{
StatusText.Text = "Неверный логин или пароль.";
StatusText.Foreground = Brushes.Red;
}
}
}
catch (NpgsqlException)
{
StatusText.Text = "Ошибка подключения. Проверьте строку в PostgresContext.cs или Docker.";
StatusText.Foreground = Brushes.Red;
}
catch (Exception ex)
{
StatusText.Text = ex.InnerException?.Message ?? ex.Message;
StatusText.Foreground = Brushes.Red;
}
}
private void GuestSignInClick(object sender, RoutedEventArgs e)
{
StatusText.Text = "Вы вошли в систему как Гость.";
LoginInput.Text = string.Empty;
PasswordInput.Text = string.Empty;
}
}
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
namespace AvaloniaPostrgresApp.Models;
public partial class Category
{
public int Id { get; set; }
public string CategoryName { get; set; } = null!;
public string Unit { get; set; } = null!;
public virtual ICollection<Tovar> Tovars { get; set; } = new List<Tovar>();
}
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
namespace AvaloniaPostrgresApp.Models;
public partial class Manufacturer
{
public int Id { get; set; }
public string ManufacturerName { get; set; } = null!;
public virtual ICollection<Tovar> Tovars { get; set; } = new List<Tovar>();
}
@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
namespace AvaloniaPostrgresApp.Models;
public partial class Order
{
public int Id { get; set; }
public DateTime OrderDate { get; set; }
public DateTime? DeliveryDate { get; set; }
public int AddressPvzId { get; set; }
public int IdUser { get; set; }
public string? Code { get; set; }
public virtual Pvz AddressPvz { get; set; } = null!;
public virtual UserInfo IdUserNavigation { get; set; } = null!;
public virtual ICollection<OrderDetail> OrderDetails { get; set; } = new List<OrderDetail>();
}
@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
namespace AvaloniaPostrgresApp.Models;
public partial class OrderDetail
{
public int Id { get; set; }
public int IdOrder { get; set; }
public int ArtId { get; set; }
public int Amount { get; set; }
public virtual Tovar Art { get; set; } = null!;
public virtual Order IdOrderNavigation { get; set; } = null!;
}
@@ -0,0 +1,265 @@
using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore;
namespace AvaloniaPostrgresApp.Models;
public partial class PostgresContext : DbContext
{
public PostgresContext()
{
}
public PostgresContext(DbContextOptions<PostgresContext> options)
: base(options)
{
}
public virtual DbSet<Category> Categories { get; set; }
public virtual DbSet<Manufacturer> Manufacturers { get; set; }
public virtual DbSet<Order> Orders { get; set; }
public virtual DbSet<OrderDetail> OrderDetails { get; set; }
public virtual DbSet<Pvz> Pvzs { get; set; }
public virtual DbSet<Role> Roles { get; set; }
public virtual DbSet<Section> Sections { get; set; }
public virtual DbSet<Supplier> Suppliers { get; set; }
public virtual DbSet<Tovar> Tovars { get; set; }
public virtual DbSet<UserInfo> UserInfos { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
#warning To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see https://go.microsoft.com/fwlink/?LinkId=723263.
=> optionsBuilder.UseNpgsql("Host=localhost;Port=5432;Database=postgres;Username=postgres;Password=mysecretpassword");
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.HasPostgresEnum("order_status", new[] { "Завершен", "Новый", "В пути" });
modelBuilder.Entity<Category>(entity =>
{
entity.HasKey(e => e.Id).HasName("category_pkey");
entity.ToTable("category");
entity.Property(e => e.Id)
.UseIdentityAlwaysColumn()
.HasColumnName("id");
entity.Property(e => e.CategoryName)
.HasMaxLength(250)
.HasColumnName("category_name");
entity.Property(e => e.Unit)
.HasMaxLength(10)
.HasColumnName("unit");
});
modelBuilder.Entity<Manufacturer>(entity =>
{
entity.HasKey(e => e.Id).HasName("manufacturer_pkey");
entity.ToTable("manufacturer");
entity.Property(e => e.Id)
.UseIdentityAlwaysColumn()
.HasColumnName("id");
entity.Property(e => e.ManufacturerName)
.HasMaxLength(250)
.HasColumnName("manufacturer_name");
});
modelBuilder.Entity<Order>(entity =>
{
entity.HasKey(e => e.Id).HasName("orders_pkey");
entity.ToTable("orders");
entity.Property(e => e.Id)
.UseIdentityAlwaysColumn()
.HasColumnName("id");
entity.Property(e => e.AddressPvzId).HasColumnName("address_pvz_id");
entity.Property(e => e.Code)
.HasMaxLength(10)
.HasColumnName("code");
entity.Property(e => e.DeliveryDate).HasColumnName("delivery_date");
entity.Property(e => e.IdUser).HasColumnName("id_user");
entity.Property(e => e.OrderDate)
.HasDefaultValueSql("now()")
.HasColumnName("order_date");
entity.HasOne(d => d.AddressPvz).WithMany(p => p.Orders)
.HasForeignKey(d => d.AddressPvzId)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("orders_address_pvz_id_fkey");
entity.HasOne(d => d.IdUserNavigation).WithMany(p => p.Orders)
.HasForeignKey(d => d.IdUser)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("orders_id_user_fkey");
});
modelBuilder.Entity<OrderDetail>(entity =>
{
entity.HasKey(e => e.Id).HasName("order_details_pkey");
entity.ToTable("order_details");
entity.Property(e => e.Id)
.UseIdentityAlwaysColumn()
.HasColumnName("id");
entity.Property(e => e.Amount).HasColumnName("amount");
entity.Property(e => e.ArtId).HasColumnName("art_id");
entity.Property(e => e.IdOrder).HasColumnName("id_order");
entity.HasOne(d => d.Art).WithMany(p => p.OrderDetails)
.HasForeignKey(d => d.ArtId)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("order_details_art_id_fkey");
entity.HasOne(d => d.IdOrderNavigation).WithMany(p => p.OrderDetails)
.HasForeignKey(d => d.IdOrder)
.HasConstraintName("order_details_id_order_fkey");
});
modelBuilder.Entity<Pvz>(entity =>
{
entity.HasKey(e => e.Id).HasName("pvz_pkey");
entity.ToTable("pvz");
entity.Property(e => e.Id)
.UseIdentityAlwaysColumn()
.HasColumnName("id");
entity.Property(e => e.Address)
.HasMaxLength(255)
.HasColumnName("address");
});
modelBuilder.Entity<Role>(entity =>
{
entity.HasKey(e => e.Id).HasName("roles_pkey");
entity.ToTable("roles");
entity.Property(e => e.Id)
.UseIdentityAlwaysColumn()
.HasColumnName("id");
entity.Property(e => e.RoleName)
.HasMaxLength(100)
.HasColumnName("role_name");
});
modelBuilder.Entity<Section>(entity =>
{
entity.HasKey(e => e.Id).HasName("sections_pkey");
entity.ToTable("sections");
entity.Property(e => e.Id)
.UseIdentityAlwaysColumn()
.HasColumnName("id");
entity.Property(e => e.Name)
.HasMaxLength(100)
.HasColumnName("name");
});
modelBuilder.Entity<Supplier>(entity =>
{
entity.HasKey(e => e.Id).HasName("supplier_pkey");
entity.ToTable("supplier");
entity.Property(e => e.Id)
.UseIdentityAlwaysColumn()
.HasColumnName("id");
entity.Property(e => e.SupName)
.HasMaxLength(200)
.HasColumnName("sup_name");
});
modelBuilder.Entity<Tovar>(entity =>
{
entity.HasKey(e => e.Id).HasName("tovar_pkey");
entity.ToTable("tovar");
entity.Property(e => e.Id)
.UseIdentityAlwaysColumn()
.HasColumnName("id");
entity.Property(e => e.Amount).HasColumnName("amount");
entity.Property(e => e.Art)
.HasMaxLength(250)
.HasColumnName("art");
entity.Property(e => e.Cost)
.HasPrecision(10, 2)
.HasColumnName("cost");
entity.Property(e => e.Description).HasColumnName("description");
entity.Property(e => e.Discount)
.HasDefaultValue(0)
.HasColumnName("discount");
entity.Property(e => e.IdCategory).HasColumnName("id_category");
entity.Property(e => e.IdManufacturer).HasColumnName("id_manufacturer");
entity.Property(e => e.IdSection).HasColumnName("id_section");
entity.Property(e => e.IdSupplier).HasColumnName("id_supplier");
entity.Property(e => e.Photo).HasColumnName("photo");
entity.HasOne(d => d.IdCategoryNavigation).WithMany(p => p.Tovars)
.HasForeignKey(d => d.IdCategory)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("tovar_id_category_fkey");
entity.HasOne(d => d.IdManufacturerNavigation).WithMany(p => p.Tovars)
.HasForeignKey(d => d.IdManufacturer)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("tovar_id_manufacturer_fkey");
entity.HasOne(d => d.IdSectionNavigation).WithMany(p => p.Tovars)
.HasForeignKey(d => d.IdSection)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("tovar_id_section_fkey");
entity.HasOne(d => d.IdSupplierNavigation).WithMany(p => p.Tovars)
.HasForeignKey(d => d.IdSupplier)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("tovar_id_supplier_fkey");
});
modelBuilder.Entity<UserInfo>(entity =>
{
entity.HasKey(e => e.Id).HasName("user_info_pkey");
entity.ToTable("user_info");
entity.HasIndex(e => e.Login, "user_info_login_key").IsUnique();
entity.Property(e => e.Id)
.UseIdentityAlwaysColumn()
.HasColumnName("id");
entity.Property(e => e.Fio)
.HasMaxLength(255)
.HasColumnName("fio");
entity.Property(e => e.Login)
.HasMaxLength(255)
.HasColumnName("login");
entity.Property(e => e.Password)
.HasMaxLength(255)
.HasColumnName("password");
entity.Property(e => e.RoleId).HasColumnName("role_id");
entity.HasOne(d => d.Role).WithMany(p => p.UserInfos)
.HasForeignKey(d => d.RoleId)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("user_info_role_id_fkey");
});
OnModelCreatingPartial(modelBuilder);
}
partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
}
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
namespace AvaloniaPostrgresApp.Models;
public partial class Pvz
{
public int Id { get; set; }
public string Address { get; set; } = null!;
public virtual ICollection<Order> Orders { get; set; } = new List<Order>();
}
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
namespace AvaloniaPostrgresApp.Models;
public partial class Role
{
public int Id { get; set; }
public string RoleName { get; set; } = null!;
public virtual ICollection<UserInfo> UserInfos { get; set; } = new List<UserInfo>();
}
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
namespace AvaloniaPostrgresApp.Models;
public partial class Section
{
public int Id { get; set; }
public string Name { get; set; } = null!;
public virtual ICollection<Tovar> Tovars { get; set; } = new List<Tovar>();
}
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
namespace AvaloniaPostrgresApp.Models;
public partial class Supplier
{
public int Id { get; set; }
public string SupName { get; set; } = null!;
public virtual ICollection<Tovar> Tovars { get; set; } = new List<Tovar>();
}
@@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
namespace AvaloniaPostrgresApp.Models;
public partial class Tovar
{
public int Id { get; set; }
public string? Art { get; set; }
public int IdCategory { get; set; }
public int IdSection { get; set; }
public int IdManufacturer { get; set; }
public int IdSupplier { get; set; }
public decimal Cost { get; set; }
public int? Discount { get; set; }
public int Amount { get; set; }
public string? Description { get; set; }
public string? Photo { get; set; }
public virtual Category IdCategoryNavigation { get; set; } = null!;
public virtual Manufacturer IdManufacturerNavigation { get; set; } = null!;
public virtual Section IdSectionNavigation { get; set; } = null!;
public virtual Supplier IdSupplierNavigation { get; set; } = null!;
public virtual ICollection<OrderDetail> OrderDetails { get; set; } = new List<OrderDetail>();
}
@@ -0,0 +1,29 @@
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using AvaloniaPostrgresApp.Models;
namespace AvaloniaPostrgresApp
{
[Table("user_info")]
public class UserInfo
{
[Key]
[Column("id")]
public int Id { get; set; }
[Column("fio")]
public string Fio { get; set; } = string.Empty;
[Column("login")]
public string Login { get; set; } = string.Empty;
[Column("password")]
public string Password { get; set; } = string.Empty;
[Column("role_id")]
public int RoleId { get; set; }
public virtual ICollection<Order> Orders { get; set; } = new List<Order>();
public virtual Role Role { get; set; } = null!;
}
}
@@ -0,0 +1,24 @@
using Avalonia;
using System;
namespace AvaloniaPostrgresApp;
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();
}
@@ -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="AvaloniaPostrgresApp.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>