Добавьте файлы проекта.

This commit is contained in:
KP9lK 2025-01-10 23:50:24 +03:00
parent f2ca134fab
commit 5d2759a070
27 changed files with 1109 additions and 0 deletions

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" addBOMForNewFiles="with BOM under Windows, with no BOM otherwise" />
</project>

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="UserContentModel">
<attachedFolders />
<explicitIncludes />
<explicitExcludes />
</component>
</project>

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RiderProjectSettingsUpdater">
<option name="singleClickDiffPreview" value="1" />
<option name="vcsConfiguration" value="3" />
</component>
</project>

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings" defaultProject="true" />
</project>

View File

@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ChangeListManager">
<list default="true" id="d83cfe2c-bda7-4b3a-acd5-26f0c169074d" name="Changes" comment="" />
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="ProjectColorInfo"><![CDATA[{
"associatedIndex": 5
}]]></component>
<component name="ProjectId" id="2qCqnpOg3DCCLb21ifgtk6icg0A" />
<component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent"><![CDATA[{
"keyToString": {
"RunOnceActivity.ShowReadmeOnStart": "true",
"nodejs_package_manager_path": "npm",
"vue.rearranger.settings.migration": "true"
}
}]]></component>
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="d83cfe2c-bda7-4b3a-acd5-26f0c169074d" name="Changes" comment="" />
<created>1734177075418</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1734177075418</updated>
<workItem from="1734177077014" duration="1000" />
</task>
<servers />
</component>
<component name="UnityProjectConfiguration" hasMinimizedUI="false" />
<component name="VcsManagerConfiguration">
<option name="CLEAR_INITIAL_COMMIT_MESSAGE" value="true" />
</component>
</project>

25
demo-12-14.sln Normal file
View File

@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.11.35222.181
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "demo-12-14", "demo-12-14\demo-12-14.csproj", "{85150DA8-82FE-41D9-B1EE-915B1231DE5F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{85150DA8-82FE-41D9-B1EE-915B1231DE5F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{85150DA8-82FE-41D9-B1EE-915B1231DE5F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{85150DA8-82FE-41D9-B1EE-915B1231DE5F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{85150DA8-82FE-41D9-B1EE-915B1231DE5F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {5344D68D-4280-42B8-9639-32A65BE8879F}
EndGlobalSection
EndGlobal

10
demo-12-14/App.axaml Normal file
View File

@ -0,0 +1,10 @@
<Application xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="demo.App"
RequestedThemeVariant="Default">
<!-- "Default" ThemeVariant follows system theme variant. "Dark" or "Light" are other available options. -->
<Application.Styles>
<FluentTheme />
</Application.Styles>
</Application>

24
demo-12-14/App.axaml.cs Normal file
View File

@ -0,0 +1,24 @@
using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml;
namespace demo
{
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();
}
}
}

View File

@ -0,0 +1,82 @@
<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="demo.MainWindow"
x:CompileBindings="False"
Title="demo">
<DockPanel>
<StackPanel
DockPanel.Dock="Top"
Spacing="5"
HorizontalAlignment="Center"
Height="40" Orientation="Horizontal">
<TextBox
TextChanging="SearchBoxChanging"
x:Name="SearchBox"
Width="200"/>
<ComboBox
SelectionChanged="ManufactureBox_SelectionChanged"
VerticalAlignment="Center"
Width="100"
x:Name="ManufactureBox"/>
<ComboBox
SelectionChanged="SortBox_SelectionChanged"
VerticalAlignment="Center"
Width="100"
x:Name="SortBox">
<ComboBoxItem>
без сорт.
</ComboBoxItem>
<ComboBoxItem>
убыв.
</ComboBoxItem>
<ComboBoxItem>
возраст.
</ComboBoxItem>
</ComboBox>
<TextBlock VerticalAlignment="Center" TextAlignment="Center" x:Name="CountTextBlock"/>
<Button Width="120" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" Height="40" Content="Новый товар" Click="AddNewProduct"/>
</StackPanel>
<ListBox x:Name="ProductBox">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Columns="3"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<Border
Background="{Binding Color}"
BorderBrush="Gray"
BorderThickness="1"
Padding="5">
<StackPanel
HorizontalAlignment="Center">
<Image
Source="{Binding Image}"
Width="100"
Height="100"
/>
<TextBlock
Text="{Binding Title}"
TextWrapping="Wrap"
TextAlignment="Center"
/>
<TextBlock
Text="{Binding Cost}"
TextAlignment="Center"
/>
</StackPanel>
</Border>
</DataTemplate>
</ListBox.ItemTemplate>
<ListBox.ContextMenu>
<ContextMenu>
<MenuItem Click="ProductItemClick" Header="Remove"/>
</ContextMenu>
</ListBox.ContextMenu>
</ListBox>
</DockPanel>
</Window>

View File

@ -0,0 +1,131 @@
using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Media;
using Avalonia.Media.Imaging;
using Avalonia.Utilities;
using demoModels;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
namespace demo
{
public partial class MainWindow : Window
{
ObservableCollection<ProductPresenter> products = new ObservableCollection<ProductPresenter>();
List<ProductPresenter> dataSourceProducts;
ObservableCollection<string> manufactures;
public MainWindow()
{
InitializeComponent();
using var context = new ProductsTradeContext();
dataSourceProducts = context.Products.Include(it => it.Manufacturer).Select(product => new ProductPresenter
{
Id = product.Id,
Mainimagepath = product.Mainimagepath,
Isactive = product.Isactive,
Cost = product.Cost,
Title = product.Title,
Description = product.Description,
Manufacturer = product.Manufacturer,
}).ToList();
var dataSourceManafacture = context.Manufacturers.Select(it => it.Name).ToList();
manufactures = new ObservableCollection<string>(dataSourceManafacture);
manufactures.Insert(0,"Âûâåñòè âñå");
ProductBox.ItemsSource = products;
ManufactureBox.ItemsSource = manufactures;
ManufactureBox.SelectedIndex = 0;
DisplayProducts();
}
private void DisplayProducts()
{
var temp = dataSourceProducts;
products.Clear();
if (ManufactureBox.SelectedIndex != 0)
{
temp = temp.Where(it => it.ManufacatureName.Contains(ManufactureBox.SelectedItem.ToString())).ToList();
}
if (!string.IsNullOrEmpty(SearchBox.Text))
{
var searchWord = SearchBox.Text.ToLower();
temp = temp.Where(it => IsContains(it.Title, it.Description, searchWord)).ToList();
}
switch (SortBox.SelectedIndex) {
case 1: temp = temp.OrderBy(temp => temp.Cost).ToList(); break;
case 2: temp = temp.OrderByDescending(temp => temp.Cost).ToList(); break;
default: break;
}
foreach (var item in temp)
{
products.Add(item);
}
CountTextBlock.Text = $"{temp.Count}\\{dataSourceProducts.Count}";
}
public bool IsContains(string title, string? description, string searchWord) {
string desc = string.Empty;
if(description != null) desc = description;
string message = (title + desc).ToLower();
searchWord = searchWord.ToLower();
var result = message.Contains(searchWord);
return message.Contains(searchWord);
}
public void SearchBoxChanging(object sender, TextChangingEventArgs eventArgs)
{
DisplayProducts();
}
public void SortBox_SelectionChanged(object sender, SelectionChangedEventArgs eventArgs) {
DisplayProducts();
}
public void ManufactureBox_SelectionChanged(object sender, SelectionChangedEventArgs eventArgs)
{
DisplayProducts();
}
public void ProductItemClick(object sender, RoutedEventArgs e)
{
using var context = new ProductsTradeContext();
var product = ProductBox.SelectedItem as ProductPresenter;
if (product == null) return;
var removeProduct = context.Products.Include(it => it.Productsales).First(it => it.Id == product.Id);
if(removeProduct == null) return;
if(removeProduct.Productsales.Count() > 0) return;
context.Products.Remove(removeProduct);
if (context.SaveChanges() > 0) products.Remove(product);
}
public async void AddNewProduct(object sender, RoutedEventArgs e)
{
using ProductsTradeContext context = new ProductsTradeContext();
var newProduct = await new ProductWindow().ShowDialog<ProductPresenter>(this);
context.Products.Add(newProduct);
if (context.SaveChanges() > 0) {
newProduct.Manufacturer = context.Manufacturers.Find(newProduct.Manufacturerid);
dataSourceProducts.Add(newProduct);
}
}
}
public class ProductPresenter() : Product{
public string ManufacatureName { get => Manufacturer.Name; }
Bitmap? Image { get
{
try
{
return new Bitmap(Mainimagepath);
}
catch
{
return null;
}
} }
public IBrush Color { get {
return Isactive? Brushes.White : Brushes.Gray;
} }
}
}

View File

@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
namespace demoModels;
public partial class Client
{
public int Id { get; set; }
public string Firstname { get; set; } = null!;
public string Lastname { get; set; } = null!;
public string? Patronymic { get; set; }
public DateOnly? Birthday { get; set; }
public DateTime Registrationdate { get; set; }
public string? Email { get; set; }
public string Phone { get; set; } = null!;
public char Gendercode { get; set; }
public string? Photopath { get; set; }
public virtual ICollection<Clientservice> Clientservices { get; set; } = new List<Clientservice>();
public virtual Gender GendercodeNavigation { get; set; } = null!;
public virtual ICollection<Tag> Tags { get; set; } = new List<Tag>();
}

View File

@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
namespace demoModels;
public partial class Clientservice
{
public int Id { get; set; }
public int Clientid { get; set; }
public int Serviceid { get; set; }
public DateTime Starttime { get; set; }
public string? Comment { get; set; }
public virtual Client Client { get; set; } = null!;
public virtual ICollection<Documentbyservice> Documentbyservices { get; set; } = new List<Documentbyservice>();
public virtual ICollection<Productsale> Productsales { get; set; } = new List<Productsale>();
public virtual Service Service { get; set; } = null!;
}

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
namespace demoModels;
public partial class Documentbyservice
{
public int Id { get; set; }
public int Clientserviceid { get; set; }
public string Documentpath { get; set; } = null!;
public virtual Clientservice Clientservice { get; set; } = null!;
}

View File

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
namespace demoModels;
public partial class Gender
{
public char Code { get; set; }
public string? Name { get; set; }
public virtual ICollection<Client> Clients { get; set; } = new List<Client>();
}

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
namespace demoModels;
public partial class Manufacturer
{
public int Id { get; set; }
public string Name { get; set; } = null!;
public DateOnly? Startdate { get; set; }
public virtual ICollection<Product> Products { get; set; } = new List<Product>();
}

View File

@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
namespace demoModels;
public partial class Product
{
public int Id { get; set; }
public string Title { get; set; } = null!;
public decimal Cost { get; set; }
public string? Description { get; set; }
public string? Mainimagepath { get; set; }
public bool Isactive { get; set; }
public int? Manufacturerid { get; set; }
public virtual Manufacturer? Manufacturer { get; set; }
public virtual ICollection<Productphoto> Productphotos { get; set; } = new List<Productphoto>();
public virtual ICollection<Productsale> Productsales { get; set; } = new List<Productsale>();
public virtual ICollection<Product> Attachedproducts { get; set; } = new List<Product>();
public virtual ICollection<Product> Mainproducts { get; set; } = new List<Product>();
}

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
namespace demoModels;
public partial class Productphoto
{
public int Id { get; set; }
public int Productid { get; set; }
public string Photopath { get; set; } = null!;
public virtual Product Product { get; set; } = null!;
}

View File

@ -0,0 +1,369 @@
using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore;
namespace demoModels;
public partial class ProductsTradeContext : DbContext
{
public ProductsTradeContext()
{
}
public ProductsTradeContext(DbContextOptions<ProductsTradeContext> options)
: base(options)
{
}
public virtual DbSet<Client> Clients { get; set; }
public virtual DbSet<Clientservice> Clientservices { get; set; }
public virtual DbSet<Documentbyservice> Documentbyservices { get; set; }
public virtual DbSet<Gender> Genders { get; set; }
public virtual DbSet<Manufacturer> Manufacturers { get; set; }
public virtual DbSet<Product> Products { get; set; }
public virtual DbSet<Productphoto> Productphotos { get; set; }
public virtual DbSet<Productsale> Productsales { get; set; }
public virtual DbSet<Service> Services { get; set; }
public virtual DbSet<Servicephoto> Servicephotos { get; set; }
public virtual DbSet<Tag> Tags { 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=products_trade;Username=postgres;Password=123");
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Client>(entity =>
{
entity.HasKey(e => e.Id).HasName("client_pkey");
entity.ToTable("client");
entity.Property(e => e.Id)
.HasDefaultValueSql("nextval('client_seq'::regclass)")
.HasColumnName("id");
entity.Property(e => e.Birthday).HasColumnName("birthday");
entity.Property(e => e.Email)
.HasMaxLength(255)
.HasColumnName("email");
entity.Property(e => e.Firstname)
.HasMaxLength(50)
.HasColumnName("firstname");
entity.Property(e => e.Gendercode)
.HasMaxLength(1)
.HasColumnName("gendercode");
entity.Property(e => e.Lastname)
.HasMaxLength(50)
.HasColumnName("lastname");
entity.Property(e => e.Patronymic)
.HasMaxLength(50)
.HasColumnName("patronymic");
entity.Property(e => e.Phone)
.HasMaxLength(20)
.HasColumnName("phone");
entity.Property(e => e.Photopath)
.HasMaxLength(1000)
.HasColumnName("photopath");
entity.Property(e => e.Registrationdate)
.HasColumnType("timestamp(6) without time zone")
.HasColumnName("registrationdate");
entity.HasOne(d => d.GendercodeNavigation).WithMany(p => p.Clients)
.HasForeignKey(d => d.Gendercode)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("fk_client_gender");
entity.HasMany(d => d.Tags).WithMany(p => p.Clients)
.UsingEntity<Dictionary<string, object>>(
"Tagofclient",
r => r.HasOne<Tag>().WithMany()
.HasForeignKey("Tagid")
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("fk_tagofclient_tag"),
l => l.HasOne<Client>().WithMany()
.HasForeignKey("Clientid")
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("fk_tagofclient_client"),
j =>
{
j.HasKey("Clientid", "Tagid").HasName("tagofclient_pkey");
j.ToTable("tagofclient");
j.IndexerProperty<int>("Clientid").HasColumnName("clientid");
j.IndexerProperty<int>("Tagid").HasColumnName("tagid");
});
});
modelBuilder.Entity<Clientservice>(entity =>
{
entity.HasKey(e => e.Id).HasName("clientservice_pkey");
entity.ToTable("clientservice");
entity.Property(e => e.Id)
.HasDefaultValueSql("nextval('clientservice_seq'::regclass)")
.HasColumnName("id");
entity.Property(e => e.Clientid).HasColumnName("clientid");
entity.Property(e => e.Comment).HasColumnName("comment");
entity.Property(e => e.Serviceid).HasColumnName("serviceid");
entity.Property(e => e.Starttime)
.HasColumnType("timestamp(6) without time zone")
.HasColumnName("starttime");
entity.HasOne(d => d.Client).WithMany(p => p.Clientservices)
.HasForeignKey(d => d.Clientid)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("fk_clientservice_client");
entity.HasOne(d => d.Service).WithMany(p => p.Clientservices)
.HasForeignKey(d => d.Serviceid)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("fk_clientservice_service");
});
modelBuilder.Entity<Documentbyservice>(entity =>
{
entity.HasKey(e => e.Id).HasName("documentbyservice_pkey");
entity.ToTable("documentbyservice");
entity.Property(e => e.Id)
.HasDefaultValueSql("nextval('documentbyservice_seq'::regclass)")
.HasColumnName("id");
entity.Property(e => e.Clientserviceid).HasColumnName("clientserviceid");
entity.Property(e => e.Documentpath)
.HasMaxLength(1000)
.HasColumnName("documentpath");
entity.HasOne(d => d.Clientservice).WithMany(p => p.Documentbyservices)
.HasForeignKey(d => d.Clientserviceid)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("fk_documentbyservice_clientservice");
});
modelBuilder.Entity<Gender>(entity =>
{
entity.HasKey(e => e.Code).HasName("gender_pkey");
entity.ToTable("gender");
entity.Property(e => e.Code)
.HasMaxLength(1)
.ValueGeneratedNever()
.HasColumnName("code");
entity.Property(e => e.Name)
.HasMaxLength(10)
.HasColumnName("name");
});
modelBuilder.Entity<Manufacturer>(entity =>
{
entity.HasKey(e => e.Id).HasName("manufacturer_pkey");
entity.ToTable("manufacturer");
entity.Property(e => e.Id)
.HasDefaultValueSql("nextval('manufacturer_seq'::regclass)")
.HasColumnName("id");
entity.Property(e => e.Name)
.HasMaxLength(100)
.HasColumnName("name");
entity.Property(e => e.Startdate).HasColumnName("startdate");
});
modelBuilder.Entity<Product>(entity =>
{
entity.HasKey(e => e.Id).HasName("product_pkey");
entity.ToTable("product");
entity.Property(e => e.Id)
.HasDefaultValueSql("nextval('product_seq'::regclass)")
.HasColumnName("id");
entity.Property(e => e.Cost)
.HasPrecision(19, 4)
.HasColumnName("cost");
entity.Property(e => e.Description).HasColumnName("description");
entity.Property(e => e.Isactive).HasColumnName("isactive");
entity.Property(e => e.Mainimagepath)
.HasMaxLength(1000)
.HasColumnName("mainimagepath");
entity.Property(e => e.Manufacturerid).HasColumnName("manufacturerid");
entity.Property(e => e.Title)
.HasMaxLength(100)
.HasColumnName("title");
entity.HasOne(d => d.Manufacturer).WithMany(p => p.Products)
.HasForeignKey(d => d.Manufacturerid)
.HasConstraintName("fk_product_manufacturer");
entity.HasMany(d => d.Attachedproducts).WithMany(p => p.Mainproducts)
.UsingEntity<Dictionary<string, object>>(
"Attachedproduct",
r => r.HasOne<Product>().WithMany()
.HasForeignKey("Attachedproductid")
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("fk_attachedproduct_product1"),
l => l.HasOne<Product>().WithMany()
.HasForeignKey("Mainproductid")
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("fk_attachedproduct_product"),
j =>
{
j.HasKey("Mainproductid", "Attachedproductid").HasName("attachedproduct_pkey");
j.ToTable("attachedproduct");
j.IndexerProperty<int>("Mainproductid").HasColumnName("mainproductid");
j.IndexerProperty<int>("Attachedproductid").HasColumnName("attachedproductid");
});
entity.HasMany(d => d.Mainproducts).WithMany(p => p.Attachedproducts)
.UsingEntity<Dictionary<string, object>>(
"Attachedproduct",
r => r.HasOne<Product>().WithMany()
.HasForeignKey("Mainproductid")
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("fk_attachedproduct_product"),
l => l.HasOne<Product>().WithMany()
.HasForeignKey("Attachedproductid")
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("fk_attachedproduct_product1"),
j =>
{
j.HasKey("Mainproductid", "Attachedproductid").HasName("attachedproduct_pkey");
j.ToTable("attachedproduct");
j.IndexerProperty<int>("Mainproductid").HasColumnName("mainproductid");
j.IndexerProperty<int>("Attachedproductid").HasColumnName("attachedproductid");
});
});
modelBuilder.Entity<Productphoto>(entity =>
{
entity.HasKey(e => e.Id).HasName("productphoto_pkey");
entity.ToTable("productphoto");
entity.Property(e => e.Id)
.HasDefaultValueSql("nextval('productphoto_seq'::regclass)")
.HasColumnName("id");
entity.Property(e => e.Photopath)
.HasMaxLength(1000)
.HasColumnName("photopath");
entity.Property(e => e.Productid).HasColumnName("productid");
entity.HasOne(d => d.Product).WithMany(p => p.Productphotos)
.HasForeignKey(d => d.Productid)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("fk_productphoto_product");
});
modelBuilder.Entity<Productsale>(entity =>
{
entity.HasKey(e => e.Id).HasName("productsale_pkey");
entity.ToTable("productsale");
entity.Property(e => e.Id)
.HasDefaultValueSql("nextval('productsale_seq'::regclass)")
.HasColumnName("id");
entity.Property(e => e.Clientserviceid).HasColumnName("clientserviceid");
entity.Property(e => e.Productid).HasColumnName("productid");
entity.Property(e => e.Quantity).HasColumnName("quantity");
entity.Property(e => e.Saledate)
.HasColumnType("timestamp(6) without time zone")
.HasColumnName("saledate");
entity.HasOne(d => d.Clientservice).WithMany(p => p.Productsales)
.HasForeignKey(d => d.Clientserviceid)
.HasConstraintName("fk_productsale_clientservice");
entity.HasOne(d => d.Product).WithMany(p => p.Productsales)
.HasForeignKey(d => d.Productid)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("fk_productsale_product");
});
modelBuilder.Entity<Service>(entity =>
{
entity.HasKey(e => e.Id).HasName("service_pkey");
entity.ToTable("service");
entity.Property(e => e.Id)
.HasDefaultValueSql("nextval('service_seq'::regclass)")
.HasColumnName("id");
entity.Property(e => e.Cost)
.HasPrecision(19, 4)
.HasColumnName("cost");
entity.Property(e => e.Description).HasColumnName("description");
entity.Property(e => e.Discount).HasColumnName("discount");
entity.Property(e => e.Durationinseconds).HasColumnName("durationinseconds");
entity.Property(e => e.Mainimagepath)
.HasMaxLength(1000)
.HasColumnName("mainimagepath");
entity.Property(e => e.Title)
.HasMaxLength(100)
.HasColumnName("title");
});
modelBuilder.Entity<Servicephoto>(entity =>
{
entity.HasKey(e => e.Id).HasName("servicephoto_pkey");
entity.ToTable("servicephoto");
entity.Property(e => e.Id)
.HasDefaultValueSql("nextval('servicephoto_seq'::regclass)")
.HasColumnName("id");
entity.Property(e => e.Photopath)
.HasMaxLength(1000)
.HasColumnName("photopath");
entity.Property(e => e.Serviceid).HasColumnName("serviceid");
entity.HasOne(d => d.Service).WithMany(p => p.Servicephotos)
.HasForeignKey(d => d.Serviceid)
.OnDelete(DeleteBehavior.ClientSetNull)
.HasConstraintName("fk_servicephoto_service");
});
modelBuilder.Entity<Tag>(entity =>
{
entity.HasKey(e => e.Id).HasName("tag_pkey");
entity.ToTable("tag");
entity.Property(e => e.Id)
.HasDefaultValueSql("nextval('tag_seq'::regclass)")
.HasColumnName("id");
entity.Property(e => e.Color)
.HasMaxLength(6)
.IsFixedLength()
.HasColumnName("color");
entity.Property(e => e.Title)
.HasMaxLength(30)
.HasColumnName("title");
});
modelBuilder.HasSequence("client_seq");
modelBuilder.HasSequence("clientservice_seq");
modelBuilder.HasSequence("documentbyservice_seq");
modelBuilder.HasSequence("manufacturer_seq");
modelBuilder.HasSequence("product_seq");
modelBuilder.HasSequence("productphoto_seq");
modelBuilder.HasSequence("productsale_seq");
modelBuilder.HasSequence("service_seq");
modelBuilder.HasSequence("servicephoto_seq");
modelBuilder.HasSequence("tag_seq");
OnModelCreatingPartial(modelBuilder);
}
partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
}

View File

@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
namespace demoModels;
public partial class Productsale
{
public int Id { get; set; }
public DateTime Saledate { get; set; }
public int Productid { get; set; }
public int Quantity { get; set; }
public int? Clientserviceid { get; set; }
public virtual Clientservice? Clientservice { get; set; }
public virtual Product Product { get; set; } = null!;
}

View File

@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
namespace demoModels;
public partial class Service
{
public int Id { get; set; }
public string Title { get; set; } = null!;
public decimal Cost { get; set; }
public int Durationinseconds { get; set; }
public string? Description { get; set; }
public double? Discount { get; set; }
public string? Mainimagepath { get; set; }
public virtual ICollection<Clientservice> Clientservices { get; set; } = new List<Clientservice>();
public virtual ICollection<Servicephoto> Servicephotos { get; set; } = new List<Servicephoto>();
}

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
namespace demoModels;
public partial class Servicephoto
{
public int Id { get; set; }
public int Serviceid { get; set; }
public string Photopath { get; set; } = null!;
public virtual Service Service { get; set; } = null!;
}

15
demo-12-14/Models/Tag.cs Normal file
View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
namespace demoModels;
public partial class Tag
{
public int Id { get; set; }
public string Title { get; set; } = null!;
public string Color { get; set; } = null!;
public virtual ICollection<Client> Clients { get; set; } = new List<Client>();
}

View File

@ -0,0 +1,36 @@
<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="400" d:DesignHeight="500"
x:Class="demo.ProductWindow"
Padding="5"
Title="ProductWindow">
<StackPanel Spacing="5" Background="AliceBlue">
<TextBlock x:Name="ProductIdLabel" Text="ProductId"/>
<TextBox x:Name="ProductId" IsReadOnly="True"/>
<TextBlock HorizontalAlignment="Center" Text="ProductImage"/>
<Image x:Name="ProductImage" Width="100" Height="100"/>
<Button HorizontalAlignment="Center" Width="100" x:Name="AddImage" Click="AddImageClick" Content="AddImage"/>
<TextBlock Text="ProductCost"/>
<TextBox x:Name="ProductCost" />
<TextBlock Text="ProductName"/>
<TextBox x:Name="ProductName"/>
<TextBlock Text="ProductTitle"/>
<TextBox x:Name="ProductTitle"/>
<TextBlock Text="ProductDesc"/>
<TextBox x:Name="ProductDesc"/>
<TextBlock Text="ProductManufacture"/>
<ComboBox x:Name="ProductManufacture" Width="150"/>
<StackPanel Spacing="5" Orientation="Horizontal">
<TextBlock VerticalAlignment="Center" Text="IsActive"/>
<CheckBox x:Name="IsActiveBox" VerticalAlignment="Center"/>
</StackPanel>
<StackPanel Spacing="5" Orientation="Horizontal">
<Button x:Name="AddButton" Click="AddClick" Content="Add"/>
<Button x:Name="EditButton" Click="EditClick" Content="Edit"/>
<Button Content="Exit"/>
</StackPanel>
</StackPanel>
</Window>

View File

@ -0,0 +1,80 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Markup.Xaml;
using Avalonia.Media.Imaging;
using Avalonia.Platform.Storage;
using demoModels;
using System;
using System.ComponentModel.Design;
using System.Linq;
using System.Threading.Tasks;
namespace demo;
public partial class ProductWindow : Window
{
public string PathToImage = string.Empty;
public ProductWindow()
{
using ProductsTradeContext context = new ProductsTradeContext();
InitializeComponent();
ProductId.IsVisible = false;
ProductIdLabel.IsVisible = false;
ProductIdLabel.IsVisible = false;
EditButton.IsVisible = false;
ProductManufacture.ItemsSource = context.Manufacturers.Select(it => it.Name).ToList();
}
private async Task<Bitmap?> SelectImageAndSaveImage()
{
var showDilaog = StorageProvider.OpenFilePickerAsync(
new Avalonia.Platform.Storage.FilePickerOpenOptions()
{
Title = "Âûáåðèòå èçîáðàæåíèå",
FileTypeFilter = new[] { FilePickerFileTypes.ImageAll }
});
var storageFile = await showDilaog;
try
{
var bmp = new Bitmap(storageFile.First().TryGetLocalPath());
string path = $"Òîâàðû àâòîñåðâèñà\\{Guid.NewGuid()}.jpg";
bmp.Save(path);
PathToImage = path;
return bmp;
}
catch
{
return null;
}
}
public async void AddClick(object sender, RoutedEventArgs e)
{
using ProductsTradeContext context = new ProductsTradeContext();
ProductPresenter presenter = new ProductPresenter();
if (!decimal.TryParse(ProductCost.Text, out decimal cost)) return;
if (cost < 0) return;
presenter.Cost = cost;
if (string.IsNullOrEmpty(ProductName.Text)) return;
presenter.Title = ProductName.Text;
if (string.IsNullOrEmpty(ProductDesc.Text)) return;
presenter.Description = ProductDesc.Text;
var findManufacture = context.Manufacturers.First(it => it.Name == ProductManufacture.SelectedItem.ToString());
if (findManufacture == null) return;
presenter.Manufacturerid = findManufacture.Id;
presenter.Isactive = IsActiveBox.IsPressed;
if (String.IsNullOrEmpty(PathToImage)) return;
presenter.Mainimagepath = PathToImage;
Close(presenter);
}
public void EditClick(object sender, RoutedEventArgs e)
{
}
public async void AddImageClick(object sender, RoutedEventArgs e)
{
ProductImage.Source = await SelectImageAndSaveImage();
}
}

22
demo-12-14/Program.cs Normal file
View File

@ -0,0 +1,22 @@
using Avalonia;
using System;
namespace demo
{
internal 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()
.WithInterFont()
.LogToTrace();
}
}

18
demo-12-14/app.manifest Normal file
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="demo.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>

View File

@ -0,0 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
<ApplicationManifest>app.manifest</ApplicationManifest>
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="11.1.0" />
<PackageReference Include="Avalonia.Desktop" Version="11.1.0" />
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.1.0" />
<PackageReference Include="Avalonia.Fonts.Inter" Version="11.1.0" />
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.10" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.10">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.10" />
</ItemGroup>
</Project>