Compare commits
11 Commits
Author | SHA1 | Date | |
---|---|---|---|
32dfbe5764 | |||
65e207cf3d | |||
dfca5ba119 | |||
233146ea2c | |||
2068af18d0 | |||
bee04958e0 | |||
3b31a57033 | |||
751030b247 | |||
5c0fdc3ee1 | |||
e73a259ccb | |||
b2505135e5 |
65
BusinessLogic/AuthorLogic.cs
Normal file
65
BusinessLogic/AuthorLogic.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
67
BusinessLogic/BookLogic.cs
Normal file
67
BusinessLogic/BookLogic.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
13
BusinessLogic/BusinessLogic.csproj
Normal file
13
BusinessLogic/BusinessLogic.csproj
Normal 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>
|
14
Contracts/BindingModels/AuthorBindingModel.cs
Normal file
14
Contracts/BindingModels/AuthorBindingModel.cs
Normal 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;
|
||||
}
|
||||
}
|
18
Contracts/BindingModels/BookBindingModel.cs
Normal file
18
Contracts/BindingModels/BookBindingModel.cs
Normal 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; }
|
||||
|
||||
}
|
||||
}
|
17
Contracts/BusinessLogicContracts/IAuthorLogic.cs
Normal file
17
Contracts/BusinessLogicContracts/IAuthorLogic.cs
Normal 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);
|
||||
}
|
||||
}
|
17
Contracts/BusinessLogicContracts/IBookLogic.cs
Normal file
17
Contracts/BusinessLogicContracts/IBookLogic.cs
Normal 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);
|
||||
}
|
||||
}
|
9
Contracts/Contracts.csproj
Normal file
9
Contracts/Contracts.csproj
Normal file
@ -0,0 +1,9 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
15
Contracts/SearchModels/AuthorSearchModel.cs
Normal file
15
Contracts/SearchModels/AuthorSearchModel.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Contracts.SearchModels
|
||||
{
|
||||
public class AuthorSearchModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string FIO { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
18
Contracts/SearchModels/BookSearchModel.cs
Normal file
18
Contracts/SearchModels/BookSearchModel.cs
Normal file
@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
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; } = string.Empty;
|
||||
public string Author { get; set; } = string.Empty;
|
||||
public string PicturePath { get; set; } = string.Empty;
|
||||
public DateTime PublicationDate { get; set; }
|
||||
}
|
||||
}
|
21
Contracts/StorageContracts/IAuthorStorage.cs
Normal file
21
Contracts/StorageContracts/IAuthorStorage.cs
Normal 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);
|
||||
}
|
||||
}
|
21
Contracts/StorageContracts/IBookStorage.cs
Normal file
21
Contracts/StorageContracts/IBookStorage.cs
Normal 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);
|
||||
}
|
||||
}
|
16
Contracts/ViewModels/AuthorViewModel.cs
Normal file
16
Contracts/ViewModels/AuthorViewModel.cs
Normal 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;
|
||||
}
|
||||
}
|
21
Contracts/ViewModels/BookViewModel.cs
Normal file
21
Contracts/ViewModels/BookViewModel.cs
Normal file
@ -0,0 +1,21 @@
|
||||
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;
|
||||
public string PicturePath { get; set; } = string.Empty;
|
||||
[DisplayName("Дата публикации")]
|
||||
public DateTime PublicationDate { get; set; }
|
||||
}
|
||||
}
|
22
DatabaseImplement/DatabaseImplement.csproj
Normal file
22
DatabaseImplement/DatabaseImplement.csproj
Normal 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>
|
120
DatabaseImplement/Implements/AuthorStorage.cs
Normal file
120
DatabaseImplement/Implements/AuthorStorage.cs
Normal 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
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
125
DatabaseImplement/Implements/BookStorage.cs
Normal file
125
DatabaseImplement/Implements/BookStorage.cs
Normal file
@ -0,0 +1,125 @@
|
||||
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.PublicationDate.Equals(model.PublicationDate))
|
||||
.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,
|
||||
PicturePath = book.PicturePath,
|
||||
PublicationDate = book.PublicationDate
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
28
DatabaseImplement/LibraryDatabase.cs
Normal file
28
DatabaseImplement/LibraryDatabase.cs
Normal 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; }
|
||||
}
|
||||
}
|
75
DatabaseImplement/Migrations/20231116173444_InitialCreate.Designer.cs
generated
Normal file
75
DatabaseImplement/Migrations/20231116173444_InitialCreate.Designer.cs
generated
Normal 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
|
||||
}
|
||||
}
|
||||
}
|
54
DatabaseImplement/Migrations/20231116173444_InitialCreate.cs
Normal file
54
DatabaseImplement/Migrations/20231116173444_InitialCreate.cs
Normal 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");
|
||||
}
|
||||
}
|
||||
}
|
71
DatabaseImplement/Migrations/20231130223553_FirstUpdate.Designer.cs
generated
Normal file
71
DatabaseImplement/Migrations/20231130223553_FirstUpdate.Designer.cs
generated
Normal file
@ -0,0 +1,71 @@
|
||||
// <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("20231130223553_FirstUpdate")]
|
||||
partial class FirstUpdate
|
||||
{
|
||||
/// <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>("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
|
||||
}
|
||||
}
|
||||
}
|
29
DatabaseImplement/Migrations/20231130223553_FirstUpdate.cs
Normal file
29
DatabaseImplement/Migrations/20231130223553_FirstUpdate.cs
Normal file
@ -0,0 +1,29 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace DatabaseImplement.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class FirstUpdate : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "Author",
|
||||
table: "Books");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<string>(
|
||||
name: "Author",
|
||||
table: "Books",
|
||||
type: "nvarchar(max)",
|
||||
nullable: false,
|
||||
defaultValue: "");
|
||||
}
|
||||
}
|
||||
}
|
75
DatabaseImplement/Migrations/20231211142817_SecondUpdate.Designer.cs
generated
Normal file
75
DatabaseImplement/Migrations/20231211142817_SecondUpdate.Designer.cs
generated
Normal 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("20231211142817_SecondUpdate")]
|
||||
partial class SecondUpdate
|
||||
{
|
||||
/// <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
|
||||
}
|
||||
}
|
||||
}
|
29
DatabaseImplement/Migrations/20231211142817_SecondUpdate.cs
Normal file
29
DatabaseImplement/Migrations/20231211142817_SecondUpdate.cs
Normal file
@ -0,0 +1,29 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace DatabaseImplement.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class SecondUpdate : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<string>(
|
||||
name: "Author",
|
||||
table: "Books",
|
||||
type: "nvarchar(max)",
|
||||
nullable: false,
|
||||
defaultValue: "");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "Author",
|
||||
table: "Books");
|
||||
}
|
||||
}
|
||||
}
|
72
DatabaseImplement/Migrations/LibraryDatabaseModelSnapshot.cs
Normal file
72
DatabaseImplement/Migrations/LibraryDatabaseModelSnapshot.cs
Normal 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
|
||||
}
|
||||
}
|
||||
}
|
17
DatabaseImplement/Models/Author.cs
Normal file
17
DatabaseImplement/Models/Author.cs
Normal 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; }
|
||||
}
|
||||
}
|
26
DatabaseImplement/Models/Book.cs
Normal file
26
DatabaseImplement/Models/Book.cs
Normal file
@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
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; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public string PicturePath { get; set; } = string.Empty;
|
||||
[Required]
|
||||
public string Author { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public DateTime PublicationDate { get; set; }
|
||||
}
|
||||
}
|
65
Library/FormAuthor.Designer.cs
generated
Normal file
65
Library/FormAuthor.Designer.cs
generated
Normal file
@ -0,0 +1,65 @@
|
||||
namespace Library
|
||||
{
|
||||
partial class FormAuthor
|
||||
{
|
||||
/// <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(704, 411);
|
||||
dataGridView1.TabIndex = 0;
|
||||
dataGridView1.CellEndEdit += dataGridView_CellEndEdit;
|
||||
dataGridView1.KeyDown += dataGridView_KeyDown;
|
||||
//
|
||||
// FormAuthor
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(704, 411);
|
||||
Controls.Add(dataGridView1);
|
||||
Name = "FormAuthor";
|
||||
Text = "Справочник авторов";
|
||||
Load += FormAuthor_Load;
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView1).EndInit();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private DataGridView dataGridView1;
|
||||
}
|
||||
}
|
119
Library/FormAuthor.cs
Normal file
119
Library/FormAuthor.cs
Normal file
@ -0,0 +1,119 @@
|
||||
using Contracts.BindingModels;
|
||||
using Contracts.BusinessLogicContracts;
|
||||
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 Library
|
||||
{
|
||||
public partial class FormAuthor : Form
|
||||
{
|
||||
private readonly IAuthorLogic authorLogic;
|
||||
BindingList<AuthorBindingModel> authorBindingList;
|
||||
|
||||
public FormAuthor(IAuthorLogic _authorLogic)
|
||||
{
|
||||
InitializeComponent();
|
||||
authorLogic = _authorLogic;
|
||||
authorBindingList = new BindingList<AuthorBindingModel>();
|
||||
dataGridView1.AllowUserToAddRows = false;
|
||||
}
|
||||
|
||||
private void LoadData()
|
||||
{
|
||||
try
|
||||
{
|
||||
var list1 = authorLogic.Read(null);
|
||||
authorBindingList.Clear();
|
||||
foreach (var item in list1)
|
||||
{
|
||||
authorBindingList.Add(new AuthorBindingModel
|
||||
{
|
||||
Id = item.Id,
|
||||
FIO = item.FIO,
|
||||
});
|
||||
}
|
||||
if (authorLogic != null)
|
||||
{
|
||||
dataGridView1.DataSource = authorBindingList;
|
||||
dataGridView1.Columns[0].Visible = false;
|
||||
dataGridView1.Columns[1].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void dataGridView_CellEndEdit(object sender, DataGridViewCellEventArgs e)
|
||||
{
|
||||
var typeName = (string)dataGridView1.CurrentRow.Cells[1].Value;
|
||||
if (!string.IsNullOrEmpty(typeName))
|
||||
{
|
||||
if (dataGridView1.CurrentRow.Cells[0].Value != null)
|
||||
{
|
||||
authorLogic.CreateOrUpdate(new AuthorBindingModel()
|
||||
{
|
||||
Id = Convert.ToInt32(dataGridView1.CurrentRow.Cells[0].Value),
|
||||
FIO = (string)dataGridView1.CurrentRow.Cells[1].EditedFormattedValue
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
authorLogic.CreateOrUpdate(new AuthorBindingModel()
|
||||
{
|
||||
FIO = (string)dataGridView1.CurrentRow.Cells[1].EditedFormattedValue
|
||||
});
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Введена пустая строка", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
LoadData();
|
||||
}
|
||||
|
||||
|
||||
private void FormAuthor_Load(object sender, EventArgs e)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
|
||||
private void dataGridView_KeyDown(object sender, KeyEventArgs e)
|
||||
{
|
||||
if (e.KeyData == Keys.Insert)
|
||||
{
|
||||
if (dataGridView1.Rows.Count == 0)
|
||||
{
|
||||
authorBindingList.Add(new AuthorBindingModel());
|
||||
dataGridView1.DataSource = new BindingList<AuthorBindingModel>(authorBindingList);
|
||||
dataGridView1.CurrentCell = dataGridView1.Rows[0].Cells[1];
|
||||
return;
|
||||
}
|
||||
if (dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells[1].Value != null)
|
||||
{
|
||||
authorBindingList.Add(new AuthorBindingModel());
|
||||
dataGridView1.DataSource = new BindingList<AuthorBindingModel>(authorBindingList);
|
||||
dataGridView1.CurrentCell = dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells[1];
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (e.KeyData == Keys.Delete)
|
||||
{
|
||||
if (MessageBox.Show("Удалить выбранный элемент", "Удаление",
|
||||
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||
{
|
||||
authorLogic.Delete(new AuthorBindingModel() { Id = (int)dataGridView1.CurrentRow.Cells[0].Value });
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
120
Library/FormAuthor.resx
Normal file
120
Library/FormAuthor.resx
Normal 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>
|
167
Library/FormBook.Designer.cs
generated
Normal file
167
Library/FormBook.Designer.cs
generated
Normal file
@ -0,0 +1,167 @@
|
||||
namespace Library
|
||||
{
|
||||
partial class FormBook
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
labelName = new Label();
|
||||
textBoxName = new TextBox();
|
||||
labelCover = new Label();
|
||||
textBoxCover = new TextBox();
|
||||
labelAuthor = new Label();
|
||||
labelDate = new Label();
|
||||
dateTextBox = new CustomComponents.DateTextBox();
|
||||
button1 = new Button();
|
||||
buttonSave = new Button();
|
||||
booksForm = new KOP_Labs.BooksForm();
|
||||
SuspendLayout();
|
||||
//
|
||||
// labelName
|
||||
//
|
||||
labelName.AutoSize = true;
|
||||
labelName.Location = new Point(34, 218);
|
||||
labelName.Name = "labelName";
|
||||
labelName.Size = new Size(124, 20);
|
||||
labelName.TabIndex = 0;
|
||||
labelName.Text = "Название книги:";
|
||||
//
|
||||
// textBoxName
|
||||
//
|
||||
textBoxName.Location = new Point(175, 218);
|
||||
textBoxName.Name = "textBoxName";
|
||||
textBoxName.Size = new Size(205, 27);
|
||||
textBoxName.TabIndex = 1;
|
||||
//
|
||||
// labelCover
|
||||
//
|
||||
labelCover.AutoSize = true;
|
||||
labelCover.Location = new Point(34, 263);
|
||||
labelCover.Name = "labelCover";
|
||||
labelCover.Size = new Size(75, 20);
|
||||
labelCover.TabIndex = 2;
|
||||
labelCover.Text = "Обложка:";
|
||||
//
|
||||
// textBoxCover
|
||||
//
|
||||
textBoxCover.Location = new Point(175, 256);
|
||||
textBoxCover.Name = "textBoxCover";
|
||||
textBoxCover.Size = new Size(205, 27);
|
||||
textBoxCover.TabIndex = 3;
|
||||
textBoxCover.DoubleClick += textBoxCover_Click;
|
||||
//
|
||||
// labelAuthor
|
||||
//
|
||||
labelAuthor.AutoSize = true;
|
||||
labelAuthor.Location = new Point(34, 14);
|
||||
labelAuthor.Name = "labelAuthor";
|
||||
labelAuthor.Size = new Size(54, 20);
|
||||
labelAuthor.TabIndex = 4;
|
||||
labelAuthor.Text = "Автор:";
|
||||
//
|
||||
// labelDate
|
||||
//
|
||||
labelDate.AutoSize = true;
|
||||
labelDate.Location = new Point(34, 327);
|
||||
labelDate.Name = "labelDate";
|
||||
labelDate.Size = new Size(106, 20);
|
||||
labelDate.TabIndex = 6;
|
||||
labelDate.Text = "Дата издания:";
|
||||
//
|
||||
// dateTextBox
|
||||
//
|
||||
dateTextBox.Location = new Point(165, 289);
|
||||
dateTextBox.Name = "dateTextBox";
|
||||
dateTextBox.Pattern = "";
|
||||
dateTextBox.Size = new Size(157, 77);
|
||||
dateTextBox.TabIndex = 8;
|
||||
dateTextBox.TextBoxValue = "";
|
||||
//
|
||||
// button1
|
||||
//
|
||||
button1.Location = new Point(34, 399);
|
||||
button1.Name = "button1";
|
||||
button1.Size = new Size(94, 29);
|
||||
button1.TabIndex = 9;
|
||||
button1.Text = "Закрыть";
|
||||
button1.UseVisualStyleBackColor = true;
|
||||
button1.Click += buttonCancel_Click;
|
||||
//
|
||||
// buttonSave
|
||||
//
|
||||
buttonSave.Location = new Point(257, 399);
|
||||
buttonSave.Name = "buttonSave";
|
||||
buttonSave.Size = new Size(94, 29);
|
||||
buttonSave.TabIndex = 10;
|
||||
buttonSave.Text = "Сохранить";
|
||||
buttonSave.UseVisualStyleBackColor = true;
|
||||
buttonSave.Click += buttonSave_Click;
|
||||
//
|
||||
// booksForm
|
||||
//
|
||||
booksForm.AutoSize = true;
|
||||
booksForm.Location = new Point(129, 14);
|
||||
booksForm.Name = "booksForm";
|
||||
booksForm.SelectedValue = null;
|
||||
booksForm.Size = new Size(251, 201);
|
||||
booksForm.TabIndex = 11;
|
||||
//
|
||||
// FormBook
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(392, 484);
|
||||
Controls.Add(booksForm);
|
||||
Controls.Add(buttonSave);
|
||||
Controls.Add(button1);
|
||||
Controls.Add(dateTextBox);
|
||||
Controls.Add(labelDate);
|
||||
Controls.Add(labelAuthor);
|
||||
Controls.Add(textBoxCover);
|
||||
Controls.Add(labelCover);
|
||||
Controls.Add(textBoxName);
|
||||
Controls.Add(labelName);
|
||||
Name = "FormBook";
|
||||
Text = "Создание/Редактирование книги";
|
||||
Load += FormBook_Load;
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private Label labelName;
|
||||
private TextBox textBoxName;
|
||||
private Label labelCover;
|
||||
private TextBox textBoxCover;
|
||||
private Label labelAuthor;
|
||||
private Label labelDate;
|
||||
private CustomComponents.DateTextBox dateTextBox;
|
||||
private Button button1;
|
||||
private Button buttonSave;
|
||||
private KOP_Labs.BooksForm booksForm;
|
||||
}
|
||||
}
|
126
Library/FormBook.cs
Normal file
126
Library/FormBook.cs
Normal file
@ -0,0 +1,126 @@
|
||||
using Contracts.BindingModels;
|
||||
using Contracts.BusinessLogicContracts;
|
||||
using Contracts.ViewModels;
|
||||
using KOP_Labs;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Library
|
||||
{
|
||||
public partial class FormBook : Form
|
||||
{
|
||||
public int Id { set { id = value; } }
|
||||
|
||||
private readonly IBookLogic _logicB;
|
||||
private readonly IAuthorLogic _logicA;
|
||||
|
||||
private int? id;
|
||||
public FormBook(IBookLogic bookLogic, IAuthorLogic authorLogic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logicB = bookLogic;
|
||||
_logicA = authorLogic;
|
||||
}
|
||||
|
||||
private void buttonSave_Click(object sender, EventArgs e)
|
||||
{
|
||||
dateTextBox.Pattern = @"^(([0-2][0-9])|([3][0-1]))\s(января|февраля|марта|апреля|мая|июня|июля|августа|сентября|октября|ноября|декабря)\s\d{4}$";
|
||||
if (string.IsNullOrEmpty(textBoxName.Text))
|
||||
{
|
||||
MessageBox.Show("Введите название книги", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(textBoxCover.Text))
|
||||
{
|
||||
MessageBox.Show("Выберите обложку", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(dateTextBox.TextBoxValue))
|
||||
{
|
||||
MessageBox.Show("Заполните дату публикации согласно шаблону", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(booksForm.SelectedValue))
|
||||
{
|
||||
MessageBox.Show("Выберите хотя бы одного автора", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
_logicB.CreateOrUpdate(new BookBindingModel
|
||||
{
|
||||
Id = id,
|
||||
Name = textBoxName.Text,
|
||||
PicturePath = textBoxCover.Text,
|
||||
Author = booksForm.SelectedValue,
|
||||
PublicationDate = DateTime.Parse(dateTextBox.TextBoxValue)
|
||||
}) ;
|
||||
|
||||
MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
DialogResult = DialogResult.OK;
|
||||
Close();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void FormBook_Load(object sender, EventArgs e)
|
||||
{
|
||||
List<AuthorViewModel> viewS = _logicA.Read(null);
|
||||
if (viewS != null)
|
||||
{
|
||||
booksForm.ClearList();
|
||||
foreach (AuthorViewModel s in viewS)
|
||||
{
|
||||
booksForm.FillValues(s.FIO);
|
||||
}
|
||||
}
|
||||
if (id.HasValue)
|
||||
{
|
||||
try
|
||||
{
|
||||
BookViewModel view = _logicB.Read(new BookBindingModel { Id = id.Value })?[0];
|
||||
if (view != null)
|
||||
{
|
||||
textBoxName.Text = view.Name;
|
||||
textBoxCover.Text = view.PicturePath;
|
||||
booksForm.SelectedValue = view.Author;
|
||||
dateTextBox.TextBoxValue = view.PublicationDate.ToString("dd MMMM yyyy", CultureInfo.CreateSpecificCulture("ru-RU"));
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonCancel_Click(object sender, EventArgs e)
|
||||
{
|
||||
DialogResult = DialogResult.Cancel;
|
||||
Close();
|
||||
}
|
||||
|
||||
private void textBoxCover_Click(object sender, EventArgs e)
|
||||
{
|
||||
using (var dialog = new OpenFileDialog { Filter = "jpg|*.jpg" })
|
||||
{
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
textBoxCover.Text = dialog.FileName.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
120
Library/FormBook.resx
Normal file
120
Library/FormBook.resx
Normal 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>
|
188
Library/FormMain.Designer.cs
generated
Normal file
188
Library/FormMain.Designer.cs
generated
Normal file
@ -0,0 +1,188 @@
|
||||
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()
|
||||
{
|
||||
components = new System.ComponentModel.Container();
|
||||
удалитьToolStripMenuItem = new ToolStripMenuItem();
|
||||
редактироватьToolStripMenuItem = new ToolStripMenuItem();
|
||||
сохранитьВPDFToolStripMenuItem = new ToolStripMenuItem();
|
||||
сохранитьВEToolStripMenuItem = new ToolStripMenuItem();
|
||||
сохранитьВWordToolStripMenuItem = new ToolStripMenuItem();
|
||||
авторыToolStripMenuItem = new ToolStripMenuItem();
|
||||
tableComponent = new KOP_Labs.TableComponent();
|
||||
pdfImages = new ViewComponents.NotVisualComponents.PdfImages(components);
|
||||
wordHistogramm = new KOP_Labs.NonVisualComponents.WordHistogramm(components);
|
||||
contextMenuStrip = new ContextMenuStrip(components);
|
||||
добавитьToolStripMenuItem = new ToolStripMenuItem();
|
||||
удалитьToolStripMenuItem1 = new ToolStripMenuItem();
|
||||
редактироватьToolStripMenuItem1 = new ToolStripMenuItem();
|
||||
сохранитьВPdfToolStripMenuItem1 = new ToolStripMenuItem();
|
||||
сохранитьВToolStripMenuItem = new ToolStripMenuItem();
|
||||
сохранитьВWordToolStripMenuItem1 = new ToolStripMenuItem();
|
||||
авторыToolStripMenuItem1 = new ToolStripMenuItem();
|
||||
excelTable1 = new ComponentsLibraryNet60.DocumentWithTable.ComponentDocumentWithTableHeaderRowExcel(components);
|
||||
contextMenuStrip.SuspendLayout();
|
||||
SuspendLayout();
|
||||
//
|
||||
// удалитьToolStripMenuItem
|
||||
//
|
||||
удалитьToolStripMenuItem.Name = "удалитьToolStripMenuItem";
|
||||
удалитьToolStripMenuItem.Size = new Size(32, 19);
|
||||
//
|
||||
// редактироватьToolStripMenuItem
|
||||
//
|
||||
редактироватьToolStripMenuItem.Name = "редактироватьToolStripMenuItem";
|
||||
редактироватьToolStripMenuItem.Size = new Size(32, 19);
|
||||
//
|
||||
// сохранитьВPDFToolStripMenuItem
|
||||
//
|
||||
сохранитьВPDFToolStripMenuItem.Name = "сохранитьВPDFToolStripMenuItem";
|
||||
сохранитьВPDFToolStripMenuItem.Size = new Size(32, 19);
|
||||
//
|
||||
// сохранитьВEToolStripMenuItem
|
||||
//
|
||||
сохранитьВEToolStripMenuItem.Name = "сохранитьВEToolStripMenuItem";
|
||||
сохранитьВEToolStripMenuItem.Size = new Size(32, 19);
|
||||
//
|
||||
// сохранитьВWordToolStripMenuItem
|
||||
//
|
||||
сохранитьВWordToolStripMenuItem.Name = "сохранитьВWordToolStripMenuItem";
|
||||
сохранитьВWordToolStripMenuItem.Size = new Size(32, 19);
|
||||
//
|
||||
// авторыToolStripMenuItem
|
||||
//
|
||||
авторыToolStripMenuItem.Name = "авторыToolStripMenuItem";
|
||||
авторыToolStripMenuItem.Size = new Size(32, 19);
|
||||
//
|
||||
// tableComponent
|
||||
//
|
||||
tableComponent.Dock = DockStyle.Fill;
|
||||
tableComponent.IndexRow = 0;
|
||||
tableComponent.Location = new Point(0, 0);
|
||||
tableComponent.Name = "tableComponent";
|
||||
tableComponent.Size = new Size(800, 450);
|
||||
tableComponent.TabIndex = 1;
|
||||
//
|
||||
// contextMenuStrip
|
||||
//
|
||||
contextMenuStrip.ImageScalingSize = new Size(20, 20);
|
||||
contextMenuStrip.Items.AddRange(new ToolStripItem[] { добавитьToolStripMenuItem, удалитьToolStripMenuItem1, редактироватьToolStripMenuItem1, сохранитьВPdfToolStripMenuItem1, сохранитьВToolStripMenuItem, сохранитьВWordToolStripMenuItem1, авторыToolStripMenuItem1 });
|
||||
contextMenuStrip.Name = "contextMenuStrip";
|
||||
contextMenuStrip.Size = new Size(256, 172);
|
||||
//
|
||||
// добавитьToolStripMenuItem
|
||||
//
|
||||
добавитьToolStripMenuItem.Name = "добавитьToolStripMenuItem";
|
||||
добавитьToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.A;
|
||||
добавитьToolStripMenuItem.Size = new Size(255, 24);
|
||||
добавитьToolStripMenuItem.Text = "Добавить";
|
||||
добавитьToolStripMenuItem.Click += добавитьToolStripMenuItem_Click;
|
||||
//
|
||||
// удалитьToolStripMenuItem1
|
||||
//
|
||||
удалитьToolStripMenuItem1.Name = "удалитьToolStripMenuItem1";
|
||||
удалитьToolStripMenuItem1.ShortcutKeys = Keys.Control | Keys.D;
|
||||
удалитьToolStripMenuItem1.Size = new Size(255, 24);
|
||||
удалитьToolStripMenuItem1.Text = "Удалить";
|
||||
удалитьToolStripMenuItem1.Click += удалитьToolStripMenuItem_Click;
|
||||
//
|
||||
// редактироватьToolStripMenuItem1
|
||||
//
|
||||
редактироватьToolStripMenuItem1.Name = "редактироватьToolStripMenuItem1";
|
||||
редактироватьToolStripMenuItem1.ShortcutKeys = Keys.Control | Keys.U;
|
||||
редактироватьToolStripMenuItem1.Size = new Size(255, 24);
|
||||
редактироватьToolStripMenuItem1.Text = "Редактировать";
|
||||
редактироватьToolStripMenuItem1.Click += редактироватьToolStripMenuItem_Click;
|
||||
//
|
||||
// сохранитьВPdfToolStripMenuItem1
|
||||
//
|
||||
сохранитьВPdfToolStripMenuItem1.Name = "сохранитьВPdfToolStripMenuItem1";
|
||||
сохранитьВPdfToolStripMenuItem1.ShortcutKeys = Keys.Control | Keys.S;
|
||||
сохранитьВPdfToolStripMenuItem1.Size = new Size(255, 24);
|
||||
сохранитьВPdfToolStripMenuItem1.Text = "Сохранить в Pdf";
|
||||
сохранитьВPdfToolStripMenuItem1.Click += сохранитьВPDFToolStripMenuItem_Click;
|
||||
//
|
||||
// сохранитьВToolStripMenuItem
|
||||
//
|
||||
сохранитьВToolStripMenuItem.Name = "сохранитьВToolStripMenuItem";
|
||||
сохранитьВToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.T;
|
||||
сохранитьВToolStripMenuItem.Size = new Size(255, 24);
|
||||
сохранитьВToolStripMenuItem.Text = "Сохранить в Excel";
|
||||
сохранитьВToolStripMenuItem.Click += сохранитьВExcelToolStripMenuItem_Click;
|
||||
//
|
||||
// сохранитьВWordToolStripMenuItem1
|
||||
//
|
||||
сохранитьВWordToolStripMenuItem1.Name = "сохранитьВWordToolStripMenuItem1";
|
||||
сохранитьВWordToolStripMenuItem1.ShortcutKeys = Keys.Control | Keys.C;
|
||||
сохранитьВWordToolStripMenuItem1.Size = new Size(255, 24);
|
||||
сохранитьВWordToolStripMenuItem1.Text = "Сохранить в Word";
|
||||
сохранитьВWordToolStripMenuItem1.Click += сохранитьВWordToolStripMenuItem_Click;
|
||||
//
|
||||
// авторыToolStripMenuItem1
|
||||
//
|
||||
авторыToolStripMenuItem1.Name = "авторыToolStripMenuItem1";
|
||||
авторыToolStripMenuItem1.ShortcutKeys = Keys.Control | Keys.F;
|
||||
авторыToolStripMenuItem1.Size = new Size(255, 24);
|
||||
авторыToolStripMenuItem1.Text = "Авторы";
|
||||
авторыToolStripMenuItem1.Click += авторыToolStripMenuItem_Click;
|
||||
//
|
||||
// FormMain
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(800, 450);
|
||||
Controls.Add(tableComponent);
|
||||
Name = "FormMain";
|
||||
Text = "Form1";
|
||||
Load += FormMain_Load;
|
||||
contextMenuStrip.ResumeLayout(false);
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
private ToolStripMenuItem удалитьToolStripMenuItem;
|
||||
private ToolStripMenuItem редактироватьToolStripMenuItem;
|
||||
private ToolStripMenuItem сохранитьВPDFToolStripMenuItem;
|
||||
private ToolStripMenuItem сохранитьВEToolStripMenuItem;
|
||||
private ToolStripMenuItem сохранитьВWordToolStripMenuItem;
|
||||
private KOP_Labs.TableComponent tableComponent;
|
||||
private ViewComponents.NotVisualComponents.PdfImages pdfImages;
|
||||
private KOP_Labs.NonVisualComponents.WordHistogramm wordHistogramm;
|
||||
private ToolStripMenuItem авторыToolStripMenuItem;
|
||||
private ContextMenuStrip contextMenuStrip;
|
||||
private ToolStripMenuItem добавитьToolStripMenuItem;
|
||||
private ToolStripMenuItem удалитьToolStripMenuItem1;
|
||||
private ToolStripMenuItem редактироватьToolStripMenuItem1;
|
||||
private ToolStripMenuItem сохранитьВPdfToolStripMenuItem1;
|
||||
private ToolStripMenuItem сохранитьВToolStripMenuItem;
|
||||
private ToolStripMenuItem сохранитьВWordToolStripMenuItem1;
|
||||
private ToolStripMenuItem авторыToolStripMenuItem1;
|
||||
private ComponentsLibraryNet60.DocumentWithTable.ComponentDocumentWithTableHeaderRowExcel excelTable1;
|
||||
}
|
||||
}
|
256
Library/FormMain.cs
Normal file
256
Library/FormMain.cs
Normal file
@ -0,0 +1,256 @@
|
||||
using ComponentsLibraryNet60.Models;
|
||||
using Contracts.BindingModels;
|
||||
using Contracts.BusinessLogicContracts;
|
||||
using Contracts.SearchModels;
|
||||
using Contracts.ViewModels;
|
||||
using CustomComponents;
|
||||
using KOP_Labs.Classes;
|
||||
using System.Collections.Generic;
|
||||
using Unity;
|
||||
using ViewComponents.NotVisualComponents;
|
||||
|
||||
namespace Library
|
||||
{
|
||||
public partial class FormMain : Form
|
||||
{
|
||||
private readonly IBookLogic _bookLogic;
|
||||
private readonly IAuthorLogic _authorLogic;
|
||||
public FormMain(IBookLogic bookLogic, IAuthorLogic authorLogic)
|
||||
{
|
||||
_bookLogic = bookLogic;
|
||||
_authorLogic = authorLogic;
|
||||
InitializeComponent();
|
||||
tableComponent.TableConfiguration(5, new List<TableParameters>
|
||||
{
|
||||
new TableParameters("Id", 80, false, "Id"),
|
||||
new TableParameters("Íàçâàíèå", 100, true, "Name"),
|
||||
new TableParameters("Àâòîð", 180, true, "Author"),
|
||||
new TableParameters("Îáëîæêà", 80, false, "PicturePath"),
|
||||
new TableParameters("Äàòà èçäàíèÿ", 150, true, "PublicationDate")
|
||||
});
|
||||
tableComponent.ContextMenuStrip = contextMenuStrip;
|
||||
}
|
||||
private void FormMain_Load(object sender, EventArgs e)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
|
||||
private void LoadData()
|
||||
{
|
||||
tableComponent.ClearRows();
|
||||
try
|
||||
{
|
||||
var list = _bookLogic.Read(null);
|
||||
foreach (var row in list)
|
||||
{
|
||||
tableComponent.AddRow(row);
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Îøèáêà", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void AddNewElement()
|
||||
{
|
||||
var form = Program.Container.Resolve<FormBook>();
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateElement()
|
||||
{
|
||||
var form = Program.Container.Resolve<FormBook>();
|
||||
var selectedBook = tableComponent.GetSelectedObject<BookSearchModel>();
|
||||
if (selectedBook != null)
|
||||
{
|
||||
form.Id = Convert.ToInt32(selectedBook.Id);
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Âûáåðèòå êíèãó äëÿ ðåäàêòèðîâàíèÿ");
|
||||
}
|
||||
}
|
||||
|
||||
private void DeleteElement()
|
||||
{
|
||||
if (MessageBox.Show("Óäàëèòü êíèãó", "Âîïðîñ", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||
{
|
||||
var selectedBook = tableComponent.GetSelectedObject<BookSearchModel>();
|
||||
int id = Convert.ToInt32(selectedBook.Id);
|
||||
try
|
||||
{
|
||||
_bookLogic.Delete(new BookBindingModel { Id = id });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Îøèáêà", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
|
||||
private void CreatePdf()
|
||||
{
|
||||
string fileName = "";
|
||||
using (var dialog = new SaveFileDialog { Filter = "pdf|*.pdf" })
|
||||
{
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
fileName = dialog.FileName.ToString();
|
||||
MessageBox.Show("Ôàéë âûáðàí", "Óñïåõ", MessageBoxButtons.OK,
|
||||
MessageBoxIcon.Information);
|
||||
}
|
||||
else return;
|
||||
}
|
||||
|
||||
List<string> images = new List<string>();
|
||||
var list = _bookLogic.Read(null);
|
||||
|
||||
try
|
||||
{
|
||||
if (list != null)
|
||||
{
|
||||
foreach (var item in list)
|
||||
{
|
||||
images.Add(item.PicturePath);
|
||||
}
|
||||
string[] imagesArray = images.ToArray();
|
||||
|
||||
pdfImages.CreatePdfDoc(new ImagesForPDF(fileName, "Èëëþñòðàöèè êíèã", imagesArray));
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Îøèáêà");
|
||||
}
|
||||
}
|
||||
|
||||
private void CreateExcel()
|
||||
{
|
||||
string fileName = "";
|
||||
using (var dialog = new SaveFileDialog { Filter = "xlsx|*.xlsx" })
|
||||
{
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
fileName = dialog.FileName.ToString();
|
||||
MessageBox.Show("Ôàéë âûáðàí", "Óñïåõ", MessageBoxButtons.OK,
|
||||
MessageBoxIcon.Information);
|
||||
}
|
||||
else return;
|
||||
}
|
||||
|
||||
List<(int Column, int Row)> width = new List<(int, int)>() { (30, 0), (30, 0), (30, 0), (30, 0) };
|
||||
List<(int StartIndex, int Count)> column_union = new List<(int, int)>() { (1, 2) };
|
||||
List<(int ColumnIndex, int RowIndex, string Header, string PropertyName)> headers =
|
||||
new List<(int ColumnIndex, int RowIndex, string Header, string PropertyName)> {
|
||||
(0,0, "Èäåíòèôèêàòîð", "Id"),
|
||||
(1,0,"Êíèãà", ""),
|
||||
(1,1,"Íàçâàíèå", "Name"),
|
||||
(2,1,"Àâòîð","Author"),
|
||||
(3,0,"Äàòà ïóáëèêàöèè", "PublicationDate")
|
||||
};
|
||||
|
||||
|
||||
|
||||
var list = _bookLogic.Read(null);
|
||||
ComponentDocumentWithTableHeaderDataConfig<BookViewModel> config = new();
|
||||
|
||||
try
|
||||
{
|
||||
excelTable1.CreateDoc(new ComponentDocumentWithTableHeaderDataConfig<BookViewModel>()
|
||||
{
|
||||
Data = list,
|
||||
UseUnion = true,
|
||||
ColumnsRowsWidth = width,
|
||||
ColumnUnion = column_union,
|
||||
Headers = headers,
|
||||
FilePath = fileName,
|
||||
Header = "Îò÷¸ò ïî êíèãàì"
|
||||
});
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Îøèáêà");
|
||||
}
|
||||
}
|
||||
|
||||
private void CreateWord()
|
||||
{
|
||||
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
|
||||
string fileName = "";
|
||||
using (var dialog = new SaveFileDialog { Filter = "docx|*.docx" })
|
||||
{
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
fileName = dialog.FileName.ToString();
|
||||
MessageBox.Show("Ôàéë âûáðàí", "Óñïåõ", MessageBoxButtons.OK,
|
||||
MessageBoxIcon.Information);
|
||||
}
|
||||
else return;
|
||||
}
|
||||
List<DataHistogramm> dataHistogramms = new List<DataHistogramm>();
|
||||
|
||||
var list_author = _authorLogic.Read(null);
|
||||
var list_book = _bookLogic.Read(null);
|
||||
foreach (var nm in list_author)
|
||||
{
|
||||
int bk_count = 0;
|
||||
foreach (var bk in list_book)
|
||||
if (bk.Author.Contains(nm.FIO)) bk_count++;
|
||||
dataHistogramms.Add(new DataHistogramm(nm.FIO, bk_count));
|
||||
}
|
||||
try
|
||||
{
|
||||
wordHistogramm.CreateHistogramm(new MyHistogramm(fileName, "Ãèñòîãðàììà", "Àâòîðû è èõ êíèãè", EnumLegends.Top, dataHistogramms));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Îøèáêà");
|
||||
}
|
||||
}
|
||||
private void äîáàâèòüToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
AddNewElement();
|
||||
}
|
||||
|
||||
private void óäàëèòüToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
DeleteElement();
|
||||
}
|
||||
|
||||
private void ðåäàêòèðîâàòüToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
UpdateElement();
|
||||
}
|
||||
|
||||
private void ñîõðàíèòüÂPDFToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
CreatePdf();
|
||||
}
|
||||
|
||||
private void ñîõðàíèòüÂExcelToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
CreateExcel();
|
||||
}
|
||||
|
||||
private void ñîõðàíèòüÂWordToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
CreateWord();
|
||||
}
|
||||
|
||||
private void àâòîðûToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var form = Program.Container.Resolve<FormAuthor>();
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
}
|
132
Library/FormMain.resx
Normal file
132
Library/FormMain.resx
Normal file
@ -0,0 +1,132 @@
|
||||
<?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>
|
||||
<metadata name="pdfImages.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>194, 17</value>
|
||||
</metadata>
|
||||
<metadata name="wordHistogramm.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>454, 17</value>
|
||||
</metadata>
|
||||
<metadata name="contextMenuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>627, 17</value>
|
||||
</metadata>
|
||||
<metadata name="excelTable1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>804, 17</value>
|
||||
</metadata>
|
||||
</root>
|
30
Library/Library.csproj
Normal file
30
Library/Library.csproj
Normal file
@ -0,0 +1,30 @@
|
||||
<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="ComponentsLibraryNet60" Version="1.0.0" />
|
||||
<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="System.Text.Encoding.CodePages" Version="8.0.0" />
|
||||
<PackageReference Include="Unity" Version="5.11.10" />
|
||||
<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>
|
38
Library/Program.cs
Normal file
38
Library/Program.cs
Normal file
@ -0,0 +1,38 @@
|
||||
using BusinessLogic;
|
||||
using Contracts.BusinessLogicContracts;
|
||||
using Contracts.StorageContracts;
|
||||
using DatabaseImplement.Implements;
|
||||
using Unity;
|
||||
using Unity.Lifetime;
|
||||
|
||||
namespace Library
|
||||
{
|
||||
internal static class Program
|
||||
{
|
||||
private static IUnityContainer container = null;
|
||||
public static IUnityContainer Container { get { if (container == null) { container = BuildUnityContainer(); } return container; } }
|
||||
/// <summary>
|
||||
/// The main entry point for the application.
|
||||
/// </summary>
|
||||
[STAThread]
|
||||
static void Main()
|
||||
{
|
||||
Application.SetHighDpiMode(HighDpiMode.SystemAware);
|
||||
Application.EnableVisualStyles();
|
||||
Application.SetCompatibleTextRenderingDefault(false);
|
||||
Application.Run(Container.Resolve<FormMain>());
|
||||
}
|
||||
private static IUnityContainer BuildUnityContainer()
|
||||
{
|
||||
var currentContainer = new UnityContainer();
|
||||
|
||||
currentContainer.RegisterType<IBookStorage, BookStorage>(new HierarchicalLifetimeManager());
|
||||
currentContainer.RegisterType<IAuthorStorage, AuthorStorage>(new HierarchicalLifetimeManager());
|
||||
|
||||
currentContainer.RegisterType<IBookLogic, BookLogic>(new HierarchicalLifetimeManager());
|
||||
currentContainer.RegisterType<IAuthorLogic, AuthorLogic>(new HierarchicalLifetimeManager());
|
||||
|
||||
return currentContainer;
|
||||
}
|
||||
}
|
||||
}
|
29
TestView/Book.cs
Normal file
29
TestView/Book.cs
Normal file
@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace TestView
|
||||
{
|
||||
public class Book
|
||||
{
|
||||
public string Genre;
|
||||
public string Author;
|
||||
public string Title;
|
||||
|
||||
public Book(string Genre, string Author, string Title)
|
||||
{
|
||||
this.Genre = Genre;
|
||||
this.Author = Author;
|
||||
this.Title = Title;
|
||||
}
|
||||
|
||||
public Book()
|
||||
{
|
||||
Genre = string.Empty;
|
||||
Author = string.Empty;
|
||||
Title= string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
26
TestView/BookInfo.cs
Normal file
26
TestView/BookInfo.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
280
TestView/Form1.Designer.cs
generated
Normal file
280
TestView/Form1.Designer.cs
generated
Normal file
@ -0,0 +1,280 @@
|
||||
namespace TestView
|
||||
{
|
||||
partial class Form1
|
||||
{
|
||||
/// <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();
|
||||
buttonAdd = new Button();
|
||||
buttonClear = new Button();
|
||||
buttonSelect = new Button();
|
||||
list_with_choice = new ViewComponents.List_with_choice();
|
||||
input_text = new ViewComponents.Input_text();
|
||||
buttonDip = new Button();
|
||||
buttonVal = new Button();
|
||||
buttonCheck = new Button();
|
||||
buttonIerarhy = new Button();
|
||||
buttonAddBook = new Button();
|
||||
buttonGetValue = new Button();
|
||||
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
|
||||
//
|
||||
buttonAdd.Location = new Point(25, 137);
|
||||
buttonAdd.Name = "buttonAdd";
|
||||
buttonAdd.Size = new Size(94, 29);
|
||||
buttonAdd.TabIndex = 1;
|
||||
buttonAdd.Text = "Добавить";
|
||||
buttonAdd.UseVisualStyleBackColor = true;
|
||||
buttonAdd.Click += buttonAdd_Click;
|
||||
//
|
||||
// buttonClear
|
||||
//
|
||||
buttonClear.Location = new Point(163, 137);
|
||||
buttonClear.Name = "buttonClear";
|
||||
buttonClear.Size = new Size(94, 29);
|
||||
buttonClear.TabIndex = 2;
|
||||
buttonClear.Text = "Очистить";
|
||||
buttonClear.UseVisualStyleBackColor = true;
|
||||
buttonClear.Click += buttonClear_Click;
|
||||
//
|
||||
// buttonSelect
|
||||
//
|
||||
buttonSelect.Location = new Point(60, 172);
|
||||
buttonSelect.Name = "buttonSelect";
|
||||
buttonSelect.Size = new Size(163, 29);
|
||||
buttonSelect.TabIndex = 3;
|
||||
buttonSelect.Text = "Выбранный элемент";
|
||||
buttonSelect.UseVisualStyleBackColor = true;
|
||||
buttonSelect.Click += buttonSelect_Click;
|
||||
//
|
||||
// list_with_choice
|
||||
//
|
||||
list_with_choice.Element = "";
|
||||
list_with_choice.Location = new Point(25, 12);
|
||||
list_with_choice.Name = "list_with_choice";
|
||||
list_with_choice.Size = new Size(232, 119);
|
||||
list_with_choice.TabIndex = 4;
|
||||
list_with_choice.SelectedItemChange += list_with_choice_SelectedItemChange;
|
||||
//
|
||||
// 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;
|
||||
input_text.ItemChange += input_text_ItemChange;
|
||||
//
|
||||
// buttonDip
|
||||
//
|
||||
buttonDip.Location = new Point(312, 137);
|
||||
buttonDip.Name = "buttonDip";
|
||||
buttonDip.Size = new Size(94, 29);
|
||||
buttonDip.TabIndex = 6;
|
||||
buttonDip.Text = "Диапазон";
|
||||
buttonDip.UseVisualStyleBackColor = true;
|
||||
buttonDip.Click += buttonDip_Click;
|
||||
//
|
||||
// buttonVal
|
||||
//
|
||||
buttonVal.Location = new Point(458, 137);
|
||||
buttonVal.Name = "buttonVal";
|
||||
buttonVal.Size = new Size(94, 29);
|
||||
buttonVal.TabIndex = 7;
|
||||
buttonVal.Text = "Значение";
|
||||
buttonVal.UseVisualStyleBackColor = true;
|
||||
buttonVal.Click += buttonVal_Click;
|
||||
//
|
||||
// buttonCheck
|
||||
//
|
||||
buttonCheck.Location = new Point(360, 172);
|
||||
buttonCheck.Name = "buttonCheck";
|
||||
buttonCheck.Size = new Size(143, 29);
|
||||
buttonCheck.TabIndex = 8;
|
||||
buttonCheck.Text = " Проверка текста";
|
||||
buttonCheck.UseVisualStyleBackColor = true;
|
||||
buttonCheck.Click += buttonCheck_Click;
|
||||
//
|
||||
// buttonIerarhy
|
||||
//
|
||||
buttonIerarhy.Location = new Point(652, 32);
|
||||
buttonIerarhy.Name = "buttonIerarhy";
|
||||
buttonIerarhy.Size = new Size(168, 29);
|
||||
buttonIerarhy.TabIndex = 10;
|
||||
buttonIerarhy.Text = "Задать иерархию";
|
||||
buttonIerarhy.UseVisualStyleBackColor = true;
|
||||
buttonIerarhy.Click += buttonIerarhy_Click;
|
||||
//
|
||||
// buttonAddBook
|
||||
//
|
||||
buttonAddBook.Location = new Point(652, 67);
|
||||
buttonAddBook.Name = "buttonAddBook";
|
||||
buttonAddBook.Size = new Size(168, 29);
|
||||
buttonAddBook.TabIndex = 11;
|
||||
buttonAddBook.Text = "Добавить книги";
|
||||
buttonAddBook.UseVisualStyleBackColor = true;
|
||||
buttonAddBook.Click += buttonAddBook_Click;
|
||||
//
|
||||
// buttonGetValue
|
||||
//
|
||||
buttonGetValue.Location = new Point(652, 102);
|
||||
buttonGetValue.Name = "buttonGetValue";
|
||||
buttonGetValue.Size = new Size(168, 29);
|
||||
buttonGetValue.TabIndex = 12;
|
||||
buttonGetValue.Text = "Получить значение";
|
||||
buttonGetValue.UseVisualStyleBackColor = true;
|
||||
buttonGetValue.Click += buttonGetValue_Click;
|
||||
//
|
||||
// buttonGetIndex
|
||||
//
|
||||
buttonGetIndex.Location = new Point(652, 137);
|
||||
buttonGetIndex.Name = "buttonGetIndex";
|
||||
buttonGetIndex.Size = new Size(168, 29);
|
||||
buttonGetIndex.TabIndex = 13;
|
||||
buttonGetIndex.Text = "Получить индекс";
|
||||
buttonGetIndex.UseVisualStyleBackColor = true;
|
||||
buttonGetIndex.Click += buttonGetIndex_Click;
|
||||
//
|
||||
// buttonSetIndex
|
||||
//
|
||||
buttonSetIndex.Location = new Point(652, 172);
|
||||
buttonSetIndex.Name = "buttonSetIndex";
|
||||
buttonSetIndex.Size = new Size(168, 29);
|
||||
buttonSetIndex.TabIndex = 14;
|
||||
buttonSetIndex.Text = "Установить индекс";
|
||||
buttonSetIndex.UseVisualStyleBackColor = true;
|
||||
buttonSetIndex.Click += buttonSetIndex_Click;
|
||||
//
|
||||
// myTreeView
|
||||
//
|
||||
myTreeView.Location = new Point(629, 218);
|
||||
myTreeView.Name = "myTreeView";
|
||||
myTreeView.SelectedNodeIndex = -1;
|
||||
myTreeView.Size = new Size(201, 192);
|
||||
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(899, 600);
|
||||
Controls.Add(buttonChart);
|
||||
Controls.Add(buttonTestPdfTable);
|
||||
Controls.Add(buttonPdfImages);
|
||||
Controls.Add(myTreeView);
|
||||
Controls.Add(buttonSetIndex);
|
||||
Controls.Add(buttonGetIndex);
|
||||
Controls.Add(buttonGetValue);
|
||||
Controls.Add(buttonAddBook);
|
||||
Controls.Add(buttonIerarhy);
|
||||
Controls.Add(buttonCheck);
|
||||
Controls.Add(buttonVal);
|
||||
Controls.Add(buttonDip);
|
||||
Controls.Add(input_text);
|
||||
Controls.Add(list_with_choice);
|
||||
Controls.Add(buttonSelect);
|
||||
Controls.Add(buttonClear);
|
||||
Controls.Add(buttonAdd);
|
||||
Name = "Form1";
|
||||
Text = "Form1";
|
||||
Load += Form1_Load;
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private Button buttonAdd;
|
||||
private Button buttonClear;
|
||||
private Button buttonSelect;
|
||||
private ViewComponents.List_with_choice list_with_choice;
|
||||
private ViewComponents.Input_text input_text;
|
||||
private Button buttonDip;
|
||||
private Button buttonVal;
|
||||
private Button buttonCheck;
|
||||
private Button buttonIerarhy;
|
||||
private Button buttonAddBook;
|
||||
private Button buttonGetValue;
|
||||
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;
|
||||
}
|
||||
}
|
168
TestView/Form1.cs
Normal file
168
TestView/Form1.cs
Normal file
@ -0,0 +1,168 @@
|
||||
using MigraDoc.DocumentObjectModel;
|
||||
using System.IO;
|
||||
using System.Windows.Forms;
|
||||
using ViewComponents.Exeption;
|
||||
using ViewComponents.NotVisualComponents;
|
||||
|
||||
namespace TestView
|
||||
{
|
||||
public partial class Form1 : Form
|
||||
{
|
||||
public Form1()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void buttonAdd_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
list_with_choice.Fill_List("ïåðâûé");
|
||||
list_with_choice.Fill_List("âòîðîé");
|
||||
list_with_choice.Fill_List("òðåòèé");
|
||||
list_with_choice.Fill_List("÷åòâ¸ðòûé");
|
||||
}
|
||||
|
||||
private void buttonClear_Click(object sender, EventArgs e)
|
||||
{
|
||||
list_with_choice.Clean_List();
|
||||
}
|
||||
|
||||
private void buttonSelect_Click(object sender, EventArgs e)
|
||||
{
|
||||
MessageBox.Show(list_with_choice.Element ?? "null", "Âûáðàííûé ýëåìåíò");
|
||||
}
|
||||
|
||||
private void list_with_choice_SelectedItemChange(string obj)
|
||||
{
|
||||
MessageBox.Show(obj, "Ñîáûòèå âûáîðà ýëåìåíòà");
|
||||
}
|
||||
|
||||
private void buttonDip_Click(object sender, EventArgs e)
|
||||
{
|
||||
input_text.MinLen = 5;
|
||||
input_text.MaxLen = 25;
|
||||
|
||||
MessageBox.Show($"Min: {input_text.MinLen}; Max: {input_text.MaxLen}");
|
||||
}
|
||||
|
||||
private void buttonVal_Click(object sender, EventArgs e)
|
||||
{
|
||||
input_text.Element = "Sample text";
|
||||
}
|
||||
|
||||
private void input_text_ItemChange(string obj)
|
||||
{
|
||||
MessageBox.Show(obj, "Ñîáûòèå èçìåíåíèÿ òåêñòà");
|
||||
}
|
||||
|
||||
private void buttonCheck_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (input_text.Element.Equals("Range exeption"))
|
||||
throw new TextBoundsNotSetExeption("Äèàïàçîí íå çàäàí");
|
||||
if (input_text.Element.Equals("Value exeption"))
|
||||
throw new TextOutOfBoundsExeption("Ñëîâî âíå äèàïàçîíà");
|
||||
|
||||
MessageBox.Show(input_text.Element, "×åðåç ñâîéñòâî");
|
||||
}
|
||||
catch (TextBoundsNotSetExeption ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message);
|
||||
}
|
||||
catch (TextOutOfBoundsExeption ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonIerarhy_Click(object sender, EventArgs e)
|
||||
{
|
||||
myTreeView.setHierarchy(new List<(string, bool)> { ("Genre", false), ("Author", false), ("Title", true) });
|
||||
MessageBox.Show("Èåðàðõèÿ çàäàíà");
|
||||
}
|
||||
|
||||
private void buttonAddBook_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
myTreeView.addItem(new Book("Ðîìàí", "Ãîãîëü Í.Â.", "̸ðòâûå äóøè"));
|
||||
myTreeView.addItem(new Book("Ðîìàí", "Òóðãåíåâ È.Ñ.", "Îòöû è äåòè"));
|
||||
myTreeView.addItem(new Book("Ôàíòàñòèêà", "Äæîðäæ Îðóýëë", "1984"));
|
||||
myTreeView.addItem(new Book("Ôàíòàñòèêà", "Ðîóëèíã", "Ãàððè Ïîòòåð"));
|
||||
}
|
||||
|
||||
private void buttonGetValue_Click(object sender, EventArgs e)
|
||||
{
|
||||
Book? book = myTreeView.getSelecetedNodeValue<Book>();
|
||||
if (book == null) return;
|
||||
MessageBox.Show("Æàíð: " + book.Genre + ", Àâòîð: " + book.Author + ", Íàçâàíèå: " + book.Title);
|
||||
}
|
||||
|
||||
private void buttonGetIndex_Click(object sender, EventArgs e)
|
||||
{
|
||||
MessageBox.Show(myTreeView.SelectedNodeIndex.ToString());
|
||||
}
|
||||
|
||||
private void buttonSetIndex_Click(object sender, EventArgs e)
|
||||
{
|
||||
myTreeView.SelectedNodeIndex = 1;
|
||||
}
|
||||
|
||||
private void Form1_Load(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
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\\Äîêóìåíòû\\test.pdf";
|
||||
MessageBox.Show(path);
|
||||
if (pdfImages1.CreatePdfDoc(new ImagesForPDF(path, "Ðóññêàÿ ëèòåðàòóðà", files))) MessageBox.Show("Óñïåõ!");
|
||||
else MessageBox.Show("Îøèáêà, ïðîâåðüòå êîíñîëü");
|
||||
}
|
||||
|
||||
private void buttonTestPdfTable_Click(object sender, EventArgs e)
|
||||
{
|
||||
List<BookInfo> books = new List<BookInfo>
|
||||
{
|
||||
new BookInfo("Ýêñìî", "Íèêîëàé", "Ãîãîëü", "1809-1852", "̸ðòâûå äóøè"),
|
||||
new BookInfo("Òðèóìô", "Èâàí", "Òóðãåíåâ", "1818-1883", "Îòöû è äåòè"),
|
||||
new BookInfo("Ýêñìî", "Äæîðäæ", "Îðóýëë", "1903-1950", "1984"),
|
||||
new BookInfo("ÀÑÒ", "Äæîàíà", "Ðîóëèíã", "1965 - í.â.", "Ãàððè Ïîòòåð")
|
||||
};
|
||||
|
||||
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\\Äîêóìåíòû\\test.pdf";
|
||||
|
||||
List<(string, string)> headers = new List<(string, string)> { ("id", "Id"), ("Redaction", "Ðåäàêöèÿ"),
|
||||
("", "Àâòîð"), ("AuthorName", "Èìÿ"),
|
||||
("AuthorSurname", "Ôàìèëèÿ"), ("AuthorLife", "Ãîäû æèçíè"),
|
||||
("Title", "Íàçâàíèå êíèãè") };
|
||||
|
||||
if (pdfTable1.createTable(new DataForPDFTable<BookInfo>(path, "test2", heights, merges, headers, books))) MessageBox.Show("Óñïåõ");
|
||||
}
|
||||
|
||||
private void buttonChart_Click(object sender, EventArgs e)
|
||||
{
|
||||
string path = "C:\\Users\\xarla\\OneDrive\\Äîêóìåíòû\\chart.pdf";
|
||||
List<(double, string)> elements = new List<(double, string)>
|
||||
{
|
||||
(200, "̸ðòâûå äóøè"),
|
||||
(157, "Ìóìó"),
|
||||
(344, "Îòöû è Äåòè"),
|
||||
(588, "Ãàððè Ïîòòåð"),
|
||||
(286, "Ìåòðî 2033")
|
||||
};
|
||||
|
||||
if(pieChartpdf1.CreatePieChart(new DataForPDFPieChart(path, "Çàãîëîâîê", "Êðóãîâàÿ äèàãðàììà", DiagramLegendEnum.Top ,"Ïðîäàæè êíèã", elements))) MessageBox.Show("Óñïåõ");
|
||||
}
|
||||
}
|
||||
}
|
132
TestView/Form1.resx
Normal file
132
TestView/Form1.resx
Normal file
@ -0,0 +1,132 @@
|
||||
<?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>
|
||||
<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>
|
17
TestView/Program.cs
Normal file
17
TestView/Program.cs
Normal file
@ -0,0 +1,17 @@
|
||||
namespace TestView
|
||||
{
|
||||
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 Form1());
|
||||
}
|
||||
}
|
||||
}
|
31
TestView/TestView.csproj
Normal file
31
TestView/TestView.csproj
Normal file
@ -0,0 +1,31 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net6.0-windows</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<RootNamespace>TestView</RootNamespace>
|
||||
</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>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Update="Program.cs">
|
||||
<CustomToolNamespace></CustomToolNamespace>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
55
TestView/TestView.sln
Normal file
55
TestView/TestView.sln
Normal file
@ -0,0 +1,55 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.5.33627.172
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestView", "TestView.csproj", "{637B2B5F-8015-4DE8-B264-74F24B115812}"
|
||||
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
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{637B2B5F-8015-4DE8-B264-74F24B115812}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{637B2B5F-8015-4DE8-B264-74F24B115812}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{637B2B5F-8015-4DE8-B264-74F24B115812}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{637B2B5F-8015-4DE8-B264-74F24B115812}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{45A652EE-B79B-4F5B-BB2A-2A51F5BEA2F1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{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
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {C28CD353-C746-4FFE-9D0D-D48764205D7B}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
18
ViewComponents/Exeption/TextBoundsNotSetExeption.cs
Normal file
18
ViewComponents/Exeption/TextBoundsNotSetExeption.cs
Normal file
@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ViewComponents.Exeption
|
||||
{
|
||||
[Serializable]
|
||||
public class TextBoundsNotSetExeption: ApplicationException
|
||||
{
|
||||
public TextBoundsNotSetExeption() : base() { }
|
||||
public TextBoundsNotSetExeption(string message) : base(message) { }
|
||||
public TextBoundsNotSetExeption(string message, Exception exception) : base(message, exception) { }
|
||||
protected TextBoundsNotSetExeption(SerializationInfo info, StreamingContext contex) : base(info, contex) { }
|
||||
}
|
||||
}
|
18
ViewComponents/Exeption/TextOutOfBoundsExeption.cs
Normal file
18
ViewComponents/Exeption/TextOutOfBoundsExeption.cs
Normal file
@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ViewComponents.Exeption
|
||||
{
|
||||
[Serializable]
|
||||
public class TextOutOfBoundsExeption: ApplicationException
|
||||
{
|
||||
public TextOutOfBoundsExeption() : base() { }
|
||||
public TextOutOfBoundsExeption(string message) : base(message) { }
|
||||
public TextOutOfBoundsExeption(string message, Exception exception) : base(message, exception) { }
|
||||
protected TextOutOfBoundsExeption(SerializationInfo info, StreamingContext contex) : base(info, contex) { }
|
||||
}
|
||||
}
|
28
ViewComponents/NotVisualComponents/DataForPDFPieChart.cs
Normal file
28
ViewComponents/NotVisualComponents/DataForPDFPieChart.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
27
ViewComponents/NotVisualComponents/DataForPDFTable.cs
Normal file
27
ViewComponents/NotVisualComponents/DataForPDFTable.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
16
ViewComponents/NotVisualComponents/DiagramLegendEnum.cs
Normal file
16
ViewComponents/NotVisualComponents/DiagramLegendEnum.cs
Normal 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,
|
||||
}
|
||||
}
|
22
ViewComponents/NotVisualComponents/ImagesForPDF.cs
Normal file
22
ViewComponents/NotVisualComponents/ImagesForPDF.cs
Normal 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;
|
||||
}
|
||||
}
|
36
ViewComponents/NotVisualComponents/PdfImages.Designer.cs
generated
Normal file
36
ViewComponents/NotVisualComponents/PdfImages.Designer.cs
generated
Normal 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
|
||||
}
|
||||
}
|
73
ViewComponents/NotVisualComponents/PdfImages.cs
Normal file
73
ViewComponents/NotVisualComponents/PdfImages.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
36
ViewComponents/NotVisualComponents/PdfTable.Designer.cs
generated
Normal file
36
ViewComponents/NotVisualComponents/PdfTable.Designer.cs
generated
Normal 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
|
||||
}
|
||||
}
|
177
ViewComponents/NotVisualComponents/PdfTable.cs
Normal file
177
ViewComponents/NotVisualComponents/PdfTable.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
36
ViewComponents/NotVisualComponents/PieChartPDF.Designer.cs
generated
Normal file
36
ViewComponents/NotVisualComponents/PieChartPDF.Designer.cs
generated
Normal 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
|
||||
}
|
||||
}
|
85
ViewComponents/NotVisualComponents/PieChartPDF.cs
Normal file
85
ViewComponents/NotVisualComponents/PieChartPDF.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
23
ViewComponents/ViewComponents.csproj
Normal file
23
ViewComponents/ViewComponents.csproj
Normal file
@ -0,0 +1,23 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0-windows</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<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>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
58
ViewComponents/VisualComponents/Input_text.Designer.cs
generated
Normal file
58
ViewComponents/VisualComponents/Input_text.Designer.cs
generated
Normal file
@ -0,0 +1,58 @@
|
||||
namespace ViewComponents
|
||||
{
|
||||
partial class Input_text
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
textBox1 = new TextBox();
|
||||
SuspendLayout();
|
||||
//
|
||||
// textBox1
|
||||
//
|
||||
textBox1.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||
textBox1.Location = new Point(19, 25);
|
||||
textBox1.Name = "textBox1";
|
||||
textBox1.Size = new Size(154, 27);
|
||||
textBox1.TabIndex = 0;
|
||||
textBox1.TextChanged += textBox1_TextChanged;
|
||||
//
|
||||
// Input_text
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
Controls.Add(textBox1);
|
||||
Name = "Input_text";
|
||||
Size = new Size(192, 79);
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private TextBox textBox1;
|
||||
}
|
||||
}
|
48
ViewComponents/VisualComponents/Input_text.cs
Normal file
48
ViewComponents/VisualComponents/Input_text.cs
Normal file
@ -0,0 +1,48 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using ViewComponents.Exeption;
|
||||
|
||||
namespace ViewComponents
|
||||
{
|
||||
public partial class Input_text : UserControl
|
||||
{
|
||||
public Input_text()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public event Action<string?> ItemChange;
|
||||
|
||||
public int MinLen { get; set; } = -1;
|
||||
public int MaxLen { get; set; } = -1;
|
||||
|
||||
public string Element
|
||||
{
|
||||
get
|
||||
{
|
||||
if (MinLen < 0 || MaxLen < 0) return "Range exeption";
|
||||
if (textBox1.Text.Length < MinLen || textBox1.Text.Length > MaxLen) return "Value exeption";
|
||||
return textBox1.Text;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (MinLen >= 0 && MaxLen >= 0 && value != null && value.Length >= MinLen && value.Length <= MaxLen) textBox1.Text = value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void textBox1_TextChanged(object sender, EventArgs e)
|
||||
{
|
||||
ItemChange?.Invoke(textBox1.Text);
|
||||
}
|
||||
}
|
||||
}
|
60
ViewComponents/VisualComponents/Input_text.resx
Normal file
60
ViewComponents/VisualComponents/Input_text.resx
Normal 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>
|
58
ViewComponents/VisualComponents/List_with_choice.Designer.cs
generated
Normal file
58
ViewComponents/VisualComponents/List_with_choice.Designer.cs
generated
Normal file
@ -0,0 +1,58 @@
|
||||
namespace ViewComponents
|
||||
{
|
||||
partial class List_with_choice
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
checkedListBox1 = new CheckedListBox();
|
||||
SuspendLayout();
|
||||
//
|
||||
// checkedListBox1
|
||||
//
|
||||
checkedListBox1.Dock = DockStyle.Fill;
|
||||
checkedListBox1.FormattingEnabled = true;
|
||||
checkedListBox1.Location = new Point(0, 0);
|
||||
checkedListBox1.Name = "checkedListBox1";
|
||||
checkedListBox1.Size = new Size(208, 150);
|
||||
checkedListBox1.TabIndex = 0;
|
||||
checkedListBox1.SelectedIndexChanged += checkedListBox1_SelectedIndexChanged;
|
||||
//
|
||||
// List_with_choice
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
Controls.Add(checkedListBox1);
|
||||
Name = "List_with_choice";
|
||||
Size = new Size(208, 150);
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private CheckedListBox checkedListBox1;
|
||||
}
|
||||
}
|
56
ViewComponents/VisualComponents/List_with_choice.cs
Normal file
56
ViewComponents/VisualComponents/List_with_choice.cs
Normal file
@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace ViewComponents
|
||||
{
|
||||
public partial class List_with_choice : UserControl
|
||||
{
|
||||
public List_with_choice()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public event Action<string?> SelectedItemChange;
|
||||
|
||||
public string? Element
|
||||
{
|
||||
get
|
||||
{
|
||||
if (checkedListBox1.SelectedItem != null) return checkedListBox1.SelectedItem.ToString();
|
||||
else return string.Empty;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value != null && checkedListBox1.Items.Contains(value)) checkedListBox1.SelectedItem = value;
|
||||
}
|
||||
}
|
||||
|
||||
public void Fill_List(string str) //метод заполнения списка
|
||||
{
|
||||
if (str == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
checkedListBox1.Items.Add(str);
|
||||
}
|
||||
public void Clean_List() //метод очистки списка
|
||||
{
|
||||
checkedListBox1.Items.Clear();
|
||||
}
|
||||
|
||||
private void checkedListBox1_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
SelectedItemChange?.Invoke(checkedListBox1.SelectedItem.ToString());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
60
ViewComponents/VisualComponents/List_with_choice.resx
Normal file
60
ViewComponents/VisualComponents/List_with_choice.resx
Normal 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>
|
55
ViewComponents/VisualComponents/MyTreeView.Designer.cs
generated
Normal file
55
ViewComponents/VisualComponents/MyTreeView.Designer.cs
generated
Normal file
@ -0,0 +1,55 @@
|
||||
namespace ViewComponents
|
||||
{
|
||||
partial class MyTreeView
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
treeView = new TreeView();
|
||||
SuspendLayout();
|
||||
//
|
||||
// treeView
|
||||
//
|
||||
treeView.Location = new Point(13, 18);
|
||||
treeView.Name = "treeView";
|
||||
treeView.Size = new Size(176, 148);
|
||||
treeView.TabIndex = 0;
|
||||
//
|
||||
// MyTreeView
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
Controls.Add(treeView);
|
||||
Name = "MyTreeView";
|
||||
Size = new Size(204, 192);
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private System.Windows.Forms.TreeView treeView;
|
||||
}
|
||||
}
|
88
ViewComponents/VisualComponents/MyTreeView.cs
Normal file
88
ViewComponents/VisualComponents/MyTreeView.cs
Normal file
@ -0,0 +1,88 @@
|
||||
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 static System.Windows.Forms.VisualStyles.VisualStyleElement;
|
||||
|
||||
namespace ViewComponents
|
||||
{
|
||||
public partial class MyTreeView : UserControl
|
||||
{
|
||||
public MyTreeView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
private List<(string, bool)> hierarchy = new List<(string, bool)>();
|
||||
|
||||
public int SelectedNodeIndex
|
||||
{
|
||||
get
|
||||
{
|
||||
return treeView.SelectedNode?.Index ?? -1;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (treeView.SelectedNode == null) treeView.SelectedNode = value >= 0 && value < treeView.Nodes.Count ? treeView.Nodes[value] : treeView.SelectedNode;
|
||||
else treeView.SelectedNode = value >= 0 && value < treeView.SelectedNode.Nodes.Count ? treeView.SelectedNode.Nodes[value] : treeView.SelectedNode;
|
||||
}
|
||||
}
|
||||
|
||||
public T? getSelecetedNodeValue<T>()
|
||||
{
|
||||
if (treeView.SelectedNode == null || treeView.SelectedNode.Nodes.Count > 0) return default(T);
|
||||
|
||||
TreeNode? node = treeView.SelectedNode;
|
||||
|
||||
var type = typeof(T);
|
||||
var fields = type.GetFields();
|
||||
|
||||
var item = Activator.CreateInstance(type);
|
||||
|
||||
while (node != null)
|
||||
{
|
||||
var field = fields.FirstOrDefault(x => x.Name == node.Name);
|
||||
if (field != null)
|
||||
{
|
||||
field.SetValue(item, node.Text);
|
||||
}
|
||||
node = node.Parent;
|
||||
}
|
||||
|
||||
return item != null ? (T)item : default(T);
|
||||
}
|
||||
|
||||
public void setHierarchy(List<(string, bool)> fields)
|
||||
{
|
||||
hierarchy = fields;
|
||||
}
|
||||
|
||||
public void addItem<T>(T item)
|
||||
{
|
||||
var type = typeof(T);
|
||||
var fields = type.GetFields();
|
||||
TreeNodeCollection nodes = treeView.Nodes;
|
||||
for (int i = 0; i < hierarchy.Count; i++)
|
||||
{
|
||||
var field = fields.FirstOrDefault(x => x.Name.Equals(hierarchy[i].Item1));
|
||||
if (field is not null)
|
||||
{
|
||||
var node = nodes.Find(field.Name, false).FirstOrDefault(x => x.Text == field.GetValue(item).ToString());
|
||||
if (node is not null && !hierarchy[i].Item2)
|
||||
{
|
||||
nodes = node.Nodes;
|
||||
}
|
||||
else
|
||||
{
|
||||
TreeNode newNode = nodes.Add(field.Name, field.GetValue(item).ToString());
|
||||
nodes = newNode.Nodes;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
60
ViewComponents/VisualComponents/MyTreeView.resx
Normal file
60
ViewComponents/VisualComponents/MyTreeView.resx
Normal 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>
|
0
nuget.config.bak
Normal file
0
nuget.config.bak
Normal file
Loading…
Reference in New Issue
Block a user