From f2445bd4486435acdc26c069e753087666667094 Mon Sep 17 00:00:00 2001 From: urlilpolly Date: Tue, 28 May 2024 21:16:51 +0400 Subject: [PATCH] =?UTF-8?q?repair(=D0=BD=D0=B5=D0=BC=D0=B0=20=D0=BA=D0=B0?= =?UTF-8?q?=D1=80=D1=82=D0=BE=D1=87=D0=B5=D0=BA)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Contracts/ViewModels/MachineViewModel.cs | 2 +- .../Contracts/ViewModels/WorkshopViewModel.cs | 2 +- .../Controllers/HomeController.cs | 68 +++++++++++++------ Course/GuarantorAPP/GuarantorData.cs | 19 +++++- Course/GuarantorAPP/Program.cs | 2 + .../Views/Home/CreateMachine.cshtml | 31 ++------- .../Views/Home/CreateWorkshop.cshtml | 57 ++++------------ Course/GuarantorAPP/Views/Home/Index.cshtml | 6 +- .../Views/Home/IndexWorkshop.cshtml | 5 +- .../Home/MachineWorkshopTimeChoose.cshtml | 32 +++++---- .../Home/MachineWorkshopTimeReport.cshtml | 2 +- .../Views/Home/ReportsMenu.cshtml | 2 +- .../Views/Home/WorkerProductChoose.cshtml | 54 +++++++++++++++ .../Views/Home/WorkerProductReport.cshtml | 2 +- .../Views/Home/WorkshopProductionAdd.cshtml | 4 +- 15 files changed, 174 insertions(+), 114 deletions(-) create mode 100644 Course/GuarantorAPP/Views/Home/WorkerProductChoose.cshtml diff --git a/Course/Contracts/ViewModels/MachineViewModel.cs b/Course/Contracts/ViewModels/MachineViewModel.cs index ef66147..ab3a0b1 100644 --- a/Course/Contracts/ViewModels/MachineViewModel.cs +++ b/Course/Contracts/ViewModels/MachineViewModel.cs @@ -11,6 +11,6 @@ namespace Contracts.ViewModels [DisplayName("Страна производитель")] public string Country { get; set; } = string.Empty; public int UserId { get; set; } - public Dictionary? WorkerMachines { get; set; } + public Dictionary WorkerMachines { get; set; } = new(); } } diff --git a/Course/Contracts/ViewModels/WorkshopViewModel.cs b/Course/Contracts/ViewModels/WorkshopViewModel.cs index 8d1e64b..2fdeeb6 100644 --- a/Course/Contracts/ViewModels/WorkshopViewModel.cs +++ b/Course/Contracts/ViewModels/WorkshopViewModel.cs @@ -15,6 +15,6 @@ namespace Contracts.ViewModels public int UserId { get; set; } public int? ProductionId { get; set; } public string? ProductionName { get; set; } - public Dictionary? WorkerWorkshops { get; set; } + public Dictionary WorkerWorkshops { get; set; } = new(); } } diff --git a/Course/GuarantorAPP/Controllers/HomeController.cs b/Course/GuarantorAPP/Controllers/HomeController.cs index 6c4ea18..a6b35e5 100644 --- a/Course/GuarantorAPP/Controllers/HomeController.cs +++ b/Course/GuarantorAPP/Controllers/HomeController.cs @@ -96,11 +96,12 @@ namespace GuarantorAPP.Controllers return View(new MachineViewModel()); } [HttpPost] - public IActionResult CreateMachine(int id, string title, int[] workerIds) + public IActionResult CreateMachine(int id, string title, string country, int[] workerIds) { MachineBindingModel model = new MachineBindingModel(); model.Id = id; model.Title = title; + model.Country = country; model.DateCreate = DateTime.Now; model.UserId = UserGuarantor.user!.Id; var workers = _data.GetWorkers(UserGuarantor.user!.Id); @@ -207,11 +208,13 @@ namespace GuarantorAPP.Controllers return View(new WorkshopViewModel()); } [HttpPost] - public IActionResult CreateWorkshop(int id, string title, int[] workerIds) + public IActionResult CreateWorkshop(int id, string title, string address, string director, int[] workerIds) { WorkshopBindingModel model = new WorkshopBindingModel(); model.Id = id; model.Title = title; + model.Address = address; + model.Director = director; model.DateCreate = DateTime.Now; model.UserId = UserGuarantor.user!.Id; var workers = _data.GetWorkers(UserGuarantor.user!.Id); @@ -220,17 +223,25 @@ namespace GuarantorAPP.Controllers var worker = workers!.FirstOrDefault(x => x.Id == workerIds[i])!; model.WorkshopWorker[workerIds[i]] = (worker); } - if (model.WorkshopWorker.Count == 0) - return RedirectToAction("IndexWorkshop"); - if (id != 0) + bool changed = false; + if (model.WorkshopWorker.Count > 0) { - _data.UpdateWorkshop(model); + if (id != 0) + { + changed = _data.UpdateWorkshop(model); + } + else + { + changed = _data.CreateWorkshop(model); + } } + if (changed) + return RedirectToAction("IndexWorkshop"); else { - _data.CreateWorkshop(model); + ViewBag.AllWorkers = workers; + return View(model); } - return RedirectToAction("IndexWorkshop"); } [HttpGet] public IActionResult Privacy() @@ -285,22 +296,37 @@ namespace GuarantorAPP.Controllers ViewBag.EndDate = endDate; return View(values); } + [HttpGet] + public IActionResult WorkerProductChoose() + { + if (!IsLoggedIn) + return RedirectToAction("IndexNonReg"); + var workers = _data.GetWorkers(UserId); + return View(workers); + } + [HttpPost] + public IActionResult WorkerProductChoose(List selectedItems, string reportType) + { + string value = string.Join("/", selectedItems); + HttpContext.Session.SetString("Workers", value); + if (reportType.Equals("default")) + return RedirectToAction("WorkerProductReport"); + else if (reportType.Equals("excel")) + return RedirectToAction(""); + else + return RedirectToAction(""); + } + [HttpGet] public IActionResult WorkerProductReport() { - List workerProductReports = new List + var value = HttpContext.Session.GetString("Workers"); + if(value != null) { - new WorkerProductReportViewModel - { - WorkerName = "Работник 1", - Products = new List { "Изделие первое", "Изделие второе" } - }, - new WorkerProductReportViewModel - { - WorkerName = "Работник 2", - Products = new List { "Изделие одно", "Изделие второе" } - } - }; - return View(workerProductReports); + List rawReports = value!.Split(',').Select(x => int.Parse(x)).ToList(); + var reports = _data.GetProductReports(rawReports); + return View(reports); + } + return View(new List()); } public IActionResult ReportsMenu() { diff --git a/Course/GuarantorAPP/GuarantorData.cs b/Course/GuarantorAPP/GuarantorData.cs index cf8a9ba..6970e57 100644 --- a/Course/GuarantorAPP/GuarantorData.cs +++ b/Course/GuarantorAPP/GuarantorData.cs @@ -13,8 +13,9 @@ namespace GuarantorAPP private readonly IMachineLogic _machineLogic; private readonly IWorkshopLogic _workshopLogic; private readonly IProductionLogic _productionLogic; + private readonly IProductLogic _productLogic; - public GuarantorData(ILogger logger, IGuarantorLogic guarantorLogic, IWorkerLogic workerLogic, IMachineLogic machineLogic, IWorkshopLogic workshopLogic, IProductionLogic productionLogic) + public GuarantorData(ILogger logger, IGuarantorLogic guarantorLogic, IWorkerLogic workerLogic, IMachineLogic machineLogic, IWorkshopLogic workshopLogic, IProductionLogic productionLogic, IProductLogic productLogic) { _logger = logger; _guarantorLogic = guarantorLogic; @@ -22,6 +23,7 @@ namespace GuarantorAPP _machineLogic = machineLogic; _workshopLogic = workshopLogic; _productionLogic = productionLogic; + _productLogic = productLogic; } public GuarantorViewModel? Login(string login, string password) @@ -128,5 +130,20 @@ namespace GuarantorAPP } return machineWorkshopTimeReports; } + public List? GetProductReports(List workers) + { + List reports = new(); + foreach (int i in workers) + { + WorkerProductReportViewModel report = new(); + var worker = _workerLogic.ReadElement(new() { Id = i }); + report.WorkerName = worker!.Name; + var products = _productLogic.ReadList(new() { WorkerId = i }); + if (products != null) + report.Products = products.Select(x => x.Name).ToList(); + reports.Add(report); + } + return reports; + } } } diff --git a/Course/GuarantorAPP/Program.cs b/Course/GuarantorAPP/Program.cs index cb14496..3fadb28 100644 --- a/Course/GuarantorAPP/Program.cs +++ b/Course/GuarantorAPP/Program.cs @@ -16,11 +16,13 @@ builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddSession(options => diff --git a/Course/GuarantorAPP/Views/Home/CreateMachine.cshtml b/Course/GuarantorAPP/Views/Home/CreateMachine.cshtml index 17ff507..75f1f94 100644 --- a/Course/GuarantorAPP/Views/Home/CreateMachine.cshtml +++ b/Course/GuarantorAPP/Views/Home/CreateMachine.cshtml @@ -42,7 +42,7 @@ @worker.Value.Name - @worker.Value.Position + @worker.Value.Specialization @worker.Value.Salary @@ -54,15 +54,11 @@ @foreach (var worker in ViewBag.AllWorkers) { - + } -
-
Общая зарплата:
-
-
@@ -73,25 +69,18 @@ +} \ No newline at end of file diff --git a/Course/GuarantorAPP/Views/Home/WorkerProductReport.cshtml b/Course/GuarantorAPP/Views/Home/WorkerProductReport.cshtml index d842847..5569c3c 100644 --- a/Course/GuarantorAPP/Views/Home/WorkerProductReport.cshtml +++ b/Course/GuarantorAPP/Views/Home/WorkerProductReport.cshtml @@ -3,7 +3,7 @@ @model List @{ - ViewData["Title"] = "Workers - Product Reports"; + ViewData["Title"] = "Отчет работник - изделие"; }

Список работников с отображением изделий

diff --git a/Course/GuarantorAPP/Views/Home/WorkshopProductionAdd.cshtml b/Course/GuarantorAPP/Views/Home/WorkshopProductionAdd.cshtml index ff59377..6a8a08b 100644 --- a/Course/GuarantorAPP/Views/Home/WorkshopProductionAdd.cshtml +++ b/Course/GuarantorAPP/Views/Home/WorkshopProductionAdd.cshtml @@ -7,11 +7,11 @@ }
-

Цех - @ViewBag.Workshop.Name

+

Цех - @ViewBag.Workshop.Title

-

Список цехов

+

Список производств

@foreach (var production in Model) {