Agliullov D. A. Lab Work 1 Hard #3

Closed
d.agliullov wants to merge 22 commits from Lab1_Hard into Lab1_Base
4 changed files with 92 additions and 14 deletions
Showing only changes of commit 78a3293bb5 - Show all commits

View File

@ -1,4 +1,5 @@
using ConfectioneryContracts.BusinessLogicsContracts;
using ConfectioneryContracts.BindingModels;
using ConfectioneryContracts.BusinessLogicsContracts;
using ConfectioneryContracts.ViewModels;
using Microsoft.Extensions.Logging;
using System;
@ -17,33 +18,84 @@ namespace ConfectioneryView
public partial class FormAddPastryInShop : Form
{
private readonly ILogger _logger;
private readonly IShopLogic _shopLogic;
private readonly IPastryLogic _pastryLogic;
private readonly List<ShopViewModel>? _listShops;
private readonly List<PastryViewModel>? _listPastries;
public FormAddPastryInShop(ILogger<FormAddPastryInShop> logger, IShopLogic shopLogic, IPastryLogic pastryLogic)
{
InitializeComponent();
_shopLogic = shopLogic;
_pastryLogic = pastryLogic;
_logger = logger;
_listShops = shopLogic.ReadList(null);
if (_listShops != null)
{
comboBoxShop.DisplayMember = "ComponentName";
comboBoxShop.DisplayMember = "Name";
comboBoxShop.ValueMember = "Id";
comboBoxShop.DataSource = _listShops;
comboBoxShop.SelectedItem = null;
}
_listPastries
_listPastries = pastryLogic.ReadList(null);
if (_listPastries != null)
{
comboBoxPastry.DisplayMember = "PastryName";
comboBoxPastry.ValueMember= "Id";
comboBoxPastry.DataSource = _listPastries;
comboBoxPastry.SelectedItem = null;
}
}
private void ButtonSave_Click(object sender, EventArgs e)
{
if (comboBoxShop.SelectedValue == null)
{
MessageBox.Show("Выберите магазин", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (comboBoxPastry.SelectedValue == null)
{
MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Добавление изделия в магазин");
try
{
var pastry = _pastryLogic.ReadElement(new()
{
Id = (int)comboBoxPastry.SelectedValue
});
if (pastry == null)
{
throw new Exception("Не найдено изделие. Дополнительная информация в логах.");
}
var resultOperation = _shopLogic.AddPastry(
model: new() { Id = (int)comboBoxShop.SelectedValue },
pastry: pastry,
count: (int)numericUpDownCount.Value
);
if (!resultOperation)
{
throw new Exception("Ошибка при добавлении. Дополнительная информация в логах.");
}
MessageBox.Show("Сохранение прошло успешно", "Сообщение",
MessageBoxButtons.OK, MessageBoxIcon.Information);
DialogResult = DialogResult.OK;
Close();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка сохранения изделия");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
}
}

View File

@ -32,13 +32,14 @@
this.справочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.pastryToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.componentToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.ShopsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.dataGridView = new System.Windows.Forms.DataGridView();
this.buttonCreateOrder = new System.Windows.Forms.Button();
this.buttonTakeOrderInWork = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.button4 = new System.Windows.Forms.Button();
this.ShopsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.buttonAddPastryInShop = new System.Windows.Forms.Button();
this.menuStrip1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.SuspendLayout();
@ -77,6 +78,13 @@
this.componentToolStripMenuItem.Text = "Компоненты";
this.componentToolStripMenuItem.Click += new System.EventHandler(this.ComponentsToolStripMenuItem_Click);
//
// ShopsToolStripMenuItem
//
this.ShopsToolStripMenuItem.Name = "ShopsToolStripMenuItem";
this.ShopsToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.ShopsToolStripMenuItem.Text = "Магазины";
this.ShopsToolStripMenuItem.Click += new System.EventHandler(this.ShopsToolStripMenuItem_Click);
//
// dataGridView
//
this.dataGridView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
@ -144,18 +152,22 @@
this.button4.UseVisualStyleBackColor = true;
this.button4.Click += new System.EventHandler(this.ButtonRef_Click);
//
// ShopsToolStripMenuItem
// buttonAddPastryInShop
//
this.ShopsToolStripMenuItem.Name = "ShopsToolStripMenuItem";
this.ShopsToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.ShopsToolStripMenuItem.Text = "Магазины";
this.ShopsToolStripMenuItem.Click += new System.EventHandler(this.ShopsToolStripMenuItem_Click);
this.buttonAddPastryInShop.Location = new System.Drawing.Point(624, 326);
this.buttonAddPastryInShop.Name = "buttonAddPastryInShop";
this.buttonAddPastryInShop.Size = new System.Drawing.Size(147, 31);
this.buttonAddPastryInShop.TabIndex = 7;
this.buttonAddPastryInShop.Text = "Пополнение магазина";
this.buttonAddPastryInShop.UseVisualStyleBackColor = true;
this.buttonAddPastryInShop.Click += new System.EventHandler(this.ButtonAddPastryInShop_Click);
//
// FormMain
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(783, 380);
this.Controls.Add(this.buttonAddPastryInShop);
this.Controls.Add(this.button4);
this.Controls.Add(this.button3);
this.Controls.Add(this.button2);
@ -187,5 +199,6 @@
private ToolStripMenuItem pastryToolStripMenuItem;
private ToolStripMenuItem componentToolStripMenuItem;
private ToolStripMenuItem ShopsToolStripMenuItem;
private Button buttonAddPastryInShop;
}
}

View File

@ -30,8 +30,8 @@ namespace ConfectioneryView
{
dataGridView.DataSource = list;
dataGridView.Columns["Id"].Visible = false;
/*dataGridView.Columns["PastryName"].AutoSizeMode =
DataGridViewAutoSizeColumnMode.Fill;*/
dataGridView.Columns["PastryName"].AutoSizeMode =
DataGridViewAutoSizeColumnMode.Fill;
}
_logger.LogInformation("Çàãðóçêà çàêàçîâ");
}
@ -158,7 +158,15 @@ namespace ConfectioneryView
if (service is FormViewShops form)
{
form.ShowDialog();
LoadData();
}
}
private void ButtonAddPastryInShop_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormAddPastryInShop));
if (service is FormAddPastryInShop form)
{
form.ShowDialog();
}
}
}

View File

@ -1,4 +1,5 @@
using AbstractShopListImplement.Implements;
using ConfectioneryBusinessLogic;
using ConfectioneryBusinessLogic.BusinessLogics;
using ConfectioneryContracts.BusinessLogicsContracts;
using ConfectioneryContracts.StoragesContract;
@ -38,9 +39,11 @@ namespace ConfectioneryView
services.AddTransient<IComponentStorage, ComponentStorage>();
services.AddTransient<IOrderStorage, OrderStorage>();
services.AddTransient<IPastryStorage, PastryStorage>();
services.AddTransient<IShopStorage, ShopStorage>();
services.AddTransient<IComponentLogic, ComponentLogic>();
services.AddTransient<IOrderLogic, OrderLogic>();
services.AddTransient<IPastryLogic, PastryLogic>();
services.AddTransient<IShopLogic, ShopLogic>();
services.AddTransient<FormMain>();
services.AddTransient<FormComponent>();
services.AddTransient<FormComponents>();
@ -48,6 +51,8 @@ namespace ConfectioneryView
services.AddTransient<FormPastry>();
services.AddTransient<FormPastryComponent>();
services.AddTransient<FormViewPastry>();
services.AddTransient<FormAddPastryInShop>();
services.AddTransient<FormViewShops>();
}
}
}