PIbd - 21 Bakalskaya E.D. LabWork01 HARD #8

Closed
ekallin wants to merge 8 commits from LabWork11 into LabWork01
18 changed files with 743 additions and 74 deletions
Showing only changes of commit 0abee5b276 - Show all commits

View File

@ -32,13 +32,14 @@
ToolStripMenuItemRef = new ToolStripMenuItem();
компонентыToolStripMenuItem = new ToolStripMenuItem();
сушиToolStripMenuItem = new ToolStripMenuItem();
магазиныToolStripMenuItem = new ToolStripMenuItem();
dataGridView = new DataGridView();
buttonCreateOrder = new Button();
buttonTakeOrderInWork = new Button();
buttonOrderReady = new Button();
buttonOrderIssued = new Button();
buttonRefreshOrders = new Button();
магазиныToolStripMenuItem = new ToolStripMenuItem();
buttonAddSushiInShop = new Button();
menuStrip1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
SuspendLayout();
@ -63,17 +64,24 @@
// компонентыToolStripMenuItem
//
компонентыToolStripMenuItem.Name = омпонентыToolStripMenuItem";
компонентыToolStripMenuItem.Size = new Size(224, 26);
компонентыToolStripMenuItem.Size = new Size(182, 26);
компонентыToolStripMenuItem.Text = "Компоненты";
компонентыToolStripMenuItem.Click += компонентыToolStripMenuItem_Click;
//
// сушиToolStripMenuItem
//
сушиToolStripMenuItem.Name = "сушиToolStripMenuItem";
сушиToolStripMenuItem.Size = new Size(224, 26);
сушиToolStripMenuItem.Size = new Size(182, 26);
сушиToolStripMenuItem.Text = "Суши";
сушиToolStripMenuItem.Click += сушиToolStripMenuItem_Click;
//
// магазиныToolStripMenuItem
//
магазиныToolStripMenuItem.Name = агазиныToolStripMenuItem";
магазиныToolStripMenuItem.Size = new Size(182, 26);
магазиныToolStripMenuItem.Text = "Магазины";
магазиныToolStripMenuItem.Click += магазиныToolStripMenuItem_Click;
//
// dataGridView
//
dataGridView.BackgroundColor = Color.White;
@ -88,7 +96,7 @@
//
// buttonCreateOrder
//
buttonCreateOrder.Location = new Point(923, 63);
buttonCreateOrder.Location = new Point(923, 43);
buttonCreateOrder.Name = "buttonCreateOrder";
buttonCreateOrder.Size = new Size(171, 52);
buttonCreateOrder.TabIndex = 2;
@ -98,7 +106,7 @@
//
// buttonTakeOrderInWork
//
buttonTakeOrderInWork.Location = new Point(923, 161);
buttonTakeOrderInWork.Location = new Point(923, 118);
buttonTakeOrderInWork.Name = "buttonTakeOrderInWork";
buttonTakeOrderInWork.Size = new Size(171, 52);
buttonTakeOrderInWork.TabIndex = 3;
@ -108,7 +116,7 @@
//
// buttonOrderReady
//
buttonOrderReady.Location = new Point(923, 253);
buttonOrderReady.Location = new Point(923, 191);
buttonOrderReady.Name = "buttonOrderReady";
buttonOrderReady.Size = new Size(171, 52);
buttonOrderReady.TabIndex = 4;
@ -118,7 +126,7 @@
//
// buttonOrderIssued
//
buttonOrderIssued.Location = new Point(923, 351);
buttonOrderIssued.Location = new Point(923, 264);
buttonOrderIssued.Name = "buttonOrderIssued";
buttonOrderIssued.Size = new Size(171, 52);
buttonOrderIssued.TabIndex = 5;
@ -135,12 +143,15 @@
buttonRefreshOrders.Text = "Обновить заказы";
buttonRefreshOrders.UseVisualStyleBackColor = true;
//
// магазиныToolStripMenuItem
// buttonAddSushiInShop
//
магазиныToolStripMenuItem.Name = агазиныToolStripMenuItem";
магазиныToolStripMenuItem.Size = new Size(224, 26);
магазиныToolStripMenuItem.Text = "Магазины";
магазиныToolStripMenuItem.Click += магазиныToolStripMenuItem_Click;
buttonAddSushiInShop.Location = new Point(923, 359);
buttonAddSushiInShop.Name = "buttonAddSushiInShop";
buttonAddSushiInShop.Size = new Size(171, 52);
buttonAddSushiInShop.TabIndex = 7;
buttonAddSushiInShop.Text = "Пополнить магазин";
buttonAddSushiInShop.UseVisualStyleBackColor = true;
buttonAddSushiInShop.Click += buttonAddSushiInShop_Click;
//
// FormMain
//
@ -148,6 +159,7 @@
AutoScaleMode = AutoScaleMode.Font;
BackColor = Color.FromArgb(210, 255, 210);
ClientSize = new Size(1140, 540);
Controls.Add(buttonAddSushiInShop);
Controls.Add(buttonRefreshOrders);
Controls.Add(buttonOrderIssued);
Controls.Add(buttonOrderReady);
@ -179,5 +191,6 @@
private ToolStripMenuItem компонентыToolStripMenuItem;
private ToolStripMenuItem сушиToolStripMenuItem;
private ToolStripMenuItem магазиныToolStripMenuItem;
private Button buttonAddSushiInShop;
}
}

View File

@ -68,7 +68,7 @@ namespace SushiBarView
private void магазиныToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormShops));
if(service is FormShops formShops) { formShops.ShowDialog(); }
if (service is FormShops formShops) { formShops.ShowDialog(); }
}
private void buttonCreateOrder_Click(object sender, EventArgs e)
@ -155,5 +155,14 @@ namespace SushiBarView
{
LoadData();
}
private void buttonAddSushiInShop_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormAddSushiInShop));
if (service is FormAddSushiInShop form)
{
form.ShowDialog();
}
}
}
}

View File

@ -1,6 +1,7 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using NLog.Extensions.Logging;
using SushiBarBusinessLogic;
using SushiBarBusinessLogic.BusinessLogic;
using SushiBarContracts.BusinessLogicsContracts;
using SushiBarContracts.StoragesContracts;
@ -29,7 +30,6 @@ namespace SushiBar
ConfigureServices(services);
_serviceProvider = services.BuildServiceProvider();
Application.Run(_serviceProvider.GetRequiredService<FormMain>());
//Application.Run(new Form1());
}
private static void ConfigureServices(ServiceCollection services)
@ -42,9 +42,13 @@ namespace SushiBar
services.AddTransient<IComponentStorage, ComponentStorage>();
services.AddTransient<IOrderStorage, OrderStorage>();
services.AddTransient<ISushiStorage, SushiStorage>();
services.AddTransient<IShopStorage, ShopStorage>();
services.AddTransient<IComponentLogic, ComponentLogic>();
services.AddTransient<IOrderLogic, OrderLogic>();
services.AddTransient<ISushiLogic, SushiLogic>();
services.AddTransient<IShopLogic, ShopLogic>();
services.AddTransient<FormMain>();
services.AddTransient<FormComponent>();
services.AddTransient<FormComponents>();
@ -54,6 +58,7 @@ namespace SushiBar
services.AddTransient<FormSushis>();
services.AddTransient<FormShop>();
services.AddTransient<FormShops>();
services.AddTransient<FormAddSushiInShop>();
}
}
}

View File

@ -0,0 +1,149 @@
namespace SushiBarView.Shops
{
partial class FormAddSushiInShop
{
/// <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()
{
comboBoxSushi = new ComboBox();
labelSushi = new Label();
labelShop = new Label();
comboBoxShop = new ComboBox();
textBoxCount = new TextBox();
labelCount = new Label();
buttonSave = new Button();
buttonCancel = new Button();
SuspendLayout();
//
// comboBoxSushi
//
comboBoxSushi.FormattingEnabled = true;
comboBoxSushi.Location = new Point(212, 49);
comboBoxSushi.Margin = new Padding(4);
comboBoxSushi.Name = "comboBoxSushi";
comboBoxSushi.Size = new Size(188, 30);
comboBoxSushi.TabIndex = 0;
//
// labelSushi
//
labelSushi.AutoSize = true;
labelSushi.Location = new Point(42, 57);
labelSushi.Margin = new Padding(4, 0, 4, 0);
labelSushi.Name = "labelSushi";
labelSushi.Size = new Size(60, 22);
labelSushi.TabIndex = 1;
labelSushi.Text = "Суши: ";
//
// labelShop
//
labelShop.AutoSize = true;
labelShop.Location = new Point(42, 188);
labelShop.Margin = new Padding(4, 0, 4, 0);
labelShop.Name = "labelShop";
labelShop.Size = new Size(86, 22);
labelShop.TabIndex = 3;
labelShop.Text = "Магазин: ";
//
// comboBoxShop
//
comboBoxShop.FormattingEnabled = true;
comboBoxShop.Location = new Point(212, 188);
comboBoxShop.Margin = new Padding(4);
comboBoxShop.Name = "comboBoxShop";
comboBoxShop.Size = new Size(188, 30);
comboBoxShop.TabIndex = 2;
//
// textBoxCount
//
textBoxCount.Location = new Point(212, 118);
textBoxCount.Name = "textBoxCount";
textBoxCount.Size = new Size(188, 29);
textBoxCount.TabIndex = 4;
//
// labelCount
//
labelCount.AutoSize = true;
labelCount.Location = new Point(42, 121);
labelCount.Margin = new Padding(4, 0, 4, 0);
labelCount.Name = "labelCount";
labelCount.Size = new Size(154, 22);
labelCount.TabIndex = 5;
labelCount.Text = "Количество суши: ";
//
// buttonSave
//
buttonSave.Location = new Point(471, 174);
buttonSave.Name = "buttonSave";
buttonSave.Size = new Size(107, 44);
buttonSave.TabIndex = 6;
buttonSave.Text = "Сохранить";
buttonSave.UseVisualStyleBackColor = true;
buttonSave.Click += buttonSave_Click;
//
// buttonCancel
//
buttonCancel.Location = new Point(617, 174);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(107, 44);
buttonCancel.TabIndex = 7;
buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += buttonCancel_Click;
//
// FormAddSushiInShop
//
AutoScaleDimensions = new SizeF(10F, 22F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(762, 267);
Controls.Add(buttonCancel);
Controls.Add(buttonSave);
Controls.Add(labelCount);
Controls.Add(textBoxCount);
Controls.Add(labelShop);
Controls.Add(comboBoxShop);
Controls.Add(labelSushi);
Controls.Add(comboBoxSushi);
Font = new Font("Candara", 10.8F, FontStyle.Regular, GraphicsUnit.Point, 204);
Margin = new Padding(4);
Name = "FormAddSushiInShop";
Text = "FormAddSushiInShop";
Review

Заголовок формы оформлен неверно

Заголовок формы оформлен неверно
Load += FormAddSushiInShop_Load;
ResumeLayout(false);
PerformLayout();
}
#endregion
private ComboBox comboBoxSushi;
private Label labelSushi;
private Label labelShop;
private ComboBox comboBoxShop;
private TextBox textBoxCount;
private Label labelCount;
private Button buttonSave;
private Button buttonCancel;
}
}

View File

@ -0,0 +1,113 @@
using Microsoft.Extensions.Logging;
using SushiBarContracts.BindingModel;
using SushiBarContracts.BusinessLogicsContracts;
using SushiBarContracts.SearchModel;
namespace SushiBarView.Shops
{
public partial class FormAddSushiInShop : Form
{
private readonly ILogger _logger;
private readonly IShopLogic _shopLogic;
private readonly ISushiLogic _sushiLogic;
public FormAddSushiInShop(ILogger<FormAddSushiInShop> logger, IShopLogic shopLogic, ISushiLogic sushiLogic)
{
InitializeComponent();
_logger = logger;
_shopLogic = shopLogic;
_sushiLogic = sushiLogic;
}
private void buttonSave_Click(object sender, EventArgs e)
{
if (comboBoxShop.SelectedValue == null)
{
MessageBox.Show("Выберите магазин", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (comboBoxSushi.SelectedValue == null)
{
MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (string.IsNullOrEmpty(textBoxCount.Text))
{
MessageBox.Show("Введите количество изделий", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Добавление изделия в магазин");
try
{
var operationResult = _shopLogic.AddSushiInShop(
new ShopSearchModel { Id = Convert.ToInt32(comboBoxShop.SelectedValue), ShopName = comboBoxShop.Text },
new SushiBindingModel { Id = Convert.ToInt32(comboBoxSushi.SelectedValue), SushiName = comboBoxSushi.Text },
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 FormAddSushiInShop_Load(object sender, EventArgs e)
{
_logger.LogInformation("Загрузка магазинов");
try
{
var listShops = _shopLogic.ReadList(null);
if (listShops != null)
{
comboBoxShop.DisplayMember = "ShopName";
comboBoxShop.ValueMember = "Id";
comboBoxShop.DataSource = listShops;
comboBoxShop.SelectedItem = null;
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки списка магазинов");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
_logger.LogInformation("Загрузка суши");
try
{
var list = _sushiLogic.ReadList(null);
if (list != null)
{
comboBoxSushi.DisplayMember = "SushiName";
comboBoxSushi.ValueMember = "Id";
comboBoxSushi.DataSource = list;
comboBoxSushi.SelectedItem = null;
}
}
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,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -31,55 +31,60 @@
buttonCancel = new Button();
buttonSave = new Button();
textBoxAddress = new TextBox();
textBoxName = new TextBox();
labelAddress = new Label();
labelName = new Label();
dateTimePickerDateOpening = new DateTimePicker();
labelDateOpening = new Label();
groupBoxComponents = new GroupBox();
buttonRefresh = new Button();
buttonDelete = new Button();
buttonUpdate = new Button();
buttonAdd = new Button();
dataGridView = new DataGridView();
ColumnId = new DataGridViewTextBoxColumn();
ColumnSushiName = new DataGridViewTextBoxColumn();
ColumnCount = new DataGridViewTextBoxColumn();
textBoxName = new TextBox();
groupBoxComponents.SuspendLayout();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
SuspendLayout();
//
// buttonCancel
//
buttonCancel.Anchor = AnchorStyles.None;
buttonCancel.Location = new Point(421, 203);
buttonCancel.Location = new Point(710, 431);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(116, 39);
buttonCancel.TabIndex = 11;
buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += buttonCancel_Click;
//
// buttonSave
//
buttonSave.Anchor = AnchorStyles.None;
buttonSave.Location = new Point(182, 203);
buttonSave.Location = new Point(471, 431);
buttonSave.Name = "buttonSave";
buttonSave.Size = new Size(116, 39);
buttonSave.TabIndex = 10;
buttonSave.Text = "Сохранить";
buttonSave.UseVisualStyleBackColor = true;
buttonSave.Click += buttonSave_Click;
//
// textBoxAddress
//
textBoxAddress.Anchor = AnchorStyles.None;
textBoxAddress.Location = new Point(182, 86);
textBoxAddress.Location = new Point(124, 46);
textBoxAddress.Name = "textBoxAddress";
textBoxAddress.Size = new Size(355, 27);
textBoxAddress.Size = new Size(330, 27);
textBoxAddress.TabIndex = 9;
//
// textBoxName
//
textBoxName.Anchor = AnchorStyles.None;
textBoxName.Location = new Point(182, 20);
textBoxName.Name = "textBoxName";
textBoxName.Size = new Size(355, 27);
textBoxName.TabIndex = 8;
//
// labelAddress
//
labelAddress.Anchor = AnchorStyles.None;
labelAddress.AutoSize = true;
labelAddress.Font = new Font("Candara", 12F);
labelAddress.Location = new Point(34, 86);
labelAddress.Location = new Point(24, 46);
labelAddress.Margin = new Padding(4, 0, 4, 0);
labelAddress.Name = "labelAddress";
labelAddress.Size = new Size(63, 24);
@ -91,7 +96,7 @@
labelName.Anchor = AnchorStyles.None;
labelName.AutoSize = true;
labelName.Font = new Font("Candara", 12F);
labelName.Location = new Point(18, 23);
labelName.Location = new Point(24, 9);
labelName.Margin = new Padding(4, 0, 4, 0);
labelName.Name = "labelName";
labelName.Size = new Size(93, 24);
@ -100,7 +105,7 @@
//
// dateTimePickerDateOpening
//
dateTimePickerDateOpening.Location = new Point(182, 152);
dateTimePickerDateOpening.Location = new Point(471, 46);
dateTimePickerDateOpening.Name = "dateTimePickerDateOpening";
dateTimePickerDateOpening.Size = new Size(355, 27);
dateTimePickerDateOpening.TabIndex = 12;
@ -110,28 +115,131 @@
labelDateOpening.Anchor = AnchorStyles.None;
labelDateOpening.AutoSize = true;
labelDateOpening.Font = new Font("Candara", 12F);
labelDateOpening.Location = new Point(18, 155);
labelDateOpening.Location = new Point(471, 6);
labelDateOpening.Margin = new Padding(4, 0, 4, 0);
labelDateOpening.Name = "labelDateOpening";
labelDateOpening.Size = new Size(140, 24);
labelDateOpening.TabIndex = 13;
labelDateOpening.Text = "Дата открытия";
//
// groupBoxComponents
//
groupBoxComponents.Controls.Add(buttonRefresh);
groupBoxComponents.Controls.Add(buttonDelete);
groupBoxComponents.Controls.Add(buttonUpdate);
groupBoxComponents.Controls.Add(buttonAdd);
groupBoxComponents.Controls.Add(dataGridView);
groupBoxComponents.Location = new Point(11, 93);
groupBoxComponents.Margin = new Padding(2, 3, 2, 3);
groupBoxComponents.Name = "groupBoxComponents";
groupBoxComponents.Padding = new Padding(2, 3, 2, 3);
groupBoxComponents.Size = new Size(443, 396);
groupBoxComponents.TabIndex = 18;
groupBoxComponents.TabStop = false;
//
// buttonRefresh
//
buttonRefresh.BackColor = Color.FromArgb(255, 192, 192);
buttonRefresh.Location = new Point(483, 330);
buttonRefresh.Name = "buttonRefresh";
buttonRefresh.Size = new Size(127, 47);
buttonRefresh.TabIndex = 9;
buttonRefresh.Text = "Обновить";
buttonRefresh.UseVisualStyleBackColor = false;
//
// buttonDelete
//
buttonDelete.BackColor = Color.FromArgb(255, 192, 192);
buttonDelete.Location = new Point(483, 228);
buttonDelete.Name = "buttonDelete";
buttonDelete.Size = new Size(127, 47);
buttonDelete.TabIndex = 8;
buttonDelete.Text = "Удалить";
buttonDelete.UseVisualStyleBackColor = false;
//
// buttonUpdate
//
buttonUpdate.BackColor = Color.FromArgb(255, 192, 192);
buttonUpdate.Location = new Point(483, 125);
buttonUpdate.Name = "buttonUpdate";
buttonUpdate.Size = new Size(127, 47);
buttonUpdate.TabIndex = 7;
buttonUpdate.Text = "Изменить";
buttonUpdate.UseVisualStyleBackColor = false;
//
// buttonAdd
//
buttonAdd.BackColor = Color.FromArgb(255, 192, 192);
buttonAdd.Location = new Point(483, 27);
buttonAdd.Name = "buttonAdd";
buttonAdd.Size = new Size(127, 47);
buttonAdd.TabIndex = 6;
buttonAdd.Text = "Добавить";
buttonAdd.UseVisualStyleBackColor = false;
//
// dataGridView
//
dataGridView.AllowUserToAddRows = false;
dataGridView.AllowUserToResizeRows = false;
dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
dataGridView.BackgroundColor = Color.FromArgb(255, 192, 192);
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView.Columns.AddRange(new DataGridViewColumn[] { ColumnId, ColumnSushiName, ColumnCount });
dataGridView.Location = new Point(13, 27);
dataGridView.Margin = new Padding(2, 3, 2, 3);
dataGridView.Name = "dataGridView";
dataGridView.RowHeadersVisible = false;
dataGridView.RowHeadersWidth = 51;
dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dataGridView.Size = new Size(419, 350);
dataGridView.TabIndex = 5;
//
// ColumnId
//
ColumnId.HeaderText = "id";
ColumnId.MinimumWidth = 6;
ColumnId.Name = "ColumnId";
ColumnId.Visible = false;
//
// ColumnSushiName
//
ColumnSushiName.HeaderText = "Название Суши";
ColumnSushiName.MinimumWidth = 6;
ColumnSushiName.Name = "ColumnSushiName";
//
// ColumnCount
//
ColumnCount.HeaderText = "Количество";
ColumnCount.MinimumWidth = 6;
ColumnCount.Name = "ColumnCount";
//
// textBoxName
//
textBoxName.Anchor = AnchorStyles.None;
textBoxName.Location = new Point(124, 6);
textBoxName.Name = "textBoxName";
textBoxName.Size = new Size(330, 27);
textBoxName.TabIndex = 19;
//
// FormShop
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(571, 273);
ClientSize = new Size(849, 522);
Controls.Add(textBoxName);
Controls.Add(groupBoxComponents);
Controls.Add(labelDateOpening);
Controls.Add(dateTimePickerDateOpening);
Controls.Add(buttonCancel);
Controls.Add(buttonSave);
Controls.Add(textBoxAddress);
Controls.Add(textBoxName);
Controls.Add(labelAddress);
Controls.Add(labelName);
Name = "FormShop";
Text = "Магазин";
Load += FormShop_Load;
groupBoxComponents.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
ResumeLayout(false);
PerformLayout();
}
@ -141,10 +249,19 @@
private Button buttonCancel;
private Button buttonSave;
private TextBox textBoxAddress;
private TextBox textBoxName;
private Label labelAddress;
private Label labelName;
private DateTimePicker dateTimePickerDateOpening;
private Label labelDateOpening;
private GroupBox groupBoxComponents;
private Button buttonRefresh;
private Button buttonDelete;
private Button buttonUpdate;
private Button buttonAdd;
private DataGridView dataGridView;
private TextBox textBoxName;
private DataGridViewTextBoxColumn ColumnId;
private DataGridViewTextBoxColumn ColumnSushiName;
private DataGridViewTextBoxColumn ColumnCount;
}
}

View File

@ -1,17 +1,9 @@
using Microsoft.Extensions.Logging;
using SushiBarContracts.BindingModel;
using SushiBarContracts.BusinessLogicsContracts;
using SushiBarContracts.SearchModel;
using SushiBarDataModels.Models;
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;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
namespace SushiBarView.Shops
{
@ -26,7 +18,7 @@ namespace SushiBarView.Shops
}
private Dictionary<int, (ISushiModel, int)> _shopSushis;
public FormShop(ILogger logger, IShopLogic shopLogic)
public FormShop(ILogger<FormShop> logger, IShopLogic shopLogic)
{
_logger = logger;
_logic = shopLogic;
@ -44,7 +36,7 @@ namespace SushiBarView.Shops
var view = _logic.ReadElement(new ShopSearchModel { Id = _id.Value });
if (view != null)
{
textBoxName.Text = view.Name;
textBoxName.Text = view.ShopName;
textBoxAddress.Text = view.Address;
dateTimePickerDateOpening.Text = view.DateOpening.ToString();
_shopSushis = view.ShopSushis ?? new Dictionary<int, (ISushiModel, int)>();
@ -59,19 +51,20 @@ namespace SushiBarView.Shops
}
}
private void LoadData() {
private void LoadData()
{
_logger.LogInformation("Загрузка изделий магазина");
try
{
if (_shopSushis != null)
{
dataGridView.Rows.Clear();
foreach (var elem in _shopPlanes)
foreach (var elem in _shopSushis)
{
dataGridView.Rows.Add(new object[]
{
elem.Key,
elem.Value.Item1.PlaneName,
elem.Value.Item1.SushiName,
elem.Value.Item2
});
}
@ -83,5 +76,51 @@ namespace SushiBarView.Shops
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($"Сохранение магазина {textBoxName.Text}");
try
{
var model = new ShopBindingModel
{
Id = _id ?? 0,
ShopName = textBoxName.Text,
Address = textBoxAddress.Text,
DateOpening = dateTimePickerDateOpening.Value.Date,
ShopSushis = _shopSushis
};
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

@ -117,4 +117,13 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="ColumnId.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="ColumnSushiName.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="ColumnCount.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
</root>

View File

@ -61,6 +61,7 @@
buttonRefresh.TabIndex = 8;
buttonRefresh.Text = "Обновить";
buttonRefresh.UseVisualStyleBackColor = true;
buttonRefresh.Click += buttonRefresh_Click;
//
// buttonRemove
//
@ -71,6 +72,7 @@
buttonRemove.TabIndex = 7;
buttonRemove.Text = "Удалить";
buttonRemove.UseVisualStyleBackColor = true;
buttonRemove.Click += buttonRemove_Click;
//
// buttonUpdate
//
@ -81,6 +83,7 @@
buttonUpdate.TabIndex = 6;
buttonUpdate.Text = "Изменить";
buttonUpdate.UseVisualStyleBackColor = true;
buttonUpdate.Click += buttonUpdate_Click;
//
// buttonAdd
//
@ -106,6 +109,7 @@
Controls.Add(dataGridView);
Name = "FormShops";
Text = "Магазины";
Load += FormShops_LoadData;
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
ResumeLayout(false);
}

View File

@ -1,4 +1,6 @@
using Microsoft.Extensions.Logging;
using SushiBar;
using SushiBarContracts.BindingModel;
using SushiBarContracts.BusinessLogicsContracts;
using SushiBarContracts.SearchModel;
using SushiBarDataModels.Models;
@ -8,11 +10,98 @@ namespace SushiBarView.Shops
{
public partial class FormShops : Form
{
private readonly ILogger _logger;
private readonly IShopLogic _shopLogic;
public FormShops(ILogger<FormShops> logger, IShopLogic shopLogic)
{
InitializeComponent();
_logger = logger;
_shopLogic = shopLogic;
}
private void FormShops_LoadData(object sender, EventArgs e)
{
LoadData();
}
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 LoadData()
{
try
{
var list = _shopLogic.ReadList(null);
if (list != null)
{
dataGridView.DataSource = list;
dataGridView.Columns["Id"].Visible = false;
dataGridView.Columns["ShopName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
dataGridView.Columns["ShopSushis"].Visible = false;
}
_logger.LogInformation("Загрузка магазинов");
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки магазинов");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void buttonUpdate_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 buttonRemove_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 (!_shopLogic.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 buttonRefresh_Click(object sender, EventArgs e)
{
LoadData();
}
}
}

View File

@ -14,7 +14,7 @@ namespace SushiBarBusinessLogic
private readonly ILogger _logger;
private readonly IShopStorage _shopStorage;
public ShopLogic(ILogger logger, IShopStorage shopStorage)
public ShopLogic(ILogger<ShopLogic> logger, IShopStorage shopStorage)
{
_logger = logger;
_shopStorage = shopStorage;
@ -22,7 +22,7 @@ namespace SushiBarBusinessLogic
public List<ShopViewModel>? ReadList(ShopSearchModel? model)
{
_logger.LogInformation("ReadList. Id:{ Id}, ShopName:{ ShopName}", model?.Id, model?.Name);
_logger.LogInformation("ReadList. Id:{ Id}, ShopName:{ ShopName}", model?.Id, model?.ShopName);
var list = model == null ? _shopStorage.GetFullList() : _shopStorage.GetFilteredList(model);
if (list == null)
{
@ -39,7 +39,7 @@ namespace SushiBarBusinessLogic
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadList. Id:{ Id}, ShopName:{ ShopName}", model.Id, model.Name);
_logger.LogInformation("ReadList. Id:{ Id}, ShopName:{ ShopName}", model.Id, model.ShopName);
var element = _shopStorage.GetElement(model);
if (element == null)
{
@ -88,7 +88,7 @@ namespace SushiBarBusinessLogic
if (model == null) throw new ArgumentNullException(nameof(model));
if(count <= 0)
throw new ArgumentException(nameof(count));
_logger.LogInformation("AddSushiInShop. ShopName:{ShopName}.Id:{ Id}", model.Name, model.Id);
_logger.LogInformation("AddSushiInShop. ShopName:{ShopName}.Id:{ Id}", model.ShopName, model.Id);
var element = _shopStorage.GetElement(model);
if (element == null)
@ -99,18 +99,18 @@ namespace SushiBarBusinessLogic
if (element.ShopSushis.TryGetValue(sushi.Id, out var samesushi))
{
element.ShopSushis[sushi.Id] = (sushi, samesushi.Item2 + count);
_logger.LogInformation("Same sushi found by supply. Added {0} of {1} in {2} shop", count, sushi.SushiName, element.Name);
_logger.LogInformation("Same sushi found by supply. Added {0} of {1} in {2} shop", count, sushi.SushiName, element.ShopName);
}
else
{
element.ShopSushis[sushi.Id] = (sushi, count);
_logger.LogInformation("New sushi added by supply. Added {0} of {1} in {2} shop", count, sushi.SushiName, element.Name);
_logger.LogInformation("New sushi added by supply. Added {0} of {1} in {2} shop", count, sushi.SushiName, element.ShopName);
}
_shopStorage.Update(new()
{
Id = element.Id,
Name = element.Name,
ShopName = element.ShopName,
Address = element.Address,
DateOpening = element.DateOpening,
ShopSushis = element.ShopSushis
@ -124,17 +124,17 @@ namespace SushiBarBusinessLogic
if(model == null)
throw new ArgumentNullException($"{nameof(model)} является null");
if (!withParams) return;
if (string.IsNullOrEmpty(model.Name))
if (string.IsNullOrEmpty(model.ShopName))
{
throw new ArgumentNullException("Нет такого магазина", nameof(model.Name));
throw new ArgumentNullException("Нет такого магазина", nameof(model.ShopName));
}
_logger.LogInformation("Shop. ShopName:{ShopName}.Address:{ Address}. Id:{ Id}",
model.Name, model.Address, model.Id);
model.ShopName, model.Address, model.Id);
var element = _shopStorage.GetElement(new ShopSearchModel
{
Name = model.Name,
ShopName = model.ShopName,
});
if(element != null && element.Id != model.Id && element.Name == model.Name)
if(element != null && element.Id != model.Id && element.ShopName == model.ShopName)
{
throw new InvalidOperationException("Такой магазин с таким названием уже есть");
}

View File

@ -6,7 +6,7 @@ namespace SushiBarContracts.BindingModel
public class ShopBindingModel : IShopModel
{
public int Id { get; set; }
public string Name { get; set; }
public string ShopName { get; set; }
public string Address { get; set; }
public DateTime DateOpening { get; set; } = DateTime.Now;
public Dictionary<int, (ISushiModel, int)> ShopSushis { get; set; } = new();

View File

@ -3,6 +3,6 @@
public class ShopSearchModel
{
public int? Id { get; set; }
public string? Name { get; set; }
public string? ShopName { get; set; }
}
}

View File

@ -9,7 +9,7 @@ namespace SushiBarContracts.ViewModels
public int Id { get; set; }
[DisplayName("Название магазина")]
public string Name { get; set; } = string.Empty;
public string ShopName { get; set; } = string.Empty;
[DisplayName("Адрес")]
public string Address { get; set; } = string.Empty;

View File

@ -4,7 +4,7 @@ namespace SushiBarDataModels
{
public interface IShopModel : IId
{
string Name { get; }
string ShopName { get; }
string Address { get; }
DateTime DateOpening { get; }
Dictionary<int, (ISushiModel, int)> ShopSushis{ get; }

View File

@ -10,7 +10,7 @@ namespace SushiBarListImplements.Implements
public class ShopStorage : IShopStorage
{
private DataListSingleton _source;
public ShopStorage(DataListSingleton source)
public ShopStorage()
{
_source = DataListSingleton.GetInstance();
}
@ -28,13 +28,14 @@ namespace SushiBarListImplements.Implements
public List<ShopViewModel> GetFilteredList(ShopSearchModel model)
{
var result = new List<ShopViewModel>();
if (model == null || !model.Id.HasValue)
if (string.IsNullOrEmpty(model.ShopName))
{
return result;
}
foreach (var shop in _source.Shops)
{
if (shop.Id == model.Id)
if (shop.ShopName.Contains(model.ShopName))
{
result.Add(shop.GetViewModel);
}
@ -44,13 +45,14 @@ namespace SushiBarListImplements.Implements
public ShopViewModel? GetElement(ShopSearchModel model)
{
if (!model.Id.HasValue)
if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue)
{
return null;
}
foreach (var shop in _source.Shops)
{
if (shop.Id == model.Id)
if ((!string.IsNullOrEmpty(model.ShopName) && shop.ShopName == model.ShopName) || (model.Id.HasValue && shop.Id == model.Id))
{
return shop.GetViewModel;
}

View File

@ -13,7 +13,7 @@ namespace SushiBarListImplements.Models
public class Shop : IShopModel
{
public int Id { get; private set; }
public string Name { get; private set; }
public string ShopName { get; private set; }
public string Address { get; private set; }
public DateTime DateOpening { get; private set; } = DateTime.Now;
public Dictionary<int, (ISushiModel, int)> ShopSushis
@ -28,7 +28,7 @@ namespace SushiBarListImplements.Models
return new Shop()
{
Id = model.Id,
Name = model.Name,
ShopName = model.ShopName,
Address = model.Address,
DateOpening = model.DateOpening,
ShopSushis = model.ShopSushis
@ -38,7 +38,7 @@ namespace SushiBarListImplements.Models
public void Update(ShopBindingModel? model)
{
if (model == null) return;
Name = model.Name;
ShopName = model.ShopName;
Address = model.Address;
DateOpening = model.DateOpening;
ShopSushis = model.ShopSushis;
@ -47,7 +47,7 @@ namespace SushiBarListImplements.Models
public ShopViewModel GetViewModel => new()
{
Id = Id,
Name = Name,
ShopName = ShopName,
Address = Address,
DateOpening = DateOpening,
ShopSushis = ShopSushis