diff --git a/Confectionery/ConfectionaryContracts/ConfectioneryContracts.csproj b/Confectionery/ConfectionaryContracts/ConfectioneryContracts.csproj
index 5a76ab1..c07ce67 100644
--- a/Confectionery/ConfectionaryContracts/ConfectioneryContracts.csproj
+++ b/Confectionery/ConfectionaryContracts/ConfectioneryContracts.csproj
@@ -11,6 +11,8 @@
+
+
diff --git a/Confectionery/ConfectionaryContracts/StoragesContracts/IOrderStorage.cs b/Confectionery/ConfectionaryContracts/StoragesContracts/IOrderStorage.cs
index 5a3228c..cbdd94f 100644
--- a/Confectionery/ConfectionaryContracts/StoragesContracts/IOrderStorage.cs
+++ b/Confectionery/ConfectionaryContracts/StoragesContracts/IOrderStorage.cs
@@ -9,7 +9,7 @@ using System.Threading.Tasks;
namespace ConfectioneryContracts.StoragesContracts
{
- internal interface IOrderStorage
+ public interface IOrderStorage
{
List GetFullList();
List GetFilteredList(OrderSearchModel model);
diff --git a/Confectionery/ConfectionaryContracts/StoragesContracts/IPastryStorage.cs b/Confectionery/ConfectionaryContracts/StoragesContracts/IPastryStorage.cs
index f08be11..50d7584 100644
--- a/Confectionery/ConfectionaryContracts/StoragesContracts/IPastryStorage.cs
+++ b/Confectionery/ConfectionaryContracts/StoragesContracts/IPastryStorage.cs
@@ -9,7 +9,7 @@ using System.Threading.Tasks;
namespace ConfectioneryContracts.StoragesContracts
{
- internal interface IPastryStorage
+ public interface IPastryStorage
{
List GetFullList();
List GetFilteredList(PastrySearchModel model);
diff --git a/Confectionery/ConfectionaryDataModels/ConfectioneryDataModels.csproj b/Confectionery/ConfectionaryDataModels/ConfectioneryDataModels.csproj
index 792d358..8ee6bda 100644
--- a/Confectionery/ConfectionaryDataModels/ConfectioneryDataModels.csproj
+++ b/Confectionery/ConfectionaryDataModels/ConfectioneryDataModels.csproj
@@ -11,6 +11,8 @@
+
+
diff --git a/Confectionery/ConfectioneryBusinessLogic/ConfectioneryBusinessLogic.csproj b/Confectionery/ConfectioneryBusinessLogic/ConfectioneryBusinessLogic.csproj
index a03d415..3aceb59 100644
--- a/Confectionery/ConfectioneryBusinessLogic/ConfectioneryBusinessLogic.csproj
+++ b/Confectionery/ConfectioneryBusinessLogic/ConfectioneryBusinessLogic.csproj
@@ -11,6 +11,8 @@
+
+
diff --git a/Confectionery/ConfectioneryBusinessLogic/OrderLogic.cs b/Confectionery/ConfectioneryBusinessLogic/OrderLogic.cs
index 27e4feb..939b321 100644
--- a/Confectionery/ConfectioneryBusinessLogic/OrderLogic.cs
+++ b/Confectionery/ConfectioneryBusinessLogic/OrderLogic.cs
@@ -9,34 +9,127 @@ using ConfectioneryContracts.ViewModels;
using ConfectioneryContracts.BusinessLogicsContracts;
using ConfectioneryContracts.StoragesContracts;
using Microsoft.Extensions.Logging;
+using ConfectioneryDataModels.Enums;
-namespace ConfectioneryBusinessLogic
+namespace ConfectioneryBusinessLogic.BusinessLogics
{
- internal class OrderLogic : IOrderLogic
+ public class OrderLogic : IOrderLogic
{
+ private readonly ILogger _logger;
+
+ private readonly IOrderStorage _orderStorage;
+
+ public OrderLogic(ILogger logger, IOrderStorage orderStorage)
+ {
+ _logger = logger;
+ _orderStorage = orderStorage;
+ }
+
public bool CreateOrder(OrderBindingModel model)
{
- throw new NotImplementedException();
- }
-
- public bool DeliveryOrder(OrderBindingModel model)
- {
- throw new NotImplementedException();
- }
-
- public bool FinishOrder(OrderBindingModel model)
- {
- throw new NotImplementedException();
+ CheckModel(model);
+ if (model.Status != OrderStatus.Неизвестен)
+ {
+ _logger.LogWarning("Invalid order status");
+ return false;
+ }
+ model.Status = OrderStatus.Принят;
+ if (_orderStorage.Insert(model) == null)
+ {
+ _logger.LogWarning("Insert operation failed");
+ return false;
+ }
+ return true;
}
public List? ReadList(OrderSearchModel? model)
{
- throw new NotImplementedException();
+ _logger.LogInformation("ReadList. OrderId: {Id}.", model?.Id);
+ var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model);
+ if (list == null)
+ {
+ _logger.LogWarning("ReadList return null list");
+ return null;
+ }
+ _logger.LogInformation("ReadList. Count: {Count}", list.Count);
+ return list;
}
public bool TakeOrderInWork(OrderBindingModel model)
{
- throw new NotImplementedException();
+ return ChangeStatus(model, OrderStatus.Выполняется);
+ }
+
+ public bool FinishOrder(OrderBindingModel model)
+ {
+ return ChangeStatus(model, OrderStatus.Готов);
+ }
+
+ public bool DeliveryOrder(OrderBindingModel model)
+ {
+ return ChangeStatus(model, OrderStatus.Выдан);
+ }
+
+ private void CheckModel(OrderBindingModel model, bool withParams = true)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+ if (!withParams)
+ {
+ return;
+ }
+ if (model.PastryId <= 0)
+ {
+ throw new ArgumentNullException("Некорректный идентификатор мороженого", nameof(model.PastryId));
+ }
+ if (model.Count <= 0)
+ {
+ throw new ArgumentNullException("В заказе должно быть хотя бы одно мороженое", nameof(model.Count));
+ }
+ if (model.Sum <= 0)
+ {
+ throw new ArgumentNullException("Стоимость заказа должна быть больше 0", nameof(model.Sum));
+ }
+ _logger.LogInformation("Order. Id: {Id}. Sum: {Sum}. PastryId: {PastryId}. PastryCount: {Count}", model.Id, model.Sum,
+ model.PastryId, model.Count);
+ }
+
+ private bool ChangeStatus(OrderBindingModel model, OrderStatus newStatus)
+ {
+ CheckModel(model, false);
+ var order = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id });
+ if (order == null)
+ {
+ _logger.LogWarning("Change status operation failed. Order not found");
+ return false;
+ }
+ if (order.Status + 1 != newStatus)
+ {
+ _logger.LogWarning("Change status operation failed. Incorrect new status: {newStatus}. Current status: {currStatus}",
+ newStatus, order.Status);
+ return false;
+ }
+ model.PastryId = order.PastryId;
+ model.Count = order.Count;
+ model.Sum = order.Sum;
+ model.DateCreate = order.DateCreate;
+ model.Status = newStatus;
+ if (model.Status == OrderStatus.Готов)
+ {
+ model.DateImplement = DateTime.Now;
+ }
+ else
+ {
+ model.DateImplement = order.DateImplement;
+ }
+ if (_orderStorage.Update(model) == null)
+ {
+ _logger.LogWarning("Change status operation failed");
+ return false;
+ }
+ return true;
}
}
}
diff --git a/Confectionery/ConfectioneryBusinessLogic/PastryLogic.cs b/Confectionery/ConfectioneryBusinessLogic/PastryLogic.cs
index d8a5d69..781d3a1 100644
--- a/Confectionery/ConfectioneryBusinessLogic/PastryLogic.cs
+++ b/Confectionery/ConfectioneryBusinessLogic/PastryLogic.cs
@@ -12,31 +12,113 @@ using Microsoft.Extensions.Logging;
namespace ConfectioneryBusinessLogic.BusinessLogics
{
- internal class PastryLogic : IPastryLogic
+ public class PastryLogic : IPastryLogic
{
- public bool Create(PastryBindingModel model)
- {
- throw new NotImplementedException();
- }
+ private readonly ILogger _logger;
- public bool Delete(PastryBindingModel model)
- {
- throw new NotImplementedException();
- }
+ private readonly IPastryStorage _iceCreamStorage;
- public PastryViewModel? ReadElement(PastrySearchModel model)
+ public PastryLogic(ILogger logger, IPastryStorage iceCreamStorage)
{
- throw new NotImplementedException();
+ _logger = logger;
+ _iceCreamStorage = iceCreamStorage;
}
public List? ReadList(PastrySearchModel? model)
{
- throw new NotImplementedException();
+ _logger.LogInformation("ReadList. PastryName: {PastryName}. Id: {Id}", model?.PastryName, model?.Id);
+ var list = model == null ? _iceCreamStorage.GetFullList() : _iceCreamStorage.GetFilteredList(model);
+ if (list == null)
+ {
+ _logger.LogWarning("ReadList return null list");
+ return null;
+ }
+ _logger.LogInformation("ReadList. Count: {Count}", list.Count);
+ return list;
+ }
+
+ public PastryViewModel? ReadElement(PastrySearchModel model)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+ _logger.LogInformation("ReadElement. PastryName: {PastryName}. Id: {Id}", model.PastryName, model.Id);
+ var element = _iceCreamStorage.GetElement(model);
+ if (element == null)
+ {
+ _logger.LogWarning("ReadElement element not found");
+ return null;
+ }
+ _logger.LogInformation("ReadElement find. Id: {Id}", element.Id);
+ return element;
+ }
+
+ public bool Create(PastryBindingModel model)
+ {
+ CheckModel(model);
+ if (_iceCreamStorage.Insert(model) == null)
+ {
+ _logger.LogWarning("Insert operation failed");
+ return false;
+ }
+ return true;
}
public bool Update(PastryBindingModel model)
{
- throw new NotImplementedException();
+ CheckModel(model);
+ if (_iceCreamStorage.Update(model) == null)
+ {
+ _logger.LogWarning("Update operation failed");
+ return false;
+ }
+ return true;
+ }
+
+ public bool Delete(PastryBindingModel model)
+ {
+ CheckModel(model, false);
+ _logger.LogInformation("Delete. Id: {Id}", model.Id);
+ if (_iceCreamStorage.Delete(model) == null)
+ {
+ _logger.LogWarning("Delete operation failed");
+ return false;
+ }
+ return true;
+ }
+
+ private void CheckModel(PastryBindingModel model, bool withParams = true)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+ if (!withParams)
+ {
+ return;
+ }
+ if (string.IsNullOrEmpty(model.PastryName))
+ {
+ throw new ArgumentNullException("Нет названия мороженого", nameof(model.PastryName));
+ }
+ if (model.Price <= 0)
+ {
+ throw new ArgumentNullException("Цена мороженого должна быть больше 0", nameof(model.Price));
+ }
+ if (model.PastryComponents == null || model.PastryComponents.Count == 0)
+ {
+ throw new ArgumentNullException("Мороженое должно состоять хотя бы из одного компонента");
+ }
+ _logger.LogInformation("Pastry. PastryName: {PastryName}. Price: {Price}. Id: {Id}", model.PastryName, model.Price, model.Id);
+ var element = _iceCreamStorage.GetElement(new PastrySearchModel
+ {
+ PastryName = model.PastryName
+ });
+ if (element != null && element.Id != model.Id)
+ {
+ throw new InvalidOperationException("Мороженое с таким названием уже есть");
+ }
}
}
}
diff --git a/Confectionery/ConfectioneryListImplement/ComponentStorage.cs b/Confectionery/ConfectioneryListImplement/ComponentStorage.cs
index 03ed3c0..a57bac3 100644
--- a/Confectionery/ConfectioneryListImplement/ComponentStorage.cs
+++ b/Confectionery/ConfectioneryListImplement/ComponentStorage.cs
@@ -11,7 +11,7 @@ using System.Threading.Tasks;
namespace ConfectioneryListImplement.Implements
{
- internal class ComponentStorage : IComponentStorage
+ public class ComponentStorage : IComponentStorage
{
private readonly DataListSingleton _source;
public ComponentStorage()
diff --git a/Confectionery/ConfectioneryListImplement/ConfectioneryListImplement.csproj b/Confectionery/ConfectioneryListImplement/ConfectioneryListImplement.csproj
index 54e27de..9fd6be9 100644
--- a/Confectionery/ConfectioneryListImplement/ConfectioneryListImplement.csproj
+++ b/Confectionery/ConfectioneryListImplement/ConfectioneryListImplement.csproj
@@ -6,6 +6,11 @@
enable
+
+
+
+
+
diff --git a/Confectionery/ConfectioneryListImplement/DataListSingleton.cs b/Confectionery/ConfectioneryListImplement/DataListSingleton.cs
index 7068cc9..c823733 100644
--- a/Confectionery/ConfectioneryListImplement/DataListSingleton.cs
+++ b/Confectionery/ConfectioneryListImplement/DataListSingleton.cs
@@ -11,12 +11,12 @@ namespace ConfectioneryListImplement.Models
private static DataListSingleton? _instance;
public List Components { get; set; }
public List Orders { get; set; }
- public List Pastrys { get; set; }
+ public List Pastries { get; set; }
private DataListSingleton()
{
Components = new List();
Orders = new List();
- Pastrys = new List();
+ Pastries = new List();
}
public static DataListSingleton GetInstance()
{
diff --git a/Confectionery/ConfectioneryListImplement/OrderStorage.cs b/Confectionery/ConfectioneryListImplement/OrderStorage.cs
new file mode 100644
index 0000000..c4c13e2
--- /dev/null
+++ b/Confectionery/ConfectioneryListImplement/OrderStorage.cs
@@ -0,0 +1,122 @@
+using ConfectioneryContracts.BindingModels;
+using ConfectioneryContracts.SearchModels;
+using ConfectioneryContracts.StoragesContracts;
+using ConfectioneryContracts.ViewModels;
+using ConfectioneryListImplement.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ConfectioneryListImplement.Implements
+{
+ public class OrderStorage : IOrderStorage
+ {
+ private readonly DataListSingleton _source;
+
+ public OrderStorage()
+ {
+ _source = DataListSingleton.GetInstance();
+ }
+
+ public List GetFullList()
+ {
+ var result = new List();
+ foreach (var order in _source.Orders)
+ {
+ result.Add(AddPastryName(order.GetViewModel));
+ }
+ return result;
+ }
+
+ public List GetFilteredList(OrderSearchModel model)
+ {
+ var result = new List();
+ if (!model.Id.HasValue)
+ {
+ return result;
+ }
+ foreach (var order in _source.Orders)
+ {
+ if (order.Id == model.Id)
+ {
+ result.Add(AddPastryName(order.GetViewModel));
+ }
+ }
+ return result;
+ }
+
+ public OrderViewModel? GetElement(OrderSearchModel model)
+ {
+ if (!model.Id.HasValue)
+ {
+ return null;
+ }
+ foreach (var order in _source.Orders)
+ {
+ if (order.Id == model.Id)
+ {
+ return AddPastryName(order.GetViewModel);
+ }
+ }
+ return null;
+ }
+
+ public OrderViewModel? Insert(OrderBindingModel model)
+ {
+ model.Id = 1;
+ foreach (var order in _source.Orders)
+ {
+ if (model.Id <= order.Id)
+ {
+ model.Id = order.Id + 1;
+ }
+ }
+ var newOrder = Order.Create(model);
+ if (newOrder == null)
+ {
+ return null;
+ }
+ _source.Orders.Add(newOrder);
+ return AddPastryName(newOrder.GetViewModel);
+ }
+
+ public OrderViewModel? Update(OrderBindingModel model)
+ {
+ foreach (var order in _source.Orders)
+ {
+ if (order.Id == model.Id)
+ {
+ order.Update(model);
+ return AddPastryName(order.GetViewModel);
+ }
+ }
+ return null;
+ }
+
+ public OrderViewModel? Delete(OrderBindingModel model)
+ {
+ for (int i = 0; i < _source.Orders.Count; ++i)
+ {
+ if (_source.Orders[i].Id == model.Id)
+ {
+ var element = _source.Orders[i];
+ _source.Orders.RemoveAt(i);
+ return AddPastryName(element.GetViewModel);
+ }
+ }
+ return null;
+ }
+
+ private OrderViewModel AddPastryName(OrderViewModel model)
+ {
+ var selectedPastry = _source.Pastries.Find(pastry => pastry.Id == model.PastryId);
+ if (selectedPastry != null)
+ {
+ model.PastryName = selectedPastry.PastryName;
+ }
+ return model;
+ }
+ }
+}
diff --git a/Confectionery/ConfectioneryListImplement/PastryStorage.cs b/Confectionery/ConfectioneryListImplement/PastryStorage.cs
new file mode 100644
index 0000000..3231fe7
--- /dev/null
+++ b/Confectionery/ConfectioneryListImplement/PastryStorage.cs
@@ -0,0 +1,114 @@
+using ConfectioneryContracts.StoragesContracts;
+using ConfectioneryContracts.ViewModels;
+using ConfectioneryContracts.SearchModels;
+using ConfectioneryContracts.BindingModels;
+using ConfectioneryListImplement.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ConfectioneryListImplement.Implements
+{
+ public class PastryStorage : IPastryStorage
+ {
+ private readonly DataListSingleton _source;
+
+ public PastryStorage()
+ {
+ _source = DataListSingleton.GetInstance();
+ }
+
+ public List GetFullList()
+ {
+ var result = new List();
+ foreach (var pastry in _source.Pastries)
+ {
+ result.Add(pastry.GetViewModel);
+ }
+ return result;
+ }
+
+ public List GetFilteredList(PastrySearchModel model)
+ {
+ var result = new List();
+ if (string.IsNullOrEmpty(model.PastryName))
+ {
+ return result;
+ }
+ foreach (var pastry in _source.Pastries)
+ {
+ if (pastry.PastryName.Contains(model.PastryName))
+ {
+ result.Add(pastry.GetViewModel);
+ }
+ }
+ return result;
+ }
+
+ public PastryViewModel? GetElement(PastrySearchModel model)
+ {
+ if (string.IsNullOrEmpty(model.PastryName) && !model.Id.HasValue)
+ {
+ return null;
+ }
+ foreach (var pastry in _source.Pastries)
+ {
+ if ((!string.IsNullOrEmpty(model.PastryName) &&
+ pastry.PastryName == model.PastryName) ||
+ (model.Id.HasValue && pastry.Id == model.Id))
+ {
+ return pastry.GetViewModel;
+ }
+ }
+ return null;
+ }
+
+ public PastryViewModel? Insert(PastryBindingModel model)
+ {
+ model.Id = 1;
+ foreach (var pastry in _source.Pastries)
+ {
+ if (model.Id <= pastry.Id)
+ {
+ model.Id = pastry.Id + 1;
+ }
+ }
+ var newPastry = Pastry.Create(model);
+ if (newPastry == null)
+ {
+ return null;
+ }
+ _source.Pastries.Add(newPastry);
+ return newPastry.GetViewModel;
+ }
+
+ public PastryViewModel? Update(PastryBindingModel model)
+ {
+ foreach (var pastry in _source.Pastries)
+ {
+ if (pastry.Id == model.Id)
+ {
+ pastry.Update(model);
+ return pastry.GetViewModel;
+ }
+ }
+ return null;
+ }
+
+ public PastryViewModel? Delete(PastryBindingModel model)
+ {
+ for (int i = 0; i < _source.Pastries.Count; ++i)
+ {
+ if (_source.Pastries[i].Id == model.Id)
+ {
+ var element = _source.Pastries[i];
+ _source.Pastries.RemoveAt(i);
+ return element.GetViewModel;
+ }
+ }
+ return null;
+ }
+ }
+}
diff --git a/Confectionery/ConfectioneryView/ConfectioneryView.csproj b/Confectionery/ConfectioneryView/ConfectioneryView.csproj
index 55e33bf..0c70544 100644
--- a/Confectionery/ConfectioneryView/ConfectioneryView.csproj
+++ b/Confectionery/ConfectioneryView/ConfectioneryView.csproj
@@ -19,6 +19,8 @@
+
+
diff --git a/Confectionery/ConfectioneryView/FormMain.Designer.cs b/Confectionery/ConfectioneryView/FormMain.Designer.cs
index 9f6753d..61c24bb 100644
--- a/Confectionery/ConfectioneryView/FormMain.Designer.cs
+++ b/Confectionery/ConfectioneryView/FormMain.Designer.cs
@@ -32,14 +32,14 @@
this.справочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.компонентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.изделияToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
- this.dataGridView1 = new System.Windows.Forms.DataGridView();
+ this.dataGridView = new System.Windows.Forms.DataGridView();
this.ButtonCreateOrder = new System.Windows.Forms.Button();
this.ButtonTakeOrderInWork = new System.Windows.Forms.Button();
this.ButtonOrderReady = new System.Windows.Forms.Button();
this.ButtonIssuedOrder = new System.Windows.Forms.Button();
this.ButtonRef = new System.Windows.Forms.Button();
this.menuStrip1.SuspendLayout();
- ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.SuspendLayout();
//
// menuStrip1
@@ -67,22 +67,24 @@
this.компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem";
this.компонентыToolStripMenuItem.Size = new System.Drawing.Size(224, 26);
this.компонентыToolStripMenuItem.Text = "Компоненты";
+ this.компонентыToolStripMenuItem.Click += new System.EventHandler(this.КомпонентыToolStripMenuItem_Click);
//
// изделияToolStripMenuItem
//
this.изделияToolStripMenuItem.Name = "изделияToolStripMenuItem";
this.изделияToolStripMenuItem.Size = new System.Drawing.Size(224, 26);
this.изделияToolStripMenuItem.Text = "Изделия";
+ this.изделияToolStripMenuItem.Click += new System.EventHandler(this.ИзделияToolStripMenuItem_Click);
//
- // dataGridView1
+ // dataGridView
//
- this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
- this.dataGridView1.Location = new System.Drawing.Point(13, 31);
- this.dataGridView1.Name = "dataGridView1";
- this.dataGridView1.RowHeadersWidth = 51;
- this.dataGridView1.RowTemplate.Height = 29;
- this.dataGridView1.Size = new System.Drawing.Size(968, 526);
- this.dataGridView1.TabIndex = 1;
+ this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ this.dataGridView.Location = new System.Drawing.Point(13, 31);
+ this.dataGridView.Name = "dataGridView";
+ this.dataGridView.RowHeadersWidth = 51;
+ this.dataGridView.RowTemplate.Height = 29;
+ this.dataGridView.Size = new System.Drawing.Size(968, 526);
+ this.dataGridView.TabIndex = 1;
//
// ButtonCreateOrder
//
@@ -144,7 +146,7 @@
this.Controls.Add(this.ButtonOrderReady);
this.Controls.Add(this.ButtonTakeOrderInWork);
this.Controls.Add(this.ButtonCreateOrder);
- this.Controls.Add(this.dataGridView1);
+ this.Controls.Add(this.dataGridView);
this.Controls.Add(this.menuStrip1);
this.MainMenuStrip = this.menuStrip1;
this.Name = "FormMain";
@@ -152,7 +154,7 @@
this.Load += new System.EventHandler(this.FormMain_Load);
this.menuStrip1.ResumeLayout(false);
this.menuStrip1.PerformLayout();
- ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
@@ -164,7 +166,7 @@
private ToolStripMenuItem справочникиToolStripMenuItem;
private ToolStripMenuItem компонентыToolStripMenuItem;
private ToolStripMenuItem изделияToolStripMenuItem;
- private DataGridView dataGridView1;
+ private DataGridView dataGridView;
private Button ButtonCreateOrder;
private Button ButtonTakeOrderInWork;
private Button ButtonOrderReady;
diff --git a/Confectionery/ConfectioneryView/FormMain.cs b/Confectionery/ConfectioneryView/FormMain.cs
index 02c0bf6..b6a28cf 100644
--- a/Confectionery/ConfectioneryView/FormMain.cs
+++ b/Confectionery/ConfectioneryView/FormMain.cs
@@ -31,8 +31,22 @@ namespace ConfectioneryView
private void LoadData()
{
- _logger.LogInformation("Загрузка заказов");
- // прописать логику
+ try
+ {
+ var list = _orderLogic.ReadList(null);
+ if (list != null)
+ {
+ dataGridView.DataSource = list;
+ dataGridView.Columns["PastryId"].Visible = false;
+ dataGridView.Columns["PastryName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
+ }
+ _logger.LogInformation("Orders loading");
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Orders loading error");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
}
private void КомпонентыToolStripMenuItem_Click(object sender, EventArgs e)
@@ -47,7 +61,11 @@ namespace ConfectioneryView
private void ИзделияToolStripMenuItem_Click(object sender, EventArgs e)
{
- // прописать логику
+ var service = Program.ServiceProvider?.GetService(typeof(FormPastries));
+ if (service is FormPastries form)
+ {
+ form.ShowDialog();
+ }
}
private void ButtonCreateOrder_Click(object sender, EventArgs e)
diff --git a/Confectionery/ConfectioneryView/FormPastries.Designer.cs b/Confectionery/ConfectioneryView/FormPastries.Designer.cs
new file mode 100644
index 0000000..d1f2fa9
--- /dev/null
+++ b/Confectionery/ConfectioneryView/FormPastries.Designer.cs
@@ -0,0 +1,110 @@
+namespace ConfectioneryView
+{
+ partial class FormPastries
+ {
+ ///
+ /// 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()
+ {
+ this.dataGridView = new System.Windows.Forms.DataGridView();
+ this.ButtonUpd = new System.Windows.Forms.Button();
+ this.ButtonDel = new System.Windows.Forms.Button();
+ this.ButtonRef = new System.Windows.Forms.Button();
+ this.ButtonAdd = new System.Windows.Forms.Button();
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
+ this.SuspendLayout();
+ //
+ // dataGridView
+ //
+ this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ this.dataGridView.Location = new System.Drawing.Point(12, 12);
+ this.dataGridView.Name = "dataGridView";
+ this.dataGridView.RowHeadersWidth = 51;
+ this.dataGridView.RowTemplate.Height = 29;
+ this.dataGridView.Size = new System.Drawing.Size(490, 426);
+ this.dataGridView.TabIndex = 0;
+ //
+ // ButtonUpd
+ //
+ this.ButtonUpd.Location = new System.Drawing.Point(530, 94);
+ this.ButtonUpd.Name = "ButtonUpd";
+ this.ButtonUpd.Size = new System.Drawing.Size(111, 32);
+ this.ButtonUpd.TabIndex = 8;
+ this.ButtonUpd.Text = "Изменить";
+ this.ButtonUpd.UseVisualStyleBackColor = true;
+ //
+ // ButtonDel
+ //
+ this.ButtonDel.Location = new System.Drawing.Point(530, 163);
+ this.ButtonDel.Name = "ButtonDel";
+ this.ButtonDel.Size = new System.Drawing.Size(111, 32);
+ this.ButtonDel.TabIndex = 7;
+ this.ButtonDel.Text = "Удалить";
+ this.ButtonDel.UseVisualStyleBackColor = true;
+ //
+ // ButtonRef
+ //
+ this.ButtonRef.Location = new System.Drawing.Point(530, 232);
+ this.ButtonRef.Name = "ButtonRef";
+ this.ButtonRef.Size = new System.Drawing.Size(111, 32);
+ this.ButtonRef.TabIndex = 6;
+ this.ButtonRef.Text = "Обновить";
+ this.ButtonRef.UseVisualStyleBackColor = true;
+ //
+ // ButtonAdd
+ //
+ this.ButtonAdd.Location = new System.Drawing.Point(530, 26);
+ this.ButtonAdd.Name = "ButtonAdd";
+ this.ButtonAdd.Size = new System.Drawing.Size(111, 32);
+ this.ButtonAdd.TabIndex = 5;
+ this.ButtonAdd.Text = "Добавить";
+ this.ButtonAdd.UseVisualStyleBackColor = true;
+ //
+ // FormPastries
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(670, 450);
+ this.Controls.Add(this.ButtonUpd);
+ this.Controls.Add(this.ButtonDel);
+ this.Controls.Add(this.ButtonRef);
+ this.Controls.Add(this.ButtonAdd);
+ this.Controls.Add(this.dataGridView);
+ this.Name = "FormPastries";
+ this.Text = "Выпечка";
+ ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
+ this.ResumeLayout(false);
+
+ }
+
+ #endregion
+
+ private DataGridView dataGridView;
+ private Button ButtonUpd;
+ private Button ButtonDel;
+ private Button ButtonRef;
+ private Button ButtonAdd;
+ }
+}
\ No newline at end of file
diff --git a/Confectionery/ConfectioneryView/FormPastries.cs b/Confectionery/ConfectioneryView/FormPastries.cs
new file mode 100644
index 0000000..7932f5b
--- /dev/null
+++ b/Confectionery/ConfectioneryView/FormPastries.cs
@@ -0,0 +1,112 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+using Microsoft.Extensions.Logging;
+using ConfectioneryContracts.BindingModels;
+using ConfectioneryContracts.BusinessLogicsContracts;
+
+namespace ConfectioneryView
+{
+ public partial class FormPastries : Form
+ {
+ private readonly ILogger _logger;
+
+ private readonly IPastryLogic _logic;
+ public FormPastries(ILogger logger, IPastryLogic logic)
+ {
+ InitializeComponent();
+ _logger = logger;
+ _logic = logic;
+ }
+
+ private void FormPastrys_Load(object sender, EventArgs e)
+ {
+ LoadData();
+ }
+
+ private void LoadData()
+ {
+ try
+ {
+ var list = _logic.ReadList(null);
+ if (list != null)
+ {
+ dataGridView.DataSource = list;
+ dataGridView.Columns["Id"].Visible = false;
+ dataGridView.Columns["PastryName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
+ dataGridView.Columns["PastryComponents"].Visible = false;
+ }
+ _logger.LogInformation("Pastries loading");
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Pastries loading error");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+
+ private void ButtonAdd_Click(object sender, EventArgs e)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormPastry));
+ if (service is FormPastry form)
+ {
+ if (form.ShowDialog() == DialogResult.OK)
+ {
+ LoadData();
+ }
+ }
+ }
+
+ private void ButtonEdit_Click(object sender, EventArgs e)
+ {
+ if (dataGridView.SelectedRows.Count == 1)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormPastry));
+ if (service is FormPastry form)
+ {
+ form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
+ if (form.ShowDialog() == DialogResult.OK)
+ {
+ LoadData();
+ }
+ }
+ }
+ }
+
+ private void ButtonDel_Click(object sender, EventArgs e)
+ {
+ if (dataGridView.SelectedRows.Count == 1)
+ {
+ if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
+ {
+ int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
+ _logger.LogInformation("Deletion of ice cream");
+ try
+ {
+ if (!_logic.Delete(new PastryBindingModel { Id = id }))
+ {
+ throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
+ }
+ LoadData();
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ice cream deletion error");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ }
+ }
+
+ private void ButtonUpd_Click(object sender, EventArgs e)
+ {
+ LoadData();
+ }
+ }
+}
diff --git a/Confectionery/ConfectioneryView/FormPastries.resx b/Confectionery/ConfectioneryView/FormPastries.resx
new file mode 100644
index 0000000..f298a7b
--- /dev/null
+++ b/Confectionery/ConfectioneryView/FormPastries.resx
@@ -0,0 +1,60 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 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/Confectionery/ConfectioneryView/Program.cs b/Confectionery/ConfectioneryView/Program.cs
index 575f8c6..cebaeea 100644
--- a/Confectionery/ConfectioneryView/Program.cs
+++ b/Confectionery/ConfectioneryView/Program.cs
@@ -1,4 +1,10 @@
+using ConfectioneryBusinessLogic.BusinessLogics;
+using ConfectioneryContracts.BusinessLogicsContracts;
+using ConfectioneryContracts.StoragesContracts;
+using ConfectioneryListImplement.Implements;
using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Logging;
+using NLog.Extensions.Logging;
namespace ConfectioneryView
{
@@ -15,7 +21,33 @@ namespace ConfectioneryView
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
- Application.Run(new FormComponent());
+ var services = new ServiceCollection();
+ ConfigureServices(services);
+ _serviceProvider = services.BuildServiceProvider();
+ Application.Run(_serviceProvider.GetRequiredService());
+ }
+ private static void ConfigureServices(ServiceCollection services)
+ {
+ services.AddLogging(option =>
+ {
+ option.SetMinimumLevel(LogLevel.Information);
+ option.AddNLog("nlog.config");
+ });
+ services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
+
+ services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
+
+ services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
}
}
}
\ No newline at end of file