This commit is contained in:
ker73rus 2023-05-20 09:55:46 +04:00
parent 89b1399fb8
commit 755c3027c4
6 changed files with 299 additions and 1 deletions

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UniversityContracts.ViewModels;
namespace UniversityContracts.BindingModels
{
public class StreamStudentBindingModel
{
public string FileType { get; set; } = string.Empty;
public List<StudentViewModel> Students { get; set; } = new();
}
}

View File

@ -116,8 +116,57 @@ namespace UniversityProvider.Controllers
($"api/discipline/getnumberofpages?userId={APIClient.User.Id}"); ($"api/discipline/getnumberofpages?userId={APIClient.User.Id}");
return View(); return View();
} }
public IActionResult StreamStudentList()
{
return View();
}
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] [HttpPost]
public int[]? StreamStudentList([FromBody] StreamStudentBindingModel listModel)
{
if (APIClient.User == null)
{
return Array.Empty<int>();
}
byte[]? file = APIClient.PostRequestWithResult<StreamStudentBindingModel, byte[]>
("api/reportprovider/streamstudentlist", listModel);
return file!.Select(b => (int)b).ToArray();
}
public IActionResult GetReport()
{
return View();
}
[HttpPost]
public List<ReportStreamStudentEdStatPeriodViewModel>? GetReport([FromBody] ReportBindingModel reportModel)
{
if (APIClient.User == null)
{
return new();
}
reportModel.UserId = APIClient.User.Id;
reportModel.UserEmail = APIClient.User.Login;
List<ReportStreamStudentEdStatPeriodViewModel>? list = APIClient.PostRequestWithResult<ReportBindingModel, List<ReportStreamStudentEdStatPeriodViewModel>>
("api/reportprovider/getreportdata", reportModel);
return list;
}
[HttpPost]
public void SendByMailStatusReport([FromBody] ReportBindingModel reportModel)
{
if (APIClient.User == null)
{
return;
}
reportModel.UserId = APIClient.User.Id;
reportModel.UserEmail = APIClient.User.Login;
APIClient.PostRequest("api/reportprovider/sendbymailstatusreport", reportModel);
}
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error() public IActionResult Error()
{ {
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });

View File

@ -0,0 +1,44 @@
@{
ViewData["Title"] = "Список студентов по потокам";
}
<div class="text-center">
<h1 class="display-4">Список студентов по потокам</h1>
</div>
<div id="error-div-shell" class="error-div-shell mb-2">
<div>
<p id="error-p" class="error-p"></p>
</div>
</div>
<div class="row justify-content-between">
<select class="form-select" id="file-type">
<option>docx</option>
<option>xlsx</option>
</select>
<button id="create-button" type="button" class="btn btn-primary mt-4">
Получить список по выбранным записям
</button>
</div>
<div class="mt-4">
<div class="scrollable-table">
<table class="table table-bordered">
<thead class="thead-light">
<tr>
<th>Имя</th>
<th>Фамилия</th>
<th>Дата рождения</th>
<th>Номер студ. билета</th>
<th>Статус обучения</th>
</tr>
</thead>
<tbody id="scrollable-table__tbody">
</tbody>
</table>
</div>
</div>
<script src="~/js/report/reportlist.js" asp-append-version="true"></script>

View File

@ -28,6 +28,12 @@
<li class="nav-item"> <li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Disciplines">Дисциплины</a> <a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Disciplines">Дисциплины</a>
</li> </li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="StreamStudentList">Получить список</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="GetReport">Получить отчёт</a>
</li>
</ul> </ul>
</div> </div>
</div> </div>

View File

@ -0,0 +1,97 @@
const createBtn = document.getElementById("create-button")
const tbody = document.getElementById("scrollable-table__tbody")
const nameInput = document.getElementById("name-input")
var fileType = document.getElementById("file-type")
var students = []
var dataArray = [];
const wordMIME = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
const excelMIME = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
window.addEventListener('load', () => {
$.ajax({
url: "/student/getallbyuser",
type: "GET",
contentType: "json"
}).done((result) => {
students = result;
students.forEach((student) => createRowForStudentsTable(student));
});
})
createBtn.addEventListener('click', () => {
let listModel = {
"Students": Array.from(dataArray),
"FileType": fileType.value
};
$.ajax({
url: "/home/streamstudentlist",
type: "POST",
contentType: "application/json",
data: JSON.stringify(listModel)
}).done((file) => {
let byteArray = new Uint8Array(file);
saveFile(byteArray, fileType);
});
})
const saveFile = async function (bytes, fileType) {
if (window.showSaveFilePicker) {
let type;
if (fileType.value == "docx") {
type = {
description: "Microsoft Word (OpenXML)",
accept: { [wordMIME]: [".docx"] }
};
} else if (fileType.value == "xlsx") {
type = {
description: "Microsoft Excel (OpenXML)",
accept: { [excelMIME]: [".xlsx"] }
};
}
const opts = {
suggestedName: `stream-student-list.${fileType.value}`,
types: [type],
};
const handle = await showSaveFilePicker(opts);
const writable = await handle.createWritable();
await writable.write(bytes);
writable.close();
}
}
const createRowForStudentsTable = (student) => {
const { id, name, surname, dateOfBirth, studentCard, educationStatusName } = student;
const row = tbody.insertRow();
row.setAttribute("data-id", id);
const cells = [name, surname, formatDate(dateOfBirth), studentCard, educationStatusName];
cells.forEach((value) => {
const cell = row.insertCell();
cell.textContent = value;
});
row.addEventListener('click', () => addAndRemoveFromList(row));
};
const formatDate = (dateString) => {
const date = new Date(dateString);
const year = date.getFullYear();
const month = ('0' + (date.getMonth() + 1)).slice(-2);
const day = ('0' + date.getDate()).slice(-2);
return `${year}-${month}-${day}`;
};
const addAndRemoveFromList = (row) => {
var id = parseInt(row.dataset.id);
console.log(students.find(x => x.id === id))
var index = dataArray.indexOf(students.find(x => x.id === id));
if (index === -1) {
dataArray.push(students.find(x => x.id === id));
row.classList.add("bg-success");
} else {
dataArray.splice(index, 1);
row.classList.remove("bg-success");
}
console.log(dataArray);
}

View File

@ -0,0 +1,87 @@
const dateFromInput = document.getElementById("date-from-input");
const dateToInput = document.getElementById("date-to-input");
const generateButton = document.getElementById("generate-button");
const sendByMailButton = document.getElementById("send-by-mail-button");
const dateToSpan = document.getElementById("date-to-span");
const dateFromSpan = document.getElementById("date-from-span");
const tbody = document.getElementById("tbody");
generateButton.addEventListener("click", () => {
const dateFrom = new Date(dateFromInput.value);
const dateTo = new Date(dateToInput.value);
const reportModel = {
"DateFrom": dateFrom,
"DateTo": dateTo
};
$.ajax({
url: "/home/getreport",
type: "POST",
contentType: "application/json",
data: JSON.stringify(reportModel)
}).done((data) => {
dateFromSpan.innerHTML = reportModel["DateFrom"].toLocaleDateString();
dateToSpan.innerHTML = reportModel["DateTo"].toLocaleDateString();
renderTable(data);
});
});
const formatDate = (dateString) => {
const date = new Date(dateString);
const year = date.getFullYear();
const month = ('0' + (date.getMonth() + 1)).slice(-2);
const day = ('0' + date.getDate()).slice(-2);
return `${year}-${month}-${day}`;
};
sendByMailButton.addEventListener("click", () => {
const dateFrom = new Date(dateFromInput.value);
const dateTo = new Date(dateToInput.value);
const reportModel = {
"DateFrom": dateFrom,
"DateTo": dateTo
};
$.ajax({
url: "/home/sendbymailstatusreport",
type: "POST",
contentType: "application/json",
data: JSON.stringify(reportModel)
}).done(() => {
alert("Отчет успешно отправлен на вашу почту!")
});
});
const renderTable = (data) => {
tbody.innerHTML = "";
for (var i = 0; i < data.length; i++) {
var streamData = data[i];
var streamName = streamData.streamName;
for (var j = 0; j < streamData.studentStatus.length; j++) {
var student = streamData.studentStatus[j];
if (j === 0) {
var row = tbody.insertRow();
var streamNameCell = row.insertCell()
streamNameCell.textContent = streamName;
var studentNameCell = row.insertCell();
var dateOfAdmissionCell = row.insertCell();
var studentStatusCell = row.insertCell();
tbody.appendChild(row)
}
var row = tbody.insertRow();
var streamNameCell = row.insertCell()
var studentNameCell = row.insertCell();
studentNameCell.textContent = student.studentName;
var dateOfAdmissionCell = row.insertCell();
dateOfAdmissionCell.textContent = formatDate(student.dateOfAddmission);
var studentStatusCell = row.insertCell();
studentStatusCell.textContent = student.educationStatus;
tbody.appendChild(row);
}
}
}