diff --git a/EmployeeLogic/BusinessLogics/EmployeeLogic.cs b/EmployeeLogic/BusinessLogics/EmployeeLogic.cs new file mode 100644 index 0000000..67a43d2 --- /dev/null +++ b/EmployeeLogic/BusinessLogics/EmployeeLogic.cs @@ -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 Read(EmployeeBindingModel model) + { + if (model == null) + { + return _employeeStorage.GetFullList(); + } + if (model.Id.HasValue) + { + return new List { _employeeStorage.GetElement(model) }; + } + return _employeeStorage.GetFilteredList(model); + } + } +} diff --git a/EmployeeLogic/BusinessLogics/PostLogic.cs b/EmployeeLogic/BusinessLogics/PostLogic.cs new file mode 100644 index 0000000..cb51ead --- /dev/null +++ b/EmployeeLogic/BusinessLogics/PostLogic.cs @@ -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 Read(PostBindingModel model) + { + if (model == null) + { + return _postStorage.GetFullList(); + } + if (model.Id.HasValue) + { + return new List { _postStorage.GetElement(model) }; + } + return _postStorage.GetFilteredList(model); + } + } +} diff --git a/EmployeeLogic/EmployeeLogic.csproj b/EmployeeLogic/EmployeeLogic.csproj new file mode 100644 index 0000000..e532879 --- /dev/null +++ b/EmployeeLogic/EmployeeLogic.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + enable + enable + + + + + + + diff --git a/EmployeesContracts/BindingModels/EmployeeBindingModel.cs b/EmployeesContracts/BindingModels/EmployeeBindingModel.cs new file mode 100644 index 0000000..237a7df --- /dev/null +++ b/EmployeesContracts/BindingModels/EmployeeBindingModel.cs @@ -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; } + } +} diff --git a/EmployeesContracts/BindingModels/PostBindingModel.cs b/EmployeesContracts/BindingModels/PostBindingModel.cs new file mode 100644 index 0000000..e807106 --- /dev/null +++ b/EmployeesContracts/BindingModels/PostBindingModel.cs @@ -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; } + } +} diff --git a/EmployeesContracts/BusinessLogicsContracts/IEmployeeLogic.cs b/EmployeesContracts/BusinessLogicsContracts/IEmployeeLogic.cs new file mode 100644 index 0000000..edf6025 --- /dev/null +++ b/EmployeesContracts/BusinessLogicsContracts/IEmployeeLogic.cs @@ -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 Read(EmployeeBindingModel model); + void CreateOrUpdate(EmployeeBindingModel model); + void Delete(EmployeeBindingModel model); + } +} diff --git a/EmployeesContracts/BusinessLogicsContracts/IPostLogic.cs b/EmployeesContracts/BusinessLogicsContracts/IPostLogic.cs new file mode 100644 index 0000000..08ba513 --- /dev/null +++ b/EmployeesContracts/BusinessLogicsContracts/IPostLogic.cs @@ -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 Read(PostBindingModel model); + void CreateOrUpdate(PostBindingModel model); + void Delete(PostBindingModel model); + } +} diff --git a/EmployeesContracts/EmployeesContracts.csproj b/EmployeesContracts/EmployeesContracts.csproj new file mode 100644 index 0000000..132c02c --- /dev/null +++ b/EmployeesContracts/EmployeesContracts.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/EmployeesContracts/StorageContracts/IEmployeeStorage.cs b/EmployeesContracts/StorageContracts/IEmployeeStorage.cs new file mode 100644 index 0000000..7b6b778 --- /dev/null +++ b/EmployeesContracts/StorageContracts/IEmployeeStorage.cs @@ -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 GetFullList(); + List GetFilteredList(EmployeeBindingModel model); + EmployeeViewModel GetElement(EmployeeBindingModel model); + + void Insert(EmployeeBindingModel model); + void Update(EmployeeBindingModel model); + void Delete(EmployeeBindingModel model); + } +} diff --git a/EmployeesContracts/StorageContracts/IPostStorage.cs b/EmployeesContracts/StorageContracts/IPostStorage.cs new file mode 100644 index 0000000..9bbce12 --- /dev/null +++ b/EmployeesContracts/StorageContracts/IPostStorage.cs @@ -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 GetFullList(); + List GetFilteredList(PostBindingModel model); + PostViewModel GetElement(PostBindingModel model); + + void Insert(PostBindingModel model); + void Update(PostBindingModel model); + void Delete(PostBindingModel model); + } +} diff --git a/EmployeesContracts/ViewModels/EmployeeViewModel.cs b/EmployeesContracts/ViewModels/EmployeeViewModel.cs new file mode 100644 index 0000000..dd0ee93 --- /dev/null +++ b/EmployeesContracts/ViewModels/EmployeeViewModel.cs @@ -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; } + } +} diff --git a/EmployeesContracts/ViewModels/PostViewModel.cs b/EmployeesContracts/ViewModels/PostViewModel.cs new file mode 100644 index 0000000..ea63220 --- /dev/null +++ b/EmployeesContracts/ViewModels/PostViewModel.cs @@ -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; } + } +} diff --git a/EmployeesDatabaseImplement/EmployeesDatabase.cs b/EmployeesDatabaseImplement/EmployeesDatabase.cs new file mode 100644 index 0000000..d274c8e --- /dev/null +++ b/EmployeesDatabaseImplement/EmployeesDatabase.cs @@ -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 Employees { set; get; } + + public virtual DbSet Posts { set; get; } + } +} \ No newline at end of file diff --git a/EmployeesDatabaseImplement/EmployeesDatabaseImplement.csproj b/EmployeesDatabaseImplement/EmployeesDatabaseImplement.csproj new file mode 100644 index 0000000..7afc175 --- /dev/null +++ b/EmployeesDatabaseImplement/EmployeesDatabaseImplement.csproj @@ -0,0 +1,26 @@ + + + + net6.0 + enable + enable + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + diff --git a/EmployeesDatabaseImplement/Implements/EmployeeStorage.cs b/EmployeesDatabaseImplement/Implements/EmployeeStorage.cs new file mode 100644 index 0000000..3781b04 --- /dev/null +++ b/EmployeesDatabaseImplement/Implements/EmployeeStorage.cs @@ -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 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 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 + }; + } + } +} diff --git a/EmployeesDatabaseImplement/Implements/PostStorage.cs b/EmployeesDatabaseImplement/Implements/PostStorage.cs new file mode 100644 index 0000000..fd62d1d --- /dev/null +++ b/EmployeesDatabaseImplement/Implements/PostStorage.cs @@ -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 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 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 + }; + } + } +} diff --git a/EmployeesDatabaseImplement/Models/Employee.cs b/EmployeesDatabaseImplement/Models/Employee.cs new file mode 100644 index 0000000..7326547 --- /dev/null +++ b/EmployeesDatabaseImplement/Models/Employee.cs @@ -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; } + + } +} diff --git a/EmployeesDatabaseImplement/Models/Post.cs b/EmployeesDatabaseImplement/Models/Post.cs new file mode 100644 index 0000000..17eebfb --- /dev/null +++ b/EmployeesDatabaseImplement/Models/Post.cs @@ -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; } + } +} diff --git a/Valova_App/Book.cs b/Valova_App/Book.cs index f7368ab..e3c9431 100644 --- a/Valova_App/Book.cs +++ b/Valova_App/Book.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace Valova_App +namespace custom_App { public class Book { diff --git a/Valova_App/Form1.Designer.cs b/Valova_App/Form1.Designer.cs index e0d7a20..a23063c 100644 --- a/Valova_App/Form1.Designer.cs +++ b/Valova_App/Form1.Designer.cs @@ -1,4 +1,4 @@ -namespace Valova_App +namespace custom_App { partial class Form1 { @@ -28,9 +28,10 @@ /// 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; } } diff --git a/Valova_App/Form1.cs b/Valova_App/Form1.cs index f963f48..b7ae102 100644 --- a/Valova_App/Form1.cs +++ b/Valova_App/Form1.cs @@ -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 books = new List(); 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 { 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 b = customListBox.GetItemFromList(); 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 = " ", + Paragraphs = new List + { + "2 2024 : . , . , . 6/4, . 1 , " + + " 2024-2025 . 350 . , . , !"} + }); + (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 + { + FilePath = "C:\\Users\\User\\Desktop\\PdfDocumentWithTableHeaderRow.pdf", + Header = "", + 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, "", "Books"), + (0, 1, "", "Name"), + (1, 1, "", "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 = "", + ChartTitle = " ", + LegendLocation = Valova_VisualComponents.Models.Location.Top, + Data = new Dictionary> + { + { "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; + } } } diff --git a/Valova_App/Form1.resx b/Valova_App/Form1.resx index af32865..efb69a7 100644 --- a/Valova_App/Form1.resx +++ b/Valova_App/Form1.resx @@ -117,4 +117,13 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 17, 17 + + + 184, 17 + + + 357, 17 + \ No newline at end of file diff --git a/Valova_App/Program.cs b/Valova_App/Program.cs index e5bea1d..379f78d 100644 --- a/Valova_App/Program.cs +++ b/Valova_App/Program.cs @@ -1,4 +1,4 @@ -namespace Valova_App +namespace custom_App { internal static class Program { diff --git a/Valova_App/Valova_App.csproj b/Valova_App/Valova_App.csproj index ade951c..9f4b280 100644 --- a/Valova_App/Valova_App.csproj +++ b/Valova_App/Valova_App.csproj @@ -8,6 +8,10 @@ enable + + + + diff --git a/Valova_VisualComponents/Valova_VisualComponents.sln b/Valova_VisualComponents/Valova_VisualComponents.sln index c9751a6..e255ec1 100644 --- a/Valova_VisualComponents/Valova_VisualComponents.sln +++ b/Valova_VisualComponents/Valova_VisualComponents.sln @@ -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 diff --git a/Valova_VisualComponents/Valova_VisualComponents/ComponentDiagramToPdf.Designer.cs b/Valova_VisualComponents/Valova_VisualComponents/ComponentDiagramToPdf.Designer.cs new file mode 100644 index 0000000..020d73f --- /dev/null +++ b/Valova_VisualComponents/Valova_VisualComponents/ComponentDiagramToPdf.Designer.cs @@ -0,0 +1,36 @@ +namespace Valova_VisualComponents +{ + partial class ComponentDiagramToPdf + { + /// + /// Обязательная переменная конструктора. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Освободить все используемые ресурсы. + /// + /// истинно, если управляемый ресурс должен быть удален; иначе ложно. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Код, автоматически созданный конструктором компонентов + + /// + /// Требуемый метод для поддержки конструктора — не изменяйте + /// содержимое этого метода с помощью редактора кода. + /// + private void InitializeComponent() + { + components = new System.ComponentModel.Container(); + } + + #endregion + } +} diff --git a/Valova_VisualComponents/Valova_VisualComponents/ComponentDiagramToPdf.cs b/Valova_VisualComponents/Valova_VisualComponents/ComponentDiagramToPdf.cs new file mode 100644 index 0000000..3068126 --- /dev/null +++ b/Valova_VisualComponents/Valova_VisualComponents/ComponentDiagramToPdf.cs @@ -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); + } + } +} diff --git a/Valova_VisualComponents/Valova_VisualComponents/ComponentTableToPdf.Designer.cs b/Valova_VisualComponents/Valova_VisualComponents/ComponentTableToPdf.Designer.cs new file mode 100644 index 0000000..199a28d --- /dev/null +++ b/Valova_VisualComponents/Valova_VisualComponents/ComponentTableToPdf.Designer.cs @@ -0,0 +1,36 @@ +namespace Valova_VisualComponents +{ + partial class ComponentTableToPdf + { + /// + /// Обязательная переменная конструктора. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Освободить все используемые ресурсы. + /// + /// истинно, если управляемый ресурс должен быть удален; иначе ложно. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Код, автоматически созданный конструктором компонентов + + /// + /// Требуемый метод для поддержки конструктора — не изменяйте + /// содержимое этого метода с помощью редактора кода. + /// + private void InitializeComponent() + { + components = new System.ComponentModel.Container(); + } + + #endregion + } +} diff --git a/Valova_VisualComponents/Valova_VisualComponents/ComponentTableToPdf.cs b/Valova_VisualComponents/Valova_VisualComponents/ComponentTableToPdf.cs new file mode 100644 index 0000000..3663c1a --- /dev/null +++ b/Valova_VisualComponents/Valova_VisualComponents/ComponentTableToPdf.cs @@ -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(ComponentTableToPdfConfig 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); + } + } + +} + diff --git a/Valova_VisualComponents/Valova_VisualComponents/ComponentTextToPdf.Designer.cs b/Valova_VisualComponents/Valova_VisualComponents/ComponentTextToPdf.Designer.cs new file mode 100644 index 0000000..226ed6f --- /dev/null +++ b/Valova_VisualComponents/Valova_VisualComponents/ComponentTextToPdf.Designer.cs @@ -0,0 +1,36 @@ +namespace Valova_VisualComponents +{ + partial class ComponentTextToPdf + { + /// + /// Обязательная переменная конструктора. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Освободить все используемые ресурсы. + /// + /// истинно, если управляемый ресурс должен быть удален; иначе ложно. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Код, автоматически созданный конструктором компонентов + + /// + /// Требуемый метод для поддержки конструктора — не изменяйте + /// содержимое этого метода с помощью редактора кода. + /// + private void InitializeComponent() + { + components = new System.ComponentModel.Container(); + } + + #endregion + } +} diff --git a/Valova_VisualComponents/Valova_VisualComponents/ComponentTextToPdf.cs b/Valova_VisualComponents/Valova_VisualComponents/ComponentTextToPdf.cs new file mode 100644 index 0000000..358a4f5 --- /dev/null +++ b/Valova_VisualComponents/Valova_VisualComponents/ComponentTextToPdf.cs @@ -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"); + } +} diff --git a/Valova_VisualComponents/Valova_VisualComponents/Helpers/ExtensionConfig.cs b/Valova_VisualComponents/Valova_VisualComponents/Helpers/ExtensionConfig.cs new file mode 100644 index 0000000..10d96a0 --- /dev/null +++ b/Valova_VisualComponents/Valova_VisualComponents/Helpers/ExtensionConfig.cs @@ -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(this ComponentTableToPdfConfig config) + { + ComponentTableToPdfConfig 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()); + } + } + } + } +} diff --git a/Valova_VisualComponents/Valova_VisualComponents/Helpers/ExtensionString.cs b/Valova_VisualComponents/Valova_VisualComponents/Helpers/ExtensionString.cs new file mode 100644 index 0000000..63086e3 --- /dev/null +++ b/Valova_VisualComponents/Valova_VisualComponents/Helpers/ExtensionString.cs @@ -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); + } + } +} diff --git a/Valova_VisualComponents/Valova_VisualComponents/Models/ComponentDiagramToPdfConfig.cs b/Valova_VisualComponents/Valova_VisualComponents/Models/ComponentDiagramToPdfConfig.cs new file mode 100644 index 0000000..6860688 --- /dev/null +++ b/Valova_VisualComponents/Valova_VisualComponents/Models/ComponentDiagramToPdfConfig.cs @@ -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> Data + { + get; + set; + } + } +} diff --git a/Valova_VisualComponents/Valova_VisualComponents/Models/ComponentDocumentConfig.cs b/Valova_VisualComponents/Valova_VisualComponents/Models/ComponentDocumentConfig.cs new file mode 100644 index 0000000..87984c7 --- /dev/null +++ b/Valova_VisualComponents/Valova_VisualComponents/Models/ComponentDocumentConfig.cs @@ -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; + } + } +} diff --git a/Valova_VisualComponents/Valova_VisualComponents/Models/ComponentDocumentWithTableHeaderConfig.cs b/Valova_VisualComponents/Valova_VisualComponents/Models/ComponentDocumentWithTableHeaderConfig.cs new file mode 100644 index 0000000..e27a2fd --- /dev/null +++ b/Valova_VisualComponents/Valova_VisualComponents/Models/ComponentDocumentWithTableHeaderConfig.cs @@ -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; } + } +} diff --git a/Valova_VisualComponents/Valova_VisualComponents/Models/ComponentTableToPdfConfig.cs b/Valova_VisualComponents/Valova_VisualComponents/Models/ComponentTableToPdfConfig.cs new file mode 100644 index 0000000..c08d8cf --- /dev/null +++ b/Valova_VisualComponents/Valova_VisualComponents/Models/ComponentTableToPdfConfig.cs @@ -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 : ComponentDocumentWithTableHeaderConfig + { + public List Data + { + get; + set; + } + } +} diff --git a/Valova_VisualComponents/Valova_VisualComponents/Models/ComponentTextToPdfConfig.cs b/Valova_VisualComponents/Valova_VisualComponents/Models/ComponentTextToPdfConfig.cs new file mode 100644 index 0000000..3170a93 --- /dev/null +++ b/Valova_VisualComponents/Valova_VisualComponents/Models/ComponentTextToPdfConfig.cs @@ -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 Paragraphs + { + get; + set; + } + } +} diff --git a/Valova_VisualComponents/Valova_VisualComponents/Models/Location.cs b/Valova_VisualComponents/Valova_VisualComponents/Models/Location.cs new file mode 100644 index 0000000..eedeecd --- /dev/null +++ b/Valova_VisualComponents/Valova_VisualComponents/Models/Location.cs @@ -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 + } +} diff --git a/Valova_VisualComponents/Valova_VisualComponents/ValovaComboBox.Designer.cs b/Valova_VisualComponents/Valova_VisualComponents/ValovaComboBox.Designer.cs index 9dd544d..6666910 100644 --- a/Valova_VisualComponents/Valova_VisualComponents/ValovaComboBox.Designer.cs +++ b/Valova_VisualComponents/Valova_VisualComponents/ValovaComboBox.Designer.cs @@ -1,6 +1,6 @@ namespace Valova_VisualComponents { - partial class ValovaComboBox + partial class customComboBox { /// /// Обязательная переменная конструктора. @@ -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); } diff --git a/Valova_VisualComponents/Valova_VisualComponents/ValovaComboBox.cs b/Valova_VisualComponents/Valova_VisualComponents/ValovaComboBox.cs index aa31d95..eadeea0 100644 --- a/Valova_VisualComponents/Valova_VisualComponents/ValovaComboBox.cs +++ b/Valova_VisualComponents/Valova_VisualComponents/ValovaComboBox.cs @@ -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(); diff --git a/Valova_VisualComponents/Valova_VisualComponents/ValovaListBox.Designer.cs b/Valova_VisualComponents/Valova_VisualComponents/ValovaListBox.Designer.cs index 94055dd..4ecb344 100644 --- a/Valova_VisualComponents/Valova_VisualComponents/ValovaListBox.Designer.cs +++ b/Valova_VisualComponents/Valova_VisualComponents/ValovaListBox.Designer.cs @@ -1,6 +1,6 @@ namespace Valova_VisualComponents { - partial class ValovaListBox + partial class customListBox { /// /// Обязательная переменная конструктора. @@ -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); } diff --git a/Valova_VisualComponents/Valova_VisualComponents/ValovaListBox.cs b/Valova_VisualComponents/Valova_VisualComponents/ValovaListBox.cs index f58fe09..74b5472 100644 --- a/Valova_VisualComponents/Valova_VisualComponents/ValovaListBox.cs +++ b/Valova_VisualComponents/Valova_VisualComponents/ValovaListBox.cs @@ -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(); } diff --git a/Valova_VisualComponents/Valova_VisualComponents/ValovaTextBox.Designer.cs b/Valova_VisualComponents/Valova_VisualComponents/ValovaTextBox.Designer.cs index 96a8e19..afb1b8a 100644 --- a/Valova_VisualComponents/Valova_VisualComponents/ValovaTextBox.Designer.cs +++ b/Valova_VisualComponents/Valova_VisualComponents/ValovaTextBox.Designer.cs @@ -1,6 +1,6 @@ namespace Valova_VisualComponents { - partial class ValovaTextBox + partial class customTextBox { /// /// Обязательная переменная конструктора. @@ -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(); diff --git a/Valova_VisualComponents/Valova_VisualComponents/ValovaTextBox.cs b/Valova_VisualComponents/Valova_VisualComponents/ValovaTextBox.cs index 0f9d34b..278288f 100644 --- a/Valova_VisualComponents/Valova_VisualComponents/ValovaTextBox.cs +++ b/Valova_VisualComponents/Valova_VisualComponents/ValovaTextBox.cs @@ -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(); } diff --git a/Valova_VisualComponents/Valova_VisualComponents/Valova_VisualComponents.csproj b/Valova_VisualComponents/Valova_VisualComponents/Valova_VisualComponents.csproj index 060aa1c..a04788f 100644 --- a/Valova_VisualComponents/Valova_VisualComponents/Valova_VisualComponents.csproj +++ b/Valova_VisualComponents/Valova_VisualComponents/Valova_VisualComponents.csproj @@ -7,4 +7,8 @@ enable + + + +