исправлен компонент 3

This commit is contained in:
DyCTaTOR 2024-11-14 20:27:58 +04:00
parent f5a1ac2240
commit 7bd3733c6e
21 changed files with 378 additions and 131 deletions

View File

@ -14,6 +14,6 @@ namespace Contracts.BindingModels
public string Name { get; set; } = string.Empty; public string Name { get; set; } = string.Empty;
public string Description { get; set; } = string.Empty; public string Description { get; set; } = string.Empty;
public string Category { get; set; } = string.Empty; public string Category { get; set; } = string.Empty;
public int CountOnStorage { get; set; } public int? CountOnStorage { get; set; }
} }
} }

View File

@ -12,6 +12,6 @@ namespace Contracts.ViewModels
{ {
public int Id { get; set; } public int Id { get; set; }
[DisplayName("Название")] [DisplayName("Название")]
public string Name { get; set; } = string.Empty; public string Name { get; set; } = "Название категории";
} }
} }

View File

@ -9,9 +9,9 @@ using System.Threading.Tasks;
namespace Contracts.ViewModels namespace Contracts.ViewModels
{ {
public class ProductViewModel : IProductModel public class ProductViewModel
{ {
public int Id { get; set; } public string Id { get; set; }
[DisplayName("Название")] [DisplayName("Название")]
public string Name { get; set; } = string.Empty; public string Name { get; set; } = string.Empty;
[DisplayName("Описание")] [DisplayName("Описание")]
@ -19,6 +19,7 @@ namespace Contracts.ViewModels
[DisplayName("Категория продукта")] [DisplayName("Категория продукта")]
public string Category { get; set; } = string.Empty; public string Category { get; set; } = string.Empty;
[DisplayName("Количество товаров на складе")] [DisplayName("Количество товаров на складе")]
public int CountOnStorage { get; set; } public int? CountOnStorage { get; set; }
public string? CountOnStorageS { get; set; }
} }
} }

View File

@ -0,0 +1,76 @@
// <auto-generated />
using System;
using DatabaseImplement;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace DatabaseImplement.Migrations
{
[DbContext(typeof(Database))]
[Migration("20241112051510_nullableCountOnStorage")]
partial class nullableCountOnStorage
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "8.0.10")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("DatabaseImplement.Models.Category", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Categories");
});
modelBuilder.Entity("DatabaseImplement.Models.Product", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Category")
.IsRequired()
.HasColumnType("text");
b.Property<int?>("CountOnStorage")
.IsRequired()
.HasColumnType("integer");
b.Property<string>("Description")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Products");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,22 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace DatabaseImplement.Migrations
{
/// <inheritdoc />
public partial class nullableCountOnStorage : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
}
}
}

View File

@ -0,0 +1,75 @@
// <auto-generated />
using System;
using DatabaseImplement;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace DatabaseImplement.Migrations
{
[DbContext(typeof(Database))]
[Migration("20241112052212_nullableCountOnStorage2")]
partial class nullableCountOnStorage2
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "8.0.10")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("DatabaseImplement.Models.Category", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Categories");
});
modelBuilder.Entity("DatabaseImplement.Models.Product", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Category")
.IsRequired()
.HasColumnType("text");
b.Property<int?>("CountOnStorage")
.HasColumnType("integer");
b.Property<string>("Description")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Products");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,36 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace DatabaseImplement.Migrations
{
/// <inheritdoc />
public partial class nullableCountOnStorage2 : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<int>(
name: "CountOnStorage",
table: "Products",
type: "integer",
nullable: true,
oldClrType: typeof(int),
oldType: "integer");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<int>(
name: "CountOnStorage",
table: "Products",
type: "integer",
nullable: false,
defaultValue: 0,
oldClrType: typeof(int),
oldType: "integer",
oldNullable: true);
}
}
}

View File

@ -1,4 +1,5 @@
// <auto-generated /> // <auto-generated />
using System;
using DatabaseImplement; using DatabaseImplement;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Infrastructure;
@ -50,7 +51,7 @@ namespace DatabaseImplement.Migrations
.IsRequired() .IsRequired()
.HasColumnType("text"); .HasColumnType("text");
b.Property<int>("CountOnStorage") b.Property<int?>("CountOnStorage")
.HasColumnType("integer"); .HasColumnType("integer");
b.Property<string>("Description") b.Property<string>("Description")

View File

@ -25,8 +25,7 @@ namespace DatabaseImplement.Models
[Required] [Required]
public string Category { get; private set; } public string Category { get; private set; }
[Required] public int? CountOnStorage { get; private set; }
public int CountOnStorage { get; private set; }
public static Product? Create(ProductBindingModel model) public static Product? Create(ProductBindingModel model)
{ {
@ -54,11 +53,12 @@ namespace DatabaseImplement.Models
public ProductViewModel GetViewModel => new() public ProductViewModel GetViewModel => new()
{ {
Id = Id, Id = Id.ToString(),
Name = Name, Name = Name,
Description = Description, Description = Description,
Category = Category, Category = Category,
CountOnStorage = CountOnStorage, CountOnStorage = CountOnStorage,
CountOnStorageS = CountOnStorage != null ? CountOnStorage.ToString() : "Нет в наличии",
}; };
} }
} }

View File

@ -12,6 +12,6 @@ namespace Models.Models
string Name { get;} string Name { get;}
string Description { get;} string Description { get;}
string Category { get;} string Category { get;}
int CountOnStorage { get;} int? CountOnStorage { get;}
} }
} }

View File

@ -18,8 +18,8 @@ namespace WinFormsApp1
private void InitializeComponent() private void InitializeComponent()
{ {
comboBoxUserControl = new ComboBox(); comboBoxUserControl = new ComboBox();
listBoxUserControl = new ListBox();
dateInputControl1 = new DateInputControl(); dateInputControl1 = new DateInputControl();
listBoxUserControl = new ListBoxUserControl();
SuspendLayout(); SuspendLayout();
// //
// comboBoxUserControl // comboBoxUserControl
@ -30,29 +30,31 @@ namespace WinFormsApp1
comboBoxUserControl.Size = new Size(160, 28); comboBoxUserControl.Size = new Size(160, 28);
comboBoxUserControl.TabIndex = 0; comboBoxUserControl.TabIndex = 0;
// //
// listBoxUserControl
//
listBoxUserControl.Location = new Point(13, 231);
listBoxUserControl.Margin = new Padding(4, 5, 4, 5);
listBoxUserControl.Name = "listBoxUserControl";
listBoxUserControl.Size = new Size(159, 144);
listBoxUserControl.TabIndex = 2;
//
// dateInputControl1 // dateInputControl1
// //
dateInputControl1.DateFormat = null;
dateInputControl1.Location = new Point(13, 107); dateInputControl1.Location = new Point(13, 107);
dateInputControl1.Margin = new Padding(4, 5, 4, 5); dateInputControl1.Margin = new Padding(4, 5, 4, 5);
dateInputControl1.Name = "dateInputControl1"; dateInputControl1.Name = "dateInputControl1";
dateInputControl1.Size = new Size(166, 96); dateInputControl1.Size = new Size(166, 96);
dateInputControl1.TabIndex = 3; dateInputControl1.TabIndex = 3;
// //
// listBoxUserControl
//
listBoxUserControl.Location = new Point(13, 233);
listBoxUserControl.Margin = new Padding(4, 5, 4, 5);
listBoxUserControl.Name = "listBoxUserControl";
listBoxUserControl.SelectedIndex = -1;
listBoxUserControl.Size = new Size(365, 182);
listBoxUserControl.TabIndex = 4;
//
// Form1 // Form1
// //
AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(400, 462); ClientSize = new Size(400, 462);
Controls.Add(dateInputControl1);
Controls.Add(listBoxUserControl); Controls.Add(listBoxUserControl);
Controls.Add(dateInputControl1);
Controls.Add(comboBoxUserControl); Controls.Add(comboBoxUserControl);
Margin = new Padding(4, 5, 4, 5); Margin = new Padding(4, 5, 4, 5);
Name = "Form1"; Name = "Form1";
@ -61,7 +63,7 @@ namespace WinFormsApp1
} }
private ComboBox comboBoxUserControl; private ComboBox comboBoxUserControl;
private ListBox listBoxUserControl;
private DateInputControl dateInputControl1; private DateInputControl dateInputControl1;
private ListBoxUserControl listBoxUserControl;
} }
} }

View File

@ -9,6 +9,19 @@ namespace WinFormsApp1
public Form1() public Form1()
{ {
InitializeComponent(); InitializeComponent();
listBoxUserControl.SetParams("Id {Id} Íŕçâŕíčĺ {Name} Ôŕěčëč˙ {Familia}", '{', '}');
listBoxUserControl.AddObject<User>(new User(1, "status1", "Vova", "Stroev", 19, "FIST", 35000.50));
listBoxUserControl.AddObject<User>(new User(1, "status2", "Vladimir", "Stroev", 20, "FIST", 33000.50));
listBoxUserControl.AddObject<User>(new User(1, "status3", "Volodya", "Stroev", 21, "FIST", 39000.50));
listBoxUserControl.AddObject<User>(new User(1, "status3", "Volodya", "Stroev", 21, "FIST", 39000.50));
listBoxUserControl.AddObject<User>(new User(1, "status3", "Volodya", "Stroev", 21, "FIST", 39000.50));
listBoxUserControl.AddObject<User>(new User(1, "status3", "Volodya", "Stroev", 21, "FIST", 39000.50));
listBoxUserControl.AddObject<User>(new User(1, "status3", "Volodya", "Stroev", 21, "FIST", 39000.50));
listBoxUserControl.AddObject<User>(new User(1, "status3", "Volodya", "Stroev", 21, "FIST", 39000.50));
listBoxUserControl.AddObject<User>(new User(1, "status3", "Volodya", "Stroev", 21, "FIST", 39000.50));
listBoxUserControl.AddObject<User>(new User(1, "status3", "Volodya", "Stroev", 21, "FIST", 39000.50));
listBoxUserControl.AddObject<User>(new User(1, "status3", "Volodya", "Stroev", 21, "FIST", 39000.50));
} }
private void ComboBoxUserControl_SelectedValueChanged(object sender, EventArgs e) private void ComboBoxUserControl_SelectedValueChanged(object sender, EventArgs e)
@ -16,9 +29,9 @@ namespace WinFormsApp1
MessageBox.Show($"ComboBox selected: {comboBoxUserControl.SelectedValue}"); MessageBox.Show($"ComboBox selected: {comboBoxUserControl.SelectedValue}");
} }
private void ListBoxUserControl_SelectedValueChanged(object sender, EventArgs e) /*private void ListBoxUserControl_SelectedValueChanged(object sender, EventArgs e)
{ {
MessageBox.Show($"ListBox selected: {listBoxUserControl.SelectedValue}"); MessageBox.Show($"ListBox selected: {listBoxUserControl.SelectedValue}");
} }*/
} }
} }

View File

@ -9,7 +9,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Library14Petrushin" Version="1.0.0" /> <PackageReference Include="Library14Petrushin" Version="1.0.1" />
<PackageReference Include="Library15Gerimovich" Version="1.0.0" /> <PackageReference Include="Library15Gerimovich" Version="1.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.10"> <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.10">
<PrivateAssets>all</PrivateAssets> <PrivateAssets>all</PrivateAssets>

View File

@ -29,26 +29,26 @@
private void InitializeComponent() private void InitializeComponent()
{ {
components = new System.ComponentModel.Container(); components = new System.ComponentModel.Container();
_productListControl = new Library15Gerimovich.OutputTableResults(); _productTreeView = new Library14Petrushin.HierarchicalTreeView();
wordTablesComponent1 = new Library15Gerimovich.WordTablesComponent(components); wordTablesComponent1 = new Library15Gerimovich.WordTablesComponent(components);
SuspendLayout(); SuspendLayout();
// //
// _productListControl // _productTreeView
// //
_productListControl.Dock = DockStyle.Fill; _productTreeView.Dock = DockStyle.Fill;
_productListControl.Location = new Point(0, 0); _productTreeView.Location = new Point(0, 0);
_productListControl.Margin = new Padding(3, 5, 3, 5); _productTreeView.Margin = new Padding(3, 5, 3, 5);
_productListControl.Name = "_productListControl"; _productTreeView.Name = "_productTreeView";
_productListControl.SelectedRow = -1; _productTreeView.SelectedNodeIndex = -1;
_productListControl.Size = new Size(487, 335); _productTreeView.Size = new Size(292, 521);
_productListControl.TabIndex = 0; _productTreeView.TabIndex = 0;
// //
// MainForm // MainForm
// //
AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(487, 335); ClientSize = new Size(292, 521);
Controls.Add(_productListControl); Controls.Add(_productTreeView);
Margin = new Padding(3, 4, 3, 4); Margin = new Padding(3, 4, 3, 4);
Name = "MainForm"; Name = "MainForm";
Text = "Учет продуктов в магазине"; Text = "Учет продуктов в магазине";
@ -58,7 +58,7 @@
#endregion #endregion
private Library15Gerimovich.OutputTableResults _productListControl; private Library14Petrushin.HierarchicalTreeView _productTreeView;
private Library15Gerimovich.WordTablesComponent wordTablesComponent1; private Library15Gerimovich.WordTablesComponent wordTablesComponent1;
} }
} }

View File

@ -31,25 +31,14 @@ namespace Forms
private void LoadProducts() private void LoadProducts()
{ {
var products = _productLogic.ReadList(null); var products = _productLogic.ReadList(null);
_productListControl.ClearGrid();
// Создаем список столбцов var hierarchy = new List<string> { "Category", "CountOnStorageS", "Id", "Name" };
var columns = new List<ColumnInfo> var alwaysNewBranch = new Dictionary<string, bool> { { "Name", true } };
{ _productTreeView.SetHierarchy(hierarchy, alwaysNewBranch);
new ColumnInfo("ID", 50, false, "Id"),
new ColumnInfo("Название", 150, true, "Name"),
new ColumnInfo("Описание", 200, true, "Description"),
new ColumnInfo("Категория продукта", 150, true, "Category"),
new ColumnInfo("Количество товаров на складе", 150, true, "CountOnStorage")
};
// Настраиваем столбцы в DataGridView
_productListControl.ConfigureColumns(columns);
// Добавляем строки
foreach (var product in products) foreach (var product in products)
{ {
_productListControl.InsertValue(product); _productTreeView.AddObjectToTree(product, "Name");
} }
} }
@ -65,7 +54,7 @@ namespace Forms
contextMenu.Items.Add("Создать документ с диаграммой", null, (s, ev) => CreateChartDocument()); contextMenu.Items.Add("Создать документ с диаграммой", null, (s, ev) => CreateChartDocument());
// Привязка контекстного меню к компоненту вывода списков // Привязка контекстного меню к компоненту вывода списков
_productListControl.ContextMenuStrip = contextMenu; _productTreeView.ContextMenuStrip = contextMenu;
// Настройка горячих клавиш // Настройка горячих клавиш
this.KeyDown += MainForm_KeyDown; this.KeyDown += MainForm_KeyDown;
@ -77,6 +66,34 @@ namespace Forms
this.Controls.Add(toolStrip); this.Controls.Add(toolStrip);
} }
private void MainForm_KeyDown(object sender, KeyEventArgs e)
{
if (e.Control)
{
switch (e.KeyCode)
{
case Keys.A:
AddProduct();
break;
case Keys.U:
EditProduct();
break;
case Keys.D:
DeleteProduct();
break;
case Keys.S:
CreateDocument();
break;
case Keys.T:
CreateTableDocument();
break;
case Keys.C:
CreateChartDocument();
break;
}
}
}
private void OpenProductForm() private void OpenProductForm()
{ {
var form = new ProductForm(_productLogic, _categoryLogic); var form = new ProductForm(_productLogic, _categoryLogic);
@ -128,37 +145,8 @@ namespace Forms
return base.ProcessCmdKey(ref msg, keyData); return base.ProcessCmdKey(ref msg, keyData);
} }
private void MainForm_KeyDown(object sender, KeyEventArgs e)
{
if (e.Control)
{
switch (e.KeyCode)
{
case Keys.A:
AddProduct();
break;
case Keys.U:
EditProduct();
break;
case Keys.D:
DeleteProduct();
break;
case Keys.S:
CreateDocument();
break;
case Keys.T:
CreateTableDocument();
break;
case Keys.C:
CreateChartDocument();
break;
}
}
}
private void AddProduct() private void AddProduct()
{ {
// Логика добавления нового продукта
var form = new ProductForm(_productLogic, _categoryLogic); var form = new ProductForm(_productLogic, _categoryLogic);
if (form.ShowDialog() == DialogResult.OK) if (form.ShowDialog() == DialogResult.OK)
{ {
@ -168,8 +156,11 @@ namespace Forms
private void EditProduct() private void EditProduct()
{ {
// Логика редактирования выбранного продукта var selectedProduct = _productTreeView.GetSelectedObject<ProductViewModel>();
var selectedProduct = _productListControl.GetSelectedObject<ProductViewModel>(); selectedProduct = _productLogic.ReadElement(new ProductSearchModel
{
Id = int.Parse(selectedProduct.Id)
});
if (selectedProduct != null) if (selectedProduct != null)
{ {
var form = new ProductForm(_productLogic, _categoryLogic, selectedProduct); var form = new ProductForm(_productLogic, _categoryLogic, selectedProduct);
@ -182,14 +173,17 @@ namespace Forms
private void DeleteProduct() private void DeleteProduct()
{ {
// Логика удаления выбранного продукта var selectedProduct = _productTreeView.GetSelectedObject<ProductViewModel>();
var selectedProduct = _productListControl.GetSelectedObject<ProductViewModel>(); selectedProduct = _productLogic.ReadElement(new ProductSearchModel
{
Id = int.Parse(selectedProduct.Id)
});
if (selectedProduct != null) if (selectedProduct != null)
{ {
var result = MessageBox.Show("Вы действительно хотите удалить этот продукт?", "Подтверждение", MessageBoxButtons.YesNo); var result = MessageBox.Show("Вы действительно хотите удалить этот продукт?", "Подтверждение", MessageBoxButtons.YesNo);
if (result == DialogResult.Yes) if (result == DialogResult.Yes)
{ {
_productLogic.Delete(new ProductBindingModel { Id = selectedProduct.Id }); _productLogic.Delete(new ProductBindingModel { Id = int.Parse(selectedProduct.Id) });
LoadProducts(); LoadProducts();
} }
} }

View File

@ -52,11 +52,11 @@ namespace Forms
{ {
var model = new ProductBindingModel var model = new ProductBindingModel
{ {
Id = _product?.Id ?? 0, Id = string.IsNullOrEmpty(_product?.Id) ? 0 : int.Parse(_product?.Id),
Name = textBoxName.Text, Name = textBoxName.Text,
Description = textBoxDescription.Text, Description = textBoxDescription.Text,
Category = _categoryComboBox.SelectedValue, Category = _categoryComboBox.SelectedValue,
CountOnStorage = (int)_countOnStorageControl.DoubleValue CountOnStorage = _countOnStorageControl.DoubleValue != null ? (int?)_countOnStorageControl.DoubleValue : null
}; };
if (_isNewProduct) if (_isNewProduct)

View File

@ -28,7 +28,7 @@ namespace WinFormsApp1
ConfigureServices(services); ConfigureServices(services);
_serviceProvider = services.BuildServiceProvider(); _serviceProvider = services.BuildServiceProvider();
Application.Run(_serviceProvider.GetRequiredService<MainForm>()); Application.Run(_serviceProvider.GetRequiredService<Form1>());
} }
private static void ConfigureServices(ServiceCollection services) private static void ConfigureServices(ServiceCollection services)
@ -47,6 +47,7 @@ namespace WinFormsApp1
services.AddTransient<CategoryForm>(); services.AddTransient<CategoryForm>();
services.AddTransient<ProductForm>(); services.AddTransient<ProductForm>();
services.AddTransient<MainForm>(); services.AddTransient<MainForm>();
services.AddTransient<Form1>();
} }
} }
} }

View File

@ -15,26 +15,27 @@
private void InitializeComponent() private void InitializeComponent()
{ {
this.listBox = new System.Windows.Forms.ListBox(); listBox = new ListBox();
this.SuspendLayout(); SuspendLayout();
// //
// listBox // listBox
// //
this.listBox.FormattingEnabled = true; listBox.FormattingEnabled = true;
this.listBox.Location = new System.Drawing.Point(0, 0); listBox.Location = new Point(0, 0);
this.listBox.Name = "listBox"; listBox.Margin = new Padding(4, 5, 4, 5);
this.listBox.Size = new System.Drawing.Size(120, 95); listBox.Name = "listBox";
this.listBox.TabIndex = 0; listBox.Size = new Size(594, 144);
//this.listBox.SelectedIndexChanged += new System.EventHandler(this.listBox_SelectedIndexChanged); listBox.TabIndex = 0;
// //
// ListBoxUserControl // ListBoxUserControl
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); AutoScaleDimensions = new SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
this.Controls.Add(this.listBox); Controls.Add(listBox);
this.Name = "ListBoxUserControl"; Margin = new Padding(4, 5, 4, 5);
this.Size = new System.Drawing.Size(120, 95); Name = "ListBoxUserControl";
this.ResumeLayout(false); Size = new Size(598, 146);
ResumeLayout(false);
} }
private System.Windows.Forms.ListBox listBox; private System.Windows.Forms.ListBox listBox;

View File

@ -116,5 +116,30 @@ namespace WinFormsLibrary1
{ {
return member is PropertyInfo property ? property.PropertyType : ((FieldInfo)member).FieldType; return member is PropertyInfo property ? property.PropertyType : ((FieldInfo)member).FieldType;
} }
public void AddObject<T>(T obj)
{
if (obj == null)
{
throw new ArgumentNullException("Добавляемый объект не существует!");
}
if (string.IsNullOrEmpty(_template) || !_startSymbol.HasValue || !_endSymbol.HasValue)
{
throw new Exception("Заполните макетную строку!");
}
if (!_template.Contains((char)_startSymbol) || !_template.Contains((char)_endSymbol))
{
throw new Exception("Макетная строка не содержит нужные элементы!");
}
string processedString = _template;
foreach (var property in obj.GetType().GetProperties())
{
string placeholder = $"{_startSymbol}{property.Name}{_endSymbol}";
processedString = processedString.Replace(placeholder, $"{_startSymbol}{property.GetValue(obj)}{_endSymbol}");
}
listBox.Items.Add(processedString);
}
} }
} }

View File

@ -6,7 +6,7 @@
<UseWindowsForms>true</UseWindowsForms> <UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild> <GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Version>1.0.2</Version> <Version>1.0.3</Version>
<Title>Library13StroevV</Title> <Title>Library13StroevV</Title>
</PropertyGroup> </PropertyGroup>