LabWork03 Debug?
This commit is contained in:
parent
3b73c69030
commit
e722d26c69
14
Components/BusinessLogics/BusinessLogics.csproj
Normal file
14
Components/BusinessLogics/BusinessLogics.csproj
Normal file
@ -0,0 +1,14 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Contracts\Contracts.csproj" />
|
||||
<ProjectReference Include="..\DatabaseImplement\DatabaseImplement.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
173
Components/BusinessLogics/BusinessLogics/OrderLogic.cs
Normal file
173
Components/BusinessLogics/BusinessLogics/OrderLogic.cs
Normal file
@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// Бизнес-логика для сущности "Счет"
|
||||
/// </summary>
|
||||
public class OrderLogic : IOrderLogic
|
||||
{
|
||||
/// <summary>
|
||||
/// Логгер
|
||||
/// </summary>
|
||||
private readonly ILogger _logger;
|
||||
|
||||
/// <summary>
|
||||
/// Хранилище
|
||||
/// </summary>
|
||||
private readonly IOrderStorage _orderStorage;
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="logger"></param>
|
||||
/// <param name="orderStorage"></param>
|
||||
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_orderStorage = orderStorage;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получить список записией
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public List<OrderViewModel>? 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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получить отдельную запись
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="ArgumentNullException"></exception>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Создать запись
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Изменить запись
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Удалить запись
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Проверить модель
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <param name="withParams"></param>
|
||||
/// <exception cref="ArgumentNullException"></exception>
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
165
Components/BusinessLogics/BusinessLogics/OrderTypeLogic.cs
Normal file
165
Components/BusinessLogics/BusinessLogics/OrderTypeLogic.cs
Normal file
@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// Бизнес-логика для сущности "Тип заказа"
|
||||
/// </summary>
|
||||
public class OrderTypeLogic : IOrderTypeLogic
|
||||
{
|
||||
/// <summary>
|
||||
/// Логгер
|
||||
/// </summary>
|
||||
private readonly ILogger _logger;
|
||||
|
||||
/// <summary>
|
||||
/// Хранилище
|
||||
/// </summary>
|
||||
private readonly IOrderTypeStorage _orderTypeStorage;
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="logger"></param>
|
||||
/// <param name="orderTypeStorage"></param>
|
||||
public OrderTypeLogic(ILogger<OrderTypeLogic> logger, IOrderTypeStorage orderTypeStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_orderTypeStorage = orderTypeStorage;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получить список записией
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public List<OrderTypeViewModel>? 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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получить отдельную запись
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="ArgumentNullException"></exception>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Создать запись
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Изменить запись
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Удалить запись
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Проверить модель
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <param name="withParams"></param>
|
||||
/// <exception cref="ArgumentNullException"></exception>
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
@ -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
|
||||
|
@ -5,6 +5,7 @@
|
||||
<Nullable>enable</Nullable>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
40
Components/Contracts/BindingModels/OrderBindingModel.cs
Normal file
40
Components/Contracts/BindingModels/OrderBindingModel.cs
Normal file
@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// Модель привязки для сущности "Счет"
|
||||
/// </summary>
|
||||
public class OrderBindingModel : IOrderModel
|
||||
{
|
||||
/// <summary>
|
||||
/// Идентификатор
|
||||
/// </summary>
|
||||
public int Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// ФИО официанта
|
||||
/// </summary>
|
||||
public string WaiterFullName { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Информация по счету
|
||||
/// </summary>
|
||||
public string Info { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Тип заказа
|
||||
/// </summary>
|
||||
public string Type { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Сумма заказа
|
||||
/// </summary>
|
||||
public double? Sum { get; set; }
|
||||
}
|
||||
}
|
25
Components/Contracts/BindingModels/OrderTypeBindingModel.cs
Normal file
25
Components/Contracts/BindingModels/OrderTypeBindingModel.cs
Normal file
@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// Модель привязки для сущности "Тип заказа"
|
||||
/// </summary>
|
||||
public class OrderTypeBindingModel : IOrderTypeModel
|
||||
{
|
||||
/// <summary>
|
||||
/// Идентификатор
|
||||
/// </summary>
|
||||
public int Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Название типа
|
||||
/// </summary>
|
||||
public string Name { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
52
Components/Contracts/BusinessLogicsContracts/IOrderLogic.cs
Normal file
52
Components/Contracts/BusinessLogicsContracts/IOrderLogic.cs
Normal file
@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// Интерфейс для описания работы бизнес-логики для сущности "Счет"
|
||||
/// </summary>
|
||||
public interface IOrderLogic
|
||||
{
|
||||
/// <summary>
|
||||
/// Получить список записией
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
List<OrderViewModel>? ReadList(OrderSearchModel? model);
|
||||
|
||||
/// <summary>
|
||||
/// Получить отдельную запись
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
OrderViewModel? ReadElement(OrderSearchModel model);
|
||||
|
||||
/// <summary>
|
||||
/// Создать запись
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
bool Create(OrderBindingModel model);
|
||||
|
||||
/// <summary>
|
||||
/// Изменить запись
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
bool Update(OrderBindingModel model);
|
||||
|
||||
/// <summary>
|
||||
/// Удалить запись
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
bool Delete(OrderBindingModel model);
|
||||
}
|
||||
}
|
@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// Интерфейс для описания работы бизнес-логики для сущности "Тип заказа"
|
||||
/// </summary>
|
||||
public interface IOrderTypeLogic
|
||||
{
|
||||
/// <summary>
|
||||
/// Получить список записией
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
List<OrderTypeViewModel>? ReadList(OrderTypeSearchModel? model);
|
||||
|
||||
/// <summary>
|
||||
/// Получить отдельную запись
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
OrderTypeViewModel? ReadElement(OrderTypeSearchModel model);
|
||||
|
||||
/// <summary>
|
||||
/// Создать запись
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
bool Create(OrderTypeBindingModel model);
|
||||
|
||||
/// <summary>
|
||||
/// Изменить запись
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
bool Update(OrderTypeBindingModel model);
|
||||
|
||||
/// <summary>
|
||||
/// Удалить запись
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
bool Delete(OrderTypeBindingModel model);
|
||||
}
|
||||
}
|
13
Components/Contracts/Contracts.csproj
Normal file
13
Components/Contracts/Contracts.csproj
Normal file
@ -0,0 +1,13 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\DataModels\DataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
29
Components/Contracts/SearchModels/OrderSearchModel.cs
Normal file
29
Components/Contracts/SearchModels/OrderSearchModel.cs
Normal file
@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Contracts.SearchModels
|
||||
{
|
||||
/// <summary>
|
||||
/// Модель поиска для сущности "Счет"
|
||||
/// </summary>
|
||||
public class OrderSearchModel
|
||||
{
|
||||
/// <summary>
|
||||
/// Идентификатор
|
||||
/// </summary>
|
||||
public int? Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// ФИО официанта
|
||||
/// </summary>
|
||||
public string? WaiterFullName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Тип заказа
|
||||
/// </summary>
|
||||
public string? Type { get; set; }
|
||||
}
|
||||
}
|
24
Components/Contracts/SearchModels/OrderTypeSearchModel.cs
Normal file
24
Components/Contracts/SearchModels/OrderTypeSearchModel.cs
Normal file
@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Contracts.SearchModels
|
||||
{
|
||||
/// <summary>
|
||||
/// Модель поиска для сущности "Тип заказа"
|
||||
/// </summary>
|
||||
public class OrderTypeSearchModel
|
||||
{
|
||||
/// <summary>
|
||||
/// Идентификатор
|
||||
/// </summary>
|
||||
public int? Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Название типа
|
||||
/// </summary>
|
||||
public string? Name { get; set; }
|
||||
}
|
||||
}
|
58
Components/Contracts/StoragesContracts/IOrderStorage.cs
Normal file
58
Components/Contracts/StoragesContracts/IOrderStorage.cs
Normal file
@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// Интерфейс для описания работы с хранилищем для сущности "Счет"
|
||||
/// </summary>
|
||||
public interface IOrderStorage
|
||||
{
|
||||
/// <summary>
|
||||
/// Получить полный список элементов
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
List<OrderViewModel> GetFullList();
|
||||
|
||||
/// <summary>
|
||||
/// Получить фильтрованный список элементов
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
List<OrderViewModel> GetFilteredList(OrderSearchModel model);
|
||||
|
||||
/// <summary>
|
||||
/// Получить элемент
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
OrderViewModel? GetElement(OrderSearchModel model);
|
||||
|
||||
/// <summary>
|
||||
/// Добавить элемент
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
OrderViewModel? Insert(OrderBindingModel model);
|
||||
|
||||
/// <summary>
|
||||
/// Редактировать элемент
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
OrderViewModel? Update(OrderBindingModel model);
|
||||
|
||||
/// <summary>
|
||||
/// Удалить элемент
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
OrderViewModel? Delete(OrderBindingModel model);
|
||||
}
|
||||
}
|
58
Components/Contracts/StoragesContracts/IOrderTypeStorage.cs
Normal file
58
Components/Contracts/StoragesContracts/IOrderTypeStorage.cs
Normal file
@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// Интерфейс для описания работы с хранилищем для сущности "Тип заказа"
|
||||
/// </summary>
|
||||
public interface IOrderTypeStorage
|
||||
{
|
||||
/// <summary>
|
||||
/// Получить полный список элементов
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
List<OrderTypeViewModel> GetFullList();
|
||||
|
||||
/// <summary>
|
||||
/// Получить фильтрованный список элементов
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
List<OrderTypeViewModel> GetFilteredList(OrderTypeSearchModel model);
|
||||
|
||||
/// <summary>
|
||||
/// Получить элемент
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
OrderTypeViewModel? GetElement(OrderTypeSearchModel model);
|
||||
|
||||
/// <summary>
|
||||
/// Добавить элемент
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
OrderTypeViewModel? Insert(OrderTypeBindingModel model);
|
||||
|
||||
/// <summary>
|
||||
/// Редактировать элемент
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
OrderTypeViewModel? Update(OrderTypeBindingModel model);
|
||||
|
||||
/// <summary>
|
||||
/// Удалить элемент
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
OrderTypeViewModel? Delete(OrderTypeBindingModel model);
|
||||
}
|
||||
}
|
27
Components/Contracts/ViewModels/OrderTypeViewModel.cs
Normal file
27
Components/Contracts/ViewModels/OrderTypeViewModel.cs
Normal file
@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// Модель отображения для сущности "Тип заказа"
|
||||
/// </summary>
|
||||
public class OrderTypeViewModel : IOrderTypeModel
|
||||
{
|
||||
/// <summary>
|
||||
/// Идентификатор
|
||||
/// </summary>
|
||||
public int Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Название типа
|
||||
/// </summary>
|
||||
[DisplayName("Тип заказа")]
|
||||
public string Name { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
45
Components/Contracts/ViewModels/OrderViewModel.cs
Normal file
45
Components/Contracts/ViewModels/OrderViewModel.cs
Normal file
@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// Модель отображения для сущности "Счет"
|
||||
/// </summary>
|
||||
public class OrderViewModel
|
||||
{
|
||||
/// <summary>
|
||||
/// Идентификатор
|
||||
/// </summary>
|
||||
public int Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// ФИО официанта
|
||||
/// </summary>
|
||||
[DisplayName("ФИО официанта")]
|
||||
public string WaiterFullName { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Информация по счету
|
||||
/// </summary>
|
||||
[DisplayName("Информация")]
|
||||
public string Info { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Тип заказа
|
||||
/// </summary>
|
||||
[DisplayName("Тип заказа")]
|
||||
public string Type { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Сумма заказа
|
||||
/// </summary>
|
||||
[DisplayName("Сумма заказа")]
|
||||
public string? Sum { get; set; }
|
||||
}
|
||||
}
|
9
Components/DataModels/DataModels.csproj
Normal file
9
Components/DataModels/DataModels.csproj
Normal file
@ -0,0 +1,9 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
19
Components/DataModels/IId.cs
Normal file
19
Components/DataModels/IId.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DataModels
|
||||
{
|
||||
/// <summary>
|
||||
/// Интерфейс для идентификатора
|
||||
/// </summary>
|
||||
public interface IId
|
||||
{
|
||||
/// <summary>
|
||||
/// Идентификатор
|
||||
/// </summary>
|
||||
int Id { get; }
|
||||
}
|
||||
}
|
34
Components/DataModels/Models/IOrderModel.cs
Normal file
34
Components/DataModels/Models/IOrderModel.cs
Normal file
@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DataModels.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// Интерфейс для сущности "Счет"
|
||||
/// </summary>
|
||||
public interface IOrderModel : IId
|
||||
{
|
||||
/// <summary>
|
||||
/// ФИО официанта
|
||||
/// </summary>
|
||||
string WaiterFullName { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Информация по счету
|
||||
/// </summary>
|
||||
string Info { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Тип заказа
|
||||
/// </summary>
|
||||
string Type { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Сумма заказа
|
||||
/// </summary>
|
||||
double? Sum { get; }
|
||||
}
|
||||
}
|
19
Components/DataModels/Models/IOrderTypeModel.cs
Normal file
19
Components/DataModels/Models/IOrderTypeModel.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace DataModels.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// Интерфейс для сущности "Тип заказа"
|
||||
/// </summary>
|
||||
public interface IOrderTypeModel : IId
|
||||
{
|
||||
/// <summary>
|
||||
/// Название типа
|
||||
/// </summary>
|
||||
string Name { get; }
|
||||
}
|
||||
}
|
44
Components/DatabaseImplement/Database.cs
Normal file
44
Components/DatabaseImplement/Database.cs
Normal file
@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс для взаимодействия с базой данных
|
||||
/// </summary>
|
||||
public class Database : DbContext
|
||||
{
|
||||
/// <summary>
|
||||
/// Параметры подключения к базе данных
|
||||
/// </summary>
|
||||
private string _dbConnectionString = "Host=localhost;Port=5432;Database=COPLabWorks;Username=postgres;Password=2004";
|
||||
|
||||
/// <summary>
|
||||
/// Подключение к базе данных
|
||||
/// </summary>
|
||||
/// <param name="optionsBuilder"></param>
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
if (optionsBuilder.IsConfigured == false)
|
||||
{
|
||||
optionsBuilder.UseNpgsql(_dbConnectionString);
|
||||
}
|
||||
base.OnConfiguring(optionsBuilder);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Таблица "Счета"
|
||||
/// </summary>
|
||||
public virtual DbSet<Order> Orders { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Таблица "Типы заказов"
|
||||
/// </summary>
|
||||
public virtual DbSet<OrderType> OrderTypes { get; set; }
|
||||
}
|
||||
}
|
22
Components/DatabaseImplement/DatabaseImplement.csproj
Normal file
22
Components/DatabaseImplement/DatabaseImplement.csproj
Normal file
@ -0,0 +1,22 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.13" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.13">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.4" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Contracts\Contracts.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
137
Components/DatabaseImplement/Implements/OrderStorage.cs
Normal file
137
Components/DatabaseImplement/Implements/OrderStorage.cs
Normal file
@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// Хранилище для сущности "Счет"
|
||||
/// </summary>
|
||||
public class OrderStorage : IOrderStorage
|
||||
{
|
||||
/// <summary>
|
||||
/// Получить полный список элементов
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public List<OrderViewModel> GetFullList()
|
||||
{
|
||||
using var context = new Database();
|
||||
return context.Orders
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получить фильтрованный список элементов
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public List<OrderViewModel> 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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получить элемент
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Добавить элемент
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Редактировать элемент
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Удалить элемент
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
128
Components/DatabaseImplement/Implements/OrderTypeStorage.cs
Normal file
128
Components/DatabaseImplement/Implements/OrderTypeStorage.cs
Normal file
@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// Хранилище для сущности "Тип заказа"
|
||||
/// </summary>
|
||||
public class OrderTypeStorage : IOrderTypeStorage
|
||||
{
|
||||
/// <summary>
|
||||
/// Получить полный список элементов
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public List<OrderTypeViewModel> GetFullList()
|
||||
{
|
||||
using var context = new Database();
|
||||
return context.OrderTypes
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получить фильтрованный список элементов
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public List<OrderTypeViewModel> 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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получить элемент
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Добавить элемент
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Редактировать элемент
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Удалить элемент
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
75
Components/DatabaseImplement/Migrations/20240920214214_InitialCreate.Designer.cs
generated
Normal file
75
Components/DatabaseImplement/Migrations/20240920214214_InitialCreate.Designer.cs
generated
Normal file
@ -0,0 +1,75 @@
|
||||
// <auto-generated />
|
||||
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
|
||||
{
|
||||
/// <inheritdoc />
|
||||
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<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Info")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double?>("Sum")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<string>("Type")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("WaiterFullName")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DatabaseImplement.Models.OrderType", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("OrderTypes");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace DatabaseImplement.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class InitialCreate : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Orders",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
WaiterFullName = table.Column<string>(type: "text", nullable: false),
|
||||
Info = table.Column<string>(type: "text", nullable: false),
|
||||
Type = table.Column<string>(type: "text", nullable: false),
|
||||
Sum = table.Column<double>(type: "double precision", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Orders", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "OrderTypes",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
Name = table.Column<string>(type: "text", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_OrderTypes", x => x.Id);
|
||||
});
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "Orders");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "OrderTypes");
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
// <auto-generated />
|
||||
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<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Info")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double?>("Sum")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<string>("Type")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("WaiterFullName")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DatabaseImplement.Models.OrderType", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Name")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("OrderTypes");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
97
Components/DatabaseImplement/Models/Order.cs
Normal file
97
Components/DatabaseImplement/Models/Order.cs
Normal file
@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// Сущность "Счет"
|
||||
/// </summary>
|
||||
public class Order : IOrderModel
|
||||
{
|
||||
/// <summary>
|
||||
/// Идентификатор
|
||||
/// </summary>
|
||||
public int Id { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// ФИО водителя
|
||||
/// </summary>
|
||||
[Required]
|
||||
public string WaiterFullName { get; private set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Информация по счету
|
||||
/// </summary>
|
||||
[Required]
|
||||
public string Info { get; private set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Тип заказа
|
||||
/// </summary>
|
||||
[Required]
|
||||
public string Type { get; private set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Сумма заказа
|
||||
/// </summary>
|
||||
public double? Sum { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Создать модель
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
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,
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Изменить модель
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
public void Update(OrderBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
WaiterFullName = model.WaiterFullName;
|
||||
Info = model.Info;
|
||||
Type = model.Type;
|
||||
Sum = model.Sum;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получить модель отображения
|
||||
/// </summary>
|
||||
public OrderViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
WaiterFullName = WaiterFullName,
|
||||
Info = Info,
|
||||
Type = Type,
|
||||
Sum = Sum.ToString(),
|
||||
};
|
||||
}
|
||||
}
|
89
Components/DatabaseImplement/Models/OrderType.cs
Normal file
89
Components/DatabaseImplement/Models/OrderType.cs
Normal file
@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// Сущность "Тип заказа"
|
||||
/// </summary>
|
||||
public class OrderType
|
||||
{
|
||||
/// <summary>
|
||||
/// Идентификатор
|
||||
/// </summary>
|
||||
public int Id { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Название типа
|
||||
/// </summary>
|
||||
[Required]
|
||||
public string Name { get; private set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Создать модель
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public static OrderType? Create(OrderTypeBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new OrderType
|
||||
{
|
||||
Id = model.Id,
|
||||
Name = model.Name,
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Создать модель
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public static OrderType? Create(OrderTypeViewModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new OrderType
|
||||
{
|
||||
Id = model.Id,
|
||||
Name = model.Name,
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Изменить модель
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
public void Update(OrderTypeBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Name = model.Name;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получить модель отображения
|
||||
/// </summary>
|
||||
public OrderTypeViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
Name = Name,
|
||||
};
|
||||
}
|
||||
}
|
@ -4,7 +4,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WinForms
|
||||
namespace WinForms.DataModels
|
||||
{
|
||||
/// <summary>
|
||||
/// Сущность "Человек"
|
@ -4,7 +4,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WinForms
|
||||
namespace WinForms.DataModels
|
||||
{
|
||||
/// <summary>
|
||||
/// Сущность "Человек"
|
141
Components/WinForms/FormMain.Designer.cs
generated
Normal file
141
Components/WinForms/FormMain.Designer.cs
generated
Normal file
@ -0,0 +1,141 @@
|
||||
namespace WinForms
|
||||
{
|
||||
partial class FormMain
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
371
Components/WinForms/FormMain.cs
Normal file
371
Components/WinForms/FormMain.cs
Normal file
@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// Главная форма
|
||||
/// </summary>
|
||||
public partial class FormMain : Form
|
||||
{
|
||||
/// <summary>
|
||||
/// Бизнес-логика для сущности "Счет"
|
||||
/// </summary>
|
||||
private readonly IOrderLogic _orderLogic;
|
||||
|
||||
/// <summary>
|
||||
/// Бизнес-логика для сущности "Тип заказа"
|
||||
/// </summary>
|
||||
private readonly IOrderTypeLogic _orderTypeLogic;
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="orderLogic"></param>
|
||||
/// <param name="orderTypeLogic"></param>
|
||||
public FormMain(IOrderLogic orderLogic, IOrderTypeLogic orderTypeLogic)
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
_orderLogic = orderLogic;
|
||||
_orderTypeLogic = orderTypeLogic;
|
||||
|
||||
userTreeView.ContextMenuStrip = contextMenuStrip;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Загрузка формы
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void FormMain_Load(object sender, EventArgs e)
|
||||
{
|
||||
var hierarchy = new List<string>()
|
||||
{
|
||||
"Type",
|
||||
"Sum",
|
||||
"Id",
|
||||
"WaiterFullName",
|
||||
};
|
||||
userTreeView.SetHierarchy(hierarchy);
|
||||
|
||||
LoadData();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Элемент контекстного меню "Добавить запись"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void createElementToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
AddElement();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Элемент контекстного меню "Редактировать запись"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void updateElementToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
UpdateElement();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Элемент контекстного меню "Удалить запись"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void deleteElementToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
DeleteElement();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Элемент контекстного меню "Создать документ Word"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void createWordDocumentToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
CreateWordDocument();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Элемент контекстного меню "Создать документ Excel"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void createExcelDocumentToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
CreateExcelDocument();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Элемент контекстного меню "Создать документ Pdf"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void createPdfDocumentToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
CreatePdfDocument();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Элемент контекстного меню "Типы заказов"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void orderTypesToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormOrderTypes));
|
||||
if (!(service is FormOrderTypes form))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
form.ShowDialog();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Загрузка данных
|
||||
/// </summary>
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Добавить запись
|
||||
/// </summary>
|
||||
private void AddElement()
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormOrder));
|
||||
if (!(service is FormOrder form))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Редактировать элемент
|
||||
/// </summary>
|
||||
private void UpdateElement()
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormOrder));
|
||||
if (!(service is FormOrder form))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var selectedOrder = userTreeView.GetSelectedObject<OrderBindingModel>();
|
||||
if (selectedOrder == null)
|
||||
{
|
||||
MessageBox.Show("Выберите счет для редактирования!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
form.Id = Convert.ToInt32(selectedOrder.Id);
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Удалить элемент
|
||||
/// </summary>
|
||||
private void DeleteElement()
|
||||
{
|
||||
if (MessageBox.Show("Удалить запись", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var selectedOrder = userTreeView.GetSelectedObject<OrderBindingModel>();
|
||||
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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Создать документ Word
|
||||
/// </summary>
|
||||
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<OrderViewModel>
|
||||
{
|
||||
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,
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Создать документ Excel
|
||||
/// </summary>
|
||||
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<string> rows = new List<string>();
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Создать документ Pdf
|
||||
/// </summary>
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
132
Components/WinForms/FormMain.resx
Normal file
132
Components/WinForms/FormMain.resx
Normal file
@ -0,0 +1,132 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<metadata name="contextMenuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
<metadata name="componentDocumentWithTableMultiHeaderWord1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>166, 17</value>
|
||||
</metadata>
|
||||
<metadata name="bigTextComponent1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>491, 17</value>
|
||||
</metadata>
|
||||
<metadata name="pdfPieChart1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>653, 17</value>
|
||||
</metadata>
|
||||
</root>
|
@ -9,6 +9,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using WinForms.DataModels;
|
||||
|
||||
namespace WinForms
|
||||
{
|
||||
|
155
Components/WinForms/FormOrder.Designer.cs
generated
Normal file
155
Components/WinForms/FormOrder.Designer.cs
generated
Normal file
@ -0,0 +1,155 @@
|
||||
namespace WinForms
|
||||
{
|
||||
partial class FormOrder
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
159
Components/WinForms/FormOrder.cs
Normal file
159
Components/WinForms/FormOrder.cs
Normal file
@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// Форма для создания или редактирования счета
|
||||
/// </summary>
|
||||
public partial class FormOrder : Form
|
||||
{
|
||||
/// <summary>
|
||||
/// Бизнес-логика для сущности "Счет"
|
||||
/// </summary>
|
||||
private readonly IOrderLogic _orderLogic;
|
||||
|
||||
/// <summary>
|
||||
/// Бизнес-логика для сущности "Тип заказа"
|
||||
/// </summary>
|
||||
private readonly IOrderTypeLogic _orderTypeLogic;
|
||||
|
||||
/// <summary>
|
||||
/// Идентификатор счета
|
||||
/// </summary>
|
||||
private int? _id;
|
||||
|
||||
/// <summary>
|
||||
/// Идентификатор счета
|
||||
/// </summary>
|
||||
public int Id { set { _id = value; } }
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="orderLogic"></param>
|
||||
/// <param name="orderTypeLogic"></param>
|
||||
public FormOrder(IOrderLogic orderLogic, IOrderTypeLogic orderTypeLogic)
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
_orderLogic = orderLogic;
|
||||
_orderTypeLogic = orderTypeLogic;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Загрузка формы
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Кнопка "Сохранить"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Кнопка "Отмена"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void buttonCancel_Click(object sender, EventArgs e)
|
||||
{
|
||||
DialogResult = DialogResult.Cancel;
|
||||
Close();
|
||||
}
|
||||
}
|
||||
}
|
120
Components/WinForms/FormOrder.resx
Normal file
120
Components/WinForms/FormOrder.resx
Normal file
@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
66
Components/WinForms/FormOrderTypes.Designer.cs
generated
Normal file
66
Components/WinForms/FormOrderTypes.Designer.cs
generated
Normal file
@ -0,0 +1,66 @@
|
||||
namespace WinForms
|
||||
{
|
||||
partial class FormOrderTypes
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
159
Components/WinForms/FormOrderTypes.cs
Normal file
159
Components/WinForms/FormOrderTypes.cs
Normal file
@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// Форма для типов заказов
|
||||
/// </summary>
|
||||
public partial class FormOrderTypes : Form
|
||||
{
|
||||
/// <summary>
|
||||
/// Бизнес-логика для сущности "Тип заказа"
|
||||
/// </summary>
|
||||
private readonly IOrderTypeLogic _orderTypeLogic;
|
||||
|
||||
/// <summary>
|
||||
/// Список типов заказов
|
||||
/// </summary>
|
||||
private BindingList<OrderTypeBindingModel> _bindingList;
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="orderTypeLogic"></param>
|
||||
public FormOrderTypes(IOrderTypeLogic orderTypeLogic)
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
_orderTypeLogic = orderTypeLogic;
|
||||
_bindingList = new BindingList<OrderTypeBindingModel>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Загрузка формы
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void FormOrderTypes_Load(object sender, EventArgs e)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Создание или редактирование типа заказа
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
/// <exception cref="Exception"></exception>
|
||||
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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Обработка нажатия кнопок
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
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<OrderTypeBindingModel>(_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<OrderTypeBindingModel>(_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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Загрузка данных
|
||||
/// </summary>
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
120
Components/WinForms/FormOrderTypes.resx
Normal file
120
Components/WinForms/FormOrderTypes.resx
Normal file
@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
@ -1,3 +1,5 @@
|
||||
using WinForms.DataModels;
|
||||
|
||||
namespace WinForms
|
||||
{
|
||||
/// <summary>
|
||||
|
@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// IoC-êîíòåéíåð
|
||||
/// </summary>
|
||||
private static ServiceProvider? _serviceProvider;
|
||||
|
||||
/// <summary>
|
||||
/// IoC-êîíòåéíåð
|
||||
/// </summary>
|
||||
public static ServiceProvider? ServiceProvider => _serviceProvider;
|
||||
|
||||
/// <summary>
|
||||
/// The main entry point for the application.
|
||||
/// </summary>
|
||||
@ -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<FormMain>());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Êîíôèãóðàöèÿ ñåðâèñîâ
|
||||
/// </summary>
|
||||
/// <param name="services"></param>
|
||||
private static void ConfigureServices(ServiceCollection services)
|
||||
{
|
||||
// Ëîããåð
|
||||
services.AddLogging(option =>
|
||||
{
|
||||
option.SetMinimumLevel(LogLevel.Information);
|
||||
option.AddNLog("nlog.config");
|
||||
});
|
||||
|
||||
// IoC-êîíòåéíåð, õðàíèëèùà
|
||||
services.AddTransient<IOrderStorage, OrderStorage>();
|
||||
services.AddTransient<IOrderTypeStorage, OrderTypeStorage>();
|
||||
|
||||
// IoC-êîíòåéíåð, áèçíåñ-ëîãèêà
|
||||
services.AddTransient<IOrderLogic, OrderLogic>();
|
||||
services.AddTransient<IOrderTypeLogic, OrderTypeLogic>();
|
||||
|
||||
// IoC-êîíòåéíåð, ôîðìû îòîáðàæåíèÿ
|
||||
services.AddTransient<FormVisualComponents>();
|
||||
services.AddTransient<FormNonVisualComponents>();
|
||||
services.AddTransient<FormMain>();
|
||||
services.AddTransient<FormOrder>();
|
||||
services.AddTransient<FormOrderTypes>();
|
||||
}
|
||||
}
|
||||
}
|
@ -9,7 +9,36 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="nlog.config" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="nlog.config">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="ComponentsLibrary" Version="1.0.0" />
|
||||
<PackageReference Include="ComponentsLibraryNet60" Version="1.0.0" />
|
||||
<PackageReference Include="ControlsLibraryNet60" Version="1.0.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.13">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
|
||||
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.13" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\BusinessLogics\BusinessLogics.csproj" />
|
||||
<ProjectReference Include="..\Components\Components.csproj" />
|
||||
<ProjectReference Include="..\Contracts\Contracts.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="packages\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
15
Components/WinForms/nlog.config
Normal file
15
Components/WinForms/nlog.config
Normal file
@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<configuration>
|
||||
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
autoReload="true" internalLogLevel="Info">
|
||||
|
||||
<targets>
|
||||
<target xsi:type="File" name="tofile" fileName="log-${shortdate}.log" />
|
||||
</targets>
|
||||
|
||||
<rules>
|
||||
<logger name="*" minLevel="Debug" writeTo="tofile" />
|
||||
</rules>
|
||||
</nlog>
|
||||
</configuration>
|
Loading…
Reference in New Issue
Block a user