From 6e34920bd39f9d3ea0ce0d7c57eff7015d8b38c7 Mon Sep 17 00:00:00 2001 From: sardq Date: Tue, 28 May 2024 20:50:32 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B2=D1=80=D0=BE=D0=B4=D0=B5=20=D1=81=D1=82?= =?UTF-8?q?=D1=80=D0=B0=D0=BD=D0=B8=D1=86=D1=8B=20=D1=81=D1=83=D1=89=D0=BD?= =?UTF-8?q?=D0=BE=D1=81=D1=82=D0=B5=D0=B9=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=B0=D1=8E=D1=82=20=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BD?= =?UTF-8?q?=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Implements/ClientStorage.cs | 2 +- .../Models/ExecutionPhase.cs | 3 +- .../Models/PlanProduction.cs | 2 +- .../Controllers/HomeController.cs | 34 ++++-- .../Views/Home/ExecutionPhase.cshtml | 6 +- .../Views/Home/PlanProduction.cshtml | 2 +- .../Views/Home/Workpiece.cshtml | 105 ++++++++++++++++-- .../Views/Home/Workpieces.cshtml | 2 +- 8 files changed, 129 insertions(+), 27 deletions(-) diff --git a/Factory/FactoryDatabaseImplement/Implements/ClientStorage.cs b/Factory/FactoryDatabaseImplement/Implements/ClientStorage.cs index e5c61e2..c9db262 100644 --- a/Factory/FactoryDatabaseImplement/Implements/ClientStorage.cs +++ b/Factory/FactoryDatabaseImplement/Implements/ClientStorage.cs @@ -37,7 +37,7 @@ namespace FactoryDatabaseImplement.Implements } using var context = new FactoryDatabase(); return context.Clients - .FirstOrDefault(x => (!string.IsNullOrEmpty(model.Login) && x.Login == model.Login) || + .FirstOrDefault(x => ((!string.IsNullOrEmpty(model.Login) && x.Login == model.Login) && (!string.IsNullOrEmpty(model.Password) && x.Password == model.Password)) || (model.Id.HasValue && x.Id == model.Id)) ?.GetViewModel; } diff --git a/Factory/FactoryDatabaseImplement/Models/ExecutionPhase.cs b/Factory/FactoryDatabaseImplement/Models/ExecutionPhase.cs index c65f032..0c6a232 100644 --- a/Factory/FactoryDatabaseImplement/Models/ExecutionPhase.cs +++ b/Factory/FactoryDatabaseImplement/Models/ExecutionPhase.cs @@ -73,7 +73,8 @@ namespace FactoryDatabaseImplement.Models { Id = Id, ExecutionPhaseName = ExecutionPhaseName, - ImplementerFIO = ImplementerFIO, + PlanProductionName = PlanProduction == null ? null : PlanProduction.ProductionName, + ImplementerFIO = ImplementerFIO, ClientId = ClientId, PlanProductionId = PlanProductionId, Status = Status, diff --git a/Factory/FactoryDatabaseImplement/Models/PlanProduction.cs b/Factory/FactoryDatabaseImplement/Models/PlanProduction.cs index fab6f1d..d7ffa90 100644 --- a/Factory/FactoryDatabaseImplement/Models/PlanProduction.cs +++ b/Factory/FactoryDatabaseImplement/Models/PlanProduction.cs @@ -11,7 +11,7 @@ namespace FactoryDatabaseImplement.Models public int Id { get; private set; } [Required] public int ClientId { get; private set; } - public virtual Client Client { get; private set; } = new(); + public virtual Client Client { get; private set; } [Required] public string ProductionName { get; private set; } = string.Empty; diff --git a/Factory/FactoryWorkerApp/Controllers/HomeController.cs b/Factory/FactoryWorkerApp/Controllers/HomeController.cs index f18b481..a181e1c 100644 --- a/Factory/FactoryWorkerApp/Controllers/HomeController.cs +++ b/Factory/FactoryWorkerApp/Controllers/HomeController.cs @@ -1,4 +1,5 @@ -using FactoryContracts.BindingModels; +using DocumentFormat.OpenXml.Office2010.Excel; +using FactoryContracts.BindingModels; using FactoryContracts.ViewModels; using FactoryDatabaseImplement.Models; using FactoryDataModels.Enums; @@ -49,8 +50,8 @@ namespace FactoryWorkerApp.Controllers if (user != null) { Client.user = user; - Response.Redirect("Index"); } + Response.Redirect("Index"); } [HttpGet] public IActionResult Register() @@ -104,21 +105,34 @@ namespace FactoryWorkerApp.Controllers return View(new WorkpieceViewModel()); } [HttpPost] - public IActionResult Workpiece(WorkpieceBindingModel model) + public IActionResult Workpiece(int id, string workpiecename, string material, int cost, int[] productIds, int[] counts) { - if (model.Id == 0) + WorkpieceBindingModel model = new WorkpieceBindingModel(); + model.Id = id; + model.WorkpieceName = workpiecename; + model.Material = material; + model.Cost = cost; + model.ClientId = Client.user!.Id; + var products = _logic.GetProducts(); + for (int i = 0; i < productIds.Length; i++) + { + var product = products!.FirstOrDefault(x => x.Id == productIds[i])!; + if (counts[i] <= 0) + continue; + model.WorkpieceProducts[productIds[i]] = (product, counts[i]); + } + if (model.WorkpieceProducts.Count == 0) + return RedirectToAction("Workpieces"); + if (model.Id == 0) { model.DateCreate = DateTime.Now; - model.ClientId = Client.user!.Id; - if (_logic.CreateWorkpiece(model)) - return RedirectToAction("Workpieces"); + _logic.CreateWorkpiece(model); } else { - if (_logic.UpdateWorkpiece(model)) - return RedirectToAction("Workpieces"); + _logic.UpdateWorkpiece(model); } - return View(); + return RedirectToAction("Workpieces"); } [HttpGet] diff --git a/Factory/FactoryWorkerApp/Views/Home/ExecutionPhase.cshtml b/Factory/FactoryWorkerApp/Views/Home/ExecutionPhase.cshtml index 1f05ba9..61df184 100644 --- a/Factory/FactoryWorkerApp/Views/Home/ExecutionPhase.cshtml +++ b/Factory/FactoryWorkerApp/Views/Home/ExecutionPhase.cshtml @@ -12,12 +12,12 @@
План производства:
-
- @foreach (var planProduction in ViewBag.AllPlans) { - + }
diff --git a/Factory/FactoryWorkerApp/Views/Home/PlanProduction.cshtml b/Factory/FactoryWorkerApp/Views/Home/PlanProduction.cshtml index e919f65..a0e4b3b 100644 --- a/Factory/FactoryWorkerApp/Views/Home/PlanProduction.cshtml +++ b/Factory/FactoryWorkerApp/Views/Home/PlanProduction.cshtml @@ -14,7 +14,7 @@
Количество:
-
+
Срок выполнения:
diff --git a/Factory/FactoryWorkerApp/Views/Home/Workpiece.cshtml b/Factory/FactoryWorkerApp/Views/Home/Workpiece.cshtml index 14af5cd..0512926 100644 --- a/Factory/FactoryWorkerApp/Views/Home/Workpiece.cshtml +++ b/Factory/FactoryWorkerApp/Views/Home/Workpiece.cshtml @@ -8,34 +8,45 @@

Заготовка

- +
Изделия
- +
- + - @foreach (var product in ViewBag.AllProducts) + @foreach (var product in ViewBag.Products) { - + - + }
Выбор Название КоличествоУдалить
- + + @product.Value.Item1.ProductName @product.ProductName - + + +
+ +
Название:
@@ -53,4 +64,80 @@
- \ No newline at end of file + + + + + + \ No newline at end of file diff --git a/Factory/FactoryWorkerApp/Views/Home/Workpieces.cshtml b/Factory/FactoryWorkerApp/Views/Home/Workpieces.cshtml index 06f2ed8..8029374 100644 --- a/Factory/FactoryWorkerApp/Views/Home/Workpieces.cshtml +++ b/Factory/FactoryWorkerApp/Views/Home/Workpieces.cshtml @@ -17,7 +17,7 @@ return; }

- Создать заказ + Создать заготовку