4 Commits
lab1 ... lab2

54 changed files with 1789 additions and 4 deletions

View File

@@ -0,0 +1,65 @@
using Contracts.BindingModels;
using Contracts.BusinessLogicContracts;
using Contracts.StorageContracts;
using Contracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BusinessLogic
{
public class AuthorLogic:IAuthorLogic
{
private readonly IAuthorStorage _authorStorage;
public AuthorLogic(IAuthorStorage authorStorage)
{
_authorStorage = authorStorage;
}
public void CreateOrUpdate(AuthorBindingModel model)
{
var element = _authorStorage.GetElement(
new AuthorBindingModel
{
FIO = model.FIO
});
if (element != null && element.Id != model.Id)
{
throw new Exception("Такой автор уже существует");
}
if (model.Id.HasValue)
{
_authorStorage.Update(model);
}
else
{
_authorStorage.Insert(model);
}
}
public void Delete(AuthorBindingModel model)
{
var element = _authorStorage.GetElement(new AuthorBindingModel { Id = model.Id });
if (element == null)
{
throw new Exception("Автор не найден");
}
_authorStorage.Delete(model);
}
public List<AuthorViewModel> Read(AuthorBindingModel model)
{
if (model == null)
{
return _authorStorage.GetFullList();
}
if (model.Id.HasValue)
{
return new List<AuthorViewModel> { _authorStorage.GetElement(model) };
}
return _authorStorage.GetFilteredList(model);
}
}
}

View File

@@ -0,0 +1,67 @@
using Contracts.BindingModels;
using Contracts.BusinessLogicContracts;
using Contracts.StorageContracts;
using Contracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BusinessLogic
{
public class BookLogic : IBookLogic
{
private readonly IBookStorage _bookStorage;
public BookLogic(IBookStorage bookStorage)
{
_bookStorage = bookStorage;
}
public void CreateOrUpdate(BookBindingModel model)
{
var element = _bookStorage.GetElement(
new BookBindingModel
{
Name = model.Name,
Author = model.Author,
PicturePath = model.PicturePath,
PublicationDate = model.PublicationDate
});
if (element != null && element.Id != model.Id)
{
throw new Exception("Книга с таким названием уже существует");
}
if (model.Id.HasValue)
{
_bookStorage.Update(model);
}
else
{
_bookStorage.Insert(model);
}
}
public void Delete(BookBindingModel model)
{
var element = _bookStorage.GetElement(new BookBindingModel { Id = model.Id });
if (element == null)
{
throw new Exception("Книга не найдена");
}
_bookStorage.Delete(model);
}
public List<BookViewModel> Read(BookBindingModel model)
{
if (model == null)
{
return _bookStorage.GetFullList();
}
if (model.Id.HasValue)
{
return new List<BookViewModel> { _bookStorage.GetElement(model) };
}
return _bookStorage.GetFilteredList(model);
}
}
}

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="..\Contracts\Contracts.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.BindingModels
{
public class AuthorBindingModel
{
public int? Id { get; set; }
public string FIO { get; set; } = string.Empty;
}
}

View File

@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Contracts.BindingModels
{
public class BookBindingModel
{
public int? Id { get; set; }
public string Name { get; set; } = string.Empty;
public string PicturePath { get; set; } = string.Empty;
public string Author { get; set; } = string.Empty;
public DateTime PublicationDate { get; set; }
}
}

View File

@@ -0,0 +1,17 @@
using Contracts.BindingModels;
using Contracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Contracts.BusinessLogicContracts
{
public interface IAuthorLogic
{
List<AuthorViewModel> Read(AuthorBindingModel model);
void CreateOrUpdate(AuthorBindingModel model);
void Delete(AuthorBindingModel model);
}
}

View File

@@ -0,0 +1,17 @@
using Contracts.BindingModels;
using Contracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Contracts.BusinessLogicContracts
{
public interface IBookLogic
{
List<BookViewModel> Read(BookBindingModel model);
void CreateOrUpdate(BookBindingModel model);
void Delete(BookBindingModel model);
}
}

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,21 @@
using Contracts.BindingModels;
using Contracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Contracts.StorageContracts
{
public interface IAuthorStorage
{
List<AuthorViewModel> GetFullList();
List<AuthorViewModel> GetFilteredList(AuthorBindingModel model);
AuthorViewModel GetElement(AuthorBindingModel model);
void Insert(AuthorBindingModel model);
void Update(AuthorBindingModel model);
void Delete(AuthorBindingModel model);
}
}

View File

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

View File

@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Contracts.ViewModels
{
public class AuthorViewModel
{
public int? Id { get; set; }
[DisplayName("Имя Автора")]
public string FIO { get; set; } = string.Empty;
}
}

View File

@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Contracts.ViewModels
{
public class BookViewModel {
public int? Id { get; set; }
[DisplayName("Название")]
public string Name { get; set; } = string.Empty;
[DisplayName("Автор")]
public string Author { get; set; } = string.Empty;
[DisplayName("Дата публикации")]
public DateTime PublicationDate { get; set; }
}
}

View File

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

View File

@@ -0,0 +1,120 @@
using Contracts.BindingModels;
using Contracts.StorageContracts;
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 AuthorStorage:IAuthorStorage
{
public void Delete(AuthorBindingModel model)
{
var context = new LibraryDatabase();
var author = context.Authors.FirstOrDefault(rec => rec.Id == model.Id);
if (author != null)
{
context.Authors.Remove(author);
context.SaveChanges();
}
else
{
throw new Exception("Автор не найден");
}
}
public AuthorViewModel GetElement(AuthorBindingModel model)
{
if (model == null)
{
return null;
}
using var context = new LibraryDatabase();
var author = context.Authors
.ToList()
.FirstOrDefault(rec => rec.Id == model.Id || rec.FIO == model.FIO);
return author != null ? CreateModel(author) : null;
}
public List<AuthorViewModel> GetFilteredList(AuthorBindingModel model)
{
if (model == null)
{
return null;
}
using var context = new LibraryDatabase();
return context.Authors
.Where(rec => rec.FIO.Contains(model.FIO))
.Select(CreateModel)
.ToList();
}
public List<AuthorViewModel> GetFullList()
{
using var context = new LibraryDatabase();
return context.Authors
.Select(CreateModel)
.ToList();
}
public void Insert(AuthorBindingModel model)
{
var context = new LibraryDatabase();
var transaction = context.Database.BeginTransaction();
try
{
context.Authors.Add(CreateModel(model, new Author()));
context.SaveChanges();
transaction.Commit();
}
catch
{
transaction.Rollback();
throw;
}
}
public void Update(AuthorBindingModel model)
{
var context = new LibraryDatabase();
var transaction = context.Database.BeginTransaction();
try
{
var author = context.Authors.FirstOrDefault(rec => rec.Id == model.Id);
if (author == null)
{
throw new Exception("Автор не найден");
}
CreateModel(model, author);
context.SaveChanges();
transaction.Commit();
}
catch
{
transaction.Rollback();
throw;
}
}
private static Author CreateModel(AuthorBindingModel model, Author author)
{
author.FIO = model.FIO;
return author;
}
private static AuthorViewModel CreateModel(Author author)
{
return new AuthorViewModel
{
Id = author.Id,
FIO = author.FIO
};
}
}
}

View File

@@ -0,0 +1,124 @@
using Contracts.BindingModels;
using Contracts.StorageContracts;
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 BookStorage:IBookStorage
{
public void Delete(BookBindingModel model)
{
var context = new LibraryDatabase();
var book = context.Books.FirstOrDefault(rec => rec.Id == model.Id);
if (book != null)
{
context.Books.Remove(book);
context.SaveChanges();
}
else
{
throw new Exception("Книга не найдена");
}
}
public BookViewModel GetElement(BookBindingModel model)
{
if (model == null)
{
return null;
}
using var context = new LibraryDatabase();
var book = context.Books
.ToList()
.FirstOrDefault(rec => rec.Id == model.Id);
return book != null ? CreateModel(book) : null;
}
public List<BookViewModel> GetFilteredList(BookBindingModel model)
{
var context = new LibraryDatabase();
return context.Books
.Where(book => book.Name.Contains(model.Name) && book.Author.Contains(model.Author))
.ToList()
.Select(CreateModel)
.ToList();
}
public List<BookViewModel> GetFullList()
{
using (var context = new LibraryDatabase())
{
return context.Books
.ToList()
.Select(CreateModel)
.ToList();
}
}
public void Insert(BookBindingModel model)
{
var context = new LibraryDatabase();
var transaction = context.Database.BeginTransaction();
try
{
context.Books.Add(CreateModel(model, new Book()));
context.SaveChanges();
transaction.Commit();
}
catch
{
transaction.Rollback();
throw;
}
}
public void Update(BookBindingModel model)
{
var context = new LibraryDatabase();
var transaction = context.Database.BeginTransaction();
try
{
var book = context.Books.FirstOrDefault(rec => rec.Id == model.Id);
if (book == null)
{
throw new Exception("Книга не найдена");
}
CreateModel(model, book);
context.SaveChanges();
transaction.Commit();
}
catch
{
transaction.Rollback();
throw;
}
}
private static Book CreateModel(BookBindingModel model, Book book)
{
book.Name = model.Name;
book.PublicationDate = model.PublicationDate;
book.PicturePath = model.PicturePath;
book.Author = model.Author;
return book;
}
private BookViewModel CreateModel(Book book)
{
return new BookViewModel
{
Id = book.Id,
Name = book.Name,
Author = book.Author,
PublicationDate = book.PublicationDate
};
}
}
}

View File

@@ -0,0 +1,28 @@
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 LibraryDatabase:DbContext
{
protected override void OnConfiguring(DbContextOptionsBuilder
optionsBuilder)
{
if (optionsBuilder.IsConfigured == false)
{
optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-7A1PHA0\SQLEXPRESS;
Initial Catalog=LibraryDatabase;
Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
}
base.OnConfiguring(optionsBuilder);
}
public virtual DbSet<Book> Books { set; get; }
public virtual DbSet<Author> Authors { set; get; }
}
}

View File

@@ -0,0 +1,75 @@
// <auto-generated />
using System;
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(LibraryDatabase))]
[Migration("20231116173444_InitialCreate")]
partial class InitialCreate
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.4")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
modelBuilder.Entity("DatabaseImplement.Models.Author", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("FIO")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Authors");
});
modelBuilder.Entity("DatabaseImplement.Models.Book", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Author")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("PicturePath")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<DateTime>("PublicationDate")
.HasColumnType("datetime2");
b.HasKey("Id");
b.ToTable("Books");
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -0,0 +1,54 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace DatabaseImplement.Migrations
{
/// <inheritdoc />
public partial class InitialCreate : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Authors",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
FIO = table.Column<string>(type: "nvarchar(max)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Authors", x => x.Id);
});
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),
PicturePath = table.Column<string>(type: "nvarchar(max)", nullable: false),
Author = table.Column<string>(type: "nvarchar(max)", nullable: false),
PublicationDate = table.Column<DateTime>(type: "datetime2", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Books", x => x.Id);
});
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Authors");
migrationBuilder.DropTable(
name: "Books");
}
}
}

View File

@@ -0,0 +1,72 @@
// <auto-generated />
using System;
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(LibraryDatabase))]
partial class LibraryDatabaseModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.4")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
modelBuilder.Entity("DatabaseImplement.Models.Author", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("FIO")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Authors");
});
modelBuilder.Entity("DatabaseImplement.Models.Book", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Author")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("PicturePath")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<DateTime>("PublicationDate")
.HasColumnType("datetime2");
b.HasKey("Id");
b.ToTable("Books");
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DatabaseImplement.Models
{
public class Author
{
public int Id { get; set; }
[Required]
public string FIO { get; set; }
}
}

View File

@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DatabaseImplement.Models
{
public class Book
{
public int Id { get; set; }
[Required]
public string Name { get; set; }
[Required]
public string PicturePath { get; set; }
[Required]
public string Author { get; set; }
[Required]
public DateTime PublicationDate { get; set; }
}
}

39
Library/FormMain.Designer.cs generated Normal file
View File

@@ -0,0 +1,39 @@
namespace Library
{
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()
{
this.components = new System.ComponentModel.Container();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Text = "Form1";
}
#endregion
}
}

10
Library/FormMain.cs Normal file
View File

@@ -0,0 +1,10 @@
namespace Library
{
public partial class FormMain : Form
{
public FormMain()
{
InitializeComponent();
}
}
}

120
Library/FormMain.resx Normal file
View File

@@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<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>

29
Library/Library.csproj Normal file
View File

@@ -0,0 +1,29 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CustomComponents" Version="1.0.0" />
<PackageReference Include="KOP_Labs" Version="1.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="PDFsharp-MigraDoc" Version="1.50.5147" />
<PackageReference Include="System.Text.Encoding.CodePages" Version="7.0.0" />
<PackageReference Include="ViewComponents" Version="1.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\BusinessLogic\BusinessLogic.csproj" />
<ProjectReference Include="..\Contracts\Contracts.csproj" />
<ProjectReference Include="..\DatabaseImplement\DatabaseImplement.csproj" />
</ItemGroup>
</Project>

17
Library/Program.cs Normal file
View File

@@ -0,0 +1,17 @@
namespace Library
{
internal static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
Application.Run(new FormMain());
}
}
}

26
TestView/BookInfo.cs Normal file
View File

@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TestView
{
public class BookInfo
{
public string Redaction;
public string AuthorName;
public string AuthorSurname;
public string AuthorLife;
public string Title;
public BookInfo(string Redaction, string AuthorName, string AuthorSurname, string AuthorLife, string Title)
{
this.Redaction = Redaction;
this.AuthorName = AuthorName;
this.AuthorSurname = AuthorSurname;
this.AuthorLife = AuthorLife;
this.Title = Title;
}
}
}

View File

@@ -28,6 +28,7 @@
/// </summary>
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
buttonAdd = new Button();
buttonClear = new Button();
buttonSelect = new Button();
@@ -42,6 +43,13 @@
buttonGetIndex = new Button();
buttonSetIndex = new Button();
myTreeView = new ViewComponents.MyTreeView();
buttonPdfImages = new Button();
pdfImages1 = new ViewComponents.NotVisualComponents.PdfImages(components);
openFileDialog1 = new OpenFileDialog();
pdfTable1 = new ViewComponents.NotVisualComponents.PdfTable(components);
buttonTestPdfTable = new Button();
pieChartpdf1 = new ViewComponents.NotVisualComponents.PieChartPDF(components);
buttonChart = new Button();
SuspendLayout();
//
// buttonAdd
@@ -85,7 +93,10 @@
//
// input_text
//
input_text.Element = "Range exeption";
input_text.Location = new Point(312, 12);
input_text.MaxLen = -1;
input_text.MinLen = -1;
input_text.Name = "input_text";
input_text.Size = new Size(240, 119);
input_text.TabIndex = 5;
@@ -179,11 +190,49 @@
myTreeView.Size = new Size(226, 204);
myTreeView.TabIndex = 8;
//
// buttonPdfImages
//
buttonPdfImages.Location = new Point(25, 434);
buttonPdfImages.Name = "buttonPdfImages";
buttonPdfImages.Size = new Size(197, 29);
buttonPdfImages.TabIndex = 15;
buttonPdfImages.Text = "Загрузить изображения";
buttonPdfImages.UseVisualStyleBackColor = true;
buttonPdfImages.Click += buttonPdfImages_Click;
//
// openFileDialog1
//
openFileDialog1.FileName = "openFileDialog1";
openFileDialog1.Multiselect = true;
//
// buttonTestPdfTable
//
buttonTestPdfTable.Location = new Point(282, 434);
buttonTestPdfTable.Name = "buttonTestPdfTable";
buttonTestPdfTable.Size = new Size(179, 29);
buttonTestPdfTable.TabIndex = 16;
buttonTestPdfTable.Text = "Создать таблицу";
buttonTestPdfTable.UseVisualStyleBackColor = true;
buttonTestPdfTable.Click += buttonTestPdfTable_Click;
//
// buttonChart
//
buttonChart.Location = new Point(534, 434);
buttonChart.Name = "buttonChart";
buttonChart.Size = new Size(171, 29);
buttonChart.TabIndex = 17;
buttonChart.Text = "Создать диаграмму";
buttonChart.UseVisualStyleBackColor = true;
buttonChart.Click += buttonChart_Click;
//
// Form1
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(909, 450);
ClientSize = new Size(899, 600);
Controls.Add(buttonChart);
Controls.Add(buttonTestPdfTable);
Controls.Add(buttonPdfImages);
Controls.Add(myTreeView);
Controls.Add(buttonSetIndex);
Controls.Add(buttonGetIndex);
@@ -220,5 +269,12 @@
private Button buttonGetIndex;
private Button buttonSetIndex;
private ViewComponents.MyTreeView myTreeView;
private Button buttonPdfImages;
private ViewComponents.NotVisualComponents.PdfImages pdfImages1;
private OpenFileDialog openFileDialog1;
private ViewComponents.NotVisualComponents.PdfTable pdfTable1;
private Button buttonTestPdfTable;
private ViewComponents.NotVisualComponents.PieChartPDF pieChartpdf1;
private Button buttonChart;
}
}

View File

@@ -1,4 +1,8 @@
using MigraDoc.DocumentObjectModel;
using System.IO;
using System.Windows.Forms;
using ViewComponents.Exeption;
using ViewComponents.NotVisualComponents;
namespace TestView
{
@@ -59,7 +63,7 @@ namespace TestView
throw new TextBoundsNotSetExeption("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD>");
if (input_text.Element.Equals("Value exeption"))
throw new TextOutOfBoundsExeption("<22><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
MessageBox.Show(input_text.Element, "<22><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
}
catch (TextBoundsNotSetExeption ex)
@@ -80,7 +84,7 @@ namespace TestView
private void buttonAddBook_Click(object sender, EventArgs e)
{
myTreeView.addItem(new Book("<22><><EFBFBD><EFBFBD><EFBFBD>", "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>.<2E>.", <><CCB8><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>"));
myTreeView.addItem(new Book("<22><><EFBFBD><EFBFBD><EFBFBD>", "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>.<2E>.", "<22><><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD>"));
myTreeView.addItem(new Book("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", "1984"));
@@ -108,5 +112,57 @@ namespace TestView
{
}
private void buttonPdfImages_Click(object sender, EventArgs e)
{
var res = openFileDialog1.ShowDialog(this);
if (res != DialogResult.OK) return;
var files = openFileDialog1.FileNames;
openFileDialog1.Dispose();
string path = "C:\\Users\\xarla\\OneDrive\\<5C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\\test.pdf";
MessageBox.Show(path);
if (pdfImages1.CreatePdfDoc(new ImagesForPDF(path, "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", files))) MessageBox.Show("<22><><EFBFBD><EFBFBD><EFBFBD>!");
else MessageBox.Show("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
}
private void buttonTestPdfTable_Click(object sender, EventArgs e)
{
List<BookInfo> books = new List<BookInfo>
{
new BookInfo("<22><><EFBFBD><EFBFBD><EFBFBD>", "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", "1809-1852", <><CCB8><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>"),
new BookInfo("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", "<22><><EFBFBD><EFBFBD>", "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", "1818-1883", "<22><><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD>"),
new BookInfo("<22><><EFBFBD><EFBFBD><EFBFBD>", "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", "1903-1950", "1984"),
new BookInfo("<22><><EFBFBD>", "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", "1965 - <20>.<2E>.", "<22><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>")
};
List<(int, int)> merges = new List<(int, int)>();
merges.Add((2, 4));
List<int> heights = new List<int> { 10, 40, 60, 20, 25, 15, 20 };
string path = "C:\\Users\\xarla\\OneDrive\\<5C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\\test.pdf";
List<(string, string)> headers = new List<(string, string)> { ("id", "Id"), ("Redaction", "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"),
("", "<22><><EFBFBD><EFBFBD><EFBFBD>"), ("AuthorName", "<22><><EFBFBD>"),
("AuthorSurname", "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"), ("AuthorLife", "<22><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>"),
("Title", "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>") };
if (pdfTable1.createTable(new DataForPDFTable<BookInfo>(path, "test2", heights, merges, headers, books))) MessageBox.Show("<22><><EFBFBD><EFBFBD><EFBFBD>");
}
private void buttonChart_Click(object sender, EventArgs e)
{
string path = "C:\\Users\\xarla\\OneDrive\\<5C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\\chart.pdf";
List<(double, string)> elements = new List<(double, string)>
{
(200, <><CCB8><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>"),
(157, "<22><><EFBFBD><EFBFBD>"),
(344, "<22><><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD>"),
(588, "<22><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"),
(286, "<22><><EFBFBD><EFBFBD><EFBFBD> 2033")
};
if(pieChartpdf1.CreatePieChart(new DataForPDFPieChart(path, "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", DiagramLegendEnum.Top ,"<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>", elements))) MessageBox.Show("<22><><EFBFBD><EFBFBD><EFBFBD>");
}
}
}

View File

@@ -57,4 +57,16 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="pdfImages1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="openFileDialog1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>150, 17</value>
</metadata>
<metadata name="pdfTable1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>317, 17</value>
</metadata>
<metadata name="pieChartpdf1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>438, 17</value>
</metadata>
</root>

View File

@@ -10,6 +10,15 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="System.Text.Encoding.CodePages" Version="7.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\DatabaseImplement\DatabaseImplement.csproj" />
<ProjectReference Include="..\ViewComponents\ViewComponents.csproj" />
</ItemGroup>

View File

@@ -7,6 +7,14 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestView", "TestView.csproj
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ViewComponents", "..\ViewComponents\ViewComponents.csproj", "{45A652EE-B79B-4F5B-BB2A-2A51F5BEA2F1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Contracts", "..\Contracts\Contracts.csproj", "{088EE607-4CC2-4F8D-8571-BA09A4A6A4B5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BusinessLogic", "..\BusinessLogic\BusinessLogic.csproj", "{84504BF2-6F50-435D-B6D4-6A06D48331A0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DatabaseImplement", "..\DatabaseImplement\DatabaseImplement.csproj", "{D9EA1B1E-A8A9-4C13-BFC9-579832B878BF}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Library", "..\Library\Library.csproj", "{B74E170A-9AB6-4A1A-9125-42B479DBFBF4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -21,6 +29,22 @@ Global
{45A652EE-B79B-4F5B-BB2A-2A51F5BEA2F1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{45A652EE-B79B-4F5B-BB2A-2A51F5BEA2F1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{45A652EE-B79B-4F5B-BB2A-2A51F5BEA2F1}.Release|Any CPU.Build.0 = Release|Any CPU
{088EE607-4CC2-4F8D-8571-BA09A4A6A4B5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{088EE607-4CC2-4F8D-8571-BA09A4A6A4B5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{088EE607-4CC2-4F8D-8571-BA09A4A6A4B5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{088EE607-4CC2-4F8D-8571-BA09A4A6A4B5}.Release|Any CPU.Build.0 = Release|Any CPU
{84504BF2-6F50-435D-B6D4-6A06D48331A0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{84504BF2-6F50-435D-B6D4-6A06D48331A0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{84504BF2-6F50-435D-B6D4-6A06D48331A0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{84504BF2-6F50-435D-B6D4-6A06D48331A0}.Release|Any CPU.Build.0 = Release|Any CPU
{D9EA1B1E-A8A9-4C13-BFC9-579832B878BF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D9EA1B1E-A8A9-4C13-BFC9-579832B878BF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D9EA1B1E-A8A9-4C13-BFC9-579832B878BF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D9EA1B1E-A8A9-4C13-BFC9-579832B878BF}.Release|Any CPU.Build.0 = Release|Any CPU
{B74E170A-9AB6-4A1A-9125-42B479DBFBF4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B74E170A-9AB6-4A1A-9125-42B479DBFBF4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B74E170A-9AB6-4A1A-9125-42B479DBFBF4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B74E170A-9AB6-4A1A-9125-42B479DBFBF4}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ViewComponents.NotVisualComponents
{
public class DataForPDFPieChart
{
public string FilePath = string.Empty;
public string DocumentTitle = string.Empty;//заголовок документа
public string ChartTitle = string.Empty;//заголовок диаграммы
public DiagramLegendEnum diagLegend;
public string LegendName = string.Empty;
public List<(double,string)> Items;
public DataForPDFPieChart(string filePath, string documentTitle, string charttitle, DiagramLegendEnum diagLegend, string legendName, List<(double, string)> items)
{
FilePath = filePath;
DocumentTitle = documentTitle;
ChartTitle = charttitle;
this.diagLegend = diagLegend;
LegendName = legendName;
Items = items;
}
}
}

View File

@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ViewComponents.NotVisualComponents
{
public class DataForPDFTable<T>
{
public string FilePath = string.Empty;
public string DocumentTitle = string.Empty; //заголовок документа
public List<int> Heights; // высота строк
public List<(int, int)> Merges; // информаци о объединении ячеек
public List<(string, string)> Headers; //заголовки шапки таблицы
public List<T> Data;
public DataForPDFTable(string filePath, string documentTitle, List<int> heights, List<(int, int)> merges, List<(string, string)> headers, List<T> data)
{
FilePath = filePath;
DocumentTitle = documentTitle;
Heights = heights;
Merges = merges;
Headers = headers;
Data = data;
}
}
}

View File

@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ViewComponents.NotVisualComponents
{
public enum DiagramLegendEnum
{
Top = 0,
Bottom = 1,
Right = 2,
Left = 3,
}
}

View File

@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ViewComponents.NotVisualComponents
{
public class ImagesForPDF
{
public ImagesForPDF(string filepath, string header, string[] imagepaths)
{
this.filepath = filepath;
this.header = header;
this.imagepaths = imagepaths;
}
public string filepath;
public string header;
public string[] imagepaths;
}
}

View File

@@ -0,0 +1,36 @@
namespace ViewComponents.NotVisualComponents
{
partial class PdfImages
{
/// <summary>
/// Обязательная переменная конструктора.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Освободить все используемые ресурсы.
/// </summary>
/// <param name="disposing">истинно, если управляемый ресурс должен быть удален; иначе ложно.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Код, автоматически созданный конструктором компонентов
/// <summary>
/// Требуемый метод для поддержки конструктора — не изменяйте
/// содержимое этого метода с помощью редактора кода.
/// </summary>
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
}
#endregion
}
}

View File

@@ -0,0 +1,73 @@
using MigraDoc.DocumentObjectModel;
using MigraDoc.Rendering;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace ViewComponents.NotVisualComponents
{
public partial class PdfImages : Component
{
public PdfImages()
{
InitializeComponent();
}
public PdfImages(IContainer container)
{
container.Add(this);
InitializeComponent();
}
public bool CreatePdfDoc (ImagesForPDF imagesForPDF)
{
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
CheckFileExsists(imagesForPDF);
// создание документа
Document _document = new Document();
var style = _document.Styles["Normal"];
style.Font.Name = "Arial";
style.Font.Size = 25;
style = _document.Styles.AddStyle("NormalTitle", "Normal");
style.Font.Bold = true;
//добавление заголовка
var section = _document.AddSection();
var paragraph = section.AddParagraph(imagesForPDF.header);
paragraph.Format.Alignment = ParagraphAlignment.Center;
paragraph.Format.SpaceAfter = "2cm";
//добавление изображений
foreach (string path in imagesForPDF.imagepaths)
if (File.Exists(path)) section.AddImage(path);
//сохранение документа
PdfDocumentRenderer renderer = new PdfDocumentRenderer(true);
renderer.Document = _document;
renderer.RenderDocument();
renderer.PdfDocument.Save(imagesForPDF.filepath);
return true;
}
private void CheckFileExsists(ImagesForPDF imagesForPDF)
{
if (string.IsNullOrEmpty(imagesForPDF.filepath) || string.IsNullOrEmpty(imagesForPDF.header) || imagesForPDF.imagepaths.Length == 0)
{
throw new ArgumentNullException();
}
if (!File.Exists(imagesForPDF.filepath))
{
throw new FileNotFoundException(imagesForPDF.filepath);
}
}
}
}

View File

@@ -0,0 +1,36 @@
namespace ViewComponents.NotVisualComponents
{
partial class PdfTable
{
/// <summary>
/// Обязательная переменная конструктора.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Освободить все используемые ресурсы.
/// </summary>
/// <param name="disposing">истинно, если управляемый ресурс должен быть удален; иначе ложно.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Код, автоматически созданный конструктором компонентов
/// <summary>
/// Требуемый метод для поддержки конструктора — не изменяйте
/// содержимое этого метода с помощью редактора кода.
/// </summary>
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
}
#endregion
}
}

View File

@@ -0,0 +1,177 @@
using MigraDoc.DocumentObjectModel;
using MigraDoc.DocumentObjectModel.Tables;
using MigraDoc.Rendering;
using PdfSharp.Pdf.Content.Objects;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ViewComponents.NotVisualComponents
{
public partial class PdfTable : Component
{
public PdfTable()
{
InitializeComponent();
}
public PdfTable(IContainer container)
{
container.Add(this);
InitializeComponent();
}
public bool createTable<T>(DataForPDFTable<T> dataForPDF)
{
//проверки
if (dataForPDF.Merges.Count == 0 || dataForPDF.Heights.Count == 0 || dataForPDF.Headers.Count == 0
|| dataForPDF.Data.Count == 0 || string.IsNullOrEmpty(dataForPDF.FilePath)
|| string.IsNullOrEmpty(dataForPDF.DocumentTitle)) throw new ArgumentException("Недостаточно данных");
int[] cellsArray = new int[dataForPDF.Heights.Count];
foreach (var merge in dataForPDF.Merges)
{
if (merge.Item1 >= merge.Item2) throw new ArgumentException("Неправильно заполнены объединения строк");
for (int i = merge.Item1; i < merge.Item2; i++)
{
cellsArray[i]++;
}
}
foreach (int cell in cellsArray)
{
if (cell > 1) throw new ArgumentException("Объединения заходят друг на друга");
}
foreach ((string, string) el in dataForPDF.Headers)
if (string.IsNullOrEmpty(el.Item2)) throw new ArgumentException("Элементы шапки не могут быть пустыми");
//создание документа
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
Document _document = new Document();
var style = _document.Styles["Normal"];
style = _document.Styles.AddStyle("NormalTitle", "Normal");
style.Font.Name = "Arial";
style.Font.Size = 25;
style.Font.Bold = true;
style = _document.Styles.AddStyle("Table", "Normal");
style.Font.Name = "Times New Roman";
style.Font.Size = 12;
//добавление заголовка
var section = _document.AddSection();
var paragraph = section.AddParagraph(dataForPDF.DocumentTitle);
paragraph.Format.Alignment = ParagraphAlignment.Center;
paragraph.Format.SpaceAfter = "2cm";
paragraph.Style = "NormalTitle";
//добавление таблицы
Table table = section.AddTable();
table.Style = "Table";
table.Borders.Width = 0.25;
Column column;
for (int i = 0; i < dataForPDF.Data.Count + 2; i++)
{
column = table.AddColumn();
column.Format.Alignment = ParagraphAlignment.Center;
}
// создание шапки и заполнение контентом
int mergeRange = 0; //размерность слияния
int mergeIndex = 0; //стартовый индекс начала слияния
Row row;
for (int i = 0; i < dataForPDF.Headers.Count; i++)
{
//если элемент шапки группируются по строкам
if (dataForPDF.Merges.Select(x => x.Item1).Contains(mergeIndex))
{
mergeRange = dataForPDF.Merges.Find(x => x.Item1 == mergeIndex).Item2 - mergeIndex;
mergeIndex = dataForPDF.Merges.Find(x => x.Item1 == mergeIndex).Item2 + 1;
//стилизация ячейки. в этом блоке кода (до цикла) создаётся объединяющая ячейка
row = table.AddRow();
row.Height = dataForPDF.Heights[i];
row.Format.Alignment = ParagraphAlignment.Center;
row.Format.Font.Bold = true;
row.Cells[0].AddParagraph(dataForPDF.Headers[i].Item2);
row.Cells[0].VerticalAlignment = VerticalAlignment.Center;
row.Cells[0].MergeDown = mergeRange;
//с этого места создаются дочерние ячейки
for (int k = 0; k<mergeRange; k++)
{
i++;
row.Cells[1].AddParagraph(dataForPDF.Headers[i].Item2);
AddTheContent<T>(dataForPDF.Data, table, dataForPDF.Headers[i].Item1, row.Index, 2);
row.Cells[1].VerticalAlignment = VerticalAlignment.Center;
row = table.AddRow();
row.Height = dataForPDF.Heights[i];
row.Format.Font.Bold = true;
row.Format.Alignment = ParagraphAlignment.Center;
}
i++;
row.Cells[1].AddParagraph(dataForPDF.Headers[i].Item2);
AddTheContent<T>(dataForPDF.Data, table, dataForPDF.Headers[i].Item1, row.Index, 2);
row.Cells[1].VerticalAlignment = VerticalAlignment.Center;
}
else //если элемент шапки не группируется по строкам
{
//стилизация ячейки
row = table.AddRow();
row.Height = dataForPDF.Heights[i];
row.Format.Font.Bold = true;
row.Format.Alignment = ParagraphAlignment.Center;
row.Cells[0].AddParagraph(dataForPDF.Headers[i].Item2);
row.Cells[0].VerticalAlignment = VerticalAlignment.Center;
row.Cells[0].MergeRight = 1;
AddTheContent<T>(dataForPDF.Data, table, dataForPDF.Headers[i].Item1, row.Index, 2);
mergeIndex++;
}
}
PdfDocumentRenderer renderer = new PdfDocumentRenderer(true);
renderer.Document = _document;
renderer.RenderDocument();
renderer.PdfDocument.Save(dataForPDF.FilePath);
return true;
}
//метод заполнения таблицы контентом, заполнение происходит построчно.
public void AddTheContent<T>(List<T> items, Table table, string header, int row_index, int cell_index)
{
foreach (Row r in table.Rows)
{
for (int i = 0; i<items.Count; i++)
{
if (r.Index == row_index && row_index == 0) r.Cells[cell_index+i].AddParagraph((i+1).ToString());
else if(row_index!=0 && r.Index == row_index)
{
T item = items[i];
var type = typeof(T);
var fields = type.GetFields();
var field = fields.FirstOrDefault(x => x.Name.Equals(header));
r.Cells[cell_index + i].AddParagraph(field.GetValue(item).ToString());
r.Cells[cell_index + i].VerticalAlignment = VerticalAlignment.Center;
}
}
}
}
}
}

View File

@@ -0,0 +1,36 @@
namespace ViewComponents.NotVisualComponents
{
partial class PieChartPDF
{
/// <summary>
/// Обязательная переменная конструктора.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Освободить все используемые ресурсы.
/// </summary>
/// <param name="disposing">истинно, если управляемый ресурс должен быть удален; иначе ложно.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Код, автоматически созданный конструктором компонентов
/// <summary>
/// Требуемый метод для поддержки конструктора — не изменяйте
/// содержимое этого метода с помощью редактора кода.
/// </summary>
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
}
#endregion
}
}

View File

@@ -0,0 +1,85 @@
using MigraDoc.DocumentObjectModel;
using MigraDoc.DocumentObjectModel.Shapes.Charts;
using MigraDoc.Rendering;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ViewComponents.NotVisualComponents
{
public partial class PieChartPDF : Component
{
public PieChartPDF()
{
InitializeComponent();
}
public PieChartPDF(IContainer container)
{
container.Add(this);
InitializeComponent();
}
public bool CreatePieChart(DataForPDFPieChart dataForPDFPie)
{
// проверки
if (string.IsNullOrEmpty(dataForPDFPie.FilePath) || string.IsNullOrEmpty(dataForPDFPie.DocumentTitle) || string.IsNullOrEmpty(dataForPDFPie.ChartTitle)
|| string.IsNullOrEmpty(dataForPDFPie.LegendName)
|| dataForPDFPie.Items.Count == 0) throw new ArgumentException("Недостаточно данных");
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
Document _document = new Document();
var section = _document.AddSection();
var paragraph = section.AddParagraph(dataForPDFPie.DocumentTitle);
paragraph.Format.Alignment = ParagraphAlignment.Center;
paragraph.Format.SpaceAfter = "2cm";
Chart chart = section.AddChart(ChartType.Pie2D);
chart.Width = Unit.FromCentimeter(16);
chart.Height = Unit.FromCentimeter(12);
chart.HeaderArea.AddParagraph(dataForPDFPie.ChartTitle); // заголовок диаграммы
Series series = chart.SeriesCollection.AddSeries();
series.Name = dataForPDFPie.LegendName; // название сериии
XSeries xseries = chart.XValues.AddXSeries();
foreach ((double, string) el in dataForPDFPie.Items) // заполнение серии
{
series.Add(el.Item1);
xseries.Add(el.Item2);
}
switch (dataForPDFPie.diagLegend) // позиция легенды
{
case DiagramLegendEnum.Top:
chart.TopArea.AddLegend();
break;
case DiagramLegendEnum.Bottom:
chart.BottomArea.AddLegend();
break;
case DiagramLegendEnum.Right:
chart.RightArea.AddLegend();
break;
case DiagramLegendEnum.Left:
chart.LeftArea.AddLegend();
break;
}
chart.DataLabel.Type = DataLabelType.Percent;
chart.DataLabel.Position = DataLabelPosition.OutsideEnd;
PdfDocumentRenderer renderer = new PdfDocumentRenderer(true);
renderer.Document = _document;
renderer.RenderDocument();
renderer.PdfDocument.Save(dataForPDFPie.FilePath);
return true;
}
}
}

View File

@@ -5,10 +5,16 @@
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
</PropertyGroup>
<ItemGroup>
<Compile Update="Input_text.cs">
<PackageReference Include="PDFsharp-MigraDoc" Version="1.50.5147" />
<PackageReference Include="System.Text.Encoding.CodePages" Version="7.0.0" />
</ItemGroup>
<ItemGroup>
<Compile Update="VisualComponents\Input_text.cs">
<SubType>UserControl</SubType>
<CustomToolNamespace>TestView</CustomToolNamespace>
</Compile>

10
nuget.config Normal file
View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="ComponentsForKOP" value="C:\ComponentsForKOP" />
</packageSources>
<activePackageSource>
<!-- this tells that all of them are active -->
<add key="All" value="(Aggregate source)" />
</activePackageSource>
</configuration>

0
nuget.config.bak Normal file
View File