2 Commits

Author SHA1 Message Date
Вячеслав Иванов
d5f90b74e1 fix 2024-09-18 22:56:59 +04:00
Вячеслав Иванов
3058978306 done 2024-09-06 00:05:36 +04:00
64 changed files with 960 additions and 2455 deletions

View File

@@ -1,68 +0,0 @@
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

@@ -1,66 +0,0 @@
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

@@ -1,13 +0,0 @@
<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

@@ -1,21 +0,0 @@
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

@@ -1,15 +0,0 @@
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

@@ -1,17 +0,0 @@
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

@@ -1,17 +0,0 @@
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

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

View File

@@ -1,21 +0,0 @@
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

@@ -1,21 +0,0 @@
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

@@ -1,24 +0,0 @@
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

@@ -1,15 +0,0 @@
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

@@ -1,22 +0,0 @@
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

@@ -1,26 +0,0 @@
<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

@@ -1,125 +0,0 @@
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

@@ -1,120 +0,0 @@
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

@@ -1,25 +0,0 @@
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

@@ -1,17 +0,0 @@
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; }
}
}

196
KOP/Ivanov_App/Form.Designer.cs generated Normal file
View File

@@ -0,0 +1,196 @@
namespace Ivanov_App
{
partial class Form
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
ItemList = new Ivanov_visual_components.ItemList();
ButtonListClear = new Button();
ButtonLoadList = new Button();
dateBoxWithNull = new Ivanov_visual_components.DateBoxWithNull();
ButtonGetValue = new Button();
ButtonSetValue = new Button();
itemTable = new Ivanov_visual_components.ItemTable();
ButtonClear = new Button();
textBoxEvent = new TextBox();
ButtonAdd = new Button();
ButtonSel = new Button();
SuspendLayout();
//
// ItemList
//
ItemList.Location = new Point(22, 26);
ItemList.Margin = new Padding(11, 13, 11, 13);
ItemList.Name = "ItemList";
ItemList.SelectedElement = "";
ItemList.Size = new Size(238, 370);
ItemList.TabIndex = 0;
ItemList.ChangeEvent += ItemList_ChangeEvent;
//
// ButtonListClear
//
ButtonListClear.Location = new Point(22, 415);
ButtonListClear.Margin = new Padding(6);
ButtonListClear.Name = "ButtonListClear";
ButtonListClear.Size = new Size(214, 49);
ButtonListClear.TabIndex = 1;
ButtonListClear.Text = "List Clear";
ButtonListClear.UseVisualStyleBackColor = true;
ButtonListClear.Click += ButtonListClear_Click;
//
// ButtonLoadList
//
ButtonLoadList.Location = new Point(22, 477);
ButtonLoadList.Margin = new Padding(6);
ButtonLoadList.Name = "ButtonLoadList";
ButtonLoadList.Size = new Size(214, 49);
ButtonLoadList.TabIndex = 2;
ButtonLoadList.Text = "Load List";
ButtonLoadList.UseVisualStyleBackColor = true;
ButtonLoadList.Click += ButtonLoadList_Click;
//
// dateBoxWithNull
//
dateBoxWithNull.BackColor = SystemColors.ControlLight;
dateBoxWithNull.Location = new Point(423, 26);
dateBoxWithNull.Margin = new Padding(11, 13, 11, 13);
dateBoxWithNull.Name = "dateBoxWithNull";
dateBoxWithNull.Size = new Size(273, 62);
dateBoxWithNull.TabIndex = 3;
dateBoxWithNull.Value = null;
dateBoxWithNull.CheckBoxEvent += dateBoxWithNull1_CheckBoxEvent;
dateBoxWithNull.ChangeEvent += dateBoxWithNull1_ChangeEvent;
//
// ButtonGetValue
//
ButtonGetValue.Location = new Point(423, 100);
ButtonGetValue.Margin = new Padding(6);
ButtonGetValue.Name = "ButtonGetValue";
ButtonGetValue.Size = new Size(273, 49);
ButtonGetValue.TabIndex = 4;
ButtonGetValue.Text = "Get Value";
ButtonGetValue.UseVisualStyleBackColor = true;
ButtonGetValue.Click += ButtonGetValue_Click;
//
// ButtonSetValue
//
ButtonSetValue.Location = new Point(423, 162);
ButtonSetValue.Margin = new Padding(6);
ButtonSetValue.Name = "ButtonSetValue";
ButtonSetValue.Size = new Size(273, 49);
ButtonSetValue.TabIndex = 5;
ButtonSetValue.Text = "Set Value";
ButtonSetValue.UseVisualStyleBackColor = true;
ButtonSetValue.Click += ButtonSetValue_Click;
//
// itemTable
//
itemTable.Location = new Point(708, 26);
itemTable.Margin = new Padding(11, 13, 11, 13);
itemTable.Name = "itemTable";
itemTable.Size = new Size(1000, 912);
itemTable.TabIndex = 6;
//
// ButtonClear
//
ButtonClear.Location = new Point(1736, 26);
ButtonClear.Margin = new Padding(6);
ButtonClear.Name = "ButtonClear";
ButtonClear.Size = new Size(175, 49);
ButtonClear.TabIndex = 7;
ButtonClear.Text = "Table clear";
ButtonClear.UseVisualStyleBackColor = true;
ButtonClear.Click += ButtonClear_Click;
//
// textBoxEvent
//
textBoxEvent.Location = new Point(423, 224);
textBoxEvent.Margin = new Padding(6);
textBoxEvent.Name = "textBoxEvent";
textBoxEvent.Size = new Size(270, 39);
textBoxEvent.TabIndex = 8;
//
// ButtonAdd
//
ButtonAdd.Location = new Point(1736, 87);
ButtonAdd.Margin = new Padding(6);
ButtonAdd.Name = "ButtonAdd";
ButtonAdd.Size = new Size(175, 49);
ButtonAdd.TabIndex = 9;
ButtonAdd.Text = "Table Add";
ButtonAdd.UseVisualStyleBackColor = true;
ButtonAdd.Click += ButtonAdd_Click;
//
// ButtonSel
//
ButtonSel.Location = new Point(1736, 149);
ButtonSel.Margin = new Padding(6);
ButtonSel.Name = "ButtonSel";
ButtonSel.Size = new Size(175, 49);
ButtonSel.TabIndex = 10;
ButtonSel.Text = "Get Value";
ButtonSel.UseVisualStyleBackColor = true;
ButtonSel.Click += ButtonSel_Click;
//
// Form
//
AutoScaleDimensions = new SizeF(13F, 32F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1933, 960);
Controls.Add(ButtonSel);
Controls.Add(ButtonAdd);
Controls.Add(textBoxEvent);
Controls.Add(ButtonClear);
Controls.Add(itemTable);
Controls.Add(ButtonSetValue);
Controls.Add(ButtonGetValue);
Controls.Add(dateBoxWithNull);
Controls.Add(ButtonLoadList);
Controls.Add(ButtonListClear);
Controls.Add(ItemList);
Margin = new Padding(6);
Name = "Form";
Text = "Form1";
ResumeLayout(false);
PerformLayout();
}
#endregion
private Ivanov_visual_components.ItemList ItemList;
private Button ButtonListClear;
private Button ButtonLoadList;
private Ivanov_visual_components.DateBoxWithNull dateBoxWithNull;
private Button ButtonGetValue;
private Button ButtonSetValue;
private Ivanov_visual_components.ItemTable itemTable;
private Button ButtonClear;
private TextBox textBoxEvent;
private Button ButtonAdd;
private Button ButtonSel;
}
}

121
KOP/Ivanov_App/Form.cs Normal file
View File

@@ -0,0 +1,121 @@
using Microsoft.VisualBasic.Devices;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Header;
namespace Ivanov_App
{
public partial class Form : System.Windows.Forms.Form
{
public Form()
{
InitializeComponent();
CreateList();
}
// 1 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
private void CreateList()
{
for (int i = 0; i < 10; i++)
{
ItemList.Items.Add($"Item-{i}");
}
}
private void ButtonListClear_Click(object sender, EventArgs e)
{
ItemList.Clear();
}
private void ButtonLoadList_Click(object sender, EventArgs e)
{
CreateList();
}
private void ItemList_ChangeEvent(object sender, EventArgs e)
{
object? selectedItem = ItemList.SelectedElement;
MessageBox.Show($"Change selected item {selectedItem?.ToString()}");
}
// 2 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
private void dateBoxWithNull1_ChangeEvent(object sender, EventArgs e)
{
textBoxEvent.Text = "TextBox change";
}
private void dateBoxWithNull1_CheckBoxEvent(object sender, EventArgs e)
{
textBoxEvent.Text = "CheckBox change";
}
private void ButtonGetValue_Click(object sender, EventArgs e)
{
MessageBox.Show($"Value is {dateBoxWithNull.Value}");
}
private bool EmptyFill = false;
private void ButtonSetValue_Click(object sender, EventArgs e)
{
if (EmptyFill)
{
dateBoxWithNull.Value = DateTime.Now;
}
else
{
dateBoxWithNull.Value = null;
}
EmptyFill = !EmptyFill;
}
// 3 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
readonly List<Student> computers = new()
{
new Student { Id = 0, Name = "<22><><EFBFBD><EFBFBD>", Surname = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", Course = 1 },
new Student { Id = 1, Name = "<22><><EFBFBD><EFBFBD>", Surname = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", Course = 2 },
new Student { Id = 2, Name = "<22><><EFBFBD><EFBFBD>", Surname = "<22><><EFBFBD><EFBFBD><EFBFBD>", Course = 3 },
new Student { Id = 3, Name = "<22><><EFBFBD><EFBFBD>", Surname = "<22><><EFBFBD><EFBFBD><EFBFBD>", Course = 4 },
new Student { Id = 4, Name = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", Surname = "<22><><EFBFBD><EFBFBD><EFBFBD>", Course = 5 }
};
private void CreateTable()
{
itemTable.ConfigColumn(new()
{
ColumnsCount = 4,
NameColumn = new string[] { "Id", "Name", "Surname", "Course" },
Width = new int[] { 10, 150, 250, 200 },
Visible = new bool[] { false, true, true, true, true },
PropertiesObject = new string[] { "Id", "Name", "Surname", "Course" }
});
foreach (Student computer in computers)
{
for (int i = 0; i < 4; i++)
{
itemTable.AddItem(computer, computer.Id, i);
itemTable.Update();
}
}
}
private void ButtonAdd_Click(object sender, EventArgs e)
{
CreateTable();
}
private void ButtonClear_Click(object sender, EventArgs e)
{
itemTable.ClearDataGrid();
}
private void ButtonSel_Click(object sender, EventArgs e)
{
Student? computer = itemTable.GetSelectedObjectInRow<Student>();
if (computer is null) return;
MessageBox.Show($"{computer.Id}-{computer.Name}-{computer.Surname}-{computer.Course}");
}
}
}

View File

@@ -9,11 +9,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="PdfSharp.MigraDoc.Standard" Version="1.51.12" /> <ProjectReference Include="..\Ivanov_visual_components\Ivanov_visual_components.csproj" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Valova_VisualComponents\Valova_VisualComponents\Valova_VisualComponents.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@@ -1,4 +1,4 @@
namespace custom_App namespace Ivanov_App
{ {
internal static class Program internal static class Program
{ {
@@ -11,7 +11,7 @@ namespace custom_App
// To customize application configuration such as set high DPI settings or default font, // To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration. // see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize(); ApplicationConfiguration.Initialize();
Application.Run(new Form1()); Application.Run(new Form());
} }
} }
} }

26
KOP/Ivanov_App/Student.cs Normal file
View File

@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Ivanov_App
{
public class Student
{
public int Id { get; set; }
public string Name { get; set; } = string.Empty;
public string Surname { get; set; } = string.Empty;
public int Course { get; set; }
public Student(int id, string name, string surname, int course)
{
Id = id;
Name = name;
Surname = surname;
Course = course;
}
public Student() { }
}
}

View File

@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Ivanov_visual_components
{
public class ColumnsConfiguratoin
{
public int ColumnsCount { get; set; }
public string[] NameColumn { get; set; }
public int[] Width { get; set; }
public bool[] Visible { get; set; }
public string[] PropertiesObject { get; set; }
}
}

View File

@@ -0,0 +1,74 @@
namespace Ivanov_visual_components
{
partial class DateBoxWithNull
{
/// <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()
{
this.CheckBoxNull = new System.Windows.Forms.CheckBox();
this.TextBoxDate = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// CheckBoxNull
//
this.CheckBoxNull.AutoSize = true;
this.CheckBoxNull.Location = new System.Drawing.Point(3, 7);
this.CheckBoxNull.Name = "CheckBoxNull";
this.CheckBoxNull.Size = new System.Drawing.Size(15, 14);
this.CheckBoxNull.TabIndex = 0;
this.CheckBoxNull.UseVisualStyleBackColor = true;
this.CheckBoxNull.CheckedChanged += new System.EventHandler(this.CheckBoxNull_CheckedChanged);
//
// TextBoxDate
//
this.TextBoxDate.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.TextBoxDate.Location = new System.Drawing.Point(24, 3);
this.TextBoxDate.Name = "TextBoxDate";
this.TextBoxDate.Size = new System.Drawing.Size(271, 23);
this.TextBoxDate.TabIndex = 1;
this.TextBoxDate.TextChanged += new System.EventHandler(this.TextBoxDate_TextChanged);
//
// DateBoxWithNull
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.SystemColors.ControlLight;
this.Controls.Add(this.TextBoxDate);
this.Controls.Add(this.CheckBoxNull);
this.Name = "DateBoxWithNull";
this.Size = new System.Drawing.Size(298, 29);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private CheckBox CheckBoxNull;
private TextBox TextBoxDate;
}
}

View File

@@ -0,0 +1,86 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Forms.VisualStyles;
namespace Ivanov_visual_components
{
public partial class DateBoxWithNull : UserControl
{
public EventHandler? _changeEvent;
public EventHandler? _checkBoxEvent;
public Exception? Error;
public DateBoxWithNull()
{
InitializeComponent();
}
public DateTime? Value
{
get
{
Error = null;
if (!CheckBoxNull.Checked)
{
if (string.IsNullOrEmpty(TextBoxDate.Text))
{
Error = new NotFilledException("Text box can't be empty, click checkbox if value must be empty!");
return null;
}
if (DateTime.TryParseExact(TextBoxDate.Text, "dd/MM/yyyy", null, DateTimeStyles.None, out DateTime parsedDate))
{
return parsedDate;
}
else
{
Error = new ParseException($"Wrong format <{TextBoxDate.Text}>!");
return null;
}
}
return null;
}
set
{
if (value is null)
{
CheckBoxNull.Checked = true;
}
else
{
TextBoxDate.Text = value?.ToString("dd/MM/yyyy");
CheckBoxNull.Checked = false;
}
}
}
public event EventHandler CheckBoxEvent
{
add { _checkBoxEvent += value; }
remove { _checkBoxEvent += value; }
}
public event EventHandler ChangeEvent
{
add { _changeEvent += value; }
remove { _changeEvent += value; }
}
private void TextBoxDate_TextChanged(object sender, EventArgs e)
{
_changeEvent?.Invoke(sender, e);
}
private void CheckBoxNull_CheckedChanged(object sender, EventArgs e)
{
TextBoxDate.Enabled = !CheckBoxNull.Checked;
_checkBoxEvent?.Invoke(sender, e);
}
}
}

View File

@@ -0,0 +1,62 @@
namespace Ivanov_visual_components
{
partial class ItemList
{
/// <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()
{
this.ListBoxCustom = new System.Windows.Forms.ListBox();
this.SuspendLayout();
//
// ListBoxCustom
//
this.ListBoxCustom.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.ListBoxCustom.FormattingEnabled = true;
this.ListBoxCustom.ItemHeight = 15;
this.ListBoxCustom.Location = new System.Drawing.Point(0, 0);
this.ListBoxCustom.Name = "ListBoxCustom";
this.ListBoxCustom.Size = new System.Drawing.Size(272, 259);
this.ListBoxCustom.TabIndex = 0;
this.ListBoxCustom.SelectedIndexChanged += new System.EventHandler(this.ListBoxCustom_SelectedIndexChanged);
//
// ItemList
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.ListBoxCustom);
this.Name = "ItemList";
this.Size = new System.Drawing.Size(272, 265);
this.ResumeLayout(false);
}
#endregion
private ListBox ListBoxCustom;
}
}

View File

@@ -0,0 +1,64 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Ivanov_visual_components
{
public partial class ItemList : UserControl
{
private EventHandler? _changeEvent;
public ListBox.ObjectCollection Items => ListBoxCustom.Items;
public ItemList()
{
InitializeComponent();
}
public void Clear()
{
ListBoxCustom.Items.Clear();
}
public event EventHandler ChangeEvent
{
add
{
_changeEvent += value;
}
remove
{
_changeEvent -= value;
}
}
public string? SelectedElement
{
get
{
return (ListBoxCustom.SelectedIndex != -1 && ListBoxCustom.SelectedItem != null)
? ListBoxCustom.SelectedItem.ToString()
: string.Empty;
}
set
{
if (!string.IsNullOrEmpty(value))
{
int index = ListBoxCustom.FindString(value);
if (index == -1) return;
ListBoxCustom.SetSelected(index, true);
}
}
}
private void ListBoxCustom_SelectedIndexChanged(object sender, EventArgs e)
{
_changeEvent?.Invoke(sender, e);
}
}
}

View File

@@ -0,0 +1,72 @@
namespace Ivanov_visual_components
{
partial class ItemTable
{
/// <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()
{
this.DataGridViewItems = new System.Windows.Forms.DataGridView();
((System.ComponentModel.ISupportInitialize)(this.DataGridViewItems)).BeginInit();
this.SuspendLayout();
//
// DataGridViewItems
//
this.DataGridViewItems.AllowUserToAddRows = false;
this.DataGridViewItems.AllowUserToDeleteRows = false;
this.DataGridViewItems.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.DataGridViewItems.BackgroundColor = System.Drawing.SystemColors.ButtonFace;
this.DataGridViewItems.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.DataGridViewItems.GridColor = System.Drawing.SystemColors.ActiveCaptionText;
this.DataGridViewItems.Location = new System.Drawing.Point(0, 0);
this.DataGridViewItems.MultiSelect = false;
this.DataGridViewItems.Name = "DataGridViewItems";
this.DataGridViewItems.ReadOnly = true;
this.DataGridViewItems.RowHeadersVisible = false;
this.DataGridViewItems.RowTemplate.Height = 25;
this.DataGridViewItems.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
this.DataGridViewItems.ShowEditingIcon = false;
this.DataGridViewItems.Size = new System.Drawing.Size(548, 358);
this.DataGridViewItems.TabIndex = 0;
//
// ItemTable
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.DataGridViewItems);
this.Name = "ItemTable";
this.Size = new System.Drawing.Size(548, 358);
((System.ComponentModel.ISupportInitialize)(this.DataGridViewItems)).EndInit();
this.ResumeLayout(false);
}
#endregion
private DataGridView DataGridViewItems;
}
}

View File

@@ -0,0 +1,103 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Ivanov_visual_components
{
public partial class ItemTable : UserControl
{
public ItemTable()
{
InitializeComponent();
}
public int SelectedRow
{
get
{
return DataGridViewItems.SelectedRows[0].Index;
}
set
{
if (DataGridViewItems.SelectedRows.Count <= value || value < 0)
{
throw new ArgumentException(string.Format("{0} is an invalid row index.", value));
}
else
{
DataGridViewItems.ClearSelection();
DataGridViewItems.Rows[value].Selected = true;
}
}
}
public void ClearDataGrid()
{
DataGridViewItems.DataSource = null;
DataGridViewItems.Rows.Clear();
}
public void ConfigColumn(ColumnsConfiguratoin columnsData)
{
DataGridViewItems.ColumnCount = columnsData.ColumnsCount;
for (int i = 0; i < columnsData.ColumnsCount; i++)
{
DataGridViewItems.Columns[i].Name = columnsData.NameColumn[i];
DataGridViewItems.Columns[i].Width = columnsData.Width[i];
DataGridViewItems.Columns[i].Visible = columnsData.Visible[i];
DataGridViewItems.Columns[i].DataPropertyName = columnsData.PropertiesObject[i];
}
}
public T GetSelectedObjectInRow<T>() where T : class, new()
{
T val = new();
var propertiesObj = typeof(T).GetProperties();
foreach (var properties in propertiesObj)
{
bool propIsExist = false;
int columnIndex = 0;
for (; columnIndex < DataGridViewItems.Columns.Count; columnIndex++)
{
if (DataGridViewItems.Columns[columnIndex].DataPropertyName.ToString() == properties.Name)
{
propIsExist = true;
break;
}
}
if (propIsExist)
{
object value = DataGridViewItems.SelectedRows[0].Cells[columnIndex].Value;
properties.SetValue(val, Convert.ChangeType(value, properties.PropertyType));
};
}
return val;
}
public void AddItem<T>(T item, int RowIndex, int ColumnIndex)
{
if (item == null)
{
return;
}
string propertyName = DataGridViewItems.Columns[ColumnIndex].DataPropertyName.ToString();
string? value = item.GetType().GetProperty(propertyName)?.GetValue(item)?.ToString();
if (RowIndex >= DataGridViewItems.Rows.Count)
{
DataGridViewItems.RowCount = RowIndex + 1;
}
DataGridViewItems.Rows[RowIndex].Cells[ColumnIndex].Value = value;
}
}
}

View File

@@ -117,13 +117,4 @@
<resheader name="writer"> <resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader> </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> </root>

View File

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

View File

@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Ivanov_visual_components
{
public class NotFilledException : Exception
{
public NotFilledException() { }
public NotFilledException(string message) : base(message) { }
public NotFilledException(string message, Exception inner) : base(message, inner) { }
}
}

View File

@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Ivanov_visual_components
{
public class ParseException : Exception
{
public ParseException() { }
public ParseException(string message) : base(message) { }
public ParseException(string message, Exception innerException) : base(message, innerException) { }
}
}

31
KOP/KOP.sln Normal file
View File

@@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.10.35122.118
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ivanov_visual_components", "Ivanov_visual_components\Ivanov_visual_components.csproj", "{3FEAB427-D75C-442E-B5FE-6285202B442C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ivanov_App", "Ivanov_App\Ivanov_App.csproj", "{64CD7137-E0BF-4F35-8F33-B07AFED1393F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{3FEAB427-D75C-442E-B5FE-6285202B442C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3FEAB427-D75C-442E-B5FE-6285202B442C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3FEAB427-D75C-442E-B5FE-6285202B442C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3FEAB427-D75C-442E-B5FE-6285202B442C}.Release|Any CPU.Build.0 = Release|Any CPU
{64CD7137-E0BF-4F35-8F33-B07AFED1393F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{64CD7137-E0BF-4F35-8F33-B07AFED1393F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{64CD7137-E0BF-4F35-8F33-B07AFED1393F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{64CD7137-E0BF-4F35-8F33-B07AFED1393F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {1A537B19-2DD7-4FCC-9CFD-9A7FAEE5D675}
EndGlobalSection
EndGlobal

View File

@@ -1,21 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace custom_App
{
public class Book
{
public string Name { get; set; }
public string Author { get; set; }
public Book(string author, string name)
{
Author = author;
Name = name;
}
public Book() { }
}
}

View File

@@ -1,258 +0,0 @@
namespace custom_App
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
customComboBox = new Valova_VisualComponents.customComboBox();
customTextBox = new Valova_VisualComponents.customTextBox();
customListBox = new Valova_VisualComponents.customListBox();
buttonAddToComboBox = new Button();
buttonClearComboBox = new Button();
textBoxForComboBox = new TextBox();
buttonCheckComboBox = new Button();
buttonGetTextBox = new Button();
textBoxAuthor = new TextBox();
textBoxName = new TextBox();
textBoxRow = new TextBox();
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();
//
// customComboBox
//
customComboBox.BorderStyle = BorderStyle.FixedSingle;
customComboBox.Location = new Point(31, 12);
customComboBox.Name = "customComboBox";
customComboBox.Size = new Size(152, 150);
customComboBox.TabIndex = 0;
//
// customTextBox
//
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;
//
// customListBox
//
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
//
buttonAddToComboBox.Location = new Point(31, 196);
buttonAddToComboBox.Name = "buttonAddToComboBox";
buttonAddToComboBox.Size = new Size(152, 32);
buttonAddToComboBox.TabIndex = 3;
buttonAddToComboBox.Text = "Add item";
buttonAddToComboBox.UseVisualStyleBackColor = true;
buttonAddToComboBox.Click += buttonAddToComboBox_Click;
//
// buttonClearComboBox
//
buttonClearComboBox.Location = new Point(31, 234);
buttonClearComboBox.Name = "buttonClearComboBox";
buttonClearComboBox.Size = new Size(152, 32);
buttonClearComboBox.TabIndex = 4;
buttonClearComboBox.Text = "Clear";
buttonClearComboBox.UseVisualStyleBackColor = true;
buttonClearComboBox.Click += buttonClearComboBox_Click;
//
// textBoxForComboBox
//
textBoxForComboBox.Location = new Point(31, 168);
textBoxForComboBox.Name = "textBoxForComboBox";
textBoxForComboBox.Size = new Size(152, 23);
textBoxForComboBox.TabIndex = 5;
//
// buttonCheckComboBox
//
buttonCheckComboBox.Location = new Point(31, 272);
buttonCheckComboBox.Name = "buttonCheckComboBox";
buttonCheckComboBox.Size = new Size(152, 32);
buttonCheckComboBox.TabIndex = 6;
buttonCheckComboBox.Text = "Check";
buttonCheckComboBox.UseVisualStyleBackColor = true;
buttonCheckComboBox.Click += buttonCheckComboBox_Click;
//
// buttonGetTextBox
//
buttonGetTextBox.Location = new Point(236, 168);
buttonGetTextBox.Name = "buttonGetTextBox";
buttonGetTextBox.Size = new Size(161, 32);
buttonGetTextBox.TabIndex = 8;
buttonGetTextBox.Text = "Get";
buttonGetTextBox.UseVisualStyleBackColor = true;
buttonGetTextBox.Click += buttonGetTextBox_Click;
//
// textBoxAuthor
//
textBoxAuthor.Location = new Point(456, 177);
textBoxAuthor.Name = "textBoxAuthor";
textBoxAuthor.Size = new Size(148, 23);
textBoxAuthor.TabIndex = 9;
//
// textBoxName
//
textBoxName.Location = new Point(610, 177);
textBoxName.Name = "textBoxName";
textBoxName.Size = new Size(167, 23);
textBoxName.TabIndex = 10;
//
// textBoxRow
//
textBoxRow.Location = new Point(456, 240);
textBoxRow.Name = "textBoxRow";
textBoxRow.Size = new Size(32, 23);
textBoxRow.TabIndex = 11;
//
// textBoxPar
//
textBoxPar.Location = new Point(494, 240);
textBoxPar.Name = "textBoxPar";
textBoxPar.Size = new Size(148, 23);
textBoxPar.TabIndex = 12;
//
// button1
//
button1.Location = new Point(648, 234);
button1.Name = "button1";
button1.Size = new Size(100, 32);
button1.TabIndex = 13;
button1.Text = "Add";
button1.UseVisualStyleBackColor = true;
button1.Click += button1_Click;
//
// buttonGet
//
buttonGet.Location = new Point(567, 287);
buttonGet.Name = "buttonGet";
buttonGet.Size = new Size(100, 32);
buttonGet.TabIndex = 14;
buttonGet.Text = "Get";
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);
Controls.Add(textBoxRow);
Controls.Add(textBoxName);
Controls.Add(textBoxAuthor);
Controls.Add(buttonGetTextBox);
Controls.Add(buttonCheckComboBox);
Controls.Add(textBoxForComboBox);
Controls.Add(buttonClearComboBox);
Controls.Add(buttonAddToComboBox);
Controls.Add(customListBox);
Controls.Add(customTextBox);
Controls.Add(customComboBox);
Name = "Form1";
Text = "Form1";
ResumeLayout(false);
PerformLayout();
}
#endregion
private Valova_VisualComponents.customComboBox customComboBox;
private Valova_VisualComponents.customTextBox customTextBox;
private Valova_VisualComponents.customListBox customListBox;
private Button buttonAddToComboBox;
private Button buttonClearComboBox;
private TextBox textBoxForComboBox;
private Button buttonCheckComboBox;
private Button buttonGetTextBox;
private TextBox textBoxAuthor;
private TextBox textBoxName;
private TextBox textBoxRow;
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,136 +0,0 @@
using System.Text;
using Valova_VisualComponents;
using Valova_VisualComponents.Models;
namespace custom_App
{
public partial class Form1 : Form
{
List<Book> books = new List<Book>();
public Form1()
{
InitializeComponent();
customComboBox.Items.AddRange(new String[] { "1 example", "2 example", "3 example", "4 example" });
customTextBox.Pattern = @"^\+7\(\d{3}\)\d{3}-\d{2}-\d{2}$";
customTextBox.SetExample("+7(927)000-00-00");
customListBox.SetLayout("My favorite book is {Author} {Name}", "{", "}");
books.AddRange(new List<Book> { new Book("a", "A"), new Book("b", "B") });
}
private void customTextBox1_Load(object sender, EventArgs e)
{
}
private void buttonAddToComboBox_Click(object sender, EventArgs e)
{
if (!String.IsNullOrEmpty(textBoxForComboBox.Text))
{
customComboBox.Items.Add(textBoxForComboBox.Text);
textBoxForComboBox.Clear();
}
else
{
MessageBox.Show("Insert text");
}
}
private void buttonClearComboBox_Click(object sender, EventArgs e)
{
customComboBox.Clear();
}
private void buttonCheckComboBox_Click(object sender, EventArgs e)
{
textBoxForComboBox.Text = customComboBox.SelectedValue;
}
private void buttonGetTextBox_Click(object sender, EventArgs e)
{
MessageBox.Show(customTextBox.TextBoxValue);
}
private void customListBox_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
Book newBook = new Book(textBoxAuthor.Text, textBoxName.Text);
customListBox.AddItemInList(newBook, int.Parse(textBoxRow.Text), textBoxPar.Text);
}
private void buttonGet_Click(object sender, EventArgs e)
{
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), (15, 0), (15, 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"),
(2, 0, "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>", "Author"),
(3, 0, "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", "Name"),
(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

@@ -1,49 +0,0 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
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("{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
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{23CBD69E-2876-4A20-996F-4230AD3E642A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{23CBD69E-2876-4A20-996F-4230AD3E642A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{23CBD69E-2876-4A20-996F-4230AD3E642A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{23CBD69E-2876-4A20-996F-4230AD3E642A}.Release|Any CPU.Build.0 = Release|Any CPU
{EF001CCD-92F6-4A12-AC58-39CFF673A16B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{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
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {8560DD17-BEB9-41F4-9FC5-FA6D16222CB6}
EndGlobalSection
EndGlobal

View File

@@ -1,36 +0,0 @@
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

@@ -1,117 +0,0 @@
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

@@ -1,36 +0,0 @@
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

@@ -1,159 +0,0 @@
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

@@ -1,36 +0,0 @@
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

@@ -1,82 +0,0 @@
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)
{
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.Size = 30;
paragraph.Format.Font.Bold = true;
}
public void CreateParagraph(string text) => this.Document.LastSection.AddParagraph(text, "Normal");
}
}

View File

@@ -1,166 +0,0 @@
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

@@ -1,21 +0,0 @@
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

@@ -1,16 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
namespace Valova_VisualComponents
{
public class InvalidLayoutException : ApplicationException
{
public InvalidLayoutException() : base("Значение не соответсвует шаблону") { }
public InvalidLayoutException(string message) : base(message) { }
public InvalidLayoutException(string message, Exception exception) : base(message, exception) { }
}
}

View File

@@ -1,29 +0,0 @@
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

@@ -1,23 +0,0 @@
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

@@ -1,21 +0,0 @@
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

@@ -1,17 +0,0 @@
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

@@ -1,17 +0,0 @@
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

@@ -1,16 +0,0 @@
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,16 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
namespace Valova_VisualComponents
{
public class PatternNotSetException : ApplicationException
{
public PatternNotSetException() : base("Шаблон не задан") { }
public PatternNotSetException(string message) : base(message) { }
public PatternNotSetException(string message, Exception exception) : base(message, exception) { }
}
}

View File

@@ -1,57 +0,0 @@
namespace Valova_VisualComponents
{
partial class customComboBox
{
/// <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()
{
comboBox = new ComboBox();
SuspendLayout();
//
// comboBox
//
comboBox.FormattingEnabled = true;
comboBox.Location = new Point(3, 3);
comboBox.Name = "comboBox";
comboBox.Size = new Size(144, 23);
comboBox.TabIndex = 0;
comboBox.SelectedIndexChanged += comboBox_SelectedIndexChanged;
//
// customComboBox
//
BorderStyle = BorderStyle.FixedSingle;
Controls.Add(comboBox);
Name = "customComboBox";
Size = new Size(148, 148);
ResumeLayout(false);
}
#endregion
private ComboBox comboBox;
}
}

View File

@@ -1,61 +0,0 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Valova_VisualComponents
{
public partial class customComboBox : UserControl
{
public ComboBox.ObjectCollection Items => comboBox.Items;
public event EventHandler _сhangeEvent;
public event EventHandler ChangeEvent
{
add
{
_сhangeEvent += value;
}
remove
{
_сhangeEvent -= value;
}
}
public customComboBox()
{
InitializeComponent();
}
public string SelectedValue
{
get
{
return comboBox.SelectedItem.ToString() ?? string.Empty;
}
set
{
comboBox.SelectedIndex = comboBox.Items.IndexOf(value);
}
}
public void Clear()
{
Items.Clear();
}
private void comboBox_SelectedIndexChanged(object sender, EventArgs e)
{
_сhangeEvent?.Invoke(this, e);
}
}
}

View File

@@ -1,58 +0,0 @@
namespace Valova_VisualComponents
{
partial class customListBox
{
/// <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()
{
listBox = new ListBox();
SuspendLayout();
//
// listBox
//
listBox.FormattingEnabled = true;
listBox.ItemHeight = 15;
listBox.Location = new Point(2, 11);
listBox.Name = "listBox";
listBox.Size = new Size(314, 109);
listBox.TabIndex = 0;
//
// customListBox
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
BorderStyle = BorderStyle.FixedSingle;
Controls.Add(listBox);
Name = "customListBox";
Size = new Size(319, 148);
ResumeLayout(false);
}
#endregion
private ListBox listBox;
}
}

View File

@@ -1,113 +0,0 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Valova_VisualComponents
{
public partial class customListBox : UserControl
{
private string LayoutString;
private string StartS;
private string EndS;
private int SelectedStr;
public customListBox()
{
InitializeComponent();
}
public int SelectedIndex
{
get
{
if (listBox.SelectedIndex == -1)
{
return -1;
}
return listBox.SelectedIndex;
}
set
{
if (listBox.Items.Count != 0)
{
listBox.SelectedIndex = value;
}
}
}
public void SetLayout(string layoutString, string startS, string endS)
{
if (layoutString == null || startS == null || endS == null) return;
LayoutString = layoutString;
StartS = startS;
EndS = endS;
}
public void AddItemInList<T>(T obj, int rowIndex, string propertyName)
{
if (obj == null)
{
throw new ArgumentNullException();
}
if (listBox.Items.Count <= rowIndex)
{
for (int i = listBox.Items.Count; i <= rowIndex; i++)
{
listBox.Items.Add(LayoutString);
}
}
string str = listBox.Items[rowIndex].ToString();
var properties = obj.GetType().GetProperties();
var prop = properties.FirstOrDefault(p => p.Name.Equals(propertyName, StringComparison.OrdinalIgnoreCase));
if (prop != null)
{
string str1 = $"{StartS}{prop.Name}{EndS}";
str = str.Replace(str1, $"{StartS}{prop.GetValue(obj)?.ToString()}{EndS}");
}
else
{
throw new ArgumentException($"Свойство с именем '{propertyName}' не найдено в объекте.");
}
listBox.Items[rowIndex] = str;
}
public T GetItemFromList<T>() where T : class, new()
{
string SelectedStr = "";
if (listBox.SelectedIndex != -1)
{
SelectedStr = listBox.SelectedItem.ToString();
}
T currentObject = new T();
foreach (var prop in typeof(T).GetProperties())
{
if (!prop.CanWrite)
{
continue;
}
int startS = SelectedStr.IndexOf(StartS);
int endS = SelectedStr.IndexOf(EndS);
if (startS == -1 || endS == -1)
{
break;
}
string propValue = SelectedStr.Substring(startS + 1, endS - startS - 1);
SelectedStr = SelectedStr.Substring(endS + 1);
prop.SetValue(currentObject, Convert.ChangeType(propValue, prop.PropertyType));
}
return currentObject;
}
}
}

View File

@@ -1,59 +0,0 @@
namespace Valova_VisualComponents
{
partial class customTextBox
{
/// <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()
{
textBox = new TextBox();
SuspendLayout();
//
// textBox
//
textBox.Location = new Point(-1, 18);
textBox.Name = "textBox";
textBox.Size = new Size(161, 23);
textBox.TabIndex = 0;
textBox.TextChanged += textBox_TextChanged;
textBox.Enter += textBox_Enter;
//
// customTextBox
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
BorderStyle = BorderStyle.FixedSingle;
Controls.Add(textBox);
Name = "customTextBox";
Size = new Size(159, 146);
ResumeLayout(false);
PerformLayout();
}
#endregion
private TextBox textBox;
}
}

View File

@@ -1,98 +0,0 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Valova_VisualComponents
{
public partial class customTextBox : UserControl
{
private string? pattern;
private string example = "+7(XXX)XXX-XX-XX";
public customTextBox()
{
InitializeComponent();
}
public string? Pattern
{
get { return pattern; }
set { pattern = value; }
}
public string TextBoxValue
{
get
{
if (string.IsNullOrEmpty(Pattern))
throw new PatternNotSetException();
Regex regex = new Regex(Pattern);
bool isValid = regex.IsMatch(textBox.Text);
if (isValid)
{
return textBox.Text;
}
else throw new InvalidLayoutException();
}
set
{
Regex regex = new Regex(Pattern);
bool isValid = regex.IsMatch(value);
if (isValid)
{
textBox.Text = value;
}
else
{
Error = "Неправильно";
}
}
}
public string Error
{
get; private set;
}
public void SetExample(string exampleStr)
{
Regex regex = new Regex(Pattern);
bool isValid = regex.IsMatch(exampleStr);
if (isValid)
{
example = exampleStr;
}
}
private void textBox_Enter(object sender, EventArgs e)
{
ToolTip tt = new ToolTip();
tt.Show(example, textBox, 20, -21, 2000);
}
private void textBox_TextChanged(object sender, EventArgs e)
{
_changeEvent?.Invoke(sender, e);
}
private EventHandler _changeEvent;
public event EventHandler ChangeEvent
{
add
{
_changeEvent += value;
}
remove
{
_changeEvent -= value;
}
}
}
}