This commit is contained in:
dimazhelovanov 2023-11-30 23:20:29 +04:00
parent 0bd1b174eb
commit 6a7c428cdb
47 changed files with 2203 additions and 38 deletions

View File

@ -0,0 +1,22 @@
using DataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Contracts.BindingModels
{
public class BookBindingModel : IBook
{
public string Name { get; set; } = string.Empty;
public string Readers { get; set; } = string.Empty;
public string Shape { get; set; } = string.Empty;
public string Annotation { get; set; } = string.Empty;
public int Id { get; set; }
}
}

View File

@ -0,0 +1,16 @@
using DataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Contracts.BindingModels
{
public class ShapeBindingModel : IShape
{
public string Name { get; set; } = string.Empty;
public int Id { get; set; }
}
}

View File

@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\DataModels\DataModels.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Contracts.SearchModels
{
public class BookSearchModel
{
public int? Id { get; set; }
public string? Name { get; set; }
}
}

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Contracts.SearchModels
{
public class ShapeSearchModel
{
public int? Id { get; set; }
public string? Name { get; set; }
}
}

View File

@ -0,0 +1,21 @@
using Contracts.BindingModels;
using Contracts.SearchModels;
using Contracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Contracts.StoragesContracts
{
public interface IBookStorage
{
List<BookViewModel> GetFullList();
List<BookViewModel> GetFilteredList(BookSearchModel model);
BookViewModel? GetElement(BookSearchModel model);
BookViewModel? Insert(BookBindingModel model);
BookViewModel? Update(BookBindingModel model);
BookViewModel? Delete(BookBindingModel model);
}
}

View File

@ -0,0 +1,21 @@
using Contracts.BindingModels;
using Contracts.SearchModels;
using Contracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Contracts.StoragesContracts
{
public interface IShapeStorage
{
List<ShapeViewModel> GetFullList();
List<ShapeViewModel> GetFilteredList(ShapeSearchModel model);
ShapeViewModel? GetElement(ShapeSearchModel model);
ShapeViewModel? Insert(ShapeBindingModel model);
ShapeViewModel? Update(ShapeBindingModel model);
ShapeViewModel? Delete(ShapeBindingModel model);
}
}

View File

@ -0,0 +1,22 @@
using DataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Contracts.ViewModels
{
public class BookViewModel : IBook
{
public string Name { get; set; } = string.Empty;
public string Readers { get; set; } = string.Empty;
public string Shape { get; set; } = string.Empty;
public string Annotation { get; set; } = string.Empty;
public int Id { get; set; }
}
}

View File

@ -0,0 +1,23 @@
using DataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Contracts.ViewModels
{
public class ShapeViewModel : IShape
{
public string Name { get; set; } = string.Empty;
public int Id { get; set; }
public ShapeViewModel() { }
public ShapeViewModel(IShape shape)
{
Id = shape.Id;
Name = shape.Name;
}
}
}

View File

@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

13
DataModels/IId.cs Normal file
View File

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DataModels
{
public interface IId
{
int Id { get; }
}
}

View File

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DataModels.Models
{
public interface IBook: IId
{
string Name { get; }
string Readers { get; }
string Shape { get; }
string Annotation { get; }
}
}

View File

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DataModels.Models
{
public interface IShape: IId
{
string Name { get; }
}
}

View File

@ -0,0 +1,26 @@
using DatabaseImplement.Models;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DatabaseImplement
{
public class COPcontext: DbContext
{
protected override void OnConfiguring(DbContextOptionsBuilder
optionsBuilder)
{
if (optionsBuilder.IsConfigured == false)
{
optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-ON2V3BB\SQLEXPRESS;Initial Catalog=COPDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
}
base.OnConfiguring(optionsBuilder);
}
public virtual DbSet<Book> Books { set; get; }
public virtual DbSet<Shape> Shapes { set; get; }
}
}

View File

@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.25" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.25" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.25">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Contracts\Contracts.csproj" />
<ProjectReference Include="..\DataModels\DataModels.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,94 @@
using Contracts.BindingModels;
using Contracts.SearchModels;
using Contracts.StoragesContracts;
using Contracts.ViewModels;
using DatabaseImplement.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DatabaseImplement.Implements
{
public class BookStorage : IBookStorage
{
public BookViewModel? Delete(BookBindingModel model)
{
using var context = new COPcontext();
var element = context.Books.FirstOrDefault(rec => rec.Id ==
model.Id);
if (element != null)
{
context.Books.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
public BookViewModel? GetElement(BookSearchModel model)
{
if (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue)
{
return null;
}
using var context = new COPcontext();
return context.Books
.FirstOrDefault(x =>
(!string.IsNullOrEmpty(model.Name) && x.Name ==
model.Name) ||
(model.Id.HasValue && x.Id == model.Id))
?.GetViewModel;
}
public List<BookViewModel> GetFilteredList(BookSearchModel model)
{
if (string.IsNullOrEmpty(model.Name))
{
return new();
}
using var context = new COPcontext();
return context.Books
.Where(x => x.Name.Contains(model.Name))
.Select(x => x.GetViewModel)
.ToList();
}
public List<BookViewModel> GetFullList()
{
using var context = new COPcontext();
return context.Books
.Select(x => x.GetViewModel)
.ToList();
}
public BookViewModel? Insert(BookBindingModel model)
{
var newComponent = Book.Create(model);
if (newComponent == null)
{
return null;
}
using var context = new COPcontext();
context.Books.Add(newComponent);
context.SaveChanges();
return newComponent.GetViewModel;
}
public BookViewModel? Update(BookBindingModel model)
{
using var context = new COPcontext();
var component = context.Books.FirstOrDefault(x => x.Id ==
model.Id);
if (component == null)
{
return null;
}
component.Update(model);
context.SaveChanges();
return component.GetViewModel;
}
}
}

View File

@ -0,0 +1,93 @@
using Contracts.BindingModels;
using Contracts.SearchModels;
using Contracts.StoragesContracts;
using Contracts.ViewModels;
using DatabaseImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DatabaseImplement.Implements
{
public class ShapeStorage : IShapeStorage
{
public ShapeViewModel? Delete(ShapeBindingModel model)
{
using var context = new COPcontext();
var element = context.Shapes.FirstOrDefault(rec => rec.Id ==
model.Id);
if (element != null)
{
context.Shapes.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
public ShapeViewModel? GetElement(ShapeSearchModel model)
{
if (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue)
{
return null;
}
using var context = new COPcontext();
return context.Shapes
.FirstOrDefault(x =>
(!string.IsNullOrEmpty(model.Name) && x.Name ==
model.Name) ||
(model.Id.HasValue && x.Id == model.Id))
?.GetViewModel;
}
public List<ShapeViewModel> GetFilteredList(ShapeSearchModel model)
{
if (string.IsNullOrEmpty(model.Name))
{
return new();
}
using var context = new COPcontext();
return context.Shapes
.Where(x => x.Name.Contains(model.Name))
.Select(x => x.GetViewModel)
.ToList();
}
public List<ShapeViewModel> GetFullList()
{
using var context = new COPcontext();
return context.Shapes
.Select(x => x.GetViewModel)
.ToList();
}
public ShapeViewModel? Insert(ShapeBindingModel model)
{
var newComponent = Shape.Create(model);
if (newComponent == null)
{
return null;
}
using var context = new COPcontext();
context.Shapes.Add(newComponent);
context.SaveChanges();
return newComponent.GetViewModel;
}
public ShapeViewModel? Update(ShapeBindingModel model)
{
using var context = new COPcontext();
var component = context.Shapes.FirstOrDefault(x => x.Id ==
model.Id);
if (component == null)
{
return null;
}
component.Update(model);
context.SaveChanges();
return component.GetViewModel;
}
}
}

View File

@ -0,0 +1,74 @@
// <auto-generated />
using DatabaseImplement;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace DatabaseImplement.Migrations
{
[DbContext(typeof(COPcontext))]
[Migration("20231116180013_Migration1")]
partial class Migration1
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "6.0.25")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1);
modelBuilder.Entity("DatabaseImplement.Models.Book", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"), 1L, 1);
b.Property<string>("Annotation")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Readers")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Shape")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Books");
});
modelBuilder.Entity("DatabaseImplement.Models.Shape", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"), 1L, 1);
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Shapes");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,50 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace DatabaseImplement.Migrations
{
public partial class Migration1 : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Books",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Name = table.Column<string>(type: "nvarchar(max)", nullable: false),
Readers = table.Column<string>(type: "nvarchar(max)", nullable: false),
Shape = table.Column<string>(type: "nvarchar(max)", nullable: false),
Annotation = table.Column<string>(type: "nvarchar(max)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Books", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Shapes",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Name = table.Column<string>(type: "nvarchar(max)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Shapes", x => x.Id);
});
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Books");
migrationBuilder.DropTable(
name: "Shapes");
}
}
}

View File

@ -0,0 +1,72 @@
// <auto-generated />
using DatabaseImplement;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace DatabaseImplement.Migrations
{
[DbContext(typeof(COPcontext))]
partial class COPcontextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "6.0.25")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1);
modelBuilder.Entity("DatabaseImplement.Models.Book", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"), 1L, 1);
b.Property<string>("Annotation")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Readers")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Shape")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Books");
});
modelBuilder.Entity("DatabaseImplement.Models.Shape", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"), 1L, 1);
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Shapes");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,65 @@
using Contracts.BindingModels;
using Contracts.ViewModels;
using DataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DatabaseImplement.Models
{
public class Book : IBook
{
[Required]
public string Name { get; set; } = string.Empty;
[Required]
public string Readers { get; set; } = string.Empty;
[Required]
public string Shape { get; set; } = string.Empty;
[Required]
public string Annotation { get; set; } = string.Empty;
public int Id { get; set; }
public static Book? Create(BookBindingModel model)
{
if (model == null)
{
return null;
}
return new Book()
{
Id = model.Id,
Annotation = model.Annotation,
Name = model.Name,
Readers = model.Readers,
Shape = model.Shape
};
}
public void Update(BookBindingModel model)
{
if (model == null)
{
return;
}
Name = model.Name;
Readers = model.Readers;
Shape = model.Shape;
Annotation = model.Annotation;
}
public BookViewModel GetViewModel => new()
{
Id = Id,
Annotation = Annotation,
Name = Name,
Readers = Readers,
Shape = Shape
};
}
}

View File

@ -0,0 +1,51 @@
using Contracts.BindingModels;
using Contracts.ViewModels;
using DataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DatabaseImplement.Models
{
public class Shape : IShape
{
[Required]
public string Name { get; set; }=string.Empty;
public int Id { get; set; }
public static Shape? Create(ShapeBindingModel model)
{
if (model == null)
{
return null;
}
return new Shape()
{
Id = model.Id,
Name = model.Name
};
}
public void Update(ShapeBindingModel model)
{
if (model == null)
{
return;
}
Id = model.Id;
Name = model.Name;
}
public ShapeViewModel GetViewModel => new()
{
Id = Id,
Name = Name
};
}
}

View File

@ -5,7 +5,15 @@ VisualStudioVersion = 17.5.33424.131
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "KOP_Labs", "KOP_Labs\KOP_Labs.csproj", "{08DA15CA-BB7D-4D5D-9BD9-46F0CCC3E779}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "KOP_Labs", "KOP_Labs\KOP_Labs.csproj", "{08DA15CA-BB7D-4D5D-9BD9-46F0CCC3E779}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WinForm", "WinForm\WinForm.csproj", "{099B4BD2-0C5E-46B0-8CE0-4E6BEB3A0E29}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WinForm", "WinForm\WinForm.csproj", "{099B4BD2-0C5E-46B0-8CE0-4E6BEB3A0E29}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DatabaseImplement", "DatabaseImplement\DatabaseImplement.csproj", "{D4DEDE5B-687B-44AD-A69E-70C374E4A62E}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DataModels", "DataModels\DataModels.csproj", "{E0145CE1-A76B-423E-BBC2-00CDF48CCAF2}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Contracts", "Contracts\Contracts.csproj", "{4F141B46-CBC9-455D-8A34-27F950FD62C2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Plugin", "Plugin\Plugin.csproj", "{CAB9F0CF-38F8-4A85-945E-6B271BB3C03B}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -21,6 +29,22 @@ Global
{099B4BD2-0C5E-46B0-8CE0-4E6BEB3A0E29}.Debug|Any CPU.Build.0 = Debug|Any CPU {099B4BD2-0C5E-46B0-8CE0-4E6BEB3A0E29}.Debug|Any CPU.Build.0 = Debug|Any CPU
{099B4BD2-0C5E-46B0-8CE0-4E6BEB3A0E29}.Release|Any CPU.ActiveCfg = Release|Any CPU {099B4BD2-0C5E-46B0-8CE0-4E6BEB3A0E29}.Release|Any CPU.ActiveCfg = Release|Any CPU
{099B4BD2-0C5E-46B0-8CE0-4E6BEB3A0E29}.Release|Any CPU.Build.0 = Release|Any CPU {099B4BD2-0C5E-46B0-8CE0-4E6BEB3A0E29}.Release|Any CPU.Build.0 = Release|Any CPU
{D4DEDE5B-687B-44AD-A69E-70C374E4A62E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D4DEDE5B-687B-44AD-A69E-70C374E4A62E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D4DEDE5B-687B-44AD-A69E-70C374E4A62E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D4DEDE5B-687B-44AD-A69E-70C374E4A62E}.Release|Any CPU.Build.0 = Release|Any CPU
{E0145CE1-A76B-423E-BBC2-00CDF48CCAF2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E0145CE1-A76B-423E-BBC2-00CDF48CCAF2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E0145CE1-A76B-423E-BBC2-00CDF48CCAF2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E0145CE1-A76B-423E-BBC2-00CDF48CCAF2}.Release|Any CPU.Build.0 = Release|Any CPU
{4F141B46-CBC9-455D-8A34-27F950FD62C2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4F141B46-CBC9-455D-8A34-27F950FD62C2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4F141B46-CBC9-455D-8A34-27F950FD62C2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4F141B46-CBC9-455D-8A34-27F950FD62C2}.Release|Any CPU.Build.0 = Release|Any CPU
{CAB9F0CF-38F8-4A85-945E-6B271BB3C03B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CAB9F0CF-38F8-4A85-945E-6B271BB3C03B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CAB9F0CF-38F8-4A85-945E-6B271BB3C03B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CAB9F0CF-38F8-4A85-945E-6B271BB3C03B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

View File

@ -28,45 +28,46 @@
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
groupBoxComponent = new GroupBox();
listBoxComponent = new ListBox(); listBoxComponent = new ListBox();
groupBoxComponent = new GroupBox();
groupBoxComponent.SuspendLayout(); groupBoxComponent.SuspendLayout();
SuspendLayout(); SuspendLayout();
// //
// groupBoxComponent
//
groupBoxComponent.Controls.Add(listBoxComponent);
groupBoxComponent.Location = new Point(19, 28);
groupBoxComponent.Name = "groupBoxComponent";
groupBoxComponent.Size = new Size(517, 183);
groupBoxComponent.TabIndex = 0;
groupBoxComponent.TabStop = false;
groupBoxComponent.Text = "Компонент";
//
// listBoxComponent // listBoxComponent
// //
listBoxComponent.FormattingEnabled = true; listBoxComponent.FormattingEnabled = true;
listBoxComponent.ItemHeight = 20; listBoxComponent.ItemHeight = 20;
listBoxComponent.Location = new Point(24, 35); listBoxComponent.Location = new Point(37, 48);
listBoxComponent.Name = "listBoxComponent"; listBoxComponent.Name = "listBoxComponent";
listBoxComponent.Size = new Size(476, 124); listBoxComponent.Size = new Size(196, 44);
listBoxComponent.TabIndex = 0; listBoxComponent.TabIndex = 0;
listBoxComponent.SelectedIndexChanged += listBoxComponent_SelectedIndexChanged; listBoxComponent.SelectedIndexChanged += listBoxComponent_SelectedIndexChanged;
// //
// groupBoxComponent
//
groupBoxComponent.Controls.Add(listBoxComponent);
groupBoxComponent.Dock = DockStyle.Fill;
groupBoxComponent.Location = new Point(0, 0);
groupBoxComponent.Name = "groupBoxComponent";
groupBoxComponent.Size = new Size(283, 132);
groupBoxComponent.TabIndex = 0;
groupBoxComponent.TabStop = false;
groupBoxComponent.Text = "Компонент";
//
// BooksForm // BooksForm
// //
AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
Controls.Add(groupBoxComponent); Controls.Add(groupBoxComponent);
Name = "BooksForm"; Name = "BooksForm";
Size = new Size(563, 258); Size = new Size(283, 132);
groupBoxComponent.ResumeLayout(false); groupBoxComponent.ResumeLayout(false);
ResumeLayout(false); ResumeLayout(false);
} }
#endregion #endregion
private GroupBox groupBoxComponent;
private ListBox listBoxComponent; private ListBox listBoxComponent;
private GroupBox groupBoxComponent;
} }
} }

View File

@ -63,7 +63,7 @@ namespace KOP_Labs
private void listBoxComponent_SelectedIndexChanged(object sender, EventArgs e) private void listBoxComponent_SelectedIndexChanged(object sender, EventArgs e)
{ {
_selectChanged?.Invoke(this, e); _selectChanged?.Invoke(this, e);
} }
} }
} }

View File

@ -10,7 +10,7 @@ namespace KOP_Labs.Classes
{ {
public string Author { get; private set; } = string.Empty; public string Author { get; private set; } = string.Empty;
public int Id { get; private set; }
public string Name { get; private set; } = string.Empty; public string Name { get; private set; } = string.Empty;
public string Annotation { get; private set; } = string.Empty; public string Annotation { get; private set; } = string.Empty;
@ -20,10 +20,10 @@ namespace KOP_Labs.Classes
{ {
} }
public Book(string author, int id, string name, string annotation) public Book(string author, string name, string annotation)
{ {
Author = author; Author = author;
Id = id;
Name = name; Name = name;
Annotation = annotation; Annotation = annotation;

View File

@ -5,11 +5,14 @@
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms> <UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Aspose.Words" Version="23.10.0" /> <PackageReference Include="Aspose.Words" Version="23.10.0" />
<PackageReference Include="DocumentFormat.OpenXml" Version="2.20.0" /> <PackageReference Include="DocumentFormat.OpenXml" Version="2.20.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.25" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.25" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -34,16 +34,17 @@
// //
// dataGridView // dataGridView
// //
dataGridView.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView.Location = new Point(36, 29); dataGridView.Location = new Point(17, 22);
dataGridView.Name = "dataGridView"; dataGridView.Name = "dataGridView";
dataGridView.RowHeadersVisible = false;
dataGridView.RowHeadersWidth = 51; dataGridView.RowHeadersWidth = 51;
dataGridView.RowTemplate.Height = 29; dataGridView.RowTemplate.Height = 29;
dataGridView.Size = new Size(300, 188); dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dataGridView.Size = new Size(304, 200);
dataGridView.TabIndex = 0; dataGridView.TabIndex = 0;
dataGridView.SelectionChanged += SelectionChanged; dataGridView.SelectionChanged += SelectionChanged;
dataGridView.RowHeadersVisible = false;
dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
// //
// TableComponent // TableComponent
// //
@ -51,7 +52,7 @@
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
Controls.Add(dataGridView); Controls.Add(dataGridView);
Name = "TableComponent"; Name = "TableComponent";
Size = new Size(542, 301); Size = new Size(342, 239);
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
ResumeLayout(false); ResumeLayout(false);
} }

7
Plugin/Class1.cs Normal file
View File

@ -0,0 +1,7 @@
namespace Plugin
{
public class Class1
{
}
}

View File

@ -0,0 +1,65 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Plugin
{
public interface IPluginsConvention
{/*
/// <summary>
/// Название плагина
/// </summary>
string PluginName { get; }
/// <summary>
/// Получение контрола для вывода набора данных
/// </summary>
UserControl GetControl { get; }
/// <summary>
/// Получение элемента, выбранного в контроле
/// </summary>
PluginsConventionElement GetElement { get; }
/// <summary>
/// Получение формы для создания/редактирования объекта
/// </summary>
/// <param name="element"></param>
/// <returns></returns>
Form GetForm(PluginsConventionElement element);
/// <summary>
/// Получение формы для работы со справочником
/// </summary>
/// <returns></returns>
Form GetThesaurus();
/// <summary>
/// Удаление элемента
3
/// </summary>
/// <param name="element"></param>
/// <returns></returns>
bool DeleteElement(PluginsConventionElement element);
/// <summary>
/// Обновление набора данных в контроле
/// </summary>
void ReloadData();
/// <summary>
/// Создание простого документа
/// </summary>
/// <param name="saveDocument"></param>
/// <returns></returns>
bool CreateSimpleDocument(PluginsConventionSaveDocument
saveDocument);
/// <summary>
/// Создание простого документа
/// </summary>
/// <param name="saveDocument"></param>
/// <returns></returns>
bool CreateTableDocument(PluginsConventionSaveDocument saveDocument);
/// <summary>
/// Создание документа с диаграммой
/// </summary>
/// <param name="saveDocument"></param>
/// <returns></returns>
bool CreateChartDocument(PluginsConventionSaveDocument saveDocument);*/
}
}

9
Plugin/Plugin.csproj Normal file
View File

@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Plugin
{
public class PluginsConventionElement
{
public Guid Id { get; set; }
}
}

View File

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Plugin
{
public class PluginsConventionSaveDocument
{
public string FileName { get; set; }
}
}

View File

@ -45,9 +45,9 @@ namespace WinForm
private void buttonTable_Click(object sender, EventArgs e) private void buttonTable_Click(object sender, EventArgs e)
{ {
tableComponent.AddRow(new Book("gfgdf",1, "book1", "lalala")); tableComponent.AddRow(new Book("gfgdf", "book1", "lalala"));
tableComponent.AddRow(new Book("Pushkin", 1, "book2", "lalala2")); tableComponent.AddRow(new Book("Pushkin","book2", "lalala2"));
tableComponent.AddRow(new Book("Pushkin", 1, "book3", "lalala")); tableComponent.AddRow(new Book("Pushkin", "book3", "lalala"));
} }

153
WinForm/FormCreateBook.Designer.cs generated Normal file
View File

@ -0,0 +1,153 @@
namespace WinForm
{
partial class FormCreateBook
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
textBoxReaders = new TextBox();
booksForm1 = new KOP_Labs.BooksForm();
textBoxAnnotation = new TextBox();
label1 = new Label();
label2 = new Label();
label3 = new Label();
label4 = new Label();
buttonSave = new Button();
input_text1 = new ViewComponents.Input_text();
SuspendLayout();
//
// textBoxReaders
//
textBoxReaders.Location = new Point(120, 95);
textBoxReaders.Name = "textBoxReaders";
textBoxReaders.Size = new Size(509, 27);
textBoxReaders.TabIndex = 1;
//
// booksForm1
//
booksForm1.Location = new Point(120, 154);
booksForm1.Name = "booksForm1";
booksForm1.SelectedValue = null;
booksForm1.Size = new Size(509, 111);
booksForm1.TabIndex = 2;
//
// textBoxAnnotation
//
textBoxAnnotation.Location = new Point(105, 345);
textBoxAnnotation.Multiline = true;
textBoxAnnotation.Name = "textBoxAnnotation";
textBoxAnnotation.Size = new Size(509, 138);
textBoxAnnotation.TabIndex = 3;
//
// label1
//
label1.AutoSize = true;
label1.Location = new Point(12, 34);
label1.Name = "label1";
label1.Size = new Size(80, 20);
label1.TabIndex = 4;
label1.Text = "Название:";
//
// label2
//
label2.AutoSize = true;
label2.Location = new Point(12, 95);
label2.Name = "label2";
label2.Size = new Size(76, 20);
label2.TabIndex = 5;
label2.Text = "Читатели:";
//
// label3
//
label3.AutoSize = true;
label3.Location = new Point(16, 192);
label3.Name = "label3";
label3.Size = new Size(60, 20);
label3.TabIndex = 6;
label3.Text = "Форма:";
//
// label4
//
label4.AutoSize = true;
label4.Location = new Point(2, 345);
label4.Name = "label4";
label4.Size = new Size(89, 20);
label4.TabIndex = 7;
label4.Text = "Аннотация:";
//
// buttonSave
//
buttonSave.Location = new Point(535, 489);
buttonSave.Name = "buttonSave";
buttonSave.Size = new Size(94, 29);
buttonSave.TabIndex = 8;
buttonSave.Text = "Сохранить";
buttonSave.UseVisualStyleBackColor = true;
buttonSave.Click += buttonSave_Click_1;
//
// input_text1
//
input_text1.Element = "Range exeption";
input_text1.Location = new Point(105, 2);
input_text1.MaxLen = -1;
input_text1.MinLen = -1;
input_text1.Name = "input_text1";
input_text1.Size = new Size(542, 68);
input_text1.TabIndex = 9;
//
// FormCreateBook
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
AutoSize = true;
ClientSize = new Size(659, 528);
Controls.Add(input_text1);
Controls.Add(buttonSave);
Controls.Add(label4);
Controls.Add(label3);
Controls.Add(label2);
Controls.Add(label1);
Controls.Add(textBoxAnnotation);
Controls.Add(booksForm1);
Controls.Add(textBoxReaders);
Name = "FormCreateBook";
Text = "FormCreateBook";
ResumeLayout(false);
PerformLayout();
}
#endregion
private TextBox textBoxReaders;
private KOP_Labs.BooksForm booksForm1;
private TextBox textBoxAnnotation;
private Label label1;
private Label label2;
private Label label3;
private Label label4;
private Button buttonSave;
private ViewComponents.Input_text input_text1;
}
}

75
WinForm/FormCreateBook.cs Normal file
View File

@ -0,0 +1,75 @@
using Contracts.BindingModels;
using Contracts.StoragesContracts;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WinForm
{
public partial class FormCreateBook : Form
{
public readonly IBookStorage _bookStorage;
public readonly IShapeStorage _shapeStorage;
private int? _id;
public int Id { set { _id = value; } }
public FormCreateBook(IBookStorage bookStorage, IShapeStorage shapeStorage)
{
InitializeComponent();
_bookStorage = bookStorage;
_shapeStorage = shapeStorage;
input_text1.MinLen = 2;
input_text1.MaxLen = 40;
LoadData();
}
private void LoadData()
{
var list = _shapeStorage.GetFullList();
foreach (var item in list)
{
booksForm1.FillValues(item.Name);
}
}
private void buttonSave_Click_1(object sender, EventArgs e)
{
if (String.IsNullOrEmpty(input_text1.Element) || String.IsNullOrEmpty(textBoxReaders.Text) || booksForm1.SelectedValue == null)
{
MessageBox.Show("Заполните поля");
}
else
{
var model = new BookBindingModel
{
Id = _id ?? 0,
Name = input_text1.Element,
Readers = textBoxReaders.Text,
Shape = booksForm1.SelectedValue.ToString(),
Annotation = textBoxAnnotation.Text,
};
if (!_id.HasValue)
{
_bookStorage.Insert(model);
}
else
{
_bookStorage.Update(model);
}
Close();
}
}
}
}

View File

@ -0,0 +1,60 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

162
WinForm/FormMain.Designer.cs generated Normal file
View File

@ -0,0 +1,162 @@
namespace WinForm
{
partial class FormMain
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
listBoxObjects1 = new CustomComponents.ListBoxObjects();
menuStrip1 = new MenuStrip();
добавитьToolStripMenuItem = new ToolStripMenuItem();
изменитьToolStripMenuItem = new ToolStripMenuItem();
удалитьToolStripMenuItem = new ToolStripMenuItem();
справочникToolStripMenuItem = new ToolStripMenuItem();
отчётToolStripMenuItem = new ToolStripMenuItem();
отчёт2ToolStripMenuItem = new ToolStripMenuItem();
отчёт3ToolStripMenuItem = new ToolStripMenuItem();
wordTableComponent1 = new KOP_Labs.NonVisualComponents.WordTableComponent(components);
listBoxObjects2 = new CustomComponents.ListBoxObjects();
componentDocumentWithTableHeaderColumnPdf1 = new ComponentsLibraryNet60.DocumentWithTable.ComponentDocumentWithTableHeaderColumnPdf(components);
pdfTable1 = new ViewComponents.NotVisualComponents.PdfTable(components);
diagramComponent1 = new CustomComponents.DiagramComponent(components);
menuStrip1.SuspendLayout();
SuspendLayout();
//
// listBoxObjects1
//
listBoxObjects1.Location = new Point(0, 31);
listBoxObjects1.Name = "listBoxObjects1";
listBoxObjects1.SelectedIndex = -1;
listBoxObjects1.Size = new Size(459, 151);
listBoxObjects1.TabIndex = 0;
listBoxObjects1.KeyDown += listBoxObjects1_KeyDown;
//
// menuStrip1
//
menuStrip1.ImageScalingSize = new Size(20, 20);
menuStrip1.Items.AddRange(new ToolStripItem[] { добавитьToolStripMenuItem, изменитьToolStripMenuItem, удалитьToolStripMenuItem, справочникToolStripMenuItem, отчётToolStripMenuItem, отчёт2ToolStripMenuItem, отчёт3ToolStripMenuItem });
menuStrip1.Location = new Point(0, 0);
menuStrip1.Name = "menuStrip1";
menuStrip1.Size = new Size(914, 28);
menuStrip1.TabIndex = 1;
menuStrip1.Text = "menuStrip1";
menuStrip1.KeyDown += menuStrip1_KeyDown;
//
// добавитьToolStripMenuItem
//
добавитьToolStripMenuItem.Name = обавитьToolStripMenuItem";
добавитьToolStripMenuItem.Size = new Size(90, 24);
добавитьToolStripMenuItem.Text = "Добавить";
добавитьToolStripMenuItem.Click += CreateToolStripMenuItem_Click;
//
// изменитьToolStripMenuItem
//
изменитьToolStripMenuItem.Name = "изменитьToolStripMenuItem";
изменитьToolStripMenuItem.Size = new Size(92, 24);
изменитьToolStripMenuItem.Text = "Изменить";
изменитьToolStripMenuItem.Click += изменитьToolStripMenuItem_Click;
//
// удалитьToolStripMenuItem
//
удалитьToolStripMenuItem.Name = "удалитьToolStripMenuItem";
удалитьToolStripMenuItem.Size = new Size(79, 24);
удалитьToolStripMenuItem.Text = "Удалить";
удалитьToolStripMenuItem.Click += удалитьToolStripMenuItem_Click;
//
// справочникToolStripMenuItem
//
справочникToolStripMenuItem.Name = "справочникToolStripMenuItem";
справочникToolStripMenuItem.Size = new Size(108, 24);
справочникToolStripMenuItem.Text = "Справочник";
справочникToolStripMenuItem.Click += справочникToolStripMenuItem_Click;
//
// отчётToolStripMenuItem
//
отчётToolStripMenuItem.Name = "отчётToolStripMenuItem";
отчётToolStripMenuItem.Size = new Size(62, 24);
отчётToolStripMenuItem.Text = "Отчёт";
отчётToolStripMenuItem.Click += отчётToolStripMenuItem_Click;
//
// отчёт2ToolStripMenuItem
//
отчёт2ToolStripMenuItem.Name = "отчёт2ToolStripMenuItem";
отчёт2ToolStripMenuItem.Size = new Size(70, 24);
отчёт2ToolStripMenuItem.Text = "Отчёт2";
отчёт2ToolStripMenuItem.Click += отчёт2ToolStripMenuItem_Click;
//
// отчёт3ToolStripMenuItem
//
отчёт3ToolStripMenuItem.Name = "отчёт3ToolStripMenuItem";
отчёт3ToolStripMenuItem.Size = new Size(70, 24);
отчёт3ToolStripMenuItem.Text = "Отчёт3";
отчёт3ToolStripMenuItem.Click += отчёт3ToolStripMenuItem_Click;
//
// listBoxObjects2
//
listBoxObjects2.Location = new Point(455, 31);
listBoxObjects2.Name = "listBoxObjects2";
listBoxObjects2.SelectedIndex = -1;
listBoxObjects2.Size = new Size(572, 195);
listBoxObjects2.TabIndex = 2;
//
// FormMain
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(914, 183);
Controls.Add(listBoxObjects2);
Controls.Add(listBoxObjects1);
Controls.Add(menuStrip1);
KeyPreview = true;
MainMenuStrip = menuStrip1;
Name = "FormMain";
Text = "FormMain";
KeyDown += FormMain_KeyDown;
menuStrip1.ResumeLayout(false);
menuStrip1.PerformLayout();
ResumeLayout(false);
PerformLayout();
}
#endregion
private CustomComponents.ListBoxObjects listBoxObjects1;
private MenuStrip menuStrip1;
private ToolStripMenuItem добавитьToolStripMenuItem;
private ToolStripMenuItem изменитьToolStripMenuItem;
private ToolStripMenuItem удалитьToolStripMenuItem;
private ToolStripMenuItem справочникToolStripMenuItem;
private KOP_Labs.NonVisualComponents.WordTableComponent wordTableComponent1;
private ToolStripMenuItem отчётToolStripMenuItem;
private CustomComponents.ListBoxObjects listBoxObjects2;
private ToolStripMenuItem отчёт2ToolStripMenuItem;
private ComponentsLibraryNet60.DocumentWithTable.ComponentDocumentWithTableHeaderColumnPdf componentDocumentWithTableHeaderColumnPdf1;
private ViewComponents.NotVisualComponents.PdfTable pdfTable1;
private ToolStripMenuItem отчёт3ToolStripMenuItem;
private CustomComponents.DiagramComponent diagramComponent1;
}
}

432
WinForm/FormMain.cs Normal file
View File

@ -0,0 +1,432 @@
using ComponentsLibraryNet60.Models;
using Contracts.BindingModels;
using Contracts.StoragesContracts;
using Contracts.ViewModels;
using CustomComponents;
using DatabaseImplement.Models;
using DataModels.Models;
using DocumentFormat.OpenXml.Drawing.Charts;
using DocumentFormat.OpenXml.Spreadsheet;
using KOP_Labs.Classes;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ViewComponents.NotVisualComponents;
using Book = DatabaseImplement.Models.Book;
namespace WinForm
{
public partial class FormMain : Form
{
private readonly IBookStorage _bookStorage;
private readonly IShapeStorage _shapeStorage;
public FormMain(IBookStorage bookStorage, IShapeStorage shapeStorage)
{
InitializeComponent();
_bookStorage = bookStorage;
_shapeStorage = shapeStorage;
LoadData();
}
public void LoadData()
{
listBoxObjects1.deleteAll();
listBoxObjects2.deleteAll();
var books = _bookStorage.GetFullList();
listBoxObjects1.SetLayoutInfo("Название *Name* Читатели *Readers* Форма *Shape* Аннотация *Annotation* Id *Id*", "*", "*");
listBoxObjects2.SetLayoutInfo("Форма *Shape* Аннотация *Annotation* Id *Id*", "*", "*");
foreach (var book in books)
{
listBoxObjects1.AddInListBox(book);
listBoxObjects2.AddInListBox(book);
}
}
private void CreateToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormCreateBook));
if (service is FormCreateBook form)
{
form.ShowDialog();
LoadData();
}
}
private void изменитьToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
int id = listBoxObjects1.GetObjectFromStr<Book>().Id;
var service = Program.ServiceProvider?.GetService(typeof(FormCreateBook));
if (service is FormCreateBook form)
{
form.Id = id;
form.ShowDialog();
LoadData();
}
}
catch (Exception ex)
{
MessageBox.Show("Ошибка операции", "Необходимо выбрать элемент списка!", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void удалитьToolStripMenuItem_Click(object sender, EventArgs e)
{
int id = listBoxObjects1.GetObjectFromStr<Book>().Id;
DialogResult result = MessageBox.Show("Вы уверены, что хотите удалить выбранную запись?" + id, "Подтверждение удаления", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (result == DialogResult.Yes)
{
_bookStorage.Delete(new BookBindingModel
{
Id = id
});
LoadData();
}
}
private void справочникToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormShapes));
if (service is FormShapes form)
{
form.ShowDialog();
LoadData();
}
}
public void CreateSimpleDocItem_Click(object sender, EventArgs e)
{
//фильтрация файлов для диалогового окна
using var dialog = new SaveFileDialog
{
Filter = "docx|*.docx"
};
if (dialog.ShowDialog() == DialogResult.OK)
{
try
{
var list = _bookStorage.GetFullList().OrderBy(l => l.Shape).ToList();
var disciplines = _shapeStorage.GetFullList().OrderBy(d => d.Name).ToList();
List<string[,]> totalList = new();
List<BookViewModel> supportList = new();
foreach (var discipline in disciplines)
{
foreach (var elem in list)
{
if (elem.Shape.Equals(discipline.Name))
{
supportList.Add(elem);
}
}
supportList = supportList.OrderBy(sl => sl.Name).ToList();
totalList.Add(new string[,] { { "Форма", discipline.Name } });
foreach (var elem in supportList)
{
var listFCs = elem.Readers.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList();
string[,] newArray = { { elem.Name, listFCs[listFCs.Count - 1] } };
totalList.Add(newArray);
}
supportList.Clear();
}
MyTable table = new(dialog.FileName, "Первое задание", totalList);
wordTableComponent1.CreateDoc(table);
MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void отчётToolStripMenuItem_Click(object sender, EventArgs e)
{
CreateSimpleDocItem_Click(sender, e);
}
private void отчёт2ToolStripMenuItem_Click(object sender, EventArgs e)
{
List<BookViewModel>? list = _bookStorage.GetFullList().OrderBy(l => l.Name).ToList();
using var dialog = new SaveFileDialog
{
Filter = "pdf|*.pdf"
};
if (dialog.ShowDialog() == DialogResult.OK)
{
try
{
componentDocumentWithTableHeaderColumnPdf1.CreateDoc(new ComponentDocumentWithTableHeaderDataConfig<BookViewModel>
{
FilePath = dialog.FileName,
Header = "Отчет PDF",
UseUnion = true,
ColumnsRowsWidth = new List<(int, int)> { (0, 25), (0, 25), (0, 25), },
ColumnUnion = new List<(int StartIndex, int Count)> { (1, 2) },
Headers = new List<(int ColumnIndex, int RowIndex, string Header, string PropertyName)>
{
(0, 0, "Название", "Name"),
(1, 0, "Описание", ""),
(1, 1, "Форма", "Shape"),
(2, 1, "Аннотация", "Annotation"),
},
Data = list
});
MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void CreateReportExcel(object sender, EventArgs e)
{
using var dialog = new SaveFileDialog
{
Filter = "xlsx|*.xlsx"
};
if (dialog.ShowDialog() == DialogResult.OK)
{
try
{
var list = _bookStorage.GetFullList();
var shapes = _shapeStorage.GetFullList();
int[,] supportList = new int[4, shapes.Count];
int c = 0;
for (int i = 0; i < shapes.Count; i++)
{
foreach (var elem in list)
{
if (shapes[i].Name.Equals(elem.Shape))
{
c++;
if (elem.Annotation.Length >= 0 && elem.Annotation.Length < 10)
{
supportList[0, i]++;
}
if (elem.Annotation.Length >= 10 && elem.Annotation.Length < 150)
{
supportList[1, i]++;
}
if (elem.Annotation.Length >= 150 && elem.Annotation.Length < 200)
{
supportList[2, i]++;
}
if (elem.Annotation.Length >= 200 && elem.Annotation.Length < 250)
{
supportList[3, i]++;
}
}
}
}
string[] Names = { "50-150", "100-150", "150-200", "200-250" };
var list2D = new Dictionary<string, List<int>>();
for (var i = 0; i < Names.Length; i++)
{
var curlist = new List<int>();
for (int j = 0; j < shapes.Count; j++)
{
curlist.Add(supportList[i, j]);
}
list2D.Add(Names[i], curlist);
}
DiagramComponent diagram = new DiagramComponent();
diagram.CreateExcel(new CustomComponents.MyNonVisualComponents.LineChartConfig
{
ChartTitle = "diagramm",
FilePath = dialog.FileName,
Header = "Diagramm",
Values = list2D
});
MessageBox.Show(" " + c);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void отчёт3ToolStripMenuItem_Click(object sender, EventArgs e)
{
CreateReportExcel(sender, e);
}
private void FormMain_KeyDown(object sender, KeyEventArgs e)
{
if (e.Control)
{
switch (e.KeyCode)
{
case Keys.A:
CreateToolStripMenuItem_Click(sender, e);
break;
case Keys.U:
изменитьToolStripMenuItem_Click(sender, e);
break;
case Keys.D:
удалитьToolStripMenuItem_Click(sender, e);
break;
case Keys.S:
справочникToolStripMenuItem_Click(sender, e);
break;
case Keys.T:
отчётToolStripMenuItem_Click(sender, e);
break;
case Keys.C:
отчёт2ToolStripMenuItem_Click(sender, e);
break;
case Keys.M:
отчёт3ToolStripMenuItem_Click(sender, e);
break;
}
}
}
private void listBoxObjects1_KeyDown(object sender, KeyEventArgs e)
{
if (e.Control)
{
switch (e.KeyCode)
{
case Keys.A:
CreateToolStripMenuItem_Click(sender, e);
break;
/*case Keys.U:
EditProviderItem_Click(sender, e);
break;
case Keys.D:
RemoveProviderItem_Click(sender, e);
break;
case Keys.S:
GetSimpleDocumentItem_Click(sender, e);
break;
case Keys.T:
GetTableDocumentItem_Click(sender, e);
break;
case Keys.C:
GetDiagramDocumentItem_Click(sender, e);
break;
case Keys.M:
OpenListToolStripMenuItem_Click(sender, e);
break;*/
}
}
}
private void menuStrip1_KeyDown(object sender, KeyEventArgs e)
{
if (e.Control)
{
switch (e.KeyCode)
{
case Keys.A:
CreateToolStripMenuItem_Click(sender, e);
break;
/*case Keys.U:
EditProviderItem_Click(sender, e);
break;
case Keys.D:
RemoveProviderItem_Click(sender, e);
break;
case Keys.S:
GetSimpleDocumentItem_Click(sender, e);
break;
case Keys.T:
GetTableDocumentItem_Click(sender, e);
break;
case Keys.C:
GetDiagramDocumentItem_Click(sender, e);
break;
case Keys.M:
OpenListToolStripMenuItem_Click(sender, e);
break;*/
}
}
}
}
}

75
WinForm/FormMain.resx Normal file
View File

@ -0,0 +1,75 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="menuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="wordTableComponent1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>152, 17</value>
</metadata>
<metadata name="componentDocumentWithTableHeaderColumnPdf1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>365, 17</value>
</metadata>
<metadata name="pdfTable1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>770, 17</value>
</metadata>
<metadata name="diagramComponent1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>891, 17</value>
</metadata>
</root>

64
WinForm/FormShapes.Designer.cs generated Normal file
View File

@ -0,0 +1,64 @@
namespace WinForm
{
partial class FormShapes
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
dataGridView1 = new DataGridView();
((System.ComponentModel.ISupportInitialize)dataGridView1).BeginInit();
SuspendLayout();
//
// dataGridView1
//
dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView1.Dock = DockStyle.Fill;
dataGridView1.Location = new Point(0, 0);
dataGridView1.Name = "dataGridView1";
dataGridView1.RowHeadersWidth = 51;
dataGridView1.RowTemplate.Height = 29;
dataGridView1.Size = new Size(800, 450);
dataGridView1.TabIndex = 0;
dataGridView1.CellValueChanged += dataGridView1_CellValueChanged;
dataGridView1.KeyDown += dataGridView1_KeyDown;
//
// FormShapes
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 450);
Controls.Add(dataGridView1);
Name = "FormShapes";
Text = "FormShapes";
((System.ComponentModel.ISupportInitialize)dataGridView1).EndInit();
ResumeLayout(false);
}
#endregion
private DataGridView dataGridView1;
}
}

148
WinForm/FormShapes.cs Normal file
View File

@ -0,0 +1,148 @@
using Contracts.BindingModels;
using Contracts.SearchModels;
using Contracts.StoragesContracts;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WinForm
{
public partial class FormShapes : Form
{
IShapeStorage _shapeStorage;
public FormShapes(IShapeStorage shapeStorage)
{
_shapeStorage = shapeStorage;
InitializeComponent();
LoadData();
}
private void LoadData()
{
try
{
var list = _shapeStorage.GetFullList();
if (list != null)
{
dataGridView1.DataSource = list;
dataGridView1.Columns["Id"].Visible = false;
dataGridView1.Columns["Name"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void AddShape()
{
var list = _shapeStorage.GetFullList();
list.Add(new());
if (list != null)
{
dataGridView1.DataSource = list;
dataGridView1.Columns["Id"].Visible = false;
dataGridView1.Columns["Name"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
}
private void dataGridView1_KeyDown(object sender, KeyEventArgs e)
{
//просто найти кнопку
if (e.Control)
{
if (e.KeyCode == Keys.Delete)
{
AddShape();
}
}
else if (e.KeyCode == Keys.Delete)
{
RemoveShape();
}
}
private void RemoveShape()
{
if (dataGridView1.SelectedRows.Count > 0)
{
DialogResult result = MessageBox.Show(
"Вы уверены, что хотите удалить выбранные записи?",
"Подтверждение удаления",
MessageBoxButtons.YesNo,
MessageBoxIcon.Question
);
if (result == DialogResult.Yes)
{
if (MessageBox.Show("Удалить выбранный элемент", "Удаление",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
_shapeStorage.Delete(new ShapeBindingModel() { Id = (int)dataGridView1.CurrentRow.Cells[1].Value });
LoadData();
}
}
LoadData();
}
else
{
MessageBox.Show("Выберите");
}
}
private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex >= 0)
{
DataGridViewRow row = dataGridView1.Rows[e.RowIndex];
int id = Convert.ToInt32(row.Cells["Id"].Value);
string? name = row.Cells["Name"].Value?.ToString();
if (string.IsNullOrWhiteSpace(name))
{
MessageBox.Show("Нельзя сохранить запись с пустым именем!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
LoadData();
}
else
{
var model = new ShapeBindingModel
{
Id = id,
Name = name
};
if (model.Id == 0)
{
_shapeStorage.Insert(model);
}
else
{
_shapeStorage.Update(model);
}
LoadData();
}
}
}
}
}

60
WinForm/FormShapes.resx Normal file
View File

@ -0,0 +1,60 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -91,12 +91,12 @@ namespace WinForm
} }
List<Book> books; List<Book> books;
Book book1 = new Book("Pushkin", 1, "fgsddsdf", "fdsds"); Book book1 = new Book("Pushkin", "fgsddsdf", "fdsds");
Book book2 = new Book("Pushkin", 2, "aa", "fdads"); Book book2 = new Book("Pushkin", "aa", "fdads");
Book book3 = new Book("Pushkin", 3, "fgdf", "ffsds"); Book book3 = new Book("Pushkin", "fgdf", "ffsds");
Book book4 = new Book("Lermontov", 4, "ffsssff", "asdss"); Book book4 = new Book("Lermontov", "ffsssff", "asdss");
Book book5 = new Book("Lermontov", 5, "ffdsff", "asdsss"); Book book5 = new Book("Lermontov", "ffdsff", "asdsss");
Book book6 = new Book("Pushkin", 6, "fgdf", "ffsds"); Book book6 = new Book("Pushkin", "fgdf", "ffsds");
Dictionary<int, ColumnParameters> colData; Dictionary<int, ColumnParameters> colData;
private void buttonHead_Click(object sender, EventArgs e) private void buttonHead_Click(object sender, EventArgs e)

View File

@ -1,7 +1,16 @@
using Contracts.StoragesContracts;
using DatabaseImplement.Implements;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
namespace WinForm namespace WinForm
{ {
internal static class Program internal static class Program
{ {
private static ServiceProvider? _serviceProvider;
public static ServiceProvider? ServiceProvider => _serviceProvider;
/// <summary> /// <summary>
/// The main entry point for the application. /// The main entry point for the application.
/// </summary> /// </summary>
@ -11,7 +20,21 @@ namespace WinForm
// To customize application configuration such as set high DPI settings or default font, // To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration. // see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize(); ApplicationConfiguration.Initialize();
Application.Run(new NonVisualForm()); var services = new ServiceCollection();
ConfigureServices(services);
_serviceProvider = services.BuildServiceProvider();
Application.Run(_serviceProvider.GetRequiredService<FormMain>());
}
private static void ConfigureServices(ServiceCollection services)
{
services.AddTransient<IBookStorage, BookStorage>();
services.AddTransient<IShapeStorage, ShapeStorage>();
services.AddTransient<NonVisualForm>();
services.AddTransient<FormMain>();
services.AddTransient<FormCreateBook>();
services.AddTransient<FormShapes>();
} }
} }
} }

View File

@ -9,10 +9,21 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="ComponentsLibraryNet60" Version="1.0.0" />
<PackageReference Include="ControlsLibraryNet60" Version="1.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.25">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.1" />
<PackageReference Include="Microsoft.Office.Interop.Word" Version="15.0.4797.1004" /> <PackageReference Include="Microsoft.Office.Interop.Word" Version="15.0.4797.1004" />
<PackageReference Include="SergComponent" Version="1.0.0" />
<PackageReference Include="ViewComponents" Version="1.0.0" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\DatabaseImplement\DatabaseImplement.csproj" />
<ProjectReference Include="..\KOP_Labs\KOP_Labs.csproj" /> <ProjectReference Include="..\KOP_Labs\KOP_Labs.csproj" />
</ItemGroup> </ItemGroup>