hard lab2 complete

This commit is contained in:
DavidMakarov 2024-04-19 02:23:50 +04:00
parent 06be024b14
commit 157df090c8
25 changed files with 1582 additions and 875 deletions

View File

@ -97,7 +97,7 @@
Controls.Add(buttonAdd);
Controls.Add(dataGridView);
Name = "FormFlowers";
Text = "FormFlowers";
Text = "Цветы";
Load += FormFlowers_Load;
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
ResumeLayout(false);

View File

@ -18,7 +18,7 @@
<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="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>

View File

@ -33,20 +33,21 @@
ЦветыToolStripMenuItem = new ToolStripMenuItem();
КомпонентыToolStripMenuItem = new ToolStripMenuItem();
магазиныToolStripMenuItem = new ToolStripMenuItem();
продажаЦветовToolStripMenuItem = new ToolStripMenuItem();
dataGridView = new DataGridView();
buttonCreateOrder = new Button();
buttonTakeOrderInWork = new Button();
buttonOrderReady = new Button();
buttonIssuedOrder = new Button();
buttonRef = new Button();
пополнениеМагазинаToolStripMenuItem = new ToolStripMenuItem();
пополениеМагазинаToolStripMenuItem = new ToolStripMenuItem();
menuStrip1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
SuspendLayout();
//
// menuStrip1
//
menuStrip1.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem });
menuStrip1.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, пополениеМагазинаToolStripMenuItem, продажаЦветовToolStripMenuItem });
menuStrip1.Location = new Point(0, 0);
menuStrip1.Name = "menuStrip1";
menuStrip1.Size = new Size(964, 24);
@ -55,7 +56,7 @@
//
// справочникиToolStripMenuItem
//
справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { ЦветыToolStripMenuItem, КомпонентыToolStripMenuItem, магазиныToolStripMenuItem, пополнениеМагазинаToolStripMenuItem });
справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { ЦветыToolStripMenuItem, КомпонентыToolStripMenuItem, магазиныToolStripMenuItem });
справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem";
справочникиToolStripMenuItem.Size = new Size(94, 20);
справочникиToolStripMenuItem.Text = "Справочники";
@ -63,24 +64,31 @@
// ЦветыToolStripMenuItem
//
ЦветыToolStripMenuItem.Name = "ЦветыToolStripMenuItem";
ЦветыToolStripMenuItem.Size = new Size(198, 22);
ЦветыToolStripMenuItem.Size = new Size(180, 22);
ЦветыToolStripMenuItem.Text = "Цветы";
ЦветыToolStripMenuItem.Click += ЦветыToolStripMenuItem_Click;
//
// КомпонентыToolStripMenuItem
//
КомпонентыToolStripMenuItem.Name = "КомпонентыToolStripMenuItem";
КомпонентыToolStripMenuItem.Size = new Size(198, 22);
КомпонентыToolStripMenuItem.Size = new Size(180, 22);
КомпонентыToolStripMenuItem.Text = "Компоненты";
КомпонентыToolStripMenuItem.Click += КомпонентыToolStripMenuItem_Click;
//
// магазиныToolStripMenuItem
//
магазиныToolStripMenuItem.Name = агазиныToolStripMenuItem";
магазиныToolStripMenuItem.Size = new Size(198, 22);
магазиныToolStripMenuItem.Size = new Size(180, 22);
магазиныToolStripMenuItem.Text = "Магазины";
магазиныToolStripMenuItem.Click += магазиныToolStripMenuItem_Click;
//
// продажаЦветовToolStripMenuItem
//
продажаЦветовToolStripMenuItem.Name = "продажаЦветовToolStripMenuItem";
продажаЦветовToolStripMenuItem.Size = new Size(109, 20);
продажаЦветовToolStripMenuItem.Text = "Продажа цветов";
продажаЦветовToolStripMenuItem.Click += продажаЦветовToolStripMenuItem_Click;
//
// dataGridView
//
dataGridView.BackgroundColor = Color.White;
@ -141,12 +149,12 @@
buttonRef.UseVisualStyleBackColor = true;
buttonRef.Click += ButtonRef_Click;
//
// пополнениеМагазинаToolStripMenuItem
// пополениеМагазинаToolStripMenuItem
//
пополнениеМагазинаToolStripMenuItem.Name = "пополнениеМагазинаToolStripMenuItem";
пополнениеМагазинаToolStripMenuItem.Size = new Size(198, 22);
пополнениеМагазинаToolStripMenuItem.Text = "Пополнение магазина";
пополнениеМагазинаToolStripMenuItem.Click += пополнениеМагазинаToolStripMenuItem_Click;
пополениеМагазинаToolStripMenuItem.Name = "пополениеМагазинаToolStripMenuItem";
пополениеМагазинаToolStripMenuItem.Size = new Size(136, 20);
пополениеМагазинаToolStripMenuItem.Text = "Пополение магазина";
пополениеМагазинаToolStripMenuItem.Click += пополениеМагазинаToolStripMenuItem_Click;
//
// FormMain
//
@ -184,6 +192,7 @@
private Button buttonIssuedOrder;
private Button buttonRef;
private ToolStripMenuItem магазиныToolStripMenuItem;
private ToolStripMenuItem пополнениеМагазинаToolStripMenuItem;
private ToolStripMenuItem продажаЦветовToolStripMenuItem;
private ToolStripMenuItem пополениеМагазинаToolStripMenuItem;
}
}

View File

@ -37,38 +37,6 @@ namespace FlowerShopView
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void КомпонентыToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormComponents));
if (service is FormComponents form)
{
form.ShowDialog();
}
}
private void ЦветыToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormFlowers));
if (service is FormFlowers form)
{
form.ShowDialog();
}
}
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(FormMakeSupply));
if (service is FormMakeSupply form)
{
form.ShowDialog();
}
}
private void ButtonCreateOrder_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder));
@ -111,9 +79,7 @@ namespace FlowerShopView
id);
try
{
var operationResult = _orderLogic.FinishOrder(new
OrderBindingModel
{ Id = id });
var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id });
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
@ -131,8 +97,7 @@ namespace FlowerShopView
{
if (dataGridView.SelectedRows.Count == 1)
{
int id =
Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", id);
try
{
@ -156,5 +121,47 @@ namespace FlowerShopView
{
LoadData();
}
private void КомпонентыToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormComponents));
if (service is FormComponents form)
{
form.ShowDialog();
}
}
private void ЦветыToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormFlowers));
if (service is FormFlowers form)
{
form.ShowDialog();
}
}
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(FormMakeSale));
if (service is FormMakeSale form)
{
form.ShowDialog();
}
}
private void пополениеМагазинаToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormMakeSupply));
if (service is FormMakeSupply form)
{
form.ShowDialog();
}
}
}
}

View File

@ -0,0 +1,127 @@
namespace FlowerShopView
{
partial class FormMakeSale
{
/// <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()
{
buttonCancel = new Button();
buttonSale = new Button();
textBoxCount = new TextBox();
labelCount = new Label();
comboBoxFlower = new ComboBox();
labelFlower = new Label();
SuspendLayout();
//
// buttonCancel
//
buttonCancel.Location = new Point(253, 83);
buttonCancel.Margin = new Padding(4, 3, 4, 3);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(88, 27);
buttonCancel.TabIndex = 17;
buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += ButtonCancel_Click;
//
// buttonSale
//
buttonSale.Location = new Point(159, 83);
buttonSale.Margin = new Padding(4, 3, 4, 3);
buttonSale.Name = "buttonSale";
buttonSale.Size = new Size(88, 27);
buttonSale.TabIndex = 16;
buttonSale.Text = "Продать";
buttonSale.UseVisualStyleBackColor = true;
buttonSale.Click += ButtonSale_Click;
//
// textBoxCount
//
textBoxCount.Location = new Point(101, 51);
textBoxCount.Margin = new Padding(4, 3, 4, 3);
textBoxCount.Name = "textBoxCount";
textBoxCount.Size = new Size(252, 23);
textBoxCount.TabIndex = 15;
//
// labelCount
//
labelCount.AutoSize = true;
labelCount.Location = new Point(13, 54);
labelCount.Margin = new Padding(4, 0, 4, 0);
labelCount.Name = "labelCount";
labelCount.Size = new Size(75, 15);
labelCount.TabIndex = 14;
labelCount.Text = "Количество:";
//
// comboBoxFlower
//
comboBoxFlower.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxFlower.FormattingEnabled = true;
comboBoxFlower.Location = new Point(101, 15);
comboBoxFlower.Margin = new Padding(4, 3, 4, 3);
comboBoxFlower.Name = "comboBoxFlower";
comboBoxFlower.Size = new Size(252, 23);
comboBoxFlower.TabIndex = 13;
//
// labelFlower
//
labelFlower.AutoSize = true;
labelFlower.Location = new Point(13, 19);
labelFlower.Margin = new Padding(4, 0, 4, 0);
labelFlower.Name = "labelFlower";
labelFlower.Size = new Size(45, 15);
labelFlower.TabIndex = 12;
labelFlower.Text = "Цветы:";
//
// FormMakeSale
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(373, 123);
Controls.Add(buttonCancel);
Controls.Add(buttonSale);
Controls.Add(textBoxCount);
Controls.Add(labelCount);
Controls.Add(comboBoxFlower);
Controls.Add(labelFlower);
Name = "FormMakeSale";
StartPosition = FormStartPosition.CenterScreen;
Text = "Продажа цветов";
Load += FormMakeSale_Load;
ResumeLayout(false);
PerformLayout();
}
#endregion
private Button buttonCancel;
private Button buttonSale;
private TextBox textBoxCount;
private Label labelCount;
private ComboBox comboBoxFlower;
private Label labelFlower;
}
}

View File

@ -0,0 +1,85 @@
using FlowerShopContracts.BindingModels;
using FlowerShopContracts.BusinessLogicsContracts;
using Microsoft.Extensions.Logging;
namespace FlowerShopView
{
public partial class FormMakeSale : Form
{
private readonly ILogger<FormMakeSale> _logger;
private readonly IFlowerLogic _logicFlower;
private readonly IShopLogic _logicShop;
public FormMakeSale(ILogger<FormMakeSale> logger, IFlowerLogic logicFlower, IShopLogic logicShop)
{
InitializeComponent();
_logger = logger;
_logicFlower = logicFlower;
_logicShop = logicShop;
}
private void FormMakeSale_Load(object sender, EventArgs e)
{
_logger.LogInformation("Flowers loading");
try
{
var list = _logicFlower.ReadList(null);
if (list != null)
{
comboBoxFlower.DisplayMember = "FlowerName";
comboBoxFlower.ValueMember = "Id";
comboBoxFlower.DataSource = list;
comboBoxFlower.SelectedItem = null;
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Flowers loading error");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonSale_Click(object sender, EventArgs e)
{
if (comboBoxFlower.SelectedValue == null)
{
MessageBox.Show("Выберите цветы", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (string.IsNullOrEmpty(textBoxCount.Text))
{
MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Flowers sale");
try
{
var operationResult = _logicShop.MakeSale(
new FlowerBindingModel
{
Id = Convert.ToInt32(comboBoxFlower.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, "Flowers sale error");
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

@ -91,14 +91,13 @@ namespace FlowerShopView
{ Id = Convert.ToInt32(comboBoxFlower.SelectedValue) });
if (iceCream == null)
{
throw new Exception("Мороженое не найдено.");
throw new Exception("Цветок не найден.");
}
var operationResult = _logicShop.MakeSupply(new ShopSearchModel
{
Id = Convert.ToInt32(comboBoxShop.SelectedValue)
},
iceCream,
Convert.ToInt32(textBoxCount.Text));
iceCream, Convert.ToInt32(textBoxCount.Text));
if (!operationResult)
{
throw new Exception("Ошибка при проведении поставки.");

View File

@ -41,6 +41,8 @@
ColumnCount = new DataGridViewTextBoxColumn();
buttonSave = new Button();
buttonCancel = new Button();
textBoxMaximum = new TextBox();
label1 = new Label();
groupBoxFlowers.SuspendLayout();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
SuspendLayout();
@ -57,7 +59,7 @@
//
// textBoxName
//
textBoxName.Location = new Point(92, 7);
textBoxName.Location = new Point(175, 7);
textBoxName.Margin = new Padding(4, 3, 4, 3);
textBoxName.Name = "textBoxName";
textBoxName.Size = new Size(252, 23);
@ -75,7 +77,7 @@
//
// textBoxAddress
//
textBoxAddress.Location = new Point(92, 37);
textBoxAddress.Location = new Point(175, 37);
textBoxAddress.Margin = new Padding(4, 3, 4, 3);
textBoxAddress.Name = "textBoxAddress";
textBoxAddress.Size = new Size(252, 23);
@ -83,7 +85,7 @@
//
// dateTimePicker
//
dateTimePicker.Location = new Point(126, 66);
dateTimePicker.Location = new Point(209, 98);
dateTimePicker.Name = "dateTimePicker";
dateTimePicker.Size = new Size(218, 23);
dateTimePicker.TabIndex = 5;
@ -91,7 +93,7 @@
// labelOpeningDate
//
labelOpeningDate.AutoSize = true;
labelOpeningDate.Location = new Point(14, 69);
labelOpeningDate.Location = new Point(14, 104);
labelOpeningDate.Margin = new Padding(4, 0, 4, 0);
labelOpeningDate.Name = "labelOpeningDate";
labelOpeningDate.Size = new Size(90, 15);
@ -101,7 +103,7 @@
// groupBoxFlowers
//
groupBoxFlowers.Controls.Add(dataGridView);
groupBoxFlowers.Location = new Point(4, 100);
groupBoxFlowers.Location = new Point(4, 135);
groupBoxFlowers.Margin = new Padding(4, 3, 4, 3);
groupBoxFlowers.Name = "groupBoxFlowers";
groupBoxFlowers.Padding = new Padding(4, 3, 4, 3);
@ -150,7 +152,7 @@
//
// buttonSave
//
buttonSave.Location = new Point(255, 394);
buttonSave.Location = new Point(255, 429);
buttonSave.Margin = new Padding(4, 3, 4, 3);
buttonSave.Name = "buttonSave";
buttonSave.Size = new Size(88, 27);
@ -161,7 +163,7 @@
//
// buttonCancel
//
buttonCancel.Location = new Point(359, 394);
buttonCancel.Location = new Point(359, 429);
buttonCancel.Margin = new Padding(4, 3, 4, 3);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(88, 27);
@ -170,11 +172,30 @@
buttonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += ButtonCancel_Click;
//
// textBoxMaximum
//
textBoxMaximum.Location = new Point(175, 68);
textBoxMaximum.Margin = new Padding(4, 3, 4, 3);
textBoxMaximum.Name = "textBoxMaximum";
textBoxMaximum.Size = new Size(252, 23);
textBoxMaximum.TabIndex = 11;
//
// label1
//
label1.Location = new Point(14, 68);
label1.Margin = new Padding(4, 0, 4, 0);
label1.Name = "label1";
label1.Size = new Size(153, 33);
label1.TabIndex = 10;
label1.Text = "Максимальное количество цветков:";
//
// FormShop
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(478, 432);
ClientSize = new Size(478, 465);
Controls.Add(textBoxMaximum);
Controls.Add(label1);
Controls.Add(buttonCancel);
Controls.Add(buttonSave);
Controls.Add(groupBoxFlowers);
@ -209,5 +230,7 @@
private DataGridViewTextBoxColumn ColumnCount;
private Button buttonSave;
private Button buttonCancel;
private TextBox textBoxMaximum;
private Label label1;
}
}

View File

@ -39,7 +39,7 @@ namespace FlowerShopView
textBoxName.Text = view.ShopName;
textBoxAddress.Text = view.Address;
dateTimePicker.Value = view.DateOpening;
_shopFlowers = view.Flowers ?? new Dictionary<int, (IFlowerModel, int)>();
_shopFlowers = view.ShopFlowers ?? new Dictionary<int, (IFlowerModel, int)>();
LoadData();
}
}
@ -98,7 +98,8 @@ namespace FlowerShopView
ShopName = textBoxName.Text,
Address = textBoxAddress.Text,
DateOpening = dateTimePicker.Value,
Flowers = _shopFlowers
ShopFlowers = _shopFlowers,
MaximumFlowers = Convert.ToInt32(textBoxMaximum.Text),
};
var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model);
if (!operationResult)

View File

@ -32,7 +32,7 @@ namespace FlowerShopView
dataGridView.DataSource = list;
dataGridView.Columns["Id"].Visible = false;
dataGridView.Columns["ShopName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
dataGridView.Columns["Flowers"].Visible = false;
dataGridView.Columns["ShopFlowers"].Visible = false;
}
_logger.LogInformation("Shops loading");
}

View File

@ -36,10 +36,12 @@ namespace FlowerShopView
services.AddTransient<IComponentStorage, ComponentStorage>();
services.AddTransient<IOrderStorage, OrderStorage>();
services.AddTransient<IFlowerStorage, FlowerStorage>();
services.AddTransient<IShopStorage, ShopStorage>();
services.AddTransient<IComponentLogic, ComponentLogic>();
services.AddTransient<IOrderLogic, OrderLogic>();
services.AddTransient<IFlowerLogic, FlowerLogic>();
services.AddTransient<IShopLogic, ShopLogic>();
services.AddTransient<FormMain>();
services.AddTransient<FormComponent>();
@ -48,6 +50,10 @@ namespace FlowerShopView
services.AddTransient<FormFlower>();
services.AddTransient<FormFlowerComponent>();
services.AddTransient<FormFlowers>();
services.AddTransient<FormShop>();
services.AddTransient<FormShops>();
services.AddTransient<FormMakeSupply>();
services.AddTransient<FormMakeSale>();
}
}
}

View File

@ -4,6 +4,7 @@ using FlowerShopContracts.SearchModels;
using FlowerShopContracts.StoragesContracts;
using FlowerShopContracts.ViewModels;
using FlowerShopDataModels.Enums;
using FlowerShopDataModels.Models;
using Microsoft.Extensions.Logging;
namespace FlowerShopBusinessLogic.BusinessLogics
@ -12,10 +13,16 @@ namespace FlowerShopBusinessLogic.BusinessLogics
{
private readonly ILogger _logger;
private readonly IOrderStorage _orderStorage;
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage)
private readonly IFlowerStorage _flowerStorage;
private readonly IShopStorage _shopStorage;
private readonly IShopLogic _shopLogic;
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage, IFlowerStorage flowerStorage, IShopStorage shopStorage, IShopLogic shopLogic)
{
_logger = logger;
_orderStorage = orderStorage;
_flowerStorage = flowerStorage;
_shopStorage = shopStorage;
_shopLogic = shopLogic;
}
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
{
@ -80,17 +87,32 @@ namespace FlowerShopBusinessLogic.BusinessLogics
_logger.LogWarning("Status update to " + orderStatus + " operation failed");
return false;
}
if (orderStatus == OrderStatus.Выдан)
{
var flower = _flowerStorage.GetElement(new FlowerSearchModel() { Id = model.FlowerId } );
if (flower == null)
{
return false;
}
if (!SupplyFlowers(flower, model.Count))
{
_logger.LogWarning("Change status operation failed. Flowers delivery operation failed");
return false;
}
}
model.Status = orderStatus;
if (model.Status == OrderStatus.Выдан)
if (model.Status == OrderStatus.Готов)
{
model.DateImplement = DateTime.Now;
}
else
{
model.DateImplement = element.DateImplement;
}
if (_orderStorage.Update(model) == null)
{
model.Status--;
_logger.LogWarning("Changing status operation faled");
_logger.LogWarning("Changing status operation failed");
return false;
}
return true;
@ -119,5 +141,62 @@ namespace FlowerShopBusinessLogic.BusinessLogics
}
_logger.LogInformation("Order. FlowerId:{EngineId}.Count:{Count}.Sum:{Sum}Id:{Id}", model.FlowerId, model.Count, model.Sum, model.Id);
}
private bool SupplyFlowers(IFlowerModel flower, int count)
{
if (count < 0)
{
_logger.LogWarning("Flower supply operation failed. Count <= 0");
return false;
}
var shopList = _shopStorage.GetFullList();
var shopsCapacity = shopList.Sum(x => x.MaximumFlowers);
int currentFlowers = shopList.Select(x => x.ShopFlowers.Sum(y => y.Value.Item2)).Sum();
int freeSpace = shopsCapacity - currentFlowers;
if (freeSpace < count)
{
_logger.LogWarning("Flower supply operation failed. No free space for new flowers");
return false;
}
foreach (var shop in shopList)
{
freeSpace = shop.MaximumFlowers - shop.ShopFlowers.Sum(x => x.Value.Item2);
if (freeSpace == 0)
{
continue;
}
if (freeSpace >= count)
{
if (_shopLogic.MakeSupply(new ShopSearchModel() { Id = shop.Id }, flower, count))
{
count = 0;
}
else
{
_logger.LogWarning("Flowers delivery operation failed");
return false;
}
}
else
{
if (_shopLogic.MakeSupply(new ShopSearchModel() { Id = shop.Id }, flower, freeSpace))
{
count -= freeSpace;
}
else
{
_logger.LogWarning("Flowers delivery operation failed");
return false;
}
}
if (count == 0)
{
return true;
}
}
return false;
}
}
}

View File

@ -100,16 +100,16 @@ namespace FlowerShopBusinessLogic.BusinessLogics
_logger.LogWarning("MakeSupply(GetElement). Element not found");
return false;
}
if (shop.Flowers.ContainsKey(flower.Id))
if (shop.ShopFlowers.ContainsKey(flower.Id))
{
var shopFlower = shop.Flowers[flower.Id];
var shopFlower = shop.ShopFlowers[flower.Id];
shopFlower.Item2 += count;
shop.Flowers[flower.Id] = shopFlower;
shop.ShopFlowers[flower.Id] = shopFlower;
_logger.LogInformation("MakeSupply. Added {count} '{flower}' to '{ShopName}' shop", count, flower.FlowerName, shop.ShopName);
}
else
{
shop.Flowers.Add(flower.Id, (flower, count));
shop.ShopFlowers.Add(flower.Id, (flower, count));
_logger.LogInformation("MakeSupply. Added {count} new '{flower}' to '{ShopName}' shop", count, flower.FlowerName, shop.ShopName);
}
if (_shopStorage.Update(new ShopBindingModel()
@ -118,7 +118,8 @@ namespace FlowerShopBusinessLogic.BusinessLogics
ShopName = shop.ShopName,
Address = shop.Address,
DateOpening = shop.DateOpening,
Flowers = shop.Flowers,
ShopFlowers = shop.ShopFlowers,
MaximumFlowers = shop.MaximumFlowers,
}) == null)
{
_logger.LogWarning("MakeSupply. Update operation failed");
@ -154,5 +155,10 @@ namespace FlowerShopBusinessLogic.BusinessLogics
throw new InvalidOperationException("Магазин с таким названием уже есть");
}
}
public bool MakeSale(IFlowerModel model, int count)
{
return _shopStorage.MakeSale(model, count);
}
}
}

View File

@ -8,10 +8,12 @@ namespace FlowerShopContracts.BindingModels
public string ShopName { get; set; } = string.Empty;
public string Address { get; set; } = string.Empty;
public DateTime DateOpening { get; set; } = DateTime.Now;
public Dictionary<int, (IFlowerModel, int)> Flowers
public Dictionary<int, (IFlowerModel, int)> ShopFlowers
{
get;
set;
} = new();
public int MaximumFlowers { get; set; }
}
}

View File

@ -13,5 +13,6 @@ namespace FlowerShopContracts.BusinessLogicsContracts
bool Update(ShopBindingModel model);
bool Delete(ShopBindingModel model);
bool MakeSupply(ShopSearchModel shopModel, IFlowerModel flower, int count);
bool MakeSale(IFlowerModel model, int count);
}
}

View File

@ -1,6 +1,7 @@
using FlowerShopContracts.BindingModels;
using FlowerShopContracts.SearchModels;
using FlowerShopContracts.ViewModels;
using FlowerShopDataModels.Models;
namespace FlowerShopContracts.StoragesContracts
{
@ -12,5 +13,6 @@ namespace FlowerShopContracts.StoragesContracts
ShopViewModel? Insert(ShopBindingModel model);
ShopViewModel? Update(ShopBindingModel model);
ShopViewModel? Delete(ShopBindingModel model);
bool MakeSale(IFlowerModel model, int count);
}
}

View File

@ -12,10 +12,12 @@ namespace FlowerShopContracts.ViewModels
public string Address { get; set; } = string.Empty;
[DisplayName("Дата открытия")]
public DateTime DateOpening { get; set; } = DateTime.Now;
public Dictionary<int, (IFlowerModel, int)> Flowers
public Dictionary<int, (IFlowerModel, int)> ShopFlowers
{
get;
set;
} = new();
[DisplayName("Максимальное количество цветков")]
public int MaximumFlowers { get; set; }
}
}

View File

@ -4,7 +4,8 @@
{
string ShopName { get; }
string Address { get; }
Dictionary<int, (IFlowerModel, int)> Flowers { get; }
Dictionary<int, (IFlowerModel, int)> ShopFlowers { get; }
DateTime DateOpening { get; }
int MaximumFlowers { get; }
}
}

View File

@ -9,9 +9,11 @@ namespace FlowerShopFileImplement
private readonly string ComponentFileName = "Component.xml";
private readonly string OrderFileName = "Order.xml";
private readonly string FlowerFileName = "Flower.xml";
private readonly string ShopFileName = "Shop.xml";
public List<Component> Components { get; private set; }
public List<Order> Orders { get; private set; }
public List<Flower> Flowers { get; private set; }
public List<Shop> Shops { get; private set; }
public static DataFileSingleton GetInstance()
{
if (instance == null)
@ -23,11 +25,13 @@ namespace FlowerShopFileImplement
public void SaveComponents() => SaveData(Components, ComponentFileName, "Components", x => x.GetXElement);
public void SaveFlowers() => SaveData(Flowers, FlowerFileName, "Flowers", x => x.GetXElement);
public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement);
public void SaveShops() => SaveData(Shops, ShopFileName, "Shops", x => x.GetXElement);
private DataFileSingleton()
{
Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!;
Flowers = LoadData(FlowerFileName, "Flower", x => Flower.Create(x)!)!;
Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!;
Shops = LoadData(ShopFileName, "Shop", x => Shop.Create(x)!)!;
}
private static List<T>? LoadData<T>(string filename, string xmlNodeName, Func<XElement, T> selectFunction)
{

View File

@ -0,0 +1,134 @@

using FlowerShopContracts.BindingModels;
using FlowerShopContracts.SearchModels;
using FlowerShopContracts.StoragesContracts;
using FlowerShopContracts.ViewModels;
using FlowerShopDataModels.Models;
using FlowerShopFileImplement.Models;
namespace FlowerShopFileImplement.Implements
{
public class ShopStorage : IShopStorage
{
private readonly DataFileSingleton source;
public ShopStorage()
{
source = DataFileSingleton.GetInstance();
}
public List<ShopViewModel> GetFullList()
{
return source.Shops
.Select(x => x.GetViewModel)
.ToList();
}
public List<ShopViewModel> GetFilteredList(ShopSearchModel model)
{
if (string.IsNullOrEmpty(model.ShopName))
{
return new();
}
return source.Shops
.Where(x => x.ShopName.Contains(model.ShopName))
.Select(x => x.GetViewModel)
.ToList();
}
public ShopViewModel? GetElement(ShopSearchModel model)
{
if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue)
{
return null;
}
return source.Shops
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.ShopName) && x.ShopName == model.ShopName) ||
(model.Id.HasValue && x.Id == model.Id))
?.GetViewModel;
}
public ShopViewModel? Insert(ShopBindingModel model)
{
model.Id = source.Shops.Count > 0 ? source.Shops.Max(x => x.Id) + 1 : 1;
var newShop = Shop.Create(model);
if (newShop == null)
{
return null;
}
source.Shops.Add(newShop);
source.SaveShops();
return newShop.GetViewModel;
}
public ShopViewModel? Update(ShopBindingModel model)
{
var shop = source.Shops.FirstOrDefault(x => x.Id == model.Id);
if (shop == null)
{
return null;
}
shop.Update(model);
source.SaveShops();
return shop.GetViewModel;
}
public ShopViewModel? Delete(ShopBindingModel model)
{
var element = source.Shops.FirstOrDefault(x => x.Id == model.Id);
if (element != null)
{
source.Shops.Remove(element);
source.SaveShops();
return element.GetViewModel;
}
return null;
}
public bool MakeSale(IFlowerModel model, int count)
{
// TODO: разобраться
var flower = source.Flowers.FirstOrDefault(x => x.Id == model.Id);
int countInShops = source.Shops.SelectMany(x => x.ShopFlowers).Sum(y => y.Key == model.Id ? y.Value.Item2 : 0);
if (flower == null || countInShops < count)
{
return false;
}
foreach (var shop in source.Shops)
{
var shopFlowers = shop.ShopFlowers.Where(x => x.Key == model.Id);
if (shopFlowers.Any())
{
var shopFlower = shopFlowers.First();
int min = Math.Min(shopFlower.Value.Item2, count);
if (min == shopFlower.Value.Item2)
{
shop.ShopFlowers.Remove(shopFlower.Key);
}
else
{
shop.ShopFlowers[shopFlower.Key] = (shopFlower.Value.Item1, shopFlower.Value.Item2 - min);
}
shop.Update(new ShopBindingModel
{
Id = shop.Id,
ShopName = shop.ShopName,
Address = shop.Address,
DateOpening = shop.DateOpening,
ShopFlowers = shop.ShopFlowers,
MaximumFlowers = shop.MaximumFlowers
});
count -= min;
if (count <= 0)
{
break;
}
}
}
source.SaveShops();
return true;
}
}
}

View File

@ -0,0 +1,88 @@
using FlowerShopContracts.BindingModels;
using FlowerShopContracts.ViewModels;
using FlowerShopDataModels.Models;
using System.Xml.Linq;
namespace FlowerShopFileImplement.Models
{
public class Shop : IShopModel
{
public int Id { get; private set; }
public string ShopName { get; private set; } = string.Empty;
public string Address { get; private set; } = string.Empty;
public DateTime DateOpening { get; private set; }
public Dictionary<int, int> Flowers { get; private set; } = new();
private Dictionary<int, (IFlowerModel, int)> _shopFlowers = null;
public Dictionary<int, (IFlowerModel, int)> ShopFlowers
{
get
{
if (_shopFlowers == null)
{
var source = DataFileSingleton.GetInstance();
_shopFlowers = Flowers.ToDictionary(x => x.Key,
y => ((source.Flowers.FirstOrDefault(z => z.Id == y.Key) as IFlowerModel)!, y.Value));
}
return _shopFlowers;
}
}
public int MaximumFlowers { get; private set; }
public static Shop? Create(ShopBindingModel model)
{
if (model == null) return null;
return new Shop()
{
Id = model.Id,
ShopName = model.ShopName,
Address = model.Address,
DateOpening = model.DateOpening,
Flowers = model.ShopFlowers.ToDictionary(x => x.Key, x => x.Value.Item2),
MaximumFlowers = model.MaximumFlowers,
};
}
public static Shop? Create(XElement element)
{
if (element == null) return null;
return new Shop()
{
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
ShopName = element.Element("ShopName")!.Value,
Address = element.Element("Address")!.Value,
DateOpening = Convert.ToDateTime(element.Element("DateOpening")!.Value),
MaximumFlowers = Convert.ToInt32(element.Element("MaximumFlowers")!.Value),
Flowers = element.Element("ShopFlowers")!.Elements("ShopFlower")
.ToDictionary(x => Convert.ToInt32(x.Element("Key")?.Value), x => Convert.ToInt32(x.Element("Value")?.Value))
};
}
public void Update(ShopBindingModel? model)
{
if (model == null) return;
ShopName = model.ShopName;
Address = model.Address;
DateOpening = model.DateOpening;
MaximumFlowers = model.MaximumFlowers;
Flowers = model.ShopFlowers.ToDictionary(x => x.Key, x => x.Value.Item2);
_shopFlowers = null;
}
public ShopViewModel GetViewModel => new()
{
Id = Id,
ShopName = ShopName,
Address = Address,
DateOpening = DateOpening,
MaximumFlowers = MaximumFlowers,
ShopFlowers = ShopFlowers,
};
public XElement GetXElement => new("Shop",
new XAttribute("Id", Id),
new XElement("ShopName", ShopName),
new XElement("Address", Address),
new XElement("DateOpening", DateOpening.ToString()),
new XElement("MaximumFlowers", MaximumFlowers.ToString()),
new XElement("ShopFlowers",
Flowers.Select(x => new XElement("ShopFlower",
new XElement("Key", x.Key),
new XElement("Value", x.Value))).ToArray()));
}
}

View File

@ -2,6 +2,7 @@
using FlowerShopContracts.SearchModels;
using FlowerShopContracts.StoragesContracts;
using FlowerShopContracts.ViewModels;
using FlowerShopDataModels.Models;
using FlowerShopListImplement.Models;
namespace FlowerShopListImplement.Implements
@ -105,5 +106,9 @@ namespace FlowerShopListImplement.Implements
}
return null;
}
public bool MakeSale(IFlowerModel model, int count)
{
throw new NotImplementedException();
}
}
}

View File

@ -10,7 +10,8 @@ namespace FlowerShopListImplement.Models
public string ShopName { get; private set; } = string.Empty;
public string Address { get; private set; } = string.Empty;
public DateTime DateOpening { get; private set; }
public Dictionary<int, (IFlowerModel, int)> Flowers { get; private set; } = new();
public Dictionary<int, (IFlowerModel, int)> ShopFlowers { get; private set; } = new();
public int MaximumFlowers { get; private set; }
public static Shop? Create(ShopBindingModel? model)
{
@ -23,7 +24,9 @@ namespace FlowerShopListImplement.Models
Id = model.Id,
ShopName = model.ShopName,
Address = model.Address,
DateOpening = model.DateOpening
DateOpening = model.DateOpening,
ShopFlowers = model.ShopFlowers,
MaximumFlowers = model.MaximumFlowers,
};
}
@ -36,6 +39,8 @@ namespace FlowerShopListImplement.Models
ShopName = model.ShopName;
Address = model.Address;
DateOpening = model.DateOpening;
ShopFlowers = model.ShopFlowers;
MaximumFlowers = model.MaximumFlowers;
}
public ShopViewModel GetViewModel => new()
@ -44,7 +49,8 @@ namespace FlowerShopListImplement.Models
ShopName = ShopName,
Address = Address,
DateOpening = DateOpening,
Flowers = Flowers
ShopFlowers = ShopFlowers,
MaximumFlowers = MaximumFlowers,
};
}
}