From 23ff91c1e53ad07fa9b05c359e035408fb26284a Mon Sep 17 00:00:00 2001 From: dex_moth Date: Sun, 12 May 2024 19:24:51 +0400 Subject: [PATCH 1/5] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=20=D0=B8=D1=81=D0=BF=D0=BE=D0=BB=D0=BD=D0=B8=D1=82=D0=B5?= =?UTF-8?q?=D0=BB=D1=8C,=20=D0=B2=D1=81=D1=91=20=D0=BF=D1=80=D0=BE=D0=BF?= =?UTF-8?q?=D0=B8=D1=81=D0=B0=D0=BD=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogic/ImplementerLogic.cs | 115 +++++++++++++++++ .../BindingModels/ImplementerBindingModel.cs | 16 +++ .../BindingModels/OrderBindingModel.cs | 1 + .../IImplementerBusinessLogic.cs | 15 +++ .../SearchModels/ImplementerSearchModel.cs | 10 ++ .../StoragesContracts/IImplementerStorage.cs | 17 +++ .../ViewModels/ImplementerViewModel.cs | 18 +++ .../ViewModels/OrderViewModel.cs | 5 +- .../Models/IImplementerModel.cs | 10 ++ FishFactoryDataModels/Models/IOrderModel.cs | 1 + .../FishFactoryDatabase.cs | 1 + .../Implements/ImplementerStorage.cs | 79 ++++++++++++ .../Implements/OrderStorage.cs | 5 + .../Models/Implementer.cs | 59 +++++++++ FishFactoryDatabaseImplement/Models/Order.cs | 14 ++- FishFactoryFileImplement/DataFileSingleton.cs | 4 + .../FishFactoryFileImplement.csproj | 2 +- .../Implements/ImplementerStorage.cs | 118 +++++++++++++++++ .../Models/Implementer.cs | 65 ++++++++++ FishFactoryFileImplement/Models/Order.cs | 22 ++-- FishFactoryListImplement/DataListSingleton.cs | 6 +- .../Implements/ImplementerStorage.cs | 119 ++++++++++++++++++ .../Models/Implementer.cs | 56 +++++++++ FishFactoryListImplement/Models/Order.cs | 14 +-- 24 files changed, 750 insertions(+), 22 deletions(-) create mode 100644 FishFactoryBusinessLogic/BusinessLogic/ImplementerLogic.cs create mode 100644 FishFactoryContracts/BindingModels/ImplementerBindingModel.cs create mode 100644 FishFactoryContracts/BusinessLogicsContracts/IImplementerBusinessLogic.cs create mode 100644 FishFactoryContracts/SearchModels/ImplementerSearchModel.cs create mode 100644 FishFactoryContracts/StoragesContracts/IImplementerStorage.cs create mode 100644 FishFactoryContracts/ViewModels/ImplementerViewModel.cs create mode 100644 FishFactoryDataModels/Models/IImplementerModel.cs create mode 100644 FishFactoryDatabaseImplement/Implements/ImplementerStorage.cs create mode 100644 FishFactoryDatabaseImplement/Models/Implementer.cs create mode 100644 FishFactoryFileImplement/Implements/ImplementerStorage.cs create mode 100644 FishFactoryFileImplement/Models/Implementer.cs create mode 100644 FishFactoryListImplement/Implements/ImplementerStorage.cs create mode 100644 FishFactoryListImplement/Models/Implementer.cs diff --git a/FishFactoryBusinessLogic/BusinessLogic/ImplementerLogic.cs b/FishFactoryBusinessLogic/BusinessLogic/ImplementerLogic.cs new file mode 100644 index 0000000..618d327 --- /dev/null +++ b/FishFactoryBusinessLogic/BusinessLogic/ImplementerLogic.cs @@ -0,0 +1,115 @@ +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.BusinessLogicsContracts; +using FishFactoryContracts.SearchModels; +using FishFactoryContracts.StoragesContracts; +using FishFactoryContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace FishFactoryBusinessLogic.BusinessLogic +{ + public class ImplementerLogic : IImplementerBusinessLogic + { + private readonly ILogger _logger; + private readonly IImplementerStorage _implementerStorage; + public ImplementerLogic(ILogger logger, IImplementerStorage implementerStorage) + { + _logger = logger; + _implementerStorage = implementerStorage; + } + public List? 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 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 bool Create(ImplementerBindingModel model) + { + CheckModel(model); + if (_implementerStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(ImplementerBindingModel model) + { + CheckModel(model); + if (_implementerStorage.Update(model) == null) + { + _logger.LogWarning("Update 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; + } + 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 (string.IsNullOrEmpty(model.Password)) + { + throw new ArgumentNullException("Нет пароля исполнителя", nameof(model.Password)); + } + if (model.WorkExperience < 0) + { + throw new ArgumentNullException("Стаж меньше 0", nameof(model.WorkExperience)); + } + if (model.Qualification < 0) + { + throw new ArgumentException("Квалификация меньше 0", nameof(model.Qualification)); + } + _logger.LogInformation("Implementer. ImplementerFIO:{ImplementerFIO}." + "Password:{ Password}. WorkExperience:{ WorkExperience}. Qualification:{ Qualification}. Id: { Id} ", model.ImplementerFIO, model.Password, model.WorkExperience, model.Qualification, model.Id); + var element = _implementerStorage.GetElement(new ImplementerSearchModel + { + ImplementerFIO = model.ImplementerFIO, + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Исполнитель с таким ФИО уже есть"); + } + } + } +} diff --git a/FishFactoryContracts/BindingModels/ImplementerBindingModel.cs b/FishFactoryContracts/BindingModels/ImplementerBindingModel.cs new file mode 100644 index 0000000..9f5155f --- /dev/null +++ b/FishFactoryContracts/BindingModels/ImplementerBindingModel.cs @@ -0,0 +1,16 @@ +using FishFactoryDataModel.Models; + +namespace FishFactoryContracts.BindingModels +{ + 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; } +} +} diff --git a/FishFactoryContracts/BindingModels/OrderBindingModel.cs b/FishFactoryContracts/BindingModels/OrderBindingModel.cs index 773c201..f74e8d3 100644 --- a/FishFactoryContracts/BindingModels/OrderBindingModel.cs +++ b/FishFactoryContracts/BindingModels/OrderBindingModel.cs @@ -8,6 +8,7 @@ namespace FishFactoryContracts.BindingModels public int Id { get; set; } public int CannedId { get; set; } public int ClientId { get; set; } + public int ImplementerId { get; } public int Count { get; set; } public double Sum { get; set; } public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; diff --git a/FishFactoryContracts/BusinessLogicsContracts/IImplementerBusinessLogic.cs b/FishFactoryContracts/BusinessLogicsContracts/IImplementerBusinessLogic.cs new file mode 100644 index 0000000..ccb10eb --- /dev/null +++ b/FishFactoryContracts/BusinessLogicsContracts/IImplementerBusinessLogic.cs @@ -0,0 +1,15 @@ +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.SearchModels; +using FishFactoryContracts.ViewModels; + +namespace FishFactoryContracts.BusinessLogicsContracts +{ + public interface IImplementerBusinessLogic + { + List? ReadList(ImplementerSearchModel? model); + ImplementerViewModel? ReadElement(ImplementerSearchModel model); + bool Create(ImplementerBindingModel model); + bool Update(ImplementerBindingModel model); + bool Delete(ImplementerBindingModel model); + } +} diff --git a/FishFactoryContracts/SearchModels/ImplementerSearchModel.cs b/FishFactoryContracts/SearchModels/ImplementerSearchModel.cs new file mode 100644 index 0000000..be9c97f --- /dev/null +++ b/FishFactoryContracts/SearchModels/ImplementerSearchModel.cs @@ -0,0 +1,10 @@ + +namespace FishFactoryContracts.SearchModels +{ + public class ImplementerSearchModel + { + public int? Id { get; set; } + public string? ImplementerFIO { get; set; } + public string? Password { get; set; } + } +} diff --git a/FishFactoryContracts/StoragesContracts/IImplementerStorage.cs b/FishFactoryContracts/StoragesContracts/IImplementerStorage.cs new file mode 100644 index 0000000..1e9579b --- /dev/null +++ b/FishFactoryContracts/StoragesContracts/IImplementerStorage.cs @@ -0,0 +1,17 @@ + +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.SearchModels; +using FishFactoryContracts.ViewModels; + +namespace FishFactoryContracts.StoragesContracts +{ + public interface IImplementerStorage + { + List GetFullList(); + List GetFilteredList(ImplementerSearchModel model); + ImplementerViewModel? GetElement(ImplementerSearchModel model); + ImplementerViewModel? Insert(ImplementerBindingModel model); + ImplementerViewModel? Update(ImplementerBindingModel model); + ImplementerViewModel? Delete(ImplementerBindingModel model); + } +} diff --git a/FishFactoryContracts/ViewModels/ImplementerViewModel.cs b/FishFactoryContracts/ViewModels/ImplementerViewModel.cs new file mode 100644 index 0000000..ceaae40 --- /dev/null +++ b/FishFactoryContracts/ViewModels/ImplementerViewModel.cs @@ -0,0 +1,18 @@ + +using System.ComponentModel; + +namespace FishFactoryContracts.ViewModels +{ + public class ImplementerViewModel + { + public int Id { get; set; } + [DisplayName("ФИО исполнителя")] + public string ImplementerFIO { get; set; } + [DisplayName("Пароль")] + public string Password { get; set; } + [DisplayName("Опыт работы")] + public int WorkExperience { get; set; } + [DisplayName("Квалификация")] + public int Qualification { get; set; } + } +} diff --git a/FishFactoryContracts/ViewModels/OrderViewModel.cs b/FishFactoryContracts/ViewModels/OrderViewModel.cs index 6594c26..03c9099 100644 --- a/FishFactoryContracts/ViewModels/OrderViewModel.cs +++ b/FishFactoryContracts/ViewModels/OrderViewModel.cs @@ -15,7 +15,10 @@ namespace FishFactoryContracts.ViewModels public int ClientId { get; set; } [DisplayName("Клиент")] public string ClientFIO { get; set; } = string.Empty; - public int CannedId { get; set; } + public int ImplementerId { get; set; } + [DisplayName("Исполнитель")] + public string ImplementerFIO { get; set; } = string.Empty; + public int CannedId { get; set; } [DisplayName("Изделие")] public string CannedName { get; set; } = string.Empty; [DisplayName("Количество")] diff --git a/FishFactoryDataModels/Models/IImplementerModel.cs b/FishFactoryDataModels/Models/IImplementerModel.cs new file mode 100644 index 0000000..396886f --- /dev/null +++ b/FishFactoryDataModels/Models/IImplementerModel.cs @@ -0,0 +1,10 @@ +namespace FishFactoryDataModel.Models +{ + public interface IImplementerModel + { + string ImplementerFIO { get; } + string Password { get; } + int WorkExperience { get; } + int Qualification { get; } + } +} diff --git a/FishFactoryDataModels/Models/IOrderModel.cs b/FishFactoryDataModels/Models/IOrderModel.cs index 2d545bf..d95bdff 100644 --- a/FishFactoryDataModels/Models/IOrderModel.cs +++ b/FishFactoryDataModels/Models/IOrderModel.cs @@ -6,6 +6,7 @@ namespace FishFactoryDataModel.Models { int CannedId { get; } int ClientId { get; } + int ImplementerId { get; } int Count { get; } double Sum { get; } OrderStatus Status { get; } diff --git a/FishFactoryDatabaseImplement/FishFactoryDatabase.cs b/FishFactoryDatabaseImplement/FishFactoryDatabase.cs index c75f78e..359e212 100644 --- a/FishFactoryDatabaseImplement/FishFactoryDatabase.cs +++ b/FishFactoryDatabaseImplement/FishFactoryDatabase.cs @@ -20,5 +20,6 @@ namespace FishFactoryDatabaseImplement public virtual DbSet CannedComponents { set; get; } public virtual DbSet Clients { set; get; } public virtual DbSet Orders { set; get; } + public virtual DbSet Implementers { set; get; } } } diff --git a/FishFactoryDatabaseImplement/Implements/ImplementerStorage.cs b/FishFactoryDatabaseImplement/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..285dac7 --- /dev/null +++ b/FishFactoryDatabaseImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,79 @@ +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.SearchModels; +using FishFactoryContracts.StoragesContracts; +using FishFactoryContracts.ViewModels; +using FishFactoryDatabaseImplement.Models; + +namespace FishFactoryDatabaseImplement.Implements +{ + public class ImplementerStorage : IImplementerStorage + { + public List GetFullList() + { + using var context = new FishFactoryDatabase(); + return context.Implementers.Select(x => x.GetViewModel).ToList(); + } + + public List GetFilteredList(ImplementerSearchModel model) + { + if (string.IsNullOrEmpty(model.ImplementerFIO)) + { + return new(); + } + using var context = new FishFactoryDatabase(); + return context.Implementers.Where(x => x.ImplementerFIO.Contains(model.ImplementerFIO)).Select(x => x.GetViewModel).ToList(); + } + + public ImplementerViewModel? GetElement(ImplementerSearchModel model) + { + if (string.IsNullOrEmpty(model.ImplementerFIO) && !model.Id.HasValue) + { + return null; + } + using var context = new FishFactoryDatabase(); + return context.Implementers.FirstOrDefault(x => + (!string.IsNullOrEmpty(model.ImplementerFIO) && x.ImplementerFIO == model.ImplementerFIO && (!string.IsNullOrEmpty(model.Password) ? x.Password == model.Password : true)) || + (model.Id.HasValue && x.Id == model.Id)) + ?.GetViewModel; + } + + 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 newImplementer.GetViewModel; + } + + public ImplementerViewModel? Update(ImplementerBindingModel model) + { + using var context = new FishFactoryDatabase(); + var implementer = context.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (implementer == null) + { + return null; + } + implementer.Update(model); + context.SaveChanges(); + return implementer.GetViewModel; + } + + public ImplementerViewModel? Delete(ImplementerBindingModel model) + { + using var context = new FishFactoryDatabase(); + var implementer = context.Implementers.FirstOrDefault(rec => rec.Id == model.Id); + if (implementer != null) + { + context.Implementers.Remove(implementer); + context.SaveChanges(); + return implementer.GetViewModel; + } + return null; + } + } +} diff --git a/FishFactoryDatabaseImplement/Implements/OrderStorage.cs b/FishFactoryDatabaseImplement/Implements/OrderStorage.cs index bcefbfc..dec4a6a 100644 --- a/FishFactoryDatabaseImplement/Implements/OrderStorage.cs +++ b/FishFactoryDatabaseImplement/Implements/OrderStorage.cs @@ -15,6 +15,7 @@ namespace FishFactoryDatabaseImplement.Implements return context.Orders .Include(x => x.Canned) .Include(x => x.Client) + .Include(x => x.Implementer) .Select(x => x.GetViewModel) .ToList(); } @@ -24,6 +25,7 @@ namespace FishFactoryDatabaseImplement.Implements return context.Orders .Include(x => x.Canned) .Include(x => x.Client) + .Include(x => x.Implementer) .Where(x => (!model.Id.HasValue || x.Id == model.Id) && (!model.DateFrom.HasValue || x.DateCreate >= model.DateFrom) && @@ -42,6 +44,7 @@ namespace FishFactoryDatabaseImplement.Implements return context.Orders .Include(x => x.Canned) .Include(x => x.Client) + .Include(x => x.Implementer) .FirstOrDefault(x => x.Id == model.Id) ?.GetViewModel; } @@ -68,6 +71,7 @@ namespace FishFactoryDatabaseImplement.Implements var order = context.Orders .Include(o => o.Canned) .Include(o => o.Client) + .Include(x => x.Implementer) .FirstOrDefault(o => o.Id == model.Id); if (order == null) { @@ -90,6 +94,7 @@ namespace FishFactoryDatabaseImplement.Implements var element = context.Orders .Include(o => o.Canned) .Include(o => o.Client) + .Include(x => x.Implementer) .FirstOrDefault(o => o.Id == model.Id); if (element != null) { diff --git a/FishFactoryDatabaseImplement/Models/Implementer.cs b/FishFactoryDatabaseImplement/Models/Implementer.cs new file mode 100644 index 0000000..55dde5e --- /dev/null +++ b/FishFactoryDatabaseImplement/Models/Implementer.cs @@ -0,0 +1,59 @@ +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.ViewModels; +using FishFactoryDataModel.Models; +using System.ComponentModel.DataAnnotations.Schema; + +namespace FishFactoryDatabaseImplement.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; } + [ForeignKey("ImplementerId")] + public virtual List Order { get; set; } = new(); + + public static Implementer? Create(ImplementerBindingModel? model) + { + if (model == null) + { + return null; + } + return new() + { + Id = model.Id, + Password = model.Password, + Qualification = model.Qualification, + ImplementerFIO = model.ImplementerFIO, + WorkExperience = model.WorkExperience, + }; + } + + public void Update(ImplementerBindingModel model) + { + if (model == null) + { + return; + } + Password = model.Password; + Qualification = model.Qualification; + ImplementerFIO = model.ImplementerFIO; + WorkExperience = model.WorkExperience; + } + + public ImplementerViewModel GetViewModel => new() + { + Id = Id, + ImplementerFIO = ImplementerFIO, + Password = Password, + Qualification = Qualification, + ImplementerFIO = ImplementerFIO, + }; + } +} diff --git a/FishFactoryDatabaseImplement/Models/Order.cs b/FishFactoryDatabaseImplement/Models/Order.cs index 234fd27..495aefe 100644 --- a/FishFactoryDatabaseImplement/Models/Order.cs +++ b/FishFactoryDatabaseImplement/Models/Order.cs @@ -18,7 +18,11 @@ namespace FishFactoryDatabaseImplement.Models public int ClientId { get; private set; } public virtual Client Client { get; set; } = new(); - [Required] + [Required] + public int ImplementerId { get; private set; } + public virtual Implementer Implementer { get; set; } = new(); + + [Required] public int Count { get; private set; } [Required] public double Sum { get; private set; } @@ -36,7 +40,9 @@ namespace FishFactoryDatabaseImplement.Models Canned = context.Canneds.First(x => x.Id == model.CannedId), ClientId = model.ClientId, Client = context.Clients.First(x => x.Id == model.ClientId), - Count = model.Count, + ImplementerId = model.ImplementerId, + Implementer = context.Implementers.First(x => x.Id == model.ImplementerId), + Count = model.Count, Sum = model.Sum, Status = model.Status, DateCreate = model.DateCreate, @@ -51,6 +57,8 @@ namespace FishFactoryDatabaseImplement.Models } Id = model.Id; CannedId = model.CannedId; + ClientId = model.ClientId; + ImplementerId = model.ImplementerId; Sum = model.Sum; Status = model.Status; DateCreate = model.DateCreate; @@ -63,6 +71,8 @@ namespace FishFactoryDatabaseImplement.Models CannedName = Canned.CannedName, ClientId = ClientId, ClientFIO = Client.ClientFIO, + ImplementerId = ImplementerId, + ImplementerFIO = Implementer.ImplementerFIO, Count = Count, Sum = Sum, Status = Status, diff --git a/FishFactoryFileImplement/DataFileSingleton.cs b/FishFactoryFileImplement/DataFileSingleton.cs index 94e30ec..0afb482 100644 --- a/FishFactoryFileImplement/DataFileSingleton.cs +++ b/FishFactoryFileImplement/DataFileSingleton.cs @@ -11,10 +11,12 @@ namespace FishFactoryFileImplement private readonly string OrderFileName = "Order.xml"; private readonly string CannedFileName = "Canned.xml"; private readonly string ClientFileName = "Client.xml"; + private readonly string ImplementerFileName = "Implementer.xml"; public List Components { get; private set; } public List Orders { get; private set; } public List Canneds { get; private set; } public List Clients { get; private set; } + public List Implementers { get; private set; } public static DataFileSingleton GetInstance() { if (instance == null) @@ -27,12 +29,14 @@ namespace FishFactoryFileImplement public void SaveCanneds() => SaveData(Canneds, CannedFileName, "Canneds", 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 SaveImplementers() => SaveData(Implementers, ImplementerFileName, "Implementer", x => x.GetXElement); private DataFileSingleton() { Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!; Canneds = LoadData(CannedFileName, "Canned", x => Canned.Create(x)!)!; Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!; Clients = LoadData(ClientFileName, "Client", x => Client.Create(x)!)!; + Implementers = LoadData(ImplementerFileName, "Implementer", x => Implementer.Create(x)!)!; } private static List? LoadData(string filename, string xmlNodeName, Func selectFunction) { diff --git a/FishFactoryFileImplement/FishFactoryFileImplement.csproj b/FishFactoryFileImplement/FishFactoryFileImplement.csproj index 2fba834..1cbc85b 100644 --- a/FishFactoryFileImplement/FishFactoryFileImplement.csproj +++ b/FishFactoryFileImplement/FishFactoryFileImplement.csproj @@ -11,4 +11,4 @@ - + \ No newline at end of file diff --git a/FishFactoryFileImplement/Implements/ImplementerStorage.cs b/FishFactoryFileImplement/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..3352213 --- /dev/null +++ b/FishFactoryFileImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,118 @@ +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 List GetFullList() + { + var result = new List(); + foreach (var implementer in _source.Implementers) + { + result.Add(implementer.GetViewModel); + } + return result; + } + public List GetFilteredList(ImplementerSearchModel model) + { + if (model == null) + { + return new(); + } + if (model.Id.HasValue) + { + var res = GetElement(model); + return res != null ? new() { res } : new(); + } + + List result = new(); + if (model.ImplementerFIO != null) + { + foreach (var implementer in _source.Implementers) + { + if (implementer.ImplementerFIO.Equals(model.ImplementerFIO)) + { + result.Add(implementer.GetViewModel); + } + } + } + return result; + } + + public ImplementerViewModel? GetElement(ImplementerSearchModel model) + { + foreach (var x in _source.Implementers) + { + if (model.Id.HasValue && x.Id == model.Id) + { + return x.GetViewModel; + } + if (model.ImplementerFIO != null && x.ImplementerFIO.Equals(model.ImplementerFIO) && + model.Password != null && x.Password.Equals(model.Password)) + { + return x.GetViewModel; + } + if (model.ImplementerFIO != null && x.ImplementerFIO.Equals(model.ImplementerFIO)) + { + return x.GetViewModel; + } + } + return null; + } + + 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? Insert(ImplementerBindingModel model) + { + model.Id = 1; + foreach (var implementer in _source.Implementers) + { + if (model.Id <= implementer.Id) + { + model.Id = implementer.Id + 1; + } + } + var res = Implementer.Create(model); + if (res != null) + { + _source.Implementers.Add(res); + } + return res?.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; + } + } +} diff --git a/FishFactoryFileImplement/Models/Implementer.cs b/FishFactoryFileImplement/Models/Implementer.cs new file mode 100644 index 0000000..9469378 --- /dev/null +++ b/FishFactoryFileImplement/Models/Implementer.cs @@ -0,0 +1,65 @@ +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.ViewModels; +using FishFactoryDataModel.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() + { + Id = model.Id, + Password = model.Password, + Qualification = model.Qualification, + ImplementerFIO = model.ImplementerFIO, + WorkExperience = model.WorkExperience, + }; + } + + public void Update(ImplementerBindingModel model) + { + if (model == null) + { + return; + } + Password = model.Password; + Qualification = model.Qualification; + ImplementerFIO = model.ImplementerFIO; + WorkExperience = model.WorkExperience; + } + + public ImplementerViewModel GetViewModel => new() + { + Id = Id, + Password = Password, + ImplementerFIO = ImplementerFIO, + Qualification = Qualification, + ImplementerFIO = ImplementerFIO, + }; + + public XElement GetXElement => new("Implementer", + new XAttribute("Id", Id), + new XElement("Password", Password), + new XElement("ImplementerFIO", ImplementerFIO), + new XElement("Qualification", Qualification), + new XElement("WorkExperience", WorkExperience) + ); + } +} diff --git a/FishFactoryFileImplement/Models/Order.cs b/FishFactoryFileImplement/Models/Order.cs index 0eb4367..e7aa048 100644 --- a/FishFactoryFileImplement/Models/Order.cs +++ b/FishFactoryFileImplement/Models/Order.cs @@ -11,7 +11,8 @@ namespace FishFactoryFileImplement.Models public int Id { get; private set; } public int CannedId { get; private set; } public int ClientId { get; private set; } - public int Count { get; private set; } + public int ImplementerId { get; set; } + public int Count { get; private set; } public double Sum { get; private set; } public OrderStatus Status { get; private set; } public DateTime DateCreate { get; private set; } @@ -25,8 +26,9 @@ namespace FishFactoryFileImplement.Models return new Order() { Id = Convert.ToInt32(element.Attribute("Id")!.Value), - ClientId = Convert.ToInt32(element.Element("ClientId")!.Value), - CannedId = Convert.ToInt32(element.Element("CannedId")!.Value), + CannedId = Convert.ToInt32(element.Element("CannedId")!.Value), + ClientId = Convert.ToInt32(element.Element("ClientId")!.Value), + ImplementerId = Convert.ToInt32(element.Element("ImplementerId")!.Value), Count = Convert.ToInt32(element.Element("Count")!.Value), Sum = Convert.ToDouble(element.Element("Sum")!.Value), Status = (OrderStatus)Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value), @@ -43,8 +45,9 @@ namespace FishFactoryFileImplement.Models return new Order() { Id = model.Id, - ClientId = model.ClientId, - CannedId = model.CannedId, + CannedId = model.CannedId, + ClientId = model.ClientId, + ImplementerId = model.ImplementerId, Count = model.Count, Sum = model.Sum, Status = model.Status, @@ -59,7 +62,8 @@ namespace FishFactoryFileImplement.Models return; } CannedId = model.CannedId; - ClientId = ClientId; + ClientId = model.ClientId; + ImplementerId = model.ImplementerId; Count = model.Count; Sum = model.Sum; Status = model.Status; @@ -71,7 +75,8 @@ namespace FishFactoryFileImplement.Models Id = Id, CannedId = CannedId, ClientId = ClientId, - Count = Count, + ImplementerId = ImplementerId, + Count = Count, Sum = Sum, Status = Status, DateCreate = DateCreate, @@ -79,8 +84,9 @@ namespace FishFactoryFileImplement.Models }; public XElement GetXElement => new("Order", new XAttribute("Id", Id), + new XElement("CannedId", CannedId.ToString()), new XElement("ClientId", ClientId.ToString()), - new XElement("CannedId", CannedId), + new XElement("ImplementerId", ImplementerId.ToString()), new XElement("Count", Count.ToString()), new XElement("Sum", Sum.ToString()), new XElement("Status", Status.ToString()), diff --git a/FishFactoryListImplement/DataListSingleton.cs b/FishFactoryListImplement/DataListSingleton.cs index 7595546..1f883f4 100644 --- a/FishFactoryListImplement/DataListSingleton.cs +++ b/FishFactoryListImplement/DataListSingleton.cs @@ -9,13 +9,15 @@ namespace FishFactoryListImplement public List Orders { get; set; } public List Canneds { get; set; } public List Clients { get; set; } - private DataListSingleton() + public List Implementers { get; set; } + private DataListSingleton() { Components = new List(); Orders = new List(); Canneds = new List(); Clients = new List(); - } + Implementers = new List(); + } public static DataListSingleton GetInstance() { if (_instance == null) diff --git a/FishFactoryListImplement/Implements/ImplementerStorage.cs b/FishFactoryListImplement/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..f93448e --- /dev/null +++ b/FishFactoryListImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,119 @@ +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) + { + foreach (var x in _source.Implementers) + { + if (model.Id.HasValue && x.Id == model.Id) + { + return x.GetViewModel; + } + if (model.ImplementerFIO != null && x.ImplementerFIO.Equals(model.ImplementerFIO) && + model.Password != null && x.Password.Equals(model.Password)) + { + return x.GetViewModel; + } + if (model.ImplementerFIO != null && x.ImplementerFIO.Equals(model.ImplementerFIO)) + { + return x.GetViewModel; + } + } + return null; + } + + public List GetFilteredList(ImplementerSearchModel model) + { + if (model == null) + { + return new(); + } + if (model.Id.HasValue) + { + var res = GetElement(model); + return res != null ? new() { res } : new(); + } + + List result = new(); + if (model.ImplementerFIO != null) + { + foreach (var implementer in _source.Implementers) + { + if (implementer.ImplementerFIO.Equals(model.ImplementerFIO)) + { + result.Add(implementer.GetViewModel); + } + } + } + return result; + } + + public List GetFullList() + { + var result = new List(); + 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 res = Implementer.Create(model); + if (res != null) + { + _source.Implementers.Add(res); + } + return res?.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; + } + } +} diff --git a/FishFactoryListImplement/Models/Implementer.cs b/FishFactoryListImplement/Models/Implementer.cs new file mode 100644 index 0000000..4530cce --- /dev/null +++ b/FishFactoryListImplement/Models/Implementer.cs @@ -0,0 +1,56 @@ +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.ViewModels; +using FishFactoryDataModel.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() + { + Id = model.Id, + Password = model.Password, + Qualification = model.Qualification, + ImplementerFIO = model.ImplementerFIO, + WorkExperience = model.WorkExperience, + }; + } + + public void Update(ImplementerBindingModel model) + { + if (model == null) + { + return; + } + Password = model.Password; + Qualification = model.Qualification; + ImplementerFIO = model.ImplementerFIO; + WorkExperience = model.WorkExperience; + } + + public ImplementerViewModel GetViewModel => new() + { + Id = Id, + Password = Password, + ImplementerFIO = ImplementerFIO, + Qualification = Qualification, + ImplementerFIO = ImplementerFIO, + }; + } +} diff --git a/FishFactoryListImplement/Models/Order.cs b/FishFactoryListImplement/Models/Order.cs index ade6f6b..6b31f26 100644 --- a/FishFactoryListImplement/Models/Order.cs +++ b/FishFactoryListImplement/Models/Order.cs @@ -2,12 +2,7 @@ using FishFactoryContracts.ViewModels; using FishFactoryDataModel.Enums; using FishFactoryDataModel.Models; -using System; -using System.Collections.Generic; -using System.Linq; using System.Reflection; -using System.Text; -using System.Threading.Tasks; namespace FishFactoryListImplement.Models { @@ -16,7 +11,8 @@ namespace FishFactoryListImplement.Models public int Id { get; private set; } public int CannedId { get; private set; } public int ClientId { get; private set; } - public int Count { get; private set; } + public int? ImplementerId { get; private set; } + public int Count { get; private set; } public double Sum { get; private set; } public OrderStatus Status { get; private set; } public DateTime DateCreate { get; private set; } @@ -32,7 +28,8 @@ namespace FishFactoryListImplement.Models Id = model.Id, CannedId = model.CannedId, ClientId = model.ClientId, - Count = model.Count, + ImplementerId = model.ImplementerId, + Count = model.Count, Sum = model.Sum, Status = model.Status, DateCreate = model.DateCreate, @@ -58,7 +55,8 @@ namespace FishFactoryListImplement.Models Id = Id, CannedId = CannedId, ClientId = ClientId, - Count = Count, + ImplementerId = model.ImplementerId, + Count = Count, Sum = Sum, Status = Status, DateCreate = DateCreate, -- 2.25.1 From 113baf20a0af4d65f08c6381c1f7224810f36dd3 Mon Sep 17 00:00:00 2001 From: dex_moth Date: Mon, 13 May 2024 22:15:56 +0400 Subject: [PATCH 2/5] =?UTF-8?q?=D0=B4=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FishFactory/Forms/FormCreateOrder.cs | 8 +- FishFactory/Forms/FormImplementer.Designer.cs | 168 ++++++++++++ FishFactory/Forms/FormImplementer.cs | 95 +++++++ FishFactory/Forms/FormImplementer.resx | 120 +++++++++ .../Forms/FormImplementers.Designer.cs | 125 +++++++++ FishFactory/Forms/FormImplementers.cs | 104 +++++++ FishFactory/Forms/FormImplementers.resx | 120 +++++++++ FishFactory/Forms/FormMain.Designer.cs | 62 ++--- FishFactory/Forms/FormMain.cs | 72 ++--- FishFactory/Program.cs | 8 +- .../BusinessLogic/ImplementerLogic.cs | 2 +- .../BusinessLogic/OrderLogic.cs | 32 ++- .../BusinessLogic/WorkModeling.cs | 141 ++++++++++ .../BindingModels/OrderBindingModel.cs | 2 +- ...rBusinessLogic.cs => IImplementerLogic.cs} | 2 +- .../BusinessLogicsContracts/IOrderLogic.cs | 1 + .../BusinessLogicsContracts/IWorkProcess.cs | 7 + .../SearchModels/OrderSearchModel.cs | 6 +- .../ViewModels/OrderViewModel.cs | 4 +- FishFactoryDataModels/Models/IOrderModel.cs | 2 +- .../FishFactoryDatabase.cs | 2 +- .../Implements/ImplementerStorage.cs | 3 +- .../Implements/OrderStorage.cs | 23 +- .../20240513132159_initialcreate.Designer.cs | 255 ++++++++++++++++++ ...ase.cs => 20240513132159_initialcreate.cs} | 75 ++++-- ...20240513152048_add_implementer.Designer.cs | 255 ++++++++++++++++++ .../20240513152048_add_implementer.cs | 22 ++ ...r.cs => 20240513170412_create.Designer.cs} | 47 +++- .../Migrations/20240513170412_create.cs | 59 ++++ .../FishFactoryDatabaseModelSnapshot.cs | 43 +++ .../Models/Implementer.cs | 2 +- FishFactoryDatabaseImplement/Models/Order.cs | 19 +- .../Models/Implementer.cs | 19 +- FishFactoryFileImplement/Models/Order.cs | 2 +- .../Models/Implementer.cs | 3 +- FishFactoryListImplement/Models/Order.cs | 3 +- .../Controllers/ImplementerController.cs | 99 +++++++ 37 files changed, 1855 insertions(+), 157 deletions(-) create mode 100644 FishFactory/Forms/FormImplementer.Designer.cs create mode 100644 FishFactory/Forms/FormImplementer.cs create mode 100644 FishFactory/Forms/FormImplementer.resx create mode 100644 FishFactory/Forms/FormImplementers.Designer.cs create mode 100644 FishFactory/Forms/FormImplementers.cs create mode 100644 FishFactory/Forms/FormImplementers.resx create mode 100644 FishFactoryBusinessLogic/BusinessLogic/WorkModeling.cs rename FishFactoryContracts/BusinessLogicsContracts/{IImplementerBusinessLogic.cs => IImplementerLogic.cs} (91%) create mode 100644 FishFactoryContracts/BusinessLogicsContracts/IWorkProcess.cs create mode 100644 FishFactoryDatabaseImplement/Migrations/20240513132159_initialcreate.Designer.cs rename FishFactoryDatabaseImplement/Migrations/{20240509142302_initialdatabase.cs => 20240513132159_initialcreate.cs} (81%) create mode 100644 FishFactoryDatabaseImplement/Migrations/20240513152048_add_implementer.Designer.cs create mode 100644 FishFactoryDatabaseImplement/Migrations/20240513152048_add_implementer.cs rename FishFactoryDatabaseImplement/Migrations/{20240509142302_initialdatabase.Designer.cs => 20240513170412_create.Designer.cs} (82%) create mode 100644 FishFactoryDatabaseImplement/Migrations/20240513170412_create.cs create mode 100644 FishFactoryRestApi/Controllers/ImplementerController.cs diff --git a/FishFactory/Forms/FormCreateOrder.cs b/FishFactory/Forms/FormCreateOrder.cs index f9cc95d..9d04f7a 100644 --- a/FishFactory/Forms/FormCreateOrder.cs +++ b/FishFactory/Forms/FormCreateOrder.cs @@ -82,9 +82,9 @@ namespace FishFactory.Forms private void buttonSave_Click(object sender, EventArgs e) { - if (string.IsNullOrEmpty(textBoxCount.Text)) + if (comboBoxClient.SelectedValue == null) { - MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show("Выберите клиента", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (comboBoxCanned.SelectedValue == null) @@ -92,9 +92,9 @@ namespace FishFactory.Forms MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } - if (comboBoxClient.SelectedValue == null) + if (string.IsNullOrEmpty(textBoxCount.Text)) { - MessageBox.Show("Выберите клиента", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } _logger.LogInformation("Создание заказа"); diff --git a/FishFactory/Forms/FormImplementer.Designer.cs b/FishFactory/Forms/FormImplementer.Designer.cs new file mode 100644 index 0000000..32f1137 --- /dev/null +++ b/FishFactory/Forms/FormImplementer.Designer.cs @@ -0,0 +1,168 @@ +namespace FishFactory.Forms +{ + partial class FormImplementer + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + textBoxWorkExperience = new TextBox(); + textBoxFIO = new TextBox(); + label2 = new Label(); + label1 = new Label(); + buttonCancel = new Button(); + buttonSave = new Button(); + textBoxQualification = new TextBox(); + label3 = new Label(); + textBoxPassword = new TextBox(); + label4 = new Label(); + SuspendLayout(); + // + // textBoxWorkExperience + // + textBoxWorkExperience.Location = new Point(189, 97); + textBoxWorkExperience.Margin = new Padding(3, 4, 3, 4); + textBoxWorkExperience.Name = "textBoxWorkExperience"; + textBoxWorkExperience.Size = new Size(305, 26); + textBoxWorkExperience.TabIndex = 11; + // + // textBoxFIO + // + textBoxFIO.Location = new Point(189, 27); + textBoxFIO.Margin = new Padding(3, 4, 3, 4); + textBoxFIO.Name = "textBoxFIO"; + textBoxFIO.Size = new Size(305, 26); + textBoxFIO.TabIndex = 10; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(43, 100); + label2.Name = "label2"; + label2.Size = new Size(95, 19); + label2.TabIndex = 9; + label2.Text = "Стаж работы:"; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(43, 29); + label1.Name = "label1"; + label1.Size = new Size(127, 19); + label1.TabIndex = 8; + label1.Text = "ФИО исполнителя:"; + // + // buttonCancel + // + buttonCancel.Location = new Point(400, 191); + buttonCancel.Margin = new Padding(3, 4, 3, 4); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(98, 32); + buttonCancel.TabIndex = 7; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // buttonSave + // + buttonSave.Location = new Point(292, 191); + buttonSave.Margin = new Padding(3, 4, 3, 4); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(98, 32); + buttonSave.TabIndex = 6; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // textBoxQualification + // + textBoxQualification.Location = new Point(189, 131); + textBoxQualification.Margin = new Padding(3, 4, 3, 4); + textBoxQualification.Name = "textBoxQualification"; + textBoxQualification.Size = new Size(305, 26); + textBoxQualification.TabIndex = 13; + // + // label3 + // + label3.AutoSize = true; + label3.Location = new Point(43, 134); + label3.Name = "label3"; + label3.Size = new Size(104, 19); + label3.TabIndex = 12; + label3.Text = "Квалификация:"; + // + // textBoxPassword + // + textBoxPassword.Location = new Point(189, 63); + textBoxPassword.Margin = new Padding(3, 4, 3, 4); + textBoxPassword.Name = "textBoxPassword"; + textBoxPassword.Size = new Size(305, 26); + textBoxPassword.TabIndex = 15; + // + // label4 + // + label4.AutoSize = true; + label4.Location = new Point(43, 65); + label4.Name = "label4"; + label4.Size = new Size(59, 19); + label4.TabIndex = 14; + label4.Text = "Пароль:"; + // + // FormImplementer + // + AutoScaleDimensions = new SizeF(8F, 19F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(536, 238); + Controls.Add(textBoxPassword); + Controls.Add(label4); + Controls.Add(textBoxQualification); + Controls.Add(label3); + Controls.Add(textBoxWorkExperience); + Controls.Add(textBoxFIO); + Controls.Add(label2); + Controls.Add(label1); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Name = "FormImplementer"; + Text = "FormImplementer"; + Load += FormImplementer_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private TextBox textBoxWorkExperience; + private TextBox textBoxFIO; + private Label label2; + private Label label1; + private Button buttonCancel; + private Button buttonSave; + private TextBox textBoxQualification; + private Label label3; + private TextBox textBoxPassword; + private Label label4; + } +} \ No newline at end of file diff --git a/FishFactory/Forms/FormImplementer.cs b/FishFactory/Forms/FormImplementer.cs new file mode 100644 index 0000000..5694413 --- /dev/null +++ b/FishFactory/Forms/FormImplementer.cs @@ -0,0 +1,95 @@ +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.BusinessLogicsContracts; +using FishFactoryContracts.SearchModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +namespace FishFactory.Forms +{ + 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 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; + textBoxWorkExperience.Text = view.WorkExperience.ToString(); + textBoxQualification.Text = view.Qualification.ToString(); + } + } + 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(textBoxFIO.Text)) + { + MessageBox.Show("Заполните ФИО", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxPassword.Text)) + { + MessageBox.Show("Заполните пароль", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение исполнителя"); + try + { + var model = new ImplementerBindingModel + { + Id = _id ?? 0, + ImplementerFIO = textBoxFIO.Text, + Password = textBoxPassword.Text, + WorkExperience = Convert.ToInt32(textBoxWorkExperience.Text), + Qualification = Convert.ToInt32(textBoxQualification.Text) + }; + 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(); + } + } +} diff --git a/FishFactory/Forms/FormImplementer.resx b/FishFactory/Forms/FormImplementer.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/FishFactory/Forms/FormImplementer.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/FishFactory/Forms/FormImplementers.Designer.cs b/FishFactory/Forms/FormImplementers.Designer.cs new file mode 100644 index 0000000..8ccea88 --- /dev/null +++ b/FishFactory/Forms/FormImplementers.Designer.cs @@ -0,0 +1,125 @@ +namespace FishFactory.Forms +{ + partial class FormImplementers + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + buttonRef = new Button(); + buttonDel = new Button(); + buttonUpd = new Button(); + buttonAdd = new Button(); + dataGridView = new DataGridView(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // buttonRef + // + buttonRef.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonRef.Location = new Point(622, 175); + buttonRef.Margin = new Padding(3, 4, 3, 4); + buttonRef.Name = "buttonRef"; + buttonRef.Size = new Size(125, 33); + buttonRef.TabIndex = 9; + buttonRef.Text = "Обновить"; + buttonRef.UseVisualStyleBackColor = true; + buttonRef.Click += buttonRef_Click; + // + // buttonDel + // + buttonDel.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonDel.Location = new Point(622, 126); + buttonDel.Margin = new Padding(3, 4, 3, 4); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(125, 33); + buttonDel.TabIndex = 8; + buttonDel.Text = "Удалить"; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += buttonDel_Click; + // + // buttonUpd + // + buttonUpd.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonUpd.Location = new Point(622, 77); + buttonUpd.Margin = new Padding(3, 4, 3, 4); + buttonUpd.Name = "buttonUpd"; + buttonUpd.Size = new Size(125, 33); + buttonUpd.TabIndex = 7; + buttonUpd.Text = "Изменить"; + buttonUpd.UseVisualStyleBackColor = true; + buttonUpd.Click += buttonUpd_Click; + // + // buttonAdd + // + buttonAdd.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonAdd.Location = new Point(622, 30); + buttonAdd.Margin = new Padding(3, 4, 3, 4); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(125, 33); + buttonAdd.TabIndex = 6; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += buttonAdd_Click; + // + // dataGridView + // + dataGridView.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(-2, -2); + dataGridView.Margin = new Padding(3, 4, 3, 4); + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 24; + dataGridView.Size = new Size(587, 549); + dataGridView.TabIndex = 5; + // + // FormImplementers + // + AutoScaleDimensions = new SizeF(8F, 19F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(775, 546); + Controls.Add(buttonRef); + Controls.Add(buttonDel); + Controls.Add(buttonUpd); + Controls.Add(buttonAdd); + Controls.Add(dataGridView); + Name = "FormImplementers"; + Text = "FormImplementers"; + Load += FormImplementers_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private Button buttonRef; + private Button buttonDel; + private Button buttonUpd; + private Button buttonAdd; + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/FishFactory/Forms/FormImplementers.cs b/FishFactory/Forms/FormImplementers.cs new file mode 100644 index 0000000..50f1271 --- /dev/null +++ b/FishFactory/Forms/FormImplementers.cs @@ -0,0 +1,104 @@ +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; + +namespace FishFactory.Forms +{ + public partial class FormImplementers : Form + { + private readonly ILogger _logger; + private readonly IImplementerLogic _logic; + + public FormImplementers(ILogger logger, IImplementerLogic implementerLogic) + { + InitializeComponent(); + _logger = logger; + _logic = implementerLogic; + } + + 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(); + } + } +} diff --git a/FishFactory/Forms/FormImplementers.resx b/FishFactory/Forms/FormImplementers.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/FishFactory/Forms/FormImplementers.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/FishFactory/Forms/FormMain.Designer.cs b/FishFactory/Forms/FormMain.Designer.cs index 94fe39f..602d6f6 100644 --- a/FishFactory/Forms/FormMain.Designer.cs +++ b/FishFactory/Forms/FormMain.Designer.cs @@ -34,13 +34,13 @@ компонентыToolStripMenuItem = new ToolStripMenuItem(); консервыToolStripMenuItem = new ToolStripMenuItem(); клиентыToolStripMenuItem = new ToolStripMenuItem(); + исполнителиToolStripMenuItem = new ToolStripMenuItem(); toolStripDropDownButton2 = new ToolStripDropDownButton(); списокКомпонентовToolStripMenuItem = new ToolStripMenuItem(); компонентыПоКонсервамToolStripMenuItem = new ToolStripMenuItem(); списокЗаказовToolStripMenuItem = new ToolStripMenuItem(); + ЗапускРаботToolStripLabel = new ToolStripLabel(); buttonCreateOrder = new Button(); - buttonTakeOrderInWork = new Button(); - buttonOrderReady = new Button(); buttonIssuedOrder = new Button(); buttonRef = new Button(); dataGridView = new DataGridView(); @@ -51,7 +51,7 @@ // toolStrip1 // toolStrip1.ImageScalingSize = new Size(20, 20); - toolStrip1.Items.AddRange(new ToolStripItem[] { toolStripDropDownButton1, toolStripDropDownButton2 }); + toolStrip1.Items.AddRange(new ToolStripItem[] { toolStripDropDownButton1, toolStripDropDownButton2, ЗапускРаботToolStripLabel }); toolStrip1.Location = new Point(0, 0); toolStrip1.Name = "toolStrip1"; toolStrip1.Size = new Size(1265, 26); @@ -61,7 +61,7 @@ // toolStripDropDownButton1 // toolStripDropDownButton1.DisplayStyle = ToolStripItemDisplayStyle.Text; - toolStripDropDownButton1.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, консервыToolStripMenuItem, клиентыToolStripMenuItem }); + toolStripDropDownButton1.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, консервыToolStripMenuItem, клиентыToolStripMenuItem, исполнителиToolStripMenuItem }); toolStripDropDownButton1.Image = (Image)resources.GetObject("toolStripDropDownButton1.Image"); toolStripDropDownButton1.ImageTransparentColor = Color.Magenta; toolStripDropDownButton1.Name = "toolStripDropDownButton1"; @@ -71,24 +71,31 @@ // компонентыToolStripMenuItem // компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; - компонентыToolStripMenuItem.Size = new Size(169, 26); + компонентыToolStripMenuItem.Size = new Size(171, 26); компонентыToolStripMenuItem.Text = "Компоненты"; компонентыToolStripMenuItem.Click += компонентыToolStripMenuItem_Click; // // консервыToolStripMenuItem // консервыToolStripMenuItem.Name = "консервыToolStripMenuItem"; - консервыToolStripMenuItem.Size = new Size(169, 26); + консервыToolStripMenuItem.Size = new Size(171, 26); консервыToolStripMenuItem.Text = "Консервы"; консервыToolStripMenuItem.Click += консервыToolStripMenuItem_Click; // // клиентыToolStripMenuItem // клиентыToolStripMenuItem.Name = "клиентыToolStripMenuItem"; - клиентыToolStripMenuItem.Size = new Size(169, 26); + клиентыToolStripMenuItem.Size = new Size(171, 26); клиентыToolStripMenuItem.Text = "Клиенты"; клиентыToolStripMenuItem.Click += клиентыToolStripMenuItem_Click; // + // исполнителиToolStripMenuItem + // + исполнителиToolStripMenuItem.Name = "исполнителиToolStripMenuItem"; + исполнителиToolStripMenuItem.Size = new Size(171, 26); + исполнителиToolStripMenuItem.Text = "Исполнители"; + исполнителиToolStripMenuItem.Click += исполнителиToolStripMenuItem_Click; + // // toolStripDropDownButton2 // toolStripDropDownButton2.DisplayStyle = ToolStripItemDisplayStyle.Text; @@ -120,6 +127,13 @@ списокЗаказовToolStripMenuItem.Text = "Список заказов"; списокЗаказовToolStripMenuItem.Click += списокЗаказовToolStripMenuItem_Click; // + // ЗапускРаботToolStripLabel + // + ЗапускРаботToolStripLabel.Name = "ЗапускРаботToolStripLabel"; + ЗапускРаботToolStripLabel.Size = new Size(93, 23); + ЗапускРаботToolStripLabel.Text = "Запуск работ"; + ЗапускРаботToolStripLabel.Click += ЗапускРаботToolStripLabel_Click; + // // buttonCreateOrder // buttonCreateOrder.Anchor = AnchorStyles.Top | AnchorStyles.Right; @@ -132,34 +146,10 @@ buttonCreateOrder.UseVisualStyleBackColor = true; buttonCreateOrder.Click += buttonCreateOrder_Click; // - // buttonTakeOrderInWork - // - buttonTakeOrderInWork.Anchor = AnchorStyles.Top | AnchorStyles.Right; - buttonTakeOrderInWork.Location = new Point(1078, 127); - buttonTakeOrderInWork.Margin = new Padding(3, 4, 3, 4); - buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; - buttonTakeOrderInWork.Size = new Size(161, 30); - buttonTakeOrderInWork.TabIndex = 2; - buttonTakeOrderInWork.Text = "Отдать на выполнение"; - buttonTakeOrderInWork.UseVisualStyleBackColor = true; - buttonTakeOrderInWork.Click += buttonTakeOrderInWork_Click; - // - // buttonOrderReady - // - buttonOrderReady.Anchor = AnchorStyles.Top | AnchorStyles.Right; - buttonOrderReady.Location = new Point(1078, 180); - buttonOrderReady.Margin = new Padding(3, 4, 3, 4); - buttonOrderReady.Name = "buttonOrderReady"; - buttonOrderReady.Size = new Size(161, 30); - buttonOrderReady.TabIndex = 3; - buttonOrderReady.Text = "Заказ готов"; - buttonOrderReady.UseVisualStyleBackColor = true; - buttonOrderReady.Click += buttonOrderReady_Click; - // // buttonIssuedOrder // buttonIssuedOrder.Anchor = AnchorStyles.Top | AnchorStyles.Right; - buttonIssuedOrder.Location = new Point(1078, 229); + buttonIssuedOrder.Location = new Point(1078, 125); buttonIssuedOrder.Margin = new Padding(3, 4, 3, 4); buttonIssuedOrder.Name = "buttonIssuedOrder"; buttonIssuedOrder.Size = new Size(161, 30); @@ -171,7 +161,7 @@ // buttonRef // buttonRef.Anchor = AnchorStyles.Top | AnchorStyles.Right; - buttonRef.Location = new Point(1078, 281); + buttonRef.Location = new Point(1078, 177); buttonRef.Margin = new Padding(3, 4, 3, 4); buttonRef.Name = "buttonRef"; buttonRef.Size = new Size(161, 30); @@ -202,8 +192,6 @@ Controls.Add(dataGridView); Controls.Add(buttonRef); Controls.Add(buttonIssuedOrder); - Controls.Add(buttonOrderReady); - Controls.Add(buttonTakeOrderInWork); Controls.Add(buttonCreateOrder); Controls.Add(toolStrip1); Margin = new Padding(3, 4, 3, 4); @@ -221,8 +209,6 @@ private ToolStrip toolStrip1; private Button buttonCreateOrder; - private Button buttonTakeOrderInWork; - private Button buttonOrderReady; private Button buttonIssuedOrder; private Button buttonRef; private DataGridView dataGridView; @@ -234,5 +220,7 @@ private ToolStripMenuItem компонентыПоКонсервамToolStripMenuItem; private ToolStripMenuItem списокЗаказовToolStripMenuItem; private ToolStripMenuItem клиентыToolStripMenuItem; + private ToolStripLabel ЗапускРаботToolStripLabel; + private ToolStripMenuItem исполнителиToolStripMenuItem; } } \ No newline at end of file diff --git a/FishFactory/Forms/FormMain.cs b/FishFactory/Forms/FormMain.cs index 3530101..a41d81f 100644 --- a/FishFactory/Forms/FormMain.cs +++ b/FishFactory/Forms/FormMain.cs @@ -1,5 +1,4 @@ -using FishFactoryBusinessLogic.BusinessLogic; -using FishFactoryContracts.BindingModels; +using FishFactoryContracts.BindingModels; using FishFactoryContracts.BusinessLogicsContracts; using Microsoft.Extensions.Logging; @@ -10,6 +9,8 @@ namespace FishFactory.Forms private readonly ILogger _logger; private readonly IOrderLogic _orderLogic; private readonly IReportLogic _reportLogic; + private IWorkProcess _workProcess; + public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic) { InitializeComponent(); @@ -35,6 +36,8 @@ namespace FishFactory.Forms dataGridView.Columns["CannedName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; dataGridView.Columns["ClientId"].Visible = false; dataGridView.Columns["ClientFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["ImplementerId"].Visible = false; + dataGridView.Columns["ImplementerFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; } _logger.LogInformation("Загрузка заказов"); @@ -70,6 +73,16 @@ namespace FishFactory.Forms form.ShowDialog(); } } + + private void исполнителиToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormImplementers)); + + if (service is FormImplementers form) + { + form.ShowDialog(); + } + } private void buttonCreateOrder_Click(object sender, EventArgs e) { @@ -80,54 +93,7 @@ namespace FishFactory.Forms LoadData(); } } - private void buttonTakeOrderInWork_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id); - try - { - var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel - { - Id = id, - }); - if (!operationResult) - { - throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); - } - LoadData(); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка передачи заказа в работу"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - } - private void buttonOrderReady_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - int id = - Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", id); - try - { - var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id }); - if (!operationResult) - { - throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); - } - LoadData(); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка отметки о готовности заказа"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - } + private void buttonIssuedOrder_Click(object sender, EventArgs e) { if (dataGridView.SelectedRows.Count == 1) @@ -190,5 +156,11 @@ namespace FishFactory.Forms form.ShowDialog(); } } + + private void ЗапускРаботToolStripLabel_Click(object sender, EventArgs e) + { + _workProcess.DoWork((Program.ServiceProvider?.GetService(typeof(IImplementerLogic)) as IImplementerLogic)!, _orderLogic); + MessageBox.Show("Процесс обработки запущен", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + } } } diff --git a/FishFactory/Program.cs b/FishFactory/Program.cs index d58bbb4..96100d9 100644 --- a/FishFactory/Program.cs +++ b/FishFactory/Program.cs @@ -41,12 +41,15 @@ namespace FishFactory services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); - services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -56,9 +59,12 @@ namespace FishFactory services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); diff --git a/FishFactoryBusinessLogic/BusinessLogic/ImplementerLogic.cs b/FishFactoryBusinessLogic/BusinessLogic/ImplementerLogic.cs index 618d327..4b820d4 100644 --- a/FishFactoryBusinessLogic/BusinessLogic/ImplementerLogic.cs +++ b/FishFactoryBusinessLogic/BusinessLogic/ImplementerLogic.cs @@ -7,7 +7,7 @@ using Microsoft.Extensions.Logging; namespace FishFactoryBusinessLogic.BusinessLogic { - public class ImplementerLogic : IImplementerBusinessLogic + public class ImplementerLogic : IImplementerLogic { private readonly ILogger _logger; private readonly IImplementerStorage _implementerStorage; diff --git a/FishFactoryBusinessLogic/BusinessLogic/OrderLogic.cs b/FishFactoryBusinessLogic/BusinessLogic/OrderLogic.cs index 9ea6392..11a0cae 100644 --- a/FishFactoryBusinessLogic/BusinessLogic/OrderLogic.cs +++ b/FishFactoryBusinessLogic/BusinessLogic/OrderLogic.cs @@ -5,20 +5,11 @@ using FishFactoryContracts.StoragesContracts; using FishFactoryContracts.ViewModels; using FishFactoryDataModel.Enums; using Microsoft.Extensions.Logging; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace FishFactoryBusinessLogic.BusinessLogic { public class OrderLogic : IOrderLogic { - //Класс с логикой для заказов будет отвечать за получение списка заказов, - //создания заказа и смены его статусов. Следует учитывать, что у заказа можно - //менять статус на новый, если его текущий статус предшествует новому - private readonly ILogger _logger; private readonly IOrderStorage _orderStorage; @@ -41,6 +32,24 @@ namespace FishFactoryBusinessLogic.BusinessLogic return list; } + public OrderViewModel? ReadElement(OrderSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + _logger.LogInformation("ReadElement. ClientId:{ClientId}.Status:{Status}.ImplementerId:{ImplementerId}.DateFrom:{DateFrom}.DateTo:{DateTo}OrderId:{Id}", model.ClientId, model.Status, model.ImplementerId, model.DateFrom, model.DateTo, 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; + } + public bool CreateOrder(OrderBindingModel model) { CheckModel(model); @@ -86,11 +95,16 @@ namespace FishFactoryBusinessLogic.BusinessLogic } model.CannedId = element.CannedId; + model.ClientId = element.ClientId; model.DateCreate = element.DateCreate; model.DateImplement = element.DateImplement; model.Status = element.Status; model.Count = element.Count; model.Sum = element.Sum; + if (!model.ImplementerId.HasValue) + { + model.ImplementerId = element.ImplementerId; + } if (model.Status != orderStatus - 1) { diff --git a/FishFactoryBusinessLogic/BusinessLogic/WorkModeling.cs b/FishFactoryBusinessLogic/BusinessLogic/WorkModeling.cs new file mode 100644 index 0000000..73eada3 --- /dev/null +++ b/FishFactoryBusinessLogic/BusinessLogic/WorkModeling.cs @@ -0,0 +1,141 @@ +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.BusinessLogicsContracts; +using FishFactoryContracts.SearchModels; +using FishFactoryContracts.ViewModels; +using FishFactoryDataModel.Enums; +using Microsoft.Extensions.Logging; + +namespace FishFactoryBusinessLogic.BusinessLogic +{ + public class WorkModeling : IWorkProcess + { + private readonly ILogger _logger; + + private readonly Random _rnd; + + private IOrderLogic? _orderLogic; + + public WorkModeling(ILogger 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 { Status = OrderStatus.Принят }); + var processingOrders = _orderLogic.ReadList(new OrderSearchModel { Status = OrderStatus.Выполняется }); + + if (orders == null || processingOrders == null || (orders.Count == 0 && processingOrders.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)); + } + } + + private async Task WorkerWorkAsync(ImplementerViewModel implementer, List 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); + // пытаемся назначить заказ на исполнителя + bool result = _orderLogic.TakeOrderInWork(new OrderBindingModel + { + Id = order.Id, + ImplementerId = implementer.Id + }); + if (!result) + { + _logger.LogDebug("WorkerWorkAsync. Worker {Id} tried to get order {Order} but it's already acquired by other worker", implementer.Id, order.Id); + continue; + } + // делаем работу + 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 + }); + } + // кто-то мог уже перехватить заказ, игнорируем ошибку + catch (InvalidOperationException ex) + { + _logger.LogWarning(ex, "Error try get work"); + } + // заканчиваем выполнение имитации в случае иной ошибки + catch (Exception ex) + { + _logger.LogError(ex, "Error while do work"); + throw; + } + // отдыхаем + Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100)); + } + }); + } + + 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, + Status = 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; + } + } + } +} diff --git a/FishFactoryContracts/BindingModels/OrderBindingModel.cs b/FishFactoryContracts/BindingModels/OrderBindingModel.cs index f74e8d3..9ea611f 100644 --- a/FishFactoryContracts/BindingModels/OrderBindingModel.cs +++ b/FishFactoryContracts/BindingModels/OrderBindingModel.cs @@ -8,7 +8,7 @@ namespace FishFactoryContracts.BindingModels public int Id { get; set; } public int CannedId { get; set; } public int ClientId { get; set; } - public int ImplementerId { get; } + public int? ImplementerId { get; set; } public int Count { get; set; } public double Sum { get; set; } public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; diff --git a/FishFactoryContracts/BusinessLogicsContracts/IImplementerBusinessLogic.cs b/FishFactoryContracts/BusinessLogicsContracts/IImplementerLogic.cs similarity index 91% rename from FishFactoryContracts/BusinessLogicsContracts/IImplementerBusinessLogic.cs rename to FishFactoryContracts/BusinessLogicsContracts/IImplementerLogic.cs index ccb10eb..29bad48 100644 --- a/FishFactoryContracts/BusinessLogicsContracts/IImplementerBusinessLogic.cs +++ b/FishFactoryContracts/BusinessLogicsContracts/IImplementerLogic.cs @@ -4,7 +4,7 @@ using FishFactoryContracts.ViewModels; namespace FishFactoryContracts.BusinessLogicsContracts { - public interface IImplementerBusinessLogic + public interface IImplementerLogic { List? ReadList(ImplementerSearchModel? model); ImplementerViewModel? ReadElement(ImplementerSearchModel model); diff --git a/FishFactoryContracts/BusinessLogicsContracts/IOrderLogic.cs b/FishFactoryContracts/BusinessLogicsContracts/IOrderLogic.cs index 958cdc8..c25ffb3 100644 --- a/FishFactoryContracts/BusinessLogicsContracts/IOrderLogic.cs +++ b/FishFactoryContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -12,6 +12,7 @@ namespace FishFactoryContracts.BusinessLogicsContracts public interface IOrderLogic { List? ReadList(OrderSearchModel? model); + OrderViewModel? ReadElement(OrderSearchModel model); bool CreateOrder(OrderBindingModel model); bool TakeOrderInWork(OrderBindingModel model); /// diff --git a/FishFactoryContracts/BusinessLogicsContracts/IWorkProcess.cs b/FishFactoryContracts/BusinessLogicsContracts/IWorkProcess.cs new file mode 100644 index 0000000..02501b8 --- /dev/null +++ b/FishFactoryContracts/BusinessLogicsContracts/IWorkProcess.cs @@ -0,0 +1,7 @@ +namespace FishFactoryContracts.BusinessLogicsContracts +{ + public interface IWorkProcess + { + void DoWork(IImplementerLogic implementerLogic, IOrderLogic orderLogic); + } +} diff --git a/FishFactoryContracts/SearchModels/OrderSearchModel.cs b/FishFactoryContracts/SearchModels/OrderSearchModel.cs index aea6adc..38b825e 100644 --- a/FishFactoryContracts/SearchModels/OrderSearchModel.cs +++ b/FishFactoryContracts/SearchModels/OrderSearchModel.cs @@ -1,10 +1,14 @@ -namespace FishFactoryContracts.SearchModels +using FishFactoryDataModel.Enums; + +namespace FishFactoryContracts.SearchModels { public class OrderSearchModel { public int? Id { get; set; } public int? ClientId { get; set; } + public int? ImplementerId { get; set; } public DateTime? DateFrom { get; set; } public DateTime? DateTo { get; set; } + public OrderStatus? Status { get; set; } } } diff --git a/FishFactoryContracts/ViewModels/OrderViewModel.cs b/FishFactoryContracts/ViewModels/OrderViewModel.cs index 03c9099..cfe31f5 100644 --- a/FishFactoryContracts/ViewModels/OrderViewModel.cs +++ b/FishFactoryContracts/ViewModels/OrderViewModel.cs @@ -15,9 +15,9 @@ namespace FishFactoryContracts.ViewModels public int ClientId { get; set; } [DisplayName("Клиент")] public string ClientFIO { get; set; } = string.Empty; - public int ImplementerId { get; set; } + public int? ImplementerId { get; set; } [DisplayName("Исполнитель")] - public string ImplementerFIO { get; set; } = string.Empty; + public string? ImplementerFIO { get; set; } = string.Empty; public int CannedId { get; set; } [DisplayName("Изделие")] public string CannedName { get; set; } = string.Empty; diff --git a/FishFactoryDataModels/Models/IOrderModel.cs b/FishFactoryDataModels/Models/IOrderModel.cs index d95bdff..67efaac 100644 --- a/FishFactoryDataModels/Models/IOrderModel.cs +++ b/FishFactoryDataModels/Models/IOrderModel.cs @@ -6,7 +6,7 @@ namespace FishFactoryDataModel.Models { int CannedId { get; } int ClientId { get; } - int ImplementerId { get; } + int? ImplementerId { get; } int Count { get; } double Sum { get; } OrderStatus Status { get; } diff --git a/FishFactoryDatabaseImplement/FishFactoryDatabase.cs b/FishFactoryDatabaseImplement/FishFactoryDatabase.cs index 359e212..48b39f5 100644 --- a/FishFactoryDatabaseImplement/FishFactoryDatabase.cs +++ b/FishFactoryDatabaseImplement/FishFactoryDatabase.cs @@ -9,7 +9,7 @@ namespace FishFactoryDatabaseImplement { if (optionsBuilder.IsConfigured == false) { - optionsBuilder.UseNpgsql(@"Host=localhost;Database=FishFactory2;Username=postgres;Password=postgres"); + optionsBuilder.UseNpgsql(@"Host=localhost;Database=FishFactory3;Username=postgres;Password=postgres"); } base.OnConfiguring(optionsBuilder); AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true); diff --git a/FishFactoryDatabaseImplement/Implements/ImplementerStorage.cs b/FishFactoryDatabaseImplement/Implements/ImplementerStorage.cs index 285dac7..3c8d2af 100644 --- a/FishFactoryDatabaseImplement/Implements/ImplementerStorage.cs +++ b/FishFactoryDatabaseImplement/Implements/ImplementerStorage.cs @@ -32,7 +32,8 @@ namespace FishFactoryDatabaseImplement.Implements } using var context = new FishFactoryDatabase(); return context.Implementers.FirstOrDefault(x => - (!string.IsNullOrEmpty(model.ImplementerFIO) && x.ImplementerFIO == model.ImplementerFIO && (!string.IsNullOrEmpty(model.Password) ? x.Password == model.Password : true)) || + (!string.IsNullOrEmpty(model.ImplementerFIO) && x.ImplementerFIO == model.ImplementerFIO && + (!string.IsNullOrEmpty(model.Password) && x.Password == model.Password)) || (model.Id.HasValue && x.Id == model.Id)) ?.GetViewModel; } diff --git a/FishFactoryDatabaseImplement/Implements/OrderStorage.cs b/FishFactoryDatabaseImplement/Implements/OrderStorage.cs index dec4a6a..40ca72a 100644 --- a/FishFactoryDatabaseImplement/Implements/OrderStorage.cs +++ b/FishFactoryDatabaseImplement/Implements/OrderStorage.cs @@ -30,9 +30,11 @@ namespace FishFactoryDatabaseImplement.Implements (!model.Id.HasValue || x.Id == model.Id) && (!model.DateFrom.HasValue || x.DateCreate >= model.DateFrom) && (!model.DateTo.HasValue || x.DateCreate <= model.DateTo) && - (!model.ClientId.HasValue || x.ClientId == model.ClientId)) + (!model.ClientId.HasValue || x.ClientId == model.ClientId) && + (!model.Status.HasValue || x.Status == model.Status)) .Select(x => x.GetViewModel) .ToList(); + } public OrderViewModel? GetElement(OrderSearchModel model) { @@ -45,7 +47,12 @@ namespace FishFactoryDatabaseImplement.Implements .Include(x => x.Canned) .Include(x => x.Client) .Include(x => x.Implementer) - .FirstOrDefault(x => x.Id == model.Id) + .FirstOrDefault(x => + (!model.Id.HasValue || x.Id == model.Id) && + (!model.DateFrom.HasValue || x.DateCreate >= model.DateFrom) && + (!model.DateTo.HasValue || x.DateCreate <= model.DateTo) && + (!model.ClientId.HasValue || x.ClientId == model.ClientId) && + (!model.Status.HasValue || x.Status == model.Status)) ?.GetViewModel; } public OrderViewModel? Insert(OrderBindingModel model) @@ -69,10 +76,10 @@ namespace FishFactoryDatabaseImplement.Implements try { var order = context.Orders - .Include(o => o.Canned) - .Include(o => o.Client) + .Include(x => x.Canned) + .Include(x => x.Client) .Include(x => x.Implementer) - .FirstOrDefault(o => o.Id == model.Id); + .FirstOrDefault(x => x.Id == model.Id); if (order == null) { return null; @@ -92,10 +99,10 @@ namespace FishFactoryDatabaseImplement.Implements { using var context = new FishFactoryDatabase(); var element = context.Orders - .Include(o => o.Canned) - .Include(o => o.Client) + .Include(x => x.Canned) + .Include(x => x.Client) .Include(x => x.Implementer) - .FirstOrDefault(o => o.Id == model.Id); + .FirstOrDefault(x => x.Id == model.Id); if (element != null) { context.Orders.Remove(element); diff --git a/FishFactoryDatabaseImplement/Migrations/20240513132159_initialcreate.Designer.cs b/FishFactoryDatabaseImplement/Migrations/20240513132159_initialcreate.Designer.cs new file mode 100644 index 0000000..28f45e9 --- /dev/null +++ b/FishFactoryDatabaseImplement/Migrations/20240513132159_initialcreate.Designer.cs @@ -0,0 +1,255 @@ +// +using System; +using FishFactoryDatabaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace FishFactoryDatabaseImplement.Migrations +{ + [DbContext(typeof(FishFactoryDatabase))] + [Migration("20240513132159_initialcreate")] + partial class initialcreate + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.16") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Canned", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CannedName") + .IsRequired() + .HasColumnType("text"); + + b.Property("Price") + .HasColumnType("double precision"); + + b.HasKey("Id"); + + b.ToTable("Canneds"); + }); + + modelBuilder.Entity("FishFactoryDatabaseImplement.Models.CannedComponent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CannedId") + .HasColumnType("integer"); + + b.Property("ComponentId") + .HasColumnType("integer"); + + b.Property("Count") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("CannedId"); + + b.HasIndex("ComponentId"); + + b.ToTable("CannedComponents"); + }); + + modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Client", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ClientFIO") + .IsRequired() + .HasColumnType("text"); + + b.Property("Email") + .IsRequired() + .HasColumnType("text"); + + b.Property("Password") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Clients"); + }); + + modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Component", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ComponentName") + .IsRequired() + .HasColumnType("text"); + + b.Property("Cost") + .HasColumnType("double precision"); + + b.HasKey("Id"); + + b.ToTable("Components"); + }); + + modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Implementer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ImplementerFIO") + .IsRequired() + .HasColumnType("text"); + + b.Property("Password") + .IsRequired() + .HasColumnType("text"); + + b.Property("Qualification") + .HasColumnType("integer"); + + b.Property("WorkExperience") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("Implementers"); + }); + + modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CannedId") + .HasColumnType("integer"); + + b.Property("ClientId") + .HasColumnType("integer"); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("DateCreate") + .HasColumnType("timestamp without time zone"); + + b.Property("DateImplement") + .HasColumnType("timestamp without time zone"); + + b.Property("ImplementerId") + .IsRequired() + .HasColumnType("integer"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("Sum") + .HasColumnType("double precision"); + + b.HasKey("Id"); + + b.HasIndex("CannedId"); + + b.HasIndex("ClientId"); + + b.HasIndex("ImplementerId"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("FishFactoryDatabaseImplement.Models.CannedComponent", b => + { + b.HasOne("FishFactoryDatabaseImplement.Models.Canned", "Canned") + .WithMany("Components") + .HasForeignKey("CannedId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("FishFactoryDatabaseImplement.Models.Component", "Component") + .WithMany("CannedComponents") + .HasForeignKey("ComponentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Canned"); + + b.Navigation("Component"); + }); + + modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Order", b => + { + b.HasOne("FishFactoryDatabaseImplement.Models.Canned", "Canned") + .WithMany("Orders") + .HasForeignKey("CannedId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("FishFactoryDatabaseImplement.Models.Client", "Client") + .WithMany() + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("FishFactoryDatabaseImplement.Models.Implementer", "Implementer") + .WithMany("Order") + .HasForeignKey("ImplementerId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Canned"); + + b.Navigation("Client"); + + b.Navigation("Implementer"); + }); + + modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Canned", b => + { + b.Navigation("Components"); + + b.Navigation("Orders"); + }); + + modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Component", b => + { + b.Navigation("CannedComponents"); + }); + + modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Implementer", b => + { + b.Navigation("Order"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/FishFactoryDatabaseImplement/Migrations/20240509142302_initialdatabase.cs b/FishFactoryDatabaseImplement/Migrations/20240513132159_initialcreate.cs similarity index 81% rename from FishFactoryDatabaseImplement/Migrations/20240509142302_initialdatabase.cs rename to FishFactoryDatabaseImplement/Migrations/20240513132159_initialcreate.cs index 6fb7665..7dd70b9 100644 --- a/FishFactoryDatabaseImplement/Migrations/20240509142302_initialdatabase.cs +++ b/FishFactoryDatabaseImplement/Migrations/20240513132159_initialcreate.cs @@ -7,7 +7,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; namespace FishFactoryDatabaseImplement.Migrations { /// - public partial class initialdatabase : Migration + public partial class initialcreate : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) @@ -56,34 +56,19 @@ namespace FishFactoryDatabaseImplement.Migrations }); migrationBuilder.CreateTable( - name: "Orders", + name: "Implementers", columns: table => new { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - CannedId = table.Column(type: "integer", nullable: false), - ClientId = table.Column(type: "integer", nullable: false), - Count = table.Column(type: "integer", nullable: false), - Sum = table.Column(type: "double precision", nullable: false), - Status = table.Column(type: "integer", nullable: false), - DateCreate = table.Column(type: "timestamp without time zone", nullable: false), - DateImplement = table.Column(type: "timestamp without time zone", nullable: true) + ImplementerFIO = table.Column(type: "text", nullable: false), + Password = table.Column(type: "text", nullable: false), + WorkExperience = table.Column(type: "integer", nullable: false), + Qualification = table.Column(type: "integer", nullable: false) }, constraints: table => { - table.PrimaryKey("PK_Orders", x => x.Id); - table.ForeignKey( - name: "FK_Orders_Canneds_CannedId", - column: x => x.CannedId, - principalTable: "Canneds", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_Orders_Clients_ClientId", - column: x => x.ClientId, - principalTable: "Clients", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); + table.PrimaryKey("PK_Implementers", x => x.Id); }); migrationBuilder.CreateTable( @@ -113,6 +98,44 @@ namespace FishFactoryDatabaseImplement.Migrations onDelete: ReferentialAction.Cascade); }); + migrationBuilder.CreateTable( + name: "Orders", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + CannedId = table.Column(type: "integer", nullable: false), + ClientId = table.Column(type: "integer", nullable: false), + ImplementerId = table.Column(type: "integer", nullable: false), + Count = table.Column(type: "integer", nullable: false), + Sum = table.Column(type: "double precision", nullable: false), + Status = table.Column(type: "integer", nullable: false), + DateCreate = table.Column(type: "timestamp without time zone", nullable: false), + DateImplement = table.Column(type: "timestamp without time zone", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Orders", x => x.Id); + table.ForeignKey( + name: "FK_Orders_Canneds_CannedId", + column: x => x.CannedId, + principalTable: "Canneds", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Orders_Clients_ClientId", + column: x => x.ClientId, + principalTable: "Clients", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Orders_Implementers_ImplementerId", + column: x => x.ImplementerId, + principalTable: "Implementers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + migrationBuilder.CreateIndex( name: "IX_CannedComponents_CannedId", table: "CannedComponents", @@ -132,6 +155,11 @@ namespace FishFactoryDatabaseImplement.Migrations name: "IX_Orders_ClientId", table: "Orders", column: "ClientId"); + + migrationBuilder.CreateIndex( + name: "IX_Orders_ImplementerId", + table: "Orders", + column: "ImplementerId"); } /// @@ -151,6 +179,9 @@ namespace FishFactoryDatabaseImplement.Migrations migrationBuilder.DropTable( name: "Clients"); + + migrationBuilder.DropTable( + name: "Implementers"); } } } diff --git a/FishFactoryDatabaseImplement/Migrations/20240513152048_add_implementer.Designer.cs b/FishFactoryDatabaseImplement/Migrations/20240513152048_add_implementer.Designer.cs new file mode 100644 index 0000000..047d932 --- /dev/null +++ b/FishFactoryDatabaseImplement/Migrations/20240513152048_add_implementer.Designer.cs @@ -0,0 +1,255 @@ +// +using System; +using FishFactoryDatabaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace FishFactoryDatabaseImplement.Migrations +{ + [DbContext(typeof(FishFactoryDatabase))] + [Migration("20240513152048_add_implementer")] + partial class add_implementer + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.16") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Canned", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CannedName") + .IsRequired() + .HasColumnType("text"); + + b.Property("Price") + .HasColumnType("double precision"); + + b.HasKey("Id"); + + b.ToTable("Canneds"); + }); + + modelBuilder.Entity("FishFactoryDatabaseImplement.Models.CannedComponent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CannedId") + .HasColumnType("integer"); + + b.Property("ComponentId") + .HasColumnType("integer"); + + b.Property("Count") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("CannedId"); + + b.HasIndex("ComponentId"); + + b.ToTable("CannedComponents"); + }); + + modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Client", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ClientFIO") + .IsRequired() + .HasColumnType("text"); + + b.Property("Email") + .IsRequired() + .HasColumnType("text"); + + b.Property("Password") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Clients"); + }); + + modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Component", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ComponentName") + .IsRequired() + .HasColumnType("text"); + + b.Property("Cost") + .HasColumnType("double precision"); + + b.HasKey("Id"); + + b.ToTable("Components"); + }); + + modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Implementer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ImplementerFIO") + .IsRequired() + .HasColumnType("text"); + + b.Property("Password") + .IsRequired() + .HasColumnType("text"); + + b.Property("Qualification") + .HasColumnType("integer"); + + b.Property("WorkExperience") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("Implementers"); + }); + + modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CannedId") + .HasColumnType("integer"); + + b.Property("ClientId") + .HasColumnType("integer"); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("DateCreate") + .HasColumnType("timestamp without time zone"); + + b.Property("DateImplement") + .HasColumnType("timestamp without time zone"); + + b.Property("ImplementerId") + .IsRequired() + .HasColumnType("integer"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("Sum") + .HasColumnType("double precision"); + + b.HasKey("Id"); + + b.HasIndex("CannedId"); + + b.HasIndex("ClientId"); + + b.HasIndex("ImplementerId"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("FishFactoryDatabaseImplement.Models.CannedComponent", b => + { + b.HasOne("FishFactoryDatabaseImplement.Models.Canned", "Canned") + .WithMany("Components") + .HasForeignKey("CannedId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("FishFactoryDatabaseImplement.Models.Component", "Component") + .WithMany("CannedComponents") + .HasForeignKey("ComponentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Canned"); + + b.Navigation("Component"); + }); + + modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Order", b => + { + b.HasOne("FishFactoryDatabaseImplement.Models.Canned", "Canned") + .WithMany("Orders") + .HasForeignKey("CannedId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("FishFactoryDatabaseImplement.Models.Client", "Client") + .WithMany() + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("FishFactoryDatabaseImplement.Models.Implementer", "Implementer") + .WithMany("Order") + .HasForeignKey("ImplementerId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Canned"); + + b.Navigation("Client"); + + b.Navigation("Implementer"); + }); + + modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Canned", b => + { + b.Navigation("Components"); + + b.Navigation("Orders"); + }); + + modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Component", b => + { + b.Navigation("CannedComponents"); + }); + + modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Implementer", b => + { + b.Navigation("Order"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/FishFactoryDatabaseImplement/Migrations/20240513152048_add_implementer.cs b/FishFactoryDatabaseImplement/Migrations/20240513152048_add_implementer.cs new file mode 100644 index 0000000..0077077 --- /dev/null +++ b/FishFactoryDatabaseImplement/Migrations/20240513152048_add_implementer.cs @@ -0,0 +1,22 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace FishFactoryDatabaseImplement.Migrations +{ + /// + public partial class add_implementer : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + + } + } +} diff --git a/FishFactoryDatabaseImplement/Migrations/20240509142302_initialdatabase.Designer.cs b/FishFactoryDatabaseImplement/Migrations/20240513170412_create.Designer.cs similarity index 82% rename from FishFactoryDatabaseImplement/Migrations/20240509142302_initialdatabase.Designer.cs rename to FishFactoryDatabaseImplement/Migrations/20240513170412_create.Designer.cs index eff9cb5..982acdf 100644 --- a/FishFactoryDatabaseImplement/Migrations/20240509142302_initialdatabase.Designer.cs +++ b/FishFactoryDatabaseImplement/Migrations/20240513170412_create.Designer.cs @@ -12,8 +12,8 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; namespace FishFactoryDatabaseImplement.Migrations { [DbContext(typeof(FishFactoryDatabase))] - [Migration("20240509142302_initialdatabase")] - partial class initialdatabase + [Migration("20240513170412_create")] + partial class create { /// protected override void BuildTargetModel(ModelBuilder modelBuilder) @@ -116,6 +116,33 @@ namespace FishFactoryDatabaseImplement.Migrations b.ToTable("Components"); }); + modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Implementer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ImplementerFIO") + .IsRequired() + .HasColumnType("text"); + + b.Property("Password") + .IsRequired() + .HasColumnType("text"); + + b.Property("Qualification") + .HasColumnType("integer"); + + b.Property("WorkExperience") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("Implementers"); + }); + modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Order", b => { b.Property("Id") @@ -139,6 +166,9 @@ namespace FishFactoryDatabaseImplement.Migrations b.Property("DateImplement") .HasColumnType("timestamp without time zone"); + b.Property("ImplementerId") + .HasColumnType("integer"); + b.Property("Status") .HasColumnType("integer"); @@ -151,6 +181,8 @@ namespace FishFactoryDatabaseImplement.Migrations b.HasIndex("ClientId"); + b.HasIndex("ImplementerId"); + b.ToTable("Orders"); }); @@ -187,9 +219,15 @@ namespace FishFactoryDatabaseImplement.Migrations .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + b.HasOne("FishFactoryDatabaseImplement.Models.Implementer", "Implementer") + .WithMany("Order") + .HasForeignKey("ImplementerId"); + b.Navigation("Canned"); b.Navigation("Client"); + + b.Navigation("Implementer"); }); modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Canned", b => @@ -203,6 +241,11 @@ namespace FishFactoryDatabaseImplement.Migrations { b.Navigation("CannedComponents"); }); + + modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Implementer", b => + { + b.Navigation("Order"); + }); #pragma warning restore 612, 618 } } diff --git a/FishFactoryDatabaseImplement/Migrations/20240513170412_create.cs b/FishFactoryDatabaseImplement/Migrations/20240513170412_create.cs new file mode 100644 index 0000000..c4820f4 --- /dev/null +++ b/FishFactoryDatabaseImplement/Migrations/20240513170412_create.cs @@ -0,0 +1,59 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace FishFactoryDatabaseImplement.Migrations +{ + /// + public partial class create : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Orders_Implementers_ImplementerId", + table: "Orders"); + + migrationBuilder.AlterColumn( + name: "ImplementerId", + table: "Orders", + type: "integer", + nullable: true, + oldClrType: typeof(int), + oldType: "integer"); + + migrationBuilder.AddForeignKey( + name: "FK_Orders_Implementers_ImplementerId", + table: "Orders", + column: "ImplementerId", + principalTable: "Implementers", + principalColumn: "Id"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Orders_Implementers_ImplementerId", + table: "Orders"); + + migrationBuilder.AlterColumn( + name: "ImplementerId", + table: "Orders", + type: "integer", + nullable: false, + defaultValue: 0, + oldClrType: typeof(int), + oldType: "integer", + oldNullable: true); + + migrationBuilder.AddForeignKey( + name: "FK_Orders_Implementers_ImplementerId", + table: "Orders", + column: "ImplementerId", + principalTable: "Implementers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + } + } +} diff --git a/FishFactoryDatabaseImplement/Migrations/FishFactoryDatabaseModelSnapshot.cs b/FishFactoryDatabaseImplement/Migrations/FishFactoryDatabaseModelSnapshot.cs index 65babc2..06bf944 100644 --- a/FishFactoryDatabaseImplement/Migrations/FishFactoryDatabaseModelSnapshot.cs +++ b/FishFactoryDatabaseImplement/Migrations/FishFactoryDatabaseModelSnapshot.cs @@ -113,6 +113,33 @@ namespace FishFactoryDatabaseImplement.Migrations b.ToTable("Components"); }); + modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Implementer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ImplementerFIO") + .IsRequired() + .HasColumnType("text"); + + b.Property("Password") + .IsRequired() + .HasColumnType("text"); + + b.Property("Qualification") + .HasColumnType("integer"); + + b.Property("WorkExperience") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("Implementers"); + }); + modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Order", b => { b.Property("Id") @@ -136,6 +163,9 @@ namespace FishFactoryDatabaseImplement.Migrations b.Property("DateImplement") .HasColumnType("timestamp without time zone"); + b.Property("ImplementerId") + .HasColumnType("integer"); + b.Property("Status") .HasColumnType("integer"); @@ -148,6 +178,8 @@ namespace FishFactoryDatabaseImplement.Migrations b.HasIndex("ClientId"); + b.HasIndex("ImplementerId"); + b.ToTable("Orders"); }); @@ -184,9 +216,15 @@ namespace FishFactoryDatabaseImplement.Migrations .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + b.HasOne("FishFactoryDatabaseImplement.Models.Implementer", "Implementer") + .WithMany("Order") + .HasForeignKey("ImplementerId"); + b.Navigation("Canned"); b.Navigation("Client"); + + b.Navigation("Implementer"); }); modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Canned", b => @@ -200,6 +238,11 @@ namespace FishFactoryDatabaseImplement.Migrations { b.Navigation("CannedComponents"); }); + + modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Implementer", b => + { + b.Navigation("Order"); + }); #pragma warning restore 612, 618 } } diff --git a/FishFactoryDatabaseImplement/Models/Implementer.cs b/FishFactoryDatabaseImplement/Models/Implementer.cs index 55dde5e..efd595b 100644 --- a/FishFactoryDatabaseImplement/Models/Implementer.cs +++ b/FishFactoryDatabaseImplement/Models/Implementer.cs @@ -53,7 +53,7 @@ namespace FishFactoryDatabaseImplement.Models ImplementerFIO = ImplementerFIO, Password = Password, Qualification = Qualification, - ImplementerFIO = ImplementerFIO, + WorkExperience = WorkExperience, }; } } diff --git a/FishFactoryDatabaseImplement/Models/Order.cs b/FishFactoryDatabaseImplement/Models/Order.cs index 495aefe..6dd1c23 100644 --- a/FishFactoryDatabaseImplement/Models/Order.cs +++ b/FishFactoryDatabaseImplement/Models/Order.cs @@ -1,5 +1,4 @@ -using System.ComponentModel.DataAnnotations.Schema; -using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations; using FishFactoryDataModel.Enums; using FishFactoryContracts.BindingModels; using FishFactoryContracts.ViewModels; @@ -12,15 +11,14 @@ namespace FishFactoryDatabaseImplement.Models public int Id { get; private set; } [Required] public int CannedId { get; private set; } - public virtual Canned Canned { get; set; } = new(); + public virtual Canned Canned { get; set; } [Required] public int ClientId { get; private set; } - public virtual Client Client { get; set; } = new(); + public virtual Client Client { get; set; } - [Required] - public int ImplementerId { get; private set; } - public virtual Implementer Implementer { get; set; } = new(); + public int? ImplementerId { get; private set; } + public virtual Implementer? Implementer { get; set; } = new(); [Required] public int Count { get; private set; } @@ -41,7 +39,7 @@ namespace FishFactoryDatabaseImplement.Models ClientId = model.ClientId, Client = context.Clients.First(x => x.Id == model.ClientId), ImplementerId = model.ImplementerId, - Implementer = context.Implementers.First(x => x.Id == model.ImplementerId), + Implementer = model.ImplementerId.HasValue ? context.Implementers.First(x => x.Id == model.ImplementerId) : null, Count = model.Count, Sum = model.Sum, Status = model.Status, @@ -55,10 +53,13 @@ namespace FishFactoryDatabaseImplement.Models { return; } + using var context = new FishFactoryDatabase(); + Id = model.Id; CannedId = model.CannedId; ClientId = model.ClientId; ImplementerId = model.ImplementerId; + Implementer = model.ImplementerId.HasValue ? context.Implementers.First(x => x.Id == model.ImplementerId) : null; Sum = model.Sum; Status = model.Status; DateCreate = model.DateCreate; @@ -72,7 +73,7 @@ namespace FishFactoryDatabaseImplement.Models ClientId = ClientId, ClientFIO = Client.ClientFIO, ImplementerId = ImplementerId, - ImplementerFIO = Implementer.ImplementerFIO, + ImplementerFIO = Implementer?.ImplementerFIO, Count = Count, Sum = Sum, Status = Status, diff --git a/FishFactoryFileImplement/Models/Implementer.cs b/FishFactoryFileImplement/Models/Implementer.cs index 9469378..99afe6d 100644 --- a/FishFactoryFileImplement/Models/Implementer.cs +++ b/FishFactoryFileImplement/Models/Implementer.cs @@ -1,6 +1,7 @@ using FishFactoryContracts.BindingModels; using FishFactoryContracts.ViewModels; using FishFactoryDataModel.Models; +using System.Reflection; using System.Xml.Linq; namespace FishFactoryFileImplement.Models @@ -17,6 +18,22 @@ namespace FishFactoryFileImplement.Models public int Qualification { get; private set; } + public static Implementer? Create(XElement element) + { + if (element == null) + { + return null; + } + return new() + { + ImplementerFIO = element.Element("FIO")!.Value, + Password = element.Element("Password")!.Value, + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + Qualification = Convert.ToInt32(element.Element("Qualification")!.Value), + WorkExperience = Convert.ToInt32(element.Element("WorkExperience")!.Value), + }; + } + public static Implementer? Create(ImplementerBindingModel model) { if (model == null) @@ -51,7 +68,7 @@ namespace FishFactoryFileImplement.Models Password = Password, ImplementerFIO = ImplementerFIO, Qualification = Qualification, - ImplementerFIO = ImplementerFIO, + WorkExperience = WorkExperience }; public XElement GetXElement => new("Implementer", diff --git a/FishFactoryFileImplement/Models/Order.cs b/FishFactoryFileImplement/Models/Order.cs index e7aa048..f308eea 100644 --- a/FishFactoryFileImplement/Models/Order.cs +++ b/FishFactoryFileImplement/Models/Order.cs @@ -11,7 +11,7 @@ namespace FishFactoryFileImplement.Models public int Id { get; private set; } public int CannedId { get; private set; } public int ClientId { get; private set; } - public int ImplementerId { get; set; } + public int? ImplementerId { get; set; } public int Count { get; private set; } public double Sum { get; private set; } public OrderStatus Status { get; private set; } diff --git a/FishFactoryListImplement/Models/Implementer.cs b/FishFactoryListImplement/Models/Implementer.cs index 4530cce..951eb1e 100644 --- a/FishFactoryListImplement/Models/Implementer.cs +++ b/FishFactoryListImplement/Models/Implementer.cs @@ -1,6 +1,7 @@ using FishFactoryContracts.BindingModels; using FishFactoryContracts.ViewModels; using FishFactoryDataModel.Models; +using System.Reflection; namespace FishFactoryListImplement.Models { @@ -50,7 +51,7 @@ namespace FishFactoryListImplement.Models Password = Password, ImplementerFIO = ImplementerFIO, Qualification = Qualification, - ImplementerFIO = ImplementerFIO, + WorkExperience = WorkExperience }; } } diff --git a/FishFactoryListImplement/Models/Order.cs b/FishFactoryListImplement/Models/Order.cs index 6b31f26..e1bf253 100644 --- a/FishFactoryListImplement/Models/Order.cs +++ b/FishFactoryListImplement/Models/Order.cs @@ -2,7 +2,6 @@ using FishFactoryContracts.ViewModels; using FishFactoryDataModel.Enums; using FishFactoryDataModel.Models; -using System.Reflection; namespace FishFactoryListImplement.Models { @@ -55,7 +54,7 @@ namespace FishFactoryListImplement.Models Id = Id, CannedId = CannedId, ClientId = ClientId, - ImplementerId = model.ImplementerId, + ImplementerId = ImplementerId, Count = Count, Sum = Sum, Status = Status, diff --git a/FishFactoryRestApi/Controllers/ImplementerController.cs b/FishFactoryRestApi/Controllers/ImplementerController.cs new file mode 100644 index 0000000..2a20029 --- /dev/null +++ b/FishFactoryRestApi/Controllers/ImplementerController.cs @@ -0,0 +1,99 @@ +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.BusinessLogicsContracts; +using FishFactoryContracts.SearchModels; +using FishFactoryContracts.ViewModels; +using FishFactoryDataModel.Enums; +using Microsoft.AspNetCore.Mvc; + +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 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? GetNewOrders() + { + try + { + return _order.ReadList(new OrderSearchModel + { + Status = 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; + } + } + } +} -- 2.25.1 From 596f77bcb965bbacd6cb51ceede944c9f5f999ed Mon Sep 17 00:00:00 2001 From: dex_moth Date: Tue, 14 May 2024 19:05:59 +0400 Subject: [PATCH 3/5] =?UTF-8?q?=D0=B3=D0=BE=D1=82=D0=BE=D0=B2=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FishFactory/Forms/FormMain.cs | 7 +- .../BusinessLogic/OrderLogic.cs | 12 +- .../BusinessLogicsContracts/IOrderLogic.cs | 15 -- .../ViewModels/OrderViewModel.cs | 7 +- .../Models/IImplementerModel.cs | 2 +- .../Implements/ImplementerStorage.cs | 3 +- .../Implements/OrderStorage.cs | 12 +- .../20240514140738_implementer.Designer.cs | 252 ++++++++++++++++++ .../Migrations/20240514140738_implementer.cs | 22 ++ .../20240514143630_implementer2.Designer.cs | 252 ++++++++++++++++++ .../Migrations/20240514143630_implementer2.cs | 22 ++ .../Models/Implementer.cs | 6 +- FishFactoryDatabaseImplement/Models/Order.cs | 7 +- 13 files changed, 573 insertions(+), 46 deletions(-) create mode 100644 FishFactoryDatabaseImplement/Migrations/20240514140738_implementer.Designer.cs create mode 100644 FishFactoryDatabaseImplement/Migrations/20240514140738_implementer.cs create mode 100644 FishFactoryDatabaseImplement/Migrations/20240514143630_implementer2.Designer.cs create mode 100644 FishFactoryDatabaseImplement/Migrations/20240514143630_implementer2.cs diff --git a/FishFactory/Forms/FormMain.cs b/FishFactory/Forms/FormMain.cs index a41d81f..50aa7f6 100644 --- a/FishFactory/Forms/FormMain.cs +++ b/FishFactory/Forms/FormMain.cs @@ -9,15 +9,16 @@ namespace FishFactory.Forms private readonly ILogger _logger; private readonly IOrderLogic _orderLogic; private readonly IReportLogic _reportLogic; - private IWorkProcess _workProcess; + private readonly IWorkProcess _workProcess; - public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic) + public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic, IWorkProcess workProcess) { InitializeComponent(); _logger = logger; _orderLogic = orderLogic; _reportLogic = reportLogic; - } + _workProcess = workProcess; + } private void FormMain_Load(object sender, EventArgs e) { LoadData(); diff --git a/FishFactoryBusinessLogic/BusinessLogic/OrderLogic.cs b/FishFactoryBusinessLogic/BusinessLogic/OrderLogic.cs index 11a0cae..52e6f46 100644 --- a/FishFactoryBusinessLogic/BusinessLogic/OrderLogic.cs +++ b/FishFactoryBusinessLogic/BusinessLogic/OrderLogic.cs @@ -13,7 +13,7 @@ namespace FishFactoryBusinessLogic.BusinessLogic private readonly ILogger _logger; private readonly IOrderStorage _orderStorage; - public OrderLogic(ILogger logger, IOrderStorage orderStorage) + public OrderLogic(ILogger logger, IOrderStorage orderStorage) { _logger = logger; _orderStorage = orderStorage; @@ -69,8 +69,8 @@ namespace FishFactoryBusinessLogic.BusinessLogic public bool TakeOrderInWork(OrderBindingModel model) { - return ToNextStatus(model, OrderStatus.Выполняется); - } + return ToNextStatus(model, OrderStatus.Выполняется); + } public bool FinishOrder(OrderBindingModel model) { @@ -101,10 +101,6 @@ namespace FishFactoryBusinessLogic.BusinessLogic model.Status = element.Status; model.Count = element.Count; model.Sum = element.Sum; - if (!model.ImplementerId.HasValue) - { - model.ImplementerId = element.ImplementerId; - } if (model.Status != orderStatus - 1) { @@ -113,7 +109,7 @@ namespace FishFactoryBusinessLogic.BusinessLogic } model.Status = orderStatus; - if (model.Status == OrderStatus.Выдан) + if (model.Status == OrderStatus.Готов) { model.DateImplement = DateTime.Now; } diff --git a/FishFactoryContracts/BusinessLogicsContracts/IOrderLogic.cs b/FishFactoryContracts/BusinessLogicsContracts/IOrderLogic.cs index c25ffb3..8391391 100644 --- a/FishFactoryContracts/BusinessLogicsContracts/IOrderLogic.cs +++ b/FishFactoryContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -1,11 +1,6 @@ using FishFactoryContracts.BindingModels; using FishFactoryContracts.SearchModels; using FishFactoryContracts.ViewModels; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace FishFactoryContracts.BusinessLogicsContracts { @@ -15,17 +10,7 @@ namespace FishFactoryContracts.BusinessLogicsContracts OrderViewModel? ReadElement(OrderSearchModel model); bool CreateOrder(OrderBindingModel model); bool TakeOrderInWork(OrderBindingModel model); - /// - /// Готов - /// - /// - /// bool FinishOrder(OrderBindingModel model); - /// - /// Доставлен - /// - /// - /// bool DeliveryOrder(OrderBindingModel model); } } diff --git a/FishFactoryContracts/ViewModels/OrderViewModel.cs b/FishFactoryContracts/ViewModels/OrderViewModel.cs index cfe31f5..3ae73d4 100644 --- a/FishFactoryContracts/ViewModels/OrderViewModel.cs +++ b/FishFactoryContracts/ViewModels/OrderViewModel.cs @@ -1,10 +1,5 @@ using FishFactoryDataModel.Enums; -using System; -using System.Collections.Generic; using System.ComponentModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace FishFactoryContracts.ViewModels { @@ -17,7 +12,7 @@ namespace FishFactoryContracts.ViewModels public string ClientFIO { get; set; } = string.Empty; public int? ImplementerId { get; set; } [DisplayName("Исполнитель")] - public string? ImplementerFIO { get; set; } = string.Empty; + public string? ImplementerFIO { get; set; } = null; public int CannedId { get; set; } [DisplayName("Изделие")] public string CannedName { get; set; } = string.Empty; diff --git a/FishFactoryDataModels/Models/IImplementerModel.cs b/FishFactoryDataModels/Models/IImplementerModel.cs index 396886f..540ede8 100644 --- a/FishFactoryDataModels/Models/IImplementerModel.cs +++ b/FishFactoryDataModels/Models/IImplementerModel.cs @@ -1,6 +1,6 @@ namespace FishFactoryDataModel.Models { - public interface IImplementerModel + public interface IImplementerModel : IId { string ImplementerFIO { get; } string Password { get; } diff --git a/FishFactoryDatabaseImplement/Implements/ImplementerStorage.cs b/FishFactoryDatabaseImplement/Implements/ImplementerStorage.cs index 3c8d2af..47eed17 100644 --- a/FishFactoryDatabaseImplement/Implements/ImplementerStorage.cs +++ b/FishFactoryDatabaseImplement/Implements/ImplementerStorage.cs @@ -26,7 +26,8 @@ namespace FishFactoryDatabaseImplement.Implements public ImplementerViewModel? GetElement(ImplementerSearchModel model) { - if (string.IsNullOrEmpty(model.ImplementerFIO) && !model.Id.HasValue) + if (string.IsNullOrEmpty(model.ImplementerFIO) && string.IsNullOrEmpty(model.Password) && + !model.Id.HasValue) { return null; } diff --git a/FishFactoryDatabaseImplement/Implements/OrderStorage.cs b/FishFactoryDatabaseImplement/Implements/OrderStorage.cs index 40ca72a..aa04722 100644 --- a/FishFactoryDatabaseImplement/Implements/OrderStorage.cs +++ b/FishFactoryDatabaseImplement/Implements/OrderStorage.cs @@ -22,7 +22,7 @@ namespace FishFactoryDatabaseImplement.Implements public List GetFilteredList(OrderSearchModel model) { using var context = new FishFactoryDatabase(); - return context.Orders + return context.Orders .Include(x => x.Canned) .Include(x => x.Client) .Include(x => x.Implementer) @@ -38,11 +38,11 @@ namespace FishFactoryDatabaseImplement.Implements } public OrderViewModel? GetElement(OrderSearchModel model) { - if (!model.Id.HasValue) - { - return new(); - } - using var context = new FishFactoryDatabase(); + if (!model.Id.HasValue && (!model.ImplementerId.HasValue || !model.Status.HasValue)) + { + return null; + } + using var context = new FishFactoryDatabase(); return context.Orders .Include(x => x.Canned) .Include(x => x.Client) diff --git a/FishFactoryDatabaseImplement/Migrations/20240514140738_implementer.Designer.cs b/FishFactoryDatabaseImplement/Migrations/20240514140738_implementer.Designer.cs new file mode 100644 index 0000000..6915550 --- /dev/null +++ b/FishFactoryDatabaseImplement/Migrations/20240514140738_implementer.Designer.cs @@ -0,0 +1,252 @@ +// +using System; +using FishFactoryDatabaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace FishFactoryDatabaseImplement.Migrations +{ + [DbContext(typeof(FishFactoryDatabase))] + [Migration("20240514140738_implementer")] + partial class implementer + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.16") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Canned", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CannedName") + .IsRequired() + .HasColumnType("text"); + + b.Property("Price") + .HasColumnType("double precision"); + + b.HasKey("Id"); + + b.ToTable("Canneds"); + }); + + modelBuilder.Entity("FishFactoryDatabaseImplement.Models.CannedComponent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CannedId") + .HasColumnType("integer"); + + b.Property("ComponentId") + .HasColumnType("integer"); + + b.Property("Count") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("CannedId"); + + b.HasIndex("ComponentId"); + + b.ToTable("CannedComponents"); + }); + + modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Client", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ClientFIO") + .IsRequired() + .HasColumnType("text"); + + b.Property("Email") + .IsRequired() + .HasColumnType("text"); + + b.Property("Password") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Clients"); + }); + + modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Component", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ComponentName") + .IsRequired() + .HasColumnType("text"); + + b.Property("Cost") + .HasColumnType("double precision"); + + b.HasKey("Id"); + + b.ToTable("Components"); + }); + + modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Implementer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ImplementerFIO") + .IsRequired() + .HasColumnType("text"); + + b.Property("Password") + .IsRequired() + .HasColumnType("text"); + + b.Property("Qualification") + .HasColumnType("integer"); + + b.Property("WorkExperience") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("Implementers"); + }); + + modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CannedId") + .HasColumnType("integer"); + + b.Property("ClientId") + .HasColumnType("integer"); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("DateCreate") + .HasColumnType("timestamp without time zone"); + + b.Property("DateImplement") + .HasColumnType("timestamp without time zone"); + + b.Property("ImplementerId") + .HasColumnType("integer"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("Sum") + .HasColumnType("double precision"); + + b.HasKey("Id"); + + b.HasIndex("CannedId"); + + b.HasIndex("ClientId"); + + b.HasIndex("ImplementerId"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("FishFactoryDatabaseImplement.Models.CannedComponent", b => + { + b.HasOne("FishFactoryDatabaseImplement.Models.Canned", "Canned") + .WithMany("Components") + .HasForeignKey("CannedId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("FishFactoryDatabaseImplement.Models.Component", "Component") + .WithMany("CannedComponents") + .HasForeignKey("ComponentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Canned"); + + b.Navigation("Component"); + }); + + modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Order", b => + { + b.HasOne("FishFactoryDatabaseImplement.Models.Canned", "Canned") + .WithMany("Orders") + .HasForeignKey("CannedId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("FishFactoryDatabaseImplement.Models.Client", "Client") + .WithMany() + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("FishFactoryDatabaseImplement.Models.Implementer", "Implementer") + .WithMany("Order") + .HasForeignKey("ImplementerId"); + + b.Navigation("Canned"); + + b.Navigation("Client"); + + b.Navigation("Implementer"); + }); + + modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Canned", b => + { + b.Navigation("Components"); + + b.Navigation("Orders"); + }); + + modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Component", b => + { + b.Navigation("CannedComponents"); + }); + + modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Implementer", b => + { + b.Navigation("Order"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/FishFactoryDatabaseImplement/Migrations/20240514140738_implementer.cs b/FishFactoryDatabaseImplement/Migrations/20240514140738_implementer.cs new file mode 100644 index 0000000..b171c71 --- /dev/null +++ b/FishFactoryDatabaseImplement/Migrations/20240514140738_implementer.cs @@ -0,0 +1,22 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace FishFactoryDatabaseImplement.Migrations +{ + /// + public partial class implementer : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + + } + } +} diff --git a/FishFactoryDatabaseImplement/Migrations/20240514143630_implementer2.Designer.cs b/FishFactoryDatabaseImplement/Migrations/20240514143630_implementer2.Designer.cs new file mode 100644 index 0000000..ac347b6 --- /dev/null +++ b/FishFactoryDatabaseImplement/Migrations/20240514143630_implementer2.Designer.cs @@ -0,0 +1,252 @@ +// +using System; +using FishFactoryDatabaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace FishFactoryDatabaseImplement.Migrations +{ + [DbContext(typeof(FishFactoryDatabase))] + [Migration("20240514143630_implementer2")] + partial class implementer2 + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.16") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Canned", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CannedName") + .IsRequired() + .HasColumnType("text"); + + b.Property("Price") + .HasColumnType("double precision"); + + b.HasKey("Id"); + + b.ToTable("Canneds"); + }); + + modelBuilder.Entity("FishFactoryDatabaseImplement.Models.CannedComponent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CannedId") + .HasColumnType("integer"); + + b.Property("ComponentId") + .HasColumnType("integer"); + + b.Property("Count") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("CannedId"); + + b.HasIndex("ComponentId"); + + b.ToTable("CannedComponents"); + }); + + modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Client", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ClientFIO") + .IsRequired() + .HasColumnType("text"); + + b.Property("Email") + .IsRequired() + .HasColumnType("text"); + + b.Property("Password") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Clients"); + }); + + modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Component", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ComponentName") + .IsRequired() + .HasColumnType("text"); + + b.Property("Cost") + .HasColumnType("double precision"); + + b.HasKey("Id"); + + b.ToTable("Components"); + }); + + modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Implementer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ImplementerFIO") + .IsRequired() + .HasColumnType("text"); + + b.Property("Password") + .IsRequired() + .HasColumnType("text"); + + b.Property("Qualification") + .HasColumnType("integer"); + + b.Property("WorkExperience") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("Implementers"); + }); + + modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CannedId") + .HasColumnType("integer"); + + b.Property("ClientId") + .HasColumnType("integer"); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("DateCreate") + .HasColumnType("timestamp without time zone"); + + b.Property("DateImplement") + .HasColumnType("timestamp without time zone"); + + b.Property("ImplementerId") + .HasColumnType("integer"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("Sum") + .HasColumnType("double precision"); + + b.HasKey("Id"); + + b.HasIndex("CannedId"); + + b.HasIndex("ClientId"); + + b.HasIndex("ImplementerId"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("FishFactoryDatabaseImplement.Models.CannedComponent", b => + { + b.HasOne("FishFactoryDatabaseImplement.Models.Canned", "Canned") + .WithMany("Components") + .HasForeignKey("CannedId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("FishFactoryDatabaseImplement.Models.Component", "Component") + .WithMany("CannedComponents") + .HasForeignKey("ComponentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Canned"); + + b.Navigation("Component"); + }); + + modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Order", b => + { + b.HasOne("FishFactoryDatabaseImplement.Models.Canned", "Canned") + .WithMany("Orders") + .HasForeignKey("CannedId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("FishFactoryDatabaseImplement.Models.Client", "Client") + .WithMany() + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("FishFactoryDatabaseImplement.Models.Implementer", "Implementer") + .WithMany("Order") + .HasForeignKey("ImplementerId"); + + b.Navigation("Canned"); + + b.Navigation("Client"); + + b.Navigation("Implementer"); + }); + + modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Canned", b => + { + b.Navigation("Components"); + + b.Navigation("Orders"); + }); + + modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Component", b => + { + b.Navigation("CannedComponents"); + }); + + modelBuilder.Entity("FishFactoryDatabaseImplement.Models.Implementer", b => + { + b.Navigation("Order"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/FishFactoryDatabaseImplement/Migrations/20240514143630_implementer2.cs b/FishFactoryDatabaseImplement/Migrations/20240514143630_implementer2.cs new file mode 100644 index 0000000..7105be2 --- /dev/null +++ b/FishFactoryDatabaseImplement/Migrations/20240514143630_implementer2.cs @@ -0,0 +1,22 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace FishFactoryDatabaseImplement.Migrations +{ + /// + public partial class implementer2 : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + + } + } +} diff --git a/FishFactoryDatabaseImplement/Models/Implementer.cs b/FishFactoryDatabaseImplement/Models/Implementer.cs index efd595b..f68ae31 100644 --- a/FishFactoryDatabaseImplement/Models/Implementer.cs +++ b/FishFactoryDatabaseImplement/Models/Implementer.cs @@ -13,10 +13,10 @@ namespace FishFactoryDatabaseImplement.Models public string Password { get; private set; } = string.Empty; - public int WorkExperience { get; private set; } + public int WorkExperience { get; private set; } = 0; - public int Qualification { get; private set; } - [ForeignKey("ImplementerId")] + public int Qualification { get; private set; } = 0; + [ForeignKey("ImplementerId")] public virtual List Order { get; set; } = new(); public static Implementer? Create(ImplementerBindingModel? model) diff --git a/FishFactoryDatabaseImplement/Models/Order.cs b/FishFactoryDatabaseImplement/Models/Order.cs index 6dd1c23..a079ca2 100644 --- a/FishFactoryDatabaseImplement/Models/Order.cs +++ b/FishFactoryDatabaseImplement/Models/Order.cs @@ -39,8 +39,9 @@ namespace FishFactoryDatabaseImplement.Models ClientId = model.ClientId, Client = context.Clients.First(x => x.Id == model.ClientId), ImplementerId = model.ImplementerId, - Implementer = model.ImplementerId.HasValue ? context.Implementers.First(x => x.Id == model.ImplementerId) : null, - Count = model.Count, + Implementer = model.ImplementerId == null ? null : context.Implementers.First(i => i.Id == model.ImplementerId), + + Count = model.Count, Sum = model.Sum, Status = model.Status, DateCreate = model.DateCreate, @@ -73,7 +74,7 @@ namespace FishFactoryDatabaseImplement.Models ClientId = ClientId, ClientFIO = Client.ClientFIO, ImplementerId = ImplementerId, - ImplementerFIO = Implementer?.ImplementerFIO, + ImplementerFIO = Implementer == null ? string.Empty : Implementer.ImplementerFIO, Count = Count, Sum = Sum, Status = Status, -- 2.25.1 From 8d048df15b45a018697fac70fd2bb0c62ff5915d Mon Sep 17 00:00:00 2001 From: dex_moth Date: Wed, 19 Jun 2024 14:38:52 +0400 Subject: [PATCH 4/5] =?UTF-8?q?=D0=BE=D1=82=D0=BE=D0=B1=D1=80=D0=B0=D0=B6?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BA=D0=BE=D0=BB=D0=BE=D0=BD=D0=BE?= =?UTF-8?q?=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogic/OrderLogic.cs | 10 ++++++++-- .../SearchModels/ImplementerSearchModel.cs | 6 +++--- .../ViewModels/ImplementerViewModel.cs | 4 ++-- .../Models/Implementer.cs | 17 +++++++++-------- 4 files changed, 22 insertions(+), 15 deletions(-) diff --git a/FishFactoryBusinessLogic/BusinessLogic/OrderLogic.cs b/FishFactoryBusinessLogic/BusinessLogic/OrderLogic.cs index 52e6f46..fb61b4e 100644 --- a/FishFactoryBusinessLogic/BusinessLogic/OrderLogic.cs +++ b/FishFactoryBusinessLogic/BusinessLogic/OrderLogic.cs @@ -94,15 +94,21 @@ namespace FishFactoryBusinessLogic.BusinessLogic throw new ArgumentNullException(nameof(element)); } - model.CannedId = element.CannedId; + if (element.ImplementerId != null && model.ImplementerId != null && model.ImplementerId != element.ImplementerId) + { + throw new InvalidOperationException(nameof(model.ImplementerId)); + } + + model.CannedId = element.CannedId; model.ClientId = element.ClientId; model.DateCreate = element.DateCreate; model.DateImplement = element.DateImplement; model.Status = element.Status; model.Count = element.Count; model.Sum = element.Sum; + model.ImplementerId = element.ImplementerId.HasValue ? element.ImplementerId : model.ImplementerId; - if (model.Status != orderStatus - 1) + if (model.Status != orderStatus - 1) { _logger.LogWarning("Status update to " + orderStatus + " operation failed"); return false; diff --git a/FishFactoryContracts/SearchModels/ImplementerSearchModel.cs b/FishFactoryContracts/SearchModels/ImplementerSearchModel.cs index be9c97f..2420ab5 100644 --- a/FishFactoryContracts/SearchModels/ImplementerSearchModel.cs +++ b/FishFactoryContracts/SearchModels/ImplementerSearchModel.cs @@ -4,7 +4,7 @@ namespace FishFactoryContracts.SearchModels public class ImplementerSearchModel { public int? Id { get; set; } - public string? ImplementerFIO { get; set; } - public string? Password { get; set; } - } + public string? ImplementerFIO { get; set; } = string.Empty; + public string? Password { get; set; } = string.Empty; + } } diff --git a/FishFactoryContracts/ViewModels/ImplementerViewModel.cs b/FishFactoryContracts/ViewModels/ImplementerViewModel.cs index ceaae40..6c8008a 100644 --- a/FishFactoryContracts/ViewModels/ImplementerViewModel.cs +++ b/FishFactoryContracts/ViewModels/ImplementerViewModel.cs @@ -1,9 +1,9 @@ - +using FishFactoryDataModel.Models; using System.ComponentModel; namespace FishFactoryContracts.ViewModels { - public class ImplementerViewModel + public class ImplementerViewModel : IImplementerModel { public int Id { get; set; } [DisplayName("ФИО исполнителя")] diff --git a/FishFactoryDatabaseImplement/Models/Implementer.cs b/FishFactoryDatabaseImplement/Models/Implementer.cs index f68ae31..dd3193e 100644 --- a/FishFactoryDatabaseImplement/Models/Implementer.cs +++ b/FishFactoryDatabaseImplement/Models/Implementer.cs @@ -1,6 +1,7 @@ using FishFactoryContracts.BindingModels; using FishFactoryContracts.ViewModels; using FishFactoryDataModel.Models; +using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; namespace FishFactoryDatabaseImplement.Models @@ -8,14 +9,14 @@ namespace FishFactoryDatabaseImplement.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; } = 0; - - public int Qualification { get; private set; } = 0; + [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; } = 0; + [Required] + public int Qualification { get; private set; } = 0; [ForeignKey("ImplementerId")] public virtual List Order { get; set; } = new(); -- 2.25.1 From 34004cd13f970e0301bf1bb2f64620816259e8cc Mon Sep 17 00:00:00 2001 From: dex_moth Date: Fri, 21 Jun 2024 20:59:30 +0400 Subject: [PATCH 5/5] =?UTF-8?q?=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=D0=B5?= =?UTF-8?q?=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FishFactory/FishFactory.csproj | 3 +++ FishFactoryBusinessLogic/BusinessLogic/WorkModeling.cs | 10 +++++----- .../SearchModels/ImplementerSearchModel.cs | 2 +- FishFactoryDatabaseImplement/Models/Order.cs | 6 ------ 4 files changed, 9 insertions(+), 12 deletions(-) diff --git a/FishFactory/FishFactory.csproj b/FishFactory/FishFactory.csproj index d2c10da..f36cb40 100644 --- a/FishFactory/FishFactory.csproj +++ b/FishFactory/FishFactory.csproj @@ -42,6 +42,9 @@ + + Always + Always diff --git a/FishFactoryBusinessLogic/BusinessLogic/WorkModeling.cs b/FishFactoryBusinessLogic/BusinessLogic/WorkModeling.cs index 73eada3..1a59259 100644 --- a/FishFactoryBusinessLogic/BusinessLogic/WorkModeling.cs +++ b/FishFactoryBusinessLogic/BusinessLogic/WorkModeling.cs @@ -31,9 +31,8 @@ namespace FishFactoryBusinessLogic.BusinessLogic return; } var orders = _orderLogic.ReadList(new OrderSearchModel { Status = OrderStatus.Принят }); - var processingOrders = _orderLogic.ReadList(new OrderSearchModel { Status = OrderStatus.Выполняется }); - if (orders == null || processingOrders == null || (orders.Count == 0 && processingOrders.Count == 0)) + if (orders == null || orders.Count == 0) { _logger.LogWarning("DoWork. Orders is null or empty"); return; @@ -78,7 +77,8 @@ namespace FishFactoryBusinessLogic.BusinessLogic { Id = order.Id }); - } + Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100)); + } // кто-то мог уже перехватить заказ, игнорируем ошибку catch (InvalidOperationException ex) { @@ -91,7 +91,7 @@ namespace FishFactoryBusinessLogic.BusinessLogic throw; } // отдыхаем - Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100)); + } }); } @@ -104,7 +104,7 @@ namespace FishFactoryBusinessLogic.BusinessLogic } try { - var runOrder = await Task.Run(() => _orderLogic.ReadElement(new OrderSearchModel + var runOrder = await Task.Run(() => _orderLogic.ReadElement(new() { ImplementerId = implementer.Id, Status = OrderStatus.Выполняется diff --git a/FishFactoryContracts/SearchModels/ImplementerSearchModel.cs b/FishFactoryContracts/SearchModels/ImplementerSearchModel.cs index 2420ab5..ec31f76 100644 --- a/FishFactoryContracts/SearchModels/ImplementerSearchModel.cs +++ b/FishFactoryContracts/SearchModels/ImplementerSearchModel.cs @@ -4,7 +4,7 @@ namespace FishFactoryContracts.SearchModels public class ImplementerSearchModel { public int? Id { get; set; } - public string? ImplementerFIO { get; set; } = string.Empty; + public string? ImplementerFIO { get; set; } = string.Empty; public string? Password { get; set; } = string.Empty; } } diff --git a/FishFactoryDatabaseImplement/Models/Order.cs b/FishFactoryDatabaseImplement/Models/Order.cs index a079ca2..10d329b 100644 --- a/FishFactoryDatabaseImplement/Models/Order.cs +++ b/FishFactoryDatabaseImplement/Models/Order.cs @@ -56,14 +56,8 @@ namespace FishFactoryDatabaseImplement.Models } using var context = new FishFactoryDatabase(); - Id = model.Id; - CannedId = model.CannedId; - ClientId = model.ClientId; ImplementerId = model.ImplementerId; - Implementer = model.ImplementerId.HasValue ? context.Implementers.First(x => x.Id == model.ImplementerId) : null; - Sum = model.Sum; Status = model.Status; - DateCreate = model.DateCreate; DateImplement = model.DateImplement; } public OrderViewModel GetViewModel => new() -- 2.25.1