Implementers

This commit is contained in:
Алишер Бустонов 2023-04-20 22:56:34 +04:00
parent 8e21d57f05
commit 684f7c0c9e
46 changed files with 1957 additions and 113 deletions

View File

@ -3,8 +3,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17 # Visual Studio Version 17
VisualStudioVersion = 17.3.32825.248 VisualStudioVersion = 17.3.32825.248
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FishFactoryView", "FishFactory\FishFactoryView.csproj", "{493271EC-376B-4F9E-A22B-433080D12559}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FishFactoryDataModels", "FishFactoryDataModels\FishFactoryDataModels.csproj", "{F6B5393D-1D0E-4A9C-A7F3-48C29DC996B4}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FishFactoryDataModels", "FishFactoryDataModels\FishFactoryDataModels.csproj", "{F6B5393D-1D0E-4A9C-A7F3-48C29DC996B4}"
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FishFactoryContracts", "FishFactoryContracts\FishFactoryContracts.csproj", "{B038384B-AEAB-4709-BFC6-84E8A485A810}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FishFactoryContracts", "FishFactoryContracts\FishFactoryContracts.csproj", "{B038384B-AEAB-4709-BFC6-84E8A485A810}"
@ -17,9 +15,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FishFactoryFileImplement",
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FishFactoryDatabaseImplement", "FishFactoryDatabaseImplement\FishFactoryDatabaseImplement.csproj", "{F5D03645-1AAA-492E-87CD-9903C526FD7B}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FishFactoryDatabaseImplement", "FishFactoryDatabaseImplement\FishFactoryDatabaseImplement.csproj", "{F5D03645-1AAA-492E-87CD-9903C526FD7B}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FishFactoryRestApi", "FishFactoryRestApi\FishFactoryRestApi.csproj", "{9781080B-C8D4-47F4-B30D-B46E30AE1E24}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FishFactoryRestApi", "FishFactoryRestApi\FishFactoryRestApi.csproj", "{9781080B-C8D4-47F4-B30D-B46E30AE1E24}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FishFactoryClientApp", "FishFactoryClientApp\FishFactoryClientApp.csproj", "{92455D8F-A94F-498B-853E-479DCF272DED}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FishFactoryClientApp", "FishFactoryClientApp\FishFactoryClientApp.csproj", "{92455D8F-A94F-498B-853E-479DCF272DED}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FishFactoryView", "FishFactoryView\FishFactoryView.csproj", "{E26B299A-FAF3-4B74-8F69-6605798D47A2}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -27,10 +27,6 @@ Global
Release|Any CPU = Release|Any CPU Release|Any CPU = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution GlobalSection(ProjectConfigurationPlatforms) = postSolution
{493271EC-376B-4F9E-A22B-433080D12559}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{493271EC-376B-4F9E-A22B-433080D12559}.Debug|Any CPU.Build.0 = Debug|Any CPU
{493271EC-376B-4F9E-A22B-433080D12559}.Release|Any CPU.ActiveCfg = Release|Any CPU
{493271EC-376B-4F9E-A22B-433080D12559}.Release|Any CPU.Build.0 = Release|Any CPU
{F6B5393D-1D0E-4A9C-A7F3-48C29DC996B4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {F6B5393D-1D0E-4A9C-A7F3-48C29DC996B4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F6B5393D-1D0E-4A9C-A7F3-48C29DC996B4}.Debug|Any CPU.Build.0 = Debug|Any CPU {F6B5393D-1D0E-4A9C-A7F3-48C29DC996B4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F6B5393D-1D0E-4A9C-A7F3-48C29DC996B4}.Release|Any CPU.ActiveCfg = Release|Any CPU {F6B5393D-1D0E-4A9C-A7F3-48C29DC996B4}.Release|Any CPU.ActiveCfg = Release|Any CPU
@ -63,6 +59,10 @@ Global
{92455D8F-A94F-498B-853E-479DCF272DED}.Debug|Any CPU.Build.0 = Debug|Any CPU {92455D8F-A94F-498B-853E-479DCF272DED}.Debug|Any CPU.Build.0 = Debug|Any CPU
{92455D8F-A94F-498B-853E-479DCF272DED}.Release|Any CPU.ActiveCfg = Release|Any CPU {92455D8F-A94F-498B-853E-479DCF272DED}.Release|Any CPU.ActiveCfg = Release|Any CPU
{92455D8F-A94F-498B-853E-479DCF272DED}.Release|Any CPU.Build.0 = Release|Any CPU {92455D8F-A94F-498B-853E-479DCF272DED}.Release|Any CPU.Build.0 = Release|Any CPU
{E26B299A-FAF3-4B74-8F69-6605798D47A2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E26B299A-FAF3-4B74-8F69-6605798D47A2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E26B299A-FAF3-4B74-8F69-6605798D47A2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E26B299A-FAF3-4B74-8F69-6605798D47A2}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

View File

@ -0,0 +1,119 @@
using Microsoft.Extensions.Logging;
using FishFactoryContracts.BindingModels;
using FishFactoryContracts.BusinessLogicsContracts;
using FishFactoryContracts.SearchModels;
using FishFactoryContracts.StoragesContracts;
using FishFactoryContracts.ViewModels;
namespace FishFactoryBusinessLogic.BusinessLogics
{
public class ImplementerLogic : IImplementerLogic
{
private readonly ILogger _logger;
private readonly IImplementerStorage _implementerStorage;
public ImplementerLogic(ILogger<ImplementerLogic> logger, IImplementerStorage implementerStorage)
{
_logger = logger;
_implementerStorage = implementerStorage;
}
public bool Create(ImplementerBindingModel model)
{
CheckModel(model);
if (_implementerStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Delete(ImplementerBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_implementerStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
public ImplementerViewModel? ReadElement(ImplementerSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. ImplementerFIO:{ImplementerFIO}.Id:{Id}", model.ImplementerFIO, model.Id);
var element = _implementerStorage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadElement element not found");
return null;
}
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
return element;
}
public List<ImplementerViewModel>? ReadList(ImplementerSearchModel? model)
{
_logger.LogInformation("ReadList. ImplementerFIO:{ImplementerFIO}.Id:{Id}", model?.ImplementerFIO, model?.Id);
var list = model == null ? _implementerStorage.GetFullList() : _implementerStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public bool Update(ImplementerBindingModel model)
{
CheckModel(model);
if (_implementerStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
private void CheckModel(ImplementerBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.ImplementerFIO))
{
throw new ArgumentNullException("У исполнителя должно быть ФИО", nameof(model.ImplementerFIO));
}
if (model.Qualification <= 0)
{
throw new ArgumentNullException("У исполнителя квалификация должна быть больше 0", nameof(model.Qualification));
}
if (model.WorkExperience <= 0)
{
throw new ArgumentNullException("У исполнителя стаж должен быть больше 0", nameof(model.WorkExperience));
}
if (string.IsNullOrEmpty(model.Password))
{
throw new ArgumentNullException("У исполнителя должен быть пароль", nameof(model.Password));
}
_logger.LogInformation("Implementer. ImplementerFIO:{ImplementerFIO}.Qualification:{Qualification}.WorkExperience:{WorkExperience} Id: {Id}", model.ImplementerFIO, model.Qualification, model.WorkExperience, model.Id);
var element = _implementerStorage.GetElement(new ImplementerSearchModel
{
ImplementerFIO = model.ImplementerFIO
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("Исполнитель с таким ФИО уже есть");
}
}
}
}

View File

@ -39,14 +39,23 @@ namespace FishFactoryBusinessLogic.BusinessLogics
public bool StatusUpdate(OrderBindingModel model, OrderStatus newStatus) public bool StatusUpdate(OrderBindingModel model, OrderStatus newStatus)
{ {
CheckModel(model); var viewModel = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id });
if (model.Status + 1 != newStatus) if (viewModel == null)
{
throw new ArgumentNullException(nameof(model));
}
if (viewModel.Status + 1 != newStatus)
{ {
_logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Order status incorrect."); _logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Order status incorrect.");
return false; return false;
} }
model.Status = newStatus; model.Status = newStatus;
if (model.Status == OrderStatus.Выдан) model.DateImplement = DateTime.Now; if (model.Status == OrderStatus.Готов) model.DateImplement = DateTime.Now;
else
{
model.DateImplement = viewModel.DateImplement;
}
CheckModel(model, false);
if (_orderStorage.Update(model) == null) if (_orderStorage.Update(model) == null)
{ {
model.Status--; model.Status--;
@ -84,6 +93,23 @@ namespace FishFactoryBusinessLogic.BusinessLogics
return list; return list;
} }
public OrderViewModel? ReadElement(OrderSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. Id:{ Id}", model.Id);
var element = _orderStorage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadElement element not found");
return null;
}
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
return element;
}
private void CheckModel(OrderBindingModel model, bool withParams = true) private void CheckModel(OrderBindingModel model, bool withParams = true)
{ {
if (model == null) if (model == null)

View File

@ -0,0 +1,144 @@
using Microsoft.Extensions.Logging;
using FishFactoryContracts.BindingModels;
using FishFactoryContracts.BusinessLogicsContracts;
using FishFactoryContracts.SearchModels;
using FishFactoryContracts.ViewModels;
using FishFactoryDataModels.Enums;
namespace FishFactoryBusinessLogic.BusinessLogics
{
public class WorkModeling : IWorkProcess
{
private readonly ILogger _logger;
private readonly Random _rnd;
private IOrderLogic? _orderLogic;
public WorkModeling(ILogger<WorkModeling> logger)
{
_logger = logger;
_rnd = new Random(1000);
}
public void DoWork(IImplementerLogic implementerLogic, IOrderLogic orderLogic)
{
_orderLogic = orderLogic;
var implementers = implementerLogic.ReadList(null);
if (implementers == null)
{
_logger.LogWarning("DoWork. Implementers is null");
return;
}
var orders = _orderLogic.ReadList(new OrderSearchModel { OrderStatus = OrderStatus.Принят });
if (orders == null || orders.Count == 0)
{
_logger.LogWarning("DoWork. Orders is null or empty");
return;
}
_logger.LogDebug("DoWork for {Count} orders", orders.Count);
foreach (var implementer in implementers)
{
Task.Run(() => WorkerWorkAsync(implementer, orders));
}
}
/// <summary>
/// Имитация работы исполнителя
/// </summary>
/// <param name="implementer"></param>
/// <param name="orders"></param>
private async Task WorkerWorkAsync(ImplementerViewModel implementer, List<OrderViewModel> orders)
{
if (_orderLogic == null || implementer == null)
{
return;
}
await RunOrderInWork(implementer);
await Task.Run(() =>
{
foreach (var order in orders)
{
try
{
_logger.LogDebug("DoWork. Worker {Id} try get order {Order}", implementer.Id, order.Id);
// пытаемся назначить заказ на исполнителя
_orderLogic.TakeOrderInWork(new OrderBindingModel
{
Id = order.Id,
ImplementerId = implementer.Id
});
// делаем работу
Thread.Sleep(implementer.WorkExperience * _rnd.Next(100, 1000) * order.Count);
_logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, order.Id);
_orderLogic.FinishOrder(new OrderBindingModel
{
Id = order.Id
});
// отдыхаем
Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100));
}
// кто-то мог уже перехватить заказ, игнорируем ошибку
catch (InvalidOperationException ex)
{
_logger.LogWarning(ex, "Error try get work");
}
// заканчиваем выполнение имитации в случае иной ошибки
catch (Exception ex)
{
_logger.LogError(ex, "Error while do work");
throw;
}
}
});
}
/// <summary>
/// Ищем заказ, которые уже в работе (вдруг исполнителя прервали)
/// </summary>
/// <param name="implementer"></param>
/// <returns></returns>
private async Task RunOrderInWork(ImplementerViewModel implementer)
{
if (_orderLogic == null || implementer == null)
{
return;
}
try
{
var runOrder = await Task.Run(() => _orderLogic.ReadElement(new OrderSearchModel
{
ImplementerId = implementer.Id,
OrderStatus = OrderStatus.Выполняется
}));
if (runOrder == null)
{
return;
}
_logger.LogDebug("DoWork. Worker {Id} back to order {Order}", implementer.Id, runOrder.Id);
// доделываем работу
Thread.Sleep(implementer.WorkExperience * _rnd.Next(100, 300) * runOrder.Count);
_logger.LogDebug("DoWork. Worker {Id} finish order {Order}", implementer.Id, runOrder.Id);
_orderLogic.FinishOrder(new OrderBindingModel
{
Id = runOrder.Id
});
// отдыхаем
Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100));
}
// заказа может не быть, просто игнорируем ошибку
catch (InvalidOperationException ex)
{
_logger.LogWarning(ex, "Error try get work");
}
// а может возникнуть иная ошибка, тогда просто заканчиваем выполнение имитации
catch (Exception ex)
{
_logger.LogError(ex, "Error while do work");
throw;
}
}
}
}

View File

@ -0,0 +1,20 @@
using FishFactoryDataModels.Models;
namespace FishFactoryContracts.BindingModels
{
/// <summary>
/// Исполнитель, выполняющий заказы
/// </summary>
public class ImplementerBindingModel : IImplementerModel
{
public int Id { get; set; }
public string ImplementerFIO { get; set; } = string.Empty;
public string Password { get; set; } = string.Empty;
public int WorkExperience { get; set; }
public int Qualification { get; set; }
}
}

View File

@ -7,7 +7,7 @@ namespace FishFactoryContracts.BindingModels
{ {
public int CannedId { get; set; } public int CannedId { get; set; }
public int ClientId { get; set; } public int ClientId { get; set; }
public string CannedName { get; set; } = string.Empty; public int? ImplementerId { get; set; }
public int Count { get; set; } public int Count { get; set; }
public double Sum { get; set; } public double Sum { get; set; }
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;

View File

@ -0,0 +1,19 @@
using FishFactoryContracts.BindingModels;
using FishFactoryContracts.SearchModels;
using FishFactoryContracts.ViewModels;
namespace FishFactoryContracts.BusinessLogicsContracts
{
public interface IImplementerLogic
{
List<ImplementerViewModel>? ReadList(ImplementerSearchModel? model);
ImplementerViewModel? ReadElement(ImplementerSearchModel model);
bool Create(ImplementerBindingModel model);
bool Update(ImplementerBindingModel model);
bool Delete(ImplementerBindingModel model);
}
}

View File

@ -7,6 +7,7 @@ namespace FishFactoryContracts.BusinessLogicsContracts
public interface IOrderLogic public interface IOrderLogic
{ {
List<OrderViewModel>? ReadList(OrderSearchModel? model); List<OrderViewModel>? ReadList(OrderSearchModel? model);
OrderViewModel? ReadElement(OrderSearchModel model);
bool CreateOrder(OrderBindingModel model); bool CreateOrder(OrderBindingModel model);
bool TakeOrderInWork(OrderBindingModel model); bool TakeOrderInWork(OrderBindingModel model);
bool FinishOrder(OrderBindingModel model); bool FinishOrder(OrderBindingModel model);

View File

@ -0,0 +1,10 @@
namespace FishFactoryContracts.BusinessLogicsContracts
{
public interface IWorkProcess
{
/// <summary>
/// Запуск работ
/// </summary>
void DoWork(IImplementerLogic implementerLogic, IOrderLogic orderLogic);
}
}

View File

@ -0,0 +1,11 @@
namespace FishFactoryContracts.SearchModels
{
public class ImplementerSearchModel
{
public int? Id { get; set; }
public string? ImplementerFIO { get; set; }
public string? Password { get; set; }
}
}

View File

@ -1,9 +1,13 @@
namespace FishFactoryContracts.SearchModels using FishFactoryDataModels.Enums;
namespace FishFactoryContracts.SearchModels
{ {
public class OrderSearchModel public class OrderSearchModel
{ {
public int? Id { get; set; } public int? Id { get; set; }
public int? ClientId { get; set; } public int? ClientId { get; set; }
public int? ImplementerId { get; set; }
public OrderStatus? OrderStatus { get; set; }
public DateTime? DateFrom { get; set; } public DateTime? DateFrom { get; set; }
public DateTime? DateTo { get; set; } public DateTime? DateTo { get; set; }
} }

View File

@ -0,0 +1,21 @@
using FishFactoryContracts.BindingModels;
using FishFactoryContracts.SearchModels;
using FishFactoryContracts.ViewModels;
namespace FishFactoryContracts.StoragesContracts
{
public interface IImplementerStorage
{
List<ImplementerViewModel> GetFullList();
List<ImplementerViewModel> GetFilteredList(ImplementerSearchModel model);
ImplementerViewModel? GetElement(ImplementerSearchModel model);
ImplementerViewModel? Insert(ImplementerBindingModel model);
ImplementerViewModel? Update(ImplementerBindingModel model);
ImplementerViewModel? Delete(ImplementerBindingModel model);
}
}

View File

@ -0,0 +1,25 @@
using FishFactoryDataModels.Models;
using System.ComponentModel;
namespace FishFactoryContracts.ViewModels
{
/// <summary>
/// Исполнитель, выполняющий заказы
/// </summary>
public class ImplementerViewModel : IImplementerModel
{
public int Id { get; set; }
[DisplayName("ФИО исполнителя")]
public string ImplementerFIO { get; set; } = string.Empty;
[DisplayName("Пароль")]
public string Password { get; set; } = string.Empty;
[DisplayName("Стаж работы")]
public int WorkExperience { get; set; }
[DisplayName("Квалификация")]
public int Qualification { get; set; }
}
}

View File

@ -10,10 +10,13 @@ namespace FishFactoryContracts.ViewModels
public int Id { get; set; } public int Id { get; set; }
public int CannedId { get; set; } public int CannedId { get; set; }
public int ClientId { get; set; } public int ClientId { get; set; }
public int? ImplementerId { get; set; }
[DisplayName("Консерва")] [DisplayName("Консерва")]
public string CannedName { get; set; } = string.Empty; public string CannedName { get; set; } = string.Empty;
[DisplayName("Клиент")] [DisplayName("Клиент")]
public string ClientFIO { get; set; } = string.Empty; public string ClientFIO { get; set; } = string.Empty;
[DisplayName("Исполнитель")]
public string ImplementerFIO { get; set; } = string.Empty;
[DisplayName("Количество")] [DisplayName("Количество")]
public int Count { get; set; } public int Count { get; set; }
[DisplayName("Сумма")] [DisplayName("Сумма")]

View File

@ -0,0 +1,13 @@
namespace FishFactoryDataModels.Models
{
public interface IImplementerModel : IId
{
string ImplementerFIO { get; }
string Password { get; }
int WorkExperience { get; }
int Qualification { get; }
}
}

View File

@ -23,5 +23,7 @@ namespace FishFactoryDatabaseImplement
public virtual DbSet<Order> Orders { set; get; } public virtual DbSet<Order> Orders { set; get; }
public virtual DbSet<Client> Clients { set; get; } public virtual DbSet<Client> Clients { set; get; }
public virtual DbSet<Implementer> Implementers { set; get; }
} }
} }

View File

@ -0,0 +1,98 @@
using Microsoft.EntityFrameworkCore;
using FishFactoryContracts.BindingModels;
using FishFactoryContracts.SearchModels;
using FishFactoryContracts.StoragesContracts;
using FishFactoryContracts.ViewModels;
using FishFactoryDatabaseImplement.Models;
namespace FishFactoryDatabaseImplement.Implements
{
public class ImplementerStorage : IImplementerStorage
{
public ImplementerViewModel? Delete(ImplementerBindingModel model)
{
using var context = new FishFactoryDatabase();
var element = context.Implementers.Include(x => x.Orders).FirstOrDefault(x => x.Id == model.Id);
if (element != null)
{
context.Implementers.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
public ImplementerViewModel? GetElement(ImplementerSearchModel model)
{
using var context = new FishFactoryDatabase();
if (model.Id.HasValue)
{
return context.Implementers
.Include(x => x.Orders)
.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)?.GetViewModel;
}
else if (!string.IsNullOrEmpty(model.ImplementerFIO) && !string.IsNullOrEmpty(model.Password))
{
return context.Implementers.Include(x => x.Orders)
.FirstOrDefault(x => x.ImplementerFIO == model.ImplementerFIO && x.Password == model.Password)?.GetViewModel;
}
else if (!string.IsNullOrEmpty(model.ImplementerFIO))
{
return context.Implementers.Include(x => x.Orders)
.FirstOrDefault(x => x.ImplementerFIO == model.ImplementerFIO)?.GetViewModel;
}
return null;
}
public List<ImplementerViewModel> GetFilteredList(ImplementerSearchModel model)
{
if (string.IsNullOrEmpty(model.ImplementerFIO))
{
return new();
}
using var context = new FishFactoryDatabase();
return context.Implementers
.Include(x => x.Orders)
.Where(x => x.ImplementerFIO.Contains(model.ImplementerFIO))
.Select(x => x.GetViewModel)
.ToList();
}
public List<ImplementerViewModel> GetFullList()
{
using var context = new FishFactoryDatabase();
return context.Implementers
.Include(x => x.Orders)
.Select(x => x.GetViewModel)
.ToList();
}
public ImplementerViewModel? Insert(ImplementerBindingModel model)
{
var newImplementer = Implementer.Create(model);
if (newImplementer == null)
{
return null;
}
using var context = new FishFactoryDatabase();
context.Implementers.Add(newImplementer);
context.SaveChanges();
return context.Implementers
.Include(x => x.Orders)
.FirstOrDefault(x => x.Id == newImplementer.Id)?.GetViewModel;
}
public ImplementerViewModel? Update(ImplementerBindingModel model)
{
using var context = new FishFactoryDatabase();
var implementer = context.Implementers.Include(x => x.Orders).FirstOrDefault(x => x.Id == model.Id);
if (implementer == null)
{
return null;
}
implementer.Update(model);
context.SaveChanges();
return implementer.GetViewModel;
}
}
}

View File

@ -15,6 +15,7 @@ namespace FishFactoryDatabaseImplement.Implements
var element = context.Orders var element = context.Orders
.Include(x => x.Canned) .Include(x => x.Canned)
.Include(x => x.Client) .Include(x => x.Client)
.Include(x => x.Implementer)
.FirstOrDefault(rec => rec.Id == model.Id); .FirstOrDefault(rec => rec.Id == model.Id);
if (element != null) if (element != null)
{ {
@ -27,30 +28,44 @@ namespace FishFactoryDatabaseImplement.Implements
public OrderViewModel? GetElement(OrderSearchModel model) public OrderViewModel? GetElement(OrderSearchModel model)
{ {
if (!model.Id.HasValue)
{
return null;
}
using var context = new FishFactoryDatabase(); using var context = new FishFactoryDatabase();
return context.Orders if (model.Id.HasValue)
.Include(x => x.Canned) {
.Include(x => x.Client) return context.Orders
.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id) .Include(x => x.Canned)
?.GetViewModel; .Include(x => x.Client)
.Include(x => x.Implementer)
.FirstOrDefault(x => x.Id == model.Id)
?.GetViewModel;
}
else if (model.ImplementerId.HasValue && model.OrderStatus.HasValue)
{
return context.Orders
.Include(x => x.Canned)
.Include(x => x.Client).Include(x => x.Implementer)
.FirstOrDefault(x => x.ImplementerId == model.ImplementerId && x.Status == model.OrderStatus)
?.GetViewModel;
}
else if (model.ImplementerId.HasValue)
{
return context.Orders
.Include(x => x.Canned)
.Include(x => x.Client).Include(x => x.Implementer)
.FirstOrDefault(x => x.ImplementerId == model.ImplementerId)
?.GetViewModel;
}
return null;
} }
public List<OrderViewModel> GetFilteredList(OrderSearchModel model) public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
{ {
if (!model.Id.HasValue && !model.DateFrom.HasValue && !model.ClientId.HasValue) if (model == null) return new();
{
return new();
}
using var context = new FishFactoryDatabase(); using var context = new FishFactoryDatabase();
if (model.DateFrom.HasValue) if (model.DateFrom.HasValue && model.DateTo.HasValue)
{ {
return context.Orders return context.Orders
.Include(x => x.Canned) .Include(x => x.Canned)
.Include(x => x.Client) .Include(x => x.Client).Include(x => x.Implementer)
.Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo) .Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo)
.Select(x => x.GetViewModel) .Select(x => x.GetViewModel)
.ToList(); .ToList();
@ -58,16 +73,25 @@ namespace FishFactoryDatabaseImplement.Implements
else if (model.ClientId.HasValue) else if (model.ClientId.HasValue)
return context.Orders return context.Orders
.Include(x => x.Canned) .Include(x => x.Canned)
.Include(x => x.Client) .Include(x => x.Client).Include(x => x.Implementer)
.Where(x => x.ClientId == model.ClientId) .Where(x => x.ClientId == model.ClientId)
.Select(x => x.GetViewModel) .Select(x => x.GetViewModel)
.ToList(); .ToList();
return context.Orders else if (model.OrderStatus.HasValue)
.Include(x => x.Canned) return context.Orders
.Include(x => x.Client) .Include(x => x.Canned)
.Where(x => x.Id == model.Id) .Include(x => x.Client).Include(x => x.Implementer)
.Select(x => x.GetViewModel) .Where(x => x.Status == model.OrderStatus)
.ToList(); .Select(x => x.GetViewModel)
.ToList();
else if (model.Id.HasValue)
return context.Orders
.Include(x => x.Canned)
.Include(x => x.Client).Include(x => x.Implementer)
.Where(x => x.Id == model.Id)
.Select(x => x.GetViewModel)
.ToList();
return new();
} }
public List<OrderViewModel> GetFullList() public List<OrderViewModel> GetFullList()
{ {
@ -75,6 +99,7 @@ namespace FishFactoryDatabaseImplement.Implements
return context.Orders return context.Orders
.Include(x => x.Canned) .Include(x => x.Canned)
.Include(x => x.Client) .Include(x => x.Client)
.Include(x => x.Implementer)
.Select(x => x.GetViewModel) .Select(x => x.GetViewModel)
.ToList(); .ToList();
} }
@ -92,6 +117,7 @@ namespace FishFactoryDatabaseImplement.Implements
return context.Orders return context.Orders
.Include(x => x.Canned) .Include(x => x.Canned)
.Include(x => x.Client) .Include(x => x.Client)
.Include(x => x.Implementer)
.FirstOrDefault(x => x.Id == newOrder.Id) .FirstOrDefault(x => x.Id == newOrder.Id)
?.GetViewModel; ?.GetViewModel;
} }
@ -102,6 +128,7 @@ namespace FishFactoryDatabaseImplement.Implements
var order = context.Orders var order = context.Orders
.Include(x => x.Canned) .Include(x => x.Canned)
.Include(x => x.Client) .Include(x => x.Client)
.Include(x => x.Implementer)
.FirstOrDefault(x => x.Id == model.Id); .FirstOrDefault(x => x.Id == model.Id);
if (order == null) if (order == null)
{ {

View File

@ -12,7 +12,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace FishFactoryDatabaseImplement.Migrations namespace FishFactoryDatabaseImplement.Migrations
{ {
[DbContext(typeof(FishFactoryDatabase))] [DbContext(typeof(FishFactoryDatabase))]
[Migration("20230412125217_InitialCreate")] [Migration("20230412194337_InitialCreate")]
partial class InitialCreate partial class InitialCreate
{ {
/// <inheritdoc /> /// <inheritdoc />
@ -96,6 +96,33 @@ namespace FishFactoryDatabaseImplement.Migrations
b.ToTable("Clients"); b.ToTable("Clients");
}); });
modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Implementer", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("ImplementerFIO")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("Qualification")
.HasColumnType("int");
b.Property<int>("WorkExperience")
.HasColumnType("int");
b.HasKey("Id");
b.ToTable("Implementers");
});
modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Ingredient", b => modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Ingredient", b =>
{ {
b.Property<int>("Id") b.Property<int>("Id")
@ -139,6 +166,9 @@ namespace FishFactoryDatabaseImplement.Migrations
b.Property<DateTime?>("DateImplement") b.Property<DateTime?>("DateImplement")
.HasColumnType("datetime2"); .HasColumnType("datetime2");
b.Property<int?>("ImplementerId")
.HasColumnType("int");
b.Property<int>("Status") b.Property<int>("Status")
.HasColumnType("int"); .HasColumnType("int");
@ -151,6 +181,8 @@ namespace FishFactoryDatabaseImplement.Migrations
b.HasIndex("ClientId"); b.HasIndex("ClientId");
b.HasIndex("ImplementerId");
b.ToTable("Orders"); b.ToTable("Orders");
}); });
@ -187,9 +219,15 @@ namespace FishFactoryDatabaseImplement.Migrations
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
b.HasOne("FishFactoryDatabaseImplement.Models.Implementer", "Implementer")
.WithMany("Orders")
.HasForeignKey("ImplementerId");
b.Navigation("Canned"); b.Navigation("Canned");
b.Navigation("Client"); b.Navigation("Client");
b.Navigation("Implementer");
}); });
modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Canned", b => modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Canned", b =>
@ -204,6 +242,11 @@ namespace FishFactoryDatabaseImplement.Migrations
b.Navigation("Orders"); b.Navigation("Orders");
}); });
modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Implementer", b =>
{
b.Navigation("Orders");
});
modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Ingredient", b => modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Ingredient", b =>
{ {
b.Navigation("SushiIngredients"); b.Navigation("SushiIngredients");

View File

@ -40,6 +40,22 @@ namespace FishFactoryDatabaseImplement.Migrations
table.PrimaryKey("PK_Clients", x => x.Id); table.PrimaryKey("PK_Clients", x => x.Id);
}); });
migrationBuilder.CreateTable(
name: "Implementers",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
ImplementerFIO = table.Column<string>(type: "nvarchar(max)", nullable: false),
Password = table.Column<string>(type: "nvarchar(max)", nullable: false),
WorkExperience = table.Column<int>(type: "int", nullable: false),
Qualification = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Implementers", x => x.Id);
});
migrationBuilder.CreateTable( migrationBuilder.CreateTable(
name: "Ingredients", name: "Ingredients",
columns: table => new columns: table => new
@ -62,6 +78,7 @@ namespace FishFactoryDatabaseImplement.Migrations
.Annotation("SqlServer:Identity", "1, 1"), .Annotation("SqlServer:Identity", "1, 1"),
CannedId = table.Column<int>(type: "int", nullable: false), CannedId = table.Column<int>(type: "int", nullable: false),
ClientId = table.Column<int>(type: "int", nullable: false), ClientId = table.Column<int>(type: "int", nullable: false),
ImplementerId = table.Column<int>(type: "int", nullable: true),
Count = table.Column<int>(type: "int", nullable: false), Count = table.Column<int>(type: "int", nullable: false),
Sum = table.Column<double>(type: "float", nullable: false), Sum = table.Column<double>(type: "float", nullable: false),
Status = table.Column<int>(type: "int", nullable: false), Status = table.Column<int>(type: "int", nullable: false),
@ -83,6 +100,11 @@ namespace FishFactoryDatabaseImplement.Migrations
principalTable: "Clients", principalTable: "Clients",
principalColumn: "Id", principalColumn: "Id",
onDelete: ReferentialAction.Cascade); onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Orders_Implementers_ImplementerId",
column: x => x.ImplementerId,
principalTable: "Implementers",
principalColumn: "Id");
}); });
migrationBuilder.CreateTable( migrationBuilder.CreateTable(
@ -131,6 +153,11 @@ namespace FishFactoryDatabaseImplement.Migrations
name: "IX_Orders_ClientId", name: "IX_Orders_ClientId",
table: "Orders", table: "Orders",
column: "ClientId"); column: "ClientId");
migrationBuilder.CreateIndex(
name: "IX_Orders_ImplementerId",
table: "Orders",
column: "ImplementerId");
} }
/// <inheritdoc /> /// <inheritdoc />
@ -150,6 +177,9 @@ namespace FishFactoryDatabaseImplement.Migrations
migrationBuilder.DropTable( migrationBuilder.DropTable(
name: "Clients"); name: "Clients");
migrationBuilder.DropTable(
name: "Implementers");
} }
} }
} }

View File

@ -93,6 +93,33 @@ namespace FishFactoryDatabaseImplement.Migrations
b.ToTable("Clients"); b.ToTable("Clients");
}); });
modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Implementer", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("ImplementerFIO")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("Qualification")
.HasColumnType("int");
b.Property<int>("WorkExperience")
.HasColumnType("int");
b.HasKey("Id");
b.ToTable("Implementers");
});
modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Ingredient", b => modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Ingredient", b =>
{ {
b.Property<int>("Id") b.Property<int>("Id")
@ -136,6 +163,9 @@ namespace FishFactoryDatabaseImplement.Migrations
b.Property<DateTime?>("DateImplement") b.Property<DateTime?>("DateImplement")
.HasColumnType("datetime2"); .HasColumnType("datetime2");
b.Property<int?>("ImplementerId")
.HasColumnType("int");
b.Property<int>("Status") b.Property<int>("Status")
.HasColumnType("int"); .HasColumnType("int");
@ -148,6 +178,8 @@ namespace FishFactoryDatabaseImplement.Migrations
b.HasIndex("ClientId"); b.HasIndex("ClientId");
b.HasIndex("ImplementerId");
b.ToTable("Orders"); b.ToTable("Orders");
}); });
@ -184,9 +216,15 @@ namespace FishFactoryDatabaseImplement.Migrations
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
b.HasOne("FishFactoryDatabaseImplement.Models.Implementer", "Implementer")
.WithMany("Orders")
.HasForeignKey("ImplementerId");
b.Navigation("Canned"); b.Navigation("Canned");
b.Navigation("Client"); b.Navigation("Client");
b.Navigation("Implementer");
}); });
modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Canned", b => modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Canned", b =>
@ -201,6 +239,11 @@ namespace FishFactoryDatabaseImplement.Migrations
b.Navigation("Orders"); b.Navigation("Orders");
}); });
modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Implementer", b =>
{
b.Navigation("Orders");
});
modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Ingredient", b => modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Ingredient", b =>
{ {
b.Navigation("SushiIngredients"); b.Navigation("SushiIngredients");

View File

@ -0,0 +1,57 @@
using FishFactoryContracts.BindingModels;
using FishFactoryContracts.ViewModels;
using FishFactoryDataModels.Models;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
namespace FishFactoryDatabaseImplement.Models
{
public class Implementer : IImplementerModel
{
public int Id { get; private set; }
[Required]
public string ImplementerFIO { get; private set; } = string.Empty;
[Required]
public string Password { get; private set; } = string.Empty;
[Required]
public int WorkExperience { get; private set; }
[Required]
public int Qualification { get; private set; }
[ForeignKey("ImplementerId")]
public virtual List<Order> Orders { get; set; } = new();
public static Implementer? Create(ImplementerBindingModel model)
{
if (model == null)
{
return null;
}
return new Implementer()
{
Id = model.Id,
ImplementerFIO = model.ImplementerFIO,
Password = model.Password,
WorkExperience = model.WorkExperience,
Qualification = model.Qualification
};
}
public void Update(ImplementerBindingModel model)
{
if (model == null)
{
return;
}
ImplementerFIO = model.ImplementerFIO;
Password = model.Password;
WorkExperience = model.WorkExperience;
Qualification = model.Qualification;
}
public ImplementerViewModel GetViewModel => new()
{
Id = Id,
ImplementerFIO = ImplementerFIO,
Password = Password,
WorkExperience = WorkExperience,
Qualification = Qualification,
};
}
}

View File

@ -12,6 +12,7 @@ namespace FishFactoryDatabaseImplement.Models
public int CannedId { get; set; } public int CannedId { get; set; }
[Required] [Required]
public int ClientId { get; set; } public int ClientId { get; set; }
public int? ImplementerId { get; private set; }
[Required] [Required]
public int Count { get; set; } public int Count { get; set; }
[Required] [Required]
@ -24,6 +25,7 @@ namespace FishFactoryDatabaseImplement.Models
public int Id { get; set; } public int Id { get; set; }
public Canned Canned { get; set; } public Canned Canned { get; set; }
public Client Client { get; set; } public Client Client { get; set; }
public Implementer? Implementer { get; set; }
public static Order? Create(OrderBindingModel? model) public static Order? Create(OrderBindingModel? model)
{ {
if (model == null) if (model == null)
@ -35,6 +37,7 @@ namespace FishFactoryDatabaseImplement.Models
Id = model.Id, Id = model.Id,
CannedId = model.CannedId, CannedId = model.CannedId,
ClientId = model.ClientId, ClientId = model.ClientId,
ImplementerId = model.ImplementerId,
Count = model.Count, Count = model.Count,
Sum = model.Sum, Sum = model.Sum,
Status = model.Status, Status = model.Status,
@ -51,6 +54,8 @@ namespace FishFactoryDatabaseImplement.Models
} }
Status = model.Status; Status = model.Status;
DateImplement = model.DateImplement; DateImplement = model.DateImplement;
if (model.ImplementerId.HasValue)
ImplementerId = model.ImplementerId;
} }
public OrderViewModel GetViewModel => new() public OrderViewModel GetViewModel => new()
@ -58,6 +63,8 @@ namespace FishFactoryDatabaseImplement.Models
CannedId = CannedId, CannedId = CannedId,
ClientId = ClientId, ClientId = ClientId,
ClientFIO = Client.ClientFIO, ClientFIO = Client.ClientFIO,
ImplementerFIO = Implementer?.ImplementerFIO ?? string.Empty,
ImplementerId = ImplementerId,
Count = Count, Count = Count,
Sum = Sum, Sum = Sum,
DateCreate = DateCreate, DateCreate = DateCreate,

View File

@ -10,10 +10,12 @@ namespace FishFactoryFileImplement
private readonly string OrderFileName = "Order.xml"; private readonly string OrderFileName = "Order.xml";
private readonly string CannedFileName = "Canned.xml"; private readonly string CannedFileName = "Canned.xml";
private readonly string ClientFileName = "Client.xml"; private readonly string ClientFileName = "Client.xml";
private readonly string ImplementerFileName = "Implementer.xml";
public List<Ingredient> Ingredients { get; private set; } public List<Ingredient> Ingredients { get; private set; }
public List<Order> Orders { get; private set; } public List<Order> Orders { get; private set; }
public List<Canned> ListCanned { get; private set; } public List<Canned> ListCanned { get; private set; }
public List<Client> Clients { get; private set; } public List<Client> Clients { get; private set; }
public List<Implementer> Implementers { get; private set; }
public static DataFileSingleton GetInstance() public static DataFileSingleton GetInstance()
{ {
if (instance == null) if (instance == null)
@ -31,12 +33,15 @@ namespace FishFactoryFileImplement
public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement); public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement);
public void SaveClients() => SaveData(Clients, ClientFileName, "Clients", x => x.GetXElement); public void SaveClients() => SaveData(Clients, ClientFileName, "Clients", x => x.GetXElement);
public void SaveImplementers() => SaveData(Implementers, ImplementerFileName, "Implementers", x => x.GetXElement);
private DataFileSingleton() private DataFileSingleton()
{ {
Ingredients = LoadData(IngredientFileName, "Ingredient", x => Ingredient.Create(x)!)!; Ingredients = LoadData(IngredientFileName, "Ingredient", x => Ingredient.Create(x)!)!;
ListCanned = LoadData(CannedFileName, "Canned", x => Canned.Create(x)!)!; ListCanned = LoadData(CannedFileName, "Canned", x => Canned.Create(x)!)!;
Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!; Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!;
Clients = LoadData(ClientFileName, "Client", x => Client.Create(x)!)!; Clients = LoadData(ClientFileName, "Client", x => Client.Create(x)!)!;
Implementers = LoadData(ImplementerFileName, "Implementer", x => Implementer.Create(x)!)!;
} }
private static List<T>? LoadData<T>(string filename, string xmlNodeName, private static List<T>? LoadData<T>(string filename, string xmlNodeName,

View File

@ -0,0 +1,83 @@
using FishFactoryContracts.BindingModels;
using FishFactoryContracts.SearchModels;
using FishFactoryContracts.StoragesContracts;
using FishFactoryContracts.ViewModels;
using FishFactoryFileImplement.Models;
namespace FishFactoryFileImplement.Implements
{
public class ImplementerStorage : IImplementerStorage
{
private readonly DataFileSingleton source;
public ImplementerStorage()
{
source = DataFileSingleton.GetInstance();
}
public ImplementerViewModel? Delete(ImplementerBindingModel model)
{
var element = source.Implementers.FirstOrDefault(x => x.Id == model.Id);
if (element != null)
{
source.Implementers.Remove(element);
source.SaveImplementers();
return element.GetViewModel;
}
return null;
}
public ImplementerViewModel? GetElement(ImplementerSearchModel model)
{
if (!string.IsNullOrEmpty(model.ImplementerFIO) || model.Id.HasValue)
{
return source.Implementers.FirstOrDefault(x =>
(!string.IsNullOrEmpty(model.ImplementerFIO) && x.ImplementerFIO == model.ImplementerFIO) ||
(model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
} else if (!string.IsNullOrEmpty(model.ImplementerFIO) && !string.IsNullOrEmpty(model.Password))
return source.Implementers.FirstOrDefault(x =>
x.ImplementerFIO == model.ImplementerFIO && x.Password == model.Password)?.GetViewModel;
return null;
}
public List<ImplementerViewModel> GetFilteredList(ImplementerSearchModel model)
{
if (string.IsNullOrEmpty(model.ImplementerFIO))
{
return new();
}
return source.Implementers
.Where(x => x.ImplementerFIO.Contains(model.ImplementerFIO))
.Select(x => x.GetViewModel)
.ToList();
}
public List<ImplementerViewModel> GetFullList()
{
return source.Implementers.Select(x => x.GetViewModel).ToList();
}
public ImplementerViewModel? Insert(ImplementerBindingModel model)
{
model.Id = source.Implementers.Count > 0 ? source.Implementers.Max(x => x.Id) + 1 : 1;
var newImplementer = Implementer.Create(model);
if (newImplementer == null)
{
return null;
}
source.Implementers.Add(newImplementer);
source.SaveImplementers();
return newImplementer.GetViewModel;
}
public ImplementerViewModel? Update(ImplementerBindingModel model)
{
var implementer = source.Implementers.FirstOrDefault(x => x.Id == model.Id);
if (implementer == null)
{
return null;
}
implementer.Update(model);
source.SaveImplementers();
return implementer.GetViewModel;
}
}
}

View File

@ -21,17 +21,22 @@ namespace FishFactoryFileImplement.Implements
public List<OrderViewModel> GetFilteredList(OrderSearchModel model) public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
{ {
if (model.DateFrom.HasValue) if (model.DateFrom.HasValue && model.DateTo.HasValue)
return source.Orders return source.Orders
.Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo) .Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo)
.Select(x => GetViewModel(x)) .Select(x => GetViewModel(x))
.ToList(); .ToList();
if (model.ClientId.HasValue && !model.Id.HasValue) else if (model.ClientId.HasValue && !model.Id.HasValue)
return source.Orders return source.Orders
.Where(x => x.ClientId == model.ClientId) .Where(x => x.ClientId == model.ClientId)
.Select(x => x.GetViewModel) .Select(x => x.GetViewModel)
.ToList(); .ToList();
if (model.Id.HasValue) else if (model.OrderStatus.HasValue)
return source.Orders
.Where(x => x.Status == model.OrderStatus)
.Select(x => x.GetViewModel)
.ToList();
else if (model.Id.HasValue)
return source.Orders return source.Orders
.Where(x => x.Id.Equals(model.Id)) .Where(x => x.Id.Equals(model.Id))
.Select(x => GetViewModel(x)) .Select(x => GetViewModel(x))
@ -41,13 +46,23 @@ namespace FishFactoryFileImplement.Implements
public OrderViewModel? GetElement(OrderSearchModel model) public OrderViewModel? GetElement(OrderSearchModel model)
{ {
if (!model.Id.HasValue) if (model.Id.HasValue)
{ {
return null; return source.Orders.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
} }
else if (model.ImplementerId.HasValue && model.OrderStatus.HasValue)
return source.Orders.FirstOrDefault(x => {
(model.Id.HasValue && x.Id == model.Id))?.GetViewModel; return source.Orders
.FirstOrDefault(x => x.ImplementerId == model.ImplementerId && x.Status == model.OrderStatus)
?.GetViewModel;
}
else if (model.ImplementerId.HasValue)
{
return source.Orders
.FirstOrDefault(x => x.ImplementerId == model.ImplementerId)
?.GetViewModel;
}
return null;
} }
private OrderViewModel GetViewModel(Order order) private OrderViewModel GetViewModel(Order order)
{ {
@ -57,11 +72,15 @@ namespace FishFactoryFileImplement.Implements
.ListCanned.FirstOrDefault(x => x.Id == order.CannedId); .ListCanned.FirstOrDefault(x => x.Id == order.CannedId);
var client = source var client = source
.Clients.FirstOrDefault(x => x.Id == order.ClientId); .Clients.FirstOrDefault(x => x.Id == order.ClientId);
var implementer = source
.Implementers.FirstOrDefault(x => x.Id == order.ImplementerId);
if (canned != null) if (canned != null)
viewModel.CannedName = canned.CannedName; viewModel.CannedName = canned.CannedName;
if (client != null) if (client != null)
viewModel.ClientFIO = client.ClientFIO; viewModel.ClientFIO = client.ClientFIO;
if (implementer != null)
viewModel.ImplementerFIO = implementer.ImplementerFIO;
return viewModel; return viewModel;
} }
public OrderViewModel? Insert(OrderBindingModel model) public OrderViewModel? Insert(OrderBindingModel model)

View File

@ -0,0 +1,76 @@
using FishFactoryContracts.BindingModels;
using FishFactoryContracts.ViewModels;
using FishFactoryDataModels.Models;
using System.Xml.Linq;
namespace FishFactoryFileImplement.Models
{
public class Implementer : IImplementerModel
{
public int Id { get; private set; }
public string ImplementerFIO { get; private set; } = string.Empty;
public string Password { get; private set; } = string.Empty;
public int WorkExperience { get; private set; }
public int Qualification { get; private set; }
public static Implementer? Create(ImplementerBindingModel? model)
{
if (model == null)
{
return null;
}
return new Implementer()
{
Id = model.Id,
ImplementerFIO = model.ImplementerFIO,
Password = model.Password,
WorkExperience = model.WorkExperience,
Qualification = model.Qualification,
};
}
public static Implementer? Create(XElement element)
{
if (element == null)
{
return null;
}
return new Implementer()
{
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
ImplementerFIO = element.Element("ImplementerFIO")!.Value,
Password = element.Element("Password")!.Value,
WorkExperience = Convert.ToInt32(element.Element("WorkExperience")!.Value),
Qualification = Convert.ToInt32(element.Element("Qualification")!.Value)
};
}
public void Update(ImplementerBindingModel? model)
{
if (model == null)
{
return;
}
ImplementerFIO = model.ImplementerFIO;
Password = model.Password;
WorkExperience = model.WorkExperience;
Qualification = model.Qualification;
}
public ImplementerViewModel GetViewModel => new()
{
Id = Id,
ImplementerFIO = ImplementerFIO,
Password = Password,
WorkExperience = WorkExperience,
Qualification = Qualification
};
public XElement GetXElement => new("Implementer",
new XAttribute("Id", Id),
new XElement("ImplementerFIO", ImplementerFIO),
new XElement("Password", Password),
new XElement("WorkExperience", WorkExperience),
new XElement("Qualification", Qualification));
}
}

View File

@ -11,6 +11,7 @@ namespace FishFactoryFileImplement.Models
public int Id { get; private set; } public int Id { get; private set; }
public int CannedId { get; private set; } public int CannedId { get; private set; }
public int ClientId { get; private set; } public int ClientId { get; private set; }
public int? ImplementerId { get; private set; }
public int Count { get; private set; } public int Count { get; private set; }
public double Sum { get; private set; } public double Sum { get; private set; }
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
@ -28,6 +29,7 @@ namespace FishFactoryFileImplement.Models
Id = model.Id, Id = model.Id,
CannedId = model.CannedId, CannedId = model.CannedId,
ClientId = model.ClientId, ClientId = model.ClientId,
ImplementerId = model.ImplementerId,
Count = model.Count, Count = model.Count,
Sum = model.Sum, Sum = model.Sum,
Status = model.Status, Status = model.Status,
@ -47,6 +49,7 @@ namespace FishFactoryFileImplement.Models
Id = Convert.ToInt32(element.Attribute("Id")!.Value), Id = Convert.ToInt32(element.Attribute("Id")!.Value),
CannedId = Convert.ToInt32(element.Element("CannedId")!.Value), CannedId = Convert.ToInt32(element.Element("CannedId")!.Value),
ClientId = Convert.ToInt32(element.Element("ClientId")!.Value), ClientId = Convert.ToInt32(element.Element("ClientId")!.Value),
ImplementerId = Convert.ToInt32(element.Element("ImplementerId")!.Value),
Sum = Convert.ToDouble(element.Element("Sum")!.Value), Sum = Convert.ToDouble(element.Element("Sum")!.Value),
Count = Convert.ToInt32(element.Element("Count")!.Value), Count = Convert.ToInt32(element.Element("Count")!.Value),
Status = (OrderStatus)Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value), Status = (OrderStatus)Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value),
@ -63,12 +66,15 @@ namespace FishFactoryFileImplement.Models
} }
Status = model.Status; Status = model.Status;
DateImplement = model.DateImplement; DateImplement = model.DateImplement;
if (model.ImplementerId.HasValue)
ImplementerId = model.ImplementerId;
} }
public OrderViewModel GetViewModel => new() public OrderViewModel GetViewModel => new()
{ {
CannedId = CannedId, CannedId = CannedId,
ClientId = ClientId, ClientId = ClientId,
ImplementerId = ImplementerId,
Count = Count, Count = Count,
Sum = Sum, Sum = Sum,
DateCreate = DateCreate, DateCreate = DateCreate,
@ -81,6 +87,7 @@ namespace FishFactoryFileImplement.Models
new XAttribute("Id", Id), new XAttribute("Id", Id),
new XElement("CannedId", CannedId), new XElement("CannedId", CannedId),
new XElement("ClientId", ClientId), new XElement("ClientId", ClientId),
new XElement("ImplementerId", ImplementerId),
new XElement("Count", Count.ToString()), new XElement("Count", Count.ToString()),
new XElement("Sum", Sum.ToString()), new XElement("Sum", Sum.ToString()),
new XElement("Status", Status.ToString()), new XElement("Status", Status.ToString()),

View File

@ -9,6 +9,7 @@ namespace FishFactoryListImplement
public List<Order> Orders { get; set; } public List<Order> Orders { get; set; }
public List<Canned> ListCanned { get; set; } public List<Canned> ListCanned { get; set; }
public List<Client> Clients { get; set; } public List<Client> Clients { get; set; }
public List<Implementer> Implementers { get; set; }
private DataListSingleton() private DataListSingleton()
{ {
@ -16,6 +17,7 @@ namespace FishFactoryListImplement
Orders = new List<Order>(); Orders = new List<Order>();
ListCanned = new List<Canned>(); ListCanned = new List<Canned>();
Clients = new List<Client>(); Clients = new List<Client>();
Implementers = new List<Implementer>();
} }
public static DataListSingleton GetInstance() public static DataListSingleton GetInstance()

View File

@ -0,0 +1,124 @@
using FishFactoryContracts.BindingModels;
using FishFactoryContracts.SearchModels;
using FishFactoryContracts.StoragesContracts;
using FishFactoryContracts.ViewModels;
using FishFactoryListImplement.Models;
namespace FishFactoryListImplement.Implements
{
public class ImplementerStorage : IImplementerStorage
{
private readonly DataListSingleton _source;
public ImplementerStorage()
{
_source = DataListSingleton.GetInstance();
}
public ImplementerViewModel? Delete(ImplementerBindingModel model)
{
for (int i = 0; i < _source.Implementers.Count; ++i)
{
if (_source.Implementers[i].Id == model.Id)
{
var element = _source.Implementers[i];
_source.Implementers.RemoveAt(i);
return element.GetViewModel;
}
}
return null;
}
public ImplementerViewModel? GetElement(ImplementerSearchModel model)
{
if (model.Id.HasValue)
{
foreach (var implementer in _source.Implementers)
{
if (implementer.Id == model.Id)
{
return implementer.GetViewModel;
}
}
}
else if (!string.IsNullOrEmpty(model.ImplementerFIO) && !string.IsNullOrEmpty(model.Password))
{
foreach (var implementer in _source.Implementers)
{
if (implementer.ImplementerFIO.Equals(model.ImplementerFIO) && implementer.Password.Equals(model.Password))
{
return implementer.GetViewModel;
}
}
}
else if (!string.IsNullOrEmpty(model.ImplementerFIO))
{
foreach (var implementer in _source.Implementers)
{
if (implementer.ImplementerFIO == model.ImplementerFIO)
{
return implementer.GetViewModel;
}
}
}
return null;
}
public List<ImplementerViewModel> GetFilteredList(ImplementerSearchModel model)
{
var result = new List<ImplementerViewModel>();
if (string.IsNullOrEmpty(model.ImplementerFIO))
{
return result;
}
foreach (var implementer in _source.Implementers)
{
if (implementer.ImplementerFIO.Contains(model.ImplementerFIO))
{
result.Add(implementer.GetViewModel);
}
}
return result;
}
public List<ImplementerViewModel> GetFullList()
{
var result = new List<ImplementerViewModel>();
foreach (var implementer in _source.Implementers)
{
result.Add(implementer.GetViewModel);
}
return result;
}
public ImplementerViewModel? Insert(ImplementerBindingModel model)
{
model.Id = 1;
foreach (var implementer in _source.Implementers)
{
if (model.Id <= implementer.Id)
{
model.Id = implementer.Id + 1;
}
}
var newImplementer = Implementer.Create(model);
if (newImplementer == null)
{
return null;
}
_source.Implementers.Add(newImplementer);
return newImplementer.GetViewModel;
}
public ImplementerViewModel? Update(ImplementerBindingModel model)
{
foreach (var implementer in _source.Implementers)
{
if (implementer.Id == model.Id)
{
implementer.Update(model);
return implementer.GetViewModel;
}
}
return null;
}
}
}

View File

@ -47,6 +47,16 @@ namespace FishFactoryListImplement.Implements
} }
} }
} }
else if (model.OrderStatus.HasValue)
{
foreach (var order in _source.Orders)
{
if (order.Status == model.OrderStatus)
{
result.Add(GetViewModel(order));
}
}
}
else if (model.Id.HasValue) else if (model.Id.HasValue)
{ {
foreach (var order in _source.Orders) foreach (var order in _source.Orders)
@ -95,6 +105,14 @@ namespace FishFactoryListImplement.Implements
break; break;
} }
} }
foreach (var implementer in _source.Implementers)
{
if (implementer.Id == order.ImplementerId)
{
viewModel.ImplementerFIO = implementer.ImplementerFIO;
break;
}
}
return viewModel; return viewModel;
} }

View File

@ -0,0 +1,54 @@
using FishFactoryContracts.BindingModels;
using FishFactoryContracts.ViewModels;
using FishFactoryDataModels.Models;
namespace FishFactoryListImplement.Models
{
public class Implementer : IImplementerModel
{
public int Id { get; private set; }
public string ImplementerFIO { get; private set; } = string.Empty;
public string Password { get; private set; } = string.Empty;
public int WorkExperience { get; private set; }
public int Qualification { get; private set; }
public static Implementer? Create(ImplementerBindingModel? model)
{
if (model == null)
{
return null;
}
return new Implementer()
{
Id = model.Id,
ImplementerFIO = model.ImplementerFIO,
Password = model.Password,
WorkExperience = model.WorkExperience,
Qualification = model.Qualification,
};
}
public void Update(ImplementerBindingModel? model)
{
if (model == null)
{
return;
}
ImplementerFIO = model.ImplementerFIO;
Password = model.Password;
WorkExperience = model.WorkExperience;
Qualification = model.Qualification;
}
public ImplementerViewModel GetViewModel => new()
{
Id = Id,
ImplementerFIO = ImplementerFIO,
Password = Password,
WorkExperience = WorkExperience,
Qualification = Qualification
};
}
}

View File

@ -9,7 +9,7 @@ namespace FishFactoryListImplement.Models
{ {
public int CannedId { get; private set; } public int CannedId { get; private set; }
public int ClientId { get; private set; } public int ClientId { get; private set; }
public string CannedName { get; private set; } = string.Empty; public int? ImplementerId { get; private set; }
public int Count { get; private set; } public int Count { get; private set; }
public double Sum { get; private set; } public double Sum { get; private set; }
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
@ -27,6 +27,7 @@ namespace FishFactoryListImplement.Models
{ {
CannedId = model.CannedId, CannedId = model.CannedId,
ClientId = model.ClientId, ClientId = model.ClientId,
ImplementerId = model.ImplementerId,
Count = model.Count, Count = model.Count,
Sum = model.Sum, Sum = model.Sum,
Status = model.Status, Status = model.Status,
@ -43,13 +44,16 @@ namespace FishFactoryListImplement.Models
return; return;
} }
Status = model.Status; Status = model.Status;
DateImplement = model.DateImplement; ImplementerId = model.ImplementerId;
if (model.ImplementerId.HasValue)
ImplementerId = model.ImplementerId;
} }
public OrderViewModel GetViewModel => new() public OrderViewModel GetViewModel => new()
{ {
CannedId = CannedId, CannedId = CannedId,
ClientId = ClientId, ClientId = ClientId,
ImplementerId = ImplementerId,
Count = Count, Count = Count,
Sum = Sum, Sum = Sum,
DateCreate = DateCreate, DateCreate = DateCreate,

View File

@ -0,0 +1,107 @@
using Microsoft.AspNetCore.Mvc;
using FishFactoryContracts.BindingModels;
using FishFactoryContracts.BusinessLogicsContracts;
using FishFactoryContracts.SearchModels;
using FishFactoryContracts.ViewModels;
using FishFactoryDataModels.Enums;
namespace FishFactoryRestApi.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class ImplementerController : Controller
{
private readonly ILogger _logger;
private readonly IOrderLogic _order;
private readonly IImplementerLogic _logic;
public ImplementerController(IOrderLogic order, IImplementerLogic logic, ILogger<ImplementerController> logger)
{
_logger = logger;
_order = order;
_logic = logic;
}
[HttpGet]
public ImplementerViewModel? Login(string login, string password)
{
try
{
return _logic.ReadElement(new ImplementerSearchModel
{
ImplementerFIO = login,
Password = password
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка входа сотрудника");
throw;
}
}
[HttpGet]
public List<OrderViewModel>? GetNewOrders()
{
try
{
return _order.ReadList(new OrderSearchModel
{
OrderStatus = OrderStatus.Принят
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения новых заказов");
throw;
}
}
[HttpGet]
public OrderViewModel? GetImplementerOrder(int implementerId)
{
try
{
return _order.ReadElement(new OrderSearchModel
{
ImplementerId = implementerId
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения текущего заказа исполнителя");
throw;
}
}
[HttpPost]
public void TakeOrderInWork(OrderBindingModel model)
{
try
{
_order.TakeOrderInWork(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка перевода заказа с №{Id} в работу", model.Id);
throw;
}
}
[HttpPost]
public void FinishOrder(OrderBindingModel model)
{
try
{
_order.FinishOrder(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка отметки о готовности заказа с №{Id}", model.Id);
throw;
}
}
}
}

View File

@ -13,10 +13,12 @@ builder.Logging.AddLog4Net("log4net.config");
builder.Services.AddTransient<IClientStorage, ClientStorage>(); builder.Services.AddTransient<IClientStorage, ClientStorage>();
builder.Services.AddTransient<IOrderStorage, OrderStorage>(); builder.Services.AddTransient<IOrderStorage, OrderStorage>();
builder.Services.AddTransient<ICannedStorage, CannedStorage>(); builder.Services.AddTransient<ICannedStorage, CannedStorage>();
builder.Services.AddTransient<IImplementerStorage, ImplementerStorage>();
builder.Services.AddTransient<IOrderLogic, OrderLogic>(); builder.Services.AddTransient<IOrderLogic, OrderLogic>();
builder.Services.AddTransient<IClientLogic, ClientLogic>(); builder.Services.AddTransient<IClientLogic, ClientLogic>();
builder.Services.AddTransient<ICannedLogic, CannedLogic>(); builder.Services.AddTransient<ICannedLogic, CannedLogic>();
builder.Services.AddTransient<IImplementerLogic, ImplementerLogic>();
builder.Services.AddControllers(); builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle

View File

@ -108,7 +108,6 @@ namespace FishFactoryView
{ {
CannedId = Convert.ToInt32(comboBoxCanned.SelectedValue), CannedId = Convert.ToInt32(comboBoxCanned.SelectedValue),
ClientId = Convert.ToInt32(comboBoxClient.SelectedValue), ClientId = Convert.ToInt32(comboBoxClient.SelectedValue),
CannedName = comboBoxCanned.Text,
Count = Convert.ToInt32(textBoxCount.Text), Count = Convert.ToInt32(textBoxCount.Text),
Sum = Convert.ToDouble(textBoxSum.Text) Sum = Convert.ToDouble(textBoxSum.Text)
}); });

View File

@ -0,0 +1,178 @@
namespace FishFactoryView
{
partial class FormImplementer
{
/// <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()
{
this.buttonSave = new System.Windows.Forms.Button();
this.buttonCancel = new System.Windows.Forms.Button();
this.numericUpDownQualification = new System.Windows.Forms.NumericUpDown();
this.numericUpDownWorkExperience = new System.Windows.Forms.NumericUpDown();
this.textBoxPassword = new System.Windows.Forms.TextBox();
this.textBoxFio = new System.Windows.Forms.TextBox();
this.labelQualification = new System.Windows.Forms.Label();
this.labelWorkExperience = new System.Windows.Forms.Label();
this.labelPassword = new System.Windows.Forms.Label();
this.labelFIO = new System.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownQualification)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWorkExperience)).BeginInit();
this.SuspendLayout();
//
// buttonSave
//
this.buttonSave.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonSave.Location = new System.Drawing.Point(190, 135);
this.buttonSave.Name = "buttonSave";
this.buttonSave.Size = new System.Drawing.Size(89, 33);
this.buttonSave.TabIndex = 19;
this.buttonSave.Text = "Сохранить";
this.buttonSave.UseVisualStyleBackColor = true;
this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click);
//
// buttonCancel
//
this.buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonCancel.Location = new System.Drawing.Point(285, 135);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(89, 33);
this.buttonCancel.TabIndex = 18;
this.buttonCancel.Text = "Отмена";
this.buttonCancel.UseVisualStyleBackColor = true;
this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
//
// numericUpDownQualification
//
this.numericUpDownQualification.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.numericUpDownQualification.Location = new System.Drawing.Point(112, 98);
this.numericUpDownQualification.Name = "numericUpDownQualification";
this.numericUpDownQualification.Size = new System.Drawing.Size(262, 23);
this.numericUpDownQualification.TabIndex = 17;
//
// numericUpDownWorkExperience
//
this.numericUpDownWorkExperience.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.numericUpDownWorkExperience.Location = new System.Drawing.Point(112, 69);
this.numericUpDownWorkExperience.Name = "numericUpDownWorkExperience";
this.numericUpDownWorkExperience.Size = new System.Drawing.Size(262, 23);
this.numericUpDownWorkExperience.TabIndex = 16;
//
// textBoxPassword
//
this.textBoxPassword.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.textBoxPassword.Location = new System.Drawing.Point(112, 41);
this.textBoxPassword.Name = "textBoxPassword";
this.textBoxPassword.PasswordChar = '*';
this.textBoxPassword.Size = new System.Drawing.Size(262, 23);
this.textBoxPassword.TabIndex = 15;
//
// textBoxFio
//
this.textBoxFio.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.textBoxFio.Location = new System.Drawing.Point(112, 12);
this.textBoxFio.Name = "textBoxFio";
this.textBoxFio.Size = new System.Drawing.Size(262, 23);
this.textBoxFio.TabIndex = 14;
//
// labelQualification
//
this.labelQualification.AutoSize = true;
this.labelQualification.Location = new System.Drawing.Point(12, 98);
this.labelQualification.Name = "labelQualification";
this.labelQualification.Size = new System.Drawing.Size(88, 15);
this.labelQualification.TabIndex = 13;
this.labelQualification.Text = "Квалификация";
//
// labelWorkExperience
//
this.labelWorkExperience.AutoSize = true;
this.labelWorkExperience.Location = new System.Drawing.Point(12, 71);
this.labelWorkExperience.Name = "labelWorkExperience";
this.labelWorkExperience.Size = new System.Drawing.Size(35, 15);
this.labelWorkExperience.TabIndex = 12;
this.labelWorkExperience.Text = "Стаж";
//
// labelPassword
//
this.labelPassword.AutoSize = true;
this.labelPassword.Location = new System.Drawing.Point(12, 41);
this.labelPassword.Name = "labelPassword";
this.labelPassword.Size = new System.Drawing.Size(49, 15);
this.labelPassword.TabIndex = 11;
this.labelPassword.Text = "Пароль";
//
// labelFIO
//
this.labelFIO.AutoSize = true;
this.labelFIO.Location = new System.Drawing.Point(12, 15);
this.labelFIO.Name = "labelFIO";
this.labelFIO.Size = new System.Drawing.Size(34, 15);
this.labelFIO.TabIndex = 10;
this.labelFIO.Text = "ФИО";
//
// FormImplementer
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(386, 180);
this.Controls.Add(this.buttonSave);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.numericUpDownQualification);
this.Controls.Add(this.numericUpDownWorkExperience);
this.Controls.Add(this.textBoxPassword);
this.Controls.Add(this.textBoxFio);
this.Controls.Add(this.labelQualification);
this.Controls.Add(this.labelWorkExperience);
this.Controls.Add(this.labelPassword);
this.Controls.Add(this.labelFIO);
this.Name = "FormImplementer";
this.Text = "Исполнитель";
this.Load += new System.EventHandler(this.FormImplementer_Load);
((System.ComponentModel.ISupportInitialize)(this.numericUpDownQualification)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownWorkExperience)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private Button buttonSave;
private Button buttonCancel;
private NumericUpDown numericUpDownQualification;
private NumericUpDown numericUpDownWorkExperience;
private TextBox textBoxPassword;
private TextBox textBoxFio;
private Label labelQualification;
private Label labelWorkExperience;
private Label labelPassword;
private Label labelFIO;
}
}

View File

@ -0,0 +1,99 @@
using Microsoft.Extensions.Logging;
using FishFactoryContracts.BindingModels;
using FishFactoryContracts.BusinessLogicsContracts;
using FishFactoryContracts.SearchModels;
namespace FishFactoryView
{
public partial class FormImplementer : Form
{
private readonly ILogger _logger;
private readonly IImplementerLogic _logic;
private int? _id;
public int Id { set { _id = value; } }
public FormImplementer(ILogger<FormImplementer> logger, IImplementerLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
}
private void FormImplementer_Load(object sender, EventArgs e)
{
if (_id.HasValue)
{
try
{
_logger.LogInformation("Получение исполнителя");
var view = _logic.ReadElement(new ImplementerSearchModel
{
Id = _id.Value
});
if (view != null)
{
textBoxFio.Text = view.ImplementerFIO;
textBoxPassword.Text = view.Password;
numericUpDownQualification.Value = view.Qualification;
numericUpDownWorkExperience.Value = view.WorkExperience;
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения исполнителя");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
}
private void ButtonSave_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBoxPassword.Text))
{
MessageBox.Show("Заполните пароль", "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (string.IsNullOrEmpty(textBoxFio.Text))
{
MessageBox.Show("Заполните ФИО", "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Сохранение исполнителя");
try
{
var model = new ImplementerBindingModel
{
Id = _id ?? 0,
ImplementerFIO = textBoxFio.Text,
Password = textBoxPassword.Text,
Qualification = (int)numericUpDownQualification.Value,
WorkExperience = (int)numericUpDownWorkExperience.Value,
};
var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model);
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
}
MessageBox.Show("Сохранение прошло успешно", "Сообщение",
MessageBoxButtons.OK, MessageBoxIcon.Information);
DialogResult = DialogResult.OK;
Close();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка сохранения исполнителя");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
private void ButtonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
}
}

View File

@ -0,0 +1,60 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -0,0 +1,122 @@
namespace FishFactoryView
{
partial class FormImplementers
{
/// <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()
{
this.dataGridView = new System.Windows.Forms.DataGridView();
this.buttonUpdate = new System.Windows.Forms.Button();
this.buttonDelete = new System.Windows.Forms.Button();
this.buttonEdit = new System.Windows.Forms.Button();
this.buttonAdd = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.SuspendLayout();
//
// dataGridView
//
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView.Dock = System.Windows.Forms.DockStyle.Left;
this.dataGridView.GridColor = System.Drawing.Color.White;
this.dataGridView.Location = new System.Drawing.Point(0, 0);
this.dataGridView.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.dataGridView.Name = "dataGridView";
this.dataGridView.RowHeadersWidth = 51;
this.dataGridView.RowTemplate.Height = 29;
this.dataGridView.Size = new System.Drawing.Size(426, 291);
this.dataGridView.TabIndex = 10;
//
// buttonUpdate
//
this.buttonUpdate.Location = new System.Drawing.Point(446, 163);
this.buttonUpdate.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonUpdate.Name = "buttonUpdate";
this.buttonUpdate.Size = new System.Drawing.Size(130, 22);
this.buttonUpdate.TabIndex = 14;
this.buttonUpdate.Text = "Обновить";
this.buttonUpdate.UseVisualStyleBackColor = true;
this.buttonUpdate.Click += new System.EventHandler(this.ButtonRef_Click);
//
// buttonDelete
//
this.buttonDelete.Location = new System.Drawing.Point(446, 137);
this.buttonDelete.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonDelete.Name = "buttonDelete";
this.buttonDelete.Size = new System.Drawing.Size(130, 22);
this.buttonDelete.TabIndex = 13;
this.buttonDelete.Text = "Удалить";
this.buttonDelete.UseVisualStyleBackColor = true;
this.buttonDelete.Click += new System.EventHandler(this.ButtonDel_Click);
//
// buttonEdit
//
this.buttonEdit.Location = new System.Drawing.Point(446, 111);
this.buttonEdit.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonEdit.Name = "buttonEdit";
this.buttonEdit.Size = new System.Drawing.Size(130, 22);
this.buttonEdit.TabIndex = 12;
this.buttonEdit.Text = "Изменить";
this.buttonEdit.UseVisualStyleBackColor = true;
this.buttonEdit.Click += new System.EventHandler(this.ButtonUpd_Click);
//
// buttonAdd
//
this.buttonAdd.Location = new System.Drawing.Point(446, 85);
this.buttonAdd.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonAdd.Name = "buttonAdd";
this.buttonAdd.Size = new System.Drawing.Size(130, 22);
this.buttonAdd.TabIndex = 11;
this.buttonAdd.Text = "Добавить";
this.buttonAdd.UseVisualStyleBackColor = true;
this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click);
//
// FormImplementers
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(590, 291);
this.Controls.Add(this.dataGridView);
this.Controls.Add(this.buttonUpdate);
this.Controls.Add(this.buttonDelete);
this.Controls.Add(this.buttonEdit);
this.Controls.Add(this.buttonAdd);
this.Name = "FormImplementers";
this.Text = "Исполнители";
this.Load += new System.EventHandler(this.FormImplementers_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.ResumeLayout(false);
}
#endregion
private DataGridView dataGridView;
private Button buttonUpdate;
private Button buttonDelete;
private Button buttonEdit;
private Button buttonAdd;
}
}

View File

@ -0,0 +1,102 @@
using Microsoft.Extensions.Logging;
using FishFactoryContracts.BindingModels;
using FishFactoryContracts.BusinessLogicsContracts;
namespace FishFactoryView
{
public partial class FormImplementers : Form
{
private readonly ILogger _logger;
private readonly IImplementerLogic _logic;
public FormImplementers(ILogger<FormImplementers> logger, IImplementerLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
}
private void FormImplementers_Load(object sender, EventArgs e)
{
LoadData();
}
private void LoadData()
{
try
{
var list = _logic.ReadList(null);
if (list != null)
{
dataGridView.DataSource = list;
dataGridView.Columns["Id"].Visible = false;
dataGridView.Columns["ImplementerFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
_logger.LogInformation("Загрузка исполнителей");
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки исполнителей");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
private void ButtonAdd_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormImplementer));
if (service is FormImplementer form)
{
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
private void ButtonUpd_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
var service = Program.ServiceProvider?.GetService(typeof(FormImplementer));
if (service is FormImplementer form)
{
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
}
private void ButtonDel_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
if (MessageBox.Show("Удалить запись?", "Вопрос",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
int id =
Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Удаление исполнителя");
try
{
if (!_logic.Delete(new ImplementerBindingModel
{
Id = id
}))
{
throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
}
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка удаления исполнителя");
MessageBox.Show(ex.Message, "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
private void ButtonRef_Click(object sender, EventArgs e)
{
LoadData();
}
}
}

View File

@ -0,0 +1,60 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -33,14 +33,14 @@
this.ingredientsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.ingredientsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.cannedToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.cannedToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.clientsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.clientsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.performersToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.reportsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.reportsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.listCannedsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.listCannedsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.ingredientsByCannedToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.ingredientsByCannedToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.ordersListToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.ordersListToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.startOfWorkToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.buttonUpdate = new System.Windows.Forms.Button(); this.buttonUpdate = new System.Windows.Forms.Button();
this.buttonSetToFinish = new System.Windows.Forms.Button(); this.buttonSetToFinish = new System.Windows.Forms.Button();
this.buttonSetToDone = new System.Windows.Forms.Button();
this.buttonSetToWork = new System.Windows.Forms.Button();
this.buttonCreateOrder = new System.Windows.Forms.Button(); this.buttonCreateOrder = new System.Windows.Forms.Button();
this.dataGridView = new System.Windows.Forms.DataGridView(); this.dataGridView = new System.Windows.Forms.DataGridView();
this.menuStrip.SuspendLayout(); this.menuStrip.SuspendLayout();
@ -51,7 +51,8 @@
// //
this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.reference_booksToolStripMenuItem, this.reference_booksToolStripMenuItem,
this.reportsToolStripMenuItem}); this.reportsToolStripMenuItem,
this.startOfWorkToolStripMenuItem});
this.menuStrip.Location = new System.Drawing.Point(0, 0); this.menuStrip.Location = new System.Drawing.Point(0, 0);
this.menuStrip.Name = "menuStrip"; this.menuStrip.Name = "menuStrip";
this.menuStrip.Size = new System.Drawing.Size(1086, 24); this.menuStrip.Size = new System.Drawing.Size(1086, 24);
@ -63,7 +64,8 @@
this.reference_booksToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.reference_booksToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.ingredientsToolStripMenuItem, this.ingredientsToolStripMenuItem,
this.cannedToolStripMenuItem, this.cannedToolStripMenuItem,
this.clientsToolStripMenuItem}); this.clientsToolStripMenuItem,
this.performersToolStripMenuItem});
this.reference_booksToolStripMenuItem.Name = "reference_booksToolStripMenuItem"; this.reference_booksToolStripMenuItem.Name = "reference_booksToolStripMenuItem";
this.reference_booksToolStripMenuItem.Size = new System.Drawing.Size(94, 20); this.reference_booksToolStripMenuItem.Size = new System.Drawing.Size(94, 20);
this.reference_booksToolStripMenuItem.Text = "Справочники"; this.reference_booksToolStripMenuItem.Text = "Справочники";
@ -71,24 +73,31 @@
// ingredientsToolStripMenuItem // ingredientsToolStripMenuItem
// //
this.ingredientsToolStripMenuItem.Name = "ingredientsToolStripMenuItem"; this.ingredientsToolStripMenuItem.Name = "ingredientsToolStripMenuItem";
this.ingredientsToolStripMenuItem.Size = new System.Drawing.Size(148, 22); this.ingredientsToolStripMenuItem.Size = new System.Drawing.Size(149, 22);
this.ingredientsToolStripMenuItem.Text = "Ингредиенты"; this.ingredientsToolStripMenuItem.Text = "Ингредиенты";
this.ingredientsToolStripMenuItem.Click += new System.EventHandler(this.IngredientsToolStripMenuItem_Click); this.ingredientsToolStripMenuItem.Click += new System.EventHandler(this.IngredientsToolStripMenuItem_Click);
// //
// cannedToolStripMenuItem // cannedToolStripMenuItem
// //
this.cannedToolStripMenuItem.Name = "cannedToolStripMenuItem"; this.cannedToolStripMenuItem.Name = "cannedToolStripMenuItem";
this.cannedToolStripMenuItem.Size = new System.Drawing.Size(148, 22); this.cannedToolStripMenuItem.Size = new System.Drawing.Size(149, 22);
this.cannedToolStripMenuItem.Text = "Консервы"; this.cannedToolStripMenuItem.Text = "Консервы";
this.cannedToolStripMenuItem.Click += new System.EventHandler(this.CannedToolStripMenuItem_Click); this.cannedToolStripMenuItem.Click += new System.EventHandler(this.CannedToolStripMenuItem_Click);
// //
// clientsToolStripMenuItem // clientsToolStripMenuItem
// //
this.clientsToolStripMenuItem.Name = "clientsToolStripMenuItem"; this.clientsToolStripMenuItem.Name = "clientsToolStripMenuItem";
this.clientsToolStripMenuItem.Size = new System.Drawing.Size(148, 22); this.clientsToolStripMenuItem.Size = new System.Drawing.Size(149, 22);
this.clientsToolStripMenuItem.Text = "Клиенты"; this.clientsToolStripMenuItem.Text = "Клиенты";
this.clientsToolStripMenuItem.Click += new System.EventHandler(this.ClientsToolStripMenuItem_Click); this.clientsToolStripMenuItem.Click += new System.EventHandler(this.ClientsToolStripMenuItem_Click);
// //
// performersToolStripMenuItem
//
this.performersToolStripMenuItem.Name = "performersToolStripMenuItem";
this.performersToolStripMenuItem.Size = new System.Drawing.Size(149, 22);
this.performersToolStripMenuItem.Text = "Исполнители";
this.performersToolStripMenuItem.Click += new System.EventHandler(this.ImplementersToolStripMenuItem_Click);
//
// reportsToolStripMenuItem // reportsToolStripMenuItem
// //
this.reportsToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.reportsToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
@ -120,12 +129,19 @@
this.ordersListToolStripMenuItem.Text = "Список заказов"; this.ordersListToolStripMenuItem.Text = "Список заказов";
this.ordersListToolStripMenuItem.Click += new System.EventHandler(this.OrdersToolStripMenuItem_Click); this.ordersListToolStripMenuItem.Click += new System.EventHandler(this.OrdersToolStripMenuItem_Click);
// //
// startOfWorkToolStripMenuItem
//
this.startOfWorkToolStripMenuItem.Name = "startOfWorkToolStripMenuItem";
this.startOfWorkToolStripMenuItem.Size = new System.Drawing.Size(92, 20);
this.startOfWorkToolStripMenuItem.Text = "Запуск работ";
this.startOfWorkToolStripMenuItem.Click += new System.EventHandler(this.DoWorkToolStripMenuItem_Click);
//
// buttonUpdate // buttonUpdate
// //
this.buttonUpdate.Location = new System.Drawing.Point(875, 318); this.buttonUpdate.Location = new System.Drawing.Point(905, 253);
this.buttonUpdate.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.buttonUpdate.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonUpdate.Name = "buttonUpdate"; this.buttonUpdate.Name = "buttonUpdate";
this.buttonUpdate.Size = new System.Drawing.Size(199, 58); this.buttonUpdate.Size = new System.Drawing.Size(169, 58);
this.buttonUpdate.TabIndex = 12; this.buttonUpdate.TabIndex = 12;
this.buttonUpdate.Text = "Обновить"; this.buttonUpdate.Text = "Обновить";
this.buttonUpdate.UseVisualStyleBackColor = true; this.buttonUpdate.UseVisualStyleBackColor = true;
@ -133,43 +149,21 @@
// //
// buttonSetToFinish // buttonSetToFinish
// //
this.buttonSetToFinish.Location = new System.Drawing.Point(875, 256); this.buttonSetToFinish.Location = new System.Drawing.Point(905, 182);
this.buttonSetToFinish.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.buttonSetToFinish.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonSetToFinish.Name = "buttonSetToFinish"; this.buttonSetToFinish.Name = "buttonSetToFinish";
this.buttonSetToFinish.Size = new System.Drawing.Size(199, 58); this.buttonSetToFinish.Size = new System.Drawing.Size(169, 58);
this.buttonSetToFinish.TabIndex = 11; this.buttonSetToFinish.TabIndex = 11;
this.buttonSetToFinish.Text = "Заказ выдан"; this.buttonSetToFinish.Text = "Заказ выдан";
this.buttonSetToFinish.UseVisualStyleBackColor = true; this.buttonSetToFinish.UseVisualStyleBackColor = true;
this.buttonSetToFinish.Click += new System.EventHandler(this.ButtonIssuedOrder_Click); this.buttonSetToFinish.Click += new System.EventHandler(this.ButtonIssuedOrder_Click);
// //
// buttonSetToDone
//
this.buttonSetToDone.Location = new System.Drawing.Point(875, 194);
this.buttonSetToDone.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonSetToDone.Name = "buttonSetToDone";
this.buttonSetToDone.Size = new System.Drawing.Size(199, 58);
this.buttonSetToDone.TabIndex = 10;
this.buttonSetToDone.Text = "Заказ готов";
this.buttonSetToDone.UseVisualStyleBackColor = true;
this.buttonSetToDone.Click += new System.EventHandler(this.ButtonOrderReady_Click);
//
// buttonSetToWork
//
this.buttonSetToWork.Location = new System.Drawing.Point(875, 132);
this.buttonSetToWork.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonSetToWork.Name = "buttonSetToWork";
this.buttonSetToWork.Size = new System.Drawing.Size(199, 58);
this.buttonSetToWork.TabIndex = 9;
this.buttonSetToWork.Text = "Отдать на выполнение";
this.buttonSetToWork.UseVisualStyleBackColor = true;
this.buttonSetToWork.Click += new System.EventHandler(this.ButtonTakeOrderInWork_Click);
//
// buttonCreateOrder // buttonCreateOrder
// //
this.buttonCreateOrder.Location = new System.Drawing.Point(875, 70); this.buttonCreateOrder.Location = new System.Drawing.Point(905, 111);
this.buttonCreateOrder.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.buttonCreateOrder.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonCreateOrder.Name = "buttonCreateOrder"; this.buttonCreateOrder.Name = "buttonCreateOrder";
this.buttonCreateOrder.Size = new System.Drawing.Size(199, 58); this.buttonCreateOrder.Size = new System.Drawing.Size(169, 58);
this.buttonCreateOrder.TabIndex = 8; this.buttonCreateOrder.TabIndex = 8;
this.buttonCreateOrder.Text = "Создать заказ"; this.buttonCreateOrder.Text = "Создать заказ";
this.buttonCreateOrder.UseVisualStyleBackColor = true; this.buttonCreateOrder.UseVisualStyleBackColor = true;
@ -184,7 +178,7 @@
this.dataGridView.Name = "dataGridView"; this.dataGridView.Name = "dataGridView";
this.dataGridView.RowHeadersWidth = 51; this.dataGridView.RowHeadersWidth = 51;
this.dataGridView.RowTemplate.Height = 29; this.dataGridView.RowTemplate.Height = 29;
this.dataGridView.Size = new System.Drawing.Size(854, 426); this.dataGridView.Size = new System.Drawing.Size(899, 426);
this.dataGridView.TabIndex = 7; this.dataGridView.TabIndex = 7;
// //
// FormMain // FormMain
@ -194,8 +188,6 @@
this.ClientSize = new System.Drawing.Size(1086, 450); this.ClientSize = new System.Drawing.Size(1086, 450);
this.Controls.Add(this.buttonUpdate); this.Controls.Add(this.buttonUpdate);
this.Controls.Add(this.buttonSetToFinish); this.Controls.Add(this.buttonSetToFinish);
this.Controls.Add(this.buttonSetToDone);
this.Controls.Add(this.buttonSetToWork);
this.Controls.Add(this.buttonCreateOrder); this.Controls.Add(this.buttonCreateOrder);
this.Controls.Add(this.dataGridView); this.Controls.Add(this.dataGridView);
this.Controls.Add(this.menuStrip); this.Controls.Add(this.menuStrip);
@ -219,8 +211,6 @@
private ToolStripMenuItem cannedToolStripMenuItem; private ToolStripMenuItem cannedToolStripMenuItem;
private Button buttonUpdate; private Button buttonUpdate;
private Button buttonSetToFinish; private Button buttonSetToFinish;
private Button buttonSetToDone;
private Button buttonSetToWork;
private Button buttonCreateOrder; private Button buttonCreateOrder;
private DataGridView dataGridView; private DataGridView dataGridView;
private ToolStripMenuItem reportsToolStripMenuItem; private ToolStripMenuItem reportsToolStripMenuItem;
@ -228,5 +218,7 @@
private ToolStripMenuItem ingredientsByCannedToolStripMenuItem; private ToolStripMenuItem ingredientsByCannedToolStripMenuItem;
private ToolStripMenuItem ordersListToolStripMenuItem; private ToolStripMenuItem ordersListToolStripMenuItem;
private ToolStripMenuItem clientsToolStripMenuItem; private ToolStripMenuItem clientsToolStripMenuItem;
private ToolStripMenuItem performersToolStripMenuItem;
private ToolStripMenuItem startOfWorkToolStripMenuItem;
} }
} }

View File

@ -1,8 +1,6 @@
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using FishFactoryContracts.BindingModels; using FishFactoryContracts.BindingModels;
using FishFactoryContracts.BusinessLogicsContracts; using FishFactoryContracts.BusinessLogicsContracts;
using FishFactoryDataModels.Enums;
using FishFactoryBusinessLogic.BusinessLogics;
namespace FishFactoryView namespace FishFactoryView
{ {
@ -11,12 +9,14 @@ namespace FishFactoryView
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly IOrderLogic _orderLogic; private readonly IOrderLogic _orderLogic;
private readonly IReportLogic _reportLogic; private readonly IReportLogic _reportLogic;
public FormMain(ILogger<FormMain> logger, IOrderLogic orderLogic, IReportLogic reportLogic) private readonly IWorkProcess _workProcess;
public FormMain(ILogger<FormMain> logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess)
{ {
InitializeComponent(); InitializeComponent();
_logger = logger; _logger = logger;
_orderLogic = orderLogic; _orderLogic = orderLogic;
_reportLogic = reportLogic; _reportLogic = reportLogic;
_workProcess = workProcess;
} }
private void FormMain_Load(object sender, EventArgs e) private void FormMain_Load(object sender, EventArgs e)
{ {
@ -33,6 +33,11 @@ namespace FishFactoryView
dataGridView.DataSource = list; dataGridView.DataSource = list;
dataGridView.Columns["CannedId"].Visible = false; dataGridView.Columns["CannedId"].Visible = false;
dataGridView.Columns["ClientId"].Visible = false; dataGridView.Columns["ClientId"].Visible = false;
dataGridView.Columns["ImplementerId"].Visible = false;
dataGridView.Columns["CannedName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
dataGridView.Columns["ClientFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
dataGridView.Columns["ImplementerFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
} }
_logger.LogInformation("Загрузка заказов"); _logger.LogInformation("Загрузка заказов");
} }
@ -58,6 +63,23 @@ namespace FishFactoryView
form.ShowDialog(); form.ShowDialog();
} }
} }
private void ImplementersToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormImplementers));
if (service is FormImplementers form)
{
form.ShowDialog();
}
}
private void DoWorkToolStripMenuItem_Click(object sender, EventArgs e)
{
_workProcess.DoWork((
Program.ServiceProvider?.GetService(typeof(IImplementerLogic)) as IImplementerLogic)!,
_orderLogic);
MessageBox.Show("Процесс обработки запущен", "Сообщение",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
private void ButtonCreateOrder_Click(object sender, EventArgs e) private void ButtonCreateOrder_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder));
@ -77,13 +99,7 @@ namespace FishFactoryView
{ {
var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel
{ {
Id = id, Id = id
CannedId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["CannedId"].Value),
CannedName = dataGridView.SelectedRows[0].Cells["CannedName"].Value.ToString(),
Status = Enum.Parse<OrderStatus>(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()),
Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value),
Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()),
DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()),
}); });
if (!operationResult) if (!operationResult)
{ {
@ -108,13 +124,7 @@ namespace FishFactoryView
{ {
var operationResult = _orderLogic.FinishOrder(new OrderBindingModel var operationResult = _orderLogic.FinishOrder(new OrderBindingModel
{ {
Id = id, Id = id
CannedId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["CannedId"].Value),
CannedName = dataGridView.SelectedRows[0].Cells["CannedName"].Value.ToString(),
Status = Enum.Parse<OrderStatus>(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()),
Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value),
Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()),
DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()),
}); });
if (!operationResult) if (!operationResult)
{ {
@ -139,13 +149,7 @@ namespace FishFactoryView
{ {
var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel
{ {
Id = id, Id = id
CannedId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["CannedId"].Value),
CannedName = dataGridView.SelectedRows[0].Cells["CannedName"].Value.ToString(),
Status = Enum.Parse<OrderStatus>(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()),
Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value),
Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()),
DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()),
}); });
if (!operationResult) if (!operationResult)
{ {

View File

@ -44,11 +44,14 @@ namespace FishFactoryView
services.AddTransient<IIngredientStorage, IngredientStorage>(); services.AddTransient<IIngredientStorage, IngredientStorage>();
services.AddTransient<IOrderStorage, OrderStorage>(); services.AddTransient<IOrderStorage, OrderStorage>();
services.AddTransient<ICannedStorage, CannedStorage>(); services.AddTransient<ICannedStorage, CannedStorage>();
services.AddTransient<IImplementerStorage, ImplementerStorage>();
services.AddTransient<IClientLogic, ClientLogic>(); services.AddTransient<IClientLogic, ClientLogic>();
services.AddTransient<IIngredientLogic, IngredientLogic>(); services.AddTransient<IIngredientLogic, IngredientLogic>();
services.AddTransient<IOrderLogic, OrderLogic>(); services.AddTransient<IOrderLogic, OrderLogic>();
services.AddTransient<ICannedLogic, CannedLogic>(); services.AddTransient<ICannedLogic, CannedLogic>();
services.AddTransient<IReportLogic, ReportLogic>(); services.AddTransient<IReportLogic, ReportLogic>();
services.AddTransient<IImplementerLogic, ImplementerLogic>();
services.AddTransient<IWorkProcess, WorkModeling>();
services.AddTransient<AbstractSaveToExcel, SaveToExcel>(); services.AddTransient<AbstractSaveToExcel, SaveToExcel>();
services.AddTransient<AbstractSaveToWord, SaveToWord>(); services.AddTransient<AbstractSaveToWord, SaveToWord>();
@ -64,6 +67,8 @@ namespace FishFactoryView
services.AddTransient<FormListCanned>(); services.AddTransient<FormListCanned>();
services.AddTransient<FormReportCannedIngredients>(); services.AddTransient<FormReportCannedIngredients>();
services.AddTransient<FormReportOrders>(); services.AddTransient<FormReportOrders>();
services.AddTransient<FormImplementers>();
services.AddTransient<FormImplementer>();
} }
} }
} }