In process

This commit is contained in:
goblinrf 2024-04-14 22:07:50 +04:00
parent 00033ec12b
commit 97b1187f1b
19 changed files with 878 additions and 33 deletions

View File

@ -3,6 +3,7 @@ using DinerContracts.BusinessLogicsContracts;
using DinerContracts.SearchModels; using DinerContracts.SearchModels;
using DinerContracts.StoragesContracts; using DinerContracts.StoragesContracts;
using DinerContracts.ViewModels; using DinerContracts.ViewModels;
using DinerShopDataModels.Models;
using DinerDataModels.Enum; using DinerDataModels.Enum;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
@ -12,10 +13,18 @@ namespace DinerBusinessLogic.BusinessLogics
{ {
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly IOrderStorage _orderStorage; private readonly IOrderStorage _orderStorage;
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage) private readonly IShopStorage _shopStorage;
private readonly IShopLogic _shopLogic;
private readonly IShopStorage _shopStorage;
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage, IShopStorage shopStorage)
{ {
_logger = logger;
_orderStorage = orderStorage; _orderStorage = orderStorage;
_logger = logger;
_shopStorage = shopStorage;
} }
public List<OrderViewModel>? ReadList(OrderSearchModel? model) public List<OrderViewModel>? ReadList(OrderSearchModel? model)
{ {
@ -29,6 +38,7 @@ namespace DinerBusinessLogic.BusinessLogics
_logger.LogInformation("ReadList. Count:{Count}", list.Count); _logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list; return list;
} }
public bool CreateOrder(OrderBindingModel model) public bool CreateOrder(OrderBindingModel model)
{ {
CheckModel(model); CheckModel(model);
@ -41,6 +51,64 @@ namespace DinerBusinessLogic.BusinessLogics
} }
return true; return true;
} }
public bool CheckSupply(IDinerModel snack, int count)
{
if (count <= 0)
{
_logger.LogWarning("Check then supply operation error. IceCream count < 0.");
return false;
}
int sumCapacity = 0;
int sumCount = 0;
sumCapacity = _shopStorage.GetFullList().Select(x => x.MaxCapacity).Sum();
sumCount = _shopStorage.GetFullList().Select(x => x.ShopIceCreams.Select(y => y.Value.Item2).Sum()).Sum();
int freeSpace = sumCapacity - sumCount;
if (freeSpace - count < 0)
{
_logger.LogWarning("Check then supply operation error. There's no place for new IceCream in shops.");
return false;
}
foreach (var shop in _shopStorage.GetFullList())
{
freeSpace = shop.MaxCapacity;
foreach (var doc in shop.ShopIceCreams)
{
freeSpace -= doc.Value.Item2;
}
if (freeSpace == 0)
{
continue;
}
if (freeSpace - count >= 0)
{
if (_shopLogic.MakeSupply(new() { Id = shop.Id }, iceCream, count))
count = 0;
else
{
_logger.LogWarning("Supply error");
return false;
}
}
if (freeSpace - count < 0)
{
if (_shopLogic.MakeSupply(new() { Id = shop.Id }, iceCream, freeSpace))
count -= freeSpace;
else
{
_logger.LogWarning("Supply error");
return false;
}
}
if (count <= 0)
{
return true;
}
}
return false;
}
public bool TakeOrderInWork(OrderBindingModel model) public bool TakeOrderInWork(OrderBindingModel model)
{ {
return ChangeStatus(model, OrderStatus.Выполняется); return ChangeStatus(model, OrderStatus.Выполняется);
@ -53,6 +121,27 @@ namespace DinerBusinessLogic.BusinessLogics
{ {
return ChangeStatus(model, OrderStatus.Выдан); return ChangeStatus(model, OrderStatus.Выдан);
} }
public bool DeliveryOrder(OrderBindingModel model)
{
var order = _orderStorage.GetElement(new OrderSearchModel
{
Id = model.Id,
});
if (order == null)
{
throw new ArgumentNullException(nameof(order));
}
if (!_shopStorage.RestockingShops(new SupplyBindingModel
{
SnackId = order.SnackId,
Count = order.Count
}))
{
throw new ArgumentException("Недостаточно места");
}
return ChangeStatus(model, OrderStatus.Выдан);
}
private void CheckModel(OrderBindingModel model, bool withParams = true) private void CheckModel(OrderBindingModel model, bool withParams = true)
{ {
if (model == null) if (model == null)

View File

@ -157,5 +157,20 @@ namespace DinerBusinessLogic.BusinessLogics
throw new InvalidOperationException("Магазин с таким названием уже есть"); throw new InvalidOperationException("Магазин с таким названием уже есть");
} }
} }
public bool Sale(SupplySearchModel model)
{
if (!model.PizzaId.HasValue || !model.Count.HasValue)
{
return false;
}
_logger.LogInformation("Check pizza count in all shops");
if (_shopStorage.Sale(model))
{
_logger.LogInformation("Selling sucsess");
return true;
}
_logger.LogInformation("Selling failed");
return false;
}
} }
} }

View File

@ -14,5 +14,6 @@ namespace DinerContracts.BindingModels
public string Adress { get; set; } = string.Empty; public string Adress { get; set; } = string.Empty;
public DateTime OpeningDate { get; set; } = DateTime.Now; public DateTime OpeningDate { get; set; } = DateTime.Now;
public Dictionary<int, (ISnackModel, int)> ShopSnacks { get; set; } = new(); public Dictionary<int, (ISnackModel, int)> ShopSnacks { get; set; } = new();
public int SnackMaxCount { get; set; }
} }
} }

View File

@ -17,5 +17,6 @@ namespace DinerContracts.BusinessLogicsContracts
bool Update(ShopBindingModel model); bool Update(ShopBindingModel model);
bool Delete(ShopBindingModel model); bool Delete(ShopBindingModel model);
bool MakeSupply(SupplyBindingModel model); bool MakeSupply(SupplyBindingModel model);
bool Sale(SupplySearchModel model);
} }
} }

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DinerContracts.SearchModels
{
public class SupplySearchModel
{
public int? SnackId { get; set; }
public int? Count { get; set; }
}
}

View File

@ -17,5 +17,7 @@ namespace DinerContracts.StoragesContracts
ShopViewModel? Insert(ShopBindingModel model); ShopViewModel? Insert(ShopBindingModel model);
ShopViewModel? Update(ShopBindingModel model); ShopViewModel? Update(ShopBindingModel model);
ShopViewModel? Delete(ShopBindingModel model); ShopViewModel? Delete(ShopBindingModel model);
bool Sale(SupplySearchModel model);
bool RestockingShops(SupplyBindingModel model);
} }
} }

View File

@ -18,5 +18,7 @@ namespace DinerContracts.ViewModels
[DisplayName("Дата открытия")] [DisplayName("Дата открытия")]
public DateTime OpeningDate { get; set; } public DateTime OpeningDate { get; set; }
public Dictionary<int, (ISnackModel, int)> ShopSnacks { get; set; } = new(); public Dictionary<int, (ISnackModel, int)> ShopSnacks { get; set; } = new();
[DisplayName("Вместимость")]
public int SnackMaxCount { get; set; }
} }
} }

View File

@ -14,5 +14,6 @@ namespace DinerDataModels.Models
string Adress { get; } string Adress { get; }
DateTime OpeningDate { get; } DateTime OpeningDate { get; }
Dictionary<int, (ISnackModel, int)> ShopSnacks { get; } Dictionary<int, (ISnackModel, int)> ShopSnacks { get; }
public int SnackMaxCount { get; }
} }
} }

View File

@ -38,9 +38,10 @@
toolStripLabel1 = new ToolStripDropDownButton(); toolStripLabel1 = new ToolStripDropDownButton();
componentsToolStripMenuItem = new ToolStripMenuItem(); componentsToolStripMenuItem = new ToolStripMenuItem();
snacksToolStripMenuItem = new ToolStripMenuItem(); snacksToolStripMenuItem = new ToolStripMenuItem();
магазиныToolStripMenuItem = new ToolStripMenuItem();
toolStripDropDownButton1 = new ToolStripDropDownButton(); toolStripDropDownButton1 = new ToolStripDropDownButton();
поставкаToolStripMenuItem = new ToolStripMenuItem(); поставкаToolStripMenuItem = new ToolStripMenuItem();
магазиныToolStripMenuItem = new ToolStripMenuItem(); продажаToolStripMenuItem = new ToolStripMenuItem();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
toolStrip1.SuspendLayout(); toolStrip1.SuspendLayout();
SuspendLayout(); SuspendLayout();
@ -126,21 +127,28 @@
// componentsToolStripMenuItem // componentsToolStripMenuItem
// //
componentsToolStripMenuItem.Name = "componentsToolStripMenuItem"; componentsToolStripMenuItem.Name = "componentsToolStripMenuItem";
componentsToolStripMenuItem.Size = new Size(224, 26); componentsToolStripMenuItem.Size = new Size(182, 26);
componentsToolStripMenuItem.Text = "Компоненты"; componentsToolStripMenuItem.Text = "Компоненты";
componentsToolStripMenuItem.Click += ComponentToolStripMenuItem_Click; componentsToolStripMenuItem.Click += ComponentToolStripMenuItem_Click;
// //
// snacksToolStripMenuItem // snacksToolStripMenuItem
// //
snacksToolStripMenuItem.Name = "snacksToolStripMenuItem"; snacksToolStripMenuItem.Name = "snacksToolStripMenuItem";
snacksToolStripMenuItem.Size = new Size(224, 26); snacksToolStripMenuItem.Size = new Size(182, 26);
snacksToolStripMenuItem.Text = "Закуски"; snacksToolStripMenuItem.Text = "Закуски";
snacksToolStripMenuItem.Click += ProductToolStripMenuItem_Click; snacksToolStripMenuItem.Click += ProductToolStripMenuItem_Click;
// //
// магазиныToolStripMenuItem
//
магазиныToolStripMenuItem.Name = агазиныToolStripMenuItem";
магазиныToolStripMenuItem.Size = new Size(182, 26);
магазиныToolStripMenuItem.Text = "Магазины";
магазиныToolStripMenuItem.Click += shopsToolStripMenuItem_Click;
//
// toolStripDropDownButton1 // toolStripDropDownButton1
// //
toolStripDropDownButton1.DisplayStyle = ToolStripItemDisplayStyle.Text; toolStripDropDownButton1.DisplayStyle = ToolStripItemDisplayStyle.Text;
toolStripDropDownButton1.DropDownItems.AddRange(new ToolStripItem[] { поставкаToolStripMenuItem }); toolStripDropDownButton1.DropDownItems.AddRange(new ToolStripItem[] { поставкаToolStripMenuItem, продажаToolStripMenuItem });
toolStripDropDownButton1.ImageTransparentColor = Color.Magenta; toolStripDropDownButton1.ImageTransparentColor = Color.Magenta;
toolStripDropDownButton1.Name = "toolStripDropDownButton1"; toolStripDropDownButton1.Name = "toolStripDropDownButton1";
toolStripDropDownButton1.Size = new Size(95, 24); toolStripDropDownButton1.Size = new Size(95, 24);
@ -153,12 +161,12 @@
поставкаToolStripMenuItem.Text = "Поставка"; поставкаToolStripMenuItem.Text = "Поставка";
поставкаToolStripMenuItem.Click += transactionToolStripMenuItem_Click; поставкаToolStripMenuItem.Click += transactionToolStripMenuItem_Click;
// //
// магазиныToolStripMenuItem // продажаToolStripMenuItem
// //
магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem"; продажаToolStripMenuItem.Name = "продажаToolStripMenuItem";
магазиныToolStripMenuItem.Size = new Size(224, 26); продажаToolStripMenuItem.Size = new Size(224, 26);
магазиныToolStripMenuItem.Text = "Магазины"; продажаToolStripMenuItem.Text = "Продажа";
магазиныToolStripMenuItem.Click += shopsToolStripMenuItem_Click; продажаToolStripMenuItem.Click += SellToolStripMenuItem_Click;
// //
// FormMain // FormMain
// //
@ -197,5 +205,6 @@
private ToolStripMenuItem магазиныToolStripMenuItem; private ToolStripMenuItem магазиныToolStripMenuItem;
private ToolStripDropDownButton toolStripDropDownButton1; private ToolStripDropDownButton toolStripDropDownButton1;
private ToolStripMenuItem поставкаToolStripMenuItem; private ToolStripMenuItem поставкаToolStripMenuItem;
private ToolStripMenuItem продажаToolStripMenuItem;
} }
} }

View File

@ -180,5 +180,13 @@ namespace Diner
form.ShowDialog(); form.ShowDialog();
} }
} }
private void SellToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormSellPizza));
if (service is FormSellSnack form)
{
form.ShowDialog();
}
}
} }
} }

117
Diner/Diner/FormSell.Designer.cs generated Normal file
View File

@ -0,0 +1,117 @@
namespace IceCreamShop
{
partial class SellForm
{
/// <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()
{
IceCreamComboBox = new ComboBox();
IceCreamLabel = new Label();
CountLabel = new Label();
CountTextBox = new TextBox();
SaveButton = new Button();
CancelButton = new Button();
SuspendLayout();
//
// IceCreamComboBox
//
IceCreamComboBox.FormattingEnabled = true;
IceCreamComboBox.Location = new Point(99, 12);
IceCreamComboBox.Name = "IceCreamComboBox";
IceCreamComboBox.Size = new Size(121, 23);
IceCreamComboBox.TabIndex = 0;
//
// IceCreamLabel
//
IceCreamLabel.AutoSize = true;
IceCreamLabel.Location = new Point(12, 20);
IceCreamLabel.Name = "IceCreamLabel";
IceCreamLabel.Size = new Size(81, 15);
IceCreamLabel.TabIndex = 1;
IceCreamLabel.Text = "Мороженное";
//
// CountLabel
//
CountLabel.AutoSize = true;
CountLabel.Location = new Point(21, 49);
CountLabel.Name = "CountLabel";
CountLabel.Size = new Size(72, 15);
CountLabel.TabIndex = 2;
CountLabel.Text = "Количество";
//
// CountTextBox
//
CountTextBox.Location = new Point(99, 41);
CountTextBox.Name = "CountTextBox";
CountTextBox.Size = new Size(121, 23);
CountTextBox.TabIndex = 3;
//
// SaveButton
//
SaveButton.Location = new Point(64, 73);
SaveButton.Name = "SaveButton";
SaveButton.Size = new Size(75, 23);
SaveButton.TabIndex = 4;
SaveButton.Text = "Сохранить";
SaveButton.UseVisualStyleBackColor = true;
SaveButton.Click += SaveButton_Click;
//
// CancelButton
//
CancelButton.Location = new Point(145, 73);
CancelButton.Name = "CancelButton";
CancelButton.Size = new Size(75, 23);
CancelButton.TabIndex = 5;
CancelButton.Text = "Отмена";
CancelButton.UseVisualStyleBackColor = true;
//
// SellForm
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(224, 108);
Controls.Add(CancelButton);
Controls.Add(SaveButton);
Controls.Add(CountTextBox);
Controls.Add(CountLabel);
Controls.Add(IceCreamLabel);
Controls.Add(IceCreamComboBox);
Name = "SellForm";
Text = "Форма продажи";
ResumeLayout(false);
PerformLayout();
}
#endregion
private ComboBox IceCreamComboBox;
private Label IceCreamLabel;
private Label CountLabel;
private TextBox CountTextBox;
private Button SaveButton;
private Button CancelButton;
}
}

117
Diner/Diner/FormSell.cs Normal file
View File

@ -0,0 +1,117 @@
using IceCreamShopContracts.BusinessLogicsContracts;
using IceCreamShopContracts.SearchModels;
using IceCreamShopContracts.ViewModels;
using IceCreamShopDataModels.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;
namespace IceCreamShop
{
public partial class SellForm : Form
{
private readonly List<IceCreamViewModel>? _iceCreamList;
IShopLogic _shopLogic;
IIceCreamLogic _iceCreamLogic;
public SellForm(IIceCreamLogic iceCreamLogic, IShopLogic shopLogic)
{
InitializeComponent();
_shopLogic = shopLogic;
_iceCreamLogic = iceCreamLogic;
_iceCreamList = iceCreamLogic.ReadList(null);
if (_iceCreamList != null)
{
IceCreamComboBox.DisplayMember = "IceCreamName";
IceCreamComboBox.ValueMember = "Id";
IceCreamComboBox.DataSource = _iceCreamList;
IceCreamComboBox.SelectedItem = null;
}
}
public int IceCreamId
{
get
{
return
Convert.ToInt32(IceCreamComboBox.SelectedValue);
}
set
{
IceCreamComboBox.SelectedValue = value;
}
}
public IIceCreamModel? IceCreamModel
{
get
{
if (_iceCreamList == null)
{
return null;
}
foreach (var elem in _iceCreamList)
{
if (elem.Id == IceCreamId)
{
return elem;
}
}
return null;
}
}
public int Count
{
get { return Convert.ToInt32(CountTextBox.Text); }
set
{ CountTextBox.Text = value.ToString(); }
}
private void SaveButton_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(CountTextBox.Text))
{
MessageBox.Show("Заполните поле Количество", "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (IceCreamComboBox.SelectedValue == null)
{
MessageBox.Show("Выберите мороженное", "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
try
{
int count = Convert.ToInt32(CountTextBox.Text);
bool res = _shopLogic.MakeSell(
_iceCreamLogic.ReadElement(new() { Id = Convert.ToInt32(IceCreamComboBox.SelectedValue) }),
count
);
if (!res)
{
throw new Exception("Ошибка при продаже.");
}
MessageBox.Show("Продажа прошла успешно");
DialogResult = DialogResult.OK;
Close();
}
catch (Exception err)
{
MessageBox.Show("Ошибка продажи");
return;
}
}
}
}

120
Diner/Diner/FormSell.resx Normal file
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>

119
Diner/Diner/FormSellSnack.Designer.cs generated Normal file
View File

@ -0,0 +1,119 @@
namespace PizzeriaView
{
partial class FormSellSnack
{
/// <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()
{
labelSnack = new Label();
comboBoxSnack = new ComboBox();
labelCount = new Label();
textBoxCount = new TextBox();
buttonSell = new Button();
buttonCancel = new Button();
SuspendLayout();
//
// labelSnack
//
labelSnack.AutoSize = true;
labelSnack.Location = new Point(12, 14);
labelSnack.Name = "labelSnack";
labelSnack.Size = new Size(68, 20);
labelSnack.TabIndex = 0;
labelSnack.Text = "Закуска: ";
//
// comboBoxSnack
//
comboBoxSnack.FormattingEnabled = true;
comboBoxSnack.Location = new Point(115, 11);
comboBoxSnack.Name = "comboBoxSnack";
comboBoxSnack.Size = new Size(239, 28);
comboBoxSnack.TabIndex = 1;
//
// labelCount
//
labelCount.AutoSize = true;
labelCount.Location = new Point(12, 55);
labelCount.Name = "labelCount";
labelCount.Size = new Size(97, 20);
labelCount.TabIndex = 2;
labelCount.Text = "Количество: ";
//
// textBoxCount
//
textBoxCount.Location = new Point(115, 52);
textBoxCount.Name = "textBoxCount";
textBoxCount.Size = new Size(239, 27);
textBoxCount.TabIndex = 3;
//
// buttonSell
//
buttonSell.Location = new Point(128, 99);
buttonSell.Name = "buttonSell";
buttonSell.Size = new Size(94, 29);
buttonSell.TabIndex = 4;
buttonSell.Text = "Продать";
buttonSell.UseVisualStyleBackColor = true;
buttonSell.Click += ButtonSell_Click;
//
// buttonCancel
//
buttonCancel.Location = new Point(242, 99);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(94, 29);
buttonCancel.TabIndex = 5;
buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += ButtonCancel_Click;
//
// FormSellSnack
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(366, 140);
Controls.Add(buttonCancel);
Controls.Add(buttonSell);
Controls.Add(textBoxCount);
Controls.Add(labelCount);
Controls.Add(comboBoxSnack);
Controls.Add(labelSnack);
Name = "FormSellSnack";
Text = "Продажа пиццы";
Load += FormSellingSnack_Load;
ResumeLayout(false);
PerformLayout();
}
#endregion
private Label labelSnack;
private ComboBox comboBoxSnack;
private Label labelCount;
private TextBox textBoxCount;
private Button buttonSell;
private Button buttonCancel;
}
}

View File

@ -0,0 +1,83 @@
using Microsoft.Extensions.Logging;
using DinerContracts.BusinessLogicsContracts;
using DinerContracts.SearchModels;
using DinerContracts.StoragesContracts;
using DinerContracts.ViewModels;
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 PizzeriaView
{
public partial class FormSellSnack : Form
{
private readonly ILogger _logger;
private readonly ISnackLogic _logicP;
private readonly IShopLogic _logicS;
private List<SnackViewModel> _snackList = new List<SnackViewModel>();
public FormSellSnack(ILogger<FormSellSnack> logger, ISnackLogic logicP, IShopLogic logicS)
{
InitializeComponent();
_logger = logger;
_logicP = logicP;
_logicS = logicS;
}
private void FormSellingSnack_Load(object sender, EventArgs e)
{
_snackList = _logicP.ReadList(null);
if (_snackList != null)
{
comboBoxSnack.DisplayMember = "PizzaName";
comboBoxSnack.ValueMember = "Id";
comboBoxSnack.DataSource = _snackList;
comboBoxSnack.SelectedItem = null;
_logger.LogInformation("Загрузка закуски для продажи");
}
}
private void ButtonSell_Click(object sender, EventArgs e)
{
if (comboBoxSnack.SelectedValue == null)
{
MessageBox.Show("Выберите закуску", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Создание покупки");
try
{
bool resout = _logicS.Sale(new SupplySearchModel
{
PizzaId = Convert.ToInt32(comboBoxSnack.SelectedValue),
Count = Convert.ToInt32(textBoxCount.Text)
});
if (resout)
{
_logger.LogInformation("Проверка пройдена, продажа проведена");
MessageBox.Show("Продажа проведена", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
DialogResult = DialogResult.OK;
Close();
}
else {
_logger.LogInformation("Проверка не пройдена");
MessageBox.Show("Продажа не может быть создана.", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
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

@ -35,12 +35,15 @@
buttonCancel = new Button(); buttonCancel = new Button();
buttonSave = new Button(); buttonSave = new Button();
dataGridView = new DataGridView(); dataGridView = new DataGridView();
label1 = new Label();
dateTimeOpen = new DateTimePicker();
id = new DataGridViewTextBoxColumn(); id = new DataGridViewTextBoxColumn();
DinerName = new DataGridViewTextBoxColumn(); DinerName = new DataGridViewTextBoxColumn();
Count = new DataGridViewTextBoxColumn(); Count = new DataGridViewTextBoxColumn();
label1 = new Label();
dateTimeOpen = new DateTimePicker();
label2 = new Label();
numericUpSnackMaxCount = new NumericUpDown();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
((System.ComponentModel.ISupportInitialize)numericUpSnackMaxCount).BeginInit();
SuspendLayout(); SuspendLayout();
// //
// labelName // labelName
@ -102,31 +105,15 @@
dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView.Columns.AddRange(new DataGridViewColumn[] { id, DinerName, Count }); dataGridView.Columns.AddRange(new DataGridViewColumn[] { id, DinerName, Count });
dataGridView.Location = new Point(12, 144); dataGridView.Location = new Point(12, 197);
dataGridView.Name = "dataGridView"; dataGridView.Name = "dataGridView";
dataGridView.ReadOnly = true; dataGridView.ReadOnly = true;
dataGridView.RowHeadersBorderStyle = DataGridViewHeaderBorderStyle.None; dataGridView.RowHeadersBorderStyle = DataGridViewHeaderBorderStyle.None;
dataGridView.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.AutoSizeToDisplayedHeaders; dataGridView.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.AutoSizeToDisplayedHeaders;
dataGridView.RowTemplate.Height = 29; dataGridView.RowTemplate.Height = 29;
dataGridView.Size = new Size(569, 307); dataGridView.Size = new Size(569, 254);
dataGridView.TabIndex = 7; dataGridView.TabIndex = 7;
// //
// label1
//
label1.AutoSize = true;
label1.Location = new Point(12, 103);
label1.Name = "label1";
label1.Size = new Size(110, 20);
label1.TabIndex = 8;
label1.Text = "Дата открытия";
//
// dateTimeOpen
//
dateTimeOpen.Location = new Point(128, 103);
dateTimeOpen.Name = "dateTimeOpen";
dateTimeOpen.Size = new Size(401, 27);
dateTimeOpen.TabIndex = 9;
//
// id // id
// //
id.HeaderText = "id"; id.HeaderText = "id";
@ -149,11 +136,46 @@
Count.Name = "Count"; Count.Name = "Count";
Count.ReadOnly = true; Count.ReadOnly = true;
// //
// label1
//
label1.AutoSize = true;
label1.Location = new Point(12, 103);
label1.Name = "label1";
label1.Size = new Size(110, 20);
label1.TabIndex = 8;
label1.Text = "Дата открытия";
//
// dateTimeOpen
//
dateTimeOpen.Location = new Point(128, 103);
dateTimeOpen.Name = "dateTimeOpen";
dateTimeOpen.Size = new Size(401, 27);
dateTimeOpen.TabIndex = 9;
//
// label2
//
label2.AutoSize = true;
label2.Location = new Point(12, 156);
label2.Name = "label2";
label2.Size = new Size(107, 20);
label2.TabIndex = 10;
label2.Text = "Вместимость: ";
//
// numericUpSnackMaxCount
//
numericUpSnackMaxCount.Location = new Point(128, 154);
numericUpSnackMaxCount.Maximum = new decimal(new int[] { 10000, 0, 0, 0 });
numericUpSnackMaxCount.Name = "numericUpSnackMaxCount";
numericUpSnackMaxCount.Size = new Size(401, 27);
numericUpSnackMaxCount.TabIndex = 12;
//
// FormShop // FormShop
// //
AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(593, 513); ClientSize = new Size(593, 513);
Controls.Add(numericUpSnackMaxCount);
Controls.Add(label2);
Controls.Add(dateTimeOpen); Controls.Add(dateTimeOpen);
Controls.Add(label1); Controls.Add(label1);
Controls.Add(dataGridView); Controls.Add(dataGridView);
@ -167,6 +189,7 @@
Text = "Магазин"; Text = "Магазин";
Load += FormShop_Load; Load += FormShop_Load;
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
((System.ComponentModel.ISupportInitialize)numericUpSnackMaxCount).EndInit();
ResumeLayout(false); ResumeLayout(false);
PerformLayout(); PerformLayout();
} }
@ -185,5 +208,7 @@
private DataGridViewTextBoxColumn id; private DataGridViewTextBoxColumn id;
private DataGridViewTextBoxColumn DinerName; private DataGridViewTextBoxColumn DinerName;
private DataGridViewTextBoxColumn Count; private DataGridViewTextBoxColumn Count;
private Label label2;
private NumericUpDown numericUpSnackMaxCount;
} }
} }

View File

@ -48,6 +48,7 @@ namespace DinerView
textBoxName.Text = view.ShopName; textBoxName.Text = view.ShopName;
textBoxAdress.Text = view.Adress; textBoxAdress.Text = view.Adress;
dateTimeOpen.Value = view.OpeningDate; dateTimeOpen.Value = view.OpeningDate;
numericUpSnackMaxCount.Value = view.SnackMaxCount;
_ShopSnacks = view.ShopSnacks ?? new Dictionary<int, (ISnackModel, int)>(); _ShopSnacks = view.ShopSnacks ?? new Dictionary<int, (ISnackModel, int)>();
LoadData(); LoadData();
} }
@ -101,7 +102,8 @@ namespace DinerView
Id = _id ?? 0, Id = _id ?? 0,
ShopName = textBoxName.Text, ShopName = textBoxName.Text,
Adress = textBoxAdress.Text, Adress = textBoxAdress.Text,
OpeningDate = dateTimeOpen.Value OpeningDate = dateTimeOpen.Value,
SnackMaxCount = (int)numericUpSnackMaxCount.Value
}; };
var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model);
if (!operationResult) if (!operationResult)

View File

@ -1,6 +1,6 @@
using DinerContracts.BusinessLogicsContracts; using DinerContracts.BusinessLogicsContracts;
using DinerContracts.StoragesContracts; using DinerContracts.StoragesContracts;
using DinerListImplement.Implements; using DinerFileImplement.Implements;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using NLog.Extensions.Logging; using NLog.Extensions.Logging;