Наполовину работает

This commit is contained in:
the 2024-06-23 17:04:26 +04:00
parent a2f733ce8e
commit 09a8d45482
12 changed files with 746 additions and 32 deletions

View File

@ -7,12 +7,12 @@ using System.Threading.Tasks;
namespace Contracts.ViewModels
{
public class ProductViewModel
public class ProductViewModel : IProduct
{
public Guid Id { get; set; }
public string Name { get; set; } = string.Empty;
public double Price { get; set; }
public double Rating { get; set; }
public double Rate { get; set; }
public bool IsBeingSold { get; set; }
public int Amount { get; set; }
public List<MediaFileViewModel> MediaFiles { get; set; } = new();

View File

@ -11,6 +11,7 @@ namespace Contracts.ViewModels
{
public Guid Id { get; set; }
public string Name { get; set; } = string.Empty;
public int Deals { get; set; }
public Dictionary<Guid, (IProduct, int)> AvailibleProducts = new();
}
}

View File

@ -37,7 +37,7 @@ namespace DatabaseImplement.Implements
}
using var context = new Database();
return context.Suppliers
.Include(x => x.Name)
//.Include(x => x.Name)
.Include(x => x.Products)
.ThenInclude(x => x.Product)
.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;

View File

@ -41,7 +41,7 @@ namespace DatabaseImplement.Models
Id = model.Id,
Name = model.Name,
Price = model.Price,
Rate = model.Rating,
Rate = model.Rate,
IsBeingSold = model.IsBeingSold,
Amount = model.Amount
};
@ -95,7 +95,7 @@ namespace DatabaseImplement.Models
Name = Name,
Price = Price,
IsBeingSold = IsBeingSold,
Rating = Rate,
Rate = Rate,
Amount = Amount
};
}

View File

@ -71,7 +71,8 @@ namespace DatabaseImplement.Models
{
Id = Id,
Name = Name,
AvailibleProducts = AvailibleProducts
AvailibleProducts = AvailibleProducts,
Deals = Deals,
};
}
}

View File

@ -32,6 +32,7 @@
buttonCreateSupply = new Button();
menuStrip1 = new MenuStrip();
товарыToolStripMenuItem = new ToolStripMenuItem();
поставщикиToolStripMenuItem = new ToolStripMenuItem();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
menuStrip1.SuspendLayout();
SuspendLayout();
@ -39,14 +40,15 @@
// dataGridView
//
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView.Location = new Point(12, 28);
dataGridView.Dock = DockStyle.Left;
dataGridView.Location = new Point(0, 24);
dataGridView.Name = "dataGridView";
dataGridView.Size = new Size(614, 321);
dataGridView.Size = new Size(663, 360);
dataGridView.TabIndex = 0;
//
// buttonCreateSupply
//
buttonCreateSupply.Location = new Point(632, 28);
buttonCreateSupply.Location = new Point(706, 12);
buttonCreateSupply.Name = "buttonCreateSupply";
buttonCreateSupply.Size = new Size(154, 23);
buttonCreateSupply.TabIndex = 1;
@ -55,10 +57,10 @@
//
// menuStrip1
//
menuStrip1.Items.AddRange(new ToolStripItem[] { товарыToolStripMenuItem });
menuStrip1.Items.AddRange(new ToolStripItem[] { товарыToolStripMenuItem, поставщикиToolStripMenuItem });
menuStrip1.Location = new Point(0, 0);
menuStrip1.Name = "menuStrip1";
menuStrip1.Size = new Size(798, 24);
menuStrip1.Size = new Size(901, 24);
menuStrip1.TabIndex = 2;
menuStrip1.Text = "menuStrip1";
//
@ -67,13 +69,20 @@
товарыToolStripMenuItem.Name = оварыToolStripMenuItem";
товарыToolStripMenuItem.Size = new Size(60, 20);
товарыToolStripMenuItem.Text = "Товары";
товарыToolStripMenuItem.Click += товарыToolStripMenuItem_Click;
товарыToolStripMenuItem.Click += товарыToolStripMenuItem_Click_1;
//
// поставщикиToolStripMenuItem
//
поставщикиToolStripMenuItem.Name = "поставщикиToolStripMenuItem";
поставщикиToolStripMenuItem.Size = new Size(89, 20);
поставщикиToolStripMenuItem.Text = "Поставщики";
поставщикиToolStripMenuItem.Click += поставщикиToolStripMenuItem_Click_1;
//
// FormMain
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(798, 361);
ClientSize = new Size(901, 384);
Controls.Add(buttonCreateSupply);
Controls.Add(dataGridView);
Controls.Add(menuStrip1);
@ -94,5 +103,6 @@
private Button buttonCreateSupply;
private MenuStrip menuStrip1;
private ToolStripMenuItem товарыToolStripMenuItem;
private ToolStripMenuItem поставщикиToolStripMenuItem;
}
}

View File

@ -51,8 +51,7 @@ namespace WinFormsApp
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void товарыToolStripMenuItem_Click(object sender, EventArgs e)
private void товарыToolStripMenuItem_Click_1(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormProducts));
if (service is FormProducts form)
@ -60,5 +59,14 @@ namespace WinFormsApp
form.ShowDialog();
}
}
private void поставщикиToolStripMenuItem_Click_1(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormSuppliers));
if (service is FormSuppliers form)
{
form.ShowDialog();
}
}
}
}

View File

@ -31,6 +31,7 @@
dataGridView = new DataGridView();
buttonCreateProduct = new Button();
groupBoxControls = new GroupBox();
buttonDeleteProduct = new Button();
buttonUpdateProduct = new Button();
groupBoxCreateProduct = new GroupBox();
numericUpDownAmount = new NumericUpDown();
@ -39,7 +40,6 @@
buttonSaveProduct = new Button();
checkBoxIsSold = new CheckBox();
textBoxName = new TextBox();
buttonDeleteProduct = new Button();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
groupBoxControls.SuspendLayout();
groupBoxCreateProduct.SuspendLayout();
@ -50,9 +50,10 @@
// dataGridView
//
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView.Location = new Point(12, 12);
dataGridView.Dock = DockStyle.Left;
dataGridView.Location = new Point(0, 0);
dataGridView.Name = "dataGridView";
dataGridView.Size = new Size(631, 304);
dataGridView.Size = new Size(602, 646);
dataGridView.TabIndex = 0;
//
// buttonCreateProduct
@ -71,13 +72,24 @@
groupBoxControls.Controls.Add(buttonDeleteProduct);
groupBoxControls.Controls.Add(buttonUpdateProduct);
groupBoxControls.Controls.Add(buttonCreateProduct);
groupBoxControls.Location = new Point(649, 12);
groupBoxControls.Dock = DockStyle.Right;
groupBoxControls.Location = new Point(617, 0);
groupBoxControls.Name = "groupBoxControls";
groupBoxControls.Size = new Size(264, 304);
groupBoxControls.Size = new Size(308, 646);
groupBoxControls.TabIndex = 2;
groupBoxControls.TabStop = false;
groupBoxControls.Text = "Действия";
//
// buttonDeleteProduct
//
buttonDeleteProduct.Location = new Point(69, 102);
buttonDeleteProduct.Name = "buttonDeleteProduct";
buttonDeleteProduct.Size = new Size(139, 23);
buttonDeleteProduct.TabIndex = 3;
buttonDeleteProduct.Text = "Удалить товар";
buttonDeleteProduct.UseVisualStyleBackColor = true;
buttonDeleteProduct.Click += buttonDeleteProduct_Click;
//
// buttonUpdateProduct
//
buttonUpdateProduct.Location = new Point(69, 62);
@ -97,9 +109,10 @@
groupBoxCreateProduct.Controls.Add(buttonSaveProduct);
groupBoxCreateProduct.Controls.Add(checkBoxIsSold);
groupBoxCreateProduct.Controls.Add(textBoxName);
groupBoxCreateProduct.Location = new Point(649, 330);
groupBoxCreateProduct.Dock = DockStyle.Right;
groupBoxCreateProduct.Location = new Point(383, 0);
groupBoxCreateProduct.Name = "groupBoxCreateProduct";
groupBoxCreateProduct.Size = new Size(257, 304);
groupBoxCreateProduct.Size = new Size(234, 646);
groupBoxCreateProduct.TabIndex = 3;
groupBoxCreateProduct.TabStop = false;
groupBoxCreateProduct.Text = "Создание/изменение продукта";
@ -158,16 +171,6 @@
textBoxName.Size = new Size(100, 23);
textBoxName.TabIndex = 0;
//
// buttonDeleteProduct
//
buttonDeleteProduct.Location = new Point(69, 102);
buttonDeleteProduct.Name = "buttonDeleteProduct";
buttonDeleteProduct.Size = new Size(139, 23);
buttonDeleteProduct.TabIndex = 3;
buttonDeleteProduct.Text = "Удалить товар";
buttonDeleteProduct.UseVisualStyleBackColor = true;
buttonDeleteProduct.Click += buttonDeleteProduct_Click;
//
// FormProducts
//
AutoScaleDimensions = new SizeF(7F, 15F);

313
WinFormsApp/FormSuppliers.Designer.cs generated Normal file
View File

@ -0,0 +1,313 @@
namespace WinFormsApp
{
partial class FormSuppliers
{
/// <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()
{
groupBoxCreateSupplier = new GroupBox();
groupBoxSupplierProducts = new GroupBox();
label2 = new Label();
buttonCancel = new Button();
label1 = new Label();
buttonSaveSupplier = new Button();
numericUpDownCount = new NumericUpDown();
comboBoxProducts = new ComboBox();
dataGridViewProducts = new DataGridView();
Column = new DataGridViewTextBoxColumn();
Column2 = new DataGridViewTextBoxColumn();
buttonAddSupplierProduct = new Button();
textBoxName = new TextBox();
groupBoxControls = new GroupBox();
buttonDeleteSupplier = new Button();
buttonUpdateSupplier = new Button();
buttonCreateSupplier = new Button();
dataGridView = new DataGridView();
numericUpDownDeals = new NumericUpDown();
label3 = new Label();
label4 = new Label();
groupBoxCreateSupplier.SuspendLayout();
groupBoxSupplierProducts.SuspendLayout();
((System.ComponentModel.ISupportInitialize)numericUpDownCount).BeginInit();
((System.ComponentModel.ISupportInitialize)dataGridViewProducts).BeginInit();
groupBoxControls.SuspendLayout();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
((System.ComponentModel.ISupportInitialize)numericUpDownDeals).BeginInit();
SuspendLayout();
//
// groupBoxCreateSupplier
//
groupBoxCreateSupplier.BackColor = Color.Transparent;
groupBoxCreateSupplier.Controls.Add(label4);
groupBoxCreateSupplier.Controls.Add(label3);
groupBoxCreateSupplier.Controls.Add(numericUpDownDeals);
groupBoxCreateSupplier.Controls.Add(groupBoxSupplierProducts);
groupBoxCreateSupplier.Controls.Add(textBoxName);
groupBoxCreateSupplier.Dock = DockStyle.Right;
groupBoxCreateSupplier.Location = new Point(288, 0);
groupBoxCreateSupplier.Name = "groupBoxCreateSupplier";
groupBoxCreateSupplier.Size = new Size(367, 637);
groupBoxCreateSupplier.TabIndex = 6;
groupBoxCreateSupplier.TabStop = false;
groupBoxCreateSupplier.Text = "Создание/изменение поставщика";
//
// groupBoxSupplierProducts
//
groupBoxSupplierProducts.Controls.Add(label2);
groupBoxSupplierProducts.Controls.Add(buttonCancel);
groupBoxSupplierProducts.Controls.Add(label1);
groupBoxSupplierProducts.Controls.Add(buttonSaveSupplier);
groupBoxSupplierProducts.Controls.Add(numericUpDownCount);
groupBoxSupplierProducts.Controls.Add(comboBoxProducts);
groupBoxSupplierProducts.Controls.Add(dataGridViewProducts);
groupBoxSupplierProducts.Controls.Add(buttonAddSupplierProduct);
groupBoxSupplierProducts.Location = new Point(0, 149);
groupBoxSupplierProducts.Name = "groupBoxSupplierProducts";
groupBoxSupplierProducts.Size = new Size(361, 482);
groupBoxSupplierProducts.TabIndex = 10;
groupBoxSupplierProducts.TabStop = false;
groupBoxSupplierProducts.Text = "Доступные товары поставщика";
//
// label2
//
label2.AutoSize = true;
label2.Location = new Point(6, 251);
label2.Name = "label2";
label2.Size = new Size(46, 15);
label2.TabIndex = 13;
label2.Text = "Кол-во";
//
// buttonCancel
//
buttonCancel.Location = new Point(262, 453);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(75, 23);
buttonCancel.TabIndex = 5;
buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true;
//
// label1
//
label1.AutoSize = true;
label1.Location = new Point(13, 223);
label1.Name = "label1";
label1.Size = new Size(39, 15);
label1.TabIndex = 12;
label1.Text = "Товар";
//
// buttonSaveSupplier
//
buttonSaveSupplier.Location = new Point(29, 453);
buttonSaveSupplier.Name = "buttonSaveSupplier";
buttonSaveSupplier.Size = new Size(75, 23);
buttonSaveSupplier.TabIndex = 4;
buttonSaveSupplier.Text = "Сохранить";
buttonSaveSupplier.UseVisualStyleBackColor = true;
buttonSaveSupplier.Click += buttonSaveProduct_Click;
//
// numericUpDownCount
//
numericUpDownCount.Location = new Point(58, 249);
numericUpDownCount.Maximum = new decimal(new int[] { 100000, 0, 0, 0 });
numericUpDownCount.Name = "numericUpDownCount";
numericUpDownCount.Size = new Size(297, 23);
numericUpDownCount.TabIndex = 11;
//
// comboBoxProducts
//
comboBoxProducts.FormattingEnabled = true;
comboBoxProducts.Location = new Point(58, 220);
comboBoxProducts.Name = "comboBoxProducts";
comboBoxProducts.Size = new Size(297, 23);
comboBoxProducts.TabIndex = 10;
//
// dataGridViewProducts
//
dataGridViewProducts.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridViewProducts.Columns.AddRange(new DataGridViewColumn[] { Column, Column2 });
dataGridViewProducts.Dock = DockStyle.Top;
dataGridViewProducts.Location = new Point(3, 19);
dataGridViewProducts.Name = "dataGridViewProducts";
dataGridViewProducts.Size = new Size(355, 195);
dataGridViewProducts.TabIndex = 8;
//
// Column
//
Column.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
Column.HeaderText = "Продукт";
Column.Name = "Column";
Column.ReadOnly = true;
//
// Column2
//
Column2.HeaderText = "Кол-во";
Column2.Name = "Column2";
Column2.ReadOnly = true;
//
// buttonAddSupplierProduct
//
buttonAddSupplierProduct.Location = new Point(58, 278);
buttonAddSupplierProduct.Name = "buttonAddSupplierProduct";
buttonAddSupplierProduct.Size = new Size(81, 23);
buttonAddSupplierProduct.TabIndex = 9;
buttonAddSupplierProduct.Text = "Добавить";
buttonAddSupplierProduct.UseVisualStyleBackColor = true;
buttonAddSupplierProduct.Click += buttonAddSupplierProduct_Click;
//
// textBoxName
//
textBoxName.Location = new Point(110, 51);
textBoxName.Name = "textBoxName";
textBoxName.Size = new Size(245, 23);
textBoxName.TabIndex = 0;
//
// groupBoxControls
//
groupBoxControls.BackColor = Color.Transparent;
groupBoxControls.Controls.Add(buttonDeleteSupplier);
groupBoxControls.Controls.Add(buttonUpdateSupplier);
groupBoxControls.Controls.Add(buttonCreateSupplier);
groupBoxControls.Dock = DockStyle.Right;
groupBoxControls.Location = new Point(655, 0);
groupBoxControls.Name = "groupBoxControls";
groupBoxControls.Size = new Size(264, 637);
groupBoxControls.TabIndex = 5;
groupBoxControls.TabStop = false;
groupBoxControls.Text = "Действия";
//
// buttonDeleteSupplier
//
buttonDeleteSupplier.Location = new Point(69, 120);
buttonDeleteSupplier.Name = "buttonDeleteSupplier";
buttonDeleteSupplier.Size = new Size(139, 23);
buttonDeleteSupplier.TabIndex = 3;
buttonDeleteSupplier.Text = "Удалить поставщика";
buttonDeleteSupplier.UseVisualStyleBackColor = true;
buttonDeleteSupplier.Click += buttonDeleteSupplier_Click;
//
// buttonUpdateSupplier
//
buttonUpdateSupplier.Location = new Point(46, 51);
buttonUpdateSupplier.Name = "buttonUpdateSupplier";
buttonUpdateSupplier.Size = new Size(179, 63);
buttonUpdateSupplier.TabIndex = 2;
buttonUpdateSupplier.Text = "Редактировать информацию о поставщике";
buttonUpdateSupplier.UseVisualStyleBackColor = true;
buttonUpdateSupplier.Click += buttonUpdateSupplier_Click;
//
// buttonCreateSupplier
//
buttonCreateSupplier.Location = new Point(69, 22);
buttonCreateSupplier.Name = "buttonCreateSupplier";
buttonCreateSupplier.Size = new Size(139, 23);
buttonCreateSupplier.TabIndex = 1;
buttonCreateSupplier.Text = "Добавить поставщика";
buttonCreateSupplier.UseVisualStyleBackColor = true;
buttonCreateSupplier.Click += buttonCreateSupplier_Click;
//
// dataGridView
//
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView.Dock = DockStyle.Left;
dataGridView.Location = new Point(0, 0);
dataGridView.Name = "dataGridView";
dataGridView.Size = new Size(392, 637);
dataGridView.TabIndex = 4;
//
// numericUpDownDeals
//
numericUpDownDeals.Location = new Point(110, 91);
numericUpDownDeals.Maximum = new decimal(new int[] { 100000, 0, 0, 0 });
numericUpDownDeals.Name = "numericUpDownDeals";
numericUpDownDeals.Size = new Size(245, 23);
numericUpDownDeals.TabIndex = 14;
//
// label3
//
label3.AutoSize = true;
label3.Location = new Point(6, 54);
label3.Name = "label3";
label3.Size = new Size(101, 15);
label3.TabIndex = 14;
label3.Text = "Имя поставщика";
//
// label4
//
label4.AutoSize = true;
label4.Location = new Point(17, 93);
label4.Name = "label4";
label4.Size = new Size(87, 15);
label4.TabIndex = 15;
label4.Text = "Кол-во сделок";
//
// FormSuppliers
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(919, 637);
Controls.Add(groupBoxCreateSupplier);
Controls.Add(groupBoxControls);
Controls.Add(dataGridView);
Name = "FormSuppliers";
Text = "FormSuppliers";
Load += FormSuppliers_Load;
groupBoxCreateSupplier.ResumeLayout(false);
groupBoxCreateSupplier.PerformLayout();
groupBoxSupplierProducts.ResumeLayout(false);
groupBoxSupplierProducts.PerformLayout();
((System.ComponentModel.ISupportInitialize)numericUpDownCount).EndInit();
((System.ComponentModel.ISupportInitialize)dataGridViewProducts).EndInit();
groupBoxControls.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
((System.ComponentModel.ISupportInitialize)numericUpDownDeals).EndInit();
ResumeLayout(false);
}
#endregion
private GroupBox groupBoxCreateSupplier;
private Button buttonCancel;
private Button buttonSaveSupplier;
private TextBox textBoxName;
private GroupBox groupBoxControls;
private Button buttonDeleteSupplier;
private Button buttonUpdateSupplier;
private Button buttonCreateSupplier;
private DataGridView dataGridView;
private DataGridView dataGridViewProducts;
private GroupBox groupBoxSupplierProducts;
private Button buttonAddSupplierProduct;
private ComboBox comboBoxProducts;
private Label label2;
private Label label1;
private NumericUpDown numericUpDownCount;
private DataGridViewTextBoxColumn Column;
private DataGridViewTextBoxColumn Column2;
private Label label4;
private Label label3;
private NumericUpDown numericUpDownDeals;
}
}

View File

@ -0,0 +1,251 @@
using Contracts.BindingModels;
using Contracts.BusinessLogicContracts;
using Contracts.SearchModels;
using Contracts.ViewModels;
using DataModels.Models;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using Microsoft.Extensions.Logging;
using Microsoft.VisualBasic.Logging;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WinFormsApp
{
public partial class FormSuppliers : Form
{
private Guid? _id;
private readonly ILogger _logger;
private readonly ISupplierLogic _supplierLogic;
private readonly IProductLogic _productLogic;
private Dictionary<Guid, (IProduct, int)> _supplierProducts;
private List<ProductViewModel> _productList;
public FormSuppliers(ILogger<FormMain> logger, ISupplierLogic supplierLogic, IProductLogic productLogic)
{
InitializeComponent();
_supplierLogic = supplierLogic;
_logger = logger;
_productLogic = productLogic;
_supplierProducts = new Dictionary<Guid, (IProduct, int)>();
_productList = _productLogic.ReadList(null);
if (_productList != null)
{
comboBoxProducts.DisplayMember = "Name";
comboBoxProducts.ValueMember = "Id";
comboBoxProducts.DataSource = _productList;
comboBoxProducts.SelectedItem = null;
}
}
private void FormSuppliers_Load(object sender, EventArgs e)
{
LoadData();
groupBoxCreateSupplier.Hide();
//groupBoxCreateProduct.Enabled = false;
}
private void LoadSupplierData()
{
if (_id.HasValue)
{
var view = _supplierLogic.ReadElement(new SupplierSearchModel
{
Id = _id.Value
});
_supplierProducts = view.AvailibleProducts;
textBoxName.Text = view.Name;
numericUpDownDeals.Value = view.Deals;
}
dataGridViewProducts.Rows.Clear();
foreach (var pc in _supplierProducts)
{
dataGridViewProducts.Rows.Add(new object[] { pc.Value.Item1.Name, pc.Value.Item2 });
}
}
private void LoadData()
{
_logger.LogInformation("Загрузка поставщиков");
try
{
var list = _supplierLogic.ReadList(null);
if (list != null)
{
dataGridView.DataSource = list;
}
_logger.LogInformation("Загрузка поставщиков");
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки поставщиков");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void buttonCreateSupplier_Click(object sender, EventArgs e)
{
//надо сделать че нибудь с фронтом а то всё грустно
groupBoxControls.Hide();
//groupBoxControls.Enabled = false;
groupBoxCreateSupplier.Show();
//groupBoxCreateProduct.Enabled = true;
}
private void buttonUpdateSupplier_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count <= 0) return;
_id = (Guid)dataGridView.SelectedRows[0].Cells["Id"].Value;
groupBoxControls.Hide();
groupBoxCreateSupplier.Show();
_logger.LogInformation("Получение поставщика");
var view = _supplierLogic.ReadElement(new SupplierSearchModel
{
Id = _id.Value
});
LoadSupplierData();
}
private void buttonCancel_Click(object sender, EventArgs e)
{
_id = null;
_supplierProducts.Clear();
groupBoxControls.Show();
//groupBoxControls.Enabled = false;
groupBoxCreateSupplier.Hide();
//groupBoxCreateProduct.Enabled = true;
textBoxName.Text = string.Empty;
}
private void buttonDeleteSupplier_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
if (MessageBox.Show("Удалить запись?", "Вопрос",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
Guid id = (Guid)dataGridView.SelectedRows[0].Cells["Id"].Value;
_logger.LogInformation("Удаление товара");
try
{
if (!_productLogic.Delete(new ProductBindingModel
{
Id = id
}))
{
throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
}
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка удаления товара");
MessageBox.Show(ex.Message, "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
public IProduct? ProductModel
{
get
{
if (_productList == null)
{
return null;
}
foreach (var elem in _productList)
{
if (elem.Id == Id)
{
return elem;
}
}
return null;
}
}
public Guid Id
{
get
{
return (Guid)comboBoxProducts.SelectedValue;
}
set
{
comboBoxProducts.SelectedValue = value;
}
}
private void buttonAddSupplierProduct_Click(object sender, EventArgs e)
{
Debug.WriteLine(comboBoxProducts.SelectedValue);
if (_supplierProducts.ContainsKey(Id))
{
_supplierProducts[Id] = (ProductModel, Convert.ToInt16(numericUpDownCount.Value));
}
else
{
_supplierProducts.Add(Id, (ProductModel, Convert.ToInt16(numericUpDownCount.Value)));
}
LoadSupplierData();
}
private void buttonSaveProduct_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBoxName.Text))
{
MessageBox.Show("Заполните имя поставщика", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Сохранение поставщика");
try
{
var model = new SupplierBindingModel
{
Id = _id ?? Guid.Empty,
Name = textBoxName.Text,
Deals = Convert.ToInt32(numericUpDownDeals.Value),
AvailibleProducts = _supplierProducts
};
var operationResult = _id.HasValue ? _supplierLogic.Update(model) : _supplierLogic.Create(model);
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
}
MessageBox.Show("Сохранение прошло успешно", "Сообщение",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка сохранения поставщика");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
finally
{
LoadData();
_id = null;
_supplierProducts.Clear();
textBoxName.Text = string.Empty;
numericUpDownDeals.Value = 0;
groupBoxControls.Enabled = true;
groupBoxControls.Show();
groupBoxCreateSupplier.Enabled = false;
groupBoxCreateSupplier.Hide();
textBoxName.Text = string.Empty;
}
}
}
}

View File

@ -0,0 +1,126 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="Column.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="Column2.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
</root>

View File

@ -46,6 +46,7 @@ namespace WinFormsApp
services.AddTransient<FormMain>();
services.AddTransient<FormProducts>();
services.AddTransient<FormSuppliers>();
}
}
}