отчеты Ворд/Эксель

This commit is contained in:
Володя 2023-05-18 19:23:52 +03:00
parent 18e9fa7508
commit 53c6b8fb76
3 changed files with 87 additions and 5 deletions

View File

@ -20,7 +20,9 @@ namespace StudentWebClient.Controllers
private readonly IProductLogic _product; private readonly IProductLogic _product;
private readonly IInterestLogic _interest; private readonly IInterestLogic _interest;
private readonly IStudentLogic _student; private readonly IStudentLogic _student;
public HomeController(ILogger<HomeController> logger, IDiyLogic diy, IProductLogic product , ITaskLogic task , IInterestLogic interest, IStudentLogic student) private readonly IReportLogic _report;
public HomeController(ILogger<HomeController> logger, IDiyLogic diy,
IProductLogic product , ITaskLogic task , IInterestLogic interest, IStudentLogic student, IReportLogic report)
{ {
_logger = logger; _logger = logger;
_diy = diy; _diy = diy;
@ -28,6 +30,7 @@ namespace StudentWebClient.Controllers
_task = task; _task = task;
_interest = interest; _interest = interest;
_student = student; _student = student;
_report = report;
} }
public IActionResult Index() public IActionResult Index()
@ -70,7 +73,7 @@ namespace StudentWebClient.Controllers
{ {
Id = APIClient.Student.Id, Id = APIClient.Student.Id,
Name = name, Name = name,
Email = login, Email = email,
Password = password, Password = password,
Login = login, Login = login,
Class = scClass Class = scClass
@ -119,7 +122,7 @@ namespace StudentWebClient.Controllers
_student.Create( new StudentBindingModel _student.Create( new StudentBindingModel
{ {
Name = name, Name = name,
Email = login, Email = email,
Password = password, Password = password,
Login = login, Login = login,
Class = scClass Class = scClass
@ -420,8 +423,30 @@ namespace StudentWebClient.Controllers
} }
public IActionResult Reports() public IActionResult Reports()
{ {
var list = _interest.ReadList(new InterestSearchModel { StudentId = APIClient.Student.Id });
var simpInterest = list.Select(x => new { InterestId = x.Id, InterestName = x.Title });
ViewBag.Interests = new MultiSelectList(simpInterest, "InterestId", "InterestName");
return View(); return View();
} }
public IActionResult GetPartial(int[] interests, string mode)
{
var list = interests.Select(x => _interest.ReadElement(new InterestSearchModel { Id = x })).ToList();
if (mode.Equals("Excel"))
{
_report.SaveInterestLessonToExcelFile
(new ReportBindingModel { FileName = $"C:\\Users\\Вова\\Documents\\Учеба\\Reports\\{APIClient.Student.Name}-{DateTime.Now.ToString("dd/MM/yyyy")}.xlsx", Interests = list, StudentId = APIClient.Student.Id });
}
else
{
_report.SaveInterestLessonToWordFile
(new ReportBindingModel { FileName = $"C:\\Users\\Вова\\Documents\\Учеба\\Reports\\{APIClient.Student.Name}-{DateTime.Now.ToString("dd/MM/yyyy")}.docx", Interests = list, StudentId = APIClient.Student.Id });
}
var items = _report.GetInterestLesson(new ReportBindingModel { Interests = list, StudentId = APIClient.Student.Id});
return PartialView("_LessonListPartial", items);
}
} }
} }

View File

@ -1 +1,23 @@
 @{
ViewData["Title"] = "Report";
}
<form id="my_form" asp-action="Reports" method="get" data-ajax="true" data-ajax-method="get" data-ajax-update="#panel" data-ajax-mode='replace' data-ajax-url="@Url.Action("GetPartial","Home")">
<select id="mode" name="mode">
<option>Excel</option>
<option>Word</option>
</select>
<div class="row">
<div class="col-4">Интересы:</div>
<div class="col-8">
@Html.ListBox("interests", (MultiSelectList)ViewBag.Interests)
</div>
</div>
<div class="row">
<div class="col-8"></div>
<div class="col-4"><input type="submit" value="Создать" class="btn btn-primary" /></div>
</div>
</form>
<div class="row pr-3 pl-3" id="panel">
@section scripts{
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-ajax-unobtrusive/3.2.6/jquery.unobtrusive-ajax.min.js"></script>
}

View File

@ -0,0 +1,35 @@
@using SchoolAgainStudyContracts.ViewModel;
@model List<ReportInterestLessonViewModel>
<div class="text-center">
@{
<table class="table">
<thead>
<tr>
<th>
Название
</th>
<th>
Интересы
</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Title)
</td>
<td>
<select asp-items="@(new SelectList(item.Lessons))"></select>
</td>
</tr>
}
</tbody>
</table>
}
</div>