diff --git a/Components/BusinessLogics/BusinessLogics.csproj b/Components/BusinessLogics/BusinessLogics.csproj
new file mode 100644
index 0000000..dc4e44e
--- /dev/null
+++ b/Components/BusinessLogics/BusinessLogics.csproj
@@ -0,0 +1,14 @@
+
+
+
+ net6.0
+ enable
+ enable
+
+
+
+
+
+
+
+
diff --git a/Components/BusinessLogics/BusinessLogics/OrderLogic.cs b/Components/BusinessLogics/BusinessLogics/OrderLogic.cs
new file mode 100644
index 0000000..61a261a
--- /dev/null
+++ b/Components/BusinessLogics/BusinessLogics/OrderLogic.cs
@@ -0,0 +1,173 @@
+using Contracts.BindingModels;
+using Contracts.BusinessLogicsContracts;
+using Contracts.SearchModels;
+using Contracts.StoragesContracts;
+using Contracts.ViewModels;
+using Microsoft.Extensions.Logging;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BusinessLogics.BusinessLogics
+{
+ ///
+ /// Бизнес-логика для сущности "Счет"
+ ///
+ public class OrderLogic : IOrderLogic
+ {
+ ///
+ /// Логгер
+ ///
+ private readonly ILogger _logger;
+
+ ///
+ /// Хранилище
+ ///
+ private readonly IOrderStorage _orderStorage;
+
+ ///
+ /// Конструктор
+ ///
+ ///
+ ///
+ public OrderLogic(ILogger logger, IOrderStorage orderStorage)
+ {
+ _logger = logger;
+ _orderStorage = orderStorage;
+ }
+
+ ///
+ /// Получить список записией
+ ///
+ ///
+ ///
+ public List? ReadList(OrderSearchModel? model)
+ {
+ _logger.LogInformation("ReadList. Order.Id: {Id}", model?.Id);
+
+ var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model);
+ if (list == null)
+ {
+ _logger.LogWarning("ReadList. Returned null list");
+ return null;
+ }
+
+ _logger.LogInformation("ReadList. Count: {Count}", list.Count);
+ return list;
+ }
+
+ ///
+ /// Получить отдельную запись
+ ///
+ ///
+ ///
+ ///
+ public OrderViewModel? ReadElement(OrderSearchModel model)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+
+ _logger.LogInformation("ReadElement. Order.Id: {Id}", model?.Id);
+
+ var element = _orderStorage.GetElement(model!);
+ if (element == null)
+ {
+ _logger.LogWarning("ReadElement. Element not found");
+ return null;
+ }
+
+ _logger.LogInformation("ReadElement. Find Order.Id: {Id}", element.Id);
+ return element;
+ }
+
+ ///
+ /// Создать запись
+ ///
+ ///
+ ///
+ public bool Create(OrderBindingModel model)
+ {
+ CheckModel(model);
+ _logger.LogInformation("Create. Order.Id: {Id}", model.Id);
+
+ if (_orderStorage.Insert(model) == null)
+ {
+ _logger.LogWarning("Insert operation failed");
+ return false;
+ }
+ return true;
+ }
+
+ ///
+ /// Изменить запись
+ ///
+ ///
+ ///
+ public bool Update(OrderBindingModel model)
+ {
+ CheckModel(model);
+ _logger.LogInformation("Update. Order.Id: {Id}", model.Id);
+
+ if (_orderStorage.Update(model) == null)
+ {
+ _logger.LogWarning("Update operation failed");
+ return false;
+ }
+ return true;
+ }
+
+ ///
+ /// Удалить запись
+ ///
+ ///
+ ///
+ public bool Delete(OrderBindingModel model)
+ {
+ CheckModel(model, false);
+ _logger.LogInformation("Delete. Order.Id: {Id}", model.Id);
+
+ if (_orderStorage.Delete(model) == null)
+ {
+ _logger.LogWarning("Delete operation failed");
+ return false;
+ }
+ return true;
+ }
+
+ ///
+ /// Проверить модель
+ ///
+ ///
+ ///
+ ///
+ private void CheckModel(OrderBindingModel model, bool withParams = true)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+ if (!withParams)
+ {
+ return;
+ }
+ if (string.IsNullOrEmpty(model.WaiterFullName))
+ {
+ throw new ArgumentNullException("Не указано ФИО официанта", nameof(model.WaiterFullName));
+ }
+ if (string.IsNullOrEmpty(model.Info))
+ {
+ throw new ArgumentNullException("Не указана информация по счету", nameof(model.Info));
+ }
+ if (string.IsNullOrEmpty(model.Type))
+ {
+ throw new ArgumentNullException("Не указан тип заказа", nameof(model.Type));
+ }
+
+ _logger.LogInformation("CheckModel. Order.Id: {Id}", model.Id);
+ }
+ }
+}
diff --git a/Components/BusinessLogics/BusinessLogics/OrderTypeLogic.cs b/Components/BusinessLogics/BusinessLogics/OrderTypeLogic.cs
new file mode 100644
index 0000000..60b74e2
--- /dev/null
+++ b/Components/BusinessLogics/BusinessLogics/OrderTypeLogic.cs
@@ -0,0 +1,165 @@
+using Contracts.BindingModels;
+using Contracts.BusinessLogicsContracts;
+using Contracts.SearchModels;
+using Contracts.StoragesContracts;
+using Contracts.ViewModels;
+using Microsoft.Extensions.Logging;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BusinessLogics.BusinessLogics
+{
+ ///
+ /// Бизнес-логика для сущности "Тип заказа"
+ ///
+ public class OrderTypeLogic : IOrderTypeLogic
+ {
+ ///
+ /// Логгер
+ ///
+ private readonly ILogger _logger;
+
+ ///
+ /// Хранилище
+ ///
+ private readonly IOrderTypeStorage _orderTypeStorage;
+
+ ///
+ /// Конструктор
+ ///
+ ///
+ ///
+ public OrderTypeLogic(ILogger logger, IOrderTypeStorage orderTypeStorage)
+ {
+ _logger = logger;
+ _orderTypeStorage = orderTypeStorage;
+ }
+
+ ///
+ /// Получить список записией
+ ///
+ ///
+ ///
+ public List? ReadList(OrderTypeSearchModel? model)
+ {
+ _logger.LogInformation("ReadList. OrderType.Id: {Id}", model?.Id);
+
+ var list = model == null ? _orderTypeStorage.GetFullList() : _orderTypeStorage.GetFilteredList(model);
+ if (list == null)
+ {
+ _logger.LogWarning("ReadList. Returned null list");
+ return null;
+ }
+
+ _logger.LogInformation("ReadList. Count: {Count}", list.Count);
+ return list;
+ }
+
+ ///
+ /// Получить отдельную запись
+ ///
+ ///
+ ///
+ ///
+ public OrderTypeViewModel? ReadElement(OrderTypeSearchModel model)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+
+ _logger.LogInformation("ReadElement. OrderType.Id: {Id}", model?.Id);
+
+ var element = _orderTypeStorage.GetElement(model!);
+ if (element == null)
+ {
+ _logger.LogWarning("ReadElement. Element not found");
+ return null;
+ }
+
+ _logger.LogInformation("ReadElement. Find OrderType.Id: {Id}", element.Id);
+ return element;
+ }
+
+ ///
+ /// Создать запись
+ ///
+ ///
+ ///
+ public bool Create(OrderTypeBindingModel model)
+ {
+ CheckModel(model);
+ _logger.LogInformation("Create. OrderType.Id: {Id}", model.Id);
+
+ if (_orderTypeStorage.Insert(model) == null)
+ {
+ _logger.LogWarning("Insert operation failed");
+ return false;
+ }
+ return true;
+ }
+
+ ///
+ /// Изменить запись
+ ///
+ ///
+ ///
+ public bool Update(OrderTypeBindingModel model)
+ {
+ CheckModel(model);
+ _logger.LogInformation("Update. OrderType.Id: {Id}", model.Id);
+
+ if (_orderTypeStorage.Update(model) == null)
+ {
+ _logger.LogWarning("Update operation failed");
+ return false;
+ }
+ return true;
+ }
+
+ ///
+ /// Удалить запись
+ ///
+ ///
+ ///
+ public bool Delete(OrderTypeBindingModel model)
+ {
+ CheckModel(model, false);
+ _logger.LogInformation("Delete. OrderType.Id: {Id}", model.Id);
+
+ if (_orderTypeStorage.Delete(model) == null)
+ {
+ _logger.LogWarning("Delete operation failed");
+ return false;
+ }
+ return true;
+ }
+
+ ///
+ /// Проверить модель
+ ///
+ ///
+ ///
+ ///
+ private void CheckModel(OrderTypeBindingModel model, bool withParams = true)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+ if (!withParams)
+ {
+ return;
+ }
+ if (string.IsNullOrEmpty(model.Name))
+ {
+ throw new ArgumentNullException("Не указано название типа", nameof(model.Name));
+ }
+
+ _logger.LogInformation("CheckModel. OrderType.Id: {Id}", model.Id);
+ }
+ }
+}
diff --git a/Components/Components.sln b/Components/Components.sln
index 20af785..b4ba791 100644
--- a/Components/Components.sln
+++ b/Components/Components.sln
@@ -3,9 +3,17 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.8.34525.116
MinimumVisualStudioVersion = 10.0.40219.1
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Components", "Components\Components.csproj", "{06211F1C-DD56-4DF0-BCBD-1F21654E1084}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Components", "Components\Components.csproj", "{06211F1C-DD56-4DF0-BCBD-1F21654E1084}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WinForms", "WinForms\WinForms.csproj", "{A961BB11-3AD9-4687-B338-FCDD7887E758}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WinForms", "WinForms\WinForms.csproj", "{A961BB11-3AD9-4687-B338-FCDD7887E758}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataModels", "DataModels\DataModels.csproj", "{E47EA28F-3148-4A37-BACE-35F70E297E9F}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Contracts", "Contracts\Contracts.csproj", "{4BA581C3-3921-4086-A41F-C507ADD258B9}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DatabaseImplement", "DatabaseImplement\DatabaseImplement.csproj", "{4007A4AB-770E-4E72-8337-BC342A8C09BD}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BusinessLogics", "BusinessLogics\BusinessLogics.csproj", "{324D5883-FDDE-46D1-ADF0-31D46EF95AFF}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -21,6 +29,22 @@ Global
{A961BB11-3AD9-4687-B338-FCDD7887E758}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A961BB11-3AD9-4687-B338-FCDD7887E758}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A961BB11-3AD9-4687-B338-FCDD7887E758}.Release|Any CPU.Build.0 = Release|Any CPU
+ {E47EA28F-3148-4A37-BACE-35F70E297E9F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {E47EA28F-3148-4A37-BACE-35F70E297E9F}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {E47EA28F-3148-4A37-BACE-35F70E297E9F}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {E47EA28F-3148-4A37-BACE-35F70E297E9F}.Release|Any CPU.Build.0 = Release|Any CPU
+ {4BA581C3-3921-4086-A41F-C507ADD258B9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {4BA581C3-3921-4086-A41F-C507ADD258B9}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {4BA581C3-3921-4086-A41F-C507ADD258B9}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {4BA581C3-3921-4086-A41F-C507ADD258B9}.Release|Any CPU.Build.0 = Release|Any CPU
+ {4007A4AB-770E-4E72-8337-BC342A8C09BD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {4007A4AB-770E-4E72-8337-BC342A8C09BD}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {4007A4AB-770E-4E72-8337-BC342A8C09BD}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {4007A4AB-770E-4E72-8337-BC342A8C09BD}.Release|Any CPU.Build.0 = Release|Any CPU
+ {324D5883-FDDE-46D1-ADF0-31D46EF95AFF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {324D5883-FDDE-46D1-ADF0-31D46EF95AFF}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {324D5883-FDDE-46D1-ADF0-31D46EF95AFF}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {324D5883-FDDE-46D1-ADF0-31D46EF95AFF}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/Components/Components/Components.csproj b/Components/Components/Components.csproj
index 096def8..c496a51 100644
--- a/Components/Components/Components.csproj
+++ b/Components/Components/Components.csproj
@@ -5,6 +5,7 @@
enable
true
enable
+ True
diff --git a/Components/Contracts/BindingModels/OrderBindingModel.cs b/Components/Contracts/BindingModels/OrderBindingModel.cs
new file mode 100644
index 0000000..46e3d41
--- /dev/null
+++ b/Components/Contracts/BindingModels/OrderBindingModel.cs
@@ -0,0 +1,40 @@
+using DataModels.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Contracts.BindingModels
+{
+ ///
+ /// Модель привязки для сущности "Счет"
+ ///
+ public class OrderBindingModel : IOrderModel
+ {
+ ///
+ /// Идентификатор
+ ///
+ public int Id { get; set; }
+
+ ///
+ /// ФИО официанта
+ ///
+ public string WaiterFullName { get; set; } = string.Empty;
+
+ ///
+ /// Информация по счету
+ ///
+ public string Info { get; set; } = string.Empty;
+
+ ///
+ /// Тип заказа
+ ///
+ public string Type { get; set; } = string.Empty;
+
+ ///
+ /// Сумма заказа
+ ///
+ public double? Sum { get; set; }
+ }
+}
diff --git a/Components/Contracts/BindingModels/OrderTypeBindingModel.cs b/Components/Contracts/BindingModels/OrderTypeBindingModel.cs
new file mode 100644
index 0000000..472d439
--- /dev/null
+++ b/Components/Contracts/BindingModels/OrderTypeBindingModel.cs
@@ -0,0 +1,25 @@
+using DataModels.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Contracts.BindingModels
+{
+ ///
+ /// Модель привязки для сущности "Тип заказа"
+ ///
+ public class OrderTypeBindingModel : IOrderTypeModel
+ {
+ ///
+ /// Идентификатор
+ ///
+ public int Id { get; set; }
+
+ ///
+ /// Название типа
+ ///
+ public string Name { get; set; } = string.Empty;
+ }
+}
diff --git a/Components/Contracts/BusinessLogicsContracts/IOrderLogic.cs b/Components/Contracts/BusinessLogicsContracts/IOrderLogic.cs
new file mode 100644
index 0000000..4952fd5
--- /dev/null
+++ b/Components/Contracts/BusinessLogicsContracts/IOrderLogic.cs
@@ -0,0 +1,52 @@
+using Contracts.BindingModels;
+using Contracts.SearchModels;
+using Contracts.ViewModels;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Contracts.BusinessLogicsContracts
+{
+ ///
+ /// Интерфейс для описания работы бизнес-логики для сущности "Счет"
+ ///
+ public interface IOrderLogic
+ {
+ ///
+ /// Получить список записией
+ ///
+ ///
+ ///
+ List? ReadList(OrderSearchModel? model);
+
+ ///
+ /// Получить отдельную запись
+ ///
+ ///
+ ///
+ OrderViewModel? ReadElement(OrderSearchModel model);
+
+ ///
+ /// Создать запись
+ ///
+ ///
+ ///
+ bool Create(OrderBindingModel model);
+
+ ///
+ /// Изменить запись
+ ///
+ ///
+ ///
+ bool Update(OrderBindingModel model);
+
+ ///
+ /// Удалить запись
+ ///
+ ///
+ ///
+ bool Delete(OrderBindingModel model);
+ }
+}
diff --git a/Components/Contracts/BusinessLogicsContracts/IOrderTypeLogic.cs b/Components/Contracts/BusinessLogicsContracts/IOrderTypeLogic.cs
new file mode 100644
index 0000000..5402ea7
--- /dev/null
+++ b/Components/Contracts/BusinessLogicsContracts/IOrderTypeLogic.cs
@@ -0,0 +1,52 @@
+using Contracts.BindingModels;
+using Contracts.SearchModels;
+using Contracts.ViewModels;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Contracts.BusinessLogicsContracts
+{
+ ///
+ /// Интерфейс для описания работы бизнес-логики для сущности "Тип заказа"
+ ///
+ public interface IOrderTypeLogic
+ {
+ ///
+ /// Получить список записией
+ ///
+ ///
+ ///
+ List? ReadList(OrderTypeSearchModel? model);
+
+ ///
+ /// Получить отдельную запись
+ ///
+ ///
+ ///
+ OrderTypeViewModel? ReadElement(OrderTypeSearchModel model);
+
+ ///
+ /// Создать запись
+ ///
+ ///
+ ///
+ bool Create(OrderTypeBindingModel model);
+
+ ///
+ /// Изменить запись
+ ///
+ ///
+ ///
+ bool Update(OrderTypeBindingModel model);
+
+ ///
+ /// Удалить запись
+ ///
+ ///
+ ///
+ bool Delete(OrderTypeBindingModel model);
+ }
+}
diff --git a/Components/Contracts/Contracts.csproj b/Components/Contracts/Contracts.csproj
new file mode 100644
index 0000000..2e520d2
--- /dev/null
+++ b/Components/Contracts/Contracts.csproj
@@ -0,0 +1,13 @@
+
+
+
+ net6.0
+ enable
+ enable
+
+
+
+
+
+
+
diff --git a/Components/Contracts/SearchModels/OrderSearchModel.cs b/Components/Contracts/SearchModels/OrderSearchModel.cs
new file mode 100644
index 0000000..105c57f
--- /dev/null
+++ b/Components/Contracts/SearchModels/OrderSearchModel.cs
@@ -0,0 +1,29 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Contracts.SearchModels
+{
+ ///
+ /// Модель поиска для сущности "Счет"
+ ///
+ public class OrderSearchModel
+ {
+ ///
+ /// Идентификатор
+ ///
+ public int? Id { get; set; }
+
+ ///
+ /// ФИО официанта
+ ///
+ public string? WaiterFullName { get; set; }
+
+ ///
+ /// Тип заказа
+ ///
+ public string? Type { get; set; }
+ }
+}
diff --git a/Components/Contracts/SearchModels/OrderTypeSearchModel.cs b/Components/Contracts/SearchModels/OrderTypeSearchModel.cs
new file mode 100644
index 0000000..6de7a98
--- /dev/null
+++ b/Components/Contracts/SearchModels/OrderTypeSearchModel.cs
@@ -0,0 +1,24 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Contracts.SearchModels
+{
+ ///
+ /// Модель поиска для сущности "Тип заказа"
+ ///
+ public class OrderTypeSearchModel
+ {
+ ///
+ /// Идентификатор
+ ///
+ public int? Id { get; set; }
+
+ ///
+ /// Название типа
+ ///
+ public string? Name { get; set; }
+ }
+}
diff --git a/Components/Contracts/StoragesContracts/IOrderStorage.cs b/Components/Contracts/StoragesContracts/IOrderStorage.cs
new file mode 100644
index 0000000..741a7ed
--- /dev/null
+++ b/Components/Contracts/StoragesContracts/IOrderStorage.cs
@@ -0,0 +1,58 @@
+using Contracts.BindingModels;
+using Contracts.SearchModels;
+using Contracts.ViewModels;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Contracts.StoragesContracts
+{
+ ///
+ /// Интерфейс для описания работы с хранилищем для сущности "Счет"
+ ///
+ public interface IOrderStorage
+ {
+ ///
+ /// Получить полный список элементов
+ ///
+ ///
+ List GetFullList();
+
+ ///
+ /// Получить фильтрованный список элементов
+ ///
+ ///
+ ///
+ List GetFilteredList(OrderSearchModel model);
+
+ ///
+ /// Получить элемент
+ ///
+ ///
+ ///
+ OrderViewModel? GetElement(OrderSearchModel model);
+
+ ///
+ /// Добавить элемент
+ ///
+ ///
+ ///
+ OrderViewModel? Insert(OrderBindingModel model);
+
+ ///
+ /// Редактировать элемент
+ ///
+ ///
+ ///
+ OrderViewModel? Update(OrderBindingModel model);
+
+ ///
+ /// Удалить элемент
+ ///
+ ///
+ ///
+ OrderViewModel? Delete(OrderBindingModel model);
+ }
+}
diff --git a/Components/Contracts/StoragesContracts/IOrderTypeStorage.cs b/Components/Contracts/StoragesContracts/IOrderTypeStorage.cs
new file mode 100644
index 0000000..b2f3ae2
--- /dev/null
+++ b/Components/Contracts/StoragesContracts/IOrderTypeStorage.cs
@@ -0,0 +1,58 @@
+using Contracts.BindingModels;
+using Contracts.SearchModels;
+using Contracts.ViewModels;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Contracts.StoragesContracts
+{
+ ///
+ /// Интерфейс для описания работы с хранилищем для сущности "Тип заказа"
+ ///
+ public interface IOrderTypeStorage
+ {
+ ///
+ /// Получить полный список элементов
+ ///
+ ///
+ List GetFullList();
+
+ ///
+ /// Получить фильтрованный список элементов
+ ///
+ ///
+ ///
+ List GetFilteredList(OrderTypeSearchModel model);
+
+ ///
+ /// Получить элемент
+ ///
+ ///
+ ///
+ OrderTypeViewModel? GetElement(OrderTypeSearchModel model);
+
+ ///
+ /// Добавить элемент
+ ///
+ ///
+ ///
+ OrderTypeViewModel? Insert(OrderTypeBindingModel model);
+
+ ///
+ /// Редактировать элемент
+ ///
+ ///
+ ///
+ OrderTypeViewModel? Update(OrderTypeBindingModel model);
+
+ ///
+ /// Удалить элемент
+ ///
+ ///
+ ///
+ OrderTypeViewModel? Delete(OrderTypeBindingModel model);
+ }
+}
diff --git a/Components/Contracts/ViewModels/OrderTypeViewModel.cs b/Components/Contracts/ViewModels/OrderTypeViewModel.cs
new file mode 100644
index 0000000..e4cb22c
--- /dev/null
+++ b/Components/Contracts/ViewModels/OrderTypeViewModel.cs
@@ -0,0 +1,27 @@
+using DataModels.Models;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Contracts.ViewModels
+{
+ ///
+ /// Модель отображения для сущности "Тип заказа"
+ ///
+ public class OrderTypeViewModel : IOrderTypeModel
+ {
+ ///
+ /// Идентификатор
+ ///
+ public int Id { get; set; }
+
+ ///
+ /// Название типа
+ ///
+ [DisplayName("Тип заказа")]
+ public string Name { get; set; } = string.Empty;
+ }
+}
diff --git a/Components/Contracts/ViewModels/OrderViewModel.cs b/Components/Contracts/ViewModels/OrderViewModel.cs
new file mode 100644
index 0000000..0db0757
--- /dev/null
+++ b/Components/Contracts/ViewModels/OrderViewModel.cs
@@ -0,0 +1,45 @@
+using DataModels.Models;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Contracts.ViewModels
+{
+ ///
+ /// Модель отображения для сущности "Счет"
+ ///
+ public class OrderViewModel
+ {
+ ///
+ /// Идентификатор
+ ///
+ public int Id { get; set; }
+
+ ///
+ /// ФИО официанта
+ ///
+ [DisplayName("ФИО официанта")]
+ public string WaiterFullName { get; set; } = string.Empty;
+
+ ///
+ /// Информация по счету
+ ///
+ [DisplayName("Информация")]
+ public string Info { get; set; } = string.Empty;
+
+ ///
+ /// Тип заказа
+ ///
+ [DisplayName("Тип заказа")]
+ public string Type { get; set; } = string.Empty;
+
+ ///
+ /// Сумма заказа
+ ///
+ [DisplayName("Сумма заказа")]
+ public string? Sum { get; set; }
+ }
+}
diff --git a/Components/DataModels/DataModels.csproj b/Components/DataModels/DataModels.csproj
new file mode 100644
index 0000000..132c02c
--- /dev/null
+++ b/Components/DataModels/DataModels.csproj
@@ -0,0 +1,9 @@
+
+
+
+ net6.0
+ enable
+ enable
+
+
+
diff --git a/Components/DataModels/IId.cs b/Components/DataModels/IId.cs
new file mode 100644
index 0000000..78f6efb
--- /dev/null
+++ b/Components/DataModels/IId.cs
@@ -0,0 +1,19 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace DataModels
+{
+ ///
+ /// Интерфейс для идентификатора
+ ///
+ public interface IId
+ {
+ ///
+ /// Идентификатор
+ ///
+ int Id { get; }
+ }
+}
diff --git a/Components/DataModels/Models/IOrderModel.cs b/Components/DataModels/Models/IOrderModel.cs
new file mode 100644
index 0000000..58337e7
--- /dev/null
+++ b/Components/DataModels/Models/IOrderModel.cs
@@ -0,0 +1,34 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace DataModels.Models
+{
+ ///
+ /// Интерфейс для сущности "Счет"
+ ///
+ public interface IOrderModel : IId
+ {
+ ///
+ /// ФИО официанта
+ ///
+ string WaiterFullName { get; }
+
+ ///
+ /// Информация по счету
+ ///
+ string Info { get; }
+
+ ///
+ /// Тип заказа
+ ///
+ string Type { get; }
+
+ ///
+ /// Сумма заказа
+ ///
+ double? Sum { get; }
+ }
+}
diff --git a/Components/DataModels/Models/IOrderTypeModel.cs b/Components/DataModels/Models/IOrderTypeModel.cs
new file mode 100644
index 0000000..d287cf2
--- /dev/null
+++ b/Components/DataModels/Models/IOrderTypeModel.cs
@@ -0,0 +1,19 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace DataModels.Models
+{
+ ///
+ /// Интерфейс для сущности "Тип заказа"
+ ///
+ public interface IOrderTypeModel : IId
+ {
+ ///
+ /// Название типа
+ ///
+ string Name { get; }
+ }
+}
diff --git a/Components/DatabaseImplement/Database.cs b/Components/DatabaseImplement/Database.cs
new file mode 100644
index 0000000..4e3130f
--- /dev/null
+++ b/Components/DatabaseImplement/Database.cs
@@ -0,0 +1,44 @@
+using DatabaseImplement.Models;
+using Microsoft.EntityFrameworkCore;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace DatabaseImplement
+{
+ ///
+ /// Класс для взаимодействия с базой данных
+ ///
+ public class Database : DbContext
+ {
+ ///
+ /// Параметры подключения к базе данных
+ ///
+ private string _dbConnectionString = "Host=localhost;Port=5432;Database=COPLabWorks;Username=postgres;Password=2004";
+
+ ///
+ /// Подключение к базе данных
+ ///
+ ///
+ protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
+ {
+ if (optionsBuilder.IsConfigured == false)
+ {
+ optionsBuilder.UseNpgsql(_dbConnectionString);
+ }
+ base.OnConfiguring(optionsBuilder);
+ }
+
+ ///
+ /// Таблица "Счета"
+ ///
+ public virtual DbSet Orders { get; set; }
+
+ ///
+ /// Таблица "Типы заказов"
+ ///
+ public virtual DbSet OrderTypes { get; set; }
+ }
+}
diff --git a/Components/DatabaseImplement/DatabaseImplement.csproj b/Components/DatabaseImplement/DatabaseImplement.csproj
new file mode 100644
index 0000000..af45de2
--- /dev/null
+++ b/Components/DatabaseImplement/DatabaseImplement.csproj
@@ -0,0 +1,22 @@
+
+
+
+ net6.0
+ enable
+ enable
+
+
+
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
+
+
+
+
+
+
+
diff --git a/Components/DatabaseImplement/Implements/OrderStorage.cs b/Components/DatabaseImplement/Implements/OrderStorage.cs
new file mode 100644
index 0000000..d1e4946
--- /dev/null
+++ b/Components/DatabaseImplement/Implements/OrderStorage.cs
@@ -0,0 +1,137 @@
+using Contracts.BindingModels;
+using Contracts.SearchModels;
+using Contracts.StoragesContracts;
+using Contracts.ViewModels;
+using DatabaseImplement.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace DatabaseImplement.Implements
+{
+ ///
+ /// Хранилище для сущности "Счет"
+ ///
+ public class OrderStorage : IOrderStorage
+ {
+ ///
+ /// Получить полный список элементов
+ ///
+ ///
+ public List GetFullList()
+ {
+ using var context = new Database();
+ return context.Orders
+ .Select(x => x.GetViewModel)
+ .ToList();
+ }
+
+ ///
+ /// Получить фильтрованный список элементов
+ ///
+ ///
+ ///
+ public List GetFilteredList(OrderSearchModel model)
+ {
+ using var context = new Database();
+ // Фильтрация по ФИО официанта
+ if (!string.IsNullOrEmpty(model.WaiterFullName))
+ {
+ return context.Orders
+ .Where(x => x.WaiterFullName.Contains(model.WaiterFullName))
+ .Select(x => x.GetViewModel)
+ .ToList();
+ }
+
+ // Фильтрация по типу заказа
+ if (!string.IsNullOrEmpty(model.Type))
+ {
+ return context.Orders
+ .Where(x => x.Type.Contains(model.Type))
+ .Select(x => x.GetViewModel)
+ .ToList();
+ }
+
+ return new();
+ }
+
+ ///
+ /// Получить элемент
+ ///
+ ///
+ ///
+ public OrderViewModel? GetElement(OrderSearchModel model)
+ {
+ using var context = new Database();
+ if (model.Id.HasValue)
+ {
+ return context.Orders
+ .FirstOrDefault(x => x.Id.Equals(model.Id))
+ ?.GetViewModel;
+ }
+
+ return null;
+ }
+
+ ///
+ /// Добавить элемент
+ ///
+ ///
+ ///
+ public OrderViewModel? Insert(OrderBindingModel model)
+ {
+ using var context = new Database();
+ var newOrder = Order.Create(model);
+ if (newOrder == null)
+ {
+ return null;
+ }
+
+ context.Orders.Add(newOrder);
+ context.SaveChanges();
+ return newOrder.GetViewModel;
+ }
+
+ ///
+ /// Редактировать элемент
+ ///
+ ///
+ ///
+ public OrderViewModel? Update(OrderBindingModel model)
+ {
+ using var context = new Database();
+ var order = context.Orders
+ .FirstOrDefault(x => x.Id.Equals(model.Id));
+ if (order == null)
+ {
+ return null;
+ }
+
+ order.Update(model);
+ context.SaveChanges();
+ return order.GetViewModel;
+ }
+
+ ///
+ /// Удалить элемент
+ ///
+ ///
+ ///
+ public OrderViewModel? Delete(OrderBindingModel model)
+ {
+ using var context = new Database();
+ var order = context.Orders
+ .FirstOrDefault(x => x.Id.Equals(model.Id));
+ if (order == null)
+ {
+ return null;
+ }
+
+ context.Orders.Remove(order);
+ context.SaveChanges();
+ return order.GetViewModel;
+ }
+ }
+}
diff --git a/Components/DatabaseImplement/Implements/OrderTypeStorage.cs b/Components/DatabaseImplement/Implements/OrderTypeStorage.cs
new file mode 100644
index 0000000..dc9a0cd
--- /dev/null
+++ b/Components/DatabaseImplement/Implements/OrderTypeStorage.cs
@@ -0,0 +1,128 @@
+using Contracts.BindingModels;
+using Contracts.SearchModels;
+using Contracts.StoragesContracts;
+using Contracts.ViewModels;
+using DatabaseImplement.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace DatabaseImplement.Implements
+{
+ ///
+ /// Хранилище для сущности "Тип заказа"
+ ///
+ public class OrderTypeStorage : IOrderTypeStorage
+ {
+ ///
+ /// Получить полный список элементов
+ ///
+ ///
+ public List GetFullList()
+ {
+ using var context = new Database();
+ return context.OrderTypes
+ .Select(x => x.GetViewModel)
+ .ToList();
+ }
+
+ ///
+ /// Получить фильтрованный список элементов
+ ///
+ ///
+ ///
+ public List GetFilteredList(OrderTypeSearchModel model)
+ {
+ using var context = new Database();
+ // Фильтрация по названию типа
+ if (!string.IsNullOrEmpty(model.Name))
+ {
+ return context.OrderTypes
+ .Where(x => x.Name.Contains(model.Name))
+ .Select(x => x.GetViewModel)
+ .ToList();
+ }
+
+ return new();
+ }
+
+ ///
+ /// Получить элемент
+ ///
+ ///
+ ///
+ public OrderTypeViewModel? GetElement(OrderTypeSearchModel model)
+ {
+ using var context = new Database();
+ if (model.Id.HasValue)
+ {
+ return context.OrderTypes
+ .FirstOrDefault(x => x.Id.Equals(model.Id))
+ ?.GetViewModel;
+ }
+
+ return null;
+ }
+
+ ///
+ /// Добавить элемент
+ ///
+ ///
+ ///
+ public OrderTypeViewModel? Insert(OrderTypeBindingModel model)
+ {
+ using var context = new Database();
+ var newOrderType = OrderType.Create(model);
+ if (newOrderType == null)
+ {
+ return null;
+ }
+
+ context.OrderTypes.Add(newOrderType);
+ context.SaveChanges();
+ return newOrderType.GetViewModel;
+ }
+
+ ///
+ /// Редактировать элемент
+ ///
+ ///
+ ///
+ public OrderTypeViewModel? Update(OrderTypeBindingModel model)
+ {
+ using var context = new Database();
+ var orderType = context.OrderTypes
+ .FirstOrDefault(x => x.Id.Equals(model.Id));
+ if (orderType == null)
+ {
+ return null;
+ }
+
+ orderType.Update(model);
+ context.SaveChanges();
+ return orderType.GetViewModel;
+ }
+
+ ///
+ /// Удалить элемент
+ ///
+ ///
+ ///
+ public OrderTypeViewModel? Delete(OrderTypeBindingModel model)
+ {
+ using var context = new Database();
+ var orderType = context.OrderTypes
+ .FirstOrDefault(x => x.Id.Equals(model.Id));
+ if (orderType == null)
+ {
+ return null;
+ }
+
+ context.OrderTypes.Remove(orderType);
+ context.SaveChanges();
+ return orderType.GetViewModel;
+ }
+ }
+}
diff --git a/Components/DatabaseImplement/Migrations/20240920214214_InitialCreate.Designer.cs b/Components/DatabaseImplement/Migrations/20240920214214_InitialCreate.Designer.cs
new file mode 100644
index 0000000..0cac390
--- /dev/null
+++ b/Components/DatabaseImplement/Migrations/20240920214214_InitialCreate.Designer.cs
@@ -0,0 +1,75 @@
+//
+using System;
+using DatabaseImplement;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Infrastructure;
+using Microsoft.EntityFrameworkCore.Migrations;
+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
+using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
+
+#nullable disable
+
+namespace DatabaseImplement.Migrations
+{
+ [DbContext(typeof(Database))]
+ [Migration("20240920214214_InitialCreate")]
+ partial class InitialCreate
+ {
+ ///
+ protected override void BuildTargetModel(ModelBuilder modelBuilder)
+ {
+#pragma warning disable 612, 618
+ modelBuilder
+ .HasAnnotation("ProductVersion", "7.0.13")
+ .HasAnnotation("Relational:MaxIdentifierLength", 63);
+
+ NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
+
+ modelBuilder.Entity("DatabaseImplement.Models.Order", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id"));
+
+ b.Property("Info")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property("Sum")
+ .HasColumnType("double precision");
+
+ b.Property("Type")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property("WaiterFullName")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.HasKey("Id");
+
+ b.ToTable("Orders");
+ });
+
+ modelBuilder.Entity("DatabaseImplement.Models.OrderType", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id"));
+
+ b.Property("Name")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.HasKey("Id");
+
+ b.ToTable("OrderTypes");
+ });
+#pragma warning restore 612, 618
+ }
+ }
+}
diff --git a/Components/DatabaseImplement/Migrations/20240920214214_InitialCreate.cs b/Components/DatabaseImplement/Migrations/20240920214214_InitialCreate.cs
new file mode 100644
index 0000000..11cddcd
--- /dev/null
+++ b/Components/DatabaseImplement/Migrations/20240920214214_InitialCreate.cs
@@ -0,0 +1,54 @@
+using Microsoft.EntityFrameworkCore.Migrations;
+using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
+
+#nullable disable
+
+namespace DatabaseImplement.Migrations
+{
+ ///
+ public partial class InitialCreate : Migration
+ {
+ ///
+ protected override void Up(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.CreateTable(
+ name: "Orders",
+ columns: table => new
+ {
+ Id = table.Column(type: "integer", nullable: false)
+ .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
+ WaiterFullName = table.Column(type: "text", nullable: false),
+ Info = table.Column(type: "text", nullable: false),
+ Type = table.Column(type: "text", nullable: false),
+ Sum = table.Column(type: "double precision", nullable: true)
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey("PK_Orders", x => x.Id);
+ });
+
+ migrationBuilder.CreateTable(
+ name: "OrderTypes",
+ columns: table => new
+ {
+ Id = table.Column(type: "integer", nullable: false)
+ .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
+ Name = table.Column(type: "text", nullable: false)
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey("PK_OrderTypes", x => x.Id);
+ });
+ }
+
+ ///
+ protected override void Down(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.DropTable(
+ name: "Orders");
+
+ migrationBuilder.DropTable(
+ name: "OrderTypes");
+ }
+ }
+}
diff --git a/Components/DatabaseImplement/Migrations/DatabaseModelSnapshot.cs b/Components/DatabaseImplement/Migrations/DatabaseModelSnapshot.cs
new file mode 100644
index 0000000..819d29f
--- /dev/null
+++ b/Components/DatabaseImplement/Migrations/DatabaseModelSnapshot.cs
@@ -0,0 +1,72 @@
+//
+using System;
+using DatabaseImplement;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Infrastructure;
+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
+using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
+
+#nullable disable
+
+namespace DatabaseImplement.Migrations
+{
+ [DbContext(typeof(Database))]
+ partial class DatabaseModelSnapshot : ModelSnapshot
+ {
+ protected override void BuildModel(ModelBuilder modelBuilder)
+ {
+#pragma warning disable 612, 618
+ modelBuilder
+ .HasAnnotation("ProductVersion", "7.0.13")
+ .HasAnnotation("Relational:MaxIdentifierLength", 63);
+
+ NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
+
+ modelBuilder.Entity("DatabaseImplement.Models.Order", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id"));
+
+ b.Property("Info")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property("Sum")
+ .HasColumnType("double precision");
+
+ b.Property("Type")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property("WaiterFullName")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.HasKey("Id");
+
+ b.ToTable("Orders");
+ });
+
+ modelBuilder.Entity("DatabaseImplement.Models.OrderType", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id"));
+
+ b.Property("Name")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.HasKey("Id");
+
+ b.ToTable("OrderTypes");
+ });
+#pragma warning restore 612, 618
+ }
+ }
+}
diff --git a/Components/DatabaseImplement/Models/Order.cs b/Components/DatabaseImplement/Models/Order.cs
new file mode 100644
index 0000000..ad2a5a0
--- /dev/null
+++ b/Components/DatabaseImplement/Models/Order.cs
@@ -0,0 +1,97 @@
+using Contracts.BindingModels;
+using Contracts.ViewModels;
+using DataModels.Models;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace DatabaseImplement.Models
+{
+ ///
+ /// Сущность "Счет"
+ ///
+ public class Order : IOrderModel
+ {
+ ///
+ /// Идентификатор
+ ///
+ public int Id { get; private set; }
+
+ ///
+ /// ФИО водителя
+ ///
+ [Required]
+ public string WaiterFullName { get; private set; } = string.Empty;
+
+ ///
+ /// Информация по счету
+ ///
+ [Required]
+ public string Info { get; private set; } = string.Empty;
+
+ ///
+ /// Тип заказа
+ ///
+ [Required]
+ public string Type { get; private set; } = string.Empty;
+
+ ///
+ /// Сумма заказа
+ ///
+ public double? Sum { get; private set; }
+
+ ///
+ /// Создать модель
+ ///
+ ///
+ ///
+ public static Order? Create(OrderBindingModel model)
+ {
+ if (model == null)
+ {
+ return null;
+ }
+
+ return new Order
+ {
+ Id = model.Id,
+ WaiterFullName = model.WaiterFullName,
+ Info = model.Info,
+ Type = model.Type,
+ Sum = model.Sum,
+ };
+ }
+
+ ///
+ /// Изменить модель
+ ///
+ ///
+ public void Update(OrderBindingModel model)
+ {
+ if (model == null)
+ {
+ return;
+ }
+
+ WaiterFullName = model.WaiterFullName;
+ Info = model.Info;
+ Type = model.Type;
+ Sum = model.Sum;
+ }
+
+ ///
+ /// Получить модель отображения
+ ///
+ public OrderViewModel GetViewModel => new()
+ {
+ Id = Id,
+ WaiterFullName = WaiterFullName,
+ Info = Info,
+ Type = Type,
+ Sum = Sum.ToString(),
+ };
+ }
+}
diff --git a/Components/DatabaseImplement/Models/OrderType.cs b/Components/DatabaseImplement/Models/OrderType.cs
new file mode 100644
index 0000000..fcc59cf
--- /dev/null
+++ b/Components/DatabaseImplement/Models/OrderType.cs
@@ -0,0 +1,89 @@
+using Contracts.BindingModels;
+using Contracts.ViewModels;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace DatabaseImplement.Models
+{
+ ///
+ /// Сущность "Тип заказа"
+ ///
+ public class OrderType
+ {
+ ///
+ /// Идентификатор
+ ///
+ public int Id { get; private set; }
+
+ ///
+ /// Название типа
+ ///
+ [Required]
+ public string Name { get; private set; } = string.Empty;
+
+ ///
+ /// Создать модель
+ ///
+ ///
+ ///
+ public static OrderType? Create(OrderTypeBindingModel model)
+ {
+ if (model == null)
+ {
+ return null;
+ }
+
+ return new OrderType
+ {
+ Id = model.Id,
+ Name = model.Name,
+ };
+ }
+
+ ///
+ /// Создать модель
+ ///
+ ///
+ ///
+ public static OrderType? Create(OrderTypeViewModel model)
+ {
+ if (model == null)
+ {
+ return null;
+ }
+
+ return new OrderType
+ {
+ Id = model.Id,
+ Name = model.Name,
+ };
+ }
+
+ ///
+ /// Изменить модель
+ ///
+ ///
+ public void Update(OrderTypeBindingModel model)
+ {
+ if (model == null)
+ {
+ return;
+ }
+
+ Name = model.Name;
+ }
+
+ ///
+ /// Получить модель отображения
+ ///
+ public OrderTypeViewModel GetViewModel => new()
+ {
+ Id = Id,
+ Name = Name,
+ };
+ }
+}
diff --git a/Components/WinForms/Employee.cs b/Components/WinForms/DataModels/Employee.cs
similarity index 98%
rename from Components/WinForms/Employee.cs
rename to Components/WinForms/DataModels/Employee.cs
index 21d6c31..7f13e15 100644
--- a/Components/WinForms/Employee.cs
+++ b/Components/WinForms/DataModels/Employee.cs
@@ -4,7 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
-namespace WinForms
+namespace WinForms.DataModels
{
///
/// Сущность "Человек"
diff --git a/Components/WinForms/Person.cs b/Components/WinForms/DataModels/Person.cs
similarity index 96%
rename from Components/WinForms/Person.cs
rename to Components/WinForms/DataModels/Person.cs
index 78f8acd..92b5293 100644
--- a/Components/WinForms/Person.cs
+++ b/Components/WinForms/DataModels/Person.cs
@@ -4,7 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
-namespace WinForms
+namespace WinForms.DataModels
{
///
/// Сущность "Человек"
diff --git a/Components/WinForms/FormMain.Designer.cs b/Components/WinForms/FormMain.Designer.cs
new file mode 100644
index 0000000..03801cd
--- /dev/null
+++ b/Components/WinForms/FormMain.Designer.cs
@@ -0,0 +1,141 @@
+namespace WinForms
+{
+ partial class FormMain
+ {
+ ///
+ /// 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()
+ {
+ components = new System.ComponentModel.Container();
+ contextMenuStrip = new ContextMenuStrip(components);
+ createElementToolStripMenuItem = new ToolStripMenuItem();
+ updateElementToolStripMenuItem = new ToolStripMenuItem();
+ deleteElementToolStripMenuItem = new ToolStripMenuItem();
+ createWordDocumentToolStripMenuItem = new ToolStripMenuItem();
+ createExcelDocumentToolStripMenuItem = new ToolStripMenuItem();
+ createPdfDocumentToolStripMenuItem = new ToolStripMenuItem();
+ orderTypesToolStripMenuItem = new ToolStripMenuItem();
+ userTreeView = new ComponentsLibrary.VisualComponents.UserTreeView();
+ componentDocumentWithTableMultiHeaderWord1 = new ComponentsLibraryNet60.DocumentWithTable.ComponentDocumentWithTableMultiHeaderWord(components);
+ bigTextComponent1 = new Components.NonVisualComponents.BigTextComponent(components);
+ pdfPieChart1 = new ComponentsLibrary.NonVisualComponents.PdfPieChart(components);
+ contextMenuStrip.SuspendLayout();
+ SuspendLayout();
+ //
+ // contextMenuStrip
+ //
+ contextMenuStrip.Items.AddRange(new ToolStripItem[] { createElementToolStripMenuItem, updateElementToolStripMenuItem, deleteElementToolStripMenuItem, createWordDocumentToolStripMenuItem, createExcelDocumentToolStripMenuItem, createPdfDocumentToolStripMenuItem, orderTypesToolStripMenuItem });
+ contextMenuStrip.Name = "contextMenuStrip";
+ contextMenuStrip.Size = new Size(205, 180);
+ contextMenuStrip.Text = "Контекстное меню";
+ //
+ // createElementToolStripMenuItem
+ //
+ createElementToolStripMenuItem.Name = "createElementToolStripMenuItem";
+ createElementToolStripMenuItem.Size = new Size(204, 22);
+ createElementToolStripMenuItem.Text = "Добавить запись";
+ createElementToolStripMenuItem.Click += createElementToolStripMenuItem_Click;
+ //
+ // updateElementToolStripMenuItem
+ //
+ updateElementToolStripMenuItem.Name = "updateElementToolStripMenuItem";
+ updateElementToolStripMenuItem.Size = new Size(204, 22);
+ updateElementToolStripMenuItem.Text = "Редактировать запись";
+ updateElementToolStripMenuItem.Click += updateElementToolStripMenuItem_Click;
+ //
+ // deleteElementToolStripMenuItem
+ //
+ deleteElementToolStripMenuItem.Name = "deleteElementToolStripMenuItem";
+ deleteElementToolStripMenuItem.Size = new Size(204, 22);
+ deleteElementToolStripMenuItem.Text = "Удалить запись";
+ deleteElementToolStripMenuItem.Click += deleteElementToolStripMenuItem_Click;
+ //
+ // createWordDocumentToolStripMenuItem
+ //
+ createWordDocumentToolStripMenuItem.Name = "createWordDocumentToolStripMenuItem";
+ createWordDocumentToolStripMenuItem.Size = new Size(204, 22);
+ createWordDocumentToolStripMenuItem.Text = "Создать документ Word";
+ createWordDocumentToolStripMenuItem.Click += createWordDocumentToolStripMenuItem_Click;
+ //
+ // createExcelDocumentToolStripMenuItem
+ //
+ createExcelDocumentToolStripMenuItem.Name = "createExcelDocumentToolStripMenuItem";
+ createExcelDocumentToolStripMenuItem.Size = new Size(204, 22);
+ createExcelDocumentToolStripMenuItem.Text = "Создать документ Excel";
+ createExcelDocumentToolStripMenuItem.Click += createExcelDocumentToolStripMenuItem_Click;
+ //
+ // createPdfDocumentToolStripMenuItem
+ //
+ createPdfDocumentToolStripMenuItem.Name = "createPdfDocumentToolStripMenuItem";
+ createPdfDocumentToolStripMenuItem.Size = new Size(204, 22);
+ createPdfDocumentToolStripMenuItem.Text = " Создать документ Pdf";
+ createPdfDocumentToolStripMenuItem.Click += createPdfDocumentToolStripMenuItem_Click;
+ //
+ // orderTypesToolStripMenuItem
+ //
+ orderTypesToolStripMenuItem.Name = "orderTypesToolStripMenuItem";
+ orderTypesToolStripMenuItem.Size = new Size(204, 22);
+ orderTypesToolStripMenuItem.Text = "Типы заказов";
+ orderTypesToolStripMenuItem.Click += orderTypesToolStripMenuItem_Click;
+ //
+ // userTreeView
+ //
+ userTreeView.Dock = DockStyle.Fill;
+ userTreeView.Location = new Point(0, 0);
+ userTreeView.Margin = new Padding(3, 2, 3, 2);
+ userTreeView.Name = "userTreeView";
+ userTreeView.SelectedNodeIndex = -1;
+ userTreeView.Size = new Size(800, 450);
+ userTreeView.TabIndex = 1;
+ //
+ // FormMain
+ //
+ AutoScaleDimensions = new SizeF(7F, 15F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(800, 450);
+ Controls.Add(userTreeView);
+ Name = "FormMain";
+ Text = "Основная форма";
+ Load += FormMain_Load;
+ contextMenuStrip.ResumeLayout(false);
+ ResumeLayout(false);
+ }
+
+ #endregion
+
+ private ContextMenuStrip contextMenuStrip;
+ private ComponentsLibrary.VisualComponents.UserTreeView userTreeView;
+ private ToolStripMenuItem createElementToolStripMenuItem;
+ private ToolStripMenuItem updateElementToolStripMenuItem;
+ private ToolStripMenuItem deleteElementToolStripMenuItem;
+ private ToolStripMenuItem createWordDocumentToolStripMenuItem;
+ private ToolStripMenuItem createExcelDocumentToolStripMenuItem;
+ private ToolStripMenuItem createPdfDocumentToolStripMenuItem;
+ private ComponentsLibraryNet60.DocumentWithTable.ComponentDocumentWithTableMultiHeaderWord componentDocumentWithTableMultiHeaderWord1;
+ private Components.NonVisualComponents.BigTextComponent bigTextComponent1;
+ private ComponentsLibrary.NonVisualComponents.PdfPieChart pdfPieChart1;
+ private ToolStripMenuItem orderTypesToolStripMenuItem;
+ }
+}
\ No newline at end of file
diff --git a/Components/WinForms/FormMain.cs b/Components/WinForms/FormMain.cs
new file mode 100644
index 0000000..72ee528
--- /dev/null
+++ b/Components/WinForms/FormMain.cs
@@ -0,0 +1,371 @@
+using ComponentsLibrary.NonVisualComponents.HelperModels;
+using ComponentsLibraryNet60.Models;
+using Contracts.BindingModels;
+using Contracts.BusinessLogicsContracts;
+using Contracts.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 WinForms
+{
+ ///
+ /// Главная форма
+ ///
+ public partial class FormMain : Form
+ {
+ ///
+ /// Бизнес-логика для сущности "Счет"
+ ///
+ private readonly IOrderLogic _orderLogic;
+
+ ///
+ /// Бизнес-логика для сущности "Тип заказа"
+ ///
+ private readonly IOrderTypeLogic _orderTypeLogic;
+
+ ///
+ /// Конструктор
+ ///
+ ///
+ ///
+ public FormMain(IOrderLogic orderLogic, IOrderTypeLogic orderTypeLogic)
+ {
+ InitializeComponent();
+
+ _orderLogic = orderLogic;
+ _orderTypeLogic = orderTypeLogic;
+
+ userTreeView.ContextMenuStrip = contextMenuStrip;
+ }
+
+ ///
+ /// Загрузка формы
+ ///
+ ///
+ ///
+ private void FormMain_Load(object sender, EventArgs e)
+ {
+ var hierarchy = new List()
+ {
+ "Type",
+ "Sum",
+ "Id",
+ "WaiterFullName",
+ };
+ userTreeView.SetHierarchy(hierarchy);
+
+ LoadData();
+ }
+
+ ///
+ /// Элемент контекстного меню "Добавить запись"
+ ///
+ ///
+ ///
+ private void createElementToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+ AddElement();
+ }
+
+ ///
+ /// Элемент контекстного меню "Редактировать запись"
+ ///
+ ///
+ ///
+ private void updateElementToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+ UpdateElement();
+ }
+
+ ///
+ /// Элемент контекстного меню "Удалить запись"
+ ///
+ ///
+ ///
+ private void deleteElementToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+ DeleteElement();
+ }
+
+ ///
+ /// Элемент контекстного меню "Создать документ Word"
+ ///
+ ///
+ ///
+ private void createWordDocumentToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+ CreateWordDocument();
+ }
+
+ ///
+ /// Элемент контекстного меню "Создать документ Excel"
+ ///
+ ///
+ ///
+ private void createExcelDocumentToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+ CreateExcelDocument();
+ }
+
+ ///
+ /// Элемент контекстного меню "Создать документ Pdf"
+ ///
+ ///
+ ///
+ private void createPdfDocumentToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+ CreatePdfDocument();
+ }
+
+ ///
+ /// Элемент контекстного меню "Типы заказов"
+ ///
+ ///
+ ///
+ private void orderTypesToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormOrderTypes));
+ if (!(service is FormOrderTypes form))
+ {
+ return;
+ }
+
+ form.ShowDialog();
+ }
+
+ ///
+ /// Загрузка данных
+ ///
+ private void LoadData()
+ {
+ try
+ {
+ var orders = _orderLogic.ReadList(null);
+ if (orders == null)
+ {
+ return;
+ }
+
+ foreach (var order in orders)
+ {
+ if (string.IsNullOrEmpty(order.Sum))
+ {
+ order.Sum = "По акции";
+ }
+
+ userTreeView.AddObjectToTree(order);
+ }
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+
+ ///
+ /// Добавить запись
+ ///
+ private void AddElement()
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormOrder));
+ if (!(service is FormOrder form))
+ {
+ return;
+ }
+
+ if (form.ShowDialog() == DialogResult.OK)
+ {
+ LoadData();
+ }
+ }
+
+ ///
+ /// Редактировать элемент
+ ///
+ private void UpdateElement()
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormOrder));
+ if (!(service is FormOrder form))
+ {
+ return;
+ }
+
+ var selectedOrder = userTreeView.GetSelectedObject();
+ if (selectedOrder == null)
+ {
+ MessageBox.Show("Выберите счет для редактирования!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+
+ form.Id = Convert.ToInt32(selectedOrder.Id);
+ if (form.ShowDialog() == DialogResult.OK)
+ {
+ LoadData();
+ }
+ }
+
+ ///
+ /// Удалить элемент
+ ///
+ private void DeleteElement()
+ {
+ if (MessageBox.Show("Удалить запись", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
+ {
+ return;
+ }
+
+ var selectedOrder = userTreeView.GetSelectedObject();
+ int id = Convert.ToInt32(selectedOrder.Id);
+ try
+ {
+ _orderLogic.Delete(new OrderBindingModel { Id = id });
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+
+ LoadData();
+ }
+
+ ///
+ /// Создать документ Word
+ ///
+ private void CreateWordDocument()
+ {
+ string fileName = "";
+ using (var dialog = new SaveFileDialog { Filter = "docx|*.docx" })
+ {
+ if (dialog.ShowDialog() == DialogResult.OK)
+ {
+ fileName = dialog.FileName.ToString();
+ MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
+ }
+ }
+
+ var orders = _orderLogic.ReadList(null);
+ if (orders == null)
+ {
+ return;
+ }
+
+ foreach (var order in orders)
+ {
+ if (string.IsNullOrEmpty(order.Sum))
+ {
+ order.Sum = "По акции";
+ }
+ }
+
+ componentDocumentWithTableMultiHeaderWord1.CreateDoc(new ComponentDocumentWithTableHeaderDataConfig
+ {
+ FilePath = fileName,
+ Header = "Информация по счетам.",
+ ColumnsRowsWidth = new List<(int Column, int Row)>()
+ {
+ (5, 5),
+ (10, 5),
+ (15, 0),
+ (15, 0),
+ },
+ Headers = new List<(int ColumnIndex, int RowIndex, string Header, string PropertyName)>()
+ {
+ (0, 0, "Id", "Id"),
+ (1, 0, "ФИО официанта", "WaiterFullName"),
+ (2, 0, "Тип заказа", "Type"),
+ (3, 0, "Сумма заказа", "Sum")
+ },
+ Data = orders,
+ });
+ }
+
+ ///
+ /// Создать документ Excel
+ ///
+ private void CreateExcelDocument()
+ {
+ string fileName = "";
+ using (var dialog = new SaveFileDialog { Filter = "xlsx|*.xlsx" })
+ {
+ if (dialog.ShowDialog() == DialogResult.OK)
+ {
+ fileName = dialog.FileName.ToString();
+ MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
+ }
+ }
+
+ var orders = _orderLogic.ReadList(null);
+ if (orders == null)
+ {
+ return;
+ }
+
+ string title = "Информация по аукционным счетам.";
+
+ List rows = new List();
+ foreach (var order in orders)
+ {
+ if (string.IsNullOrEmpty(order.Sum))
+ {
+ string row = $"ФИО официанта: {order.WaiterFullName} -- Описание счета: {order.Info}";
+ rows.Add(row);
+ }
+ }
+ string[] rowsArray = rows.ToArray();
+
+ bigTextComponent1.CreateDocument(fileName, title, rowsArray);
+ }
+
+ ///
+ /// Создать документ Pdf
+ ///
+ private void CreatePdfDocument()
+ {
+ string fileName = "";
+ using (var dialog = new SaveFileDialog { Filter = "pdf|*.pdf" })
+ {
+ if (dialog.ShowDialog() == DialogResult.OK)
+ {
+ fileName = dialog.FileName.ToString();
+ MessageBox.Show("Выполнено", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
+ }
+ }
+
+ var orders = _orderLogic.ReadList(null);
+ if (orders == null)
+ {
+ return;
+ }
+
+ var orderTypes = _orderTypeLogic.ReadList(null);
+ if (orderTypes == null)
+ {
+ return;
+ }
+
+ List<(double, string)> items = new List<(double, string)>();
+ foreach (var orderType in orderTypes)
+ {
+ int count = 0;
+ foreach (var order in orders)
+ {
+ if (order.Type == orderType.Name && !string.IsNullOrEmpty(order.Sum))
+ {
+ count++;
+ }
+ }
+
+ items.Add((count, orderType.Name));
+ }
+
+ pdfPieChart1.CreatePieChart(new DataForPieChart(fileName, "Информация по оплаченным счетам каждого типа заказов", "Круговая диаграмма", DiagramLegendEnum.Top, "Типы заказов", items));
+ }
+ }
+}
diff --git a/Components/WinForms/FormMain.resx b/Components/WinForms/FormMain.resx
new file mode 100644
index 0000000..a347663
--- /dev/null
+++ b/Components/WinForms/FormMain.resx
@@ -0,0 +1,132 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 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
+
+
+ 17, 17
+
+
+ 166, 17
+
+
+ 491, 17
+
+
+ 653, 17
+
+
\ No newline at end of file
diff --git a/Components/WinForms/FormNonVisualComponents.cs b/Components/WinForms/FormNonVisualComponents.cs
index 031f536..3dab8df 100644
--- a/Components/WinForms/FormNonVisualComponents.cs
+++ b/Components/WinForms/FormNonVisualComponents.cs
@@ -9,6 +9,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
+using WinForms.DataModels;
namespace WinForms
{
diff --git a/Components/WinForms/FormOrder.Designer.cs b/Components/WinForms/FormOrder.Designer.cs
new file mode 100644
index 0000000..a18fe5c
--- /dev/null
+++ b/Components/WinForms/FormOrder.Designer.cs
@@ -0,0 +1,155 @@
+namespace WinForms
+{
+ partial class FormOrder
+ {
+ ///
+ /// 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()
+ {
+ textBoxWaiterFullName = new TextBox();
+ buttonSave = new Button();
+ buttonCancel = new Button();
+ textBoxInfo = new TextBox();
+ customComboBox = new Components.VisualComponents.CustomComboBox();
+ controlInputNullableDouble = new ControlsLibraryNet60.Input.ControlInputNullableDouble();
+ label1 = new Label();
+ labelInfo = new Label();
+ labelSum = new Label();
+ SuspendLayout();
+ //
+ // textBoxWaiterFullName
+ //
+ textBoxWaiterFullName.Location = new Point(65, 60);
+ textBoxWaiterFullName.Name = "textBoxWaiterFullName";
+ textBoxWaiterFullName.Size = new Size(250, 23);
+ textBoxWaiterFullName.TabIndex = 0;
+ //
+ // buttonSave
+ //
+ buttonSave.Location = new Point(65, 320);
+ buttonSave.Name = "buttonSave";
+ buttonSave.Size = new Size(75, 23);
+ buttonSave.TabIndex = 1;
+ buttonSave.Text = "Сохранить";
+ buttonSave.UseVisualStyleBackColor = true;
+ buttonSave.Click += buttonSave_Click;
+ //
+ // buttonCancel
+ //
+ buttonCancel.Location = new Point(240, 320);
+ buttonCancel.Name = "buttonCancel";
+ buttonCancel.Size = new Size(75, 23);
+ buttonCancel.TabIndex = 2;
+ buttonCancel.Text = "Отмена";
+ buttonCancel.UseVisualStyleBackColor = true;
+ buttonCancel.Click += buttonCancel_Click;
+ //
+ // textBoxInfo
+ //
+ textBoxInfo.Location = new Point(66, 120);
+ textBoxInfo.Name = "textBoxInfo";
+ textBoxInfo.Size = new Size(250, 23);
+ textBoxInfo.TabIndex = 3;
+ //
+ // customComboBox
+ //
+ customComboBox.Location = new Point(65, 150);
+ customComboBox.Name = "customComboBox";
+ customComboBox.SelectedItem = "";
+ customComboBox.Size = new Size(250, 53);
+ customComboBox.TabIndex = 4;
+ //
+ // controlInputNullableDouble
+ //
+ controlInputNullableDouble.BackColor = SystemColors.Window;
+ controlInputNullableDouble.BorderStyle = BorderStyle.Fixed3D;
+ controlInputNullableDouble.Location = new Point(66, 240);
+ controlInputNullableDouble.Margin = new Padding(5, 3, 5, 3);
+ controlInputNullableDouble.Name = "controlInputNullableDouble";
+ controlInputNullableDouble.Size = new Size(250, 23);
+ controlInputNullableDouble.TabIndex = 5;
+ controlInputNullableDouble.Value = null;
+ //
+ // label1
+ //
+ label1.AutoSize = true;
+ label1.Location = new Point(66, 42);
+ label1.Name = "label1";
+ label1.Size = new Size(103, 15);
+ label1.TabIndex = 6;
+ label1.Text = "ФИО официанта*";
+ //
+ // labelInfo
+ //
+ labelInfo.AutoSize = true;
+ labelInfo.Location = new Point(66, 102);
+ labelInfo.Name = "labelInfo";
+ labelInfo.Size = new Size(136, 15);
+ labelInfo.TabIndex = 7;
+ labelInfo.Text = "Информация по счету*";
+ //
+ // labelSum
+ //
+ labelSum.AutoSize = true;
+ labelSum.Location = new Point(66, 222);
+ labelSum.Name = "labelSum";
+ labelSum.Size = new Size(45, 15);
+ labelSum.TabIndex = 8;
+ labelSum.Text = "Сумма";
+ //
+ // FormOrder
+ //
+ AutoScaleDimensions = new SizeF(7F, 15F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(384, 361);
+ Controls.Add(labelSum);
+ Controls.Add(labelInfo);
+ Controls.Add(label1);
+ Controls.Add(controlInputNullableDouble);
+ Controls.Add(customComboBox);
+ Controls.Add(textBoxInfo);
+ Controls.Add(buttonCancel);
+ Controls.Add(buttonSave);
+ Controls.Add(textBoxWaiterFullName);
+ Name = "FormOrder";
+ Text = "Счет";
+ Load += FormOrder_Load;
+ ResumeLayout(false);
+ PerformLayout();
+ }
+
+ #endregion
+
+ private TextBox textBoxWaiterFullName;
+ private Button buttonSave;
+ private Button buttonCancel;
+ private TextBox textBoxInfo;
+ private Components.VisualComponents.CustomComboBox customComboBox;
+ private ControlsLibraryNet60.Input.ControlInputNullableDouble controlInputNullableDouble;
+ private Label label1;
+ private Label labelInfo;
+ private Label labelSum;
+ }
+}
\ No newline at end of file
diff --git a/Components/WinForms/FormOrder.cs b/Components/WinForms/FormOrder.cs
new file mode 100644
index 0000000..acb1b48
--- /dev/null
+++ b/Components/WinForms/FormOrder.cs
@@ -0,0 +1,159 @@
+using Contracts.BindingModels;
+using Contracts.BusinessLogicsContracts;
+using Contracts.SearchModels;
+using DocumentFormat.OpenXml.Office2010.Excel;
+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 WinForms
+{
+ ///
+ /// Форма для создания или редактирования счета
+ ///
+ public partial class FormOrder : Form
+ {
+ ///
+ /// Бизнес-логика для сущности "Счет"
+ ///
+ private readonly IOrderLogic _orderLogic;
+
+ ///
+ /// Бизнес-логика для сущности "Тип заказа"
+ ///
+ private readonly IOrderTypeLogic _orderTypeLogic;
+
+ ///
+ /// Идентификатор счета
+ ///
+ private int? _id;
+
+ ///
+ /// Идентификатор счета
+ ///
+ public int Id { set { _id = value; } }
+
+ ///
+ /// Конструктор
+ ///
+ ///
+ ///
+ public FormOrder(IOrderLogic orderLogic, IOrderTypeLogic orderTypeLogic)
+ {
+ InitializeComponent();
+
+ _orderLogic = orderLogic;
+ _orderTypeLogic = orderTypeLogic;
+ }
+
+ ///
+ /// Загрузка формы
+ ///
+ ///
+ ///
+ private void FormOrder_Load(object sender, EventArgs e)
+ {
+ var listOrderTypes = _orderTypeLogic.ReadList(null);
+ if (listOrderTypes != null)
+ {
+ foreach (var type in listOrderTypes)
+ {
+ customComboBox.AddItem(type.Name);
+ }
+ }
+
+ if (!_id.HasValue)
+ {
+ return;
+ }
+
+ try
+ {
+ var order = _orderLogic.ReadElement(new OrderSearchModel { Id = _id.Value });
+ if (order == null)
+ {
+ return;
+ }
+
+ textBoxWaiterFullName.Text = order.WaiterFullName;
+ textBoxInfo.Text = order.Info;
+ customComboBox.SelectedItem = order.Type;
+ if (string.IsNullOrEmpty(order.Sum))
+ {
+ controlInputNullableDouble.Value = double.Parse(order.Sum!);
+ }
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+
+ ///
+ /// Кнопка "Сохранить"
+ ///
+ ///
+ ///
+ private void buttonSave_Click(object sender, EventArgs e)
+ {
+ if (string.IsNullOrEmpty(textBoxWaiterFullName.Text))
+ {
+ MessageBox.Show("Заполните ФИО официанта!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ if (string.IsNullOrEmpty(textBoxInfo.Text))
+ {
+ MessageBox.Show("Заполните информацию по счету!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ if (string.IsNullOrEmpty(customComboBox.SelectedItem))
+ {
+ MessageBox.Show("Выберите тип заказа!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+
+ try
+ {
+ var model = new OrderBindingModel
+ {
+ Id = _id ?? 0,
+ WaiterFullName = textBoxWaiterFullName.Text,
+ Info = textBoxInfo.Text,
+ Type = customComboBox.SelectedItem,
+ Sum = controlInputNullableDouble.Value,
+ };
+
+ var operatingResult = _id.HasValue ? _orderLogic.Update(model) : _orderLogic.Create(model);
+ if (!operatingResult)
+ {
+ throw new Exception("Ошибка при создании сущности 'Счет'!");
+ }
+
+ MessageBox.Show("Создание сущности 'Счет' прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
+ DialogResult = DialogResult.OK;
+ Close();
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+
+ ///
+ /// Кнопка "Отмена"
+ ///
+ ///
+ ///
+ private void buttonCancel_Click(object sender, EventArgs e)
+ {
+ DialogResult = DialogResult.Cancel;
+ Close();
+ }
+ }
+}
diff --git a/Components/WinForms/FormOrder.resx b/Components/WinForms/FormOrder.resx
new file mode 100644
index 0000000..af32865
--- /dev/null
+++ b/Components/WinForms/FormOrder.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/Components/WinForms/FormOrderTypes.Designer.cs b/Components/WinForms/FormOrderTypes.Designer.cs
new file mode 100644
index 0000000..4302eac
--- /dev/null
+++ b/Components/WinForms/FormOrderTypes.Designer.cs
@@ -0,0 +1,66 @@
+namespace WinForms
+{
+ partial class FormOrderTypes
+ {
+ ///
+ /// 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()
+ {
+ dataGridView = new DataGridView();
+ ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
+ SuspendLayout();
+ //
+ // dataGridView
+ //
+ dataGridView.AllowUserToAddRows = false;
+ dataGridView.BackgroundColor = SystemColors.Control;
+ dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ dataGridView.Dock = DockStyle.Fill;
+ dataGridView.Location = new Point(0, 0);
+ dataGridView.Name = "dataGridView";
+ dataGridView.RowTemplate.Height = 25;
+ dataGridView.Size = new Size(384, 211);
+ dataGridView.TabIndex = 0;
+ dataGridView.CellEndEdit += dataGridView_CellEndEdit;
+ dataGridView.KeyDown += dataGridView_KeyDown;
+ //
+ // FormOrderTypes
+ //
+ AutoScaleDimensions = new SizeF(7F, 15F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(384, 211);
+ Controls.Add(dataGridView);
+ Name = "FormOrderTypes";
+ Text = "Типы заказов";
+ Load += FormOrderTypes_Load;
+ ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
+ ResumeLayout(false);
+ }
+
+ #endregion
+
+ private DataGridView dataGridView;
+ }
+}
\ No newline at end of file
diff --git a/Components/WinForms/FormOrderTypes.cs b/Components/WinForms/FormOrderTypes.cs
new file mode 100644
index 0000000..ba103cb
--- /dev/null
+++ b/Components/WinForms/FormOrderTypes.cs
@@ -0,0 +1,159 @@
+using Contracts.BindingModels;
+using Contracts.BusinessLogicsContracts;
+using DocumentFormat.OpenXml.Office2010.ExcelAc;
+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 WinForms
+{
+ ///
+ /// Форма для типов заказов
+ ///
+ public partial class FormOrderTypes : Form
+ {
+ ///
+ /// Бизнес-логика для сущности "Тип заказа"
+ ///
+ private readonly IOrderTypeLogic _orderTypeLogic;
+
+ ///
+ /// Список типов заказов
+ ///
+ private BindingList _bindingList;
+
+ ///
+ /// Конструктор
+ ///
+ ///
+ public FormOrderTypes(IOrderTypeLogic orderTypeLogic)
+ {
+ InitializeComponent();
+
+ _orderTypeLogic = orderTypeLogic;
+ _bindingList = new BindingList();
+ }
+
+ ///
+ /// Загрузка формы
+ ///
+ ///
+ ///
+ private void FormOrderTypes_Load(object sender, EventArgs e)
+ {
+ LoadData();
+ }
+
+ ///
+ /// Создание или редактирование типа заказа
+ ///
+ ///
+ ///
+ ///
+ private void dataGridView_CellEndEdit(object sender, DataGridViewCellEventArgs e)
+ {
+ var typeName = dataGridView.CurrentRow.Cells[1].Value.ToString();
+ if (!string.IsNullOrEmpty(typeName))
+ {
+ int id = dataGridView.CurrentRow.Cells[0].Value != null
+ ? Convert.ToInt32(dataGridView.CurrentRow.Cells[0].Value)
+ : 0;
+ string name = dataGridView.CurrentRow.Cells[1].EditedFormattedValue.ToString()!;
+ var model = new OrderTypeBindingModel
+ {
+ Id = id,
+ Name = name
+ };
+
+ var operatingResult = id == 0 ? _orderTypeLogic.Update(model) : _orderTypeLogic.Create(model);
+ if (!operatingResult)
+ {
+ throw new Exception("Ошибка при создании сущности 'Тип заказа'!");
+ }
+ }
+ else
+ {
+ MessageBox.Show("Введена пустая строка!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+
+ LoadData();
+ }
+
+ ///
+ /// Обработка нажатия кнопок
+ ///
+ ///
+ ///
+ private void dataGridView_KeyDown(object sender, KeyEventArgs e)
+ {
+ if (e.KeyData == Keys.Insert)
+ {
+ if (dataGridView.Rows.Count == 0)
+ {
+ _bindingList.Add(new OrderTypeBindingModel());
+ dataGridView.DataSource = new BindingList(_bindingList);
+ dataGridView.CurrentCell = dataGridView.Rows[0].Cells[1];
+ return;
+ }
+ if (dataGridView.Rows[dataGridView.Rows.Count - 1].Cells[1].Value != null)
+ {
+ _bindingList.Add(new OrderTypeBindingModel());
+ dataGridView.DataSource = new BindingList(_bindingList);
+ dataGridView.CurrentCell = dataGridView.Rows[dataGridView.Rows.Count - 1].Cells[1];
+ return;
+ }
+ }
+
+ if (e.KeyData == Keys.Delete)
+ {
+ if (MessageBox.Show("Удалить выбранный элемент&", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
+ {
+ _orderTypeLogic.Delete(new OrderTypeBindingModel { Id = (int)dataGridView.CurrentRow.Cells[0].Value });
+ LoadData();
+ }
+ }
+ }
+
+ ///
+ /// Загрузка данных
+ ///
+ private void LoadData()
+ {
+ try
+ {
+ var types = _orderTypeLogic.ReadList(null);
+ if (types == null)
+ {
+ return;
+ }
+
+ _bindingList.Clear();
+ foreach (var type in types)
+ {
+ _bindingList.Add(new OrderTypeBindingModel
+ {
+ Id = type.Id,
+ Name = type.Name,
+ });
+ }
+
+ if (_bindingList != null)
+ {
+ dataGridView.DataSource = _bindingList;
+ dataGridView.Columns[0].Visible = false;
+ dataGridView.Columns[1].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
+ }
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ }
+}
diff --git a/Components/WinForms/FormOrderTypes.resx b/Components/WinForms/FormOrderTypes.resx
new file mode 100644
index 0000000..af32865
--- /dev/null
+++ b/Components/WinForms/FormOrderTypes.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/Components/WinForms/FormVisualComponents.cs b/Components/WinForms/FormVisualComponents.cs
index 74f5022..1d5c947 100644
--- a/Components/WinForms/FormVisualComponents.cs
+++ b/Components/WinForms/FormVisualComponents.cs
@@ -1,3 +1,5 @@
+using WinForms.DataModels;
+
namespace WinForms
{
///
diff --git a/Components/WinForms/Program.cs b/Components/WinForms/Program.cs
index 62dccf2..e5134f2 100644
--- a/Components/WinForms/Program.cs
+++ b/Components/WinForms/Program.cs
@@ -1,7 +1,26 @@
+using BusinessLogics.BusinessLogics;
+using Contracts.BusinessLogicsContracts;
+using Contracts.StoragesContracts;
+using DatabaseImplement.Implements;
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Logging;
+using NLog.Extensions.Logging;
+using System;
+
namespace WinForms
{
internal static class Program
{
+ ///
+ /// IoC-
+ ///
+ private static ServiceProvider? _serviceProvider;
+
+ ///
+ /// IoC-
+ ///
+ public static ServiceProvider? ServiceProvider => _serviceProvider;
+
///
/// The main entry point for the application.
///
@@ -11,7 +30,41 @@ namespace WinForms
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
- Application.Run(new FormNonVisualComponents());
+
+ 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");
+ });
+
+ // IoC-,
+ services.AddTransient();
+ services.AddTransient();
+
+ // IoC-, -
+ services.AddTransient();
+ services.AddTransient();
+
+ // IoC-,
+ services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
}
}
}
\ No newline at end of file
diff --git a/Components/WinForms/WinForms.csproj b/Components/WinForms/WinForms.csproj
index a813ce4..84d8c55 100644
--- a/Components/WinForms/WinForms.csproj
+++ b/Components/WinForms/WinForms.csproj
@@ -9,7 +9,36 @@
+
+
+
+
+
+ Always
+
+
+
+
+
+
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Components/WinForms/nlog.config b/Components/WinForms/nlog.config
new file mode 100644
index 0000000..bf280eb
--- /dev/null
+++ b/Components/WinForms/nlog.config
@@ -0,0 +1,15 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file