somechange

This commit is contained in:
Sergey Kozyrev 2024-05-27 22:06:37 +04:00
parent 1d49b42cd6
commit 64d1c12832
6 changed files with 114 additions and 26 deletions

View File

@ -36,7 +36,7 @@ namespace DatabaseImplement.Implements
} }
using var context = new FactoryGoWorkDatabase(); using var context = new FactoryGoWorkDatabase();
if (model.DetailId.HasValue) 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) 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(); 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 else

View File

@ -299,22 +299,35 @@ namespace ImplementerApp.Controllers
return View(values); return View(values);
} }
[HttpGet]
public IActionResult DetailWorkshopChoose()
{
if (!IsLoggedIn)
return RedirectToAction("IndexNonReg");
var details = _data.GetDetails(UserId);
return View(details);
}
[HttpPost]
public IActionResult DetailWorkshopChoose(List<int> 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() public IActionResult DetailWorkshopReport()
{ {
List<DetailWorkshopReportViewModel> detailWorkshopReports = new List<DetailWorkshopReportViewModel> var value = HttpContext.Session.GetString("Details");
if (value != null)
{ {
new DetailWorkshopReportViewModel List<int> rawReports = value!.Split('/').Select(x => int.Parse(x)).ToList();
{ var reports = _data.GetWorkshopReports(rawReports);
DetailName = "Деталь X", return View(reports);
WorkShops = new List<string> { "Цех 1", "Цех 2" }
},
new DetailWorkshopReportViewModel
{
DetailName = "Деталь Y",
WorkShops = new List<string> { "Цех 3", "Цех 4" }
} }
}; return View(new List<DetailWorkshopReportViewModel>());
return View(detailWorkshopReports);
} }
public IActionResult ReportsMenu() public IActionResult ReportsMenu()
{ {

View File

@ -14,8 +14,9 @@ namespace ImplementerApp
private readonly IProductionLogic _productionLogic; private readonly IProductionLogic _productionLogic;
private readonly IProductLogic _productLogic; private readonly IProductLogic _productLogic;
private readonly IMachineLogic _machineLogic; private readonly IMachineLogic _machineLogic;
private readonly IWorkshopLogic _workshopLogic;
public ImplementerData(ILogger<ImplementerData> logger, IImplementerLogic implementerLogic, IDetailLogic detailLogic, IProductionLogic productionLogic, IProductLogic productLogic, IMachineLogic machineLogic) public ImplementerData(ILogger<ImplementerData> logger, IImplementerLogic implementerLogic, IDetailLogic detailLogic, IProductionLogic productionLogic, IProductLogic productLogic, IMachineLogic machineLogic, IWorkshopLogic workshopLogic)
{ {
_logger = logger; _logger = logger;
_implementerLogic = implementerLogic; _implementerLogic = implementerLogic;
@ -23,6 +24,7 @@ namespace ImplementerApp
_productionLogic = productionLogic; _productionLogic = productionLogic;
_productLogic = productLogic; _productLogic = productLogic;
_machineLogic = machineLogic; _machineLogic = machineLogic;
_workshopLogic = workshopLogic;
} }
public ImplementerViewModel? Login(string login, string password) public ImplementerViewModel? Login(string login, string password)
@ -130,5 +132,22 @@ namespace ImplementerApp
} }
return detailTimeReports; return detailTimeReports;
} }
public List<DetailWorkshopReportViewModel>? GetWorkshopReports(List<int> details)
{
List<DetailWorkshopReportViewModel> 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;
}
} }
} }

View File

@ -17,11 +17,13 @@ builder.Services.AddTransient<IDetailStorage, DetailStorage>();
builder.Services.AddTransient<IProductStorage, ProductStorage>(); builder.Services.AddTransient<IProductStorage, ProductStorage>();
builder.Services.AddTransient<IProductionStorage, ProductionStorage>(); builder.Services.AddTransient<IProductionStorage, ProductionStorage>();
builder.Services.AddTransient<IMachineStorage, MachineStorage>(); builder.Services.AddTransient<IMachineStorage, MachineStorage>();
builder.Services.AddTransient<IWorkshopStorage, WorkshopStorage>();
builder.Services.AddTransient<IImplementerLogic, ImplementerLogic>(); builder.Services.AddTransient<IImplementerLogic, ImplementerLogic>();
builder.Services.AddTransient<IDetailLogic, DetailLogic>(); builder.Services.AddTransient<IDetailLogic, DetailLogic>();
builder.Services.AddTransient<IProductionLogic, ProductionLogic>(); builder.Services.AddTransient<IProductionLogic, ProductionLogic>();
builder.Services.AddTransient<IProductLogic, ProductLogic>(); builder.Services.AddTransient<IProductLogic, ProductLogic>();
builder.Services.AddTransient<IMachineLogic, MachineLogic>(); builder.Services.AddTransient<IMachineLogic, MachineLogic>();
builder.Services.AddTransient<IWorkshopLogic, WorkshopLogic>();
builder.Services.AddTransient<ImplementerData>(); builder.Services.AddTransient<ImplementerData>();
builder.Services.AddSession(options => builder.Services.AddSession(options =>

View File

@ -0,0 +1,54 @@
@using Contracts.ViewModels;
@model List<DetailViewModel>
@{
ViewData["Title"] = "Выбор деталей для отчета";
}
<h2>Выберите детали для отчета</h2>
<form asp-controller="Home" asp-action="DetailWorkshopChoose" method="post" onsubmit="return validateForm()">
<table class="table">
<thead>
<tr>
<th>Select</th>
<th>Name</th>
</tr>
</thead>
<tbody>
@for (int i = 0; i < Model.Count; i++)
{
<tr>
<td>
<input type="checkbox" name="selectedItems" value="@Model[i].Id" />
</td>
<td>@Model[i].Name</td>
</tr>
}
</tbody>
</table>
<input type="hidden" id="reportType" name="reportType" value="default" />
<button type="submit" class="btn btn-primary" onclick="setReportType('default')">Сгенерировать отчет</button>
<button type="submit" class="btn btn-secondary" onclick="setReportType('excel')">Сгенерировать отчет в Excel</button>
<button type="submit" class="btn btn-secondary" onclick="setReportType('word')">Сгенерировать отчет в Word</button>
<div id="validationMessage" style="display:none;color:red;">Пожалуйста, выберите хотя бы одну деталь.</div>
</form>
@section Scripts {
<script>
function validateForm() {
var checkboxes = document.querySelectorAll('input[name="selectedItems"]:checked');
if (checkboxes.length === 0) {
document.getElementById('validationMessage').style.display = 'block';
return false;
} else {
document.getElementById('validationMessage').style.display = 'none';
return true;
}
}
function setReportType(type) {
document.getElementById('reportType').value = type;
}
</script>
}

View File

@ -5,7 +5,7 @@
<div class="text-center"> <div class="text-center">
<h1 class="display-4">Меню создания отчетов</h1> <h1 class="display-4">Меню создания отчетов</h1>
<div class="list-group"> <div class="list-group">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="DetailWorkshopReport">Отчет деталь-цех</a> <a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="DetailWorkshopChoose">Отчет деталь-цех</a>
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="DetailTimeChoose">Отчет по деталям по датам</a> <a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="DetailTimeChoose">Отчет по деталям по датам</a>
</div> </div>
</div> </div>