Готовая лабораторная 2 (усложненная)

This commit is contained in:
Даниил Путинцев 2024-04-15 23:43:49 +04:00
parent 0e834f7f9c
commit 238b04bf5c
22 changed files with 805 additions and 43 deletions

View File

@ -4,6 +4,7 @@ using FoodOrdersContracts.SearchModels;
using FoodOrdersContracts.StoragesContracts;
using FoodOrdersContracts.ViewModels;
using FoodOrdersDataModels.Enums;
using FoodOrdersDataModels.Models;
using Microsoft.Extensions.Logging;
namespace FoodOrdersBusinessLogic.BusinessLogics
@ -14,10 +15,19 @@ namespace FoodOrdersBusinessLogic.BusinessLogics
private readonly IOrderStorage _orderStorage;
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage)
private readonly IShopStorage _shopStorage;
private readonly IShopLogic _shopLogic;
private readonly IDishStorage _dishStorage;
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage, IShopLogic shopLogic, IDishStorage dishStorage, IShopStorage shopStorage)
{
_logger = logger;
_orderStorage = orderStorage;
_shopLogic = shopLogic;
_dishStorage = dishStorage;
_shopStorage = shopStorage;
}
public bool CreateOrder(OrderBindingModel model)
@ -90,7 +100,67 @@ namespace FoodOrdersBusinessLogic.BusinessLogics
_logger.LogInformation("Order. Id: {Id}. Sum: {Sum}. DishId: {DishId}. DishCount: {Count}", model.Id, model.Sum,
model.DishId, model.Count);
}
public bool CheckThenMakeShipment(IDishModel dish, int count)
{
if (count <= 0)
{
_logger.LogWarning("Check then make shipment operation error. Dish count < 0.");
return false;
}
int freeSpace = 0;
foreach (var shop in _shopStorage.GetFullList())
{
freeSpace += shop.MaxCountDishs;
foreach (var c in shop.ShopDishs)
{
freeSpace -= c.Value.Item2;
}
}
if (freeSpace < count)
{
_logger.LogWarning("Check then supply operation error. There's no place for new dishs in shops.");
return false;
}
foreach (var shop in _shopStorage.GetFullList())
{
freeSpace = shop.MaxCountDishs;
foreach (var c in shop.ShopDishs)
freeSpace -= c.Value.Item2;
if (freeSpace <= 0)
continue;
if (freeSpace >= count)
{
if (_shopLogic.MakeShipment(new ShopSearchModel() { Id = shop.Id }, dish, count))
count = 0;
else
{
_logger.LogWarning("Supply error");
return false;
}
}
if (freeSpace < count)
{
if (_shopLogic.MakeShipment(new ShopSearchModel() { Id = shop.Id }, dish, freeSpace))
count -= freeSpace;
else
{
_logger.LogWarning("Supply error");
return false;
}
}
if (count <= 0)
{
return true;
}
}
return false;
}
private bool ChangeStatus(OrderBindingModel model, OrderStatus newStatus)
{
CheckModel(model, false);
@ -106,6 +176,20 @@ namespace FoodOrdersBusinessLogic.BusinessLogics
newStatus, order.Status);
return false;
}
if (newStatus == OrderStatus.Выдан)
{
var dish = _dishStorage.GetElement(new DishSearchModel() { Id = order.DishId });
if (dish == null)
{
_logger.LogWarning("Change status operation failed. Dish not found");
return false;
}
if (!CheckThenMakeShipment(dish, order.Count))
{
_logger.LogWarning("Change status operation failed. Dishs delivery operation failed");
return false;
}
}
model.DishId = order.DishId;
model.Count = order.Count;
model.Sum = order.Sum;

View File

@ -105,6 +105,11 @@ namespace FoodOrdersBusinessLogic.BusinessLogics
_logger.LogWarning("MakeShipment(GetElement). Element not found");
return false;
}
if (shop.MaxCountDishs - shop.ShopDishs.Sum(x => x.Value.Item2) < count)
{
_logger.LogWarning("MakeShipment error. No space for new dishs");
return false;
}
if (shop.ShopDishs.ContainsKey(dish.Id))
{
var shopIC = shop.ShopDishs[dish.Id];
@ -124,6 +129,7 @@ namespace FoodOrdersBusinessLogic.BusinessLogics
Id = shop.Id,
ShopName = shop.ShopName,
Address = shop.Address,
MaxCountDishs = shop.MaxCountDishs,
DateOpening = shop.DateOpening,
ShopDishs = shop.ShopDishs,
}) == null)
@ -162,5 +168,9 @@ namespace FoodOrdersBusinessLogic.BusinessLogics
throw new InvalidOperationException("Магазин с таким названием уже есть");
}
}
public bool SellDish(IDishModel dish, int count)
{
return _shopStorage.SellDish(dish, count);
}
}
}

View File

@ -10,6 +10,8 @@ namespace FoodOrdersContracts.BindingModels
public string Address { get; set; } = string.Empty;
public int MaxCountDishs { get; set; }
public DateTime DateOpening { get; set; } = DateTime.Now;
public Dictionary<int, (IDishModel, int)> ShopDishs

View File

@ -18,5 +18,7 @@ namespace FoodOrdersContracts.BusinessLogicsContracts
bool Delete(ShopBindingModel model);
bool MakeShipment(ShopSearchModel shopModel, IDishModel dish, int count);
bool SellDish(IDishModel dish, int count);
}
}

View File

@ -1,6 +1,7 @@
using FoodOrdersContracts.BindingModels;
using FoodOrdersContracts.SearchModels;
using FoodOrdersContracts.ViewModels;
using FoodOrdersDataModels.Models;
namespace FoodOrdersContracts.StoragesContracts
{
@ -17,5 +18,7 @@ namespace FoodOrdersContracts.StoragesContracts
ShopViewModel? Update(ShopBindingModel model);
ShopViewModel? Delete(ShopBindingModel model);
bool SellDish(IDishModel model, int count);
}
}

View File

@ -13,6 +13,9 @@ namespace FoodOrdersContracts.ViewModels
[DisplayName("Адрес")]
public string Address { get; set; } = string.Empty;
[DisplayName("Максимум блюд")]
public int MaxCountDishs { get; set; }
[DisplayName("Дата открытия")]
public DateTime DateOpening { get; set; } = DateTime.Now;

View File

@ -6,6 +6,8 @@
string Address { get; }
int MaxCountDishs { get; }
DateTime DateOpening { get; }
Dictionary<int, (IDishModel, int)> ShopDishs { get; }

View File

@ -13,12 +13,15 @@ namespace FoodOrdersFileImplement
private readonly string DishFileName = "Dish.xml";
private readonly string ShopFileName = "Shop.xml";
public List<Component> Components { get; private set; }
public List<Order> Orders { get; private set; }
public List<Dish> Dishs { get; private set; }
public List<Shop> Shops { get; private set; }
public static DataFileSingleton GetInstance()
{
if (instance == null)
@ -34,11 +37,14 @@ namespace FoodOrdersFileImplement
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)!)!;
Dishs = LoadData(DishFileName, "Dish", x => Dish.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

@ -6,6 +6,10 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\FoodOrdersContracts\FoodOrdersContracts.csproj" />
<ProjectReference Include="..\FoodOrdersDataModels\FoodOrdersDataModels.csproj" />

View File

@ -0,0 +1,137 @@
using FoodOrdersContracts.BindingModels;
using FoodOrdersContracts.SearchModels;
using FoodOrdersContracts.StoragesContracts;
using FoodOrdersContracts.ViewModels;
using FoodOrdersDataModels.Models;
using FoodOrdersFileImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FoodOrdersFileImplement.Implements
{
public class ShopStorage : IShopStorage
{
private readonly DataFileSingleton source;
public ShopStorage()
{
source = DataFileSingleton.GetInstance();
}
public ShopViewModel? GetElement(ShopSearchModel model)
{
if (!model.Id.HasValue)
{
return null;
}
return source.Shops.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)?.GetViewModel;
}
public List<ShopViewModel> GetFilteredList(ShopSearchModel model)
{
if (string.IsNullOrEmpty(model.ShopName))
{
return new();
}
return source.Shops
.Select(x => x.GetViewModel)
.Where(x => x.ShopName.Contains(model.ShopName ?? string.Empty))
.ToList();
}
public List<ShopViewModel> GetFullList()
{
return source.Shops.Select(shop => shop.GetViewModel).ToList();
}
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 shop = source.Shops.FirstOrDefault(x => x.Id == model.Id);
if (shop == null)
{
return null;
}
source.Shops.Remove(shop);
source.SaveShops();
return shop.GetViewModel;
}
public bool SellDish(IDishModel model, int count)
{
var dish = source.Dishs.FirstOrDefault(x => x.Id == model.Id);
if (dish == null)
{
return false;
}
var shopDishs = source.Shops.SelectMany(shop => shop.ShopDishs.Where(c => c.Value.Item1.Id == dish.Id));
int countStore = 0;
foreach (var it in shopDishs)
countStore += it.Value.Item2;
if (count > countStore)
return false;
foreach (var shop in source.Shops)
{
var dishs = shop.ShopDishs;
foreach (var c in dishs.Where(x => x.Value.Item1.Id == dish.Id))
{
int min = Math.Min(c.Value.Item2, count);
dishs[c.Value.Item1.Id] = (c.Value.Item1, c.Value.Item2 - min);
count -= min;
if (count <= 0)
break;
}
shop.Update(new ShopBindingModel
{
Id = shop.Id,
ShopName = shop.ShopName,
Address = shop.Address,
MaxCountDishs = shop.MaxCountDishs,
DateOpening = shop.DateOpening,
ShopDishs = dishs
});
source.SaveShops();
if (count <= 0)
return true;
}
return true;
}
}
}

View File

@ -0,0 +1,116 @@
using FoodOrdersContracts.BindingModels;
using FoodOrdersContracts.ViewModels;
using FoodOrdersDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace FoodOrdersFileImplement.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 int MaxCountDishs { get; private set; }
public DateTime DateOpening { get; private set; }
public Dictionary<int, int> Dishs { get; private set; } = new();
private Dictionary<int, (IDishModel, int)>? _shopDishs = null;
public Dictionary<int, (IDishModel, int)> ShopDishs
{
get
{
if (_shopDishs == null)
{
var source = DataFileSingleton.GetInstance();
_shopDishs = Dishs.ToDictionary(
x => x.Key,
y => ((source.Dishs.FirstOrDefault(z => z.Id == y.Key) as IDishModel)!, y.Value)
);
}
return _shopDishs;
}
}
public static Shop? Create(ShopBindingModel? model)
{
if (model == null)
{
return null;
}
return new Shop()
{
Id = model.Id,
ShopName = model.ShopName,
Address = model.Address,
MaxCountDishs = model.MaxCountDishs,
DateOpening = model.DateOpening,
Dishs = model.ShopDishs.ToDictionary(x => x.Key, x => x.Value.Item2)
};
}
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,
MaxCountDishs = Convert.ToInt32(element.Element("MaxCountDishs")!.Value),
DateOpening = Convert.ToDateTime(element.Element("DateOpening")!.Value),
Dishs = element.Element("ShopDishs")!.Elements("ShopDish").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;
MaxCountDishs = model.MaxCountDishs;
DateOpening = model.DateOpening;
if (model.ShopDishs.Count > 0)
{
Dishs = model.ShopDishs.ToDictionary(x => x.Key, x => x.Value.Item2);
_shopDishs = null;
}
}
public ShopViewModel GetViewModel => new()
{
Id = Id,
ShopName = ShopName,
Address = Address,
MaxCountDishs = MaxCountDishs,
DateOpening = DateOpening,
ShopDishs = ShopDishs,
};
public XElement GetXElement => new(
"Shop",
new XAttribute("Id", Id),
new XElement("ShopName", ShopName),
new XElement("Address", Address),
new XElement("MaxCountDishs", MaxCountDishs),
new XElement("DateOpening", DateOpening.ToString()),
new XElement("ShopDishs", Dishs.Select(x =>
new XElement("ShopDish",
new XElement("Key", x.Key),
new XElement("Value", x.Value)))
.ToArray()));
}
}

View File

@ -2,12 +2,18 @@
using FoodOrdersContracts.SearchModels;
using FoodOrdersContracts.StoragesContracts;
using FoodOrdersContracts.ViewModels;
using FoodOrdersDataModels.Models;
using FoodOrdersListImplement.Models;
namespace FoodOrdersListImplement.Implements
{
public class ShopStorage : IShopStorage
{
public bool SellDish(IDishModel dish, int count)
{
throw new NotImplementedException();
}
private readonly DataListSingleton _source;
public ShopStorage()

View File

@ -12,6 +12,8 @@ namespace FoodOrdersListImplement.Models
public string Address { get; private set; } = string.Empty;
public int MaxCountDishs { get; private set; }
public DateTime DateOpening { get; private set; }
public Dictionary<int, (IDishModel, int)> ShopDishs

View File

@ -0,0 +1,128 @@
namespace FoodOrdersView
{
partial class FormDishSale
{
/// <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();
comboBoxDish = new ComboBox();
labelDish = new Label();
SuspendLayout();
//
// buttonCancel
//
buttonCancel.Location = new Point(289, 111);
buttonCancel.Margin = new Padding(5, 4, 5, 4);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(101, 36);
buttonCancel.TabIndex = 17;
buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += ButtonCancel_Click;
//
// buttonSale
//
buttonSale.Location = new Point(182, 111);
buttonSale.Margin = new Padding(5, 4, 5, 4);
buttonSale.Name = "buttonSale";
buttonSale.Size = new Size(101, 36);
buttonSale.TabIndex = 16;
buttonSale.Text = "Продать";
buttonSale.UseVisualStyleBackColor = true;
buttonSale.Click += ButtonSale_Click;
//
// textBoxCount
//
textBoxCount.Location = new Point(115, 68);
textBoxCount.Margin = new Padding(5, 4, 5, 4);
textBoxCount.Name = "textBoxCount";
textBoxCount.Size = new Size(287, 27);
textBoxCount.TabIndex = 15;
//
// labelCount
//
labelCount.AutoSize = true;
labelCount.Location = new Point(15, 72);
labelCount.Margin = new Padding(5, 0, 5, 0);
labelCount.Name = "labelCount";
labelCount.Size = new Size(97, 20);
labelCount.TabIndex = 14;
labelCount.Text = "Количество :";
//
// comboBoxDish
//
comboBoxDish.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxDish.FormattingEnabled = true;
comboBoxDish.Location = new Point(115, 20);
comboBoxDish.Margin = new Padding(5, 4, 5, 4);
comboBoxDish.Name = "comboBoxDish";
comboBoxDish.Size = new Size(287, 28);
comboBoxDish.TabIndex = 13;
//
// labelDish
//
labelDish.AutoSize = true;
labelDish.Location = new Point(15, 23);
labelDish.Margin = new Padding(5, 0, 5, 0);
labelDish.Name = "labelDish";
labelDish.Size = new Size(62, 20);
labelDish.TabIndex = 12;
labelDish.Text = "Блюдо :";
//
// FormDishSale
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(426, 164);
Controls.Add(buttonCancel);
Controls.Add(buttonSale);
Controls.Add(textBoxCount);
Controls.Add(labelCount);
Controls.Add(comboBoxDish);
Controls.Add(labelDish);
Margin = new Padding(3, 4, 3, 4);
Name = "FormDishSale";
StartPosition = FormStartPosition.CenterScreen;
Text = "Продажа блюд";
Load += FormDishSale_Load;
ResumeLayout(false);
PerformLayout();
}
#endregion
private Button buttonCancel;
private Button buttonSale;
private TextBox textBoxCount;
private Label labelCount;
private ComboBox comboBoxDish;
private Label labelDish;
}
}

View File

@ -0,0 +1,87 @@
using FoodOrdersContracts.BusinessLogicsContracts;
using FoodOrdersContracts.BindingModels;
using Microsoft.Extensions.Logging;
namespace FoodOrdersView
{
public partial class FormDishSale : Form
{
private readonly ILogger _logger;
private readonly IDishLogic _logicDish;
private readonly IShopLogic _logicShop;
public FormDishSale(ILogger<FormMakeShipment> logger, IDishLogic logicDish, IShopLogic logicShop)
{
InitializeComponent();
_logger = logger;
_logicDish = logicDish;
_logicShop = logicShop;
}
private void FormDishSale_Load(object sender, EventArgs e)
{
_logger.LogInformation("Dishs loading");
try
{
var list = _logicDish.ReadList(null);
if (list != null)
{
comboBoxDish.DisplayMember = "DishName";
comboBoxDish.ValueMember = "Id";
comboBoxDish.DataSource = list;
comboBoxDish.SelectedItem = null;
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Dishs loading error");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonSale_Click(object sender, EventArgs e)
{
if (comboBoxDish.SelectedValue == null)
{
MessageBox.Show("Выберите блюдо", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (string.IsNullOrEmpty(textBoxCount.Text))
{
MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Dish sale");
try
{
var operationResult = _logicShop.SellDish(
new DishBindingModel
{
Id = Convert.ToInt32(comboBoxDish.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, "Dish 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

@ -162,5 +162,14 @@ namespace FoodOrdersView
form.ShowDialog();
}
}
private void продажаБлюдToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormDishSale));
if (service is FormDishSale form)
{
form.ShowDialog();
}
}
}
}

View File

@ -40,6 +40,7 @@
buttonCreateOrder = new Button();
dataGridView = new DataGridView();
buttonUpd = new Button();
продажаБлюдToolStripMenuItem = new ToolStripMenuItem();
menuStrip.SuspendLayout();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
SuspendLayout();
@ -47,7 +48,7 @@
// menuStrip
//
menuStrip.ImageScalingSize = new Size(20, 20);
menuStrip.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, пополнениеМагазинаToolStripMenuItem });
menuStrip.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, пополнениеМагазинаToolStripMenuItem, продажаБлюдToolStripMenuItem });
menuStrip.Location = new Point(0, 0);
menuStrip.Name = "menuStrip";
menuStrip.Padding = new Padding(8, 3, 0, 3);
@ -65,21 +66,21 @@
// компоненты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(224, 26);
магазиныToolStripMenuItem.Size = new Size(182, 26);
магазиныToolStripMenuItem.Text = "Магазины";
магазиныToolStripMenuItem.Click += магазиныToolStripMenuItem_Click;
//
@ -168,6 +169,13 @@
buttonUpd.UseVisualStyleBackColor = true;
buttonUpd.Click += ButtonUpd_Click;
//
// продажаБлюдToolStripMenuItem
//
продажаБлюдToolStripMenuItem.Name = "продажаБлюдToolStripMenuItem";
продажаБлюдToolStripMenuItem.Size = new Size(128, 24);
продажаБлюдToolStripMenuItem.Text = "Продажа блюд";
продажаБлюдToolStripMenuItem.Click += продажаБлюдToolStripMenuItem_Click;
//
// FormMain
//
AutoScaleDimensions = new SizeF(8F, 20F);
@ -207,6 +215,7 @@
private Button buttonUpd;
private ToolStripMenuItem магазиныToolStripMenuItem;
private ToolStripMenuItem пополнениеМагазинаToolStripMenuItem;
private ToolStripMenuItem продажаБлюдToolStripMenuItem;
}
}

View File

@ -33,14 +33,16 @@
labelAddress = new Label();
textBoxAddress = new TextBox();
dateTimePicker = new DateTimePicker();
labelOpeningDate = new Label();
labelDateOpening = new Label();
groupBoxDishs = new GroupBox();
dataGridView = new DataGridView();
buttonSave = new Button();
buttonCancel = new Button();
ColumnId = new DataGridViewTextBoxColumn();
ColumnName = new DataGridViewTextBoxColumn();
ColumnCount = new DataGridViewTextBoxColumn();
buttonSave = new Button();
buttonCancel = new Button();
textBoxMaximum = new TextBox();
labelMaximum = new Label();
groupBoxDishs.SuspendLayout();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
SuspendLayout();
@ -89,24 +91,24 @@
dateTimePicker.Size = new Size(249, 27);
dateTimePicker.TabIndex = 5;
//
// labelOpeningDate
// labelDateOpening
//
labelOpeningDate.AutoSize = true;
labelOpeningDate.Location = new Point(16, 92);
labelOpeningDate.Margin = new Padding(5, 0, 5, 0);
labelOpeningDate.Name = "labelOpeningDate";
labelOpeningDate.Size = new Size(117, 20);
labelOpeningDate.TabIndex = 6;
labelOpeningDate.Text = "Дата открытия :";
labelDateOpening.AutoSize = true;
labelDateOpening.Location = new Point(16, 92);
labelDateOpening.Margin = new Padding(5, 0, 5, 0);
labelDateOpening.Name = "labelDateOpening";
labelDateOpening.Size = new Size(117, 20);
labelDateOpening.TabIndex = 6;
labelDateOpening.Text = "Дата открытия :";
//
// groupBoxDishs
//
groupBoxDishs.Controls.Add(dataGridView);
groupBoxDishs.Location = new Point(5, 133);
groupBoxDishs.Location = new Point(5, 184);
groupBoxDishs.Margin = new Padding(5, 4, 5, 4);
groupBoxDishs.Name = "groupBoxDishs";
groupBoxDishs.Padding = new Padding(5, 4, 5, 4);
groupBoxDishs.Size = new Size(536, 384);
groupBoxDishs.Size = new Size(536, 333);
groupBoxDishs.TabIndex = 7;
groupBoxDishs.TabStop = false;
groupBoxDishs.Text = "Блюдо";
@ -127,31 +129,9 @@
dataGridView.RowHeadersVisible = false;
dataGridView.RowHeadersWidth = 51;
dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dataGridView.Size = new Size(522, 356);
dataGridView.Size = new Size(522, 305);
dataGridView.TabIndex = 0;
//
// buttonSave
//
buttonSave.Location = new Point(291, 525);
buttonSave.Margin = new Padding(5, 4, 5, 4);
buttonSave.Name = "buttonSave";
buttonSave.Size = new Size(101, 36);
buttonSave.TabIndex = 8;
buttonSave.Text = "Сохранить";
buttonSave.UseVisualStyleBackColor = true;
buttonSave.Click += ButtonSave_Click;
//
// buttonCancel
//
buttonCancel.Location = new Point(410, 525);
buttonCancel.Margin = new Padding(5, 4, 5, 4);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(101, 36);
buttonCancel.TabIndex = 9;
buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += ButtonCancel_Click;
//
// ColumnId
//
ColumnId.HeaderText = "Id";
@ -177,15 +157,57 @@
ColumnCount.ReadOnly = true;
ColumnCount.Width = 125;
//
// buttonSave
//
buttonSave.Location = new Point(291, 525);
buttonSave.Margin = new Padding(5, 4, 5, 4);
buttonSave.Name = "buttonSave";
buttonSave.Size = new Size(101, 36);
buttonSave.TabIndex = 8;
buttonSave.Text = "Сохранить";
buttonSave.UseVisualStyleBackColor = true;
buttonSave.Click += ButtonSave_Click;
//
// buttonCancel
//
buttonCancel.Location = new Point(410, 525);
buttonCancel.Margin = new Padding(5, 4, 5, 4);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(101, 36);
buttonCancel.TabIndex = 9;
buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += ButtonCancel_Click;
//
// textBoxMaximum
//
textBoxMaximum.Location = new Point(193, 133);
textBoxMaximum.Margin = new Padding(5, 4, 5, 4);
textBoxMaximum.Name = "textBoxMaximum";
textBoxMaximum.Size = new Size(199, 27);
textBoxMaximum.TabIndex = 13;
//
// labelMaximum
//
labelMaximum.AutoSize = true;
labelMaximum.Location = new Point(16, 137);
labelMaximum.Margin = new Padding(5, 0, 5, 0);
labelMaximum.Name = "labelMaximum";
labelMaximum.Size = new Size(130, 20);
labelMaximum.TabIndex = 12;
labelMaximum.Text = "Максимум блюд :";
//
// FormShop
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(546, 576);
Controls.Add(textBoxMaximum);
Controls.Add(labelMaximum);
Controls.Add(buttonCancel);
Controls.Add(buttonSave);
Controls.Add(groupBoxDishs);
Controls.Add(labelOpeningDate);
Controls.Add(labelDateOpening);
Controls.Add(dateTimePicker);
Controls.Add(textBoxAddress);
Controls.Add(labelAddress);
@ -209,7 +231,7 @@
private Label labelAddress;
private TextBox textBoxAddress;
private DateTimePicker dateTimePicker;
private Label labelOpeningDate;
private Label labelDateOpening;
private GroupBox groupBoxDishs;
private DataGridView dataGridView;
private Button buttonSave;
@ -217,5 +239,7 @@
private DataGridViewTextBoxColumn ColumnId;
private DataGridViewTextBoxColumn ColumnName;
private DataGridViewTextBoxColumn ColumnCount;
private TextBox textBoxMaximum;
private Label labelMaximum;
}
}

View File

@ -39,6 +39,7 @@ namespace FoodOrdersView
textBoxName.Text = view.ShopName;
textBoxAddress.Text = view.Address;
dateTimePicker.Value = view.DateOpening;
textBoxMaximum.Text = view.MaxCountDishs.ToString();
_shopDishs = view.ShopDishs ?? new Dictionary<int, (IDishModel, int)>();
LoadData();
}
@ -89,6 +90,11 @@ namespace FoodOrdersView
MessageBox.Show("Заполните дату", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (string.IsNullOrEmpty(textBoxMaximum.Text))
{
MessageBox.Show("Заполните максимальное количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Shop saving");
try
{
@ -98,6 +104,7 @@ namespace FoodOrdersView
ShopName = textBoxName.Text,
Address = textBoxAddress.Text,
DateOpening = dateTimePicker.Value,
MaxCountDishs = Convert.ToInt32(textBoxMaximum.Text),
ShopDishs = _shopDishs
};
var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model);

View File

@ -55,6 +55,7 @@ namespace FoodOrdersView
services.AddTransient<FormShop>();
services.AddTransient<FormShops>();
services.AddTransient<FormMakeShipment>();
services.AddTransient<FormDishSale>();
}
}
}