упс, 2 и начало 3 лабы

This commit is contained in:
2024-09-26 12:51:52 +04:00
parent 9e89370e0c
commit 7408afe8aa
46 changed files with 1626 additions and 65 deletions

View File

@@ -0,0 +1,68 @@
using EmployeesContracts.BindingModels;
using EmployeesContracts.BusinessLogicsContracts;
using EmployeesContracts.StorageContracts;
using EmployeesContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EmployeeLogic.BusinessLogics
{
public class EmployeeLogic : IEmployeeLogic
{
private readonly IEmployeeStorage _employeeStorage;
public EmployeeLogic(IEmployeeStorage employeeStorage)
{
_employeeStorage = employeeStorage;
}
public void CreateOrUpdate(EmployeeBindingModel model)
{
var element = _employeeStorage.GetElement(
new EmployeeBindingModel
{
Autobiography = model.Autobiography,
Name = model.Name,
Post = model.Post,
Upgrade = model.Upgrade
});
if (element != null && element.Id != model.Id)
{
throw new Exception("Сотрудник с таким именем уже существует");
}
if (model.Id.HasValue)
{
_employeeStorage.Update(model);
}
else
{
_employeeStorage.Insert(model);
}
}
public void Delete(EmployeeBindingModel model)
{
var element = _employeeStorage.GetElement(new EmployeeBindingModel { Id = model.Id });
if (element == null)
{
throw new Exception("Сотрудник не найден");
}
_employeeStorage.Delete(model);
}
public List<EmployeeViewModel> Read(EmployeeBindingModel model)
{
if (model == null)
{
return _employeeStorage.GetFullList();
}
if (model.Id.HasValue)
{
return new List<EmployeeViewModel> { _employeeStorage.GetElement(model) };
}
return _employeeStorage.GetFilteredList(model);
}
}
}

View File

@@ -0,0 +1,66 @@
using EmployeesContracts.BindingModels;
using EmployeesContracts.BusinessLogicsContracts;
using EmployeesContracts.StorageContracts;
using EmployeesContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EmployeeLogic.BusinessLogics
{
public class PostLogic : IPostLogic
{
private readonly IPostStorage _postStorage;
public PostLogic(IPostStorage postStorage)
{
_postStorage = postStorage;
}
public void CreateOrUpdate(PostBindingModel model)
{
var element = _postStorage.GetElement(
new PostBindingModel
{
Name = model.Name
});
if (element != null && element.Id != model.Id)
{
throw new Exception("Такая должность уже существует");
}
if (model.Id.HasValue)
{
_postStorage.Update(model);
}
else
{
_postStorage.Insert(model);
}
}
public void Delete(PostBindingModel model)
{
var element = _postStorage.GetElement(new PostBindingModel { Id = model.Id });
if (element == null)
{
throw new Exception("Должность не найдена");
}
_postStorage.Delete(model);
}
public List<PostViewModel> Read(PostBindingModel model)
{
if (model == null)
{
return _postStorage.GetFullList();
}
if (model.Id.HasValue)
{
return new List<PostViewModel> { _postStorage.GetElement(model) };
}
return _postStorage.GetFilteredList(model);
}
}
}

View File

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

View File

@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EmployeesContracts.BindingModels
{
public class EmployeeBindingModel
{
public int? Id { get; set; }
public string Name { get; set; }
public string Autobiography { get; set; }
public string Post { get; set; }
public DateTime? Upgrade { get; set; }
}
}

View File

@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EmployeesContracts.BindingModels
{
public class PostBindingModel
{
public int? Id { get; set; }
public string Name { get; set; }
}
}

View File

@@ -0,0 +1,17 @@
using EmployeesContracts.BindingModels;
using EmployeesContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EmployeesContracts.BusinessLogicsContracts
{
public interface IEmployeeLogic
{
List<EmployeeViewModel> Read(EmployeeBindingModel model);
void CreateOrUpdate(EmployeeBindingModel model);
void Delete(EmployeeBindingModel model);
}
}

View File

@@ -0,0 +1,17 @@
using EmployeesContracts.BindingModels;
using EmployeesContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EmployeesContracts.BusinessLogicsContracts
{
public interface IPostLogic
{
List<PostViewModel> Read(PostBindingModel model);
void CreateOrUpdate(PostBindingModel model);
void Delete(PostBindingModel model);
}
}

View File

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

View File

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

View File

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

View File

@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EmployeesContracts.ViewModels
{
public class EmployeeViewModel
{
public int? Id { get; set; }
[DisplayName("Название")]
public string Name { get; set; }
[DisplayName("Автобиография")]
public string Autobiography { get; set; }
[DisplayName("Должность")]
public string Post { get; set; }
[DisplayName("Дата повышения квалификации")]
public DateTime? Upgrade { get; set; }
}
}

View File

@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EmployeesContracts.ViewModels
{
public class PostViewModel
{
public int? Id { get; set; }
public string Name { get; set; }
}
}

View File

@@ -0,0 +1,22 @@
using EmployeesDatabaseImplement.Models;
using Microsoft.EntityFrameworkCore;
namespace EmployeesDatabaseImplement
{
public class EmployeesDatabase : DbContext
{
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (optionsBuilder.IsConfigured == false)
{
optionsBuilder.UseSqlServer(@"Data Source=localhost\SQLEXPRESS;Initial Catalog=DatabaseEmployees;Integrated Security=True;MultipleActiveResultSets=True;TrustServerCertificate=True");
}
base.OnConfiguring(optionsBuilder);
}
public virtual DbSet<Employee> Employees { set; get; }
public virtual DbSet<Post> Posts { set; get; }
}
}

View File

@@ -0,0 +1,26 @@
<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.17" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.17">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.17" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.17">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\EmployeesContracts\EmployeesContracts.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,125 @@
using EmployeesContracts.BindingModels;
using EmployeesContracts.StorageContracts;
using EmployeesContracts.ViewModels;
using EmployeesDatabaseImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EmployeesDatabaseImplement.Implements
{
public class EmployeeStorage : IEmployeeStorage
{
public void Delete(EmployeeBindingModel model)
{
var context = new EmployeesDatabase();
var employee = context.Employees.FirstOrDefault(rec => rec.Id == model.Id);
if (employee != null)
{
context.Employees.Remove(employee);
context.SaveChanges();
}
else
{
throw new Exception("Сотрудник не найден");
}
}
public EmployeeViewModel GetElement(EmployeeBindingModel model)
{
if (model == null)
{
return null;
}
using var context = new EmployeesDatabase();
var employee = context.Employees
.ToList()
.FirstOrDefault(rec => rec.Id == model.Id);
return employee != null ? CreateModel(employee) : null;
}
public List<EmployeeViewModel> GetFilteredList(EmployeeBindingModel model)
{
var context = new EmployeesDatabase();
return context.Employees
.Where(employee => employee.Name.Contains(model.Name) && employee.Post.Contains(model.Post))
.ToList()
.Select(CreateModel)
.ToList();
}
public List<EmployeeViewModel> GetFullList()
{
using (var context = new EmployeesDatabase())
{
return context.Employees
.ToList()
.Select(CreateModel)
.ToList();
}
}
public void Insert(EmployeeBindingModel model)
{
var context = new EmployeesDatabase();
var transaction = context.Database.BeginTransaction();
try
{
context.Employees.Add(CreateModel(model, new Employee()));
context.SaveChanges();
transaction.Commit();
}
catch
{
transaction.Rollback();
throw;
}
}
public void Update(EmployeeBindingModel model)
{
var context = new EmployeesDatabase();
var transaction = context.Database.BeginTransaction();
try
{
var employee = context.Employees.FirstOrDefault(rec => rec.Id == model.Id);
if (employee == null)
{
throw new Exception("Сотрудник не найден");
}
CreateModel(model, employee);
context.SaveChanges();
transaction.Commit();
}
catch
{
transaction.Rollback();
throw;
}
}
private static Employee CreateModel(EmployeeBindingModel model, Employee employee)
{
employee.Upgrade = model.Upgrade;
employee.Name = model.Name;
employee.Post = model.Post;
employee.Autobiography = model.Autobiography;
return employee;
}
private EmployeeViewModel CreateModel(Employee employee)
{
return new EmployeeViewModel
{
Id = employee.Id,
Upgrade = employee.Upgrade,
Name = employee.Name,
Post = employee.Post,
Autobiography = employee.Autobiography
};
}
}
}

View File

@@ -0,0 +1,120 @@
using EmployeesContracts.BindingModels;
using EmployeesContracts.StorageContracts;
using EmployeesContracts.ViewModels;
using EmployeesDatabaseImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EmployeesDatabaseImplement.Implements
{
public class PostStorage : IPostStorage
{
public void Delete(PostBindingModel model)
{
var context = new EmployeesDatabase();
var post = context.Posts.FirstOrDefault(rec => rec.Id == model.Id);
if (post != null)
{
context.Posts.Remove(post);
context.SaveChanges();
}
else
{
throw new Exception("Должность не найдена");
}
}
public PostViewModel GetElement(PostBindingModel model)
{
if (model == null)
{
return null;
}
using var context = new EmployeesDatabase();
var post = context.Posts
.ToList()
.FirstOrDefault(rec => rec.Id == model.Id || rec.Name == model.Name);
return post != null ? CreateModel(post) : null;
}
public List<PostViewModel> GetFilteredList(PostBindingModel model)
{
if (model == null)
{
return null;
}
using var context = new EmployeesDatabase();
return context.Posts
.Where(rec => rec.Name.Contains(model.Name))
.Select(CreateModel)
.ToList();
}
public List<PostViewModel> GetFullList()
{
using var context = new EmployeesDatabase();
return context.Posts
.Select(CreateModel)
.ToList();
}
public void Insert(PostBindingModel model)
{
var context = new EmployeesDatabase();
var transaction = context.Database.BeginTransaction();
try
{
context.Posts.Add(CreateModel(model, new Post()));
context.SaveChanges();
transaction.Commit();
}
catch
{
transaction.Rollback();
throw;
}
}
public void Update(PostBindingModel model)
{
var context = new EmployeesDatabase();
var transaction = context.Database.BeginTransaction();
try
{
var post = context.Posts.FirstOrDefault(rec => rec.Id == model.Id);
if (post == null)
{
throw new Exception("Должность не найдена");
}
CreateModel(model, post);
context.SaveChanges();
transaction.Commit();
}
catch
{
transaction.Rollback();
throw;
}
}
private static Post CreateModel(PostBindingModel model, Post post)
{
post.Name = model.Name;
return post;
}
private static PostViewModel CreateModel(Post post)
{
return new PostViewModel
{
Id = post.Id,
Name = post.Name
};
}
}
}

View File

@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EmployeesDatabaseImplement.Models
{
public class Employee
{
public int Id { get; set; }
[Required]
public string Name { get; set; }
[Required]
public string Autobiography { get; set; }
[Required]
public string Post { get; set; }
public DateTime? Upgrade { get; set; }
}
}

View File

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

View File

@@ -4,7 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Valova_App
namespace custom_App
{
public class Book
{

View File

@@ -1,4 +1,4 @@
namespace Valova_App
namespace custom_App
{
partial class Form1
{
@@ -28,9 +28,10 @@
/// </summary>
private void InitializeComponent()
{
valovaComboBox = new Valova_VisualComponents.ValovaComboBox();
valovaTextBox = new Valova_VisualComponents.ValovaTextBox();
valovaListBox = new Valova_VisualComponents.ValovaListBox();
components = new System.ComponentModel.Container();
customComboBox = new Valova_VisualComponents.customComboBox();
customTextBox = new Valova_VisualComponents.customTextBox();
customListBox = new Valova_VisualComponents.customListBox();
buttonAddToComboBox = new Button();
buttonClearComboBox = new Button();
textBoxForComboBox = new TextBox();
@@ -42,36 +43,41 @@
textBoxPar = new TextBox();
button1 = new Button();
buttonGet = new Button();
ButtonDocumentWithContextTextPdf = new Button();
ButtonDocumentWithChartLinePdf = new Button();
ButtonDocumentWithTableHeaderRowPdf = new Button();
componentTextToPdf = new Valova_VisualComponents.ComponentTextToPdf(components);
componentTableToPdf = new Valova_VisualComponents.ComponentTableToPdf(components);
componentDiagramToPdf = new Valova_VisualComponents.ComponentDiagramToPdf(components);
SuspendLayout();
//
// valovaComboBox
// customComboBox
//
valovaComboBox.BorderStyle = BorderStyle.FixedSingle;
valovaComboBox.Location = new Point(31, 12);
valovaComboBox.Name = "valovaComboBox";
valovaComboBox.SelectedValue = "";
valovaComboBox.Size = new Size(152, 150);
valovaComboBox.TabIndex = 0;
customComboBox.BorderStyle = BorderStyle.FixedSingle;
customComboBox.Location = new Point(31, 12);
customComboBox.Name = "customComboBox";
customComboBox.Size = new Size(152, 150);
customComboBox.TabIndex = 0;
//
// valovaTextBox
// customTextBox
//
valovaTextBox.BorderStyle = BorderStyle.FixedSingle;
valovaTextBox.Location = new Point(236, 12);
valovaTextBox.Name = "valovaTextBox";
valovaTextBox.Pattern = null;
valovaTextBox.Size = new Size(161, 148);
valovaTextBox.TabIndex = 1;
valovaTextBox.Load += valovaTextBox1_Load;
customTextBox.BorderStyle = BorderStyle.FixedSingle;
customTextBox.Location = new Point(236, 12);
customTextBox.Name = "customTextBox";
customTextBox.Pattern = null;
customTextBox.Size = new Size(161, 148);
customTextBox.TabIndex = 1;
customTextBox.Load += customTextBox1_Load;
//
// valovaListBox
// customListBox
//
valovaListBox.BorderStyle = BorderStyle.FixedSingle;
valovaListBox.Location = new Point(456, 12);
valovaListBox.Name = "valovaListBox";
valovaListBox.SelectedIndex = -1;
valovaListBox.Size = new Size(321, 150);
valovaListBox.TabIndex = 2;
valovaListBox.Load += valovaListBox_Load;
customListBox.BorderStyle = BorderStyle.FixedSingle;
customListBox.Location = new Point(456, 12);
customListBox.Name = "customListBox";
customListBox.SelectedIndex = -1;
customListBox.Size = new Size(321, 150);
customListBox.TabIndex = 2;
customListBox.Load += customListBox_Load;
//
// buttonAddToComboBox
//
@@ -168,11 +174,44 @@
buttonGet.UseVisualStyleBackColor = true;
buttonGet.Click += buttonGet_Click;
//
// ButtonDocumentWithContextTextPdf
//
ButtonDocumentWithContextTextPdf.Location = new Point(190, 402);
ButtonDocumentWithContextTextPdf.Name = "ButtonDocumentWithContextTextPdf";
ButtonDocumentWithContextTextPdf.Size = new Size(124, 36);
ButtonDocumentWithContextTextPdf.TabIndex = 15;
ButtonDocumentWithContextTextPdf.Text = "Текст";
ButtonDocumentWithContextTextPdf.UseVisualStyleBackColor = true;
ButtonDocumentWithContextTextPdf.Click += ButtonDocumentWithContextTextPdf_Click;
//
// ButtonDocumentWithChartLinePdf
//
ButtonDocumentWithChartLinePdf.Location = new Point(450, 402);
ButtonDocumentWithChartLinePdf.Name = "ButtonDocumentWithChartLinePdf";
ButtonDocumentWithChartLinePdf.Size = new Size(124, 36);
ButtonDocumentWithChartLinePdf.TabIndex = 16;
ButtonDocumentWithChartLinePdf.Text = "Диаграмма";
ButtonDocumentWithChartLinePdf.UseVisualStyleBackColor = true;
ButtonDocumentWithChartLinePdf.Click += ButtonDocumentWithChartLinePdf_Click;
//
// ButtonDocumentWithTableHeaderRowPdf
//
ButtonDocumentWithTableHeaderRowPdf.Location = new Point(320, 402);
ButtonDocumentWithTableHeaderRowPdf.Name = "ButtonDocumentWithTableHeaderRowPdf";
ButtonDocumentWithTableHeaderRowPdf.Size = new Size(124, 36);
ButtonDocumentWithTableHeaderRowPdf.TabIndex = 17;
ButtonDocumentWithTableHeaderRowPdf.Text = "Таблица";
ButtonDocumentWithTableHeaderRowPdf.UseVisualStyleBackColor = true;
ButtonDocumentWithTableHeaderRowPdf.Click += ButtonDocumentWithTableHeaderRowPdf_Click;
//
// Form1
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 450);
Controls.Add(ButtonDocumentWithTableHeaderRowPdf);
Controls.Add(ButtonDocumentWithChartLinePdf);
Controls.Add(ButtonDocumentWithContextTextPdf);
Controls.Add(buttonGet);
Controls.Add(button1);
Controls.Add(textBoxPar);
@@ -184,9 +223,9 @@
Controls.Add(textBoxForComboBox);
Controls.Add(buttonClearComboBox);
Controls.Add(buttonAddToComboBox);
Controls.Add(valovaListBox);
Controls.Add(valovaTextBox);
Controls.Add(valovaComboBox);
Controls.Add(customListBox);
Controls.Add(customTextBox);
Controls.Add(customComboBox);
Name = "Form1";
Text = "Form1";
ResumeLayout(false);
@@ -195,9 +234,9 @@
#endregion
private Valova_VisualComponents.ValovaComboBox valovaComboBox;
private Valova_VisualComponents.ValovaTextBox valovaTextBox;
private Valova_VisualComponents.ValovaListBox valovaListBox;
private Valova_VisualComponents.customComboBox customComboBox;
private Valova_VisualComponents.customTextBox customTextBox;
private Valova_VisualComponents.customListBox customListBox;
private Button buttonAddToComboBox;
private Button buttonClearComboBox;
private TextBox textBoxForComboBox;
@@ -209,5 +248,11 @@
private TextBox textBoxPar;
private Button button1;
private Button buttonGet;
private Button ButtonDocumentWithContextTextPdf;
private Button ButtonDocumentWithChartLinePdf;
private Button ButtonDocumentWithTableHeaderRowPdf;
private Valova_VisualComponents.ComponentTextToPdf componentTextToPdf;
private Valova_VisualComponents.ComponentTableToPdf componentTableToPdf;
private Valova_VisualComponents.ComponentDiagramToPdf componentDiagramToPdf;
}
}

View File

@@ -1,22 +1,26 @@
using System.Text;
using Valova_VisualComponents;
using Valova_VisualComponents.Models;
namespace Valova_App
namespace custom_App
{
public partial class Form1 : Form
{
List<Book> books = new List<Book>();
public Form1()
{
InitializeComponent();
valovaComboBox.Items.AddRange(new String[] { "1 example", "2 example", "3 example", "4 example" });
customComboBox.Items.AddRange(new String[] { "1 example", "2 example", "3 example", "4 example" });
valovaTextBox.Pattern = @"^\+7\(\d{3}\)\d{3}-\d{2}-\d{2}$";
valovaTextBox.SetExample("+7(927)000-00-00");
customTextBox.Pattern = @"^\+7\(\d{3}\)\d{3}-\d{2}-\d{2}$";
customTextBox.SetExample("+7(927)000-00-00");
valovaListBox.SetLayout("My favorite book is {Author} {Name}", "{", "}");
customListBox.SetLayout("My favorite book is {Author} {Name}", "{", "}");
books.AddRange(new List<Book> { new Book("a", "A"), new Book("b", "B") });
}
private void valovaTextBox1_Load(object sender, EventArgs e)
private void customTextBox1_Load(object sender, EventArgs e)
{
}
@@ -25,7 +29,7 @@ namespace Valova_App
{
if (!String.IsNullOrEmpty(textBoxForComboBox.Text))
{
valovaComboBox.Items.Add(textBoxForComboBox.Text);
customComboBox.Items.Add(textBoxForComboBox.Text);
textBoxForComboBox.Clear();
}
else
@@ -36,21 +40,21 @@ namespace Valova_App
private void buttonClearComboBox_Click(object sender, EventArgs e)
{
valovaComboBox.Clear();
customComboBox.Clear();
}
private void buttonCheckComboBox_Click(object sender, EventArgs e)
{
textBoxForComboBox.Text = valovaComboBox.SelectedValue;
textBoxForComboBox.Text = customComboBox.SelectedValue;
}
private void buttonGetTextBox_Click(object sender, EventArgs e)
{
MessageBox.Show(valovaTextBox.TextBoxValue);
MessageBox.Show(customTextBox.TextBoxValue);
}
private void valovaListBox_Load(object sender, EventArgs e)
private void customListBox_Load(object sender, EventArgs e)
{
}
@@ -59,12 +63,72 @@ namespace Valova_App
{
Book newBook = new Book(textBoxAuthor.Text, textBoxName.Text);
valovaListBox.AddItemInList(newBook, int.Parse(textBoxRow.Text), textBoxPar.Text);
customListBox.AddItemInList(newBook, int.Parse(textBoxRow.Text), textBoxPar.Text);
}
private void buttonGet_Click(object sender, EventArgs e)
{
Book b = valovaListBox.GetItemFromList<Book>();
Book b = customListBox.GetItemFromList<Book>();
MessageBox.Show(b.Author + " " + b.Name);
}
private void ButtonDocumentWithContextTextPdf_Click(object sender, EventArgs e)
{
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
(sender as Control).BackColor = Color.White; componentTextToPdf.CreateDoc(new ComponentTextToPdfConfig
{
FilePath = "C:\\Users\\User\\Desktop\\PdfDocumentWithContextTextPdf.pdf",
Header = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>",
Paragraphs = new List<string>
{
"2 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 2024 <20><><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20>. <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20><>. <20><><EFBFBD><EFBFBD><EFBFBD>, <20>. 6/4, <20><><EFBFBD>. 1 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, " +
"<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 2024-2025 <20><><EFBFBD><EFBFBD>. 350 <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>. <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>. <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!"}
});
(sender as Control).BackColor = Color.AliceBlue;
}
private void ButtonDocumentWithTableHeaderRowPdf_Click(object sender, EventArgs e)
{
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
(sender as Control).BackColor = Color.White;
componentTableToPdf.CreateDoc(new ComponentTableToPdfConfig<Book>
{
FilePath = "C:\\Users\\User\\Desktop\\PdfDocumentWithTableHeaderRow.pdf",
Header = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>",
UseUnion = true,
ColumnsRowsWidth = new List<(int, int)> { (20, 0), (20, 0) },
ColumnUnion = new List<(int StartIndex, int Count)> { (0, 2)},
Headers = new List<(int ColumnIndex, int RowIndex, string Header, string PropertyName)>
{
(0, 0, "<22><><EFBFBD><EFBFBD><EFBFBD>", "Books"),
(0, 1, "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", "Name"),
(1, 1, "<22><><EFBFBD><EFBFBD><EFBFBD>", "Author")
},
Data = books
});
(sender as Control).BackColor = Color.AliceBlue;
}
private void ButtonDocumentWithChartLinePdf_Click(object sender, EventArgs e)
{
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
(sender as Control).BackColor = Color.White;
componentDiagramToPdf.CreateDoc(new ComponentDiagramToPdfConfig
{
FilePath = "C:\\Users\\User\\Desktop\\PdfDocumentWithChartLine.pdf",
Header = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>",
ChartTitle = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>",
LegendLocation = Valova_VisualComponents.Models.Location.Top,
Data = new Dictionary<string, List<(string Name, double Value)>>
{
{ "0-20", new() { ("2021", 30), ("2022", 15), ("2023", 18) } },
{ "20-40", new(){ ("2021", 15), ("2022", 24), ("2023", 10) } },
{ "40+", new() { ("2021", 5), ("2022", 20), ("2023", 1) } }
}
});
(sender as Control).BackColor = Color.AliceBlue;
}
}
}

View File

@@ -117,4 +117,13 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="componentTextToPdf.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="componentTableToPdf.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>184, 17</value>
</metadata>
<metadata name="componentDiagramToPdf.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>357, 17</value>
</metadata>
</root>

View File

@@ -1,4 +1,4 @@
namespace Valova_App
namespace custom_App
{
internal static class Program
{

View File

@@ -8,6 +8,10 @@
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="PdfSharp.MigraDoc.Standard" Version="1.51.12" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Valova_VisualComponents\Valova_VisualComponents\Valova_VisualComponents.csproj" />
</ItemGroup>

View File

@@ -5,7 +5,13 @@ VisualStudioVersion = 17.9.34723.18
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Valova_VisualComponents", "Valova_VisualComponents\Valova_VisualComponents.csproj", "{23CBD69E-2876-4A20-996F-4230AD3E642A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Valova_App", "..\Valova_App\Valova_App.csproj", "{EF001CCD-92F6-4A12-AC58-39CFF673A16B}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Valova_App", "..\Valova_App\Valova_App.csproj", "{EF001CCD-92F6-4A12-AC58-39CFF673A16B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EmployeesDatabaseImplement", "..\EmployeesDatabaseImplement\EmployeesDatabaseImplement.csproj", "{A088FD57-FB19-46F5-9334-33D33FD6B388}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EmployeeLogic", "..\EmployeeLogic\EmployeeLogic.csproj", "{25C68FC9-1CA2-4D48-B02D-5CA6B42F51E2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EmployeesContracts", "..\EmployeesContracts\EmployeesContracts.csproj", "{D8029FF9-4EF1-479B-80FB-0AC04CBB5471}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -21,6 +27,18 @@ Global
{EF001CCD-92F6-4A12-AC58-39CFF673A16B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EF001CCD-92F6-4A12-AC58-39CFF673A16B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EF001CCD-92F6-4A12-AC58-39CFF673A16B}.Release|Any CPU.Build.0 = Release|Any CPU
{A088FD57-FB19-46F5-9334-33D33FD6B388}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A088FD57-FB19-46F5-9334-33D33FD6B388}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A088FD57-FB19-46F5-9334-33D33FD6B388}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A088FD57-FB19-46F5-9334-33D33FD6B388}.Release|Any CPU.Build.0 = Release|Any CPU
{25C68FC9-1CA2-4D48-B02D-5CA6B42F51E2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{25C68FC9-1CA2-4D48-B02D-5CA6B42F51E2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{25C68FC9-1CA2-4D48-B02D-5CA6B42F51E2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{25C68FC9-1CA2-4D48-B02D-5CA6B42F51E2}.Release|Any CPU.Build.0 = Release|Any CPU
{D8029FF9-4EF1-479B-80FB-0AC04CBB5471}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D8029FF9-4EF1-479B-80FB-0AC04CBB5471}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D8029FF9-4EF1-479B-80FB-0AC04CBB5471}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D8029FF9-4EF1-479B-80FB-0AC04CBB5471}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

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

View File

@@ -0,0 +1,117 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MigraDoc.DocumentObjectModel;
using MigraDoc.DocumentObjectModel.Shapes;
using MigraDoc.DocumentObjectModel.Shapes.Charts;
using MigraDoc.DocumentObjectModel.Tables;
using MigraDoc.Rendering;
using Valova_VisualComponents.Helpers;
using Valova_VisualComponents.Models;
namespace Valova_VisualComponents
{
public partial class ComponentDiagramToPdf : Component
{
public ComponentDiagramToPdf()
{
InitializeComponent();
}
public ComponentDiagramToPdf(IContainer container)
{
container.Add(this);
InitializeComponent();
}
private Document _document;
private Chart _chart;
private Document Document
{
get
{
if (this._document == null)
{
this._document = new Document();
}
return this._document;
}
}
public void CreateHeader(string header)
{
var section = this.Document.AddSection();
var paragraph = section.AddParagraph(header);
paragraph.Format.Font.Color = Colors.Black;
paragraph.Format.Font.Bold = true;
}
private void ConfigChart(ComponentDiagramToPdfConfig config)
{
((Shape)this._chart).Width = Unit.FromCentimeter(16.0);
((Shape)this._chart).Height = Unit.FromCentimeter(12.0);
this._chart.TopArea.AddParagraph(config.ChartTitle);
this._chart.XAxis.MajorTickMark = (TickMarkType)2;
this._chart.YAxis.MajorTickMark = (TickMarkType)2;
this._chart.YAxis.HasMajorGridlines = true;
this._chart.PlotArea.LineFormat.Width = new Unit(1);
this._chart.PlotArea.LineFormat.Visible = true;
switch (config.LegendLocation)
{
case Location.Left:
this._chart.LeftArea.AddLegend();
break;
case Location.Rigth:
this._chart.RightArea.AddLegend();
break;
case Location.Top:
this._chart.TopArea.AddLegend();
break;
case Location.Bottom:
this._chart.BottomArea.AddLegend();
break;
}
}
public void CreateLineChart(ComponentDiagramToPdfConfig config)
{
this._chart = new Chart((ChartType)0);
foreach (string key in config.Data.Keys)
{
Series series = this._chart.SeriesCollection.AddSeries();
series.Name = key;
series.Add(config.Data[key].Select(x => x.Item2).ToArray());
}
this._chart.XValues.AddXSeries().Add(config.Data.First().Value.Select(x => x.Item1.ToString()).ToArray());
this.ConfigChart(config);
}
public void SaveDoc(string filepath)
{
if (filepath.IsEmpty())
throw new ArgumentNullException("Имя файла не задано");
if (this._document == null)
throw new ArgumentNullException("Документ не сформирован, сохранять нечего");
if (this._chart != null)
this._document.LastSection.Add(this._chart);
PdfDocumentRenderer documentRenderer = new PdfDocumentRenderer(true)
{
Document = this._document
};
documentRenderer.RenderDocument();
documentRenderer.PdfDocument.Save(filepath);
}
public void CreateDoc(ComponentDiagramToPdfConfig config)
{
config.CheckFields();
CreateHeader(config.Header);
CreateLineChart(config);
SaveDoc(config.FilePath);
}
}
}

View File

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

View File

@@ -0,0 +1,159 @@
using MigraDoc.DocumentObjectModel.Tables;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Valova_VisualComponents.Helpers;
using Valova_VisualComponents.Models;
using MigraDoc.DocumentObjectModel;
using MigraDoc.DocumentObjectModel.Shapes;
using MigraDoc.DocumentObjectModel.Shapes.Charts;
using MigraDoc.Rendering;
namespace Valova_VisualComponents
{
public partial class ComponentTableToPdf : Component
{
private Document _document;
private Table _table;
public ComponentTableToPdf()
{
InitializeComponent();
}
public ComponentTableToPdf(IContainer container)
{
container.Add(this);
InitializeComponent();
}
private Document Document
{
get
{
if (this._document == null)
{
this._document = new Document();
}
return this._document;
}
}
private Table Table
{
get
{
if (this._table == null)
this._table = new Table();
return this._table;
}
}
public void CreateHeader(string header)
{
var section = this.Document.AddSection();
var paragraph = section.AddParagraph(header);
paragraph.Format.Font.Color = Colors.Black;
paragraph.Format.Font.Bold = true;
}
public void CreateTableWithHeader() => this.Table.Borders.Width = new Unit(0.75);
private static void AddRowHeaderCellMergeByRows(int columnIndex, string header, Row row)
{
SetHeaderCell(columnIndex, header, row);
row.Cells[columnIndex].MergeDown = 1;
}
private static void SetHeaderCell(int columnIndex, string header, Row row)
{
row.Cells[columnIndex].AddParagraph(header);
row.Cells[columnIndex].Format.Font.Bold = true;
row.Cells[columnIndex].Format.Alignment = (ParagraphAlignment)1;
row.Cells[columnIndex].VerticalAlignment = (VerticalAlignment)1;
}
public void CreateRowHeader(ComponentDocumentWithTableHeaderConfig config)
{
foreach ((int Column, int Row) tuple in config.ColumnsRowsWidth)
this.Table.AddColumn(new Unit(tuple.Column * 5));
Row row1 = this.Table.AddRow();
Row row2 = this.Table.AddRow();
for (int i = 0; i < config.ColumnUnion[0].StartIndex; ++i)
AddRowHeaderCellMergeByRows(i, config.Headers.FirstOrDefault(x => x.Item1 == i).Item3, row1);
for (int i = 0; i < config.ColumnUnion.Count; i++)
{
SetHeaderCell(config.ColumnUnion[i].StartIndex, config.Headers.FirstOrDefault(x => x.Item1 == config.ColumnUnion[i].StartIndex && x.Item2 == 0).Item3, row1);
row1.Cells[config.ColumnUnion[i].StartIndex].MergeRight = config.ColumnUnion[i].Count - 1;
for (int j = config.ColumnUnion[i].StartIndex; j < config.ColumnUnion[i].StartIndex + config.ColumnUnion[i].Count; ++j)
SetHeaderCell(j, config.Headers.FirstOrDefault(x => x.Item1 == j && x.Item2 == 1).Item3, row2);
if (i < config.ColumnUnion.Count - 1)
{
for (int j = config.ColumnUnion[i].StartIndex + config.ColumnUnion[i].Count; j < config.ColumnUnion[i + 1].StartIndex; ++j)
AddRowHeaderCellMergeByRows(j, config.Headers.FirstOrDefault(x => x.Item1 == j).Item3, row1);
}
}
List<(int StartIndex, int Count)> columnUnion1 = config.ColumnUnion;
int startIndex = columnUnion1[columnUnion1.Count - 1].StartIndex;
List<(int StartIndex, int Count)> columnUnion2 = config.ColumnUnion;
int count = columnUnion2[columnUnion2.Count - 1].Count;
int num = startIndex + count;
for (int i = num; i < config.ColumnsRowsWidth.Count; ++i)
AddRowHeaderCellMergeByRows(i, config.Headers.FirstOrDefault(x => x.Item1 == i).Item3, row1);
}
public void LoadDataToTableWithRowHeader(string[,] data)
{
for (int index1 = 0; index1 < data.GetLength(0); ++index1)
{
Row row = this.Table.AddRow();
for (int index2 = 0; index2 < data.GetLength(1); ++index2)
row.Cells[index2].AddParagraph(data[index1, index2]);
}
}
public void SaveDoc(string filepath)
{
if (filepath.IsEmpty())
throw new ArgumentNullException("Имя файла не задано");
if (this._document == null)
throw new ArgumentNullException("Документ не сформирован, сохранять нечего");
if (this._table != null)
this._document.LastSection.Add(this._table);
PdfDocumentRenderer documentRenderer = new PdfDocumentRenderer(true)
{
Document = this._document
};
documentRenderer.RenderDocument();
documentRenderer.PdfDocument.Save(filepath);
}
public void CreateDoc<T>(ComponentTableToPdfConfig<T> config)
{
config.CheckFields();
config.ColumnsRowsDataCount = (config.ColumnsRowsWidth.Count, config.Data.Count + 2);
CreateHeader(config.Header);
CreateTableWithHeader();
CreateRowHeader(config);
string[,] array = new string[config.Data.Count, config.ColumnsRowsWidth.Count];
for (int j = 0; j < config.Data.Count; j++)
{
int i;
for (i = 0; i < config.ColumnsRowsWidth.Count; i++)
{
(int, int, string, string) tuple = config.Headers.FirstOrDefault<(int, int, string, string)>(((int ColumnIndex, int RowIndex, string Header, string PropertyName) x) => x.ColumnIndex == i && x.RowIndex == 1);
if (tuple.Equals(default((int, int, string, string))))
{
tuple = config.Headers.FirstOrDefault<(int, int, string, string)>(((int ColumnIndex, int RowIndex, string Header, string PropertyName) x) => x.ColumnIndex == i && x.RowIndex == 0);
}
array[j, i] = config.Data[j].GetType().GetProperty(tuple.Item4)!.GetValue(config.Data[j], null)!.ToString();
}
}
LoadDataToTableWithRowHeader(array);
SaveDoc(config.FilePath);
}
}
}

View File

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

View File

@@ -0,0 +1,81 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MigraDoc.DocumentObjectModel;
using MigraDoc.DocumentObjectModel.Shapes;
using MigraDoc.DocumentObjectModel.Shapes.Charts;
using MigraDoc.DocumentObjectModel.Tables;
using MigraDoc.Rendering;
using Valova_VisualComponents.Models;
namespace Valova_VisualComponents
{
public partial class ComponentTextToPdf : Component
{
private Document _document;
public ComponentTextToPdf()
{
InitializeComponent();
}
public ComponentTextToPdf(IContainer container)
{
container.Add(this);
InitializeComponent();
}
private Document Document
{
get
{
if (_document == null)
{
_document = new Document();
}
return _document;
}
}
public void SaveDoc(string filepath)
{
if (filepath == null)
throw new ArgumentNullException("Имя файла не задано");
if (this._document == null)
throw new ArgumentNullException("Документ не сформирован");
PdfDocumentRenderer documentRenderer = new PdfDocumentRenderer(true)
{
Document = this._document
};
documentRenderer.RenderDocument();
documentRenderer.PdfDocument.Save(filepath);
}
public void CreateDoc(ComponentTextToPdfConfig config)
{
//config.CheckFields();
CreateHeader(config.Header);
foreach (string paragraph in config.Paragraphs)
{
CreateParagraph(paragraph);
}
SaveDoc(config.FilePath);
}
public void CreateHeader(string header)
{
var section = this.Document.AddSection();
var paragraph = section.AddParagraph(header);
paragraph.Format.Font.Color = Colors.Black;
paragraph.Format.Font.Bold = true;
}
public void CreateParagraph(string text) => this.Document.LastSection.AddParagraph(text, "Normal");
}
}

View File

@@ -0,0 +1,166 @@
using Valova_VisualComponents.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
namespace Valova_VisualComponents.Helpers
{
public static class ExtensionConfig
{
public static void CheckFields(this ComponentDocumentConfig config)
{
if (config.FilePath.IsEmpty())
{
throw new ArgumentNullException("Имя файла не задано");
}
if (config.Header.IsEmpty())
{
throw new ArgumentNullException("Заголовок документа не задан");
}
}
public static void CheckFields(this ComponentTextToPdfConfig config)
{
if (config.Header.IsEmpty() || config.FilePath.IsEmpty() || (config.Paragraphs != null && config.Paragraphs.Count == 0) || (config.Paragraphs != null && config.Paragraphs.All((string x) => x.IsEmpty())))
{
throw new ArgumentNullException("Нет текста для вставки в документ");
}
}
public static void CheckFields<T>(this ComponentTableToPdfConfig<T> config)
{
ComponentTableToPdfConfig<T> config2 = config;
((ComponentDocumentConfig)config2).CheckFields();
if (config2.ColumnsRowsWidth == null || config2.ColumnsRowsWidth.Count == 0)
{
throw new ArgumentNullException("Нет данных по ширине колонок таблицы");
}
if (config2.UseUnion && (config2.ColumnUnion == null || config2.ColumnUnion.Count == 0))
{
throw new ArgumentNullException("Нет данных по объединению колонок таблицы");
}
if (config2.Headers == null || config2.Headers.Count == 0 || config2.Headers.Any<(int, int, string, string)>(((int ColumnIndex, int RowIndex, string Header, string PropertyName) x) => x.Header.IsEmpty()))
{
throw new ArgumentNullException("Нет данных по заголовкам таблицы");
}
if (config2.Data == null || config2.Data.Count == 0)
{
throw new ArgumentNullException("Нет данных для заполнения таблицы");
}
if (!config2.UseUnion)
{
return;
}
if (config2.ColumnsRowsWidth.Count < config2.ColumnUnion[config2.ColumnUnion.Count - 1].StartIndex + config2.ColumnUnion[config2.ColumnUnion.Count - 1].Count - 1)
{
throw new IndexOutOfRangeException("Последнее объединение ячеек выходит за границы таблицы");
}
int k;
for (k = 0; k < config2.ColumnUnion[0].StartIndex; k++)
{
int num = config2.Headers.Where<(int, int, string, string)>(((int ColumnIndex, int RowIndex, string Header, string PropertyName) x) => x.ColumnIndex == k).Count();
if (num == 0)
{
DefaultInterpolatedStringHandler defaultInterpolatedStringHandler = new DefaultInterpolatedStringHandler(34, 1);
defaultInterpolatedStringHandler.AppendLiteral("Для ");
defaultInterpolatedStringHandler.AppendFormatted(k);
defaultInterpolatedStringHandler.AppendLiteral(" колонки отсутствует заголовок");
throw new ArgumentNullException(defaultInterpolatedStringHandler.ToStringAndClear());
}
if (num > 1)
{
DefaultInterpolatedStringHandler defaultInterpolatedStringHandler = new DefaultInterpolatedStringHandler(37, 1);
defaultInterpolatedStringHandler.AppendLiteral("Для ");
defaultInterpolatedStringHandler.AppendFormatted(k);
defaultInterpolatedStringHandler.AppendLiteral(" колонки задано более 1 заголовка");
throw new ArgumentNullException(defaultInterpolatedStringHandler.ToStringAndClear());
}
}
int j;
for (j = 0; j < config2.ColumnUnion.Count; j++)
{
if (j < config2.ColumnUnion.Count - 1 && config2.ColumnUnion[j].StartIndex + config2.ColumnUnion[j].Count - 1 > config2.ColumnUnion[j + 1].StartIndex)
{
throw new IndexOutOfRangeException("Имеется накладка в объединении ячеек");
}
int num2 = config2.Headers.Where<(int, int, string, string)>(((int ColumnIndex, int RowIndex, string Header, string PropertyName) x) => x.ColumnIndex >= config2.ColumnUnion[j].StartIndex && x.ColumnIndex <= config2.ColumnUnion[j].StartIndex + config2.ColumnUnion[j].Count - 1 && x.RowIndex == 0).Count();
if (num2 == 0)
{
throw new ArgumentNullException("Для колонок 0 строки отсутствует заголовок");
}
if (num2 > 1)
{
throw new ArgumentNullException("Для колонок 0 строки задано более 1 заголовка");
}
num2 = config2.Headers.Where<(int, int, string, string)>(((int ColumnIndex, int RowIndex, string Header, string PropertyName) x) => x.ColumnIndex >= config2.ColumnUnion[j].StartIndex && x.ColumnIndex <= config2.ColumnUnion[j].StartIndex + config2.ColumnUnion[j].Count - 1 && x.RowIndex == 1).Count();
if (num2 < config2.ColumnUnion[j].Count)
{
throw new ArgumentNullException("Для колонок 1 строки не хватает заголовков");
}
if (num2 > config2.ColumnUnion[j].Count)
{
throw new ArgumentNullException("Для колонок 1 строки задано более требуемого числа заголовков");
}
if (j < config2.ColumnUnion.Count - 1)
{
num2 = config2.Headers.Where<(int, int, string, string)>(((int ColumnIndex, int RowIndex, string Header, string PropertyName) x) => x.ColumnIndex >= config2.ColumnUnion[j].StartIndex + config2.ColumnUnion[j].Count && x.ColumnIndex < config2.ColumnUnion[j + 1].StartIndex && x.RowIndex == 0).Count();
if (num2 < config2.ColumnUnion[j + 1].StartIndex - (config2.ColumnUnion[j].StartIndex + config2.ColumnUnion[j].Count))
{
throw new ArgumentNullException("Для колонок не хватает заголовков");
}
if (num2 > config2.ColumnUnion[j + 1].StartIndex - (config2.ColumnUnion[j].StartIndex + config2.ColumnUnion[j].Count))
{
throw new ArgumentNullException("Для колонок задано более требуемого числа заголовков");
}
num2 = config2.Headers.Where<(int, int, string, string)>(((int ColumnIndex, int RowIndex, string Header, string PropertyName) x) => x.ColumnIndex >= config2.ColumnUnion[j].StartIndex + config2.ColumnUnion[j].Count && x.ColumnIndex < config2.ColumnUnion[j + 1].StartIndex && x.RowIndex == 1).Count();
if (num2 > 0)
{
throw new ArgumentNullException("Для колонок заданы заголовки 2 уровня, чего быть не должно");
}
}
}
int i;
for (i = config2.ColumnUnion[config2.ColumnUnion.Count - 1].StartIndex + config2.ColumnUnion[config2.ColumnUnion.Count - 1].Count; i < config2.ColumnsRowsWidth.Count; i++)
{
int num3 = config2.Headers.Where<(int, int, string, string)>(((int ColumnIndex, int RowIndex, string Header, string PropertyName) x) => x.ColumnIndex == i).Count();
if (num3 == 0)
{
DefaultInterpolatedStringHandler defaultInterpolatedStringHandler = new DefaultInterpolatedStringHandler(34, 1);
defaultInterpolatedStringHandler.AppendLiteral("Для ");
defaultInterpolatedStringHandler.AppendFormatted(i);
defaultInterpolatedStringHandler.AppendLiteral(" колонки отсутствует заголовок");
throw new ArgumentNullException(defaultInterpolatedStringHandler.ToStringAndClear());
}
if (num3 > 1)
{
DefaultInterpolatedStringHandler defaultInterpolatedStringHandler = new DefaultInterpolatedStringHandler(37, 1);
defaultInterpolatedStringHandler.AppendLiteral("Для ");
defaultInterpolatedStringHandler.AppendFormatted(i);
defaultInterpolatedStringHandler.AppendLiteral(" колонки задано более 1 заголовка");
throw new ArgumentNullException(defaultInterpolatedStringHandler.ToStringAndClear());
}
}
}
}
}

View File

@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Valova_VisualComponents.Helpers
{
public static class ExtensionString
{
public static bool HaveText(this string str)
{
return !string.IsNullOrEmpty(str);
}
public static bool IsEmpty(this string str)
{
return string.IsNullOrEmpty(str);
}
}
}

View File

@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Valova_VisualComponents.Models
{
public class ComponentDiagramToPdfConfig : ComponentDocumentConfig
{
public string ChartTitle
{
get;
set;
}
public Location LegendLocation
{
get;
set;
}
public Dictionary<string, List<(string Name, double Value)>> Data
{
get;
set;
}
}
}

View File

@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Valova_VisualComponents.Models
{
public class ComponentDocumentConfig
{
public string FilePath
{
get;
set;
}
public string Header
{
get;
set;
}
}
}

View File

@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Valova_VisualComponents.Models
{
public class ComponentDocumentWithTableHeaderConfig : ComponentDocumentConfig
{
public bool UseUnion { get; set; }
public (int Columns, int Rows) ColumnsRowsDataCount { get; set; }
public List<(int Column, int Row)> ColumnsRowsWidth { get; set; }
public List<(int StartIndex, int Count)> ColumnUnion { get; set; }
public List<(int ColumnIndex, int RowIndex, string Header, string PropertyName)> Headers { get; set; }
}
}

View File

@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Valova_VisualComponents.Models
{
public class ComponentTableToPdfConfig<T> : ComponentDocumentWithTableHeaderConfig
{
public List<T> Data
{
get;
set;
}
}
}

View File

@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Valova_VisualComponents.Models
{
public class ComponentTextToPdfConfig : ComponentDocumentConfig
{
public List<string> Paragraphs
{
get;
set;
}
}
}

View File

@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Valova_VisualComponents.Models
{
public enum Location
{
Left,
Rigth,
Top,
Bottom
}
}

View File

@@ -1,6 +1,6 @@
namespace Valova_VisualComponents
{
partial class ValovaComboBox
partial class customComboBox
{
/// <summary>
/// Обязательная переменная конструктора.
@@ -40,11 +40,11 @@
comboBox.TabIndex = 0;
comboBox.SelectedIndexChanged += comboBox_SelectedIndexChanged;
//
// ValovaComboBox
// customComboBox
//
BorderStyle = BorderStyle.FixedSingle;
Controls.Add(comboBox);
Name = "ValovaComboBox";
Name = "customComboBox";
Size = new Size(148, 148);
ResumeLayout(false);
}

View File

@@ -10,7 +10,7 @@ using System.Windows.Forms;
namespace Valova_VisualComponents
{
public partial class ValovaComboBox : UserControl
public partial class customComboBox : UserControl
{
public ComboBox.ObjectCollection Items => comboBox.Items;
@@ -30,7 +30,7 @@ namespace Valova_VisualComponents
}
public ValovaComboBox()
public customComboBox()
{
InitializeComponent();

View File

@@ -1,6 +1,6 @@
namespace Valova_VisualComponents
{
partial class ValovaListBox
partial class customListBox
{
/// <summary>
/// Обязательная переменная конструктора.
@@ -40,13 +40,13 @@
listBox.Size = new Size(314, 109);
listBox.TabIndex = 0;
//
// ValovaListBox
// customListBox
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
BorderStyle = BorderStyle.FixedSingle;
Controls.Add(listBox);
Name = "ValovaListBox";
Name = "customListBox";
Size = new Size(319, 148);
ResumeLayout(false);
}

View File

@@ -10,14 +10,14 @@ using System.Windows.Forms;
namespace Valova_VisualComponents
{
public partial class ValovaListBox : UserControl
public partial class customListBox : UserControl
{
private string LayoutString;
private string StartS;
private string EndS;
private int SelectedStr;
public ValovaListBox()
public customListBox()
{
InitializeComponent();
}

View File

@@ -1,6 +1,6 @@
namespace Valova_VisualComponents
{
partial class ValovaTextBox
partial class customTextBox
{
/// <summary>
/// Обязательная переменная конструктора.
@@ -40,13 +40,13 @@
textBox.TextChanged += textBox_TextChanged;
textBox.Enter += textBox_Enter;
//
// ValovaTextBox
// customTextBox
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
BorderStyle = BorderStyle.FixedSingle;
Controls.Add(textBox);
Name = "ValovaTextBox";
Name = "customTextBox";
Size = new Size(159, 146);
ResumeLayout(false);
PerformLayout();

View File

@@ -11,11 +11,11 @@ using System.Windows.Forms;
namespace Valova_VisualComponents
{
public partial class ValovaTextBox : UserControl
public partial class customTextBox : UserControl
{
private string? pattern;
private string example = "+7(XXX)XXX-XX-XX";
public ValovaTextBox()
public customTextBox()
{
InitializeComponent();
}

View File

@@ -7,4 +7,8 @@
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="PdfSharp.MigraDoc.Standard" Version="1.51.12" />
</ItemGroup>
</Project>