diff --git a/CaseAccounting/CaseAccountingBusinessLogics/CaseAccountingBusinessLogic.csproj b/CaseAccounting/CaseAccountingBusinessLogics/CaseAccountingBusinessLogic.csproj index d0f81fd..02c99ca 100644 --- a/CaseAccounting/CaseAccountingBusinessLogics/CaseAccountingBusinessLogic.csproj +++ b/CaseAccounting/CaseAccountingBusinessLogics/CaseAccountingBusinessLogic.csproj @@ -7,6 +7,7 @@ + @@ -18,7 +19,6 @@ - diff --git a/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/AbstractSaveToExcelCustomer.cs b/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/AbstractSaveToExcelCustomer.cs deleted file mode 100644 index ad98b9c..0000000 --- a/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/AbstractSaveToExcelCustomer.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace CaseAccountingBusinessLogic.OfficePackage -{ - public class AbstractSaveToExcelCustomer - { - } -} diff --git a/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/AbstractSaveToExcelProvider.cs b/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/AbstractSaveToExcelProvider.cs deleted file mode 100644 index 681ddf1..0000000 --- a/CaseAccounting/CaseAccountingBusinessLogics/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 CaseAccountingBusinessLogic.OfficePackage -{ - public class AbstractSaveToExcelProvider - { - } -} diff --git a/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/AbstractSaveToPdfCustomer.cs b/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/AbstractSaveToPdfCustomer.cs deleted file mode 100644 index e5619ee..0000000 --- a/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/AbstractSaveToPdfCustomer.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace CaseAccountingBusinessLogic.OfficePackage -{ - public class AbstractSaveToPdfCustomer - { - } -} diff --git a/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/AbstractSaveToPdfProvider.cs b/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/AbstractSaveToPdfProvider.cs deleted file mode 100644 index d8bc181..0000000 --- a/CaseAccounting/CaseAccountingBusinessLogics/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 CaseAccountingBusinessLogic.OfficePackage -{ - public class AbstractSaveToPdfProvider - { - } -} diff --git a/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/AbstractSaveToWordCustomer.cs b/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/AbstractSaveToWordCustomer.cs deleted file mode 100644 index f9bc408..0000000 --- a/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/AbstractSaveToWordCustomer.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace CaseAccountingBusinessLogic.OfficePackage -{ - public class AbstractSaveToWordCustomer - { - } -} diff --git a/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/AbstractSaveToWordProvider.cs b/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/AbstractSaveToWordProvider.cs deleted file mode 100644 index ff4597c..0000000 --- a/CaseAccounting/CaseAccountingBusinessLogics/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 CaseAccountingBusinessLogic.OfficePackage -{ - public class AbstractSaveToWordProvider - { - } -} diff --git a/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/ExcelBuilderProvider.cs b/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/ExcelBuilderProvider.cs new file mode 100644 index 0000000..41b5f48 --- /dev/null +++ b/CaseAccounting/CaseAccountingBusinessLogics/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 CaseAccountingBusinessLogic.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/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/WordBuilderProvider.cs b/CaseAccounting/CaseAccountingBusinessLogics/OfficePackage/WordBuilderProvider.cs new file mode 100644 index 0000000..bc9633c --- /dev/null +++ b/CaseAccounting/CaseAccountingBusinessLogics/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 CaseAccountingBusinessLogic.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 studentCells = new() { student.Student, "" }; + rows.Add(studentCells); + List disciplineCells; + foreach (string discipline in student.Disciplines) + { + disciplineCells = new() { "", discipline }; + rows.Add(disciplineCells); + } + } + WordTableData wordTable = new() + { + Columns = new List<(string, int)>() + { + ("Студент", 3000), + ("Дисциплина", 3000) + }, + Rows = rows + }; + CreateTable(wordTable); + } + } +} diff --git a/CaseAccounting/CaseAccountingProviderView/Views/Home/GetList.cshtml b/CaseAccounting/CaseAccountingProviderView/Views/Home/GetList.cshtml new file mode 100644 index 0000000..8279fe3 --- /dev/null +++ b/CaseAccounting/CaseAccountingProviderView/Views/Home/GetList.cshtml @@ -0,0 +1,45 @@ +@{ + ViewData["Title"] = "Список специализаций по делам"; +} + +

Список специализаций по делам

+ +
+
+

+
+
+ + + + + + + +
+
+ + + + + + + + + + + + +
ИмяФамилияДата рожденияНомер студ. билетаСтатус обучения
+
+
+ + + diff --git a/CaseAccounting/CaseAccountingProviderView/Views/Shared/_Layout.cshtml b/CaseAccounting/CaseAccountingProviderView/Views/Shared/_Layout.cshtml index 4c626ff..eb9d159 100644 --- a/CaseAccounting/CaseAccountingProviderView/Views/Shared/_Layout.cshtml +++ b/CaseAccounting/CaseAccountingProviderView/Views/Shared/_Layout.cshtml @@ -21,6 +21,8 @@ Дела Договора Слушания + Получение список + Получение отчёта diff --git a/CaseAccounting/CaseAccountingProviderView/wwwroot/js/report/reportlist.js b/CaseAccounting/CaseAccountingProviderView/wwwroot/js/report/reportlist.js new file mode 100644 index 0000000..e69de29