From 140678293fd01fc93d3a6bd80d90549fa7a17c93 Mon Sep 17 00:00:00 2001 From: Zakharov_Rostislav Date: Mon, 22 Apr 2024 20:50:21 +0400 Subject: [PATCH 01/15] lab-6 --- .../DataFileSingleton.cs | 6 + .../Implements/ImplementerStorage.cs | 79 ++++++++ .../Implements/OrderStorage.cs | 39 ++-- .../Models/Implementer.cs | 76 ++++++++ .../Models/Order.cs | 5 + .../BlacksmithWorkshop/FormMain.Designer.cs | 42 +++-- .../BlacksmithWorkshop/FormMain.cs | 19 +- .../ImplementerForm.Designer.cs | 172 ++++++++++++++++++ .../BlacksmithWorkshop/ImplementerForm.cs | 102 +++++++++++ .../BlacksmithWorkshop/ImplementerForm.resx | 120 ++++++++++++ .../ImplementersForm.Designer.cs | 114 ++++++++++++ .../BlacksmithWorkshop/ImplementersForm.cs | 113 ++++++++++++ .../BlacksmithWorkshop/ImplementersForm.resx | 120 ++++++++++++ .../BlacksmithWorkshop/Program.cs | 5 + .../BusinessLogics/ImplementerLogic.cs | 126 +++++++++++++ .../BusinessLogics/OrderLogic.cs | 36 ++-- .../BusinessLogics/WorkModeling.cs | 137 ++++++++++++++ .../BindingModels/ImplementerBindingModel.cs | 18 ++ .../BindingModels/OrderBindingModel .cs | 1 + .../IImplementerLogic.cs | 20 ++ .../BusinessLogicsContracts/IOrderLogic.cs | 1 + .../BusinessLogicsContracts/IWorkProcess.cs | 13 ++ .../SearchModels/ImplementerSearchModel.cs | 15 ++ .../SearchModels/OrderSearchModel.cs | 5 +- .../StoragesContracts/IImplementerStorage.cs | 21 +++ .../ViewModels/ImplementerViewModel.cs | 23 +++ .../ViewModels/OrderViewModel.cs | 3 + .../Models/IImplementerModel.cs | 17 ++ .../Models/IOrderModel.cs | 1 + .../BlacksmithWorkshopDataBase.cs | 3 + .../Implements/ImplementerStorage.cs | 82 +++++++++ .../Implements/OrderStorage.cs | 19 +- .../Models/Implementer.cs | 64 +++++++ .../Models/Order.cs | 8 +- .../DataListSingleton.cs | 2 + .../Implements/ImplementerStorage.cs | 102 +++++++++++ .../Implements/OrderStorage.cs | 27 +-- .../Models/Implementer.cs | 54 ++++++ .../Models/Order .cs | 4 + .../BlacksmithWorkshopRestApi.csproj | 4 - .../Controllers/ImplementerController.cs | 101 ++++++++++ 41 files changed, 1852 insertions(+), 67 deletions(-) create mode 100644 BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Implements/ImplementerStorage.cs create mode 100644 BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Models/Implementer.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshop/ImplementerForm.Designer.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshop/ImplementerForm.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshop/ImplementerForm.resx create mode 100644 BlacksmithWorkshop/BlacksmithWorkshop/ImplementersForm.Designer.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshop/ImplementersForm.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshop/ImplementersForm.resx create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/ImplementerLogic.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/WorkModeling.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ImplementerBindingModel.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IImplementerLogic.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IWorkProcess.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/ImplementerSearchModel.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IImplementerStorage.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ImplementerViewModel.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IImplementerModel.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/ImplementerStorage.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Implementer.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/ImplementerStorage.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Implementer.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopRestApi/Controllers/ImplementerController.cs diff --git a/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/DataFileSingleton.cs b/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/DataFileSingleton.cs index 90aeb50..2df3458 100644 --- a/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/DataFileSingleton.cs +++ b/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/DataFileSingleton.cs @@ -10,10 +10,12 @@ namespace BlackcmithWorkshopFileImplement private readonly string OrderFileName = "Order.xml"; private readonly string ManufactureFileName = "Manufacture.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 Manufactures { get; private set; } public List Clients { get; private set; } + public List Implementers { get; private set; } public static DataFileSingleton GetInstance() { if (instance == null) @@ -30,6 +32,8 @@ namespace BlackcmithWorkshopFileImplement "Orders", x => x.GetXElement); public void SaveClients() => SaveData(Clients, ClientFileName, "Clients", x => x.GetXElement); + public void SaveImplementers() => SaveData(Implementers, ImplementerFileName, + "Implementers", x => x.GetXElement); private DataFileSingleton() { Components = LoadData(ComponentFileName, "Component", x => @@ -40,6 +44,8 @@ namespace BlackcmithWorkshopFileImplement 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/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Implements/ImplementerStorage.cs b/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..ccae9ad --- /dev/null +++ b/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,79 @@ +using BlackcmithWorkshopFileImplement; +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.StoragesContracts; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopFileImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopFileImplement.Implements +{ + public class ImplementerStorage : IImplementerStorage + { + private readonly DataFileSingleton source; + public ImplementerStorage() + { + source = DataFileSingleton.GetInstance(); + } + public List GetFullList() + { + return source.Implementers + .Select(x => x.GetViewModel) + .ToList(); + } + public List GetFilteredList(ImplementerSearchModel model) + { + if (string.IsNullOrEmpty(model.ImplementerFIO) && string.IsNullOrEmpty(model.Password)) + { + return new(); + } + return source.Implementers + .Where(x => (string.IsNullOrEmpty(model.ImplementerFIO) || + x.ImplementerFIO.Contains(model.ImplementerFIO)) && + (string.IsNullOrEmpty(model.Password) || x.Password.Contains(model.Password))) + .Select(x => x.GetViewModel) + .ToList(); + } + public ImplementerViewModel? GetElement(ImplementerSearchModel model) + { + return source.Implementers + .FirstOrDefault(x => (string.IsNullOrEmpty(model.ImplementerFIO) || x.ImplementerFIO == model.ImplementerFIO) && + (!model.Id.HasValue || x.Id == model.Id) && (string.IsNullOrEmpty(model.Password) || x.Password == model.Password))? + .GetViewModel; + } + public ImplementerViewModel? Insert(ImplementerBindingModel model) + { + model.Id = source.Implementers.Count > 0 ? source.Implementers.Max(x => x.Id) + 1 : 1; + var newImplementer = Implementer.Create(model); + if (newImplementer == null) + return null; + source.Implementers.Add(newImplementer); + source.SaveImplementers(); + return newImplementer.GetViewModel; + } + public ImplementerViewModel? Update(ImplementerBindingModel model) + { + var implementer = source.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (implementer == null) + return null; + implementer.Update(model); + source.SaveImplementers(); + return implementer.GetViewModel; + } + public ImplementerViewModel? Delete(ImplementerBindingModel model) + { + var element = source.Implementers.FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + source.Implementers.Remove(element); + source.SaveImplementers(); + return element.GetViewModel; + } + return null; + } + } +} diff --git a/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Implements/OrderStorage.cs b/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Implements/OrderStorage.cs index 30e2f4f..813bb70 100644 --- a/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Implements/OrderStorage.cs +++ b/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Implements/OrderStorage.cs @@ -28,14 +28,14 @@ namespace BlacksmithWorkshopFileImplement.Implements public List GetFilteredList(OrderSearchModel model) { return source.Orders - .Where(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) - ) + .Where(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) ) - .Select(x => AccessStorage(x.GetViewModel)) + .Select(x => AccessStorage(x.GetViewModel) ?? new()) .ToList(); } public OrderViewModel? GetElement(OrderSearchModel model) @@ -44,9 +44,12 @@ namespace BlacksmithWorkshopFileImplement.Implements { return null; } - return AccessStorage(source.Orders.FirstOrDefault( - x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel - ); + return AccessStorage(source.Orders + .FirstOrDefault( + x => (model.Id.HasValue && x.Id == model.Id) || + (model.ImplementerId.HasValue && model.Status.HasValue && + x.ImplementerId == model.ImplementerId && x.Status == model.Status))? + .GetViewModel ?? new()); } public OrderViewModel? Insert(OrderBindingModel model) { @@ -85,19 +88,15 @@ namespace BlacksmithWorkshopFileImplement.Implements } public OrderViewModel? AccessStorage(OrderViewModel model) { - if (model == null) - return null; + var iceCream = source.Manufactures.FirstOrDefault(x => x.Id == model.Id); var client = source.Clients.FirstOrDefault(x => x.Id == model.Id); + var implementer = source.Implementers.FirstOrDefault(x => x.Id == model.ImplementerId); + if (iceCream != null) + model.ManufactureName = iceCream.ManufactureName; if (client != null) model.ClientFIO = client.ClientFIO; - foreach (var Manufacture in source.Manufactures) - { - if (Manufacture.Id == model.ManufactureId) - { - model.ManufactureName = Manufacture.ManufactureName; - break; - } - } + if (implementer != null) + model.ImplementerFIO = implementer.ImplementerFIO; return model; } } diff --git a/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Models/Implementer.cs b/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Models/Implementer.cs new file mode 100644 index 0000000..241bebf --- /dev/null +++ b/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Models/Implementer.cs @@ -0,0 +1,76 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace BlacksmithWorkshopFileImplement.Models +{ + public class Implementer : IImplementerModel + { + public int Id { get; private set; } + public string ImplementerFIO { get; private set; } = string.Empty; + public string Password { get; set; } = string.Empty; + public int Qualification { get; set; } = 0; + public int WorkExperience { get; set; } = 0; + public static Implementer? Create(ImplementerBindingModel model) + { + if (model == null) + { + return null; + } + return new Implementer() + { + Id = model.Id, + ImplementerFIO = model.ImplementerFIO, + Password = model.Password, + WorkExperience = model.WorkExperience, + Qualification = model.Qualification + }; + } + public void Update(ImplementerBindingModel model) + { + if (model == null) + { + return; + } + ImplementerFIO = model.ImplementerFIO; + Password = model.Password; + WorkExperience = model.WorkExperience; + Qualification = model.Qualification; + } + public ImplementerViewModel GetViewModel => new() + { + Id = Id, + ImplementerFIO = ImplementerFIO, + Password = Password, + WorkExperience = WorkExperience, + Qualification = Qualification + }; + public static Implementer? Create(XElement element) + { + if (element == null) + { + return null; + } + return new Implementer() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + ImplementerFIO = element.Element("ImplementerFIO")!.Value, + Password = element.Element("Password")!.Value, + Qualification = Convert.ToInt32(element.Element("Qualification")!.Value), + WorkExperience = Convert.ToInt32(element.Element("WorkExperience")!.Value) + }; + } + public XElement GetXElement => new("Implementer", + new XAttribute("Id", Id), + new XElement("ImplementerFIO", ImplementerFIO), + new XElement("Password", Password), + new XElement("Qualification", Qualification.ToString()), + new XElement("WorkExperience", WorkExperience.ToString())); + } +} diff --git a/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Models/Order.cs b/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Models/Order.cs index b3031c8..98b409b 100644 --- a/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Models/Order.cs +++ b/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Models/Order.cs @@ -16,6 +16,7 @@ namespace BlacksmithWorkshopFileImplement.Models public int Id { get; private set; } public int ManufactureId { get; private set; } public int ClientId { get; private set; } + public int? ImplementerId { get; private set; } = null; public int Count { get; private set; } public double Sum { get; private set; } public OrderStatus Status { get; private set; } @@ -32,6 +33,7 @@ namespace BlacksmithWorkshopFileImplement.Models { Id = model.Id, ManufactureId = model.ManufactureId, + ImplementerId = model.ImplementerId, ClientId = model.ClientId, Count = model.Count, Sum = model.Sum, @@ -50,6 +52,7 @@ namespace BlacksmithWorkshopFileImplement.Models { Id = Convert.ToInt32(element.Attribute("Id")!.Value), ManufactureId = Convert.ToInt32(element.Element("ManufactureId")!.Value), + ImplementerId = Convert.ToInt32(element.Element("ImplementerId")!.Value), ClientId = Convert.ToInt32(element.Element("ClientId")!.Value), Count = Convert.ToInt32(element.Element("Count")!.Value), Sum = Convert.ToDouble(element.Element("Sum")!.Value), @@ -71,6 +74,7 @@ namespace BlacksmithWorkshopFileImplement.Models { Id = Id, ManufactureId = ManufactureId, + ImplementerId = ImplementerId, ClientId = ClientId, Count = Count, Sum = Sum, @@ -82,6 +86,7 @@ namespace BlacksmithWorkshopFileImplement.Models new XAttribute("Id", Id), new XElement("ManufactureId", ManufactureId), new XElement("ClientId", ClientId), + new XElement("ImplementerId", ImplementerId), new XElement("Sum", Sum.ToString()), new XElement("Count", Count), new XElement("Status", Status.ToString()), diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs index b31a161..76a5c06 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs @@ -32,6 +32,9 @@ GuidesToolStripMenuItem = new ToolStripMenuItem(); ComponentsToolStripMenuItem = new ToolStripMenuItem(); ManufacturesToolStripMenuItem = new ToolStripMenuItem(); + ClientsToolStripMenuItem = new ToolStripMenuItem(); + ImplementersToolStripMenuItem = new ToolStripMenuItem(); + StartWorkingToolStripMenuItem = new ToolStripMenuItem(); ReportsToolStripMenuItem = new ToolStripMenuItem(); ManufacturesListToolStripMenuItem = new ToolStripMenuItem(); ManufacturesComponentsListToolStripMenuItem = new ToolStripMenuItem(); @@ -42,7 +45,6 @@ buttonIssued = new Button(); buttonReady = new Button(); buttonTakeInWork = new Button(); - ClientsToolStripMenuItem = new ToolStripMenuItem(); menuStrip.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); SuspendLayout(); @@ -58,7 +60,7 @@ // // GuidesToolStripMenuItem // - GuidesToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { ComponentsToolStripMenuItem, ManufacturesToolStripMenuItem, ClientsToolStripMenuItem}); + GuidesToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { ComponentsToolStripMenuItem, ManufacturesToolStripMenuItem, ClientsToolStripMenuItem, ImplementersToolStripMenuItem, StartWorkingToolStripMenuItem }); GuidesToolStripMenuItem.Name = "GuidesToolStripMenuItem"; GuidesToolStripMenuItem.Size = new Size(94, 20); GuidesToolStripMenuItem.Text = "Справочники"; @@ -66,20 +68,41 @@ // ComponentsToolStripMenuItem // ComponentsToolStripMenuItem.Name = "ComponentsToolStripMenuItem"; - ComponentsToolStripMenuItem.Size = new Size(198, 22); + ComponentsToolStripMenuItem.Size = new Size(181, 22); ComponentsToolStripMenuItem.Text = "Компоненты"; ComponentsToolStripMenuItem.Click += ComponentsStripMenuItem_Click; // // ManufacturesToolStripMenuItem // ManufacturesToolStripMenuItem.Name = "ManufacturesToolStripMenuItem"; - ManufacturesToolStripMenuItem.Size = new Size(198, 22); + ManufacturesToolStripMenuItem.Size = new Size(181, 22); ManufacturesToolStripMenuItem.Text = "Кузнечные изделия"; ManufacturesToolStripMenuItem.Click += ManufacturesStripMenuItem_Click; // + // ClientsToolStripMenuItem + // + ClientsToolStripMenuItem.Name = "ClientsToolStripMenuItem"; + ClientsToolStripMenuItem.Size = new Size(181, 22); + ClientsToolStripMenuItem.Text = "Клиенты"; + ClientsToolStripMenuItem.Click += ClientsToolStripMenuItem_Click; + // + // ImplementersToolStripMenuItem + // + ImplementersToolStripMenuItem.Name = "ImplementersToolStripMenuItem"; + ImplementersToolStripMenuItem.Size = new Size(181, 22); + ImplementersToolStripMenuItem.Text = "Исполнители"; + ImplementersToolStripMenuItem.Click += ImplementersToolStripMenuItem_Click; + // + // StartWorkingToolStripMenuItem + // + StartWorkingToolStripMenuItem.Name = "StartWorkingToolStripMenuItem"; + StartWorkingToolStripMenuItem.Size = new Size(181, 22); + StartWorkingToolStripMenuItem.Text = "Старт работ"; + StartWorkingToolStripMenuItem.Click += StartWorkingToolStripMenuItem_Click; + // // ReportsToolStripMenuItem // - ReportsToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { ManufacturesListToolStripMenuItem, ManufacturesComponentsListToolStripMenuItem, OrdersListToolStripMenuItem}); + ReportsToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { ManufacturesListToolStripMenuItem, ManufacturesComponentsListToolStripMenuItem, OrdersListToolStripMenuItem }); ReportsToolStripMenuItem.Name = "ReportsToolStripMenuItem"; ReportsToolStripMenuItem.Size = new Size(60, 20); ReportsToolStripMenuItem.Text = "Отчёты"; @@ -164,13 +187,6 @@ buttonTakeInWork.UseVisualStyleBackColor = true; buttonTakeInWork.Click += TakeInWorkButton_Click; // - // ClientsToolStripMenuItem - // - ClientsToolStripMenuItem.Name = "ClientsToolStripMenuItem"; - ClientsToolStripMenuItem.Size = new Size(198, 22); - ClientsToolStripMenuItem.Text = "Клиенты"; - ClientsToolStripMenuItem.Click += ClientsToolStripMenuItem_Click; - // // FormMain // AutoScaleDimensions = new SizeF(7F, 15F); @@ -212,5 +228,7 @@ private ToolStripMenuItem ManufacturesComponentsListToolStripMenuItem; private ToolStripMenuItem OrdersListToolStripMenuItem; private ToolStripMenuItem ClientsToolStripMenuItem; + private ToolStripMenuItem ImplementersToolStripMenuItem; + private ToolStripMenuItem StartWorkingToolStripMenuItem; } } \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs index de700cd..be207e7 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs @@ -19,12 +19,15 @@ namespace BlacksmithWorkshop private readonly ILogger _logger; private readonly IOrderLogic _orderLogic; private readonly IReportLogic _reportLogic; - public FormMain(ILogger logger, IOrderLogic orderLogic, IReportLogic reportLogic) + private readonly IWorkProcess _workProcess; + public FormMain(ILogger logger, IOrderLogic orderLogic, + IReportLogic reportLogic, IWorkProcess workProcess) { InitializeComponent(); _logger = logger; _orderLogic = orderLogic; _reportLogic = reportLogic; + _workProcess = workProcess; } private void ComponentsStripMenuItem_Click(object sender, EventArgs e) { @@ -48,6 +51,7 @@ namespace BlacksmithWorkshop { dataGridView.DataSource = list; dataGridView.Columns["ManufactureId"].Visible = false; + dataGridView.Columns["ImplementerId"].Visible = false; dataGridView.Columns["ManufactureName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; dataGridView.Columns["ClientId"].Visible = false; } @@ -204,5 +208,18 @@ namespace BlacksmithWorkshop form.ShowDialog(); } } + private void StartWorkingToolStripMenuItem_Click(object sender, EventArgs e) + { + _workProcess.DoWork((Program.ServiceProvider?.GetService(typeof(IImplementerLogic)) as IImplementerLogic)!, _orderLogic); + MessageBox.Show("Процесс обработки запущен", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + private void ImplementersToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(ImplementersForm)); + if (service is ImplementersForm form) + { + form.ShowDialog(); + } + } } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/ImplementerForm.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/ImplementerForm.Designer.cs new file mode 100644 index 0000000..854012b --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/ImplementerForm.Designer.cs @@ -0,0 +1,172 @@ +using DocumentFormat.OpenXml.Spreadsheet; +using DocumentFormat.OpenXml.Wordprocessing; + +namespace BlacksmithWorkshop +{ + partial class ImplementerForm + { + /// + /// 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() + { + FIOTextBox = new TextBox(); + PasswordTextBox = new TextBox(); + QualificationTextBox = new TextBox(); + WorkExperienceTextBox = new TextBox(); + labelFio = new Label(); + labelPassword = new Label(); + labelQualification = new Label(); + labelExperience = new Label(); + SaveButton = new Button(); + CancelButton = new Button(); + SuspendLayout(); + // + // FIOTextBox + // + FIOTextBox.Location = new Point(108, 14); + FIOTextBox.Margin = new Padding(3, 2, 3, 2); + FIOTextBox.Name = "FIOTextBox"; + FIOTextBox.Size = new Size(360, 23); + FIOTextBox.TabIndex = 0; + // + // PasswordTextBox + // + PasswordTextBox.Location = new Point(108, 39); + PasswordTextBox.Margin = new Padding(3, 2, 3, 2); + PasswordTextBox.Name = "PasswordTextBox"; + PasswordTextBox.Size = new Size(360, 23); + PasswordTextBox.TabIndex = 1; + // + // QualificationTextBox + // + QualificationTextBox.Location = new Point(108, 64); + QualificationTextBox.Margin = new Padding(3, 2, 3, 2); + QualificationTextBox.Name = "QualificationTextBox"; + QualificationTextBox.Size = new Size(360, 23); + QualificationTextBox.TabIndex = 2; + // + // WorkExperienceTextBox + // + WorkExperienceTextBox.Location = new Point(108, 88); + WorkExperienceTextBox.Margin = new Padding(3, 2, 3, 2); + WorkExperienceTextBox.Name = "WorkExperienceTextBox"; + WorkExperienceTextBox.Size = new Size(360, 23); + WorkExperienceTextBox.TabIndex = 3; + // + // labelFio + // + labelFio.AutoSize = true; + labelFio.Location = new Point(8, 14); + labelFio.Name = "labelFio"; + labelFio.Size = new Size(34, 15); + labelFio.TabIndex = 4; + labelFio.Text = "ФИО"; + // + // labelPassword + // + labelPassword.AutoSize = true; + labelPassword.Location = new Point(8, 39); + labelPassword.Name = "labelPassword"; + labelPassword.Size = new Size(49, 15); + labelPassword.TabIndex = 5; + labelPassword.Text = "Пароль"; + // + // labelQualification + // + labelQualification.AutoSize = true; + labelQualification.Location = new Point(8, 64); + labelQualification.Name = "labelQualification"; + labelQualification.Size = new Size(88, 15); + labelQualification.TabIndex = 6; + labelQualification.Text = "Квалификация"; + // + // labelExperience + // + labelExperience.AutoSize = true; + labelExperience.Location = new Point(8, 88); + labelExperience.Name = "labelExperience"; + labelExperience.Size = new Size(79, 15); + labelExperience.TabIndex = 7; + labelExperience.Text = "Стаж работы"; + // + // SaveButton + // + SaveButton.Location = new Point(298, 113); + SaveButton.Margin = new Padding(3, 2, 3, 2); + SaveButton.Name = "SaveButton"; + SaveButton.Size = new Size(82, 22); + SaveButton.TabIndex = 8; + SaveButton.Text = "Сохранить"; + SaveButton.UseVisualStyleBackColor = true; + SaveButton.Click += SaveButton_Click; + // + // CancelButton + // + CancelButton.Location = new Point(386, 113); + CancelButton.Margin = new Padding(3, 2, 3, 2); + CancelButton.Name = "CancelButton"; + CancelButton.Size = new Size(82, 22); + CancelButton.TabIndex = 9; + CancelButton.Text = "Отмена"; + CancelButton.UseVisualStyleBackColor = true; + CancelButton.Click += CancelButton_Click; + // + // ImplementerForm + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(480, 140); + Controls.Add(CancelButton); + Controls.Add(SaveButton); + Controls.Add(labelExperience); + Controls.Add(labelQualification); + Controls.Add(labelPassword); + Controls.Add(labelFio); + Controls.Add(WorkExperienceTextBox); + Controls.Add(QualificationTextBox); + Controls.Add(PasswordTextBox); + Controls.Add(FIOTextBox); + Margin = new Padding(3, 2, 3, 2); + Name = "ImplementerForm"; + Text = "Исполнитель"; + Load += ImplementerForm_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private TextBox FIOTextBox; + private TextBox PasswordTextBox; + private TextBox QualificationTextBox; + private TextBox WorkExperienceTextBox; + private Label labelFio; + private Label labelPassword; + private Label labelQualification; + private Label labelExperience; + private Button SaveButton; + private Button CancelButton; + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/ImplementerForm.cs b/BlacksmithWorkshop/BlacksmithWorkshop/ImplementerForm.cs new file mode 100644 index 0000000..55e8944 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/ImplementerForm.cs @@ -0,0 +1,102 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.BusinessLogicsContracts; +using BlacksmithWorkshopContracts.SearchModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace BlacksmithWorkshop +{ + public partial class ImplementerForm : Form + { + private readonly ILogger _logger; + private readonly IImplementerLogic _logic; + private int? _id; + public int Id { set { _id = value; } } + public ImplementerForm(ILogger logger, IImplementerLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void ImplementerForm_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + _logger.LogInformation("Получение исполнителя"); + var view = _logic.ReadElement(new ImplementerSearchModel + { + Id = _id.Value + }); + if (view != null) + { + FIOTextBox.Text = view.ImplementerFIO; + PasswordTextBox.Text = view.Password; + QualificationTextBox.Text = view.Qualification.ToString(); + WorkExperienceTextBox.Text = view.WorkExperience.ToString(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения исполнителя"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + + private void SaveButton_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(FIOTextBox.Text)) + { + MessageBox.Show("Заполните ФИО", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(PasswordTextBox.Text)) + { + MessageBox.Show("Заполните пароль", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение компонента"); + try + { + var model = new ImplementerBindingModel + { + Id = _id ?? 0, + ImplementerFIO = FIOTextBox.Text, + Password = PasswordTextBox.Text, + Qualification = Convert.ToInt32(QualificationTextBox.Text), + WorkExperience = Convert.ToInt32(WorkExperienceTextBox.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 CancelButton_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/ImplementerForm.resx b/BlacksmithWorkshop/BlacksmithWorkshop/ImplementerForm.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/ImplementerForm.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/BlacksmithWorkshop/BlacksmithWorkshop/ImplementersForm.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/ImplementersForm.Designer.cs new file mode 100644 index 0000000..e1890c9 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/ImplementersForm.Designer.cs @@ -0,0 +1,114 @@ +namespace BlacksmithWorkshop +{ + partial class ImplementersForm + { + /// + /// 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() + { + dataGridView1 = new DataGridView(); + CreateButton = new Button(); + ChangeButton = new Button(); + DeleteButton = new Button(); + RefreshButton = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView1).BeginInit(); + SuspendLayout(); + // + // dataGridView1 + // + dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView1.Location = new Point(12, 12); + dataGridView1.Name = "dataGridView1"; + dataGridView1.RowHeadersWidth = 51; + dataGridView1.RowTemplate.Height = 29; + dataGridView1.Size = new Size(565, 426); + dataGridView1.TabIndex = 0; + // + // CreateButton + // + CreateButton.Location = new Point(583, 12); + CreateButton.Name = "CreateButton"; + CreateButton.Size = new Size(205, 29); + CreateButton.TabIndex = 1; + CreateButton.Text = "Создать"; + CreateButton.UseVisualStyleBackColor = true; + CreateButton.Click += CreateButton_Click; + // + // ChangeButton + // + ChangeButton.Location = new Point(583, 47); + ChangeButton.Name = "ChangeButton"; + ChangeButton.Size = new Size(205, 29); + ChangeButton.TabIndex = 2; + ChangeButton.Text = "Изменить"; + ChangeButton.UseVisualStyleBackColor = true; + ChangeButton.Click += ChangeButton_Click; + // + // DeleteButton + // + DeleteButton.Location = new Point(583, 82); + DeleteButton.Name = "DeleteButton"; + DeleteButton.Size = new Size(205, 29); + DeleteButton.TabIndex = 3; + DeleteButton.Text = "Удалить"; + DeleteButton.UseVisualStyleBackColor = true; + DeleteButton.Click += DeleteButton_Click; + // + // RefreshButton + // + RefreshButton.Location = new Point(583, 117); + RefreshButton.Name = "RefreshButton"; + RefreshButton.Size = new Size(205, 29); + RefreshButton.TabIndex = 4; + RefreshButton.Text = "Обновить"; + RefreshButton.UseVisualStyleBackColor = true; + RefreshButton.Click += RefreshButton_Click; + // + // ImplementersForm + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(RefreshButton); + Controls.Add(DeleteButton); + Controls.Add(ChangeButton); + Controls.Add(CreateButton); + Controls.Add(dataGridView1); + Name = "ImplementersForm"; + Text = "Исполнители"; + Load += ImplementersForm_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView1).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView1; + private Button CreateButton; + private Button ChangeButton; + private Button DeleteButton; + private Button RefreshButton; + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/ImplementersForm.cs b/BlacksmithWorkshop/BlacksmithWorkshop/ImplementersForm.cs new file mode 100644 index 0000000..7a6934e --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/ImplementersForm.cs @@ -0,0 +1,113 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace BlacksmithWorkshop +{ + public partial class ImplementersForm : Form + { + private readonly ILogger _logger; + private readonly IImplementerLogic _logic; + public ImplementersForm(ILogger logger, IImplementerLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + private void ImplementersForm_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView1.DataSource = list; + dataGridView1.Columns["Id"].Visible = false; + dataGridView1.Columns["ImplementerFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView1.Columns["Password"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView1.Columns["Qualification"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView1.Columns["WorkExperience"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка компонентов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки исполнителей"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void CreateButton_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(ImplementerForm)); + if (service is ImplementerForm form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + private void ChangeButton_Click(object sender, EventArgs e) + { + if (dataGridView1.SelectedRows.Count == 1) + { + var service = + Program.ServiceProvider?.GetService(typeof(ImplementerForm)); + if (service is ImplementerForm form) + { + form.Id = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + private void DeleteButton_Click(object sender, EventArgs e) + { + if (dataGridView1.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", + MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridView1.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 RefreshButton_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/ImplementersForm.resx b/BlacksmithWorkshop/BlacksmithWorkshop/ImplementersForm.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/ImplementersForm.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/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs b/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs index f80fc7f..b8d0edc 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs @@ -48,6 +48,9 @@ namespace BlacksmithWorkshop services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -58,6 +61,8 @@ namespace BlacksmithWorkshop services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/ImplementerLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/ImplementerLogic.cs new file mode 100644 index 0000000..e74c712 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/ImplementerLogic.cs @@ -0,0 +1,126 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.BusinessLogicsContracts; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.StoragesContracts; +using BlacksmithWorkshopContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopBusinessLogic.BusinessLogics +{ + public class ImplementerLogic : IImplementerLogic + { + 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:{ClientFIO}. 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/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs index a77a22a..282e732 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs @@ -17,13 +17,29 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogics { private readonly ILogger _logger; private readonly IOrderStorage _orderStorage; + static readonly object locker = new object(); public OrderLogic(ILogger logger, IOrderStorage orderStorage) { _logger = logger; _orderStorage = orderStorage; } - + public OrderViewModel? ReadElement(OrderSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. Id:{ Id}", model.Id); + var element = _orderStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } public List? ReadList(OrderSearchModel? model) { _logger.LogInformation("ReadList. Id:{ Id}", model?.Id); @@ -37,7 +53,6 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogics _logger.LogInformation("ReadList. Count:{Count}", list.Count); return list; } - public bool CreateOrder(OrderBindingModel model) { CheckModel(model); @@ -50,10 +65,9 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogics } return true; } - public bool ChangeStatus(OrderBindingModel model, OrderStatus status) { - CheckModel(model); + CheckModel(model, false); var element = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id }); if (element == null) { @@ -68,27 +82,27 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogics model.Status = status; if (model.Status == OrderStatus.Выдан) model.DateImplement = DateTime.Now; + if (element.ImplementerId.HasValue) + model.ImplementerId = element.ImplementerId; _orderStorage.Update(model); return true; } - public bool TakeOrderInWork(OrderBindingModel model) { - return ChangeStatus(model, OrderStatus.Выполняется); + lock (locker) + { + return ChangeStatus(model, OrderStatus.Выполняется); + } } - public bool FinishOrder(OrderBindingModel model) { return ChangeStatus(model, OrderStatus.Готов); } - public bool DeliveryOrder(OrderBindingModel model) { return ChangeStatus(model, OrderStatus.Выдан); } - - private void CheckModel(OrderBindingModel model, bool withParams = - true) + private void CheckModel(OrderBindingModel model, bool withParams = true) { if (model == null) { diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/WorkModeling.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/WorkModeling.cs new file mode 100644 index 0000000..c902441 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/WorkModeling.cs @@ -0,0 +1,137 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.BusinessLogicsContracts; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopDataModels.Enums; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopBusinessLogic.BusinessLogics +{ + 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.Принят + }); + if (orders == null || orders.Count == 0) + { + _logger.LogWarning("DoWork. Orders is null or empty"); + return; + } + _logger.LogDebug("DoWork for {Count} orders", orders.Count); + foreach (var implementer in implementers) + { + Task.Run(() => WorkerWorkAsync(implementer, orders)); + } + } + /// Иммитация работы исполнителя + 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); + // пытаемся назначить заказ на исполнителя + _orderLogic.TakeOrderInWork(new OrderBindingModel + { + Id = order.Id, + ImplementerId = implementer.Id + }); + // делаем работу + Thread.Sleep(implementer.WorkExperience * _rnd.Next(100, + 1000) * order.Count); + _logger.LogDebug("DoWork. Worker {Id} finish order { Order}", implementer.Id, order.Id); + _orderLogic.FinishOrder(new OrderBindingModel + { + Id = order.Id + }); + } + // кто-то мог уже перехватить заказ, игнорируем ошибку + 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/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ImplementerBindingModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ImplementerBindingModel.cs new file mode 100644 index 0000000..7a3ec35 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/ImplementerBindingModel.cs @@ -0,0 +1,18 @@ +using BlacksmithWorkshopDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopContracts.BindingModels +{ + public class ImplementerBindingModel : IImplementerModel + { + public int Id { get; set; } + public string ImplementerFIO { get; set; } = string.Empty; + public int WorkExperience { get; set; } = 0; + public int Qualification { get; set; } = 0; + public string Password { get; set; } = string.Empty; + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/OrderBindingModel .cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/OrderBindingModel .cs index 7bd89c8..f8da514 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/OrderBindingModel .cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BindingModels/OrderBindingModel .cs @@ -18,6 +18,7 @@ namespace BlacksmithWorkshopContracts.BindingModels public int Count { get; set; } public double Sum { get; set; } + public int? ImplementerId { get; set; } = null; public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IImplementerLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IImplementerLogic.cs new file mode 100644 index 0000000..551bcf1 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IImplementerLogic.cs @@ -0,0 +1,20 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopContracts.BusinessLogicsContracts +{ + public interface IImplementerLogic + { + List? ReadList(ImplementerSearchModel? model); + ImplementerViewModel? ReadElement(ImplementerSearchModel model); + bool Create(ImplementerBindingModel model); + bool Update(ImplementerBindingModel model); + bool Delete(ImplementerBindingModel model); + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IOrderLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IOrderLogic.cs index bdd54b4..0634b84 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IOrderLogic.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -16,5 +16,6 @@ namespace BlacksmithWorkshopContracts.BusinessLogicsContracts bool TakeOrderInWork(OrderBindingModel model); bool FinishOrder(OrderBindingModel model); bool DeliveryOrder(OrderBindingModel model); + OrderViewModel? ReadElement(OrderSearchModel model); } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IWorkProcess.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IWorkProcess.cs new file mode 100644 index 0000000..8b5f34a --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/BusinessLogicsContracts/IWorkProcess.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopContracts.BusinessLogicsContracts +{ + public interface IWorkProcess + { + void DoWork(IImplementerLogic implementerLogic, IOrderLogic orderLogic); + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/ImplementerSearchModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/ImplementerSearchModel.cs new file mode 100644 index 0000000..eae8594 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/ImplementerSearchModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopContracts.SearchModels +{ + public class ImplementerSearchModel + { + public int? Id { get; set; } + public string? ImplementerFIO { get; set; } = string.Empty; + public string? Password { get; set; } = string.Empty; + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/OrderSearchModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/OrderSearchModel.cs index e0e42b2..1027069 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/OrderSearchModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/SearchModels/OrderSearchModel.cs @@ -1,4 +1,5 @@ -using System; +using BlacksmithWorkshopDataModels.Enums; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -12,5 +13,7 @@ namespace BlacksmithWorkshopContracts.SearchModels public DateTime? DateFrom { get; set; } public DateTime? DateTo { get; set; } public int? ClientId { get; set; } + public int? ImplementerId { get; set; } + public OrderStatus? Status { get; set; } } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IImplementerStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IImplementerStorage.cs new file mode 100644 index 0000000..9dadb14 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/StoragesContracts/IImplementerStorage.cs @@ -0,0 +1,21 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopContracts.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/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ImplementerViewModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ImplementerViewModel.cs new file mode 100644 index 0000000..58ee191 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/ImplementerViewModel.cs @@ -0,0 +1,23 @@ +using BlacksmithWorkshopDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopContracts.ViewModels +{ + public class ImplementerViewModel : IImplementerModel + { + public int Id { get; set; } + [DisplayName("ФИО исполнителя")] + public string ImplementerFIO { get; set; } = string.Empty; + [DisplayName("Стаж работы")] + public int WorkExperience { get; set; } = 0; + [DisplayName("Квалификация")] + public int Qualification { get; set; } = 0; + [DisplayName("Пароль")] + public string Password { get; set; } = string.Empty; + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/OrderViewModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/OrderViewModel.cs index d895345..0cd267f 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/OrderViewModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopContracts/ViewModels/OrderViewModel.cs @@ -13,6 +13,7 @@ namespace BlacksmithWorkshopContracts.ViewModels { [DisplayName("Номер")] public int Id { get; set; } + public int? ImplementerId { get; set; } = null; public int ClientId { get; set; } [DisplayName("Клиент")] public string ClientFIO { get; set; } = string.Empty; @@ -25,6 +26,8 @@ namespace BlacksmithWorkshopContracts.ViewModels public double Sum { get; set; } [DisplayName("Статус")] public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; + [DisplayName("Исполнитель")] + public string ImplementerFIO { get; set; } = string.Empty; [DisplayName("Дата создания")] public DateTime DateCreate { get; set; } = DateTime.Now; [DisplayName("Дата выполнения")] diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IImplementerModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IImplementerModel.cs new file mode 100644 index 0000000..c8e1951 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IImplementerModel.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopDataModels.Models +{ + public interface IImplementerModel + { + string ImplementerFIO { get; } + string Password { get; } + int WorkExperience { get; } + int Qualification { get; } + + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IOrderModel.cs b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IOrderModel.cs index 58c843d..29c8fff 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IOrderModel.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Models/IOrderModel.cs @@ -13,6 +13,7 @@ namespace BlacksmithWorkshopDataModels.Models int ClientId { get; } int Count { get; } double Sum { get; } + int? ImplementerId { get; } OrderStatus Status { get; } DateTime DateCreate { get; } DateTime? DateImplement { get; } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/BlacksmithWorkshopDataBase.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/BlacksmithWorkshopDataBase.cs index 77782a7..8d7ee0a 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/BlacksmithWorkshopDataBase.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/BlacksmithWorkshopDataBase.cs @@ -1,4 +1,5 @@ using BlacksmithWorkshopDatabaseImplement.Models; +using BlacksmithWorkshopDataModels.Models; using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; @@ -23,5 +24,7 @@ namespace BlacksmithWorkshopDatabaseImplement public virtual DbSet ManufactureComponents { set; get; } public virtual DbSet Orders { set; get; } public virtual DbSet Clients { set; get; } + public virtual DbSet Implementers { set; get; } + } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/ImplementerStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..77b15ab --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,82 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.StoragesContracts; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopDatabaseImplement.Implements +{ + public class ImplementerStorage : IImplementerStorage + { + public ImplementerViewModel? Delete(ImplementerBindingModel model) + { + using var context = new BlacksmithWorkshopDataBase(); + var res = context.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (res != null) + { + context.Implementers.Remove(res); + context.SaveChanges(); + } + return res?.GetViewModel; + } + public ImplementerViewModel? GetElement(ImplementerSearchModel model) + { + if (string.IsNullOrEmpty(model.ImplementerFIO) && string.IsNullOrEmpty(model.Password) && + !model.Id.HasValue) + { + return null; + } + using var context = new BlacksmithWorkshopDataBase(); + return context.Implementers + .FirstOrDefault(x => (string.IsNullOrEmpty(model.ImplementerFIO) || x.ImplementerFIO == model.ImplementerFIO) && + (!model.Id.HasValue || x.Id == model.Id) && + (string.IsNullOrEmpty(model.Password) || x.Password == model.Password)) + ?.GetViewModel; + } + public List GetFilteredList(ImplementerSearchModel model) + { + if (model == null) + { + return new(); + } + if (model.Id.HasValue) + { + var res = GetElement(model); + return res != null ? new() { res } : new(); + } + return new(); + } + public List GetFullList() + { + using var context = new BlacksmithWorkshopDataBase(); + return context.Implementers.Select(x => x.GetViewModel).ToList(); + } + public ImplementerViewModel? Insert(ImplementerBindingModel model) + { + using var context = new BlacksmithWorkshopDataBase(); + var res = Implementer.Create(model); + if (res != null) + { + context.Implementers.Add(res); + context.SaveChanges(); + } + return res?.GetViewModel; + } + public ImplementerViewModel? Update(ImplementerBindingModel model) + { + using var context = new BlacksmithWorkshopDataBase(); + var res = context.Implementers.FirstOrDefault(x => x.Id == model.Id); + if (res != null) + { + res.Update(model); + context.SaveChanges(); + } + return res?.GetViewModel; + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/OrderStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/OrderStorage.cs index c976717..26e0798 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/OrderStorage.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Implements/OrderStorage.cs @@ -20,6 +20,7 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements return context.Orders .Include(x => x.Manufacture) .Include(x => x.Client) + .Include(x => x.Implementer) .Select(x => x.GetViewModel) .ToList(); } @@ -29,12 +30,13 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements return context.Orders .Include(x => x.Manufacture) .Include(x => x.Client) + .Include(x => x.Implementer) .Where(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.ClientId.HasValue || x.ClientId == model.ClientId) && + (!model.Status.HasValue || x.Status == model.Status)) ) .Select(x => x.GetViewModel) .ToList(); @@ -47,9 +49,14 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements } using var context = new BlacksmithWorkshopDataBase(); return context.Orders - .Include(x => x.Manufacture) - .Include(x => x.Client) - .FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; + .Include(x => x.Manufacture) + .Include(x => x.Client) + .Include(x => x.Implementer) + .FirstOrDefault( + x => (model.Id.HasValue && x.Id == model.Id) || + (model.ImplementerId.HasValue && model.Status.HasValue && + x.ImplementerId == model.ImplementerId && x.Status == model.Status))? + .GetViewModel; } public OrderViewModel? Insert(OrderBindingModel model) { @@ -69,6 +76,7 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements var order = context.Orders .Include(x => x.Manufacture) .Include(x => x.Client) + .Include(x => x.Implementer) .FirstOrDefault(x => x.Id == model.Id); if (order == null) { @@ -84,6 +92,7 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements var element = context.Orders .Include(x => x.Manufacture) .Include(x => x.Client) + .Include(x => x.Implementer) .FirstOrDefault(rec => rec.Id == model.Id); if (element != null) { diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Implementer.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Implementer.cs new file mode 100644 index 0000000..7d07cf7 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Implementer.cs @@ -0,0 +1,64 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopDatabaseImplement.Models; +using BlacksmithWorkshopContracts.ViewModels; + +namespace BlacksmithWorkshopDataModels.Models +{ + public class Implementer : IImplementerModel + { + public int Id { get; private set; } + [Required] + public string ImplementerFIO { get; private set; } = string.Empty; + [Required] + public string Password { get; set; } = string.Empty; + [Required] + public int Qualification { get; set; } = 0; + [Required] + public int WorkExperience { get; set; } = 0; + [ForeignKey("ImplementerId")] + public virtual List Orders { 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, + Password = Password, + Qualification = Qualification, + ImplementerFIO = ImplementerFIO, + WorkExperience = WorkExperience, + }; + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Order.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Order.cs index 377e303..852f053 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Order.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Models/Order.cs @@ -29,6 +29,8 @@ namespace BlacksmithWorkshopDatabaseImplement.Models [Required] public int ManufactureId { get; private set; } public virtual Manufacture? Manufacture { get; set; } + public int? ImplementerId { get; private set; } = null; + public virtual Implementer? Implementer { get; private set; } public static Order Create(OrderBindingModel model) { @@ -42,6 +44,7 @@ namespace BlacksmithWorkshopDatabaseImplement.Models DateImplement = model.DateImplement, ManufactureId = model.ManufactureId, ClientId = model.ClientId, + ImplementerId = model.ImplementerId, }; } public void Update(OrderBindingModel? model) @@ -51,7 +54,8 @@ namespace BlacksmithWorkshopDatabaseImplement.Models return; } Status = model.Status; - DateImplement = model.DateImplement; + DateImplement = model.DateImplement; + ImplementerId = model.ImplementerId; } public OrderViewModel GetViewModel => new() { @@ -65,6 +69,8 @@ namespace BlacksmithWorkshopDatabaseImplement.Models Id = Id, ClientId = ClientId, ClientFIO = Client?.ClientFIO ?? string.Empty, + ImplementerId = ImplementerId, + ImplementerFIO = Implementer != null ? Implementer.ImplementerFIO : string.Empty }; } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/DataListSingleton.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/DataListSingleton.cs index 4c59148..bd1cc04 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/DataListSingleton.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/DataListSingleton.cs @@ -14,12 +14,14 @@ namespace BlacksmithWorkshopListImplement public List Orders { get; set; } public List Manufactures { get; set; } public List Clients { get; set; } + public List Implementers { get; set; } private DataListSingleton() { Components = new List(); Orders = new List(); Manufactures = new List(); Clients = new List(); + Implementers = new List(); } public static DataListSingleton GetInstance() { diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/ImplementerStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..cda5043 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,102 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.StoragesContracts; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopListImplement.Implements +{ + public class ImplementerStorage : IImplementerStorage + { + private readonly DataListSingleton _source; + public ImplementerStorage() + { + _source = DataListSingleton.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) + { + var result = new List(); + if (string.IsNullOrEmpty(model.ImplementerFIO) && string.IsNullOrEmpty(model.Password)) + { + return result; + } + foreach (var implementer in _source.Implementers) + { + if (model.ImplementerFIO != null && implementer.ImplementerFIO.Contains(model.ImplementerFIO)) + { + result.Add(implementer.GetViewModel); + } + } + return result; + } + public ImplementerViewModel? GetElement(ImplementerSearchModel model) + { + foreach (var implementer in _source.Implementers) + { + if ((string.IsNullOrEmpty(model.ImplementerFIO) || implementer.ImplementerFIO == model.ImplementerFIO) && + (!model.Id.HasValue || implementer.Id == model.Id) && (string.IsNullOrEmpty(model.Password) || implementer.Password == model.Password)) + { + return implementer.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 newImplementer = Implementer.Create(model); + if (newImplementer == null) + { + return null; + } + _source.Implementers.Add(newImplementer); + return newImplementer.GetViewModel; + } + public ImplementerViewModel? Update(ImplementerBindingModel model) + { + foreach (var implementer in _source.Implementers) + { + if (model.Id == implementer.Id) + { + implementer.Update(model); + return implementer.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; + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs index 4b3aeac..1b2dee0 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs @@ -36,7 +36,8 @@ namespace BlacksmithWorkshopListImplement.Implements if ((!model.Id.HasValue || order.Id == model.Id) && (!model.DateFrom.HasValue || order.DateCreate >= model.DateFrom) && (!model.DateTo.HasValue || order.DateCreate <= model.DateTo) && - (!model.ClientId.HasValue || order.ClientId == model.ClientId)) + (!model.ClientId.HasValue || order.ClientId == model.ClientId) && + (!model.Status.HasValue || order.Status == model.Status)) { result.Add(AccessStorage(order.GetViewModel)); } @@ -51,9 +52,11 @@ namespace BlacksmithWorkshopListImplement.Implements } foreach (var order in _source.Orders) { - if (model.Id.HasValue && order.Id == model.Id) + if ((model.Id.HasValue && order.Id == model.Id) || + (model.ImplementerId.HasValue && model.Status.HasValue && + order.ImplementerId == model.ImplementerId && order.Status == model.Status)) { - return order.GetViewModel; + return AccessStorage(order.GetViewModel); } } return null; @@ -103,17 +106,17 @@ namespace BlacksmithWorkshopListImplement.Implements } public OrderViewModel AccessStorage(OrderViewModel model) { - var client = _source.Clients.FirstOrDefault(x => x.Id == model.ClientId); + if (model == null) + return null; + var iceCream = _source.Manufactures.FirstOrDefault(x => x.Id == model.Id); + var client = _source.Clients.FirstOrDefault(x => x.Id == model.Id); + var implementer = _source.Implementers.FirstOrDefault(x => x.Id == model.ImplementerId); + if (iceCream != null) + model.ManufactureName = iceCream.ManufactureName; if (client != null) model.ClientFIO = client.ClientFIO; - foreach (var Manufacture in _source.Manufactures) - { - if (Manufacture.Id == model.ManufactureId) - { - model.ManufactureName = Manufacture.ManufactureName; - break; - } - } + if (implementer != null) + model.ImplementerFIO = implementer.ImplementerFIO; return model; } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Implementer.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Implementer.cs new file mode 100644 index 0000000..79c8a4e --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Implementer.cs @@ -0,0 +1,54 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopListImplement.Models +{ + public class Implementer : IImplementerModel + { + public int Id { get; private set; } + public string ImplementerFIO { get; private set; } = string.Empty; + public string Password { get; set; } = string.Empty; + public int WorkExperience { get; set; } = 0; + public int Qualification { get; set; } = 0; + public static Implementer? Create(ImplementerBindingModel model) + { + if (model == null) + { + return null; + } + return new Implementer() + { + Id = model.Id, + ImplementerFIO = model.ImplementerFIO, + Password = model.Password, + WorkExperience = model.WorkExperience, + Qualification = model.Qualification + }; + } + public void Update(ImplementerBindingModel model) + { + if (model == null) + { + return; + } + ImplementerFIO = model.ImplementerFIO; + Password = model.Password; + WorkExperience = model.WorkExperience; + Qualification = model.Qualification; + } + public ImplementerViewModel GetViewModel => new() + { + Id = Id, + ImplementerFIO = ImplementerFIO, + Password = Password, + WorkExperience = WorkExperience, + Qualification = Qualification + }; + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order .cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order .cs index a41914d..843ed78 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order .cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order .cs @@ -15,6 +15,7 @@ namespace BlacksmithWorkshopListImplement.Models public int Id { get; private set; } public int ManufactureId { get; private set; } public int ClientId { 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; } @@ -37,6 +38,7 @@ namespace BlacksmithWorkshopListImplement.Models Status = model.Status, DateCreate = model.DateCreate, DateImplement = model.DateImplement, + ImplementerId = model.ImplementerId }; } public void Update(OrderBindingModel? model) @@ -47,6 +49,7 @@ namespace BlacksmithWorkshopListImplement.Models } Status = model.Status; DateImplement = model.DateImplement; + ImplementerId = model.ImplementerId; } public OrderViewModel GetViewModel => new() { @@ -58,6 +61,7 @@ namespace BlacksmithWorkshopListImplement.Models Status = Status, DateCreate = DateCreate, DateImplement = DateImplement, + ImplementerId = ImplementerId, }; } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopRestApi/BlacksmithWorkshopRestApi.csproj b/BlacksmithWorkshop/BlacksmithWorkshopRestApi/BlacksmithWorkshopRestApi.csproj index 4be2400..d41ceab 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopRestApi/BlacksmithWorkshopRestApi.csproj +++ b/BlacksmithWorkshop/BlacksmithWorkshopRestApi/BlacksmithWorkshopRestApi.csproj @@ -21,10 +21,6 @@ - - - - diff --git a/BlacksmithWorkshop/BlacksmithWorkshopRestApi/Controllers/ImplementerController.cs b/BlacksmithWorkshop/BlacksmithWorkshopRestApi/Controllers/ImplementerController.cs new file mode 100644 index 0000000..1fd2db5 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopRestApi/Controllers/ImplementerController.cs @@ -0,0 +1,101 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.BusinessLogicsContracts; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopDataModels.Enums; +using Microsoft.AspNetCore.Mvc; + +namespace BlacksmithWorkshopRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class ImplementerController : ControllerBase + { + 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 5d72ed77eadded5449e44f2375f22aaefa13c8e8 Mon Sep 17 00:00:00 2001 From: Zakharov_Rostislav Date: Mon, 22 Apr 2024 20:56:24 +0400 Subject: [PATCH 02/15] lab-6 add migration addingImplementors --- ...40422165434_addingImplementors.Designer.cs | 257 ++++++++++++++++++ .../20240422165434_addingImplementors.cs | 67 +++++ ...BlacksmithWorkshopDataBaseModelSnapshot.cs | 43 +++ 3 files changed, 367 insertions(+) create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240422165434_addingImplementors.Designer.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240422165434_addingImplementors.cs diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240422165434_addingImplementors.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240422165434_addingImplementors.Designer.cs new file mode 100644 index 0000000..c6b2862 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240422165434_addingImplementors.Designer.cs @@ -0,0 +1,257 @@ +// +using System; +using BlacksmithWorkshopDatabaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace BlacksmithWorkshopDatabaseImplement.Migrations +{ + [DbContext(typeof(BlacksmithWorkshopDataBase))] + [Migration("20240422165434_addingImplementors")] + partial class addingImplementors + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.16") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("BlacksmithWorkshopDataModels.Models.Implementer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ImplementerFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Qualification") + .HasColumnType("int"); + + b.Property("WorkExperience") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Implementers"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Client", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Email") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Clients"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Component", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Cost") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Components"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ManufactureName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Price") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Manufactures"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.ManufactureComponent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("ManufactureId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ComponentId"); + + b.HasIndex("ManufactureId"); + + b.ToTable("ManufactureComponents"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("DateCreate") + .HasColumnType("datetime2"); + + b.Property("DateImplement") + .HasColumnType("datetime2"); + + b.Property("ImplementerId") + .HasColumnType("int"); + + b.Property("ManufactureId") + .HasColumnType("int"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("Sum") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.HasIndex("ClientId"); + + b.HasIndex("ImplementerId"); + + b.HasIndex("ManufactureId"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.ManufactureComponent", b => + { + b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Component", "Component") + .WithMany("ManufactureComponents") + .HasForeignKey("ComponentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", "Manufacture") + .WithMany("Components") + .HasForeignKey("ManufactureId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Component"); + + b.Navigation("Manufacture"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Order", b => + { + b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Client", "Client") + .WithMany("Orders") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("BlacksmithWorkshopDataModels.Models.Implementer", "Implementer") + .WithMany("Orders") + .HasForeignKey("ImplementerId"); + + b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", "Manufacture") + .WithMany("Orders") + .HasForeignKey("ManufactureId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Client"); + + b.Navigation("Implementer"); + + b.Navigation("Manufacture"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDataModels.Models.Implementer", b => + { + b.Navigation("Orders"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Client", b => + { + b.Navigation("Orders"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Component", b => + { + b.Navigation("ManufactureComponents"); + }); + + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", b => + { + b.Navigation("Components"); + + b.Navigation("Orders"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240422165434_addingImplementors.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240422165434_addingImplementors.cs new file mode 100644 index 0000000..d6ee27e --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240422165434_addingImplementors.cs @@ -0,0 +1,67 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace BlacksmithWorkshopDatabaseImplement.Migrations +{ + /// + public partial class addingImplementors : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "ImplementerId", + table: "Orders", + type: "int", + nullable: true); + + migrationBuilder.CreateTable( + name: "Implementers", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ImplementerFIO = table.Column(type: "nvarchar(max)", nullable: false), + Password = table.Column(type: "nvarchar(max)", nullable: false), + Qualification = table.Column(type: "int", nullable: false), + WorkExperience = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Implementers", x => x.Id); + }); + + migrationBuilder.CreateIndex( + name: "IX_Orders_ImplementerId", + table: "Orders", + column: "ImplementerId"); + + 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.DropTable( + name: "Implementers"); + + migrationBuilder.DropIndex( + name: "IX_Orders_ImplementerId", + table: "Orders"); + + migrationBuilder.DropColumn( + name: "ImplementerId", + table: "Orders"); + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/BlacksmithWorkshopDataBaseModelSnapshot.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/BlacksmithWorkshopDataBaseModelSnapshot.cs index 161a546..8aafc9b 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/BlacksmithWorkshopDataBaseModelSnapshot.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/BlacksmithWorkshopDataBaseModelSnapshot.cs @@ -22,6 +22,33 @@ namespace BlacksmithWorkshopDatabaseImplement.Migrations SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + modelBuilder.Entity("BlacksmithWorkshopDataModels.Models.Implementer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ImplementerFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Qualification") + .HasColumnType("int"); + + b.Property("WorkExperience") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Implementers"); + }); + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Client", b => { b.Property("Id") @@ -133,6 +160,9 @@ namespace BlacksmithWorkshopDatabaseImplement.Migrations b.Property("DateImplement") .HasColumnType("datetime2"); + b.Property("ImplementerId") + .HasColumnType("int"); + b.Property("ManufactureId") .HasColumnType("int"); @@ -146,6 +176,8 @@ namespace BlacksmithWorkshopDatabaseImplement.Migrations b.HasIndex("ClientId"); + b.HasIndex("ImplementerId"); + b.HasIndex("ManufactureId"); b.ToTable("Orders"); @@ -178,6 +210,10 @@ namespace BlacksmithWorkshopDatabaseImplement.Migrations .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + b.HasOne("BlacksmithWorkshopDataModels.Models.Implementer", "Implementer") + .WithMany("Orders") + .HasForeignKey("ImplementerId"); + b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", "Manufacture") .WithMany("Orders") .HasForeignKey("ManufactureId") @@ -186,9 +222,16 @@ namespace BlacksmithWorkshopDatabaseImplement.Migrations b.Navigation("Client"); + b.Navigation("Implementer"); + b.Navigation("Manufacture"); }); + modelBuilder.Entity("BlacksmithWorkshopDataModels.Models.Implementer", b => + { + b.Navigation("Orders"); + }); + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Client", b => { b.Navigation("Orders"); -- 2.25.1 From 05ac38f5f94bd7016601157755e9bc6d32f14344 Mon Sep 17 00:00:00 2001 From: Zakharov_Rostislav Date: Mon, 22 Apr 2024 21:24:16 +0400 Subject: [PATCH 03/15] lab-6 some changes in FormMain --- .../BlacksmithWorkshop/FormMain.Designer.cs | 16 ++++++++-------- .../BlacksmithWorkshop/FormMain.cs | 7 ++++--- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs index 76a5c06..a7639bd 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs @@ -54,7 +54,7 @@ menuStrip.Items.AddRange(new ToolStripItem[] { GuidesToolStripMenuItem, ReportsToolStripMenuItem }); menuStrip.Location = new Point(0, 0); menuStrip.Name = "menuStrip"; - menuStrip.Size = new Size(1011, 24); + menuStrip.Size = new Size(1267, 24); menuStrip.TabIndex = 0; menuStrip.Text = "Меню"; // @@ -134,12 +134,12 @@ dataGridView.Location = new Point(0, 23); dataGridView.Name = "dataGridView"; dataGridView.RowTemplate.Height = 25; - dataGridView.Size = new Size(847, 427); + dataGridView.Size = new Size(1101, 427); dataGridView.TabIndex = 1; // // buttonCreateOrder // - buttonCreateOrder.Location = new Point(853, 38); + buttonCreateOrder.Location = new Point(1107, 27); buttonCreateOrder.Name = "buttonCreateOrder"; buttonCreateOrder.Size = new Size(148, 31); buttonCreateOrder.TabIndex = 2; @@ -149,7 +149,7 @@ // // buttonRefresh // - buttonRefresh.Location = new Point(853, 186); + buttonRefresh.Location = new Point(1107, 175); buttonRefresh.Name = "buttonRefresh"; buttonRefresh.Size = new Size(148, 31); buttonRefresh.TabIndex = 3; @@ -159,7 +159,7 @@ // // buttonIssued // - buttonIssued.Location = new Point(853, 149); + buttonIssued.Location = new Point(1107, 138); buttonIssued.Name = "buttonIssued"; buttonIssued.Size = new Size(148, 31); buttonIssued.TabIndex = 4; @@ -169,7 +169,7 @@ // // buttonReady // - buttonReady.Location = new Point(853, 112); + buttonReady.Location = new Point(1107, 101); buttonReady.Name = "buttonReady"; buttonReady.Size = new Size(148, 31); buttonReady.TabIndex = 5; @@ -179,7 +179,7 @@ // // buttonTakeInWork // - buttonTakeInWork.Location = new Point(853, 75); + buttonTakeInWork.Location = new Point(1107, 64); buttonTakeInWork.Name = "buttonTakeInWork"; buttonTakeInWork.Size = new Size(148, 31); buttonTakeInWork.TabIndex = 6; @@ -191,7 +191,7 @@ // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(1011, 450); + ClientSize = new Size(1267, 450); Controls.Add(buttonTakeInWork); Controls.Add(buttonReady); Controls.Add(buttonIssued); diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs index be207e7..70600d7 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs @@ -52,8 +52,10 @@ namespace BlacksmithWorkshop dataGridView.DataSource = list; dataGridView.Columns["ManufactureId"].Visible = false; dataGridView.Columns["ImplementerId"].Visible = false; - dataGridView.Columns["ManufactureName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; dataGridView.Columns["ClientId"].Visible = false; + dataGridView.Columns["ManufactureName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["ClientFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["ImplementerFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; } _logger.LogInformation("Загрузка заказов"); } @@ -97,8 +99,7 @@ namespace BlacksmithWorkshop { if (dataGridView.SelectedRows.Count == 1) { - int id = - Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); _logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id); try { -- 2.25.1 From 6b0de7b41d44aee0f9a73780d4bdbb0fd7867123 Mon Sep 17 00:00:00 2001 From: Zakharov_Rostislav Date: Mon, 22 Apr 2024 21:26:39 +0400 Subject: [PATCH 04/15] lab-6 some minor fixes --- .../Implements/OrderStorage.cs | 6 +++--- .../Implements/OrderStorage.cs | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Implements/OrderStorage.cs b/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Implements/OrderStorage.cs index 813bb70..cb9c984 100644 --- a/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Implements/OrderStorage.cs +++ b/BlacksmithWorkshop/BlackcmithWorkshopFileImplement/Implements/OrderStorage.cs @@ -88,11 +88,11 @@ namespace BlacksmithWorkshopFileImplement.Implements } public OrderViewModel? AccessStorage(OrderViewModel model) { - var iceCream = source.Manufactures.FirstOrDefault(x => x.Id == model.Id); + var manufacture = source.Manufactures.FirstOrDefault(x => x.Id == model.Id); var client = source.Clients.FirstOrDefault(x => x.Id == model.Id); var implementer = source.Implementers.FirstOrDefault(x => x.Id == model.ImplementerId); - if (iceCream != null) - model.ManufactureName = iceCream.ManufactureName; + if (manufacture != null) + model.ManufactureName = manufacture.ManufactureName; if (client != null) model.ClientFIO = client.ClientFIO; if (implementer != null) diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs index 1b2dee0..98df2cc 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs @@ -108,11 +108,11 @@ namespace BlacksmithWorkshopListImplement.Implements { if (model == null) return null; - var iceCream = _source.Manufactures.FirstOrDefault(x => x.Id == model.Id); + var manufacture = _source.Manufactures.FirstOrDefault(x => x.Id == model.Id); var client = _source.Clients.FirstOrDefault(x => x.Id == model.Id); var implementer = _source.Implementers.FirstOrDefault(x => x.Id == model.ImplementerId); - if (iceCream != null) - model.ManufactureName = iceCream.ManufactureName; + if (manufacture != null) + model.ManufactureName = manufacture.ManufactureName; if (client != null) model.ClientFIO = client.ClientFIO; if (implementer != null) -- 2.25.1 From fc3da246e23f0ca84d6dd4d71195224a93300bde Mon Sep 17 00:00:00 2001 From: Zakharov_Rostislav Date: Wed, 24 Apr 2024 15:24:15 +0400 Subject: [PATCH 05/15] lab-6 some minor fixes --- .../BusinessLogics/WorkModeling.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/WorkModeling.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/WorkModeling.cs index c902441..b135f47 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/WorkModeling.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/WorkModeling.cs @@ -75,6 +75,8 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogics { Id = order.Id }); + // отдыхаем + Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100)); } // кто-то мог уже перехватить заказ, игнорируем ошибку catch (InvalidOperationException ex) @@ -87,8 +89,6 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogics _logger.LogError(ex, "Error while do work"); throw; } - // отдыхаем - Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100)); } }); } -- 2.25.1 From 5aa2ac7e17372359161adb62ae2e9c1cc3fb62ee Mon Sep 17 00:00:00 2001 From: Zakharov_Rostislav Date: Wed, 24 Apr 2024 15:53:20 +0400 Subject: [PATCH 06/15] lab-6 new fixes --- .../BusinessLogics/WorkModeling.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/WorkModeling.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/WorkModeling.cs index b135f47..5039e65 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/WorkModeling.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/WorkModeling.cs @@ -68,8 +68,7 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogics ImplementerId = implementer.Id }); // делаем работу - Thread.Sleep(implementer.WorkExperience * _rnd.Next(100, - 1000) * order.Count); + 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 { -- 2.25.1 From 906019a63d6f5d5de2b4f725a5c0e62f1b1e02fb Mon Sep 17 00:00:00 2001 From: Zakharov_Rostislav Date: Tue, 7 May 2024 17:58:51 +0400 Subject: [PATCH 07/15] preparing for pr --- .../FormCreateOrder.Designer.cs | 51 ++++++++----------- 1 file changed, 22 insertions(+), 29 deletions(-) diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormCreateOrder.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormCreateOrder.Designer.cs index 0ff4191..64c9e47 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormCreateOrder.Designer.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormCreateOrder.Designer.cs @@ -43,36 +43,35 @@ // labelName // labelName.AutoSize = true; - labelName.Location = new Point(25, 23); + labelName.Location = new Point(22, 17); labelName.Name = "labelName"; - labelName.Size = new Size(71, 20); + labelName.Size = new Size(56, 15); labelName.TabIndex = 0; labelName.Text = "Изделие:"; // // labelCount // labelCount.AutoSize = true; - labelCount.Location = new Point(25, 61); + labelCount.Location = new Point(22, 46); labelCount.Name = "labelCount"; - labelCount.Size = new Size(93, 20); + labelCount.Size = new Size(75, 15); labelCount.TabIndex = 1; labelCount.Text = "Количество:"; // // labelSum // labelSum.AutoSize = true; - labelSum.Location = new Point(25, 139); + labelSum.Location = new Point(22, 104); labelSum.Name = "labelSum"; - labelSum.Size = new Size(58, 20); + labelSum.Size = new Size(48, 15); labelSum.TabIndex = 2; labelSum.Text = "Сумма:"; // // TextBoxCount // - TextBoxCount.Location = new Point(143, 57); - TextBoxCount.Margin = new Padding(3, 4, 3, 4); + TextBoxCount.Location = new Point(125, 43); TextBoxCount.Name = "TextBoxCount"; - TextBoxCount.Size = new Size(244, 27); + TextBoxCount.Size = new Size(214, 23); TextBoxCount.TabIndex = 3; TextBoxCount.TextChanged += TextBoxCount_TextChanged; // @@ -80,29 +79,26 @@ // ComboBoxManufacture.DropDownStyle = ComboBoxStyle.DropDownList; ComboBoxManufacture.FormattingEnabled = true; - ComboBoxManufacture.Location = new Point(143, 19); - ComboBoxManufacture.Margin = new Padding(3, 4, 3, 4); + ComboBoxManufacture.Location = new Point(125, 14); ComboBoxManufacture.Name = "ComboBoxManufacture"; - ComboBoxManufacture.Size = new Size(244, 28); + ComboBoxManufacture.Size = new Size(214, 23); ComboBoxManufacture.TabIndex = 4; ComboBoxManufacture.SelectedIndexChanged += ComboBoxManufacture_SelectedIndexChanged; // // TextBoxSum // - TextBoxSum.Location = new Point(143, 135); - TextBoxSum.Margin = new Padding(3, 4, 3, 4); + TextBoxSum.Location = new Point(125, 101); TextBoxSum.Name = "TextBoxSum"; TextBoxSum.ReadOnly = true; - TextBoxSum.Size = new Size(244, 27); + TextBoxSum.Size = new Size(214, 23); TextBoxSum.TabIndex = 5; TextBoxSum.TextChanged += TextBoxSum_TextChanged; // // buttonCancel // - buttonCancel.Location = new Point(299, 173); - buttonCancel.Margin = new Padding(3, 4, 3, 4); + buttonCancel.Location = new Point(262, 130); buttonCancel.Name = "buttonCancel"; - buttonCancel.Size = new Size(88, 32); + buttonCancel.Size = new Size(77, 24); buttonCancel.TabIndex = 6; buttonCancel.Text = "Отмена"; buttonCancel.UseVisualStyleBackColor = true; @@ -110,10 +106,9 @@ // // buttonSave // - buttonSave.Location = new Point(200, 173); - buttonSave.Margin = new Padding(3, 4, 3, 4); + buttonSave.Location = new Point(175, 130); buttonSave.Name = "buttonSave"; - buttonSave.Size = new Size(93, 32); + buttonSave.Size = new Size(81, 24); buttonSave.TabIndex = 7; buttonSave.Text = "Сохранить"; buttonSave.UseVisualStyleBackColor = true; @@ -122,9 +117,9 @@ // labelClient // labelClient.AutoSize = true; - labelClient.Location = new Point(25, 100); + labelClient.Location = new Point(22, 75); labelClient.Name = "labelClient"; - labelClient.Size = new Size(61, 20); + labelClient.Size = new Size(49, 15); labelClient.TabIndex = 8; labelClient.Text = "Клиент:"; // @@ -132,17 +127,16 @@ // ComboBoxClient.DropDownStyle = ComboBoxStyle.DropDownList; ComboBoxClient.FormattingEnabled = true; - ComboBoxClient.Location = new Point(143, 96); - ComboBoxClient.Margin = new Padding(3, 4, 3, 4); + ComboBoxClient.Location = new Point(125, 72); ComboBoxClient.Name = "ComboBoxClient"; - ComboBoxClient.Size = new Size(244, 28); + ComboBoxClient.Size = new Size(214, 23); ComboBoxClient.TabIndex = 9; // // FormCreateOrder // - AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(399, 221); + ClientSize = new Size(349, 166); Controls.Add(ComboBoxClient); Controls.Add(labelClient); Controls.Add(buttonSave); @@ -153,7 +147,6 @@ Controls.Add(labelSum); Controls.Add(labelCount); Controls.Add(labelName); - Margin = new Padding(3, 4, 3, 4); Name = "FormCreateOrder"; StartPosition = FormStartPosition.CenterParent; Text = "Заказ"; -- 2.25.1 From 611b301f3dc02ec2c4d3ce5579d8dbacaa57a7e7 Mon Sep 17 00:00:00 2001 From: Zakharov_Rostislav Date: Tue, 7 May 2024 18:02:28 +0400 Subject: [PATCH 08/15] preparing for pr p.2 --- .../FormCreateOrder.Designer.cs | 270 +++++++++--------- 1 file changed, 135 insertions(+), 135 deletions(-) diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormCreateOrder.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormCreateOrder.Designer.cs index 64c9e47..16b3838 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormCreateOrder.Designer.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormCreateOrder.Designer.cs @@ -20,144 +20,144 @@ base.Dispose(disposing); } - #region Windows Form Designer generated code + #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() - { - labelName = new Label(); - labelCount = new Label(); - labelSum = new Label(); - TextBoxCount = new TextBox(); - ComboBoxManufacture = new ComboBox(); - TextBoxSum = new TextBox(); - buttonCancel = new Button(); - buttonSave = new Button(); - labelClient = new Label(); - ComboBoxClient = new ComboBox(); - SuspendLayout(); - // - // labelName - // - labelName.AutoSize = true; - labelName.Location = new Point(22, 17); - labelName.Name = "labelName"; - labelName.Size = new Size(56, 15); - labelName.TabIndex = 0; - labelName.Text = "Изделие:"; - // - // labelCount - // - labelCount.AutoSize = true; - labelCount.Location = new Point(22, 46); - labelCount.Name = "labelCount"; - labelCount.Size = new Size(75, 15); - labelCount.TabIndex = 1; - labelCount.Text = "Количество:"; - // - // labelSum - // - labelSum.AutoSize = true; - labelSum.Location = new Point(22, 104); - labelSum.Name = "labelSum"; - labelSum.Size = new Size(48, 15); - labelSum.TabIndex = 2; - labelSum.Text = "Сумма:"; - // - // TextBoxCount - // - TextBoxCount.Location = new Point(125, 43); - TextBoxCount.Name = "TextBoxCount"; - TextBoxCount.Size = new Size(214, 23); - TextBoxCount.TabIndex = 3; - TextBoxCount.TextChanged += TextBoxCount_TextChanged; - // - // ComboBoxManufacture - // - ComboBoxManufacture.DropDownStyle = ComboBoxStyle.DropDownList; - ComboBoxManufacture.FormattingEnabled = true; - ComboBoxManufacture.Location = new Point(125, 14); - ComboBoxManufacture.Name = "ComboBoxManufacture"; - ComboBoxManufacture.Size = new Size(214, 23); - ComboBoxManufacture.TabIndex = 4; - ComboBoxManufacture.SelectedIndexChanged += ComboBoxManufacture_SelectedIndexChanged; - // - // TextBoxSum - // - TextBoxSum.Location = new Point(125, 101); - TextBoxSum.Name = "TextBoxSum"; - TextBoxSum.ReadOnly = true; - TextBoxSum.Size = new Size(214, 23); - TextBoxSum.TabIndex = 5; - TextBoxSum.TextChanged += TextBoxSum_TextChanged; - // - // buttonCancel - // - buttonCancel.Location = new Point(262, 130); - buttonCancel.Name = "buttonCancel"; - buttonCancel.Size = new Size(77, 24); - buttonCancel.TabIndex = 6; - buttonCancel.Text = "Отмена"; - buttonCancel.UseVisualStyleBackColor = true; - buttonCancel.Click += CancelButton_Click; - // - // buttonSave - // - buttonSave.Location = new Point(175, 130); - buttonSave.Name = "buttonSave"; - buttonSave.Size = new Size(81, 24); - buttonSave.TabIndex = 7; - buttonSave.Text = "Сохранить"; - buttonSave.UseVisualStyleBackColor = true; - buttonSave.Click += SaveButton_Click; - // - // labelClient - // - labelClient.AutoSize = true; - labelClient.Location = new Point(22, 75); - labelClient.Name = "labelClient"; - labelClient.Size = new Size(49, 15); - labelClient.TabIndex = 8; - labelClient.Text = "Клиент:"; - // - // ComboBoxClient - // - ComboBoxClient.DropDownStyle = ComboBoxStyle.DropDownList; - ComboBoxClient.FormattingEnabled = true; - ComboBoxClient.Location = new Point(125, 72); - ComboBoxClient.Name = "ComboBoxClient"; - ComboBoxClient.Size = new Size(214, 23); - ComboBoxClient.TabIndex = 9; - // - // FormCreateOrder - // - AutoScaleDimensions = new SizeF(7F, 15F); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(349, 166); - Controls.Add(ComboBoxClient); - Controls.Add(labelClient); - Controls.Add(buttonSave); - Controls.Add(buttonCancel); - Controls.Add(TextBoxSum); - Controls.Add(ComboBoxManufacture); - Controls.Add(TextBoxCount); - Controls.Add(labelSum); - Controls.Add(labelCount); - Controls.Add(labelName); - Name = "FormCreateOrder"; - StartPosition = FormStartPosition.CenterParent; - Text = "Заказ"; - Load += FormCreateOrder_Load; - ResumeLayout(false); - PerformLayout(); - } + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + labelName = new Label(); + labelCount = new Label(); + labelSum = new Label(); + TextBoxCount = new TextBox(); + ComboBoxManufacture = new ComboBox(); + TextBoxSum = new TextBox(); + buttonCancel = new Button(); + buttonSave = new Button(); + labelClient = new Label(); + ComboBoxClient = new ComboBox(); + SuspendLayout(); + // + // labelName + // + labelName.AutoSize = true; + labelName.Location = new Point(22, 17); + labelName.Name = "labelName"; + labelName.Size = new Size(56, 15); + labelName.TabIndex = 0; + labelName.Text = "Изделие:"; + // + // labelCount + // + labelCount.AutoSize = true; + labelCount.Location = new Point(22, 46); + labelCount.Name = "labelCount"; + labelCount.Size = new Size(75, 15); + labelCount.TabIndex = 1; + labelCount.Text = "Количество:"; + // + // labelSum + // + labelSum.AutoSize = true; + labelSum.Location = new Point(22, 104); + labelSum.Name = "labelSum"; + labelSum.Size = new Size(48, 15); + labelSum.TabIndex = 2; + labelSum.Text = "Сумма:"; + // + // TextBoxCount + // + TextBoxCount.Location = new Point(125, 43); + TextBoxCount.Name = "TextBoxCount"; + TextBoxCount.Size = new Size(214, 23); + TextBoxCount.TabIndex = 3; + TextBoxCount.TextChanged += TextBoxCount_TextChanged; + // + // ComboBoxManufacture + // + ComboBoxManufacture.DropDownStyle = ComboBoxStyle.DropDownList; + ComboBoxManufacture.FormattingEnabled = true; + ComboBoxManufacture.Location = new Point(125, 14); + ComboBoxManufacture.Name = "ComboBoxManufacture"; + ComboBoxManufacture.Size = new Size(214, 23); + ComboBoxManufacture.TabIndex = 4; + ComboBoxManufacture.SelectedIndexChanged += ComboBoxManufacture_SelectedIndexChanged; + // + // TextBoxSum + // + TextBoxSum.Location = new Point(125, 101); + TextBoxSum.Name = "TextBoxSum"; + TextBoxSum.ReadOnly = true; + TextBoxSum.Size = new Size(214, 23); + TextBoxSum.TabIndex = 5; + TextBoxSum.TextChanged += TextBoxSum_TextChanged; + // + // buttonCancel + // + buttonCancel.Location = new Point(262, 130); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(77, 24); + buttonCancel.TabIndex = 6; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += CancelButton_Click; + // + // buttonSave + // + buttonSave.Location = new Point(175, 130); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(81, 24); + buttonSave.TabIndex = 7; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += SaveButton_Click; + // + // labelClient + // + labelClient.AutoSize = true; + labelClient.Location = new Point(22, 75); + labelClient.Name = "labelClient"; + labelClient.Size = new Size(49, 15); + labelClient.TabIndex = 8; + labelClient.Text = "Клиент:"; + // + // ComboBoxClient + // + ComboBoxClient.DropDownStyle = ComboBoxStyle.DropDownList; + ComboBoxClient.FormattingEnabled = true; + ComboBoxClient.Location = new Point(125, 72); + ComboBoxClient.Name = "ComboBoxClient"; + ComboBoxClient.Size = new Size(214, 23); + ComboBoxClient.TabIndex = 9; + // + // FormCreateOrder + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(349, 166); + Controls.Add(ComboBoxClient); + Controls.Add(labelClient); + Controls.Add(buttonSave); + Controls.Add(buttonCancel); + Controls.Add(TextBoxSum); + Controls.Add(ComboBoxManufacture); + Controls.Add(TextBoxCount); + Controls.Add(labelSum); + Controls.Add(labelCount); + Controls.Add(labelName); + Name = "FormCreateOrder"; + StartPosition = FormStartPosition.CenterParent; + Text = "Заказ"; + Load += FormCreateOrder_Load; + ResumeLayout(false); + PerformLayout(); + } - #endregion + #endregion - private Label labelName; + private Label labelName; private Label labelCount; private Label labelSum; private TextBox TextBoxCount; -- 2.25.1 From 821d25241c5cc5484442950a1a7de5aca2a9137e Mon Sep 17 00:00:00 2001 From: Zakharov_Rostislav Date: Tue, 7 May 2024 18:05:03 +0400 Subject: [PATCH 09/15] preparing for pr p.3 --- .../BlacksmithWorkshop/FormCreateOrder.Designer.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormCreateOrder.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormCreateOrder.Designer.cs index 16b3838..ae847b7 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormCreateOrder.Designer.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormCreateOrder.Designer.cs @@ -106,9 +106,9 @@ // // buttonSave // - buttonSave.Location = new Point(175, 130); + buttonSave.Location = new Point(179, 130); buttonSave.Name = "buttonSave"; - buttonSave.Size = new Size(81, 24); + buttonSave.Size = new Size(77, 24); buttonSave.TabIndex = 7; buttonSave.Text = "Сохранить"; buttonSave.UseVisualStyleBackColor = true; -- 2.25.1 From 3366feb37614850e32af94f47d9322119d9745c2 Mon Sep 17 00:00:00 2001 From: Zakharov_Rostislav Date: Tue, 7 May 2024 18:09:16 +0400 Subject: [PATCH 10/15] preparing for pr p.4 --- .../BlacksmithWorkshopRestApi.csproj | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/BlacksmithWorkshop/BlacksmithWorkshopRestApi/BlacksmithWorkshopRestApi.csproj b/BlacksmithWorkshop/BlacksmithWorkshopRestApi/BlacksmithWorkshopRestApi.csproj index d41ceab..349291b 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopRestApi/BlacksmithWorkshopRestApi.csproj +++ b/BlacksmithWorkshop/BlacksmithWorkshopRestApi/BlacksmithWorkshopRestApi.csproj @@ -21,6 +21,11 @@ + + + + + -- 2.25.1 From 82c15131d08f137db12bb4dd26402542379bcf83 Mon Sep 17 00:00:00 2001 From: Zakharov_Rostislav Date: Tue, 7 May 2024 18:10:07 +0400 Subject: [PATCH 11/15] preparing for pr p.5 --- .../BlacksmithWorkshopRestApi/BlacksmithWorkshopRestApi.csproj | 1 - 1 file changed, 1 deletion(-) diff --git a/BlacksmithWorkshop/BlacksmithWorkshopRestApi/BlacksmithWorkshopRestApi.csproj b/BlacksmithWorkshop/BlacksmithWorkshopRestApi/BlacksmithWorkshopRestApi.csproj index 349291b..4be2400 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopRestApi/BlacksmithWorkshopRestApi.csproj +++ b/BlacksmithWorkshop/BlacksmithWorkshopRestApi/BlacksmithWorkshopRestApi.csproj @@ -25,7 +25,6 @@ - -- 2.25.1 From f40d8a97af13cf286c67af856e93a71935e44238 Mon Sep 17 00:00:00 2001 From: Zakharov_Rostislav Date: Tue, 7 May 2024 19:07:57 +0400 Subject: [PATCH 12/15] lab-6-hard fix --- .../BusinessLogics/OrderLogic.cs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs index b4d748a..db921be 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs @@ -21,11 +21,9 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogics private readonly IShopLogic _shopLogic; private readonly IManufactureStorage _manufactureStorage; private readonly IShopStorage _shopStorage; + static readonly object locker = new object(); public OrderLogic(ILogger logger, IOrderStorage orderStorage, IManufactureStorage manufactureStorage, IShopLogic shopLogic, IShopStorage shopStorage) - static readonly object locker = new object(); - - public OrderLogic(ILogger logger, IOrderStorage orderStorage) { _logger = logger; _orderStorage = orderStorage; @@ -76,7 +74,6 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogics } private bool ChangeStatus(OrderBindingModel model, OrderStatus status) - public bool ChangeStatus(OrderBindingModel model, OrderStatus status) { CheckModel(model, false); var element = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id }); -- 2.25.1 From 45ca52198f191224ff06ca4b7e150f93dbdca777 Mon Sep 17 00:00:00 2001 From: Zakharov_Rostislav Date: Tue, 7 May 2024 21:50:23 +0400 Subject: [PATCH 13/15] lab-6-hard do not work --- .../BusinessLogics/OrderLogic.cs | 6 +- .../BusinessLogics/WorkModeling.cs | 63 ++++- .../Enums/OrderStatus.cs | 4 +- ...40422165434_addingImplementors.Designer.cs | 257 ------------------ .../20240422165434_addingImplementors.cs | 67 ----- ... 20240507165329_InitialCreate.Designer.cs} | 47 +++- ...ate.cs => 20240507165329_InitialCreate.cs} | 34 ++- 7 files changed, 141 insertions(+), 337 deletions(-) delete mode 100644 BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240422165434_addingImplementors.Designer.cs delete mode 100644 BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240422165434_addingImplementors.cs rename BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/{20240421170619_initialCreate.Designer.cs => 20240507165329_InitialCreate.Designer.cs} (86%) rename BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/{20240421170619_initialCreate.cs => 20240507165329_InitialCreate.cs} (86%) diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs index db921be..349ad70 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs @@ -82,12 +82,12 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogics _logger.LogWarning("Read operation failed"); return false; } - if (element.Status != status - 1) + if (!(element.Status == status - 1 || model.Status == OrderStatus.Готов)) { _logger.LogWarning("Status change operation failed"); throw new InvalidOperationException("Текущий статус заказа не может быть переведен в выбранный"); } - if (element.Status == OrderStatus.Готов) + if (element.Status == OrderStatus.Готов || element.Status == OrderStatus.Ожидает) { var manufacture = _manufactureStorage.GetElement(new ManufactureSearchModel() { Id = model.ManufactureId }); if (manufacture == null) @@ -98,7 +98,7 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogics if (CheckSupply(manufacture, model.Count) == false) { _logger.LogWarning("Status update to " + status.ToString() + " operation failed. Shop supply error."); - return false; + status = OrderStatus.Ожидает; } } model.Status = status; diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/WorkModeling.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/WorkModeling.cs index 5039e65..738afc1 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/WorkModeling.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/WorkModeling.cs @@ -31,19 +31,21 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogics _logger.LogWarning("DoWork. Implementers is null"); return; } - var orders = _orderLogic.ReadList(new OrderSearchModel + var deliveredOrders = _orderLogic.ReadList(new OrderSearchModel { - Status = OrderStatus.Принят + Status = OrderStatus.Выдан }); - if (orders == null || orders.Count == 0) + var allOrders = _orderLogic.ReadList(null); + if (deliveredOrders == null || allOrders == null || deliveredOrders.Count == allOrders.Count) { _logger.LogWarning("DoWork. Orders is null or empty"); return; } - _logger.LogDebug("DoWork for {Count} orders", orders.Count); + deliveredOrders.ForEach(x => allOrders.Remove(x)); + _logger.LogDebug("DoWork for {Count} orders", allOrders.Count); foreach (var implementer in implementers) { - Task.Run(() => WorkerWorkAsync(implementer, orders)); + Task.Run(() => WorkerWorkAsync(implementer, allOrders)); } } /// Иммитация работы исполнителя @@ -53,6 +55,7 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogics { return; } + await DeliverWaitingOrder(implementer); await RunOrderInWork(implementer); await Task.Run(() => { @@ -74,6 +77,10 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogics { Id = order.Id }); + _orderLogic.DeliveryOrder(new OrderBindingModel + { + Id = order.Id + }); // отдыхаем Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100)); } @@ -117,6 +124,10 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogics { Id = runOrder.Id }); + _orderLogic.DeliveryOrder(new OrderBindingModel + { + Id = runOrder.Id + }); // отдыхаем Thread.Sleep(implementer.Qualification * _rnd.Next(10, 100)); } @@ -132,5 +143,47 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogics throw; } } + /// Обрабатываем заказ, которые в ожидании (вдруг место освободилось) + private async Task DeliverWaitingOrder(ImplementerViewModel implementer) + { + if (_orderLogic == null || implementer == null) + { + return; + } + var waitingOrders = await Task.Run(() => _orderLogic.ReadList(new OrderSearchModel + { + ImplementerId = implementer.Id, + Status = OrderStatus.Ожидает + })); + if (waitingOrders == null || waitingOrders.Count == 0) + { + return; + } + _logger.LogInformation("DeliverWaitingOrder. Find some waitig order for implementer:{id}.Count:{count}", implementer.Id, waitingOrders.Count); + foreach (var waitingOrder in waitingOrders) + { + try + { + _logger.LogInformation("DeliverWaitingOrder. Trying to deliver order id:{id}", waitingOrder.Id); + var res = _orderLogic.DeliveryOrder(new OrderBindingModel + { + Id = waitingOrder.Id + }); + } + catch (ArgumentException ex) + { + _logger.LogWarning(ex, "DeliverWaitingOrder. Fault"); + } + catch (InvalidOperationException ex) + { + _logger.LogWarning(ex, "Error try deliver order"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Error while do work"); + throw; + } + } + } } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Enums/OrderStatus.cs b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Enums/OrderStatus.cs index 4777cd9..6d7015c 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Enums/OrderStatus.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDataModels/Enums/OrderStatus.cs @@ -10,6 +10,8 @@ Готов = 2, - Выдан = 3 + Ожидает = 3, + + Выдан = 4 } } \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240422165434_addingImplementors.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240422165434_addingImplementors.Designer.cs deleted file mode 100644 index c6b2862..0000000 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240422165434_addingImplementors.Designer.cs +++ /dev/null @@ -1,257 +0,0 @@ -// -using System; -using BlacksmithWorkshopDatabaseImplement; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -#nullable disable - -namespace BlacksmithWorkshopDatabaseImplement.Migrations -{ - [DbContext(typeof(BlacksmithWorkshopDataBase))] - [Migration("20240422165434_addingImplementors")] - partial class addingImplementors - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "7.0.16") - .HasAnnotation("Relational:MaxIdentifierLength", 128); - - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - - modelBuilder.Entity("BlacksmithWorkshopDataModels.Models.Implementer", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("ImplementerFIO") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Password") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Qualification") - .HasColumnType("int"); - - b.Property("WorkExperience") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.ToTable("Implementers"); - }); - - modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Client", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("ClientFIO") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Email") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Password") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.HasKey("Id"); - - b.ToTable("Clients"); - }); - - modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Component", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("ComponentName") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Cost") - .HasColumnType("float"); - - b.HasKey("Id"); - - b.ToTable("Components"); - }); - - modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("ManufactureName") - .IsRequired() - .HasColumnType("nvarchar(max)"); - - b.Property("Price") - .HasColumnType("float"); - - b.HasKey("Id"); - - b.ToTable("Manufactures"); - }); - - modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.ManufactureComponent", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("ComponentId") - .HasColumnType("int"); - - b.Property("Count") - .HasColumnType("int"); - - b.Property("ManufactureId") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.HasIndex("ComponentId"); - - b.HasIndex("ManufactureId"); - - b.ToTable("ManufactureComponents"); - }); - - modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Order", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("ClientId") - .HasColumnType("int"); - - b.Property("Count") - .HasColumnType("int"); - - b.Property("DateCreate") - .HasColumnType("datetime2"); - - b.Property("DateImplement") - .HasColumnType("datetime2"); - - b.Property("ImplementerId") - .HasColumnType("int"); - - b.Property("ManufactureId") - .HasColumnType("int"); - - b.Property("Status") - .HasColumnType("int"); - - b.Property("Sum") - .HasColumnType("float"); - - b.HasKey("Id"); - - b.HasIndex("ClientId"); - - b.HasIndex("ImplementerId"); - - b.HasIndex("ManufactureId"); - - b.ToTable("Orders"); - }); - - modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.ManufactureComponent", b => - { - b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Component", "Component") - .WithMany("ManufactureComponents") - .HasForeignKey("ComponentId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", "Manufacture") - .WithMany("Components") - .HasForeignKey("ManufactureId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Component"); - - b.Navigation("Manufacture"); - }); - - modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Order", b => - { - b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Client", "Client") - .WithMany("Orders") - .HasForeignKey("ClientId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("BlacksmithWorkshopDataModels.Models.Implementer", "Implementer") - .WithMany("Orders") - .HasForeignKey("ImplementerId"); - - b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", "Manufacture") - .WithMany("Orders") - .HasForeignKey("ManufactureId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Client"); - - b.Navigation("Implementer"); - - b.Navigation("Manufacture"); - }); - - modelBuilder.Entity("BlacksmithWorkshopDataModels.Models.Implementer", b => - { - b.Navigation("Orders"); - }); - - modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Client", b => - { - b.Navigation("Orders"); - }); - - modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Component", b => - { - b.Navigation("ManufactureComponents"); - }); - - modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", b => - { - b.Navigation("Components"); - - b.Navigation("Orders"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240422165434_addingImplementors.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240422165434_addingImplementors.cs deleted file mode 100644 index d6ee27e..0000000 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240422165434_addingImplementors.cs +++ /dev/null @@ -1,67 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace BlacksmithWorkshopDatabaseImplement.Migrations -{ - /// - public partial class addingImplementors : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.AddColumn( - name: "ImplementerId", - table: "Orders", - type: "int", - nullable: true); - - migrationBuilder.CreateTable( - name: "Implementers", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - ImplementerFIO = table.Column(type: "nvarchar(max)", nullable: false), - Password = table.Column(type: "nvarchar(max)", nullable: false), - Qualification = table.Column(type: "int", nullable: false), - WorkExperience = table.Column(type: "int", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Implementers", x => x.Id); - }); - - migrationBuilder.CreateIndex( - name: "IX_Orders_ImplementerId", - table: "Orders", - column: "ImplementerId"); - - 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.DropTable( - name: "Implementers"); - - migrationBuilder.DropIndex( - name: "IX_Orders_ImplementerId", - table: "Orders"); - - migrationBuilder.DropColumn( - name: "ImplementerId", - table: "Orders"); - } - } -} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240421170619_initialCreate.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240507165329_InitialCreate.Designer.cs similarity index 86% rename from BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240421170619_initialCreate.Designer.cs rename to BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240507165329_InitialCreate.Designer.cs index 6808a76..bcf11bf 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240421170619_initialCreate.Designer.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240507165329_InitialCreate.Designer.cs @@ -12,8 +12,8 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace BlacksmithWorkshopDatabaseImplement.Migrations { [DbContext(typeof(BlacksmithWorkshopDataBase))] - [Migration("20240421170619_initialCreate")] - partial class initialCreate + [Migration("20240507165329_InitialCreate")] + partial class InitialCreate { /// protected override void BuildTargetModel(ModelBuilder modelBuilder) @@ -25,6 +25,33 @@ namespace BlacksmithWorkshopDatabaseImplement.Migrations SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + modelBuilder.Entity("BlacksmithWorkshopDataModels.Models.Implementer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ImplementerFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Qualification") + .HasColumnType("int"); + + b.Property("WorkExperience") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Implementers"); + }); + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Client", b => { b.Property("Id") @@ -136,6 +163,9 @@ namespace BlacksmithWorkshopDatabaseImplement.Migrations b.Property("DateImplement") .HasColumnType("datetime2"); + b.Property("ImplementerId") + .HasColumnType("int"); + b.Property("ManufactureId") .HasColumnType("int"); @@ -149,6 +179,8 @@ namespace BlacksmithWorkshopDatabaseImplement.Migrations b.HasIndex("ClientId"); + b.HasIndex("ImplementerId"); + b.HasIndex("ManufactureId"); b.ToTable("Orders"); @@ -234,6 +266,10 @@ namespace BlacksmithWorkshopDatabaseImplement.Migrations .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + b.HasOne("BlacksmithWorkshopDataModels.Models.Implementer", "Implementer") + .WithMany("Orders") + .HasForeignKey("ImplementerId"); + b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", "Manufacture") .WithMany("Orders") .HasForeignKey("ManufactureId") @@ -242,6 +278,8 @@ namespace BlacksmithWorkshopDatabaseImplement.Migrations b.Navigation("Client"); + b.Navigation("Implementer"); + b.Navigation("Manufacture"); }); @@ -264,6 +302,11 @@ namespace BlacksmithWorkshopDatabaseImplement.Migrations b.Navigation("Shop"); }); + modelBuilder.Entity("BlacksmithWorkshopDataModels.Models.Implementer", b => + { + b.Navigation("Orders"); + }); + modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Client", b => { b.Navigation("Orders"); diff --git a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240421170619_initialCreate.cs b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240507165329_InitialCreate.cs similarity index 86% rename from BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240421170619_initialCreate.cs rename to BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240507165329_InitialCreate.cs index a30604d..7483112 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240421170619_initialCreate.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopDatabaseImplement/Migrations/20240507165329_InitialCreate.cs @@ -6,7 +6,7 @@ using Microsoft.EntityFrameworkCore.Migrations; namespace BlacksmithWorkshopDatabaseImplement.Migrations { /// - public partial class initialCreate : Migration + public partial class InitialCreate : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) @@ -40,6 +40,22 @@ namespace BlacksmithWorkshopDatabaseImplement.Migrations table.PrimaryKey("PK_Components", x => x.Id); }); + migrationBuilder.CreateTable( + name: "Implementers", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ImplementerFIO = table.Column(type: "nvarchar(max)", nullable: false), + Password = table.Column(type: "nvarchar(max)", nullable: false), + Qualification = table.Column(type: "int", nullable: false), + WorkExperience = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Implementers", x => x.Id); + }); + migrationBuilder.CreateTable( name: "Manufactures", columns: table => new @@ -109,7 +125,8 @@ namespace BlacksmithWorkshopDatabaseImplement.Migrations Status = table.Column(type: "int", nullable: false), DateCreate = table.Column(type: "datetime2", nullable: false), DateImplement = table.Column(type: "datetime2", nullable: true), - ManufactureId = table.Column(type: "int", nullable: false) + ManufactureId = table.Column(type: "int", nullable: false), + ImplementerId = table.Column(type: "int", nullable: true) }, constraints: table => { @@ -120,6 +137,11 @@ namespace BlacksmithWorkshopDatabaseImplement.Migrations principalTable: "Clients", principalColumn: "Id", onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Orders_Implementers_ImplementerId", + column: x => x.ImplementerId, + principalTable: "Implementers", + principalColumn: "Id"); table.ForeignKey( name: "FK_Orders_Manufactures_ManufactureId", column: x => x.ManufactureId, @@ -170,6 +192,11 @@ namespace BlacksmithWorkshopDatabaseImplement.Migrations table: "Orders", column: "ClientId"); + migrationBuilder.CreateIndex( + name: "IX_Orders_ImplementerId", + table: "Orders", + column: "ImplementerId"); + migrationBuilder.CreateIndex( name: "IX_Orders_ManufactureId", table: "Orders", @@ -204,6 +231,9 @@ namespace BlacksmithWorkshopDatabaseImplement.Migrations migrationBuilder.DropTable( name: "Clients"); + migrationBuilder.DropTable( + name: "Implementers"); + migrationBuilder.DropTable( name: "Manufactures"); -- 2.25.1 From 94ca959be134e4ca12a74f098f10645a7b9ee5b2 Mon Sep 17 00:00:00 2001 From: Zakharov_Rostislav Date: Tue, 7 May 2024 22:27:51 +0400 Subject: [PATCH 14/15] lab-6-hard --- .../BusinessLogics/OrderLogic.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs index 349ad70..fb6ecfb 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs @@ -82,20 +82,20 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogics _logger.LogWarning("Read operation failed"); return false; } - if (!(element.Status == status - 1 || model.Status == OrderStatus.Готов)) + if (!(element.Status == status - 1 || element.Status == OrderStatus.Готов)) { _logger.LogWarning("Status change operation failed"); throw new InvalidOperationException("Текущий статус заказа не может быть переведен в выбранный"); } if (element.Status == OrderStatus.Готов || element.Status == OrderStatus.Ожидает) { - var manufacture = _manufactureStorage.GetElement(new ManufactureSearchModel() { Id = model.ManufactureId }); + var manufacture = _manufactureStorage.GetElement(new ManufactureSearchModel() { Id = element.ManufactureId }); if (manufacture == null) { _logger.LogWarning("Status update to " + status.ToString() + " operation failed. Document not found."); return false; } - if (CheckSupply(manufacture, model.Count) == false) + if (CheckSupply(manufacture, element.Count) == false) { _logger.LogWarning("Status update to " + status.ToString() + " operation failed. Shop supply error."); status = OrderStatus.Ожидает; -- 2.25.1 From 69d4fd07ee2d26eb1df3b9b7c971f2b1ea813234 Mon Sep 17 00:00:00 2001 From: Zakharov_Rostislav Date: Fri, 24 May 2024 22:48:16 +0400 Subject: [PATCH 15/15] lab-6-hard preparing for pr --- .../BusinessLogics/OrderLogic.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs index fb6ecfb..f0c7a01 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BusinessLogics/OrderLogic.cs @@ -95,7 +95,7 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogics _logger.LogWarning("Status update to " + status.ToString() + " operation failed. Document not found."); return false; } - if (CheckSupply(manufacture, element.Count) == false) + if (!CheckSupply(manufacture, element.Count)) { _logger.LogWarning("Status update to " + status.ToString() + " operation failed. Shop supply error."); status = OrderStatus.Ожидает; -- 2.25.1