почти готовая лаба 1

This commit is contained in:
Полина Чубыкина 2024-03-26 19:45:16 +04:00
parent 36ed1f21b0
commit aff701fb60
8 changed files with 386 additions and 9 deletions

View File

@ -17,6 +17,6 @@ namespace ConfectioneryContracts.BusinessLogicsContracts
bool Delete(ShopBindingModel model);
bool MakeShipment(ShopSearchModel shopModel, IPastryModel pastry, int count);
bool Supply(ShopSearchModel shopModel, IPastryModel pastry, int count);
}
}

View File

@ -84,7 +84,7 @@ namespace ConfectioneryBusinessLogic.BusinessLogics
return true;
}
public bool MakeShipment(ShopSearchModel shopModel, IPastryModel Pastry, int count)
public bool Supply(ShopSearchModel shopModel, IPastryModel Pastry, int count)
{
if (shopModel == null)
{
@ -98,11 +98,11 @@ namespace ConfectioneryBusinessLogic.BusinessLogics
{
throw new ArgumentException("Количество товаров(мороженого) в магазине должно быть больше нуля", nameof(count));
}
_logger.LogInformation("MakeShipment(GetElement). ShopName: {ShopName}. Id: {Id}", shopModel.ShopName, shopModel.Id);
_logger.LogInformation("Supply(GetElement). ShopName: {ShopName}. Id: {Id}", shopModel.ShopName, shopModel.Id);
var shop = _shopStorage.GetElement(shopModel);
if (shop == null)
{
_logger.LogWarning("MakeShipment(GetElement). Element not found");
_logger.LogWarning("Supply(GetElement). Element not found");
return false;
}
if (shop.ShopPastries.ContainsKey(Pastry.Id))
@ -110,13 +110,13 @@ namespace ConfectioneryBusinessLogic.BusinessLogics
var shopIC = shop.ShopPastries[Pastry.Id];
shopIC.Item2 += count;
shop.ShopPastries[Pastry.Id] = shopIC;
_logger.LogInformation("MakeShipment. Added {count} '{Pastry}' to '{ShopName}' shop", count, Pastry.PastryName,
_logger.LogInformation("Supply. Added {count} '{Pastry}' to '{ShopName}' shop", count, Pastry.PastryName,
shop.ShopName);
}
else
{
shop.ShopPastries.Add(Pastry.Id, (Pastry, count));
_logger.LogInformation("MakeShipment. Added {count} new '{Pastry}' to '{ShopName}' shop", count, Pastry.PastryName,
_logger.LogInformation("Supply. Added {count} new '{Pastry}' to '{ShopName}' shop", count, Pastry.PastryName,
shop.ShopName);
}
if (_shopStorage.Update(new ShopBindingModel()
@ -128,7 +128,7 @@ namespace ConfectioneryBusinessLogic.BusinessLogics
ShopPastries = shop.ShopPastries,
}) == null)
{
_logger.LogWarning("MakeShipment. Update operation failed");
_logger.LogWarning("Supply. Update operation failed");
return false;
}
return true;

View File

@ -32,6 +32,8 @@
this.справочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.компонентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.изделияToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.магазиныToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.пополнениеМагазинаToolStripMenuItem = 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();
@ -46,7 +48,8 @@
//
this.menuStrip.ImageScalingSize = new System.Drawing.Size(20, 20);
this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.справочникиToolStripMenuItem});
this.справочникиToolStripMenuItem,
this.пополнениеМагазинаToolStripMenuItem});
this.menuStrip.Location = new System.Drawing.Point(0, 0);
this.menuStrip.Name = "menuStrip";
this.menuStrip.Size = new System.Drawing.Size(1376, 28);
@ -57,7 +60,8 @@
//
this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.компонентыToolStripMenuItem,
this.изделияToolStripMenuItem});
this.изделияToolStripMenuItem,
this.магазиныToolStripMenuItem});
this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem";
this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(117, 24);
this.справочникиToolStripMenuItem.Text = "Справочники";
@ -76,6 +80,20 @@
this.изделияToolStripMenuItem.Text = "Изделия";
this.изделияToolStripMenuItem.Click += new System.EventHandler(this.ИзделияToolStripMenuItem_Click);
//
// магазиныToolStripMenuItem
//
this.магазиныToolStripMenuItem.Name = агазиныToolStripMenuItem";
this.магазиныToolStripMenuItem.Size = new System.Drawing.Size(224, 26);
this.магазиныToolStripMenuItem.Text = "Магазины";
this.магазиныToolStripMenuItem.Click += new System.EventHandler(this.МагазиныToolStripMenuItem_Click);
//
// пополнениеМагазинаToolStripMenuItem
//
this.пополнениеМагазинаToolStripMenuItem.Name = "пополнениеМагазинаToolStripMenuItem";
this.пополнениеМагазинаToolStripMenuItem.Size = new System.Drawing.Size(182, 24);
this.пополнениеМагазинаToolStripMenuItem.Text = "Пополнение магазина";
this.пополнениеМагазинаToolStripMenuItem.Click += new System.EventHandler(this.ПополнениеМагазинаToolStripMenuItem_Click);
//
// dataGridView
//
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
@ -172,5 +190,7 @@
private Button ButtonOrderReady;
private Button ButtonIssuedOrder;
private Button ButtonRef;
private ToolStripMenuItem магазиныToolStripMenuItem;
private ToolStripMenuItem пополнениеМагазинаToolStripMenuItem;
}
}

View File

@ -68,6 +68,24 @@ namespace ConfectioneryView
}
}
private void МагазиныToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormShops));
if (service is FormShops form)
{
form.ShowDialog();
}
}
private void ПополнениеМагазинаToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormSupply));
if (service is FormSupply form)
{
form.ShowDialog();
}
}
private void ButtonCreateOrder_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder));

View File

@ -0,0 +1,150 @@
namespace ConfectioneryView
{
partial class FormSupply
{
/// <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()
{
this.buttonCancel = new System.Windows.Forms.Button();
this.buttonSave = new System.Windows.Forms.Button();
this.textBoxCount = new System.Windows.Forms.TextBox();
this.labelCount = new System.Windows.Forms.Label();
this.comboBoxPastry = new System.Windows.Forms.ComboBox();
this.labelPastry = new System.Windows.Forms.Label();
this.comboBoxShop = new System.Windows.Forms.ComboBox();
this.labelShop = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// buttonCancel
//
this.buttonCancel.Location = new System.Drawing.Point(312, 170);
this.buttonCancel.Margin = new System.Windows.Forms.Padding(5, 4, 5, 4);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(101, 36);
this.buttonCancel.TabIndex = 19;
this.buttonCancel.Text = "Отмена";
this.buttonCancel.UseVisualStyleBackColor = true;
//
// buttonSave
//
this.buttonSave.Location = new System.Drawing.Point(205, 170);
this.buttonSave.Margin = new System.Windows.Forms.Padding(5, 4, 5, 4);
this.buttonSave.Name = "buttonSave";
this.buttonSave.Size = new System.Drawing.Size(101, 36);
this.buttonSave.TabIndex = 18;
this.buttonSave.Text = "Сохранить";
this.buttonSave.UseVisualStyleBackColor = true;
//
// textBoxCount
//
this.textBoxCount.Location = new System.Drawing.Point(139, 128);
this.textBoxCount.Margin = new System.Windows.Forms.Padding(5, 4, 5, 4);
this.textBoxCount.Name = "textBoxCount";
this.textBoxCount.Size = new System.Drawing.Size(287, 27);
this.textBoxCount.TabIndex = 17;
//
// labelCount
//
this.labelCount.AutoSize = true;
this.labelCount.Location = new System.Drawing.Point(38, 132);
this.labelCount.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0);
this.labelCount.Name = "labelCount";
this.labelCount.Size = new System.Drawing.Size(93, 20);
this.labelCount.TabIndex = 16;
this.labelCount.Text = "Количество:";
//
// comboBoxPastry
//
this.comboBoxPastry.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBoxPastry.FormattingEnabled = true;
this.comboBoxPastry.Location = new System.Drawing.Point(139, 80);
this.comboBoxPastry.Margin = new System.Windows.Forms.Padding(5, 4, 5, 4);
this.comboBoxPastry.Name = "comboBoxPastry";
this.comboBoxPastry.Size = new System.Drawing.Size(287, 28);
this.comboBoxPastry.TabIndex = 15;
//
// labelPastry
//
this.labelPastry.AutoSize = true;
this.labelPastry.Location = new System.Drawing.Point(38, 85);
this.labelPastry.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0);
this.labelPastry.Name = "labelPastry";
this.labelPastry.Size = new System.Drawing.Size(72, 20);
this.labelPastry.TabIndex = 14;
this.labelPastry.Text = "Выпечка:";
//
// comboBoxShop
//
this.comboBoxShop.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBoxShop.FormattingEnabled = true;
this.comboBoxShop.Location = new System.Drawing.Point(139, 34);
this.comboBoxShop.Margin = new System.Windows.Forms.Padding(5, 4, 5, 4);
this.comboBoxShop.Name = "comboBoxShop";
this.comboBoxShop.Size = new System.Drawing.Size(287, 28);
this.comboBoxShop.TabIndex = 13;
//
// labelShop
//
this.labelShop.AutoSize = true;
this.labelShop.Location = new System.Drawing.Point(38, 38);
this.labelShop.Margin = new System.Windows.Forms.Padding(5, 0, 5, 0);
this.labelShop.Name = "labelShop";
this.labelShop.Size = new System.Drawing.Size(72, 20);
this.labelShop.TabIndex = 12;
this.labelShop.Text = "Магазин:";
//
// FormSupply
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(464, 233);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.buttonSave);
this.Controls.Add(this.textBoxCount);
this.Controls.Add(this.labelCount);
this.Controls.Add(this.comboBoxPastry);
this.Controls.Add(this.labelPastry);
this.Controls.Add(this.comboBoxShop);
this.Controls.Add(this.labelShop);
this.Name = "FormSupply";
this.Text = "Пополнение магазина";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private Button buttonCancel;
private Button buttonSave;
private TextBox textBoxCount;
private Label labelCount;
private ComboBox comboBoxPastry;
private Label labelPastry;
private ComboBox comboBoxShop;
private Label labelShop;
}
}

View File

@ -0,0 +1,124 @@
using ConfectioneryContracts.BusinessLogicsContracts;
using ConfectioneryContracts.SearchModels;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ConfectioneryView
{
public partial class FormSupply : Form
{
private readonly ILogger _logger;
private readonly IPastryLogic _logicPastry;
private readonly IShopLogic _logicShop;
public FormSupply(ILogger<FormSupply> logger, IPastryLogic logicPastry, IShopLogic logicShop)
{
InitializeComponent();
_logger = logger;
_logicPastry = logicPastry;
_logicShop = logicShop;
}
private void FormSupply_Load(object sender, EventArgs e)
{
_logger.LogInformation("Ice creams loading");
try
{
var list = _logicPastry.ReadList(null);
if (list != null)
{
comboBoxPastry.DisplayMember = "PastryName";
comboBoxPastry.ValueMember = "Id";
comboBoxPastry.DataSource = list;
comboBoxPastry.SelectedItem = null;
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Ice creams loading error");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
_logger.LogInformation("Shops loading");
try
{
var list = _logicShop.ReadList(null);
if (list != null)
{
comboBoxShop.DisplayMember = "ShopName";
comboBoxShop.ValueMember = "Id";
comboBoxShop.DataSource = list;
comboBoxShop.SelectedItem = null;
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Shops loading error");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
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;
}
if (string.IsNullOrEmpty(textBoxCount.Text))
{
MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Shop replenishment");
try
{
var pastry = _logicPastry.ReadElement(new PastrySearchModel
{ Id = Convert.ToInt32(comboBoxPastry.SelectedValue) });
if (pastry == null)
{
throw new Exception("Мороженое не найдено.");
}
var operationResult = _logicShop.Supply(new ShopSearchModel
{
Id = Convert.ToInt32(comboBoxShop.SelectedValue)
},
pastry,
Convert.ToInt32(textBoxCount.Text));
if (!operationResult)
{
throw new Exception("Ошибка при проведении поставки.");
}
MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
DialogResult = DialogResult.OK;
Close();
}
catch (Exception ex)
{
_logger.LogError(ex, "Shop replenishment error");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
DialogResult = DialogResult.OK;
Close();
}
private void ButtonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
}
}

View File

@ -0,0 +1,60 @@
<root>
<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>
</root>

View File

@ -36,10 +36,12 @@ 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>();
@ -48,6 +50,9 @@ namespace ConfectioneryView
services.AddTransient<FormPastry>();
services.AddTransient<FormPastryComponent>();
services.AddTransient<FormPastries>();
services.AddTransient<FormShop>();
services.AddTransient<FormShops>();
services.AddTransient<FormSupply>();
}
}
}