исправлен компонент 3
This commit is contained in:
parent
f5a1ac2240
commit
7bd3733c6e
@ -14,6 +14,6 @@ namespace Contracts.BindingModels
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public string Description { get; set; } = string.Empty;
|
||||
public string Category { get; set; } = string.Empty;
|
||||
public int CountOnStorage { get; set; }
|
||||
public int? CountOnStorage { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,6 @@ namespace Contracts.ViewModels
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[DisplayName("Название")]
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public string Name { get; set; } = "Название категории";
|
||||
}
|
||||
}
|
||||
|
@ -9,9 +9,9 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace Contracts.ViewModels
|
||||
{
|
||||
public class ProductViewModel : IProductModel
|
||||
public class ProductViewModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Id { get; set; }
|
||||
[DisplayName("Название")]
|
||||
public string Name { get; set; } = string.Empty;
|
||||
[DisplayName("Описание")]
|
||||
@ -19,6 +19,7 @@ namespace Contracts.ViewModels
|
||||
[DisplayName("Категория продукта")]
|
||||
public string Category { get; set; } = string.Empty;
|
||||
[DisplayName("Количество товаров на складе")]
|
||||
public int CountOnStorage { get; set; }
|
||||
public int? CountOnStorage { get; set; }
|
||||
public string? CountOnStorageS { get; set; }
|
||||
}
|
||||
}
|
||||
|
76
WinFormsLibrary1/DatabaseImplement/Migrations/20241112051510_nullableCountOnStorage.Designer.cs
generated
Normal file
76
WinFormsLibrary1/DatabaseImplement/Migrations/20241112051510_nullableCountOnStorage.Designer.cs
generated
Normal 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
|
||||
}
|
||||
}
|
||||
}
|
@ -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)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
75
WinFormsLibrary1/DatabaseImplement/Migrations/20241112052212_nullableCountOnStorage2.Designer.cs
generated
Normal file
75
WinFormsLibrary1/DatabaseImplement/Migrations/20241112052212_nullableCountOnStorage2.Designer.cs
generated
Normal file
@ -0,0 +1,75 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using DatabaseImplement;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.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
|
||||
}
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using DatabaseImplement;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
@ -50,7 +51,7 @@ namespace DatabaseImplement.Migrations
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("CountOnStorage")
|
||||
b.Property<int?>("CountOnStorage")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("Description")
|
||||
|
@ -25,8 +25,7 @@ namespace DatabaseImplement.Models
|
||||
[Required]
|
||||
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)
|
||||
{
|
||||
@ -54,11 +53,12 @@ namespace DatabaseImplement.Models
|
||||
|
||||
public ProductViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
Id = Id.ToString(),
|
||||
Name = Name,
|
||||
Description = Description,
|
||||
Category = Category,
|
||||
CountOnStorage = CountOnStorage,
|
||||
CountOnStorageS = CountOnStorage != null ? CountOnStorage.ToString() : "Нет в наличии",
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,6 @@ namespace Models.Models
|
||||
string Name { get;}
|
||||
string Description { get;}
|
||||
string Category { get;}
|
||||
int CountOnStorage { get;}
|
||||
int? CountOnStorage { get;}
|
||||
}
|
||||
}
|
||||
|
24
WinFormsLibrary1/WinFormsApp1/Form1.Designer.cs
generated
24
WinFormsLibrary1/WinFormsApp1/Form1.Designer.cs
generated
@ -18,8 +18,8 @@ namespace WinFormsApp1
|
||||
private void InitializeComponent()
|
||||
{
|
||||
comboBoxUserControl = new ComboBox();
|
||||
listBoxUserControl = new ListBox();
|
||||
dateInputControl1 = new DateInputControl();
|
||||
listBoxUserControl = new ListBoxUserControl();
|
||||
SuspendLayout();
|
||||
//
|
||||
// comboBoxUserControl
|
||||
@ -30,29 +30,31 @@ namespace WinFormsApp1
|
||||
comboBoxUserControl.Size = new Size(160, 28);
|
||||
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.DateFormat = null;
|
||||
dateInputControl1.Location = new Point(13, 107);
|
||||
dateInputControl1.Margin = new Padding(4, 5, 4, 5);
|
||||
dateInputControl1.Name = "dateInputControl1";
|
||||
dateInputControl1.Size = new Size(166, 96);
|
||||
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
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(400, 462);
|
||||
Controls.Add(dateInputControl1);
|
||||
Controls.Add(listBoxUserControl);
|
||||
Controls.Add(dateInputControl1);
|
||||
Controls.Add(comboBoxUserControl);
|
||||
Margin = new Padding(4, 5, 4, 5);
|
||||
Name = "Form1";
|
||||
@ -61,7 +63,7 @@ namespace WinFormsApp1
|
||||
}
|
||||
|
||||
private ComboBox comboBoxUserControl;
|
||||
private ListBox listBoxUserControl;
|
||||
private DateInputControl dateInputControl1;
|
||||
private ListBoxUserControl listBoxUserControl;
|
||||
}
|
||||
}
|
@ -9,6 +9,19 @@ namespace WinFormsApp1
|
||||
public Form1()
|
||||
{
|
||||
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)
|
||||
@ -16,9 +29,9 @@ namespace WinFormsApp1
|
||||
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}");
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
@ -9,7 +9,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Library14Petrushin" Version="1.0.0" />
|
||||
<PackageReference Include="Library14Petrushin" Version="1.0.1" />
|
||||
<PackageReference Include="Library15Gerimovich" Version="1.0.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.10">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
|
24
WinFormsLibrary1/WinFormsApp1/MainForm.Designer.cs
generated
24
WinFormsLibrary1/WinFormsApp1/MainForm.Designer.cs
generated
@ -29,26 +29,26 @@
|
||||
private void InitializeComponent()
|
||||
{
|
||||
components = new System.ComponentModel.Container();
|
||||
_productListControl = new Library15Gerimovich.OutputTableResults();
|
||||
_productTreeView = new Library14Petrushin.HierarchicalTreeView();
|
||||
wordTablesComponent1 = new Library15Gerimovich.WordTablesComponent(components);
|
||||
SuspendLayout();
|
||||
//
|
||||
// _productListControl
|
||||
// _productTreeView
|
||||
//
|
||||
_productListControl.Dock = DockStyle.Fill;
|
||||
_productListControl.Location = new Point(0, 0);
|
||||
_productListControl.Margin = new Padding(3, 5, 3, 5);
|
||||
_productListControl.Name = "_productListControl";
|
||||
_productListControl.SelectedRow = -1;
|
||||
_productListControl.Size = new Size(487, 335);
|
||||
_productListControl.TabIndex = 0;
|
||||
_productTreeView.Dock = DockStyle.Fill;
|
||||
_productTreeView.Location = new Point(0, 0);
|
||||
_productTreeView.Margin = new Padding(3, 5, 3, 5);
|
||||
_productTreeView.Name = "_productTreeView";
|
||||
_productTreeView.SelectedNodeIndex = -1;
|
||||
_productTreeView.Size = new Size(292, 521);
|
||||
_productTreeView.TabIndex = 0;
|
||||
//
|
||||
// MainForm
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(487, 335);
|
||||
Controls.Add(_productListControl);
|
||||
ClientSize = new Size(292, 521);
|
||||
Controls.Add(_productTreeView);
|
||||
Margin = new Padding(3, 4, 3, 4);
|
||||
Name = "MainForm";
|
||||
Text = "Учет продуктов в магазине";
|
||||
@ -58,7 +58,7 @@
|
||||
|
||||
#endregion
|
||||
|
||||
private Library15Gerimovich.OutputTableResults _productListControl;
|
||||
private Library14Petrushin.HierarchicalTreeView _productTreeView;
|
||||
private Library15Gerimovich.WordTablesComponent wordTablesComponent1;
|
||||
}
|
||||
}
|
@ -31,25 +31,14 @@ namespace Forms
|
||||
private void LoadProducts()
|
||||
{
|
||||
var products = _productLogic.ReadList(null);
|
||||
_productListControl.ClearGrid();
|
||||
|
||||
// Создаем список столбцов
|
||||
var columns = new List<ColumnInfo>
|
||||
{
|
||||
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")
|
||||
};
|
||||
var hierarchy = new List<string> { "Category", "CountOnStorageS", "Id", "Name" };
|
||||
var alwaysNewBranch = new Dictionary<string, bool> { { "Name", true } };
|
||||
_productTreeView.SetHierarchy(hierarchy, alwaysNewBranch);
|
||||
|
||||
// Настраиваем столбцы в DataGridView
|
||||
_productListControl.ConfigureColumns(columns);
|
||||
|
||||
// Добавляем строки
|
||||
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());
|
||||
|
||||
// Привязка контекстного меню к компоненту вывода списков
|
||||
_productListControl.ContextMenuStrip = contextMenu;
|
||||
_productTreeView.ContextMenuStrip = contextMenu;
|
||||
|
||||
// Настройка горячих клавиш
|
||||
this.KeyDown += MainForm_KeyDown;
|
||||
@ -77,6 +66,34 @@ namespace Forms
|
||||
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()
|
||||
{
|
||||
var form = new ProductForm(_productLogic, _categoryLogic);
|
||||
@ -128,37 +145,8 @@ namespace Forms
|
||||
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()
|
||||
{
|
||||
// Логика добавления нового продукта
|
||||
var form = new ProductForm(_productLogic, _categoryLogic);
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
@ -168,8 +156,11 @@ namespace Forms
|
||||
|
||||
private void EditProduct()
|
||||
{
|
||||
// Логика редактирования выбранного продукта
|
||||
var selectedProduct = _productListControl.GetSelectedObject<ProductViewModel>();
|
||||
var selectedProduct = _productTreeView.GetSelectedObject<ProductViewModel>();
|
||||
selectedProduct = _productLogic.ReadElement(new ProductSearchModel
|
||||
{
|
||||
Id = int.Parse(selectedProduct.Id)
|
||||
});
|
||||
if (selectedProduct != null)
|
||||
{
|
||||
var form = new ProductForm(_productLogic, _categoryLogic, selectedProduct);
|
||||
@ -182,14 +173,17 @@ namespace Forms
|
||||
|
||||
private void DeleteProduct()
|
||||
{
|
||||
// Логика удаления выбранного продукта
|
||||
var selectedProduct = _productListControl.GetSelectedObject<ProductViewModel>();
|
||||
var selectedProduct = _productTreeView.GetSelectedObject<ProductViewModel>();
|
||||
selectedProduct = _productLogic.ReadElement(new ProductSearchModel
|
||||
{
|
||||
Id = int.Parse(selectedProduct.Id)
|
||||
});
|
||||
if (selectedProduct != null)
|
||||
{
|
||||
var result = MessageBox.Show("Вы действительно хотите удалить этот продукт?", "Подтверждение", MessageBoxButtons.YesNo);
|
||||
if (result == DialogResult.Yes)
|
||||
{
|
||||
_productLogic.Delete(new ProductBindingModel { Id = selectedProduct.Id });
|
||||
_productLogic.Delete(new ProductBindingModel { Id = int.Parse(selectedProduct.Id) });
|
||||
LoadProducts();
|
||||
}
|
||||
}
|
||||
|
@ -52,11 +52,11 @@ namespace Forms
|
||||
{
|
||||
var model = new ProductBindingModel
|
||||
{
|
||||
Id = _product?.Id ?? 0,
|
||||
Id = string.IsNullOrEmpty(_product?.Id) ? 0 : int.Parse(_product?.Id),
|
||||
Name = textBoxName.Text,
|
||||
Description = textBoxDescription.Text,
|
||||
Category = _categoryComboBox.SelectedValue,
|
||||
CountOnStorage = (int)_countOnStorageControl.DoubleValue
|
||||
CountOnStorage = _countOnStorageControl.DoubleValue != null ? (int?)_countOnStorageControl.DoubleValue : null
|
||||
};
|
||||
|
||||
if (_isNewProduct)
|
||||
|
@ -28,7 +28,7 @@ namespace WinFormsApp1
|
||||
ConfigureServices(services);
|
||||
_serviceProvider = services.BuildServiceProvider();
|
||||
|
||||
Application.Run(_serviceProvider.GetRequiredService<MainForm>());
|
||||
Application.Run(_serviceProvider.GetRequiredService<Form1>());
|
||||
}
|
||||
|
||||
private static void ConfigureServices(ServiceCollection services)
|
||||
@ -47,6 +47,7 @@ namespace WinFormsApp1
|
||||
services.AddTransient<CategoryForm>();
|
||||
services.AddTransient<ProductForm>();
|
||||
services.AddTransient<MainForm>();
|
||||
services.AddTransient<Form1>();
|
||||
}
|
||||
}
|
||||
}
|
@ -15,26 +15,27 @@
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.listBox = new System.Windows.Forms.ListBox();
|
||||
this.SuspendLayout();
|
||||
listBox = new ListBox();
|
||||
SuspendLayout();
|
||||
//
|
||||
// listBox
|
||||
//
|
||||
this.listBox.FormattingEnabled = true;
|
||||
this.listBox.Location = new System.Drawing.Point(0, 0);
|
||||
this.listBox.Name = "listBox";
|
||||
this.listBox.Size = new System.Drawing.Size(120, 95);
|
||||
this.listBox.TabIndex = 0;
|
||||
//this.listBox.SelectedIndexChanged += new System.EventHandler(this.listBox_SelectedIndexChanged);
|
||||
listBox.FormattingEnabled = true;
|
||||
listBox.Location = new Point(0, 0);
|
||||
listBox.Margin = new Padding(4, 5, 4, 5);
|
||||
listBox.Name = "listBox";
|
||||
listBox.Size = new Size(594, 144);
|
||||
listBox.TabIndex = 0;
|
||||
//
|
||||
// ListBoxUserControl
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.Controls.Add(this.listBox);
|
||||
this.Name = "ListBoxUserControl";
|
||||
this.Size = new System.Drawing.Size(120, 95);
|
||||
this.ResumeLayout(false);
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
Controls.Add(listBox);
|
||||
Margin = new Padding(4, 5, 4, 5);
|
||||
Name = "ListBoxUserControl";
|
||||
Size = new Size(598, 146);
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
private System.Windows.Forms.ListBox listBox;
|
||||
|
@ -116,5 +116,30 @@ namespace WinFormsLibrary1
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
@ -6,7 +6,7 @@
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
|
||||
<Version>1.0.2</Version>
|
||||
<Version>1.0.3</Version>
|
||||
<Title>Library13StroevV</Title>
|
||||
</PropertyGroup>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user