From 09a8d4548205ff3fb5e5019c77a91e10935ce580 Mon Sep 17 00:00:00 2001 From: the Date: Sun, 23 Jun 2024 17:04:26 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9D=D0=B0=D0=BF=D0=BE=D0=BB=D0=BE=D0=B2?= =?UTF-8?q?=D0=B8=D0=BD=D1=83=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=D0=B5?= =?UTF-8?q?=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Contracts/ViewModels/ProductViewModel.cs | 4 +- Contracts/ViewModels/SupplierViewModel.cs | 1 + .../Implements/SupplierStorage.cs | 2 +- DatabaseImplement/Models/Product.cs | 4 +- DatabaseImplement/Models/Supplier.cs | 3 +- WinFormsApp/FormMain.Designer.cs | 24 +- WinFormsApp/FormMain.cs | 12 +- WinFormsApp/FormProducts.Designer.cs | 37 ++- WinFormsApp/FormSuppliers.Designer.cs | 313 ++++++++++++++++++ WinFormsApp/FormSuppliers.cs | 251 ++++++++++++++ WinFormsApp/FormSuppliers.resx | 126 +++++++ WinFormsApp/Program.cs | 1 + 12 files changed, 746 insertions(+), 32 deletions(-) create mode 100644 WinFormsApp/FormSuppliers.Designer.cs create mode 100644 WinFormsApp/FormSuppliers.cs create mode 100644 WinFormsApp/FormSuppliers.resx diff --git a/Contracts/ViewModels/ProductViewModel.cs b/Contracts/ViewModels/ProductViewModel.cs index efb0338..14b7df3 100644 --- a/Contracts/ViewModels/ProductViewModel.cs +++ b/Contracts/ViewModels/ProductViewModel.cs @@ -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 MediaFiles { get; set; } = new(); diff --git a/Contracts/ViewModels/SupplierViewModel.cs b/Contracts/ViewModels/SupplierViewModel.cs index 09b2af2..d844c1c 100644 --- a/Contracts/ViewModels/SupplierViewModel.cs +++ b/Contracts/ViewModels/SupplierViewModel.cs @@ -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 AvailibleProducts = new(); } } diff --git a/DatabaseImplement/Implements/SupplierStorage.cs b/DatabaseImplement/Implements/SupplierStorage.cs index c44c0bf..3c9a469 100644 --- a/DatabaseImplement/Implements/SupplierStorage.cs +++ b/DatabaseImplement/Implements/SupplierStorage.cs @@ -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; diff --git a/DatabaseImplement/Models/Product.cs b/DatabaseImplement/Models/Product.cs index 7edb9f4..ca674c5 100644 --- a/DatabaseImplement/Models/Product.cs +++ b/DatabaseImplement/Models/Product.cs @@ -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 }; } diff --git a/DatabaseImplement/Models/Supplier.cs b/DatabaseImplement/Models/Supplier.cs index 2901ee2..86b2da0 100644 --- a/DatabaseImplement/Models/Supplier.cs +++ b/DatabaseImplement/Models/Supplier.cs @@ -71,7 +71,8 @@ namespace DatabaseImplement.Models { Id = Id, Name = Name, - AvailibleProducts = AvailibleProducts + AvailibleProducts = AvailibleProducts, + Deals = Deals, }; } } diff --git a/WinFormsApp/FormMain.Designer.cs b/WinFormsApp/FormMain.Designer.cs index c657f92..e5feb1c 100644 --- a/WinFormsApp/FormMain.Designer.cs +++ b/WinFormsApp/FormMain.Designer.cs @@ -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; } } \ No newline at end of file diff --git a/WinFormsApp/FormMain.cs b/WinFormsApp/FormMain.cs index bce168b..a7fd7da 100644 --- a/WinFormsApp/FormMain.cs +++ b/WinFormsApp/FormMain.cs @@ -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(); + } + } } } diff --git a/WinFormsApp/FormProducts.Designer.cs b/WinFormsApp/FormProducts.Designer.cs index 77b8931..88c12c7 100644 --- a/WinFormsApp/FormProducts.Designer.cs +++ b/WinFormsApp/FormProducts.Designer.cs @@ -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); diff --git a/WinFormsApp/FormSuppliers.Designer.cs b/WinFormsApp/FormSuppliers.Designer.cs new file mode 100644 index 0000000..97b4c89 --- /dev/null +++ b/WinFormsApp/FormSuppliers.Designer.cs @@ -0,0 +1,313 @@ +namespace WinFormsApp +{ + partial class FormSuppliers + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + 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; + } +} \ No newline at end of file diff --git a/WinFormsApp/FormSuppliers.cs b/WinFormsApp/FormSuppliers.cs new file mode 100644 index 0000000..14ebd30 --- /dev/null +++ b/WinFormsApp/FormSuppliers.cs @@ -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 _supplierProducts; + private List _productList; + public FormSuppliers(ILogger logger, ISupplierLogic supplierLogic, IProductLogic productLogic) + { + InitializeComponent(); + _supplierLogic = supplierLogic; + _logger = logger; + _productLogic = productLogic; + _supplierProducts = new Dictionary(); + _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; + } + } + } +} diff --git a/WinFormsApp/FormSuppliers.resx b/WinFormsApp/FormSuppliers.resx new file mode 100644 index 0000000..ab04799 --- /dev/null +++ b/WinFormsApp/FormSuppliers.resx @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + True + + + True + + \ No newline at end of file diff --git a/WinFormsApp/Program.cs b/WinFormsApp/Program.cs index 0f7a7c9..3297ebc 100644 --- a/WinFormsApp/Program.cs +++ b/WinFormsApp/Program.cs @@ -46,6 +46,7 @@ namespace WinFormsApp services.AddTransient(); services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file