diff --git a/UniversityContracts/BindingModels/StreamStudentBindingModel.cs b/UniversityContracts/BindingModels/StreamStudentBindingModel.cs new file mode 100644 index 0000000..492d667 --- /dev/null +++ b/UniversityContracts/BindingModels/StreamStudentBindingModel.cs @@ -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 Students { get; set; } = new(); + } +} diff --git a/UniversityCustomer/Controllers/HomeController.cs b/UniversityCustomer/Controllers/HomeController.cs index 5b9d222..75ba5c3 100644 --- a/UniversityCustomer/Controllers/HomeController.cs +++ b/UniversityCustomer/Controllers/HomeController.cs @@ -116,8 +116,57 @@ namespace UniversityProvider.Controllers ($"api/discipline/getnumberofpages?userId={APIClient.User.Id}"); 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(); + } + byte[]? file = APIClient.PostRequestWithResult + ("api/reportprovider/streamstudentlist", listModel); + return file!.Select(b => (int)b).ToArray(); + } + + public IActionResult GetReport() + { + return View(); + } + + [HttpPost] + public List? GetReport([FromBody] ReportBindingModel reportModel) + { + if (APIClient.User == null) + { + return new(); + } + reportModel.UserId = APIClient.User.Id; + reportModel.UserEmail = APIClient.User.Login; + List? list = APIClient.PostRequestWithResult> + ("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() { return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); diff --git a/UniversityCustomer/Views/Home/StreamStudentList.cshtml b/UniversityCustomer/Views/Home/StreamStudentList.cshtml new file mode 100644 index 0000000..895d5cc --- /dev/null +++ b/UniversityCustomer/Views/Home/StreamStudentList.cshtml @@ -0,0 +1,44 @@ +@{ + ViewData["Title"] = "Список студентов по потокам"; +} + +
+

Список студентов по потокам

+
+ +
+
+

+
+
+ +
+ + + +
+ +
+
+ + + + + + + + + + + + +
ИмяФамилияДата рожденияНомер студ. билетаСтатус обучения
+
+
+ + \ No newline at end of file diff --git a/UniversityCustomer/Views/Shared/_Layout.cshtml b/UniversityCustomer/Views/Shared/_Layout.cshtml index 0ded43b..b0892ad 100644 --- a/UniversityCustomer/Views/Shared/_Layout.cshtml +++ b/UniversityCustomer/Views/Shared/_Layout.cshtml @@ -28,6 +28,12 @@ + + diff --git a/UniversityCustomer/wwwroot/js/report/reportlist.js b/UniversityCustomer/wwwroot/js/report/reportlist.js new file mode 100644 index 0000000..339c297 --- /dev/null +++ b/UniversityCustomer/wwwroot/js/report/reportlist.js @@ -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); +} \ No newline at end of file diff --git a/UniversityCustomer/wwwroot/js/report/reportpdf.js b/UniversityCustomer/wwwroot/js/report/reportpdf.js new file mode 100644 index 0000000..c09270b --- /dev/null +++ b/UniversityCustomer/wwwroot/js/report/reportpdf.js @@ -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); + } + } +}