diff --git a/UniversityBusinessLogic/BusinessLogics/ReportCustomerLogic.cs b/UniversityBusinessLogic/BusinessLogics/ReportCustomerLogic.cs index 75c4986..edbd290 100644 --- a/UniversityBusinessLogic/BusinessLogics/ReportCustomerLogic.cs +++ b/UniversityBusinessLogic/BusinessLogics/ReportCustomerLogic.cs @@ -1,4 +1,4 @@ -using System; +/*using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -108,3 +108,4 @@ namespace UniversityBusinessLogic.BusinessLogics } } } +*/ \ No newline at end of file diff --git a/UniversityBusinessLogic/BusinessLogics/ReportProviderLogic.cs b/UniversityBusinessLogic/BusinessLogics/ReportProviderLogic.cs index 9ad3b15..357c2d9 100644 --- a/UniversityBusinessLogic/BusinessLogics/ReportProviderLogic.cs +++ b/UniversityBusinessLogic/BusinessLogics/ReportProviderLogic.cs @@ -1,14 +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 CarDealershipBusinessLogic.BusinessLogic.OfficePackage; using UniversityBusinessLogic.OfficePackage; +using System.Reflection.PortableExecutable; +using DocumentFormat.OpenXml.InkML; +using DocumentFormat.OpenXml.Wordprocessing; namespace UniversityBusinessLogic.BusinessLogics { @@ -20,19 +19,19 @@ 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 WordBuilderProvider wordBuilder; + private readonly ExcelBuilderProvider excelBuilder; + private readonly PdfBuilderProvider pdfBuilder; public ReportProviderLogic(IDocumentStorage documentStorage, IStudentStorage studentStorage, IEducationStatusStorage educationStatusStorage, IEducationGroupStorage educationGroupStorage, IDisciplineStorage disciplineStorage, - IStreamStorage streamStorage, - AbstractSaveToExcelProvider saveToExcel, - AbstractSaveToWordProvider saveToWord, - AbstractSaveToPdfProvider saveToPdf) + IStreamStorage streamStorage, + WordBuilderProvider wordBuilder, + ExcelBuilderProvider excelBuilder, + PdfBuilderProvider pdfBuilder) { _documentStorage = documentStorage; _studentStorage = studentStorage; @@ -40,69 +39,96 @@ namespace UniversityBusinessLogic.BusinessLogics _educationGroupStorage = educationGroupStorage; _disciplineStorage = disciplineStorage; _streamStorage = streamStorage; - _saveToExcel = saveToExcel; - _saveToWord = saveToWord; - _saveToPdf = saveToPdf; + this.wordBuilder = wordBuilder; + this.excelBuilder = excelBuilder; + this.pdfBuilder = pdfBuilder; } public List GetStudentsDiscipline(List students) { - var result = students - .Select(student => new ReportStudentsDisciplineViewModel + 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() { - StudentFIO = $"{student.Name} {student.Surname}", - Disciplines = _streamStorage.GetFullList() - .Where(stream => stream.StudentStream.ContainsKey(student.Id)) - .Join(_disciplineStorage.GetFullList(), - stream => stream.Id, - discipline => discipline.StreamId, - (stream, discipline) => discipline.Name) - .ToList() - }) - .ToList(); - - return result; + Student = student.Name + " " + student.Surname + " " + student.StudentCard, + Disciplines = disciplines + }; + reportRecords.Add(reportRecord); + } + return reportRecords; } - public List StreamStudentEdStatPeriod(ReportBindingModel model) + public List GetStreamStudentEdStatPeriod(ReportBindingModel model) { - var result = _streamStorage - .GetFilteredList(new StreamSearchModel { UserId = model.UserId }) - .Select(stream => new ReportStreamStudentEdStatPeriodViewModel - { - StreamName = stream.Name, - StudentEdStatus = stream.StudentStream - .Where(student => _documentStorage.GetFilteredList(new DocumentSearchModel - { - UserId = model.UserId, - DateFrom = model.DateFrom, - DateTo = model.DateTo, - }) - .Any(document => document.DocumentStudents.Any(x => x.Id == student.Value.Id)))//Выбираем студентов, которые есть в приказах за выбранный промежуток времени - .Select(student => ( - StudentFIO: $"{student.Value.Name} {student.Value.Surname}", - EdStatus: _educationStatusStorage.GetElement(new EducationStatusSearchModel { Id = student.Value.EducationStatusId })?.Name ?? "не удалось получить")) - .ToList() - }) - .ToList(); - return result; + List reportRecords = new List(); + + var streams = _streamStorage.GetFilteredList(new StreamSearchModel() + { + UserId = model.UserId, + }); + + foreach (var stream in streams) + { + ReportStreamStudentEdStatPeriodViewModel reportData = new ReportStreamStudentEdStatPeriodViewModel(); + reportData.StreamName = stream.Name; + + var students = _streamStorage.GetStreamStudents(new() { Id = stream.Id }) + .Select(s => new StudentStatusViewModel() + { + StudentName = s.Name + " " + s.Surname, + EducationStatus = s.EducationStatusName + }) + .ToList(); + + reportData.StudentStatus = students; + + reportRecords.Add(reportData); + } + + return reportRecords; } - public void SaveBlanksToWordFile(ReportBindingModel model) + public byte[] SaveListFile(StudentDisciplineListBindingModel model) { - throw new NotImplementedException(); - //TODO + byte[] file = Array.Empty(); + if (model.FileType == "docx") + { + wordBuilder.CreateDocument(); + wordBuilder.CreateTitle("Список комплектаций по выбранным покупкам"); + wordBuilder.CreateStudentsDisciplineTable(GetStudentsDiscipline(model.Students)); + file = wordBuilder.GetFile(); + } + else if (model.FileType == "xlsx") + { + excelBuilder.CreateDocument(); + excelBuilder.CreateTitle("Список комплектаций по выбранным покупкам"); + excelBuilder.CreateStudentsDisciplineTable(GetStudentsDiscipline(model.Students)); + file = excelBuilder.GetFile(); + } + return file; } - public void SaveDocumentBlankToExcelFile(ReportBindingModel model) + public void SendByMailEducationStatusReport(ReportBindingModel reportModel) { - throw new NotImplementedException(); - //TODO - } - - public void SaveOrdersToPdfFile(ReportBindingModel model) - { - throw new NotImplementedException(); - //TODO + byte[] file = pdfBuilder.GetEquipmentReportFile(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 + }); */ } } } diff --git a/UniversityBusinessLogic/OfficePackage/AbstractSaveToExcelProvider.cs b/UniversityBusinessLogic/OfficePackage/AbstractSaveToExcelProvider.cs deleted file mode 100644 index 72e5fe5..0000000 --- a/UniversityBusinessLogic/OfficePackage/AbstractSaveToExcelProvider.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace UniversityBusinessLogic.OfficePackage -{ - public abstract class AbstractSaveToExcelProvider - { - } -} diff --git a/UniversityBusinessLogic/OfficePackage/AbstractSaveToPdfProvider.cs b/UniversityBusinessLogic/OfficePackage/AbstractSaveToPdfProvider.cs deleted file mode 100644 index ecc2618..0000000 --- a/UniversityBusinessLogic/OfficePackage/AbstractSaveToPdfProvider.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace UniversityBusinessLogic.OfficePackage -{ - public abstract class AbstractSaveToPdfProvider - { - } -} diff --git a/UniversityBusinessLogic/OfficePackage/AbstractSaveToWordProvider.cs b/UniversityBusinessLogic/OfficePackage/AbstractSaveToWordProvider.cs deleted file mode 100644 index b94b729..0000000 --- a/UniversityBusinessLogic/OfficePackage/AbstractSaveToWordProvider.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace UniversityBusinessLogic.OfficePackage -{ - public abstract class AbstractSaveToWordProvider - { - } -} diff --git a/UniversityBusinessLogic/OfficePackage/Enums/PdfParagraphAlignmentType.cs b/UniversityBusinessLogic/OfficePackage/Enums/PdfParagraphAlignmentType.cs new file mode 100644 index 0000000..edd5d03 --- /dev/null +++ b/UniversityBusinessLogic/OfficePackage/Enums/PdfParagraphAlignmentType.cs @@ -0,0 +1,8 @@ +namespace UniversityBusinessLogic.OfficePackage.Enums +{ + public enum PdfParagraphAlignmentType + { + Center, + Left + } +} diff --git a/UniversityBusinessLogic/OfficePackage/ExcelBuilderProvider.cs b/UniversityBusinessLogic/OfficePackage/ExcelBuilderProvider.cs new file mode 100644 index 0000000..61b6c25 --- /dev/null +++ b/UniversityBusinessLogic/OfficePackage/ExcelBuilderProvider.cs @@ -0,0 +1,356 @@ +using UniversityBusinessLogic.OfficePackage.Models; +using UniversityContracts.ViewModels; +using DocumentFormat.OpenXml; +using DocumentFormat.OpenXml.Packaging; +using DocumentFormat.OpenXml.Spreadsheet; + +namespace UniversityBusinessLogic.OfficePackage +{ + public class ExcelBuilderProvider + { + 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 data) + { + 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 (ReportStudentsDisciplineViewModel student in data) + { + InsertCellInWorksheet(new ExcelCellData + { + ColumnName = "A", + RowIndex = currentRow, + Text = student.Student, + StyleIndex = 1 + }); + InsertCellInWorksheet(new ExcelCellData + { + ColumnName = "B", + RowIndex = currentRow, + Text = "", + StyleIndex = 1 + }); + currentRow++; + foreach (string discipline in student.Disciplines) + { + InsertCellInWorksheet(new ExcelCellData + { + ColumnName = "A", + RowIndex = currentRow, + Text = "", + StyleIndex = 1 + }); + InsertCellInWorksheet(new ExcelCellData + { + ColumnName = "B", + RowIndex = currentRow, + Text = discipline, + StyleIndex = 1 + }); + currentRow++; + } + } + } + } +} diff --git a/UniversityBusinessLogic/OfficePackage/Models/ExcelCellData.cs b/UniversityBusinessLogic/OfficePackage/Models/ExcelCellData.cs new file mode 100644 index 0000000..6267863 --- /dev/null +++ b/UniversityBusinessLogic/OfficePackage/Models/ExcelCellData.cs @@ -0,0 +1,15 @@ +namespace UniversityBusinessLogic.OfficePackage.Models +{ + public class ExcelCellData + { + public string ColumnName { get; set; } = string.Empty; + + public uint RowIndex { get; set; } + + public string Text { get; set; } = string.Empty; + + public string CellReference => $"{ColumnName}{RowIndex}"; + + public uint StyleIndex { get; set; } = 0; + } +} diff --git a/UniversityBusinessLogic/OfficePackage/Models/ExcelMergeParameters.cs b/UniversityBusinessLogic/OfficePackage/Models/ExcelMergeParameters.cs new file mode 100644 index 0000000..c3d8d7e --- /dev/null +++ b/UniversityBusinessLogic/OfficePackage/Models/ExcelMergeParameters.cs @@ -0,0 +1,11 @@ +namespace UniversityBusinessLogic.OfficePackage.Models +{ + public class ExcelMergeParameters + { + public string CellFromName { get; set; } = string.Empty; + + public string CellToName { get; set; } = string.Empty; + + public string Merge => $"{CellFromName}:{CellToName}"; + } +} diff --git a/UniversityBusinessLogic/OfficePackage/Models/PdfData.cs b/UniversityBusinessLogic/OfficePackage/Models/PdfData.cs new file mode 100644 index 0000000..b1d7d93 --- /dev/null +++ b/UniversityBusinessLogic/OfficePackage/Models/PdfData.cs @@ -0,0 +1,13 @@ +namespace UniversityBusinessLogic.OfficePackage.Models +{ + public class PdfData + { + public string Title { get; set; } = string.Empty; + + public DateTime DateFrom { get; set; } + + public DateTime DateTo { get; set; } + + public List Records { get; set; } = new(); + } +} diff --git a/UniversityBusinessLogic/OfficePackage/Models/PdfParagraph.cs b/UniversityBusinessLogic/OfficePackage/Models/PdfParagraph.cs new file mode 100644 index 0000000..c356233 --- /dev/null +++ b/UniversityBusinessLogic/OfficePackage/Models/PdfParagraph.cs @@ -0,0 +1,11 @@ +using UniversityBusinessLogic.OfficePackage.Enums; + +namespace UniversityBusinessLogic.OfficePackage.Models +{ + public class PdfParagraph + { + public string Text { get; set; } = string.Empty; + public string Style { get; set; } = string.Empty; + public PdfParagraphAlignmentType ParagraphAlignment { get; set; } + } +} diff --git a/UniversityBusinessLogic/OfficePackage/Models/PdfRowParameters.cs b/UniversityBusinessLogic/OfficePackage/Models/PdfRowParameters.cs new file mode 100644 index 0000000..244869b --- /dev/null +++ b/UniversityBusinessLogic/OfficePackage/Models/PdfRowParameters.cs @@ -0,0 +1,11 @@ +using UniversityBusinessLogic.OfficePackage.Enums; + +namespace UniversityBusinessLogic.OfficePackage.Models +{ + public class PdfRowParameters + { + public List Texts { get; set; } = new(); + public string Style { get; set; } = string.Empty; + public PdfParagraphAlignmentType ParagraphAlignment { get; set; } + } +} diff --git a/UniversityBusinessLogic/OfficePackage/Models/WordTableData.cs b/UniversityBusinessLogic/OfficePackage/Models/WordTableData.cs new file mode 100644 index 0000000..ee57110 --- /dev/null +++ b/UniversityBusinessLogic/OfficePackage/Models/WordTableData.cs @@ -0,0 +1,8 @@ +namespace UniversityBusinessLogic.OfficePackage.Models +{ + public class WordTableData + { + public List<(string, int)> Columns { get; set; } = new(); + public List> Rows { get; set; } = new(); + } +} diff --git a/UniversityBusinessLogic/OfficePackage/PdfBuilderProvider.cs b/UniversityBusinessLogic/OfficePackage/PdfBuilderProvider.cs new file mode 100644 index 0000000..6678e94 --- /dev/null +++ b/UniversityBusinessLogic/OfficePackage/PdfBuilderProvider.cs @@ -0,0 +1,176 @@ +using UniversityBusinessLogic.OfficePackage.Enums; +using UniversityBusinessLogic.OfficePackage.Models; +using UniversityContracts.ViewModels; +using MigraDoc.DocumentObjectModel; +using MigraDoc.DocumentObjectModel.Tables; +using MigraDoc.Rendering; +using PdfSharp.Pdf; + +namespace CarDealershipBusinessLogic.BusinessLogic.OfficePackage +{ + public class PdfBuilderProvider + { + private readonly string tempFileName = "temp.pdf"; + private Document? document; + private Section? section; + private Table? table; + + private static ParagraphAlignment GetParagraphAlignment(PdfParagraphAlignmentType type) + { + return type switch + { + PdfParagraphAlignmentType.Center => ParagraphAlignment.Center, + PdfParagraphAlignmentType.Left => ParagraphAlignment.Left, + _ => ParagraphAlignment.Justify, + }; + } + + private void DefineStyles(Document document) + { + var style = document.Styles["Normal"]; + style.Font.Name = "Times New Roman"; + style.Font.Size = 14; + + style = document.Styles.AddStyle("NormalTitle", "Normal"); + style.Font.Bold = true; + } + + public void CreateDocument() + { + document = new Document(); + DefineStyles(document); + section = document.AddSection(); + } + + public void CreateParagraph(PdfParagraph pdfParagraph) + { + if (section == null) + { + return; + } + var paragraph = section.AddParagraph(pdfParagraph.Text); + paragraph.Format.SpaceAfter = "1cm"; + paragraph.Format.Alignment = GetParagraphAlignment(pdfParagraph.ParagraphAlignment); + paragraph.Style = pdfParagraph.Style; + } + + public void CreateTable(List columns) + { + if (document == null) + { + return; + } + table = document.LastSection.AddTable(); + foreach (var elem in columns) + { + table.AddColumn(elem); + } + } + + public void CreateRow(PdfRowParameters rowParameters) + { + if (table == null) + { + return; + } + var row = table.AddRow(); + for (int i = 0; i < rowParameters.Texts.Count; ++i) + { + row.Cells[i].AddParagraph(rowParameters.Texts[i]); + if (!string.IsNullOrEmpty(rowParameters.Style)) + { + row.Cells[i].Style = rowParameters.Style; + } + Unit borderWidth = 0.5; + row.Cells[i].Borders.Left.Width = borderWidth; + row.Cells[i].Borders.Right.Width = borderWidth; + row.Cells[i].Borders.Top.Width = borderWidth; + row.Cells[i].Borders.Bottom.Width = borderWidth; + row.Cells[i].Format.Alignment = GetParagraphAlignment(rowParameters.ParagraphAlignment); + row.Cells[i].VerticalAlignment = VerticalAlignment.Center; + } + } + + private void Save() + { + var renderer = new PdfDocumentRenderer(true) + { + Document = document + }; + renderer.RenderDocument(); + renderer.PdfDocument.Save(tempFileName); + } + + public byte[] GetFile() + { + Save(); + byte[] file = File.ReadAllBytes(tempFileName); + File.Delete(tempFileName); + return file; + } + + public byte[] GetEquipmentReportFile(PdfData data) + { + CreateDocument(); + + CreateParagraph(new PdfParagraph + { + Text = data.Title, + Style = "NormalTitle", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + + CreateParagraph(new PdfParagraph + { + Text = $"за период с {data.DateFrom.ToShortDateString()} " + + $"по {data.DateTo.ToShortDateString()}", + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + + CreateTable(new List { "5cm", "5cm", "5cm" }); + + CreateRow(new PdfRowParameters + { + Texts = new List { "Статус обучения", "Поток", "Количество студентов" }, + Style = "NormalTitle", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + + foreach (var record in data.Records) + { + List studentsAndStatus = record.StudentStatus; + int recordHeight = studentsAndStatus.Count + 1; + for (int i = 0; i < recordHeight; i++) + { + List cellsData = new() { "", "", "" }; + if (i == 0) + { + cellsData[0] = record.StreamName; + CreateRow(new PdfRowParameters + { + Texts = cellsData, + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Left + }); + continue; + } + int k = i - 1; + if (k < studentsAndStatus.Count) + { + cellsData[1] = studentsAndStatus[k].StudentName; + cellsData[2] = studentsAndStatus[k].EducationStatus; + } + CreateRow(new PdfRowParameters + { + Texts = cellsData, + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Left + }); + } + } + + return GetFile(); + } + } +} diff --git a/UniversityBusinessLogic/OfficePackage/WordBuilderProvider.cs b/UniversityBusinessLogic/OfficePackage/WordBuilderProvider.cs new file mode 100644 index 0000000..124e536 --- /dev/null +++ b/UniversityBusinessLogic/OfficePackage/WordBuilderProvider.cs @@ -0,0 +1,170 @@ +using UniversityBusinessLogic.OfficePackage.Models; +using UniversityContracts.ViewModels; +using DocumentFormat.OpenXml; +using DocumentFormat.OpenXml.Packaging; +using DocumentFormat.OpenXml.Wordprocessing; + +namespace CarDealershipBusinessLogic.BusinessLogic.OfficePackage +{ + public class WordBuilderProvider + { + 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 CreateStudentsDisciplineTable(List data) + { + List> rows = new(); + foreach (ReportStudentsDisciplineViewModel student in data) + { + List disciplineCells = new() { student.Student, "" }; + rows.Add(disciplineCells); + List workCells; + foreach (string discipline in student.Disciplines) + { + workCells = new() { "", discipline }; + rows.Add(workCells); + } + } + WordTableData wordTable = new() + { + Columns = new List<(string, int)>() + { + ("Дисциплина", 3000), + ("Студент", 3000) + }, + Rows = rows + }; + CreateTable(wordTable); + } + } +} diff --git a/UniversityBusinessLogic/UniversityBusinessLogic.csproj b/UniversityBusinessLogic/UniversityBusinessLogic.csproj index 188dc46..41a3377 100644 --- a/UniversityBusinessLogic/UniversityBusinessLogic.csproj +++ b/UniversityBusinessLogic/UniversityBusinessLogic.csproj @@ -11,9 +11,12 @@ - - + + + + + diff --git a/UniversityContracts/BindingModels/ReportBindingModel.cs b/UniversityContracts/BindingModels/ReportBindingModel.cs index 8c8589b..0f607a4 100644 --- a/UniversityContracts/BindingModels/ReportBindingModel.cs +++ b/UniversityContracts/BindingModels/ReportBindingModel.cs @@ -8,10 +8,9 @@ namespace UniversityContracts.BindingModels { public class ReportBindingModel { - public string FileName { get; set; } = string.Empty; - public string DisciplineName { get; set; } = string.Empty; - public DateTime? DateFrom { get; set; } - public DateTime? DateTo { get; set; } - public int? UserId { get; set; } + public string UserEmail { get; set; } = string.Empty; + public DateTime DateFrom { get; set; } + public DateTime DateTo { get; set; } + public int UserId { get; set; } } } diff --git a/UniversityContracts/BindingModels/StudentBindingModel.cs b/UniversityContracts/BindingModels/StudentBindingModel.cs index 7438b76..beb17d9 100644 --- a/UniversityContracts/BindingModels/StudentBindingModel.cs +++ b/UniversityContracts/BindingModels/StudentBindingModel.cs @@ -13,6 +13,7 @@ namespace UniversityContracts.BindingModels public string Name { get; set; } = string.Empty; public string Surname { get; set; } = string.Empty; public DateTime DateOfBirth { get; set; } + public DateTime DateOfAddmission { get; set; } public int StudentCard { get; set; } public int? EducationStatusId { get; set; } public int UserId { get; set; } diff --git a/UniversityContracts/BindingModels/StudentDisciplineListBindingModel.cs b/UniversityContracts/BindingModels/StudentDisciplineListBindingModel.cs new file mode 100644 index 0000000..8eef451 --- /dev/null +++ b/UniversityContracts/BindingModels/StudentDisciplineListBindingModel.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 StudentDisciplineListBindingModel + { + public string FileType { get; set; } = string.Empty; + public List Students { get; set; } = new(); + } +} diff --git a/UniversityContracts/BusinessLogicContracts/IReportProviderLogic.cs b/UniversityContracts/BusinessLogicContracts/IReportProviderLogic.cs index 539d8c6..066fb4f 100644 --- a/UniversityContracts/BusinessLogicContracts/IReportProviderLogic.cs +++ b/UniversityContracts/BusinessLogicContracts/IReportProviderLogic.cs @@ -12,12 +12,10 @@ namespace UniversityContracts.BusinessLogicContracts { List GetStudentsDiscipline(List students); - List StreamStudentEdStatPeriod(ReportBindingModel model); + List GetStreamStudentEdStatPeriod(ReportBindingModel model); - void SaveBlanksToWordFile(ReportBindingModel model); + byte[] SaveListFile(StudentDisciplineListBindingModel model); - void SaveDocumentBlankToExcelFile(ReportBindingModel model); - - void SaveOrdersToPdfFile(ReportBindingModel model); + void SendByMailEducationStatusReport(ReportBindingModel reportModel); } } diff --git a/UniversityContracts/StoragesContracts/IStreamStorage.cs b/UniversityContracts/StoragesContracts/IStreamStorage.cs index e9cc104..ab5e822 100644 --- a/UniversityContracts/StoragesContracts/IStreamStorage.cs +++ b/UniversityContracts/StoragesContracts/IStreamStorage.cs @@ -17,5 +17,7 @@ namespace UniversityContracts.StoragesContracts StreamViewModel? Insert(StreamBindingModel model); StreamViewModel? Update(StreamBindingModel model); StreamViewModel? Delete(StreamBindingModel model); + List GetStreamDisciplines(StreamSearchModel model); + List GetStreamStudents(StreamSearchModel model); } } diff --git a/UniversityContracts/StoragesContracts/IStudentStorage.cs b/UniversityContracts/StoragesContracts/IStudentStorage.cs index 369ff95..6ce9a49 100644 --- a/UniversityContracts/StoragesContracts/IStudentStorage.cs +++ b/UniversityContracts/StoragesContracts/IStudentStorage.cs @@ -17,6 +17,7 @@ namespace UniversityContracts.StoragesContracts StudentViewModel? Insert(StudentBindingModel model); StudentViewModel? Update(StudentBindingModel model); StudentViewModel? Delete(StudentBindingModel model); + List GetStudentStreams(StudentSearchModel model); int GetNumberOfPages(int userId, int pageSize); } } diff --git a/UniversityContracts/ViewModels/ReportStreamStudentEdStatPeriodViewModel.cs b/UniversityContracts/ViewModels/ReportStreamStudentEdStatPeriodViewModel.cs index 3871b27..1d875b2 100644 --- a/UniversityContracts/ViewModels/ReportStreamStudentEdStatPeriodViewModel.cs +++ b/UniversityContracts/ViewModels/ReportStreamStudentEdStatPeriodViewModel.cs @@ -10,6 +10,6 @@ namespace UniversityContracts.ViewModels { public int Id { get; set; } public string StreamName { get; set; } = string.Empty; - public List<(string StudentFIO, string EdStatus)> StudentEdStatus { get; set; } = new(); + public List StudentStatus { get; set; } = new(); } } diff --git a/UniversityContracts/ViewModels/ReportStudentsDisciplineViewModel.cs b/UniversityContracts/ViewModels/ReportStudentsDisciplineViewModel.cs index 6d14046..7b11c70 100644 --- a/UniversityContracts/ViewModels/ReportStudentsDisciplineViewModel.cs +++ b/UniversityContracts/ViewModels/ReportStudentsDisciplineViewModel.cs @@ -8,7 +8,7 @@ namespace UniversityContracts.ViewModels { public class ReportStudentsDisciplineViewModel { - public string StudentFIO { get; set; } = string.Empty; + public string Student { get; set; } = string.Empty; public List Disciplines { get; set; } = new(); } } diff --git a/UniversityContracts/ViewModels/StudentStatusViewModel.cs b/UniversityContracts/ViewModels/StudentStatusViewModel.cs new file mode 100644 index 0000000..c4f93a8 --- /dev/null +++ b/UniversityContracts/ViewModels/StudentStatusViewModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace UniversityContracts.ViewModels +{ + public class StudentStatusViewModel + { + public string StudentName { get; set; } = string.Empty; + public string EducationStatus { get; set; } = string.Empty; + } +} diff --git a/UniversityContracts/ViewModels/StudentViewModel.cs b/UniversityContracts/ViewModels/StudentViewModel.cs index 7b5ab7c..caeaab5 100644 --- a/UniversityContracts/ViewModels/StudentViewModel.cs +++ b/UniversityContracts/ViewModels/StudentViewModel.cs @@ -19,6 +19,8 @@ namespace UniversityContracts.ViewModels public string Surname { get; set; } = string.Empty; [DisplayName("Дата рождения студента")] public DateTime DateOfBirth { get; set; } = DateTime.Now; + [DisplayName("Дата поступления")] + public DateTime DateOfAddmission { get; set; } = DateTime.Now; [DisplayName("Статус обучения")] public string EducationStatusName { get; set; } = string.Empty; public int StudentCard { get; set; } diff --git a/UniversityDataBaseImplemet/Implements/DocumentStorage.cs b/UniversityDataBaseImplemet/Implements/DocumentStorage.cs index 50e04b0..02dd7c0 100644 --- a/UniversityDataBaseImplemet/Implements/DocumentStorage.cs +++ b/UniversityDataBaseImplemet/Implements/DocumentStorage.cs @@ -47,20 +47,6 @@ namespace UniversityDataBaseImplemet.Implements .Select(record => record.GetViewModel) .ToList(); } - else if (model.DateFrom != null && model.DateTo != null && model.UserId.HasValue) - { - return context.Documents - .Where(d => d.Date >= model.DateFrom && d.Date <= model.DateTo && d.UserId == model.UserId) - .Include(d => d.Students) - .ThenInclude(sd => sd.Student) - .ThenInclude(s => s.StudentStream) - .ThenInclude(ss => ss.Stream) - .Include(d => d.Students) - .ThenInclude(sd => sd.Student) - .ThenInclude(s => s.EducationStatus) - .Select(result => result.GetViewModel) - .ToList(); - } else if (model.UserId.HasValue) { return context.Documents diff --git a/UniversityDataBaseImplemet/Implements/StreamStorage.cs b/UniversityDataBaseImplemet/Implements/StreamStorage.cs index 5edc699..aa5daf6 100644 --- a/UniversityDataBaseImplemet/Implements/StreamStorage.cs +++ b/UniversityDataBaseImplemet/Implements/StreamStorage.cs @@ -44,7 +44,7 @@ namespace UniversityDataBaseImplemet.Implements { return context.Streams .Include(record => record.StreamStudents) - .ThenInclude(record => record.Student) + .ThenInclude(record => record.Student) .Where(record => record.UserId == model.UserId) .Select(record => record.GetViewModel) .ToList(); @@ -112,5 +112,32 @@ namespace UniversityDataBaseImplemet.Implements context.SaveChanges(); return stream.GetViewModel; } + + public List GetStreamDisciplines(StreamSearchModel model) { + if (model == null) + { + return new(); + } + using var context = new Database(); + var disciplines = context.Discipline + .Where(x => x.StreamId == model.Id) + .Select(x => x.GetViewModel) + .ToList(); + return disciplines; + } + + public List GetStreamStudents(StreamSearchModel model) + { + if (model == null) + { + return new(); + } + using var context = new Database(); + var students = context.StudentStreams + .Where(x => x.StreamId == model.Id) + .Select(x => x.Student.GetViewModel) + .ToList(); + return students; + } } } diff --git a/UniversityDataBaseImplemet/Implements/StudentStorage.cs b/UniversityDataBaseImplemet/Implements/StudentStorage.cs index 6bddfd3..b48b296 100644 --- a/UniversityDataBaseImplemet/Implements/StudentStorage.cs +++ b/UniversityDataBaseImplemet/Implements/StudentStorage.cs @@ -60,6 +60,14 @@ namespace UniversityDataBaseImplemet.Implements .Select(record => record.GetViewModel) .ToList(); } + else if (model.DateFrom != null && model.DateTo != null && model.UserId.HasValue) + { + return context.Students + .Where(s => s.DateOfAddmission >= model.DateFrom && s.DateOfAddmission <= model.DateTo && s.UserId == model.UserId) + .Include(s => s.EducationStatus) + .Select(result => result.GetViewModel) + .ToList(); + } else if (model.UserId.HasValue && model.EducationStatusId.HasValue) { return context.Students @@ -152,5 +160,19 @@ namespace UniversityDataBaseImplemet.Implements int numberOfpages = (int)Math.Ceiling((double)carsCount / pageSize); return numberOfpages != 0 ? numberOfpages : 1; } + + public List GetStudentStreams(StudentSearchModel model) + { + if (model == null) + { + return new(); + } + using var context = new Database(); + var streams = context.StudentStreams + .Where(x => x.StudentId == model.Id) + .Select(x => x.Stream.GetViewModel) + .ToList(); + return streams; + } } } diff --git a/UniversityDataBaseImplemet/Migrations/20230518162032_fix2.Designer.cs b/UniversityDataBaseImplemet/Migrations/20230518162032_fix2.Designer.cs new file mode 100644 index 0000000..d3da172 --- /dev/null +++ b/UniversityDataBaseImplemet/Migrations/20230518162032_fix2.Designer.cs @@ -0,0 +1,488 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using UniversityDataBaseImplemet; + +#nullable disable + +namespace UniversityDataBaseImplemet.Migrations +{ + [DbContext(typeof(Database))] + [Migration("20230518162032_fix2")] + partial class fix2 + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.5") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.Discipline", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Hours") + .HasColumnType("integer"); + + b.Property("MarkType") + .HasColumnType("boolean"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("StreamId") + .HasColumnType("integer"); + + b.Property("UserId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("StreamId"); + + b.HasIndex("UserId"); + + b.ToTable("Discipline"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.Document", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Date") + .HasColumnType("timestamp with time zone"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("UserId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Documents"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.EducationGroup", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("NumberOfStudent") + .HasColumnType("integer"); + + b.Property("UserId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("EducationGroups"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.EducationGroupDocument", b => + { + b.Property("EducationGroupId") + .HasColumnType("integer"); + + b.Property("DocumentId") + .HasColumnType("integer"); + + b.HasKey("EducationGroupId", "DocumentId"); + + b.HasIndex("DocumentId"); + + b.ToTable("EducationGroupsDocuments"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.EducationGroupStream", b => + { + b.Property("EducationGroupId") + .HasColumnType("integer"); + + b.Property("StreamId") + .HasColumnType("integer"); + + b.HasKey("EducationGroupId", "StreamId"); + + b.HasIndex("StreamId"); + + b.ToTable("EducationGroupsStreams"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.EducationStatus", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("UserId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("EducationStatuses"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.Stream", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Course") + .HasColumnType("integer"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("UserId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Streams"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.Student", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("DateOfAddmission") + .HasColumnType("timestamp with time zone"); + + b.Property("DateOfBirth") + .HasColumnType("timestamp with time zone"); + + b.Property("EducationStatusId") + .HasColumnType("integer"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("StudentCard") + .HasColumnType("integer"); + + b.Property("Surname") + .IsRequired() + .HasColumnType("text"); + + b.Property("UserId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("EducationStatusId"); + + b.HasIndex("UserId"); + + b.ToTable("Students"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.StudentDocument", b => + { + b.Property("StudentId") + .HasColumnType("integer"); + + b.Property("DocumentId") + .HasColumnType("integer"); + + b.HasKey("StudentId", "DocumentId"); + + b.HasIndex("DocumentId"); + + b.ToTable("StudentDocuments"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.StudentStream", b => + { + b.Property("StudentId") + .HasColumnType("integer"); + + b.Property("StreamId") + .HasColumnType("integer"); + + b.HasKey("StudentId", "StreamId"); + + b.HasIndex("StreamId"); + + b.ToTable("StudentStreams"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Login") + .IsRequired() + .HasColumnType("text"); + + b.Property("Password") + .IsRequired() + .HasColumnType("text"); + + b.Property("Role") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("User"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.Discipline", b => + { + b.HasOne("UniversityDataBaseImplemet.Models.Stream", "Stream") + .WithMany() + .HasForeignKey("StreamId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("UniversityDataBaseImplemet.Models.User", "User") + .WithMany("Disciplines") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Stream"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.Document", b => + { + b.HasOne("UniversityDataBaseImplemet.Models.User", "User") + .WithMany("Documents") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.NoAction) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.EducationGroup", b => + { + b.HasOne("UniversityDataBaseImplemet.Models.User", "User") + .WithMany("EducationGroups") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.EducationGroupDocument", b => + { + b.HasOne("UniversityDataBaseImplemet.Models.Document", "Document") + .WithMany("EducationGroupDocument") + .HasForeignKey("DocumentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("UniversityDataBaseImplemet.Models.EducationGroup", "EducationGroup") + .WithMany("EducationGroupDocument") + .HasForeignKey("EducationGroupId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Document"); + + b.Navigation("EducationGroup"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.EducationGroupStream", b => + { + b.HasOne("UniversityDataBaseImplemet.Models.EducationGroup", "EducationGroup") + .WithMany("EducationGroupStream") + .HasForeignKey("EducationGroupId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("UniversityDataBaseImplemet.Models.Stream", "Stream") + .WithMany("EducationGroupStream") + .HasForeignKey("StreamId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("EducationGroup"); + + b.Navigation("Stream"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.EducationStatus", b => + { + b.HasOne("UniversityDataBaseImplemet.Models.User", "User") + .WithMany("EducationStatuses") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.NoAction) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.Stream", b => + { + b.HasOne("UniversityDataBaseImplemet.Models.User", "User") + .WithMany("Streams") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.Student", b => + { + b.HasOne("UniversityDataBaseImplemet.Models.EducationStatus", "EducationStatus") + .WithMany("Students") + .HasForeignKey("EducationStatusId"); + + b.HasOne("UniversityDataBaseImplemet.Models.User", "User") + .WithMany("Students") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.NoAction) + .IsRequired(); + + b.Navigation("EducationStatus"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.StudentDocument", b => + { + b.HasOne("UniversityDataBaseImplemet.Models.Document", "Document") + .WithMany("Students") + .HasForeignKey("DocumentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("UniversityDataBaseImplemet.Models.Student", "Student") + .WithMany("DocumentStudents") + .HasForeignKey("StudentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Document"); + + b.Navigation("Student"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.StudentStream", b => + { + b.HasOne("UniversityDataBaseImplemet.Models.Stream", "Stream") + .WithMany("StreamStudents") + .HasForeignKey("StreamId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("UniversityDataBaseImplemet.Models.Student", "Student") + .WithMany("StudentStream") + .HasForeignKey("StudentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Stream"); + + b.Navigation("Student"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.Document", b => + { + b.Navigation("EducationGroupDocument"); + + b.Navigation("Students"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.EducationGroup", b => + { + b.Navigation("EducationGroupDocument"); + + b.Navigation("EducationGroupStream"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.EducationStatus", b => + { + b.Navigation("Students"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.Stream", b => + { + b.Navigation("EducationGroupStream"); + + b.Navigation("StreamStudents"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.Student", b => + { + b.Navigation("DocumentStudents"); + + b.Navigation("StudentStream"); + }); + + modelBuilder.Entity("UniversityDataBaseImplemet.Models.User", b => + { + b.Navigation("Disciplines"); + + b.Navigation("Documents"); + + b.Navigation("EducationGroups"); + + b.Navigation("EducationStatuses"); + + b.Navigation("Streams"); + + b.Navigation("Students"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/UniversityDataBaseImplemet/Migrations/20230518162032_fix2.cs b/UniversityDataBaseImplemet/Migrations/20230518162032_fix2.cs new file mode 100644 index 0000000..179873a --- /dev/null +++ b/UniversityDataBaseImplemet/Migrations/20230518162032_fix2.cs @@ -0,0 +1,30 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace UniversityDataBaseImplemet.Migrations +{ + /// + public partial class fix2 : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "DateOfAddmission", + table: "Students", + type: "timestamp with time zone", + nullable: false, + defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified)); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "DateOfAddmission", + table: "Students"); + } + } +} diff --git a/UniversityDataBaseImplemet/Migrations/DatabaseModelSnapshot.cs b/UniversityDataBaseImplemet/Migrations/DatabaseModelSnapshot.cs index 5c8e40d..62aa716 100644 --- a/UniversityDataBaseImplemet/Migrations/DatabaseModelSnapshot.cs +++ b/UniversityDataBaseImplemet/Migrations/DatabaseModelSnapshot.cs @@ -190,6 +190,9 @@ namespace UniversityDataBaseImplemet.Migrations NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + b.Property("DateOfAddmission") + .HasColumnType("timestamp with time zone"); + b.Property("DateOfBirth") .HasColumnType("timestamp with time zone"); diff --git a/UniversityDataBaseImplemet/Models/Student.cs b/UniversityDataBaseImplemet/Models/Student.cs index 9d46149..7227183 100644 --- a/UniversityDataBaseImplemet/Models/Student.cs +++ b/UniversityDataBaseImplemet/Models/Student.cs @@ -21,6 +21,8 @@ namespace UniversityDataBaseImplemet.Models [Required] public DateTime DateOfBirth { get; set; } [Required] + public DateTime DateOfAddmission { get; set; } + [Required] public int StudentCard { get; set; } public int? EducationStatusId { get; set; } @@ -41,6 +43,7 @@ namespace UniversityDataBaseImplemet.Models Name = model.Name, Surname = model.Surname, DateOfBirth = model.DateOfBirth, + DateOfAddmission = model.DateOfAddmission, StudentCard = model.StudentCard, EducationStatusId = model.EducationStatusId, UserId = model.UserId @@ -51,6 +54,7 @@ namespace UniversityDataBaseImplemet.Models Name = model.Name; Surname = model.Surname; DateOfBirth = model.DateOfBirth; + DateOfAddmission = model.DateOfAddmission; StudentCard = model.StudentCard; EducationStatusId = model.EducationStatusId; } @@ -60,6 +64,7 @@ namespace UniversityDataBaseImplemet.Models Name = Name, Surname = Surname, DateOfBirth = DateOfBirth, + DateOfAddmission = DateOfAddmission, StudentCard = StudentCard, EducationStatusId = EducationStatusId, UserId = UserId, diff --git a/UniversityModels/Models/IStudentModel.cs b/UniversityModels/Models/IStudentModel.cs index 52242e3..0bc2aec 100644 --- a/UniversityModels/Models/IStudentModel.cs +++ b/UniversityModels/Models/IStudentModel.cs @@ -11,6 +11,7 @@ namespace UniversityModels.Models string Name { get; } string Surname { get; } DateTime DateOfBirth { get; } + DateTime DateOfAddmission { get; } int StudentCard { get; } int? EducationStatusId { get; } int UserId { get; } diff --git a/UniversityProvider/APIClient.cs b/UniversityProvider/APIClient.cs index 9ef18e1..29a51f6 100644 --- a/UniversityProvider/APIClient.cs +++ b/UniversityProvider/APIClient.cs @@ -43,5 +43,25 @@ namespace UniversityProvider throw new Exception(result); } } + + public static O? PostRequestWithResult(string requestUrl, I model) + { + var json = JsonConvert.SerializeObject(model); + var data = new StringContent(json, Encoding.UTF8, "application/json"); + + var response = _user.PostAsync(requestUrl, data); + + var result = response.Result.Content.ReadAsStringAsync().Result; + + if (response.Result.IsSuccessStatusCode) + { + var temp = JsonConvert.DeserializeObject(result); + return temp; + } + else + { + return default; + } + } } } diff --git a/UniversityProvider/Controllers/HomeController.cs b/UniversityProvider/Controllers/HomeController.cs index 0b9a40c..1814ccc 100644 --- a/UniversityProvider/Controllers/HomeController.cs +++ b/UniversityProvider/Controllers/HomeController.cs @@ -116,6 +116,42 @@ namespace UniversityProvider.Controllers return View(); } + public IActionResult DisciplineStudentList() + { + return View(); + } + + [HttpPost] + public int[]? DisciplineStudentList([FromBody] StudentDisciplineListBindingModel listModel) + { + if (APIClient.User == null) + { + return Array.Empty(); + } + byte[]? file = APIClient.PostRequestWithResult + ("api/reportprovider/studentdisciplinelist", 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; + } + [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] public IActionResult Error() { diff --git a/UniversityProvider/Views/Home/DisciplineStudentList.cshtml b/UniversityProvider/Views/Home/DisciplineStudentList.cshtml new file mode 100644 index 0000000..61a901f --- /dev/null +++ b/UniversityProvider/Views/Home/DisciplineStudentList.cshtml @@ -0,0 +1,44 @@ +@{ + ViewData["Title"] = "Список дисциплин по студентам"; +} + +

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

+ +
+
+

+
+
+ + + + + + + +
+
+ + + + + + + + + + + + +
ИмяФамилияДата рожденияНомер студ. билетаСтатус обучения
+
+
+ + \ No newline at end of file diff --git a/UniversityProvider/Views/Home/GetList.cshtml b/UniversityProvider/Views/Home/GetList.cshtml deleted file mode 100644 index e1dd794..0000000 --- a/UniversityProvider/Views/Home/GetList.cshtml +++ /dev/null @@ -1,5 +0,0 @@ -@* - For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 -*@ -@{ -} diff --git a/UniversityProvider/Views/Home/GetReport.cshtml b/UniversityProvider/Views/Home/GetReport.cshtml index e1dd794..e327f74 100644 --- a/UniversityProvider/Views/Home/GetReport.cshtml +++ b/UniversityProvider/Views/Home/GetReport.cshtml @@ -1,5 +1,30 @@ -@* - For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 -*@ -@{ +@{ + ViewData["Title"] = "Список дисциплин по студентам"; } + +

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

+ +
+
+

+
+
+ +
+
+

Дата начала:

+ +
+
+

Дата конца:

+ +
+ + +
+ + \ No newline at end of file diff --git a/UniversityProvider/Views/Shared/_Layout.cshtml b/UniversityProvider/Views/Shared/_Layout.cshtml index 5445c77..e2c9ea3 100644 --- a/UniversityProvider/Views/Shared/_Layout.cshtml +++ b/UniversityProvider/Views/Shared/_Layout.cshtml @@ -29,7 +29,7 @@ Статусы обучения