diff --git a/AbstractShopBusinessLogic/BusinessLogics/OrderLogic.cs b/AbstractShopBusinessLogic/BusinessLogics/OrderLogic.cs index 1466f90..005107e 100644 --- a/AbstractShopBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/AbstractShopBusinessLogic/BusinessLogics/OrderLogic.cs @@ -3,6 +3,7 @@ using DinerContracts.BusinessLogicsContracts; using DinerContracts.SearchModels; using DinerContracts.StoragesContracts; using DinerContracts.ViewModels; +using DinerShopDataModels.Models; using DinerDataModels.Enum; using Microsoft.Extensions.Logging; @@ -12,10 +13,18 @@ namespace DinerBusinessLogic.BusinessLogics { private readonly ILogger _logger; private readonly IOrderStorage _orderStorage; - public OrderLogic(ILogger logger, IOrderStorage orderStorage) + private readonly IShopStorage _shopStorage; + private readonly IShopLogic _shopLogic; + + private readonly IShopStorage _shopStorage; + + + public OrderLogic(ILogger logger, IOrderStorage orderStorage, IShopStorage shopStorage) { - _logger = logger; _orderStorage = orderStorage; + _logger = logger; + _shopStorage = shopStorage; + } public List? ReadList(OrderSearchModel? model) { @@ -29,6 +38,7 @@ namespace DinerBusinessLogic.BusinessLogics _logger.LogInformation("ReadList. Count:{Count}", list.Count); return list; } + public bool CreateOrder(OrderBindingModel model) { CheckModel(model); @@ -41,6 +51,64 @@ namespace DinerBusinessLogic.BusinessLogics } 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) { return ChangeStatus(model, OrderStatus.Выполняется); @@ -53,6 +121,27 @@ namespace DinerBusinessLogic.BusinessLogics { 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) { if (model == null) diff --git a/AbstractShopBusinessLogic/BusinessLogics/ShopLogic.cs b/AbstractShopBusinessLogic/BusinessLogics/ShopLogic.cs index 6f35a4c..ed9d705 100644 --- a/AbstractShopBusinessLogic/BusinessLogics/ShopLogic.cs +++ b/AbstractShopBusinessLogic/BusinessLogics/ShopLogic.cs @@ -157,5 +157,20 @@ namespace DinerBusinessLogic.BusinessLogics 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; + } } } diff --git a/AbstractShopContracts/BindingModels/ShopBindingModel.cs b/AbstractShopContracts/BindingModels/ShopBindingModel.cs index d4d5088..c347698 100644 --- a/AbstractShopContracts/BindingModels/ShopBindingModel.cs +++ b/AbstractShopContracts/BindingModels/ShopBindingModel.cs @@ -14,5 +14,6 @@ namespace DinerContracts.BindingModels public string Adress { get; set; } = string.Empty; public DateTime OpeningDate { get; set; } = DateTime.Now; public Dictionary ShopSnacks { get; set; } = new(); + public int SnackMaxCount { get; set; } } } \ No newline at end of file diff --git a/AbstractShopContracts/BusinessLogicsContracts/IShopLogic.cs b/AbstractShopContracts/BusinessLogicsContracts/IShopLogic.cs index 1d540ad..2adad26 100644 --- a/AbstractShopContracts/BusinessLogicsContracts/IShopLogic.cs +++ b/AbstractShopContracts/BusinessLogicsContracts/IShopLogic.cs @@ -17,5 +17,6 @@ namespace DinerContracts.BusinessLogicsContracts bool Update(ShopBindingModel model); bool Delete(ShopBindingModel model); bool MakeSupply(SupplyBindingModel model); + bool Sale(SupplySearchModel model); } } \ No newline at end of file diff --git a/AbstractShopContracts/SearchModels/SupplySearchModel.cs b/AbstractShopContracts/SearchModels/SupplySearchModel.cs new file mode 100644 index 0000000..67d40b6 --- /dev/null +++ b/AbstractShopContracts/SearchModels/SupplySearchModel.cs @@ -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; } + } +} diff --git a/AbstractShopContracts/StoragesContracts/IShopStorage.cs b/AbstractShopContracts/StoragesContracts/IShopStorage.cs index 9c62afa..c5d4ae2 100644 --- a/AbstractShopContracts/StoragesContracts/IShopStorage.cs +++ b/AbstractShopContracts/StoragesContracts/IShopStorage.cs @@ -17,5 +17,7 @@ namespace DinerContracts.StoragesContracts ShopViewModel? Insert(ShopBindingModel model); ShopViewModel? Update(ShopBindingModel model); ShopViewModel? Delete(ShopBindingModel model); + bool Sale(SupplySearchModel model); + bool RestockingShops(SupplyBindingModel model); } } \ No newline at end of file diff --git a/AbstractShopContracts/ViewModels/ShopViewModel.cs b/AbstractShopContracts/ViewModels/ShopViewModel.cs index 85331fc..7684fe8 100644 --- a/AbstractShopContracts/ViewModels/ShopViewModel.cs +++ b/AbstractShopContracts/ViewModels/ShopViewModel.cs @@ -18,5 +18,7 @@ namespace DinerContracts.ViewModels [DisplayName("Дата открытия")] public DateTime OpeningDate { get; set; } public Dictionary ShopSnacks { get; set; } = new(); + [DisplayName("Вместимость")] + public int SnackMaxCount { get; set; } } } \ No newline at end of file diff --git a/AbstractShopDataModels/Models/IShopModel.cs b/AbstractShopDataModels/Models/IShopModel.cs index e236e00..3e48cc7 100644 --- a/AbstractShopDataModels/Models/IShopModel.cs +++ b/AbstractShopDataModels/Models/IShopModel.cs @@ -14,5 +14,6 @@ namespace DinerDataModels.Models string Adress { get; } DateTime OpeningDate { get; } Dictionary ShopSnacks { get; } + public int SnackMaxCount { get; } } } \ No newline at end of file diff --git a/Diner/Diner/FormMain.Designer.cs b/Diner/Diner/FormMain.Designer.cs index 2f7fe59..8b18c18 100644 --- a/Diner/Diner/FormMain.Designer.cs +++ b/Diner/Diner/FormMain.Designer.cs @@ -38,9 +38,10 @@ toolStripLabel1 = new ToolStripDropDownButton(); componentsToolStripMenuItem = new ToolStripMenuItem(); snacksToolStripMenuItem = new ToolStripMenuItem(); + магазиныToolStripMenuItem = new ToolStripMenuItem(); toolStripDropDownButton1 = new ToolStripDropDownButton(); поставкаToolStripMenuItem = new ToolStripMenuItem(); - магазиныToolStripMenuItem = new ToolStripMenuItem(); + продажаToolStripMenuItem = new ToolStripMenuItem(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); toolStrip1.SuspendLayout(); SuspendLayout(); @@ -126,21 +127,28 @@ // componentsToolStripMenuItem // componentsToolStripMenuItem.Name = "componentsToolStripMenuItem"; - componentsToolStripMenuItem.Size = new Size(224, 26); + componentsToolStripMenuItem.Size = new Size(182, 26); componentsToolStripMenuItem.Text = "Компоненты"; componentsToolStripMenuItem.Click += ComponentToolStripMenuItem_Click; // // snacksToolStripMenuItem // snacksToolStripMenuItem.Name = "snacksToolStripMenuItem"; - snacksToolStripMenuItem.Size = new Size(224, 26); + snacksToolStripMenuItem.Size = new Size(182, 26); snacksToolStripMenuItem.Text = "Закуски"; snacksToolStripMenuItem.Click += ProductToolStripMenuItem_Click; // + // магазиныToolStripMenuItem + // + магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem"; + магазиныToolStripMenuItem.Size = new Size(182, 26); + магазиныToolStripMenuItem.Text = "Магазины"; + магазиныToolStripMenuItem.Click += shopsToolStripMenuItem_Click; + // // toolStripDropDownButton1 // toolStripDropDownButton1.DisplayStyle = ToolStripItemDisplayStyle.Text; - toolStripDropDownButton1.DropDownItems.AddRange(new ToolStripItem[] { поставкаToolStripMenuItem }); + toolStripDropDownButton1.DropDownItems.AddRange(new ToolStripItem[] { поставкаToolStripMenuItem, продажаToolStripMenuItem }); toolStripDropDownButton1.ImageTransparentColor = Color.Magenta; toolStripDropDownButton1.Name = "toolStripDropDownButton1"; toolStripDropDownButton1.Size = new Size(95, 24); @@ -153,12 +161,12 @@ поставкаToolStripMenuItem.Text = "Поставка"; поставкаToolStripMenuItem.Click += transactionToolStripMenuItem_Click; // - // магазиныToolStripMenuItem + // продажаToolStripMenuItem // - магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem"; - магазиныToolStripMenuItem.Size = new Size(224, 26); - магазиныToolStripMenuItem.Text = "Магазины"; - магазиныToolStripMenuItem.Click += shopsToolStripMenuItem_Click; + продажаToolStripMenuItem.Name = "продажаToolStripMenuItem"; + продажаToolStripMenuItem.Size = new Size(224, 26); + продажаToolStripMenuItem.Text = "Продажа"; + продажаToolStripMenuItem.Click += SellToolStripMenuItem_Click; // // FormMain // @@ -197,5 +205,6 @@ private ToolStripMenuItem магазиныToolStripMenuItem; private ToolStripDropDownButton toolStripDropDownButton1; private ToolStripMenuItem поставкаToolStripMenuItem; + private ToolStripMenuItem продажаToolStripMenuItem; } } \ No newline at end of file diff --git a/Diner/Diner/FormMain.cs b/Diner/Diner/FormMain.cs index b7fe7b9..19c9fc2 100644 --- a/Diner/Diner/FormMain.cs +++ b/Diner/Diner/FormMain.cs @@ -180,5 +180,13 @@ namespace Diner form.ShowDialog(); } } + private void SellToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormSellPizza)); + if (service is FormSellSnack form) + { + form.ShowDialog(); + } + } } } diff --git a/Diner/Diner/FormSell.Designer.cs b/Diner/Diner/FormSell.Designer.cs new file mode 100644 index 0000000..95509c4 --- /dev/null +++ b/Diner/Diner/FormSell.Designer.cs @@ -0,0 +1,117 @@ +namespace IceCreamShop +{ + partial class SellForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + 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; + } +} \ No newline at end of file diff --git a/Diner/Diner/FormSell.cs b/Diner/Diner/FormSell.cs new file mode 100644 index 0000000..96143c6 --- /dev/null +++ b/Diner/Diner/FormSell.cs @@ -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? _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; + } + } + } +} diff --git a/Diner/Diner/FormSell.resx b/Diner/Diner/FormSell.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/Diner/Diner/FormSell.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Diner/Diner/FormSellSnack.Designer.cs b/Diner/Diner/FormSellSnack.Designer.cs new file mode 100644 index 0000000..36fbfeb --- /dev/null +++ b/Diner/Diner/FormSellSnack.Designer.cs @@ -0,0 +1,119 @@ +namespace PizzeriaView +{ + partial class FormSellSnack + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + 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; + } +} \ No newline at end of file diff --git a/Diner/Diner/FormSellSnack.cs b/Diner/Diner/FormSellSnack.cs new file mode 100644 index 0000000..b6070ae --- /dev/null +++ b/Diner/Diner/FormSellSnack.cs @@ -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 _snackList = new List(); + public FormSellSnack(ILogger 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(); + } + } +} diff --git a/Diner/Diner/FormSellSnack.resx b/Diner/Diner/FormSellSnack.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/Diner/Diner/FormSellSnack.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Diner/Diner/FormShop.Designer.cs b/Diner/Diner/FormShop.Designer.cs index ee461b3..f7a0154 100644 --- a/Diner/Diner/FormShop.Designer.cs +++ b/Diner/Diner/FormShop.Designer.cs @@ -35,12 +35,15 @@ buttonCancel = new Button(); buttonSave = new Button(); dataGridView = new DataGridView(); - label1 = new Label(); - dateTimeOpen = new DateTimePicker(); id = new DataGridViewTextBoxColumn(); DinerName = 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)numericUpSnackMaxCount).BeginInit(); SuspendLayout(); // // labelName @@ -102,31 +105,15 @@ dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; dataGridView.Columns.AddRange(new DataGridViewColumn[] { id, DinerName, Count }); - dataGridView.Location = new Point(12, 144); + dataGridView.Location = new Point(12, 197); dataGridView.Name = "dataGridView"; dataGridView.ReadOnly = true; dataGridView.RowHeadersBorderStyle = DataGridViewHeaderBorderStyle.None; dataGridView.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.AutoSizeToDisplayedHeaders; dataGridView.RowTemplate.Height = 29; - dataGridView.Size = new Size(569, 307); + dataGridView.Size = new Size(569, 254); 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.HeaderText = "id"; @@ -149,11 +136,46 @@ Count.Name = "Count"; 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 // AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(593, 513); + Controls.Add(numericUpSnackMaxCount); + Controls.Add(label2); Controls.Add(dateTimeOpen); Controls.Add(label1); Controls.Add(dataGridView); @@ -167,6 +189,7 @@ Text = "Магазин"; Load += FormShop_Load; ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ((System.ComponentModel.ISupportInitialize)numericUpSnackMaxCount).EndInit(); ResumeLayout(false); PerformLayout(); } @@ -185,5 +208,7 @@ private DataGridViewTextBoxColumn id; private DataGridViewTextBoxColumn DinerName; private DataGridViewTextBoxColumn Count; + private Label label2; + private NumericUpDown numericUpSnackMaxCount; } } \ No newline at end of file diff --git a/Diner/Diner/FormShop.cs b/Diner/Diner/FormShop.cs index c34f982..2eacec2 100644 --- a/Diner/Diner/FormShop.cs +++ b/Diner/Diner/FormShop.cs @@ -48,6 +48,7 @@ namespace DinerView textBoxName.Text = view.ShopName; textBoxAdress.Text = view.Adress; dateTimeOpen.Value = view.OpeningDate; + numericUpSnackMaxCount.Value = view.SnackMaxCount; _ShopSnacks = view.ShopSnacks ?? new Dictionary(); LoadData(); } @@ -101,7 +102,8 @@ namespace DinerView Id = _id ?? 0, ShopName = textBoxName.Text, Adress = textBoxAdress.Text, - OpeningDate = dateTimeOpen.Value + OpeningDate = dateTimeOpen.Value, + SnackMaxCount = (int)numericUpSnackMaxCount.Value }; var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); if (!operationResult) diff --git a/Diner/Diner/Program.cs b/Diner/Diner/Program.cs index 8a61d8f..cbde433 100644 --- a/Diner/Diner/Program.cs +++ b/Diner/Diner/Program.cs @@ -1,6 +1,6 @@ using DinerContracts.BusinessLogicsContracts; using DinerContracts.StoragesContracts; -using DinerListImplement.Implements; +using DinerFileImplement.Implements; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using NLog.Extensions.Logging;