diff --git a/UniversityBusinessLogic/BusinessLogics/ReportCustomerLogic.cs b/UniversityBusinessLogic/BusinessLogics/ReportCustomerLogic.cs index edbd290..b86c327 100644 --- a/UniversityBusinessLogic/BusinessLogics/ReportCustomerLogic.cs +++ b/UniversityBusinessLogic/BusinessLogics/ReportCustomerLogic.cs @@ -1,17 +1,13 @@ -/*using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using UniversityContracts.BindingModels; +using UniversityContracts.BindingModels; using UniversityContracts.BusinessLogicContracts; using UniversityContracts.ViewModels; using UniversityContracts.SearchModels; using UniversityContracts.StoragesContracts; using UniversityBusinessLogic.OfficePackage; -using System.Reflection; -using System.Net; -using System.Reflection.Metadata; +using System.Reflection.PortableExecutable; +using DocumentFormat.OpenXml.InkML; +using DocumentFormat.OpenXml.Wordprocessing; +using UniversityBusinessLogic.BusinessLogic.OfficePackage; namespace UniversityBusinessLogic.BusinessLogics { @@ -23,9 +19,10 @@ namespace UniversityBusinessLogic.BusinessLogics private readonly IEducationGroupStorage _educationGroupStorage; private readonly IDisciplineStorage _disciplineStorage; private readonly IStreamStorage _streamStorage; - private readonly AbstractSaveToExcelProvider _saveToExcel; - private readonly AbstractSaveToWordProvider _saveToWord; - private readonly AbstractSaveToPdfProvider _saveToPdf; + private readonly WordBuilderCustomer _wordBuilder; + private readonly ExcelBuilderCustomer _excelBuilder; + private readonly PdfBuilderProvider _pdfBuilder; + private readonly MailSender _mailSender; public ReportCustomerLogic(IDocumentStorage documentStorage, IStudentStorage studentStorage, @@ -33,9 +30,10 @@ namespace UniversityBusinessLogic.BusinessLogics IEducationGroupStorage educationGroupStorage, IDisciplineStorage disciplineStorage, IStreamStorage streamStorage, - AbstractSaveToExcelProvider saveToExcel, - AbstractSaveToWordProvider saveToWord, - AbstractSaveToPdfProvider saveToPdf) + WordBuilderCustomer wordBuilder, + ExcelBuilderCustomer excelBuilder, + PdfBuilderProvider pdfBuilder, + MailSender mailSender) { _documentStorage = documentStorage; _studentStorage = studentStorage; @@ -43,69 +41,88 @@ namespace UniversityBusinessLogic.BusinessLogics _educationGroupStorage = educationGroupStorage; _disciplineStorage = disciplineStorage; _streamStorage = streamStorage; - _saveToExcel = saveToExcel; - _saveToWord = saveToWord; - _saveToPdf = saveToPdf; + _wordBuilder = wordBuilder; + _excelBuilder = excelBuilder; + _pdfBuilder = pdfBuilder; + _mailSender = mailSender; } - public List GetDiscipline(ReportBindingModel model) + public List GetStudentsDiscipline(List students) { - var result = _streamStorage.GetFilteredList(new StreamSearchModel { Id = _disciplineStorage.GetElement(new DisciplineSearchModel { Name = model.DisciplineName })?.StreamId }) - .Select(stream => new ReportDisciplineViewModel + var reportRecords = new List(); + foreach (var student in students) + { + var disciplines = _studentStorage.GetStudentStreams(new() { Id = student.Id }) + .SelectMany(stream => _streamStorage.GetStreamDisciplines(new() { Id = stream.Id })) + .Select(discipline => discipline.Name) + .ToList(); + ReportStudentsDisciplineViewModel reportRecord = new() { - DisciplineName = model.DisciplineName, - StudentEdStatus = stream.StudentStream - .Where(student => _documentStorage.GetFilteredList(new DocumentSearchModel - { - UserId = model.UserId, - DateFrom = model.DateFrom, - DateTo = model.DateTo, - }) - .Any(document => document.DocumentStudents.Contains(student.Value)))//Выбираем студентов, которые есть в приказах за выбранный промежуток времени - .Join(_documentStorage.GetFullList(), - t1 => t1.Value.Id, - t2 => t2.UserId, - (t1, t2) => new { student = t1, document = t2 }) - .Select(res => ( - StudentFIO: $"{res.student.Value.Name} {res.student.Value.Surname}", - Document: $"{res.document.Date}", - EdStatus: _educationStatusStorage.GetElement(new EducationStatusSearchModel { Id = res.student.Value.EducationStatusId })?.Name ?? "не удалось получить")) - .ToList() - }) - .ToList(); - return result; + Student = student.Name + " " + student.Surname + ", " + student.StudentCard, + Disciplines = disciplines + }; + reportRecords.Add(reportRecord); + } + return reportRecords; } - public List StreamEducationStatus(List streams) + + + public byte[] SaveListFile(StreamStudentBindingModel model) { - var result = streams - .Select(stream => new ReportStreamEducationStatusViewModel - { - StreamName = stream.Name, - StudentEdStatus = stream.StudentStream - .Select(student => ( - StudentFIO: $"{student.Value.Name} {student.Value.Surname}", - EdStatus: _educationStatusStorage.GetElement(new EducationStatusSearchModel { Id = student.Value.EducationStatusId })?.Name ?? "не удалось получить")) - .ToList() - }) - .ToList(); - return result; + byte[] file = Array.Empty(); + + string title = "Список студентов по потоку " + model.StreamName; + + if (model.FileType == "docx") + { + _wordBuilder.CreateDocument(); + _wordBuilder.CreateTitle(title); + _wordBuilder.CreateStudentsStatusTable(model.Students); + file = _wordBuilder.GetFile(); + } + else if (model.FileType == "xlsx") + { + _excelBuilder.CreateDocument(); + _excelBuilder.CreateTitle(title); + _excelBuilder.CreateStudentsDisciplineTable(model.Students); + file = _excelBuilder.GetFile(); + } + return file; } + public void SendByMailStatusReport(ReportBindingModel reportModel) + { + /*byte[] file = _pdfBuilder.GetEducationStatusReportFile(new() + { + Title = "Отчет по статусам обучения", + DateFrom = reportModel.DateFrom, + DateTo = reportModel.DateTo, + Records = GetStreamStudentEdStatPeriod(reportModel) + }); + _mailSender.SendMailAsync(new() + { + MailAddress = reportModel.UserEmail, + Subject = "Отчет по статусам обучения", + Text = $"За период с {reportModel.DateFrom.ToShortDateString()} " + + $"по {reportModel.DateTo.ToShortDateString()}.", + File = file + });*/ + } - public void SaveBlanksToWordFile(ReportBindingModel model) + List IReportCustomerLogic.GetDiscipline(ReportBindingModel model) { throw new NotImplementedException(); } - public void SaveDocumentBlankToExcelFile(ReportBindingModel model) + List IReportCustomerLogic.StreamEducationStatus(List streams) { throw new NotImplementedException(); } - public void SaveOrdersToPdfFile(ReportBindingModel model) + + void IReportCustomerLogic.SendByMailStatusReport(ReportBindingModel reportModel) { throw new NotImplementedException(); } } } -*/ \ No newline at end of file diff --git a/UniversityBusinessLogic/BusinessLogics/StudentLogic.cs b/UniversityBusinessLogic/BusinessLogics/StudentLogic.cs index a2b93e8..d9c680d 100644 --- a/UniversityBusinessLogic/BusinessLogics/StudentLogic.cs +++ b/UniversityBusinessLogic/BusinessLogics/StudentLogic.cs @@ -112,5 +112,10 @@ namespace UniversityBusinessLogic.BusinessLogics throw new InvalidOperationException("Студент с таким номером студенческого билета уже есть"); } } + + public List GetStudentsFromStream(int streamId) + { + return _studentStorage.GetStudentsFromStream(streamId); + } } } diff --git a/UniversityBusinessLogic/OfficePackage/ExcelBuilderCustomer.cs b/UniversityBusinessLogic/OfficePackage/ExcelBuilderCustomer.cs new file mode 100644 index 0000000..a5b1463 --- /dev/null +++ b/UniversityBusinessLogic/OfficePackage/ExcelBuilderCustomer.cs @@ -0,0 +1,344 @@ +using DocumentFormat.OpenXml.Packaging; +using DocumentFormat.OpenXml.Spreadsheet; +using DocumentFormat.OpenXml; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UniversityBusinessLogic.OfficePackage.Models; +using UniversityContracts.ViewModels; + +namespace UniversityBusinessLogic.OfficePackage +{ + public class ExcelBuilderCustomer + { + private readonly string tempFileName = "temp.xlsx"; + private SpreadsheetDocument? spreadsheetDocument; + private SharedStringTablePart? shareStringPart; + private Worksheet? worksheet; + + private void CreateStyles(WorkbookPart workbookpart) + { + var sp = workbookpart.AddNewPart(); + sp.Stylesheet = new Stylesheet(); + + var fonts = new Fonts() { Count = 2U, KnownFonts = true }; + + var fontUsual = new Font(); + fontUsual.Append(new FontSize() { Val = 12D }); + fonts.Append(fontUsual); + + var fontTitle = new Font(); + fontTitle.Append(new Bold()); + fontTitle.Append(new FontSize() { Val = 12D }); + fonts.Append(fontTitle); + + var fills = new Fills() { Count = 3U }; + + var fill1 = new Fill(); + fill1.Append(new PatternFill() + { + PatternType = PatternValues.None + }); + + var fill2 = new Fill(); + fill2.Append(new PatternFill() + { + PatternType = PatternValues.Gray125 + }); + + var fill3 = new Fill(); + fill3.Append(new PatternFill() + { + PatternType = PatternValues.Solid, + ForegroundColor = new() + { + Rgb = "e0e8ff" + } + }); + + var fill4 = new Fill(); + fill1.Append(new PatternFill() + { + PatternType = PatternValues.None + }); + + fills.Append(fill1); + fills.Append(fill2); + fills.Append(fill3); + fills.Append(fill4); + + var borders = new Borders() { Count = 2U }; + + var borderNoBorder = new Border(); + borderNoBorder.Append(new LeftBorder()); + borderNoBorder.Append(new RightBorder()); + borderNoBorder.Append(new TopBorder()); + borderNoBorder.Append(new BottomBorder()); + borderNoBorder.Append(new DiagonalBorder()); + + var borderThin = new Border(); + + var leftBorder = new LeftBorder() { Style = BorderStyleValues.Thin }; + leftBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Indexed = 64U }); + var rightBorder = new RightBorder() { Style = BorderStyleValues.Thin }; + rightBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Indexed = 64U }); + var topBorder = new TopBorder() { Style = BorderStyleValues.Thin }; + topBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Indexed = 64U }); + var bottomBorder = new BottomBorder() { Style = BorderStyleValues.Thin }; + bottomBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Indexed = 64U }); + + borderThin.Append(leftBorder); + borderThin.Append(rightBorder); + borderThin.Append(topBorder); + borderThin.Append(bottomBorder); + borderThin.Append(new DiagonalBorder()); + + borders.Append(borderNoBorder); + borders.Append(borderThin); + + CellFormats cellFormats = new() { Count = 4U }; + CellFormat cellFormatEmpty = new() + { + FontId = 0U, + FillId = 0U, + BorderId = 1U, + ApplyFont = true + }; + CellFormat cellFormatDefault = new() + { + FontId = 0U, + FillId = 3U, + BorderId = 1U, + ApplyFont = true + }; + CellFormat cellFormatTitle = new() + { + FontId = 1U, + FillId = 2U, + BorderId = 1U, + ApplyFont = true, + ApplyBorder = true, + Alignment = new Alignment() + { + Vertical = VerticalAlignmentValues.Center, + Horizontal = HorizontalAlignmentValues.Center, + WrapText = true + } + }; + + cellFormats.Append(cellFormatEmpty); + cellFormats.Append(cellFormatDefault); + cellFormats.Append(cellFormatTitle); + + sp.Stylesheet.Append(fonts); + sp.Stylesheet.Append(fills); + sp.Stylesheet.Append(borders); + sp.Stylesheet.Append(cellFormats); + } + + public void CreateDocument() + { + spreadsheetDocument = SpreadsheetDocument.Create(tempFileName, + SpreadsheetDocumentType.Workbook); + WorkbookPart workbookpart = spreadsheetDocument.AddWorkbookPart(); + workbookpart.Workbook = new Workbook(); + + CreateStyles(workbookpart); + + shareStringPart = spreadsheetDocument.WorkbookPart! + .GetPartsOfType() + .Any() + ? spreadsheetDocument.WorkbookPart + .GetPartsOfType() + .First() + : spreadsheetDocument.WorkbookPart + .AddNewPart(); + + if (shareStringPart.SharedStringTable == null) + { + shareStringPart.SharedStringTable = new SharedStringTable(); + } + + WorksheetPart worksheetPart = workbookpart.AddNewPart(); + worksheetPart.Worksheet = new Worksheet(new SheetData()); + + Sheets sheets = spreadsheetDocument.WorkbookPart.Workbook.AppendChild(new Sheets()); + Sheet sheet = new() + { + Id = spreadsheetDocument.WorkbookPart.GetIdOfPart(worksheetPart), + SheetId = 1, + Name = "Лист" + }; + sheets.Append(sheet); + + worksheet = worksheetPart.Worksheet; + } + + public void InsertCellInWorksheet(ExcelCellData cellData) + { + if (worksheet == null || shareStringPart == null) + { + return; + } + var sheetData = worksheet.GetFirstChild(); + if (sheetData == null) + { + return; + } + + Row? row = sheetData.Elements() + .Where(r => r.RowIndex! == cellData.RowIndex) + .FirstOrDefault(); + if (row == null) + { + row = new Row() { RowIndex = cellData.RowIndex }; + sheetData.Append(row); + } + + Cell? cell = row.Elements() + .Where(c => c.CellReference!.Value == cellData.CellReference) + .FirstOrDefault(); + if (cell == null) + { + Cell? refCell = null; + foreach (Cell rowCell in row.Elements()) + { + if (string.Compare(rowCell.CellReference!.Value, cellData.CellReference, true) > 0) + { + refCell = rowCell; + break; + } + } + var newCell = new Cell() + { + CellReference = cellData.CellReference + }; + row.InsertBefore(newCell, refCell); + cell = newCell; + } + + shareStringPart.SharedStringTable.AppendChild(new SharedStringItem(new Text(cellData.Text))); + shareStringPart.SharedStringTable.Save(); + cell.CellValue = new CellValue((shareStringPart.SharedStringTable.Elements().Count() - 1).ToString()); + cell.DataType = new EnumValue(CellValues.SharedString); + cell.StyleIndex = cellData.StyleIndex; + } + + private void MergeCells(ExcelMergeParameters excelParams) + { + if (worksheet == null) + { + return; + } + MergeCells mergeCells; + if (worksheet.Elements().Any()) + { + mergeCells = worksheet.Elements().First(); + } + else + { + mergeCells = new MergeCells(); + if (worksheet.Elements().Any()) + { + worksheet.InsertAfter(mergeCells, worksheet.Elements().First()); + } + else + { + worksheet.InsertAfter(mergeCells, worksheet.Elements().First()); + } + } + var mergeCell = new MergeCell() + { + Reference = new StringValue(excelParams.Merge) + }; + mergeCells.Append(mergeCell); + } + + private void Save() + { + if (spreadsheetDocument == null) + { + return; + } + spreadsheetDocument.WorkbookPart!.Workbook.Save(); + spreadsheetDocument.Dispose(); + } + + public byte[] GetFile() + { + Save(); + byte[] file = File.ReadAllBytes(tempFileName); + File.Delete(tempFileName); + return file; + } + + public void CreateTitle(string text) + { + MergeCells(new ExcelMergeParameters + { + CellFromName = "A1", + CellToName = "B1" + }); + InsertCellInWorksheet(new ExcelCellData + { + ColumnName = "A", + RowIndex = 1, + Text = text, + StyleIndex = 0 + }); + } + + public void CreateStudentsDisciplineTable(List students) + { + if (worksheet == null || shareStringPart == null) + { + return; + } + + Columns columns = new(); + Column columnA = new() { Min = 1, Max = 1, Width = 30, CustomWidth = true }; + columns.Append(columnA); + Column columnB = new() { Min = 2, Max = 2, Width = 30, CustomWidth = true }; + columns.Append(columnB); + worksheet.InsertAt(columns, 0); + + InsertCellInWorksheet(new ExcelCellData + { + ColumnName = "A", + RowIndex = 2, + Text = "Студент", + StyleIndex = 2 + }); + InsertCellInWorksheet(new ExcelCellData + { + ColumnName = "B", + RowIndex = 2, + Text = "Дисциплина", + StyleIndex = 2 + }); + + uint currentRow = 3; + foreach (StudentViewModel student in students) + { + InsertCellInWorksheet(new ExcelCellData + { + ColumnName = "A", + RowIndex = currentRow, + Text = student.Name + " " + student.Surname, + StyleIndex = 1 + }); + InsertCellInWorksheet(new ExcelCellData + { + ColumnName = "B", + RowIndex = currentRow, + Text = student.EducationStatusName, + StyleIndex = 1 + }); + currentRow++; + + } + } + } +} diff --git a/UniversityBusinessLogic/OfficePackage/PdfBuilderProvider.cs b/UniversityBusinessLogic/OfficePackage/PdfBuilderProvider.cs index 48008c7..9700b55 100644 --- a/UniversityBusinessLogic/OfficePackage/PdfBuilderProvider.cs +++ b/UniversityBusinessLogic/OfficePackage/PdfBuilderProvider.cs @@ -164,7 +164,7 @@ namespace UniversityBusinessLogic.BusinessLogic.OfficePackage if (k < studentsAndStatus.Count) { cellsData[1] = studentsAndStatus[k].StudentName; - cellsData[2] = studentsAndStatus[k].DateOfAddmission.ToString("yyyy-MM-dd"); + //cellsData[2] = studentsAndStatus[k].DateOfAddmission.ToString("yyyy-MM-dd"); cellsData[3] = studentsAndStatus[k].EducationStatus; } CreateRow(new PdfRowParameters diff --git a/UniversityBusinessLogic/OfficePackage/WordBuilderCustomer.cs b/UniversityBusinessLogic/OfficePackage/WordBuilderCustomer.cs new file mode 100644 index 0000000..35449a1 --- /dev/null +++ b/UniversityBusinessLogic/OfficePackage/WordBuilderCustomer.cs @@ -0,0 +1,171 @@ +using DocumentFormat.OpenXml.Packaging; +using DocumentFormat.OpenXml.Wordprocessing; +using DocumentFormat.OpenXml; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UniversityBusinessLogic.OfficePackage.Models; +using UniversityContracts.ViewModels; + +namespace UniversityBusinessLogic.OfficePackage +{ + public class WordBuilderCustomer + { + + private readonly string tempFileName = "temp.docx"; + private WordprocessingDocument? wordDocument; + private Body? documentBody; + + public void CreateDocument() + { + wordDocument = WordprocessingDocument.Create(tempFileName, + WordprocessingDocumentType.Document); + MainDocumentPart mainPart = wordDocument.AddMainDocumentPart(); + mainPart.Document = new Document(); + documentBody = mainPart.Document.AppendChild(new Body()); + } + + public void CreateParagraph(string text) + { + if (documentBody == null) + { + return; + } + Paragraph paragraph = new(); + Run run = new(); + run.AppendChild(new Text + { + Text = text + }); + paragraph.AppendChild(run); + documentBody.AppendChild(paragraph); + } + + public void CreateTitle(string text) + { + if (documentBody == null) + { + return; + } + Paragraph paragraph = new(); + Run run = new(); + RunProperties properties = new(); + properties.AppendChild(new Bold()); + run.AppendChild(properties); + run.AppendChild(new Text + { + Text = text + }); + paragraph.AppendChild(run); + documentBody.AppendChild(paragraph); + } + + private TableCell CreateTableCell(string text, bool inHead = false, int? cellWidth = null) + { + Run run = new(); + TableCell tableCell = new(); + TableCellProperties cellProperties = new() + { + TableCellWidth = new() + { + Width = cellWidth.ToString() + }, + TableCellMargin = new() + { + LeftMargin = new() + { + Width = "100" + } + } + }; + if (inHead) + { + Shading shading = new() + { + Color = "auto", + Fill = "e0e8ff", + Val = ShadingPatternValues.Clear + }; + cellProperties.Append(shading); + RunProperties properties = new(); + properties.AppendChild(new Bold()); + run.AppendChild(properties); + } + run.AppendChild(new Text + { + Text = text + }); + Paragraph paragraph = new(run); + tableCell.AppendChild(paragraph); + tableCell.Append(cellProperties); + return tableCell; + } + + protected void CreateTable(WordTableData tableData) + { + if (documentBody == null || tableData == null) + { + return; + } + var table = new Table(); + + TableProperties tableProperties = new( + new TableBorders( + new TopBorder() { Val = new EnumValue(BorderValues.Single), Size = 3 }, + new BottomBorder() { Val = new EnumValue(BorderValues.Single), Size = 3 }, + new LeftBorder() { Val = new EnumValue(BorderValues.Single), Size = 3 }, + new RightBorder() { Val = new EnumValue(BorderValues.Single), Size = 3 }, + new InsideHorizontalBorder() { Val = new EnumValue(BorderValues.Single), Size = 3 }, + new InsideVerticalBorder() { Val = new EnumValue(BorderValues.Single), Size = 3 } + ) + ); + table.AppendChild(tableProperties); + + table.Append(new TableRow(tableData.Columns.Select(x => CreateTableCell(x.Item1, true, x.Item2)))); + table.Append(tableData.Rows.Select(x => new TableRow(x.Select(y => CreateTableCell(y))))); + + documentBody.AppendChild(table); + } + + private void Save() + { + if (documentBody == null || wordDocument == null) + { + return; + } + wordDocument.MainDocumentPart!.Document.Save(); + wordDocument.Dispose(); + } + + public byte[] GetFile() + { + Save(); + byte[] file = File.ReadAllBytes(tempFileName); + File.Delete(tempFileName); + return file; + } + + public void CreateStudentsStatusTable(List students) + { + List> rows = new(); + + + foreach(StudentViewModel student in students) { + List studentCells = new() { student.Name + " " + student.Surname, student.EducationStatusName }; + rows.Add(studentCells); + } + WordTableData wordTable = new() + { + Columns = new List<(string, int)>() + { + ("Студент", 3000), + ("Cтатус", 3000) + }, + Rows = rows + }; + CreateTable(wordTable); + } + } +} diff --git a/UniversityContracts/BindingModels/StreamStudentBindingModel.cs b/UniversityContracts/BindingModels/StreamStudentBindingModel.cs index 492d667..bc87bba 100644 --- a/UniversityContracts/BindingModels/StreamStudentBindingModel.cs +++ b/UniversityContracts/BindingModels/StreamStudentBindingModel.cs @@ -10,6 +10,7 @@ namespace UniversityContracts.BindingModels public class StreamStudentBindingModel { public string FileType { get; set; } = string.Empty; + public string StreamName { get; set; } public List Students { get; set; } = new(); } } diff --git a/UniversityContracts/BusinessLogicContracts/IStudentLogic.cs b/UniversityContracts/BusinessLogicContracts/IStudentLogic.cs index 974dbde..5c4dd7c 100644 --- a/UniversityContracts/BusinessLogicContracts/IStudentLogic.cs +++ b/UniversityContracts/BusinessLogicContracts/IStudentLogic.cs @@ -17,5 +17,6 @@ namespace UniversityContracts.BusinessLogicContracts List? ReadList(StudentSearchModel? model); StudentViewModel? ReadElement(StudentSearchModel model); int GetNumberOfPages(int userId, int pageSize = 10); - } + List GetStudentsFromStream(int streamId); + } } diff --git a/UniversityContracts/StoragesContracts/IStudentStorage.cs b/UniversityContracts/StoragesContracts/IStudentStorage.cs index 6ce9a49..4275cb6 100644 --- a/UniversityContracts/StoragesContracts/IStudentStorage.cs +++ b/UniversityContracts/StoragesContracts/IStudentStorage.cs @@ -18,6 +18,7 @@ namespace UniversityContracts.StoragesContracts StudentViewModel? Update(StudentBindingModel model); StudentViewModel? Delete(StudentBindingModel model); List GetStudentStreams(StudentSearchModel model); + List GetStudentsFromStream(int streamId); int GetNumberOfPages(int userId, int pageSize); } } diff --git a/UniversityContracts/ViewModels/StudentStatusViewModel.cs b/UniversityContracts/ViewModels/StudentStatusViewModel.cs index 5ee4331..a2cb48f 100644 --- a/UniversityContracts/ViewModels/StudentStatusViewModel.cs +++ b/UniversityContracts/ViewModels/StudentStatusViewModel.cs @@ -9,7 +9,7 @@ namespace UniversityContracts.ViewModels public class StudentStatusViewModel { public string StudentName { get; set; } = string.Empty; - public DateTime DateOfAddmission { get; set; } + public DateTime? DateOfAddmission { get; set; } public string EducationStatus { get; set; } = string.Empty; } } diff --git a/UniversityCustomer/Controllers/HomeController.cs b/UniversityCustomer/Controllers/HomeController.cs index 5331b4f..42c29b9 100644 --- a/UniversityCustomer/Controllers/HomeController.cs +++ b/UniversityCustomer/Controllers/HomeController.cs @@ -80,8 +80,12 @@ namespace UniversityProvider.Controllers ($"api/stream/getnumberofpages?userId={APIClient.User.Id}"); return View(); } - - public IActionResult EducationGroups(int page) + public List Status() + { + return APIClient.GetRequest> + ($"api/educationstatus/getall"); + } + public IActionResult EducationGroups(int page) { if (APIClient.User == null) { diff --git a/UniversityCustomer/Controllers/ReportCustomerController.cs b/UniversityCustomer/Controllers/ReportCustomerController.cs index 619ebb9..162d86b 100644 --- a/UniversityCustomer/Controllers/ReportCustomerController.cs +++ b/UniversityCustomer/Controllers/ReportCustomerController.cs @@ -16,6 +16,7 @@ namespace UniversityRestAPI.Controllers this.reportLogic = reportLogic; } + [HttpPost] public byte[] StreamStudentList(StreamStudentBindingModel listModel) { diff --git a/UniversityCustomer/Views/Home/StreamStudentList.cshtml b/UniversityCustomer/Views/Home/StreamStudentList.cshtml index 456925b..1aa9151 100644 --- a/UniversityCustomer/Views/Home/StreamStudentList.cshtml +++ b/UniversityCustomer/Views/Home/StreamStudentList.cshtml @@ -30,22 +30,5 @@ -
-
- - - - - - - - - - - - -
ИмяФамилияДата рожденияНомер студ. билетаСтатус обучения
-
-
\ No newline at end of file diff --git a/UniversityCustomer/wwwroot/js/report/reportlist.js b/UniversityCustomer/wwwroot/js/report/reportlist.js index 4ef4ee7..e057d05 100644 --- a/UniversityCustomer/wwwroot/js/report/reportlist.js +++ b/UniversityCustomer/wwwroot/js/report/reportlist.js @@ -34,12 +34,27 @@ createBtn.addEventListener('click', async () => { type: "GET", contentType: "json" }); + console.log(st); + const edst = await $.ajax({ + url: `status`, + type: "GET", + contentType: "json" + }); + console.log(edst); + console.log(select[select.selectedIndex].innerHTML); students = st.studentStream; students.forEach((student) => { - createRowForStudentsTable(student); - }) + edst.forEach((status) => { + if (student.educationStatusId = status.id) { + student.educationStatusName = status.name + } + + }); + }); + let listModel = { - "Students": Array.from(dataArray), + "StreamName": select[select.selectedIndex].innerHTML, + "Students": Array.from(students), "FileType": fileType.value }; $.ajax({ @@ -48,6 +63,7 @@ createBtn.addEventListener('click', async () => { contentType: "application/json", data: JSON.stringify(listModel) }).done((file) => { + console.log(file); let byteArray = new Uint8Array(file); saveFile(byteArray, fileType); }); diff --git a/UniversityDataBaseImplemet/Database.cs b/UniversityDataBaseImplemet/Database.cs index 7613a90..843e4f7 100644 --- a/UniversityDataBaseImplemet/Database.cs +++ b/UniversityDataBaseImplemet/Database.cs @@ -10,7 +10,7 @@ namespace UniversityDataBaseImplemet { if (optionsBuilder.IsConfigured == false) { - optionsBuilder.UseNpgsql("Host=localhost;Port=5432;Database=UniversityCourseWork;Username=postgres;Password=4757"); + optionsBuilder.UseNpgsql("Host=localhost;Port=5432;Database=UniversityCourseWork;Username=postgres;Password=0000"); } base.OnConfiguring(optionsBuilder); } diff --git a/UniversityDataBaseImplemet/Implements/StreamStorage.cs b/UniversityDataBaseImplemet/Implements/StreamStorage.cs index 61a89ad..c43a3d3 100644 --- a/UniversityDataBaseImplemet/Implements/StreamStorage.cs +++ b/UniversityDataBaseImplemet/Implements/StreamStorage.cs @@ -31,6 +31,11 @@ namespace UniversityDataBaseImplemet.Implements || record.Name.Equals(model.Name)) ?.GetViewModel; } + + + + + public List GetFilteredList(StreamSearchModel model) { using var context = new Database(); diff --git a/UniversityDataBaseImplemet/Implements/StudentStorage.cs b/UniversityDataBaseImplemet/Implements/StudentStorage.cs index b48b296..6f71edb 100644 --- a/UniversityDataBaseImplemet/Implements/StudentStorage.cs +++ b/UniversityDataBaseImplemet/Implements/StudentStorage.cs @@ -100,6 +100,19 @@ namespace UniversityDataBaseImplemet.Implements .Select(record => record.GetViewModel) .ToList(); } + + public List GetStudentsFromStream(int streamId) + { + using var context = new Database(); + return context.StudentStreams + .Include(x => x.Student) + .Where(x => x.StreamId == streamId) + .Select(x => x.Student.GetViewModel) + .ToList(); + } + + + public StudentViewModel? Insert(StudentBindingModel model) { var newStudent = Student.Create(model); diff --git a/UniversityRestAPI/Controllers/EducationStatusController.cs b/UniversityRestAPI/Controllers/EducationStatusController.cs index 0ff3f26..73f254f 100644 --- a/UniversityRestAPI/Controllers/EducationStatusController.cs +++ b/UniversityRestAPI/Controllers/EducationStatusController.cs @@ -29,6 +29,19 @@ namespace UniversityRestAPI.Controllers throw; } } + [HttpGet] + public List? GetAll() + { + try + { + return _educationStatusLogic.ReadList(null); + } + catch (Exception ex) + { + throw; + } + } + [HttpGet] public List? GetAllByUser(int userId) diff --git a/UniversityRestAPI/Controllers/ReportCustomerController.cs b/UniversityRestAPI/Controllers/ReportCustomerController.cs index 619ebb9..7122486 100644 --- a/UniversityRestAPI/Controllers/ReportCustomerController.cs +++ b/UniversityRestAPI/Controllers/ReportCustomerController.cs @@ -19,6 +19,7 @@ namespace UniversityRestAPI.Controllers [HttpPost] public byte[] StreamStudentList(StreamStudentBindingModel listModel) { + Console.BackgroundColor = ConsoleColor.Green; byte[] file = reportLogic.SaveListFile(listModel); return file; } diff --git a/UniversityRestAPI/Controllers/StudentController.cs b/UniversityRestAPI/Controllers/StudentController.cs index 8edb35a..4f5e205 100644 --- a/UniversityRestAPI/Controllers/StudentController.cs +++ b/UniversityRestAPI/Controllers/StudentController.cs @@ -146,5 +146,17 @@ namespace UniversityRestAPI.Controllers throw; } } + [HttpGet] + public List GetStudentsFromStream(int streamId ) { + try + { + + return _studentLogic.GetStudentsFromStream(streamId); + } + catch (Exception ex) + { + throw; + } + } } } diff --git a/UniversityRestAPI/Program.cs b/UniversityRestAPI/Program.cs index 138a868..4bb4e49 100644 --- a/UniversityRestAPI/Program.cs +++ b/UniversityRestAPI/Program.cs @@ -27,9 +27,12 @@ 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.AddSingleton();