Eliseev E.E. LabWork01_Hard #3

Closed
ElEgEv wants to merge 4 commits from LabWork01_Hard into LabWork01
13 changed files with 1215 additions and 24 deletions
Showing only changes of commit 4e6da8e751 - Show all commits

View File

@ -0,0 +1,151 @@
namespace BlacksmithWorkshop
{
partial class FormAddManufacture
{
/// <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.labelIceCream = new System.Windows.Forms.Label();
this.labelCount = new System.Windows.Forms.Label();
this.labelShop = new System.Windows.Forms.Label();
this.comboBoxManufacture = new System.Windows.Forms.ComboBox();
this.textBoxCount = new System.Windows.Forms.TextBox();
this.buttonSave = new System.Windows.Forms.Button();
this.buttonCancel = new System.Windows.Forms.Button();
this.comboBoxShop = new System.Windows.Forms.ComboBox();
this.SuspendLayout();
//
// labelIceCream
//
this.labelIceCream.AutoSize = true;
this.labelIceCream.Location = new System.Drawing.Point(28, 58);
this.labelIceCream.Name = "labelIceCream";
this.labelIceCream.Size = new System.Drawing.Size(56, 15);
this.labelIceCream.TabIndex = 0;
this.labelIceCream.Text = "Изделие:";
//
// labelCount
//
this.labelCount.AutoSize = true;
this.labelCount.Location = new System.Drawing.Point(28, 91);
this.labelCount.Name = "labelCount";
this.labelCount.Size = new System.Drawing.Size(75, 15);
this.labelCount.TabIndex = 1;
this.labelCount.Text = "Количество:";
//
// labelShop
//
this.labelShop.AutoSize = true;
this.labelShop.Location = new System.Drawing.Point(28, 23);
this.labelShop.Name = "labelShop";
this.labelShop.Size = new System.Drawing.Size(57, 15);
this.labelShop.TabIndex = 2;
this.labelShop.Text = "Магазин:";
//
// comboBoxManufacture
//
this.comboBoxManufacture.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBoxManufacture.FormattingEnabled = true;
this.comboBoxManufacture.Location = new System.Drawing.Point(149, 55);
this.comboBoxManufacture.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.comboBoxManufacture.Name = "comboBoxManufacture";
this.comboBoxManufacture.Size = new System.Drawing.Size(230, 23);
this.comboBoxManufacture.TabIndex = 3;
//
// textBoxCount
//
this.textBoxCount.Location = new System.Drawing.Point(149, 88);
this.textBoxCount.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.textBoxCount.Name = "textBoxCount";
this.textBoxCount.Size = new System.Drawing.Size(230, 23);
this.textBoxCount.TabIndex = 4;
//
// buttonSave
//
this.buttonSave.Location = new System.Drawing.Point(209, 123);
this.buttonSave.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonSave.Name = "buttonSave";
this.buttonSave.Size = new System.Drawing.Size(82, 22);
this.buttonSave.TabIndex = 6;
this.buttonSave.Text = "Сохранить";
this.buttonSave.UseVisualStyleBackColor = true;
this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click);
//
// buttonCancel
//
this.buttonCancel.Location = new System.Drawing.Point(297, 123);
this.buttonCancel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(82, 22);
this.buttonCancel.TabIndex = 7;
this.buttonCancel.Text = "Отмена";
this.buttonCancel.UseVisualStyleBackColor = true;
this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
//
// comboBoxShop
//
this.comboBoxShop.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBoxShop.FormattingEnabled = true;
this.comboBoxShop.Location = new System.Drawing.Point(149, 23);
this.comboBoxShop.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.comboBoxShop.Name = "comboBoxShop";
this.comboBoxShop.Size = new System.Drawing.Size(230, 23);
this.comboBoxShop.TabIndex = 8;
//
// FormAddManufacture
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(394, 159);
this.Controls.Add(this.comboBoxShop);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.buttonSave);
this.Controls.Add(this.textBoxCount);
this.Controls.Add(this.comboBoxManufacture);
this.Controls.Add(this.labelShop);
this.Controls.Add(this.labelCount);
this.Controls.Add(this.labelIceCream);
this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.Name = "FormAddManufacture";
this.Text = "Пополнение магазина";
this.Load += new System.EventHandler(this.FormAddManufacture_Load_1);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private Label labelIceCream;
private Label labelCount;
private Label labelShop;
private ComboBox comboBoxManufacture;
private TextBox textBoxCount;
private Button buttonSave;
private Button buttonCancel;
private ComboBox comboBoxShop;
}
}

View File

@ -0,0 +1,128 @@
using BlacksmithWorkshopContracts.BusinessLogicsContracts;
using BlacksmithWorkshopContracts.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 BlacksmithWorkshop
{
public partial class FormAddManufacture : Form
{
private readonly ILogger _logger;
private readonly IManufactureLogic _logicI;
private readonly IShopLogic _logicS;
public FormAddManufacture(ILogger<FormAddManufacture> logger, IManufactureLogic logicI, IShopLogic logicS)
{
InitializeComponent();
_logger = logger;
_logicI = logicI;
_logicS = logicS;
}
private void FormAddManufacture_Load_1(object sender, EventArgs e)
{
_logger.LogInformation("Загрузка списка изделий для пополнения");
try
{
var list = _logicI.ReadList(null);
if (list != null)
{
comboBoxManufacture.DisplayMember = "ManufactureName";
comboBoxManufacture.ValueMember = "Id";
comboBoxManufacture.DataSource = list;
comboBoxManufacture.SelectedItem = null;
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки списка изделий");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
_logger.LogInformation("Загрузка списка магазинов для пополнения");
try
{
var list = _logicS.ReadList(null);
if (list != null)
{
comboBoxShop.DisplayMember = "ShopName";
comboBoxShop.ValueMember = "Id";
comboBoxShop.DataSource = list;
comboBoxShop.SelectedItem = null;
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки списка магазинов");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonSave_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBoxCount.Text))
{
MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (comboBoxManufacture.SelectedValue == null)
{
MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (comboBoxShop.SelectedValue == null)
{
MessageBox.Show("Выберите магазин", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Пополнение магазина");
try
{
var operationResult = _logicS.AddManufacture(new ShopSearchModel
{
Id = Convert.ToInt32(comboBoxShop.SelectedValue)
},
_logicI.ReadElement(new ManufactureSearchModel()
{
Id = Convert.ToInt32(comboBoxManufacture.SelectedValue)
})!, 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, "Ошибка создания заказа");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
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

@ -38,6 +38,8 @@
this.toolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.workPieceToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.manufactureToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.shopToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.addManufactureToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.menuStrip1.SuspendLayout();
this.SuspendLayout();
@ -45,18 +47,20 @@
// dataGridView
//
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView.Location = new System.Drawing.Point(12, 36);
this.dataGridView.Location = new System.Drawing.Point(10, 27);
this.dataGridView.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.dataGridView.Name = "dataGridView";
this.dataGridView.RowHeadersWidth = 51;
this.dataGridView.RowTemplate.Height = 29;
this.dataGridView.Size = new System.Drawing.Size(937, 402);
this.dataGridView.Size = new System.Drawing.Size(820, 302);
this.dataGridView.TabIndex = 0;
//
// buttonCreateOrder
//
this.buttonCreateOrder.Location = new System.Drawing.Point(1014, 66);
this.buttonCreateOrder.Location = new System.Drawing.Point(887, 50);
this.buttonCreateOrder.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonCreateOrder.Name = "buttonCreateOrder";
this.buttonCreateOrder.Size = new System.Drawing.Size(235, 29);
this.buttonCreateOrder.Size = new System.Drawing.Size(206, 22);
this.buttonCreateOrder.TabIndex = 1;
this.buttonCreateOrder.Text = "Создать заказ";
this.buttonCreateOrder.UseVisualStyleBackColor = true;
@ -64,9 +68,10 @@
//
// buttonTakeOrderInWork
//
this.buttonTakeOrderInWork.Location = new System.Drawing.Point(1014, 143);
this.buttonTakeOrderInWork.Location = new System.Drawing.Point(887, 107);
this.buttonTakeOrderInWork.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonTakeOrderInWork.Name = "buttonTakeOrderInWork";
this.buttonTakeOrderInWork.Size = new System.Drawing.Size(235, 29);
this.buttonTakeOrderInWork.Size = new System.Drawing.Size(206, 22);
this.buttonTakeOrderInWork.TabIndex = 2;
this.buttonTakeOrderInWork.Text = "Отдать на выполнение";
this.buttonTakeOrderInWork.UseVisualStyleBackColor = true;
@ -74,9 +79,10 @@
//
// buttonOrderReady
//
this.buttonOrderReady.Location = new System.Drawing.Point(1014, 220);
this.buttonOrderReady.Location = new System.Drawing.Point(887, 165);
this.buttonOrderReady.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonOrderReady.Name = "buttonOrderReady";
this.buttonOrderReady.Size = new System.Drawing.Size(235, 29);
this.buttonOrderReady.Size = new System.Drawing.Size(206, 22);
this.buttonOrderReady.TabIndex = 3;
this.buttonOrderReady.Text = "Заказ готов";
this.buttonOrderReady.UseVisualStyleBackColor = true;
@ -84,9 +90,10 @@
//
// buttonIssuedOrder
//
this.buttonIssuedOrder.Location = new System.Drawing.Point(1014, 296);
this.buttonIssuedOrder.Location = new System.Drawing.Point(887, 222);
this.buttonIssuedOrder.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonIssuedOrder.Name = "buttonIssuedOrder";
this.buttonIssuedOrder.Size = new System.Drawing.Size(235, 29);
this.buttonIssuedOrder.Size = new System.Drawing.Size(206, 22);
this.buttonIssuedOrder.TabIndex = 4;
this.buttonIssuedOrder.Text = "Заказ выдан";
this.buttonIssuedOrder.UseVisualStyleBackColor = true;
@ -94,9 +101,10 @@
//
// buttonRef
//
this.buttonRef.Location = new System.Drawing.Point(1014, 369);
this.buttonRef.Location = new System.Drawing.Point(887, 277);
this.buttonRef.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonRef.Name = "buttonRef";
this.buttonRef.Size = new System.Drawing.Size(235, 29);
this.buttonRef.Size = new System.Drawing.Size(206, 22);
this.buttonRef.TabIndex = 5;
this.buttonRef.Text = "Обновить";
this.buttonRef.UseVisualStyleBackColor = true;
@ -109,7 +117,8 @@
this.toolStripMenuItem});
this.menuStrip1.Location = new System.Drawing.Point(0, 0);
this.menuStrip1.Name = "menuStrip1";
this.menuStrip1.Size = new System.Drawing.Size(1297, 28);
this.menuStrip1.Padding = new System.Windows.Forms.Padding(5, 2, 0, 2);
this.menuStrip1.Size = new System.Drawing.Size(1135, 24);
this.menuStrip1.TabIndex = 6;
this.menuStrip1.Text = "menuStrip1";
//
@ -117,30 +126,46 @@
//
this.toolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.workPieceToolStripMenuItem,
this.manufactureToolStripMenuItem});
this.manufactureToolStripMenuItem,
this.shopToolStripMenuItem,
this.addManufactureToolStripMenuItem});
this.toolStripMenuItem.Name = "toolStripMenuItem";
this.toolStripMenuItem.Size = new System.Drawing.Size(117, 24);
this.toolStripMenuItem.Size = new System.Drawing.Size(94, 20);
this.toolStripMenuItem.Text = "Справочники";
//
// workPieceToolStripMenuItem
//
this.workPieceToolStripMenuItem.Name = "workPieceToolStripMenuItem";
this.workPieceToolStripMenuItem.Size = new System.Drawing.Size(162, 26);
this.workPieceToolStripMenuItem.Size = new System.Drawing.Size(198, 22);
this.workPieceToolStripMenuItem.Text = "Заготовки";
this.workPieceToolStripMenuItem.Click += new System.EventHandler(this.WorkPieceToolStripMenuItem_Click);
//
// manufactureToolStripMenuItem
//
this.manufactureToolStripMenuItem.Name = "manufactureToolStripMenuItem";
this.manufactureToolStripMenuItem.Size = new System.Drawing.Size(162, 26);
this.manufactureToolStripMenuItem.Size = new System.Drawing.Size(198, 22);
this.manufactureToolStripMenuItem.Text = "Изделия";
this.manufactureToolStripMenuItem.Click += new System.EventHandler(this.ManufactureToolStripMenuItem_Click);
//
// shopToolStripMenuItem
//
this.shopToolStripMenuItem.Name = "shopToolStripMenuItem";
this.shopToolStripMenuItem.Size = new System.Drawing.Size(198, 22);
this.shopToolStripMenuItem.Text = "Магазины";
this.shopToolStripMenuItem.Click += new System.EventHandler(this.ShopToolStripMenuItem_Click);
//
// addManufactureToolStripMenuItem
//
this.addManufactureToolStripMenuItem.Name = "addManufactureToolStripMenuItem";
this.addManufactureToolStripMenuItem.Size = new System.Drawing.Size(198, 22);
this.addManufactureToolStripMenuItem.Text = "Пополнение магазина";
this.addManufactureToolStripMenuItem.Click += new System.EventHandler(this.AddManufactureToolStripMenuItem_Click);
//
// FormMain
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1297, 450);
this.ClientSize = new System.Drawing.Size(1135, 338);
this.Controls.Add(this.buttonRef);
this.Controls.Add(this.buttonIssuedOrder);
this.Controls.Add(this.buttonOrderReady);
@ -149,6 +174,7 @@
this.Controls.Add(this.dataGridView);
this.Controls.Add(this.menuStrip1);
this.MainMenuStrip = this.menuStrip1;
this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.Name = "FormMain";
this.Text = "Кузнечная мастерская";
this.Load += new System.EventHandler(this.FormMain_Load);
@ -172,5 +198,7 @@
private ToolStripMenuItem toolStripMenuItem;
private ToolStripMenuItem workPieceToolStripMenuItem;
private ToolStripMenuItem manufactureToolStripMenuItem;
private ToolStripMenuItem shopToolStripMenuItem;
private ToolStripMenuItem addManufactureToolStripMenuItem;
}
}

View File

@ -181,5 +181,27 @@ namespace BlacksmithWorkshop
{
LoadData();
}
private void ShopToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormShops));
if (service is FormShops form)
{
form.ShowDialog();
}
}
private void AddManufactureToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormAddManufacture));
if (service is FormAddManufacture form)
{
form.ShowDialog();
LoadData();
}
}
}
}

View File

@ -0,0 +1,209 @@
namespace BlacksmithWorkshop
{
partial class FormShop
{
/// <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.labelName = new System.Windows.Forms.Label();
this.labelAddress = new System.Windows.Forms.Label();
this.textBoxName = new System.Windows.Forms.TextBox();
this.textBoxAddress = new System.Windows.Forms.TextBox();
this.groupBoxIceCreams = new System.Windows.Forms.GroupBox();
this.dataGridView = new System.Windows.Forms.DataGridView();
this.buttonSave = new System.Windows.Forms.Button();
this.buttonCancel = new System.Windows.Forms.Button();
this.labelDate = new System.Windows.Forms.Label();
this.dateTimePickerDate = new System.Windows.Forms.DateTimePicker();
this.ID = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.ColumnManufactureName = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.ColumnCount = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.groupBoxIceCreams.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.SuspendLayout();
//
// labelName
//
this.labelName.AutoSize = true;
this.labelName.Location = new System.Drawing.Point(18, 10);
this.labelName.Name = "labelName";
this.labelName.Size = new System.Drawing.Size(62, 15);
this.labelName.TabIndex = 0;
this.labelName.Text = "Название:";
//
// labelAddress
//
this.labelAddress.AutoSize = true;
this.labelAddress.Location = new System.Drawing.Point(266, 9);
this.labelAddress.Name = "labelAddress";
this.labelAddress.Size = new System.Drawing.Size(43, 15);
this.labelAddress.TabIndex = 1;
this.labelAddress.Text = "Адрес:";
//
// textBoxName
//
this.textBoxName.Location = new System.Drawing.Point(86, 7);
this.textBoxName.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.textBoxName.Name = "textBoxName";
this.textBoxName.Size = new System.Drawing.Size(138, 23);
this.textBoxName.TabIndex = 2;
//
// textBoxAddress
//
this.textBoxAddress.Location = new System.Drawing.Point(315, 6);
this.textBoxAddress.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.textBoxAddress.Name = "textBoxAddress";
this.textBoxAddress.Size = new System.Drawing.Size(138, 23);
this.textBoxAddress.TabIndex = 3;
//
// groupBoxIceCreams
//
this.groupBoxIceCreams.Controls.Add(this.dataGridView);
this.groupBoxIceCreams.Location = new System.Drawing.Point(12, 62);
this.groupBoxIceCreams.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.groupBoxIceCreams.Name = "groupBoxIceCreams";
this.groupBoxIceCreams.Padding = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.groupBoxIceCreams.Size = new System.Drawing.Size(720, 206);
this.groupBoxIceCreams.TabIndex = 4;
this.groupBoxIceCreams.TabStop = false;
this.groupBoxIceCreams.Text = "Изделия";
//
// dataGridView
//
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.ID,
this.ColumnManufactureName,
this.ColumnCount});
this.dataGridView.Location = new System.Drawing.Point(5, 20);
this.dataGridView.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.dataGridView.Name = "dataGridView";
this.dataGridView.RowHeadersWidth = 51;
this.dataGridView.RowTemplate.Height = 29;
this.dataGridView.Size = new System.Drawing.Size(709, 182);
this.dataGridView.TabIndex = 0;
//
// buttonSave
//
this.buttonSave.Location = new System.Drawing.Point(411, 286);
this.buttonSave.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonSave.Name = "buttonSave";
this.buttonSave.Size = new System.Drawing.Size(136, 22);
this.buttonSave.TabIndex = 5;
this.buttonSave.Text = "Сохранить";
this.buttonSave.UseVisualStyleBackColor = true;
this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click);
//
// buttonCancel
//
this.buttonCancel.Location = new System.Drawing.Point(579, 286);
this.buttonCancel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(136, 22);
this.buttonCancel.TabIndex = 6;
this.buttonCancel.Text = "Отмена";
this.buttonCancel.UseVisualStyleBackColor = true;
this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
//
// labelDate
//
this.labelDate.AutoSize = true;
this.labelDate.Location = new System.Drawing.Point(492, 9);
this.labelDate.Name = "labelDate";
this.labelDate.Size = new System.Drawing.Size(90, 15);
this.labelDate.TabIndex = 7;
this.labelDate.Text = "Дата открытия:";
//
// dateTimePickerDate
//
this.dateTimePickerDate.Location = new System.Drawing.Point(588, 7);
this.dateTimePickerDate.Name = "dateTimePickerDate";
this.dateTimePickerDate.Size = new System.Drawing.Size(127, 23);
this.dateTimePickerDate.TabIndex = 9;
//
// ID
//
this.ID.HeaderText = "ID";
this.ID.Name = "ID";
this.ID.Visible = false;
//
// ColumnManufactureName
//
this.ColumnManufactureName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
this.ColumnManufactureName.HeaderText = "Изделие";
this.ColumnManufactureName.MinimumWidth = 6;
this.ColumnManufactureName.Name = "ColumnManufactureName";
this.ColumnManufactureName.Resizable = System.Windows.Forms.DataGridViewTriState.True;
//
// ColumnCount
//
this.ColumnCount.HeaderText = "Количество";
this.ColumnCount.MinimumWidth = 6;
this.ColumnCount.Name = "ColumnCount";
this.ColumnCount.Width = 125;
//
// FormShop
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(744, 319);
this.Controls.Add(this.dateTimePickerDate);
this.Controls.Add(this.labelDate);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.buttonSave);
this.Controls.Add(this.groupBoxIceCreams);
this.Controls.Add(this.textBoxAddress);
this.Controls.Add(this.textBoxName);
this.Controls.Add(this.labelAddress);
this.Controls.Add(this.labelName);
this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.Name = "FormShop";
this.Text = "Магазин";
this.Load += new System.EventHandler(this.FormShop_Load);
this.groupBoxIceCreams.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private Label labelName;
private Label labelAddress;
private TextBox textBoxName;
private TextBox textBoxAddress;
private GroupBox groupBoxIceCreams;
private DataGridView dataGridView;
private Button buttonSave;
private Button buttonCancel;
private Label labelDate;
private DateTimePicker dateTimePickerDate;
private DataGridViewTextBoxColumn ID;
private DataGridViewTextBoxColumn ColumnManufactureName;
private DataGridViewTextBoxColumn ColumnCount;
}
}

View File

@ -0,0 +1,131 @@
using BlacksmithWorkshopContracts.BindingModels;
using BlacksmithWorkshopContracts.BusinessLogicsContracts;
using BlacksmithWorkshopContracts.SearchModels;
using BlacksmithWorkshopDataModels.Models;
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 BlacksmithWorkshop
{
public partial class FormShop : Form
{
private readonly ILogger _logger;
private readonly IShopLogic _logic;
private int? _id;
private Dictionary<int, (IManufactureModel, int)> _shopManufactures;
public int Id { set { _id = value; } }
public FormShop(ILogger<FormShop> logger, IShopLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
_shopManufactures = new Dictionary<int, (IManufactureModel, int)>();
}
private void FormShop_Load(object sender, EventArgs e)
{
if (_id.HasValue)
{
_logger.LogInformation("Загрузка магазина");
try
{
var view = _logic.ReadElement(new ShopSearchModel
{
Id = _id.Value
});
if (view != null)
{
textBoxName.Text = view.ShopName;
textBoxAddress.Text = view.Address.ToString();
dateTimePickerDate.Value = view.DateOpen;
_shopManufactures = view.Manufactures ?? new Dictionary<int, (IManufactureModel, int)>();
LoadData();
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки магазина");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void LoadData()
{
_logger.LogInformation("Загрузка изделий в магазине");
try
{
if (_shopManufactures != null)
{
dataGridView.Rows.Clear();
foreach (var element in _shopManufactures)
{
dataGridView.Rows.Add(new object[] { element.Key, element.Value.Item1.ManufactureName, element.Value.Item2 });
}
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки изделий в магазине");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonSave_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBoxName.Text))
{
MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (string.IsNullOrEmpty(textBoxAddress.Text))
{
MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Сохранение магазина");
try
{
var model = new ShopBindingModel
{
Id = _id ?? 0,
ShopName = textBoxName.Text,
Address = textBoxAddress.Text,
DateOpen = dateTimePickerDate.Value.Date
};
var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model);
if (!operationResult)
{
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

@ -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

@ -0,0 +1,121 @@
namespace BlacksmithWorkshop
{
partial class FormShops
{
/// <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.dataGridView = new System.Windows.Forms.DataGridView();
this.buttonAdd = new System.Windows.Forms.Button();
this.buttonUpd = new System.Windows.Forms.Button();
this.buttonDel = new System.Windows.Forms.Button();
this.buttonRef = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.SuspendLayout();
//
// dataGridView
//
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView.Location = new System.Drawing.Point(10, 9);
this.dataGridView.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.dataGridView.Name = "dataGridView";
this.dataGridView.RowHeadersWidth = 51;
this.dataGridView.RowTemplate.Height = 29;
this.dataGridView.Size = new System.Drawing.Size(444, 320);
this.dataGridView.TabIndex = 1;
//
// buttonAdd
//
this.buttonAdd.Location = new System.Drawing.Point(465, 37);
this.buttonAdd.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonAdd.Name = "buttonAdd";
this.buttonAdd.Size = new System.Drawing.Size(133, 22);
this.buttonAdd.TabIndex = 2;
this.buttonAdd.Text = "Добавить";
this.buttonAdd.UseVisualStyleBackColor = true;
this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click);
//
// buttonUpd
//
this.buttonUpd.Location = new System.Drawing.Point(465, 119);
this.buttonUpd.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonUpd.Name = "buttonUpd";
this.buttonUpd.Size = new System.Drawing.Size(133, 22);
this.buttonUpd.TabIndex = 3;
this.buttonUpd.Text = "Изменить";
this.buttonUpd.UseVisualStyleBackColor = true;
this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click);
//
// buttonDel
//
this.buttonDel.Location = new System.Drawing.Point(465, 197);
this.buttonDel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonDel.Name = "buttonDel";
this.buttonDel.Size = new System.Drawing.Size(133, 22);
this.buttonDel.TabIndex = 4;
this.buttonDel.Text = "Удалить";
this.buttonDel.UseVisualStyleBackColor = true;
this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click);
//
// buttonRef
//
this.buttonRef.Location = new System.Drawing.Point(465, 274);
this.buttonRef.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonRef.Name = "buttonRef";
this.buttonRef.Size = new System.Drawing.Size(133, 22);
this.buttonRef.TabIndex = 5;
this.buttonRef.Text = "Обновить";
this.buttonRef.UseVisualStyleBackColor = true;
this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click);
//
// FormShops
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(610, 338);
this.Controls.Add(this.buttonRef);
this.Controls.Add(this.buttonDel);
this.Controls.Add(this.buttonUpd);
this.Controls.Add(this.buttonAdd);
this.Controls.Add(this.dataGridView);
this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.Name = "FormShops";
this.Text = "Магазины";
this.Load += new System.EventHandler(this.FormShops_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.ResumeLayout(false);
}
#endregion
private DataGridView dataGridView;
private Button buttonAdd;
private Button buttonUpd;
private Button buttonDel;
private Button buttonRef;
}
}

View File

@ -0,0 +1,117 @@
using BlacksmithWorkshopContracts.BindingModels;
using BlacksmithWorkshopContracts.BusinessLogicsContracts;
using BlacksmithWorkshopContracts.SearchModels;
using BlacksmithWorkshopDataModels.Models;
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 BlacksmithWorkshop
{
public partial class FormShops : Form
{
private readonly ILogger _logger;
private readonly IShopLogic _logic;
public FormShops(ILogger<FormShops> logger, IShopLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
}
private void FormShops_Load(object sender, EventArgs e)
{
LoadData();
}
private void LoadData()
{
try
{
var list = _logic.ReadList(null);
if (list != null)
{
dataGridView.DataSource = list;
dataGridView.Columns["Id"].Visible = false;
dataGridView.Columns["Manufactures"].Visible = false;
dataGridView.Columns["ShopName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
_logger.LogInformation("Загрузка магазинов");
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки магазинов");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonAdd_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormShop));
if (service is FormShop form)
{
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
private void ButtonUpd_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
var service = Program.ServiceProvider?.GetService(typeof(FormShop));
if (service is FormShop form)
{
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
}
private void ButtonDel_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Удаление магазина");
try
{
if (!_logic.Delete(new ShopBindingModel
{
Id = id
}))
{
throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
}
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка удаления мороженого");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
private void ButtonRef_Click(object sender, EventArgs e)
{
LoadData();
}
}
}

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

@ -39,10 +39,12 @@ namespace BlacksmithWorkshop
services.AddTransient<IWorkPieceStorage, WorkPieceStorage>();
services.AddTransient<IOrderStorage, OrderStorage>();
services.AddTransient<IManufactureStorage, ManufactureStorage>();
services.AddTransient<IShopStorage, ShopStorage>();
services.AddTransient<IWorkPieceLogic, WorkPieceLogic>();
services.AddTransient<IOrderLogic, OrderLogic>();
services.AddTransient<IManufactureLogic, ManufactureLogic>();
services.AddTransient<IShopLogic, ShopLogic>();
services.AddTransient<FormMain>();
services.AddTransient<FormWorkPiece>();
@ -51,6 +53,9 @@ namespace BlacksmithWorkshop
services.AddTransient<FormManufacture>();
services.AddTransient<FormManufactures>();
services.AddTransient<FormManufactureWorkPiece>();
services.AddTransient<FormShop>();
services.AddTransient<FormShops>();
services.AddTransient<FormAddManufacture>();
}
}

View File

@ -13,7 +13,7 @@ using System.Threading.Tasks;
namespace BlacksmithWorkshopBusinessLogic.BusinessLogic
{
internal class ShopLogic : IShopLogic
public class ShopLogic : IShopLogic
{
private readonly ILogger _logger;
private readonly IShopStorage _shopStorage;
@ -65,22 +65,121 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic
public bool AddManufacture(ShopSearchModel model, IManufactureModel manufacture, int count)
{
throw new NotImplementedException();
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (count <= 0)
{
throw new ArgumentNullException("Количество добавляемого мороженого должно быть больше 0", nameof(count));
}
_logger.LogInformation("AddIceCream. ShopName:{ShopName}. Id: {Id}", model?.ShopName, model?.Id);
var shop = _shopStorage.GetElement(model);
if (shop == null)
{
_logger.LogWarning("Add Manufacture operation failed");
return false;
}
if (!shop.Manufactures.ContainsKey(manufacture.Id))
{
shop.Manufactures[manufacture.Id] = (manufacture, count);
}
else
{
shop.Manufactures[manufacture.Id] = (manufacture, shop.Manufactures[manufacture.Id].Item2 + count);
}
_shopStorage.Update(new ShopBindingModel()
{
ShopName = shop.ShopName,
Address = shop.Address,
DateOpen = shop.DateOpen,
Manufactures = shop.Manufactures
});
return true;
}
public bool Create(ShopBindingModel model)
{
throw new NotImplementedException();
CheckModel(model);
if (_shopStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Update(ShopBindingModel model)
{
throw new NotImplementedException();
CheckModel(model);
if (_shopStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool Delete(ShopBindingModel model)
{
throw new NotImplementedException();
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_shopStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
private void CheckModel(ShopBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.ShopName))
{
throw new ArgumentNullException("Отсутствует названия магазина", nameof(model.ShopName));
}
if (string.IsNullOrEmpty(model.Address))
{
throw new ArgumentNullException("Отсутствует адреса магазина", nameof(model.Address));
}
_logger.LogInformation("Shop. ShopName:{ShopName}. Address:{Address}. Id: {Id}", model.ShopName, model.Address, model.Id);
var element = _shopStorage.GetElement(new ShopSearchModel
{
ShopName = model.ShopName
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("Магазин с таким названием уже есть");
}
}
}
}