From 64d1c12832c1c6751f1e963a7b72e0cfe144adc3 Mon Sep 17 00:00:00 2001 From: Sergey Kozyrev Date: Mon, 27 May 2024 22:06:37 +0400 Subject: [PATCH] somechange --- .../Implements/WorkshopStorage.cs | 2 +- .../Controllers/HomeController.cs | 41 +++++++++----- Course/ImplementerApp/ImplementerData.cs | 39 ++++++++++---- Course/ImplementerApp/Program.cs | 2 + .../Views/Home/DetailWorkshopChoose.cshtml | 54 +++++++++++++++++++ .../Views/Home/ReportsMenu.cshtml | 2 +- 6 files changed, 114 insertions(+), 26 deletions(-) create mode 100644 Course/ImplementerApp/Views/Home/DetailWorkshopChoose.cshtml diff --git a/Course/DatabaseImplement/Implements/WorkshopStorage.cs b/Course/DatabaseImplement/Implements/WorkshopStorage.cs index 327f90c..f3b77d1 100644 --- a/Course/DatabaseImplement/Implements/WorkshopStorage.cs +++ b/Course/DatabaseImplement/Implements/WorkshopStorage.cs @@ -36,7 +36,7 @@ namespace DatabaseImplement.Implements } using var context = new FactoryGoWorkDatabase(); if (model.DetailId.HasValue) - return context.Workshops.Where(x => x.ProductionId.HasValue).Include(x => x.Production).Where(x => x.Production.Details.FirstOrDefault(y => y.DetailId == model.DetailId) != null).Where(x => x.UserId == model.UserId).Select(x => x.GetViewModel).ToList(); + return context.Workshops.Where(x => x.ProductionId.HasValue).Include(x => x.Production).Where(x => x.Production.Details.FirstOrDefault(y => y.DetailId == model.DetailId) != null).Select(x => x.GetViewModel).ToList(); else if (model.DateFrom.HasValue) return context.Workshops.Where(x => x.UserId == model.Id).Where(x => x.DateCreate < model.DateTo && x.DateCreate > model.DateFrom).Select(x => x.GetViewModel).ToList(); else diff --git a/Course/ImplementerApp/Controllers/HomeController.cs b/Course/ImplementerApp/Controllers/HomeController.cs index 485577f..25c7c1e 100644 --- a/Course/ImplementerApp/Controllers/HomeController.cs +++ b/Course/ImplementerApp/Controllers/HomeController.cs @@ -299,22 +299,35 @@ namespace ImplementerApp.Controllers return View(values); } - public IActionResult DetailWorkshopReport() + [HttpGet] + public IActionResult DetailWorkshopChoose() { - List detailWorkshopReports = new List + if (!IsLoggedIn) + return RedirectToAction("IndexNonReg"); + var details = _data.GetDetails(UserId); + return View(details); + } + [HttpPost] + public IActionResult DetailWorkshopChoose(List selectedItems, string reportType) + { + string value = string.Join("/", selectedItems); + HttpContext.Session.SetString("Details", value); + if (reportType.Equals("default")) + return RedirectToAction("DetailWorkshopReport"); + else + return RedirectToAction("Index"); // СДЕЛАТЬ EXCEL И WORD + } + [HttpGet] + public IActionResult DetailWorkshopReport() + { + var value = HttpContext.Session.GetString("Details"); + if (value != null) { - new DetailWorkshopReportViewModel - { - DetailName = "Деталь X", - WorkShops = new List { "Цех 1", "Цех 2" } - }, - new DetailWorkshopReportViewModel - { - DetailName = "Деталь Y", - WorkShops = new List { "Цех 3", "Цех 4" } - } - }; - return View(detailWorkshopReports); + List rawReports = value!.Split('/').Select(x => int.Parse(x)).ToList(); + var reports = _data.GetWorkshopReports(rawReports); + return View(reports); + } + return View(new List()); } public IActionResult ReportsMenu() { diff --git a/Course/ImplementerApp/ImplementerData.cs b/Course/ImplementerApp/ImplementerData.cs index 6d872a4..efd43d1 100644 --- a/Course/ImplementerApp/ImplementerData.cs +++ b/Course/ImplementerApp/ImplementerData.cs @@ -14,18 +14,20 @@ namespace ImplementerApp private readonly IProductionLogic _productionLogic; private readonly IProductLogic _productLogic; private readonly IMachineLogic _machineLogic; + private readonly IWorkshopLogic _workshopLogic; - public ImplementerData(ILogger logger, IImplementerLogic implementerLogic, IDetailLogic detailLogic, IProductionLogic productionLogic, IProductLogic productLogic, IMachineLogic machineLogic) - { - _logger = logger; - _implementerLogic = implementerLogic; - _detailLogic = detailLogic; - _productionLogic = productionLogic; - _productLogic = productLogic; - _machineLogic = machineLogic; - } + public ImplementerData(ILogger logger, IImplementerLogic implementerLogic, IDetailLogic detailLogic, IProductionLogic productionLogic, IProductLogic productLogic, IMachineLogic machineLogic, IWorkshopLogic workshopLogic) + { + _logger = logger; + _implementerLogic = implementerLogic; + _detailLogic = detailLogic; + _productionLogic = productionLogic; + _productLogic = productLogic; + _machineLogic = machineLogic; + _workshopLogic = workshopLogic; + } - public ImplementerViewModel? Login(string login, string password) + public ImplementerViewModel? Login(string login, string password) { return _implementerLogic.ReadElement(new() { @@ -130,5 +132,22 @@ namespace ImplementerApp } return detailTimeReports; } + + public List? GetWorkshopReports(List details) + { + List reports = new(); + foreach (int i in details) + { + DetailWorkshopReportViewModel report = new(); + var detail = _detailLogic.ReadElement(new() { Id = i }); + report.DetailName = detail!.Name; + var workshops = _workshopLogic.ReadList(new() { DetailId = i }); + if (workshops != null) + report.WorkShops = workshops.Select(w => w.Title).ToList(); + reports.Add(report); + } + return reports; + } + } } diff --git a/Course/ImplementerApp/Program.cs b/Course/ImplementerApp/Program.cs index cdae25d..2f034e2 100644 --- a/Course/ImplementerApp/Program.cs +++ b/Course/ImplementerApp/Program.cs @@ -17,11 +17,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/ImplementerApp/Views/Home/DetailWorkshopChoose.cshtml b/Course/ImplementerApp/Views/Home/DetailWorkshopChoose.cshtml new file mode 100644 index 0000000..48f35db --- /dev/null +++ b/Course/ImplementerApp/Views/Home/DetailWorkshopChoose.cshtml @@ -0,0 +1,54 @@ +@using Contracts.ViewModels; +@model List + +@{ + ViewData["Title"] = "Выбор деталей для отчета"; +} + +

Выберите детали для отчета

+ +
+ + + + + + + + + @for (int i = 0; i < Model.Count; i++) + { + + + + + } + +
SelectName
+ + @Model[i].Name
+ + + + + +
+ +@section Scripts { + +} \ No newline at end of file diff --git a/Course/ImplementerApp/Views/Home/ReportsMenu.cshtml b/Course/ImplementerApp/Views/Home/ReportsMenu.cshtml index dfbef55..5aacaf2 100644 --- a/Course/ImplementerApp/Views/Home/ReportsMenu.cshtml +++ b/Course/ImplementerApp/Views/Home/ReportsMenu.cshtml @@ -5,7 +5,7 @@