diff --git a/University/UniversityBusinessLogic/BusinessLogics/ReportLogic.cs b/University/UniversityBusinessLogic/BusinessLogics/ReportLogic.cs index c0c3f60..a39f007 100644 --- a/University/UniversityBusinessLogic/BusinessLogics/ReportLogic.cs +++ b/University/UniversityBusinessLogic/BusinessLogics/ReportLogic.cs @@ -1,4 +1,5 @@ -using System.Reflection; +using PlumbingRepairBusinessLogic.OfficePackage; +using System.Reflection; using University.ViewModels; using UniversityBusinessLogic.OfficePackage; using UniversityContracts.BindingModels; @@ -25,6 +26,25 @@ public class ReportLogic : IReportLogic private readonly IStudentStorage _studentStorage; private readonly IStatementStorage _statementStorage; private readonly IPlanOfStudyStorage _planOfStudyStorage; + + private readonly AbstractSaveToExcelWorker _saveToExcelWorker; + private readonly AbstractSaveToWordWorker _saveToWordWorker; + private readonly AbstractSaveToPdfWorker _saveToPdfWorker; + public ReportLogic (ITeacherStorage teacherStorage, IDisciplineStorage + disciplineStorage, IStudentStorage studentStorage, IStatementStorage statementStorage, + IPlanOfStudyStorage planOfStudyStorage, AbstractSaveToExcelWorker saveToExcelWorker, AbstractSaveToWordWorker saveToWordWorker, + AbstractSaveToPdfWorker saveToPdfWorker) + { + _teacherStorage = teacherStorage; + _disciplineStorage = disciplineStorage; + _studentStorage = studentStorage; + _statementStorage = statementStorage; + _planOfStudyStorage = planOfStudyStorage; + + _saveToExcelWorker = saveToExcelWorker; + _saveToWordWorker = saveToWordWorker; + _saveToPdfWorker = saveToPdfWorker; + } public List GetTeachers() { var teachers = _teacherStorage.GetFullList(); diff --git a/University/UniversityBusinessLogic/OfficePackage/AbstractSaveToExcelWorker.cs b/University/UniversityBusinessLogic/OfficePackage/AbstractSaveToExcelWorker.cs new file mode 100644 index 0000000..39e4d5b --- /dev/null +++ b/University/UniversityBusinessLogic/OfficePackage/AbstractSaveToExcelWorker.cs @@ -0,0 +1,82 @@ +using PlumbingRepairBusinessLogic.OfficePackage.HelperEnum; +using PlumbingRepairBusinessLogic.OfficePackage.HelperModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PlumbingRepairBusinessLogic.OfficePackage +{ + public abstract class AbstractSaveToExcelWorker + { + public void CreateReport(ExcelInfo info) + { + CreateExcel(info); + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "A", + RowIndex = 1, + Text = info.Title, + StyleInfo = ExcelStyleInfoType.Title + }); + MergeCells(new ExcelMergeParameters + { + CellFromName = "A1", + CellToName = "C1" + }); + uint rowIndex = 2; + foreach (var wk in info.WorkComponents) + { + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "A", + RowIndex = rowIndex, + Text = wk.WorkName, + StyleInfo = ExcelStyleInfoType.Text + }); + rowIndex++; + foreach (var (Component, Count) in wk.Components) + { + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "B", + RowIndex = rowIndex, + Text = Component, + StyleInfo = + ExcelStyleInfoType.TextWithBroder + }); + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "C", + RowIndex = rowIndex, + Text = Count.ToString(), + StyleInfo = + ExcelStyleInfoType.TextWithBroder + }); + rowIndex++; + } + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "A", + RowIndex = rowIndex, + Text = "Итого", + StyleInfo = ExcelStyleInfoType.Text + }); + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "C", + RowIndex = rowIndex, + Text = wk.TotalCount.ToString(), + StyleInfo = ExcelStyleInfoType.Text + }); + rowIndex++; + } + SaveExcel(info); + } + protected abstract void CreateExcel(ExcelInfo info); + protected abstract void InsertCellInWorksheet(ExcelCellParameters excelParams); + protected abstract void MergeCells(ExcelMergeParameters excelParams); + protected abstract void SaveExcel(ExcelInfo info); + } +} diff --git a/University/UniversityBusinessLogic/OfficePackage/AbstractSaveToPdfWorker.cs b/University/UniversityBusinessLogic/OfficePackage/AbstractSaveToPdfWorker.cs new file mode 100644 index 0000000..327fd52 --- /dev/null +++ b/University/UniversityBusinessLogic/OfficePackage/AbstractSaveToPdfWorker.cs @@ -0,0 +1,69 @@ +using PlumbingRepairBusinessLogic.OfficePackage.HelperEnum; +using PlumbingRepairBusinessLogic.OfficePackage.HelperModels; + +namespace PlumbingRepairBusinessLogic.OfficePackage +{ + public abstract class AbstractSaveToPdfWorker + { + public void CreateDoc(PdfInfo info) + { + CreatePdf(info); + CreateParagraph(new PdfParagraph { Text = info.Title, Style = "NormalTitle", ParagraphAlignment = PdfParagraphAlignmentType.Center }); + CreateParagraph(new PdfParagraph { Text = $"с {info.DateFrom.ToShortDateString()} по {info.DateTo.ToShortDateString()}", Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Center }); + + CreateTable(new List { "2cm", "3cm", "6cm", "3cm", "4 cm" }); + + CreateRow(new PdfRowParameters + { + Texts = new List { "Номер", "Дата заказа", "Работа", "Статус", "Сумма" }, + Style = "NormalTitle", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + + foreach (var order in info.Orders) + { + CreateRow(new PdfRowParameters + { + Texts = new List { order.Id.ToString(), order.DateCreate.ToShortDateString(), order.WorkName, order.OrderStatus.ToString(), order.Sum.ToString() }, + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Left + }); + } + CreateParagraph(new PdfParagraph { Text = $"Итого: {info.Orders.Sum(x => x.Sum)}\t", Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Right }); + + SavePdf(info); + } + + /// + /// Создание doc-файла + /// + /// + protected abstract void CreatePdf(PdfInfo info); + + /// + /// Создание параграфа с текстом + /// + /// + /// + protected abstract void CreateParagraph(PdfParagraph paragraph); + + /// + /// Создание таблицы + /// + /// + /// + protected abstract void CreateTable(List columns); + + /// + /// Создание и заполнение строки + /// + /// + protected abstract void CreateRow(PdfRowParameters rowParameters); + + /// + /// Сохранение файла + /// + /// + protected abstract void SavePdf(PdfInfo info); + } +} diff --git a/University/UniversityBusinessLogic/OfficePackage/AbstractSaveToWordWorker.cs b/University/UniversityBusinessLogic/OfficePackage/AbstractSaveToWordWorker.cs new file mode 100644 index 0000000..fded6f4 --- /dev/null +++ b/University/UniversityBusinessLogic/OfficePackage/AbstractSaveToWordWorker.cs @@ -0,0 +1,47 @@ +using UniversityBusinessLogic.OfficePackage.HelperEnums; +using UniversityBusinessLogic.OfficePackage.HelperModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace UniversityBusinessLogic.OfficePackage +{ + public abstract class AbstractSaveToWordWorker + { + public void CreateDoc(WordInfoWorker info) + { + CreateWord(info); + CreateParagraph(new WordParagraph + { + Texts = new List<(string, WordTextProperties)> { (info.Title, new +WordTextProperties { Bold = true, Size = "24", }) }, + TextProperties = new WordTextProperties + { + Size = "24", + JustificationType = WordJustificationType.Center + } + }); + foreach (var planOfStudys in info.PlanOfStudys) + { + CreateParagraph(new WordParagraph + { + Texts = new List<(string, WordTextProperties)> { +(work.WorkName + " - ", new WordTextProperties { Size = "24", Bold = true, }), + (work.Price.ToString(), new WordTextProperties { Size = "24", }) }, + TextProperties = new WordTextProperties + { + Size = "24", + JustificationType = WordJustificationType.Both + } + }); + } + SaveWord(info); + } + protected abstract void CreateWord(WordInfoWorker info); + protected abstract void CreateParagraph(WordParagraph paragraph); + protected abstract void SaveWord(WordInfoWorker info); + + } +} diff --git a/University/UniversityBusinessLogic/OfficePackage/HelperModels/WordInfo.cs b/University/UniversityBusinessLogic/OfficePackage/HelperModels/WordInfoWorker.cs similarity index 92% rename from University/UniversityBusinessLogic/OfficePackage/HelperModels/WordInfo.cs rename to University/UniversityBusinessLogic/OfficePackage/HelperModels/WordInfoWorker.cs index 07e7573..8e1e9a3 100644 --- a/University/UniversityBusinessLogic/OfficePackage/HelperModels/WordInfo.cs +++ b/University/UniversityBusinessLogic/OfficePackage/HelperModels/WordInfoWorker.cs @@ -4,7 +4,7 @@ using UniversityContracts.ViewModels; namespace UniversityBusinessLogic.OfficePackage.HelperModels { - public class WordInfo + public class WordInfoWorker { public string? FileName { get; set; } public Stream? Stream { get; set; }