diff --git a/SewingFactory/SewingFactory.sln b/SewingFactory/SewingFactory.sln index 89e29f8..6803579 100644 --- a/SewingFactory/SewingFactory.sln +++ b/SewingFactory/SewingFactory.sln @@ -9,6 +9,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SewingFactoryDataModels", " EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SewingFactoryContracts", "SewingFactoryContracts\SewingFactoryContracts.csproj", "{D979DF0C-B534-4563-97E5-04389DB2F6B9}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SewingFactoryListImplement", "SewingFactoryListImplement\SewingFactoryListImplement.csproj", "{31EA02DD-1E53-4FB5-A729-EF5D3F50E27D}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SewingFactoryBusinessLogic", "SewingFactoryBusinessLogic\SewingFactoryBusinessLogic.csproj", "{909C9D71-212E-4544-BC3F-919BF60CBC14}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -27,6 +31,14 @@ Global {D979DF0C-B534-4563-97E5-04389DB2F6B9}.Debug|Any CPU.Build.0 = Debug|Any CPU {D979DF0C-B534-4563-97E5-04389DB2F6B9}.Release|Any CPU.ActiveCfg = Release|Any CPU {D979DF0C-B534-4563-97E5-04389DB2F6B9}.Release|Any CPU.Build.0 = Release|Any CPU + {31EA02DD-1E53-4FB5-A729-EF5D3F50E27D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {31EA02DD-1E53-4FB5-A729-EF5D3F50E27D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {31EA02DD-1E53-4FB5-A729-EF5D3F50E27D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {31EA02DD-1E53-4FB5-A729-EF5D3F50E27D}.Release|Any CPU.Build.0 = Release|Any CPU + {909C9D71-212E-4544-BC3F-919BF60CBC14}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {909C9D71-212E-4544-BC3F-919BF60CBC14}.Debug|Any CPU.Build.0 = Debug|Any CPU + {909C9D71-212E-4544-BC3F-919BF60CBC14}.Release|Any CPU.ActiveCfg = Release|Any CPU + {909C9D71-212E-4544-BC3F-919BF60CBC14}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/SewingFactory/SewingFactoryBusinessLogic/BusinessLogics/ComponentLogic.cs b/SewingFactory/SewingFactoryBusinessLogic/BusinessLogics/ComponentLogic.cs new file mode 100644 index 0000000..1d06c94 --- /dev/null +++ b/SewingFactory/SewingFactoryBusinessLogic/BusinessLogics/ComponentLogic.cs @@ -0,0 +1,115 @@ +using Microsoft.Extensions.Logging; +using SewingFactoryContracts.BindingModels; +using SewingFactoryContracts.BusinessLogicContracts; +using SewingFactoryContracts.SearchModels; +using SewingFactoryContracts.StoragesContracts; +using SewingFactoryContracts.ViewModels; + +namespace SewingFactoryBusinessLogic.BusinessLogics +{ + public class ComponentLogic : IComponentLogic + { + private readonly ILogger _logger; + + private readonly IComponentStorage _componentStorage; + + public ComponentLogic(ILogger logger, IComponentStorage componentStorage) + { + _logger = logger; + _componentStorage = componentStorage; + } + + public List? ReadList(ComponentSearchModel? model) + { + _logger.LogInformation("ReadList. ComponentName:{ComponentName}. Id:(Id))", model?.ComponentName, model?.Id); + var list = model == null ? _componentStorage.GetFullList() : _componentStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public ComponentViewModel? ReadElement(ComponentSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ComponentName:{ComponentName}. Id:{Id})", model?.ComponentName, model?.Id); + var element = _componentStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadList element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id})", element.Id); + return element; + } + + public bool Create(ComponentBindingModel model) + { + CheckModel(model); + if (_componentStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Update(ComponentBindingModel model) + { + CheckModel(model); + if (_componentStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + public bool Delete(ComponentBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id})", model.Id); + if (_componentStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + private void CheckModel(ComponentBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if(string.IsNullOrEmpty(model.ComponentName)) + { + throw new ArgumentNullException("Нет названия компонента", nameof(model.ComponentName)); + } + if (model.Cost <= 0) + { + throw new ArgumentException("Цена компонента должна быть больше 0", nameof(model.Cost)); + } + _logger.LogInformation("Component. ComponentName:(ComponentName}. Cost:{Cost}. Id:{Id})", model.ComponentName, model.Cost, model.Id); + var element = _componentStorage.GetElement(new ComponentSearchModel + { + ComponentName = model.ComponentName, + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Компонента с таким названием уже есть"); + } + } + } +} \ No newline at end of file diff --git a/SewingFactory/SewingFactoryBusinessLogic/BusinessLogics/OrderLogic.cs b/SewingFactory/SewingFactoryBusinessLogic/BusinessLogics/OrderLogic.cs new file mode 100644 index 0000000..3b2a9a0 --- /dev/null +++ b/SewingFactory/SewingFactoryBusinessLogic/BusinessLogics/OrderLogic.cs @@ -0,0 +1,35 @@ +using SewingFactoryContracts.BindingModels; +using SewingFactoryContracts.BusinessLogicContracts; +using SewingFactoryContracts.SearchModels; +using SewingFactoryContracts.ViewModels; + +namespace SewingFactoryBusinessLogic.BusinessLogics +{ + public class OrderLogic : IOrderLogic + { + public bool CreateOrder(OrderBindingModel model) + { + throw new NotImplementedException(); + } + + public bool DeliveryOrder(OrderBindingModel model) + { + throw new NotImplementedException(); + } + + public bool FinishOrder(OrderBindingModel model) + { + throw new NotImplementedException(); + } + + public List? ReadList(OrderSearchModel? model) + { + throw new NotImplementedException(); + } + + public bool TakeOrderInWork(OrderBindingModel model) + { + throw new NotImplementedException(); + } + } +} diff --git a/SewingFactory/SewingFactoryBusinessLogic/BusinessLogics/TextileLogic.cs b/SewingFactory/SewingFactoryBusinessLogic/BusinessLogics/TextileLogic.cs new file mode 100644 index 0000000..2423c9f --- /dev/null +++ b/SewingFactory/SewingFactoryBusinessLogic/BusinessLogics/TextileLogic.cs @@ -0,0 +1,35 @@ +using SewingFactoryContracts.BindingModels; +using SewingFactoryContracts.BusinessLogicContracts; +using SewingFactoryContracts.SearchModels; +using SewingFactoryContracts.ViewModels; + +namespace SewingFactoryBusinessLogic.BusinessLogics +{ + public class TextileLogic : ITextileLogic + { + public bool Create(TextileBindingModel model) + { + throw new NotImplementedException(); + } + + public bool Delete(TextileBindingModel model) + { + throw new NotImplementedException(); + } + + public TextileViewModel? ReadElement(TextileSearchModel model) + { + throw new NotImplementedException(); + } + + public List? ReadList(TextileSearchModel? model) + { + throw new NotImplementedException(); + } + + public bool Update(TextileBindingModel model) + { + throw new NotImplementedException(); + } + } +} diff --git a/SewingFactory/SewingFactoryBusinessLogic/SewingFactoryBusinessLogic.csproj b/SewingFactory/SewingFactoryBusinessLogic/SewingFactoryBusinessLogic.csproj new file mode 100644 index 0000000..745c272 --- /dev/null +++ b/SewingFactory/SewingFactoryBusinessLogic/SewingFactoryBusinessLogic.csproj @@ -0,0 +1,17 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + diff --git a/SewingFactory/SewingFactoryContracts/BindingModels/OrderBindingModel.cs b/SewingFactory/SewingFactoryContracts/BindingModels/OrderBindingModel.cs index 8a2169f..d9a20db 100644 --- a/SewingFactory/SewingFactoryContracts/BindingModels/OrderBindingModel.cs +++ b/SewingFactory/SewingFactoryContracts/BindingModels/OrderBindingModel.cs @@ -9,7 +9,9 @@ namespace SewingFactoryContracts.BindingModels { public class OrderBindingModel { - public int TextileID { get; set; } + public int Id { get; set; } + + public int TextileId { get; set; } public int Count { get; set; } diff --git a/SewingFactory/SewingFactoryContracts/ViewModels/OrderViewModel.cs b/SewingFactory/SewingFactoryContracts/ViewModels/OrderViewModel.cs index f74d924..c1145a6 100644 --- a/SewingFactory/SewingFactoryContracts/ViewModels/OrderViewModel.cs +++ b/SewingFactory/SewingFactoryContracts/ViewModels/OrderViewModel.cs @@ -13,7 +13,7 @@ namespace SewingFactoryContracts.ViewModels public int Id { get; set; } public int TextileID { get; set; } - + public int TextileId { get; set; } [DisplayName("Изделие")] public string TextileName { get; set; } = string.Empty; diff --git a/SewingFactory/SewingFactoryDataModels/Models/IComponentModel.cs b/SewingFactory/SewingFactoryDataModels/Models/IComponentModel.cs index 5f55619..dc3d1fb 100644 --- a/SewingFactory/SewingFactoryDataModels/Models/IComponentModel.cs +++ b/SewingFactory/SewingFactoryDataModels/Models/IComponentModel.cs @@ -12,4 +12,4 @@ namespace SewingFactoryDataModels.Models double Cost { get; } } -} +} \ No newline at end of file diff --git a/SewingFactory/SewingFactoryDataModels/Models/IOrderModel.cs b/SewingFactory/SewingFactoryDataModels/Models/IOrderModel.cs index 8e90866..6443608 100644 --- a/SewingFactory/SewingFactoryDataModels/Models/IOrderModel.cs +++ b/SewingFactory/SewingFactoryDataModels/Models/IOrderModel.cs @@ -9,7 +9,7 @@ namespace SewingFactoryDataModels.Models { public interface IOrderModel : IId { - int TextileID { get; } + int TextileId{ get; } int Count { get; } diff --git a/SewingFactory/SewingFactoryListImplement/Models/Component.cs b/SewingFactory/SewingFactoryListImplement/Models/Component.cs new file mode 100644 index 0000000..6f646ef --- /dev/null +++ b/SewingFactory/SewingFactoryListImplement/Models/Component.cs @@ -0,0 +1,43 @@ +using SewingFactoryContracts.BindingModels; +using SewingFactoryContracts.ViewModels; +using SewingFactoryDataModels; +using SewingFactoryDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SewingFactoryListImplement.Models +{ + internal class Component : IComponentModel + { + public int Id { get; set; } + + public string ComponentName { get; private set; } = string.Empty; + + public double Cost { get; set; } + + public static Component? Create(ComponentBindingModel? model) + { + if (model == null) + { + return null; + } + return new Component() + { + Id = model.Id, + ComponentName = model.ComponentName, + Cost = model.Cost + }; + } + + public ComponentViewModel GetViewModel => new() + { + Id = Id, + ComponentName = ComponentName, + Cost = Cost + }; + } +} diff --git a/SewingFactory/SewingFactoryListImplement/Models/Order.cs b/SewingFactory/SewingFactoryListImplement/Models/Order.cs new file mode 100644 index 0000000..008799e --- /dev/null +++ b/SewingFactory/SewingFactoryListImplement/Models/Order.cs @@ -0,0 +1,70 @@ +using SewingFactoryContracts.BindingModels; +using SewingFactoryContracts.ViewModels; +using SewingFactoryDataModels; +using SewingFactoryDataModels.Enums; +using SewingFactoryDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SewingFactoryListImplement.Models +{ + internal class Order : IOrderModel + { + public int Id { get; private set; } + + public int TextileId { get; private set; } + + public int Count { get; private set; } + + public double Sum { get; private set; } + + public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; + + public DateTime DateCreate { get; set; } = DateTime.Now; + + public DateTime? DateImplement { get; private set; } + + public static Order? Create(OrderBindingModel? model) + { + if (model == null) + { + return null; + } + return new Order() + { + Id = model.Id, + TextileId = model.TextileId, + Count = model.Count, + Sum = model.Sum, + Status = model.Status, + }; + } + + public void Update(OrderBindingModel? model) + { + if (model == null) + { + return; + } + + TextileId = TextileId; + Count = model.Count; + Sum = model.Sum; + Status = model.Status; + } + + public OrderViewModel GetViewModel => new() + { + Id = Id, + TextileId = TextileId, + Count = Count, + Sum = Sum, + Status = Status, + DateCreate = DateCreate, + DateImplement = DateImplement + }; + } +} \ No newline at end of file diff --git a/SewingFactory/SewingFactoryListImplement/Models/Textile.cs b/SewingFactory/SewingFactoryListImplement/Models/Textile.cs new file mode 100644 index 0000000..95ced10 --- /dev/null +++ b/SewingFactory/SewingFactoryListImplement/Models/Textile.cs @@ -0,0 +1,54 @@ +using SewingFactoryContracts.BindingModels; +using SewingFactoryContracts.ViewModels; +using SewingFactoryDataModels; +using SewingFactoryDataModels.Models; + +namespace SewingFactoryListImplement.Models +{ + internal class Textile : ITextileModel + { + public int Id { get; private set; } + + public string ComponentName { get; private set; } = string.Empty; + + public double Price { get; private set; } + + public string TextileName { get; private set; } = string.Empty; + + public Dictionary TextileComponents { get; private set; } = new Dictionary(); + + public static Textile? Create(TextileBindingModel? model) + { + if (model == null) + { + return null; + } + return new Textile() + { + Id = model.Id, + TextileName = model.TextileName, + Price = model.Price, + TextileComponents = model.TextileComponents + }; + } + + public void Update(TextileBindingModel? model) + { + if (model == null) + { + return; + } + TextileName = model.TextileName; + Price = model.Price; + TextileComponents = TextileComponents; + } + + public TextileViewModel GetViewModel => new() + { + Id = Id, + TextileName = TextileName, + Price = Price, + TextileComponents = TextileComponents + }; + } +} \ No newline at end of file diff --git a/SewingFactory/SewingFactoryListImplement/SewingFactoryListImplement.csproj b/SewingFactory/SewingFactoryListImplement/SewingFactoryListImplement.csproj new file mode 100644 index 0000000..1cc019f --- /dev/null +++ b/SewingFactory/SewingFactoryListImplement/SewingFactoryListImplement.csproj @@ -0,0 +1,14 @@ + + + + net6.0 + enable + enable + + + + + + + + diff --git a/SewingFactory/SewingFactoryView/Form1.Designer.cs b/SewingFactory/SewingFactoryView/Form1.Designer.cs deleted file mode 100644 index fc012ac..0000000 --- a/SewingFactory/SewingFactoryView/Form1.Designer.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace SewingFactoryView -{ - partial class Form1 - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.components = new System.ComponentModel.Container(); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "Form1"; - } - - #endregion - } -} diff --git a/SewingFactory/SewingFactoryView/Form1.cs b/SewingFactory/SewingFactoryView/Form1.cs deleted file mode 100644 index 8624737..0000000 --- a/SewingFactory/SewingFactoryView/Form1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace SewingFactoryView -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} diff --git a/SewingFactory/SewingFactoryView/Form1.resx b/SewingFactory/SewingFactoryView/Form1.resx deleted file mode 100644 index 1af7de1..0000000 --- a/SewingFactory/SewingFactoryView/Form1.resx +++ /dev/null @@ -1,120 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 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