diff --git a/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/BusinessLogic/ReportLogic.cs b/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/BusinessLogic/ReportLogic.cs new file mode 100644 index 0000000..3604adb --- /dev/null +++ b/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/BusinessLogic/ReportLogic.cs @@ -0,0 +1,298 @@ +using SchoolAgainStudyBusinessLogic.OfficePackage; +using SchoolAgainStudyBusinessLogic.OfficePackage.HelperModels; +using SchoolAgainStudyContracts.BindingModel; +using SchoolAgainStudyContracts.BusinessLogicContracts; +using SchoolAgainStudyContracts.SearchModel; +using SchoolAgainStudyContracts.StorageContracts; +using SchoolAgainStudyContracts.ViewModel; +using SchoolAgainStudyDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SchoolAgainStudyBusinessLogic.BusinessLogic +{ + public class ReportLogic : IReportLogic + { + private readonly IInterestStorage _interestStorage; + private readonly IMaterialStorage _materialStorage; + private readonly IProductStorage _productStorage; + private readonly IDiyStorage _diyStorage; + private readonly ITaskStorage _taskStorage; + private readonly ILessonStorage _lessonStorage; + + private readonly AbstractSaveToExcelTeacher _saveToExcelTeacher; + + private readonly AbstractSaveToWordTeacher _saveToWordTeacher; + + private readonly AbstractSaveToPdfTeacher _saveToPdfTeacher; + + private readonly AbstractSaveToExcelStudent _saveToExcelStudent; + + private readonly AbstractSaveToWordStudent _saveToWordStudent; + + private readonly AbstractSaveToPdfStudent _saveToPdfStudent; + + public ReportLogic(IInterestStorage interestStorage, IMaterialStorage materialStorage, IProductStorage productStorage, IDiyStorage diyStorage, ITaskStorage taskStorage, ILessonStorage lessonStorage, AbstractSaveToExcelTeacher saveToExcelTeacher, AbstractSaveToWordTeacher saveToWordTeacher, AbstractSaveToPdfTeacher saveToPdfTeacher, AbstractSaveToExcelStudent saveToExcelStudent, AbstractSaveToWordStudent saveToWordStudent, AbstractSaveToPdfStudent saveToPdfStudent) + { + _interestStorage = interestStorage; + _materialStorage = materialStorage; + _productStorage = productStorage; + _diyStorage = diyStorage; + _taskStorage = taskStorage; + _lessonStorage = lessonStorage; + _saveToExcelTeacher = saveToExcelTeacher; + _saveToWordTeacher = saveToWordTeacher; + _saveToPdfTeacher = saveToPdfTeacher; + _saveToExcelStudent = saveToExcelStudent; + _saveToWordStudent = saveToWordStudent; + _saveToPdfStudent = saveToPdfStudent; + } + + + + + + public List GetDiyMaterial(ReportBindingModel model) + { + + var tasks = _taskStorage.GetFilteredList(new TaskSearchModel{ + TeacherId=model.TeacherId + }); + var diys = _diyStorage.GetFullList(); + var list = new List(); + + foreach (MaterialViewModel material in model.Materials) + { + var record = new ReportDiyMaterialViewModel + { + Title = material.Title + }; + foreach(TaskViewModel task in tasks) + { + if (task.TaskMaterials.ContainsKey(material.Id)) + { + foreach(DiyViewModel diy in diys) + { + if (diy.TaskId == task.Id) + record.Diys.Add(diy.Title); + } + } + } + list.Add(record); + } + return list; + } + + public List GetInterestLesson(ReportBindingModel model) + { + var products = _productStorage.GetFilteredList(new ProductSearchModel + { + StudentId = model.StudentId + }); + var lessons = _lessonStorage.GetFullList(); + var list = new List(); + foreach(InterestViewModel interest in model.Interests) + { + var record = new ReportInterestLessonViewModel + { + Title = interest.Title + }; + foreach(ProductViewModel product in products) + { + if (product.ProductInterests.ContainsKey(interest.Id)) + { + foreach(LessonViewModel lesson in lessons) + { + if(lesson.ProductId == product.Id) + { + record.Lessons.Add(lesson.Title); + } + } + } + } + list.Add(record); + } + return list; + } + + public List GetInterests(ReportBindingModel model) + { + var interests = _interestStorage.GetFilteredList(new InterestSearchModel + { + StudentId = model.StudentId + }); + var products = _productStorage.GetFilteredList(new ProductSearchModel + { + StudentId = model.StudentId, + DateFrom = model.DateFrom, + DateTo = model.DateTo + }); + var diys = _diyStorage.GetFilteredList(new DiySearchModel + { + StudentId = model.StudentId, + DateFrom = model.DateFrom, + DateTo = model.DateTo + }); + var list = new List(); + foreach(InterestViewModel interest in interests) + { + foreach(ProductViewModel product in products) + { + if (product.ProductInterests.ContainsKey(interest.Id)) + { + list.Add(new ReportInterestViewModel + { + InterestTitle=interest.Title, + InterestDesc = interest.Description, + WorkType = "Изделие", + WorkTitle = product.Title, + WorkDesc = product.Description, + DateCreate = product.DateCreate + }); + } + } + } + foreach (InterestViewModel interest in interests) + { + foreach (DiyViewModel diy in diys) + { + if (diy.DiyInterests.ContainsKey(interest.Id)) + { + list.Add(new ReportInterestViewModel + { + InterestTitle = interest.Title, + InterestDesc = interest.Description, + WorkType = "Поделка", + WorkTitle = diy.Title, + WorkDesc = diy.Description, + DateCreate=diy.DateCreate + }); + } + } + } + return list; + } + + public List GetLessonTask(ReportBindingModel model) + { + var materials = _materialStorage.GetFilteredList(new MaterialSearchModel + { + TeacherId = model.TeacherId + }); + var tasks = _taskStorage.GetFilteredList(new TaskSearchModel + { + TeacherId = model.TeacherId, + DateFrom = model.DateFrom, + DateTo = model.DateTo + }); + var lessons = _lessonStorage.GetFilteredList(new LessonSearchModel + { + TeacherId = model.TeacherId, + DateFrom = model.DateFrom, + DateTo = model.DateTo + }); + var list = new List(); + + foreach (TaskViewModel task in tasks) + { + + foreach(LessonViewModel lesson in lessons) + { + bool check = false; + foreach (int materialTask in task.TaskMaterials.Keys) + { + if (check) + { + break; + } + foreach (int materialLesson in lesson.LessonMaterials.Keys) + { + if (materialLesson == materialTask) + { + list.Add(new ReportLessonTaskViewModel + { + TitleLesson = lesson.Title, + TitleTask = task.Title, + DateEventLesson = lesson.DateEvent, + DateIssueTask = task.DateIssue + }); + check=true; + break; + } + } + } + } + + + } + return list; + } + + public void SaveDiyMaterialToExcelFile(ReportBindingModel model) + { + _saveToExcelTeacher.CreateReport(new ExcelInfoTeacher + { + FileName = model.FileName, + Title = "Список поделок по материалам", + DiyMaterials = GetDiyMaterial(model) + }); + } + + public void SaveDiyMaterialToWordFile(ReportBindingModel model) + { + _saveToWordTeacher.CreateDoc(new WordInfoTeacher + { + FileName = model.FileName, + Title = "Список поделок по материалам", + DiyMaterials = GetDiyMaterial(model) + }); + } + + public void SaveInterestLessonToExcelFile(ReportBindingModel model) + { + _saveToExcelStudent.CreateReport(new ExcelInfoStudent + { + FileName = model.FileName, + Title = "Список занятий по интресам", + InterestLessons = GetInterestLesson(model) + }); + } + + public void SaveInterestLessonToWordFile(ReportBindingModel model) + { + _saveToWordStudent.CreateDoc(new WordInfoStudent + { + FileName = model.FileName, + Title = "Список занятий по интресам", + InterestLessons = GetInterestLesson(model) + }); + } + + public void SaveInterestsToPdfFile(ReportBindingModel model) + { + _saveToPdfStudent.CreateDoc(new PdfInfoStudent + { + FileName = model.FileName, + Title = "Список интересов", + DateFrom = DateTime.SpecifyKind(model.DateFrom!.Value, DateTimeKind.Utc), + DateTo = DateTime.SpecifyKind(model.DateTo!.Value, DateTimeKind.Utc), + Interests = GetInterests(model) + }); + } + + public void SaveLessonTaskToPdfFile(ReportBindingModel model) + { + _saveToPdfTeacher.CreateDoc(new PdfInfoTeacher + { + FileName = model.FileName, + Title = "Список заданий и занятий со сохожими материалами", + DateFrom = DateTime.SpecifyKind(model.DateFrom!.Value, DateTimeKind.Utc), + DateTo = DateTime.SpecifyKind(model.DateTo!.Value, DateTimeKind.Utc), + LessonTasks = GetLessonTask(model) + }); + } + } +} diff --git a/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/OfficePackage/AbstractSaveToExcelStudent.cs b/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/OfficePackage/AbstractSaveToExcelStudent.cs new file mode 100644 index 0000000..3e511f7 --- /dev/null +++ b/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/OfficePackage/AbstractSaveToExcelStudent.cs @@ -0,0 +1,93 @@ +using SchoolAgainStudyBusinessLogic.OfficePackage.HelperEnums; +using SchoolAgainStudyBusinessLogic.OfficePackage.HelperModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SchoolAgainStudyBusinessLogic.OfficePackage +{ + public abstract class AbstractSaveToExcelStudent + { + /// + /// Создание отчета + /// + /// + public void CreateReport(ExcelInfoStudent 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 pc in info.InterestLessons) + { + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "A", + RowIndex = rowIndex, + Text = pc.Title, + StyleInfo = ExcelStyleInfoType.Text + }); + rowIndex++; + + foreach (var lesson in pc.Lessons) + { + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "B", + RowIndex = rowIndex, + Text = lesson, + StyleInfo = ExcelStyleInfoType.TextWithBroder + }); + + + + rowIndex++; + } + + + rowIndex++; + } + + SaveExcel(info); + } + + /// + /// Создание excel-файла + /// + /// + protected abstract void CreateExcel(ExcelInfoStudent info); + + /// + /// Добавляем новую ячейку в лист + /// + /// + protected abstract void InsertCellInWorksheet(ExcelCellParameters excelParams); + + /// + /// Объединение ячеек + /// + /// + protected abstract void MergeCells(ExcelMergeParameters excelParams); + + /// + /// Сохранение файла + /// + /// + protected abstract void SaveExcel(ExcelInfoStudent info); + } +} diff --git a/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/OfficePackage/AbstractSaveToExcelTeacher.cs b/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/OfficePackage/AbstractSaveToExcelTeacher.cs new file mode 100644 index 0000000..f5a6924 --- /dev/null +++ b/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/OfficePackage/AbstractSaveToExcelTeacher.cs @@ -0,0 +1,93 @@ +using SchoolAgainStudyBusinessLogic.OfficePackage.HelperEnums; +using SchoolAgainStudyBusinessLogic.OfficePackage.HelperModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SchoolAgainStudyBusinessLogic.OfficePackage +{ + public abstract class AbstractSaveToExcelTeacher + { + /// + /// Создание отчета + /// + /// + public void CreateReport(ExcelInfoTeacher 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 pc in info.DiyMaterials) + { + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "A", + RowIndex = rowIndex, + Text = pc.Title, + StyleInfo = ExcelStyleInfoType.Text + }); + rowIndex++; + + foreach (var diy in pc.Diys) + { + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "B", + RowIndex = rowIndex, + Text = diy, + StyleInfo = ExcelStyleInfoType.TextWithBroder + }); + + + + rowIndex++; + } + + + rowIndex++; + } + + SaveExcel(info); + } + + /// + /// Создание excel-файла + /// + /// + protected abstract void CreateExcel(ExcelInfoTeacher info); + + /// + /// Добавляем новую ячейку в лист + /// + /// + protected abstract void InsertCellInWorksheet(ExcelCellParameters excelParams); + + /// + /// Объединение ячеек + /// + /// + protected abstract void MergeCells(ExcelMergeParameters excelParams); + + /// + /// Сохранение файла + /// + /// + protected abstract void SaveExcel(ExcelInfoTeacher info); + } +} diff --git a/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/OfficePackage/AbstractSaveToPdfStudent.cs b/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/OfficePackage/AbstractSaveToPdfStudent.cs new file mode 100644 index 0000000..d2050e1 --- /dev/null +++ b/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/OfficePackage/AbstractSaveToPdfStudent.cs @@ -0,0 +1,74 @@ +using SchoolAgainStudyBusinessLogic.OfficePackage.HelperEnums; +using SchoolAgainStudyBusinessLogic.OfficePackage.HelperModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SchoolAgainStudyBusinessLogic.OfficePackage +{ + public abstract class AbstractSaveToPdfStudent + { + public void CreateDoc(PdfInfoStudent 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", "3cm", "6cm", "6cm" }); + + CreateRow(new PdfRowParameters + { + Texts = new List { "Номер","Интерес", "Описание интереса", "Тип","Название", "Описание", "Дата" }, + Style = "NormalTitle", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + + foreach (var interest in info.Interests) + { + CreateRow(new PdfRowParameters + { + Texts = new List { interest.Id.ToString(),interest.InterestTitle,interest.InterestDesc,interest.WorkType,interest.WorkTitle,interest.WorkDesc, interest.DateCreate.ToShortDateString() }, + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Left + }); + } + + + SavePdf(info); + } + + /// + /// Создание doc-файла + /// + /// + protected abstract void CreatePdf(PdfInfoStudent info); + + /// + /// Создание параграфа с текстом + /// + /// + /// + protected abstract void CreateParagraph(PdfParagraph paragraph); + + /// + /// Создание таблицы + /// + /// + /// + protected abstract void CreateTable(List columns); + + /// + /// Создание и заполнение строки + /// + /// + protected abstract void CreateRow(PdfRowParameters rowParameters); + + /// + /// Сохранение файла + /// + /// + protected abstract void SavePdf(PdfInfoStudent info); + } +} diff --git a/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/OfficePackage/AbstractSaveToPdfTeacher.cs b/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/OfficePackage/AbstractSaveToPdfTeacher.cs new file mode 100644 index 0000000..bfefc47 --- /dev/null +++ b/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/OfficePackage/AbstractSaveToPdfTeacher.cs @@ -0,0 +1,74 @@ +using SchoolAgainStudyBusinessLogic.OfficePackage.HelperEnums; +using SchoolAgainStudyBusinessLogic.OfficePackage.HelperModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SchoolAgainStudyBusinessLogic.OfficePackage +{ + public abstract class AbstractSaveToPdfTeacher + { + public void CreateDoc(PdfInfoTeacher 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", "4cm", "6cm", "4cm", "6cm" }); + + CreateRow(new PdfRowParameters + { + Texts = new List { "Номер","Занятие", "Дата занятия", "Задание", "Дата выдачи задания" }, + Style = "NormalTitle", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + + foreach (var taskLesson in info.LessonTasks) + { + CreateRow(new PdfRowParameters + { + Texts = new List { taskLesson.Id.ToString(), taskLesson.TitleLesson, taskLesson.DateEventLesson.ToShortDateString(), taskLesson.TitleTask, taskLesson.DateIssueTask.ToShortDateString()}, + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Left + }); + } + + + SavePdf(info); + } + + /// + /// Создание doc-файла + /// + /// + protected abstract void CreatePdf(PdfInfoTeacher info); + + /// + /// Создание параграфа с текстом + /// + /// + /// + protected abstract void CreateParagraph(PdfParagraph paragraph); + + /// + /// Создание таблицы + /// + /// + /// + protected abstract void CreateTable(List columns); + + /// + /// Создание и заполнение строки + /// + /// + protected abstract void CreateRow(PdfRowParameters rowParameters); + + /// + /// Сохранение файла + /// + /// + protected abstract void SavePdf(PdfInfoTeacher info); + } +} diff --git a/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/OfficePackage/AbstractSaveToWordStudent.cs b/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/OfficePackage/AbstractSaveToWordStudent.cs new file mode 100644 index 0000000..7fef4bc --- /dev/null +++ b/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/OfficePackage/AbstractSaveToWordStudent.cs @@ -0,0 +1,76 @@ +using SchoolAgainStudyBusinessLogic.OfficePackage.HelperEnums; +using SchoolAgainStudyBusinessLogic.OfficePackage.HelperModels; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SchoolAgainStudyBusinessLogic.OfficePackage +{ + public abstract class AbstractSaveToWordStudent + { + public void CreateDoc(WordInfoStudent 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 interest in info.InterestLessons) + { + CreateParagraph(new WordParagraph + { + Texts = new List<(string, WordTextProperties)> { (interest.Title, new WordTextProperties { Size = "24", Bold=true,})}, + TextProperties = new WordTextProperties + { + Size = "24", + JustificationType = WordJustificationType.Both + } + }); + foreach (var lesson in interest.Lessons) + { + CreateParagraph(new WordParagraph + { + Texts = new List<(string, WordTextProperties)> { (lesson, new WordTextProperties { Size = "20", Bold=false,})}, + TextProperties = new WordTextProperties + { + Size = "24", + JustificationType = WordJustificationType.Both + } + }); + } + + } + + SaveWord(info); + } + + /// + /// Создание doc-файла + /// + /// + protected abstract void CreateWord(WordInfoStudent info); + + /// + /// Создание абзаца с текстом + /// + /// + /// + protected abstract void CreateParagraph(WordParagraph paragraph); + + /// + /// Сохранение файла + /// + /// + protected abstract void SaveWord(WordInfoStudent info); + } +} diff --git a/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/OfficePackage/AbstractSaveToWordTeacher.cs b/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/OfficePackage/AbstractSaveToWordTeacher.cs new file mode 100644 index 0000000..7b0cf57 --- /dev/null +++ b/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/OfficePackage/AbstractSaveToWordTeacher.cs @@ -0,0 +1,76 @@ +using SchoolAgainStudyBusinessLogic.OfficePackage.HelperEnums; +using SchoolAgainStudyBusinessLogic.OfficePackage.HelperModels; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SchoolAgainStudyBusinessLogic.OfficePackage +{ + public abstract class AbstractSaveToWordTeacher + { + public void CreateDoc(WordInfoTeacher 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 material in info.DiyMaterials) + { + CreateParagraph(new WordParagraph + { + Texts = new List<(string, WordTextProperties)> { (material.Title, new WordTextProperties { Size = "24", Bold=true,})}, + TextProperties = new WordTextProperties + { + Size = "24", + JustificationType = WordJustificationType.Both + } + }); + foreach (var diy in material.Diys) + { + CreateParagraph(new WordParagraph + { + Texts = new List<(string, WordTextProperties)> { (diy, new WordTextProperties { Size = "20", Bold=false,})}, + TextProperties = new WordTextProperties + { + Size = "24", + JustificationType = WordJustificationType.Both + } + }); + } + + } + + SaveWord(info); + } + + /// + /// Создание doc-файла + /// + /// + protected abstract void CreateWord(WordInfoTeacher info); + + /// + /// Создание абзаца с текстом + /// + /// + /// + protected abstract void CreateParagraph(WordParagraph paragraph); + + /// + /// Сохранение файла + /// + /// + protected abstract void SaveWord(WordInfoTeacher info); + } +} diff --git a/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/OfficePackage/HelperEnums/ExcelStyleInfoType.cs b/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/OfficePackage/HelperEnums/ExcelStyleInfoType.cs new file mode 100644 index 0000000..213d87e --- /dev/null +++ b/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/OfficePackage/HelperEnums/ExcelStyleInfoType.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SchoolAgainStudyBusinessLogic.OfficePackage.HelperEnums +{ + public enum ExcelStyleInfoType + { + Title, + + Text, + + TextWithBroder + } +} diff --git a/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/OfficePackage/HelperEnums/PdfParagraphAlignmentType.cs b/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/OfficePackage/HelperEnums/PdfParagraphAlignmentType.cs new file mode 100644 index 0000000..ca90df5 --- /dev/null +++ b/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/OfficePackage/HelperEnums/PdfParagraphAlignmentType.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SchoolAgainStudyBusinessLogic.OfficePackage.HelperEnums +{ + public enum PdfParagraphAlignmentType + { + Center, + + Left, + + Rigth + } +} diff --git a/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/OfficePackage/HelperEnums/WordJustificationType.cs b/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/OfficePackage/HelperEnums/WordJustificationType.cs new file mode 100644 index 0000000..171b5f4 --- /dev/null +++ b/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/OfficePackage/HelperEnums/WordJustificationType.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SchoolAgainStudyBusinessLogic.OfficePackage.HelperEnums +{ + public enum WordJustificationType + { + Center, + + Both + } +} diff --git a/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/OfficePackage/HelperModels/ExcelCellParameters.cs b/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/OfficePackage/HelperModels/ExcelCellParameters.cs new file mode 100644 index 0000000..361cdf3 --- /dev/null +++ b/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/OfficePackage/HelperModels/ExcelCellParameters.cs @@ -0,0 +1,17 @@ +using SchoolAgainStudyBusinessLogic.OfficePackage.HelperEnums; + +namespace SchoolAgainStudyBusinessLogic.OfficePackage.HelperModels +{ + public class ExcelCellParameters + { + 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 ExcelStyleInfoType StyleInfo { get; set; } + } +} \ No newline at end of file diff --git a/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/OfficePackage/HelperModels/ExcelInfoStudent.cs b/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/OfficePackage/HelperModels/ExcelInfoStudent.cs new file mode 100644 index 0000000..359e67e --- /dev/null +++ b/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/OfficePackage/HelperModels/ExcelInfoStudent.cs @@ -0,0 +1,13 @@ +using SchoolAgainStudyContracts.ViewModel; + +namespace SchoolAgainStudyBusinessLogic.OfficePackage.HelperModels +{ + public class ExcelInfoStudent + { + public string FileName { get; set; } = string.Empty; + + public string Title { get; set; } = string.Empty; + + public List InterestLessons { get; set; } = new(); + } +} \ No newline at end of file diff --git a/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/OfficePackage/HelperModels/ExcelInfoTeacher.cs b/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/OfficePackage/HelperModels/ExcelInfoTeacher.cs new file mode 100644 index 0000000..544d5ed --- /dev/null +++ b/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/OfficePackage/HelperModels/ExcelInfoTeacher.cs @@ -0,0 +1,13 @@ +using SchoolAgainStudyContracts.ViewModel; + +namespace SchoolAgainStudyBusinessLogic.OfficePackage.HelperModels +{ + public class ExcelInfoTeacher + { + public string FileName { get; set; } = string.Empty; + + public string Title { get; set; } = string.Empty; + + public List DiyMaterials { get; set; } = new(); + } +} \ No newline at end of file diff --git a/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/OfficePackage/HelperModels/ExcelMergeParameters.cs b/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/OfficePackage/HelperModels/ExcelMergeParameters.cs new file mode 100644 index 0000000..2ae63ee --- /dev/null +++ b/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/OfficePackage/HelperModels/ExcelMergeParameters.cs @@ -0,0 +1,11 @@ +namespace SchoolAgainStudyBusinessLogic.OfficePackage.HelperModels +{ + public class ExcelMergeParameters + { + public string CellFromName { get; set; } = string.Empty; + + public string CellToName { get; set; } = string.Empty; + + public string Merge => $"{CellFromName}:{CellToName}"; + } +} \ No newline at end of file diff --git a/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/OfficePackage/HelperModels/PdfInfoStudent.cs b/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/OfficePackage/HelperModels/PdfInfoStudent.cs new file mode 100644 index 0000000..c955799 --- /dev/null +++ b/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/OfficePackage/HelperModels/PdfInfoStudent.cs @@ -0,0 +1,17 @@ +using SchoolAgainStudyContracts.ViewModel; + +namespace SchoolAgainStudyBusinessLogic.OfficePackage.HelperModels +{ + public class PdfInfoStudent + { + public string FileName { get; set; } = string.Empty; + + public string Title { get; set; } = string.Empty; + + public DateTime DateFrom { get; set; } + + public DateTime DateTo { get; set; } + + public List Interests { get; set; } = new(); + } +} \ No newline at end of file diff --git a/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/OfficePackage/HelperModels/PdfInfoTeacher.cs b/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/OfficePackage/HelperModels/PdfInfoTeacher.cs new file mode 100644 index 0000000..1e5207b --- /dev/null +++ b/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/OfficePackage/HelperModels/PdfInfoTeacher.cs @@ -0,0 +1,17 @@ +using SchoolAgainStudyContracts.ViewModel; + +namespace SchoolAgainStudyBusinessLogic.OfficePackage.HelperModels +{ + public class PdfInfoTeacher + { + public string FileName { get; set; } = string.Empty; + + public string Title { get; set; } = string.Empty; + + public DateTime DateFrom { get; set; } + + public DateTime DateTo { get; set; } + + public List LessonTasks { get; set; } = new(); + } +} \ No newline at end of file diff --git a/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/OfficePackage/HelperModels/PdfParagraph.cs b/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/OfficePackage/HelperModels/PdfParagraph.cs new file mode 100644 index 0000000..33dffd8 --- /dev/null +++ b/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/OfficePackage/HelperModels/PdfParagraph.cs @@ -0,0 +1,13 @@ +using SchoolAgainStudyBusinessLogic.OfficePackage.HelperEnums; + +namespace SchoolAgainStudyBusinessLogic.OfficePackage.HelperModels +{ + public class PdfParagraph + { + public string Text { get; set; } = string.Empty; + + public string Style { get; set; } = string.Empty; + + public PdfParagraphAlignmentType ParagraphAlignment { get; set; } + } +} \ No newline at end of file diff --git a/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/OfficePackage/HelperModels/PdfRowParameters.cs b/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/OfficePackage/HelperModels/PdfRowParameters.cs new file mode 100644 index 0000000..fa5d480 --- /dev/null +++ b/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/OfficePackage/HelperModels/PdfRowParameters.cs @@ -0,0 +1,13 @@ +using SchoolAgainStudyBusinessLogic.OfficePackage.HelperEnums; + +namespace SchoolAgainStudyBusinessLogic.OfficePackage.HelperModels +{ + public class PdfRowParameters + { + public List Texts { get; set; } = new(); + + public string Style { get; set; } = string.Empty; + + public PdfParagraphAlignmentType ParagraphAlignment { get; set; } + } +} \ No newline at end of file diff --git a/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/OfficePackage/HelperModels/WordInfoStudent.cs b/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/OfficePackage/HelperModels/WordInfoStudent.cs new file mode 100644 index 0000000..d770637 --- /dev/null +++ b/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/OfficePackage/HelperModels/WordInfoStudent.cs @@ -0,0 +1,13 @@ +using SchoolAgainStudyContracts.ViewModel; + +namespace SchoolAgainStudyBusinessLogic.OfficePackage.HelperModels +{ + public class WordInfoStudent + { + public string FileName { get; set; } = string.Empty; + + public string Title { get; set; } = string.Empty; + + public List InterestLessons { get; set; } = new(); + } +} \ No newline at end of file diff --git a/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/OfficePackage/HelperModels/WordInfoTeacher.cs b/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/OfficePackage/HelperModels/WordInfoTeacher.cs new file mode 100644 index 0000000..d860e4d --- /dev/null +++ b/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/OfficePackage/HelperModels/WordInfoTeacher.cs @@ -0,0 +1,13 @@ +using SchoolAgainStudyContracts.ViewModel; + +namespace SchoolAgainStudyBusinessLogic.OfficePackage.HelperModels +{ + public class WordInfoTeacher + { + public string FileName { get; set; } = string.Empty; + + public string Title { get; set; } = string.Empty; + + public List DiyMaterials { get; set; } = new(); + } +} \ No newline at end of file diff --git a/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/OfficePackage/HelperModels/WordParagraph.cs b/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/OfficePackage/HelperModels/WordParagraph.cs new file mode 100644 index 0000000..501fa5e --- /dev/null +++ b/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/OfficePackage/HelperModels/WordParagraph.cs @@ -0,0 +1,9 @@ +namespace SchoolAgainStudyBusinessLogic.OfficePackage.HelperModels +{ + public class WordParagraph + { + public List<(string, WordTextProperties)> Texts { get; set; } = new(); + + public WordTextProperties? TextProperties { get; set; } + } +} \ No newline at end of file diff --git a/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/OfficePackage/HelperModels/WordTextProperties.cs b/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/OfficePackage/HelperModels/WordTextProperties.cs new file mode 100644 index 0000000..6ffe694 --- /dev/null +++ b/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/OfficePackage/HelperModels/WordTextProperties.cs @@ -0,0 +1,13 @@ +using SchoolAgainStudyBusinessLogic.OfficePackage.HelperEnums; + +namespace SchoolAgainStudyBusinessLogic.OfficePackage.HelperModels +{ + public class WordTextProperties + { + public string Size { get; set; } = string.Empty; + + public bool Bold { get; set; } + + public WordJustificationType JustificationType { get; set; } + } +} diff --git a/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/OfficePackage/Implements/SaveToExcelStudent.cs b/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/OfficePackage/Implements/SaveToExcelStudent.cs new file mode 100644 index 0000000..568a975 --- /dev/null +++ b/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/OfficePackage/Implements/SaveToExcelStudent.cs @@ -0,0 +1,291 @@ +using SchoolAgainStudyBusinessLogic.OfficePackage.HelperEnums; +using SchoolAgainStudyBusinessLogic.OfficePackage.HelperModels; +using DocumentFormat.OpenXml; +using DocumentFormat.OpenXml.Office2010.Excel; +using DocumentFormat.OpenXml.Office2013.Excel; +using DocumentFormat.OpenXml.Packaging; +using DocumentFormat.OpenXml.Spreadsheet; + +namespace SchoolAgainStudyBusinessLogic.OfficePackage.Implements +{ + public class SaveToExcelStudent : AbstractSaveToExcelStudent + { + private SpreadsheetDocument? _spreadsheetDocument; + + private SharedStringTablePart? _shareStringPart; + + private Worksheet? _worksheet; + + /// + /// Настройка стилей для файла + /// + /// + private static 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 }); + fontUsual.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Theme = 1U }); + fontUsual.Append(new FontName() { Val = "Times New Roman" }); + fontUsual.Append(new FontFamilyNumbering() { Val = 2 }); + fontUsual.Append(new FontScheme() { Val = FontSchemeValues.Minor }); + + var fontTitle = new Font(); + fontTitle.Append(new Bold()); + fontTitle.Append(new FontSize() { Val = 14D }); + fontTitle.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Theme = 1U }); + fontTitle.Append(new FontName() { Val = "Times New Roman" }); + fontTitle.Append(new FontFamilyNumbering() { Val = 2 }); + fontTitle.Append(new FontScheme() { Val = FontSchemeValues.Minor }); + + fonts.Append(fontUsual); + fonts.Append(fontTitle); + + var fills = new Fills() { Count = 2U }; + + var fill1 = new Fill(); + fill1.Append(new PatternFill() { PatternType = PatternValues.None }); + + var fill2 = new Fill(); + fill2.Append(new PatternFill() { PatternType = PatternValues.Gray125 }); + + fills.Append(fill1); + fills.Append(fill2); + + 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); + + var cellStyleFormats = new CellStyleFormats() { Count = 1U }; + var cellFormatStyle = new CellFormat() { NumberFormatId = 0U, FontId = 0U, FillId = 0U, BorderId = 0U }; + + cellStyleFormats.Append(cellFormatStyle); + + var cellFormats = new CellFormats() { Count = 3U }; + var cellFormatFont = new CellFormat() { NumberFormatId = 0U, FontId = 0U, FillId = 0U, BorderId = 0U, FormatId = 0U, ApplyFont = true }; + var cellFormatFontAndBorder = new CellFormat() { NumberFormatId = 0U, FontId = 0U, FillId = 0U, BorderId = 1U, FormatId = 0U, ApplyFont = true, ApplyBorder = true }; + var cellFormatTitle = new CellFormat() { NumberFormatId = 0U, FontId = 1U, FillId = 0U, BorderId = 0U, FormatId = 0U, Alignment = new Alignment() { Vertical = VerticalAlignmentValues.Center, WrapText = true, Horizontal = HorizontalAlignmentValues.Center }, ApplyFont = true }; + + cellFormats.Append(cellFormatFont); + cellFormats.Append(cellFormatFontAndBorder); + cellFormats.Append(cellFormatTitle); + + var cellStyles = new CellStyles() { Count = 1U }; + + cellStyles.Append(new CellStyle() { Name = "Normal", FormatId = 0U, BuiltinId = 0U }); + + var differentialFormats = new DocumentFormat.OpenXml.Office2013.Excel.DifferentialFormats() { Count = 0U }; + + var tableStyles = new TableStyles() { Count = 0U, DefaultTableStyle = "TableStyleMedium2", DefaultPivotStyle = "PivotStyleLight16" }; + + var stylesheetExtensionList = new StylesheetExtensionList(); + + var stylesheetExtension1 = new StylesheetExtension() { Uri = "{EB79DEF2-80B8-43e5-95BD-54CBDDF9020C}" }; + stylesheetExtension1.AddNamespaceDeclaration("x14", "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main"); + stylesheetExtension1.Append(new SlicerStyles() { DefaultSlicerStyle = "SlicerStyleLight1" }); + + var stylesheetExtension2 = new StylesheetExtension() { Uri = "{9260A510-F301-46a8-8635-F512D64BE5F5}" }; + stylesheetExtension2.AddNamespaceDeclaration("x15", "http://schemas.microsoft.com/office/spreadsheetml/2010/11/main"); + stylesheetExtension2.Append(new TimelineStyles() { DefaultTimelineStyle = "TimeSlicerStyleLight1" }); + + stylesheetExtensionList.Append(stylesheetExtension1); + stylesheetExtensionList.Append(stylesheetExtension2); + + sp.Stylesheet.Append(fonts); + sp.Stylesheet.Append(fills); + sp.Stylesheet.Append(borders); + sp.Stylesheet.Append(cellStyleFormats); + sp.Stylesheet.Append(cellFormats); + sp.Stylesheet.Append(cellStyles); + sp.Stylesheet.Append(differentialFormats); + sp.Stylesheet.Append(tableStyles); + sp.Stylesheet.Append(stylesheetExtensionList); + } + + /// + /// Получение номера стиля из типа + /// + /// + /// + private static uint GetStyleValue(ExcelStyleInfoType styleInfo) + { + return styleInfo switch + { + ExcelStyleInfoType.Title => 2U, + ExcelStyleInfoType.TextWithBroder => 1U, + ExcelStyleInfoType.Text => 0U, + _ => 0U, + }; + } + + protected override void CreateExcel(ExcelInfoStudent info) + { + _spreadsheetDocument = SpreadsheetDocument.Create(info.FileName, SpreadsheetDocumentType.Workbook); + + var 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(); + } + + + var worksheetPart = workbookpart.AddNewPart(); + worksheetPart.Worksheet = new Worksheet(new SheetData()); + + + var sheets = _spreadsheetDocument.WorkbookPart.Workbook.AppendChild(new Sheets()); + var sheet = new Sheet() + { + Id = _spreadsheetDocument.WorkbookPart.GetIdOfPart(worksheetPart), + SheetId = 1, + Name = "Лист" + }; + sheets.Append(sheet); + + _worksheet = worksheetPart.Worksheet; + } + + protected override void InsertCellInWorksheet(ExcelCellParameters excelParams) + { + if (_worksheet == null || _shareStringPart == null) + { + return; + } + var sheetData = _worksheet.GetFirstChild(); + if (sheetData == null) + { + return; + } + + + Row row; + if (sheetData.Elements().Where(r => r.RowIndex! == excelParams.RowIndex).Any()) + { + row = sheetData.Elements().Where(r => r.RowIndex! == excelParams.RowIndex).First(); + } + else + { + row = new Row() { RowIndex = excelParams.RowIndex }; + sheetData.Append(row); + } + + + Cell cell; + if (row.Elements().Where(c => c.CellReference!.Value == excelParams.CellReference).Any()) + { + cell = row.Elements().Where(c => c.CellReference!.Value == excelParams.CellReference).First(); + } + else + { + + Cell? refCell = null; + foreach (Cell rowCell in row.Elements()) + { + if (string.Compare(rowCell.CellReference!.Value, excelParams.CellReference, true) > 0) + { + refCell = rowCell; + break; + } + } + + var newCell = new Cell() { CellReference = excelParams.CellReference }; + row.InsertBefore(newCell, refCell); + + cell = newCell; + } + + + _shareStringPart.SharedStringTable.AppendChild(new SharedStringItem(new Text(excelParams.Text))); + _shareStringPart.SharedStringTable.Save(); + + cell.CellValue = new CellValue((_shareStringPart.SharedStringTable.Elements().Count() - 1).ToString()); + cell.DataType = new EnumValue(CellValues.SharedString); + cell.StyleIndex = GetStyleValue(excelParams.StyleInfo); + } + + protected override 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); + } + + protected override void SaveExcel(ExcelInfoStudent info) + { + if (_spreadsheetDocument == null) + { + return; + } + _spreadsheetDocument.WorkbookPart!.Workbook.Save(); + _spreadsheetDocument.Close(); + } + } +} \ No newline at end of file diff --git a/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/OfficePackage/Implements/SaveToExcelTeacher.cs b/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/OfficePackage/Implements/SaveToExcelTeacher.cs new file mode 100644 index 0000000..2e86bb8 --- /dev/null +++ b/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/OfficePackage/Implements/SaveToExcelTeacher.cs @@ -0,0 +1,291 @@ +using SchoolAgainStudyBusinessLogic.OfficePackage.HelperEnums; +using SchoolAgainStudyBusinessLogic.OfficePackage.HelperModels; +using DocumentFormat.OpenXml; +using DocumentFormat.OpenXml.Office2010.Excel; +using DocumentFormat.OpenXml.Office2013.Excel; +using DocumentFormat.OpenXml.Packaging; +using DocumentFormat.OpenXml.Spreadsheet; + +namespace SchoolAgainStudyBusinessLogic.OfficePackage.Implements +{ + public class SaveToExcelTeacher : AbstractSaveToExcelTeacher + { + private SpreadsheetDocument? _spreadsheetDocument; + + private SharedStringTablePart? _shareStringPart; + + private Worksheet? _worksheet; + + /// + /// Настройка стилей для файла + /// + /// + private static 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 }); + fontUsual.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Theme = 1U }); + fontUsual.Append(new FontName() { Val = "Times New Roman" }); + fontUsual.Append(new FontFamilyNumbering() { Val = 2 }); + fontUsual.Append(new FontScheme() { Val = FontSchemeValues.Minor }); + + var fontTitle = new Font(); + fontTitle.Append(new Bold()); + fontTitle.Append(new FontSize() { Val = 14D }); + fontTitle.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Theme = 1U }); + fontTitle.Append(new FontName() { Val = "Times New Roman" }); + fontTitle.Append(new FontFamilyNumbering() { Val = 2 }); + fontTitle.Append(new FontScheme() { Val = FontSchemeValues.Minor }); + + fonts.Append(fontUsual); + fonts.Append(fontTitle); + + var fills = new Fills() { Count = 2U }; + + var fill1 = new Fill(); + fill1.Append(new PatternFill() { PatternType = PatternValues.None }); + + var fill2 = new Fill(); + fill2.Append(new PatternFill() { PatternType = PatternValues.Gray125 }); + + fills.Append(fill1); + fills.Append(fill2); + + 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); + + var cellStyleFormats = new CellStyleFormats() { Count = 1U }; + var cellFormatStyle = new CellFormat() { NumberFormatId = 0U, FontId = 0U, FillId = 0U, BorderId = 0U }; + + cellStyleFormats.Append(cellFormatStyle); + + var cellFormats = new CellFormats() { Count = 3U }; + var cellFormatFont = new CellFormat() { NumberFormatId = 0U, FontId = 0U, FillId = 0U, BorderId = 0U, FormatId = 0U, ApplyFont = true }; + var cellFormatFontAndBorder = new CellFormat() { NumberFormatId = 0U, FontId = 0U, FillId = 0U, BorderId = 1U, FormatId = 0U, ApplyFont = true, ApplyBorder = true }; + var cellFormatTitle = new CellFormat() { NumberFormatId = 0U, FontId = 1U, FillId = 0U, BorderId = 0U, FormatId = 0U, Alignment = new Alignment() { Vertical = VerticalAlignmentValues.Center, WrapText = true, Horizontal = HorizontalAlignmentValues.Center }, ApplyFont = true }; + + cellFormats.Append(cellFormatFont); + cellFormats.Append(cellFormatFontAndBorder); + cellFormats.Append(cellFormatTitle); + + var cellStyles = new CellStyles() { Count = 1U }; + + cellStyles.Append(new CellStyle() { Name = "Normal", FormatId = 0U, BuiltinId = 0U }); + + var differentialFormats = new DocumentFormat.OpenXml.Office2013.Excel.DifferentialFormats() { Count = 0U }; + + var tableStyles = new TableStyles() { Count = 0U, DefaultTableStyle = "TableStyleMedium2", DefaultPivotStyle = "PivotStyleLight16" }; + + var stylesheetExtensionList = new StylesheetExtensionList(); + + var stylesheetExtension1 = new StylesheetExtension() { Uri = "{EB79DEF2-80B8-43e5-95BD-54CBDDF9020C}" }; + stylesheetExtension1.AddNamespaceDeclaration("x14", "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main"); + stylesheetExtension1.Append(new SlicerStyles() { DefaultSlicerStyle = "SlicerStyleLight1" }); + + var stylesheetExtension2 = new StylesheetExtension() { Uri = "{9260A510-F301-46a8-8635-F512D64BE5F5}" }; + stylesheetExtension2.AddNamespaceDeclaration("x15", "http://schemas.microsoft.com/office/spreadsheetml/2010/11/main"); + stylesheetExtension2.Append(new TimelineStyles() { DefaultTimelineStyle = "TimeSlicerStyleLight1" }); + + stylesheetExtensionList.Append(stylesheetExtension1); + stylesheetExtensionList.Append(stylesheetExtension2); + + sp.Stylesheet.Append(fonts); + sp.Stylesheet.Append(fills); + sp.Stylesheet.Append(borders); + sp.Stylesheet.Append(cellStyleFormats); + sp.Stylesheet.Append(cellFormats); + sp.Stylesheet.Append(cellStyles); + sp.Stylesheet.Append(differentialFormats); + sp.Stylesheet.Append(tableStyles); + sp.Stylesheet.Append(stylesheetExtensionList); + } + + /// + /// Получение номера стиля из типа + /// + /// + /// + private static uint GetStyleValue(ExcelStyleInfoType styleInfo) + { + return styleInfo switch + { + ExcelStyleInfoType.Title => 2U, + ExcelStyleInfoType.TextWithBroder => 1U, + ExcelStyleInfoType.Text => 0U, + _ => 0U, + }; + } + + protected override void CreateExcel(ExcelInfoTeacher info) + { + _spreadsheetDocument = SpreadsheetDocument.Create(info.FileName, SpreadsheetDocumentType.Workbook); + + var 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(); + } + + + var worksheetPart = workbookpart.AddNewPart(); + worksheetPart.Worksheet = new Worksheet(new SheetData()); + + + var sheets = _spreadsheetDocument.WorkbookPart.Workbook.AppendChild(new Sheets()); + var sheet = new Sheet() + { + Id = _spreadsheetDocument.WorkbookPart.GetIdOfPart(worksheetPart), + SheetId = 1, + Name = "Лист" + }; + sheets.Append(sheet); + + _worksheet = worksheetPart.Worksheet; + } + + protected override void InsertCellInWorksheet(ExcelCellParameters excelParams) + { + if (_worksheet == null || _shareStringPart == null) + { + return; + } + var sheetData = _worksheet.GetFirstChild(); + if (sheetData == null) + { + return; + } + + + Row row; + if (sheetData.Elements().Where(r => r.RowIndex! == excelParams.RowIndex).Any()) + { + row = sheetData.Elements().Where(r => r.RowIndex! == excelParams.RowIndex).First(); + } + else + { + row = new Row() { RowIndex = excelParams.RowIndex }; + sheetData.Append(row); + } + + + Cell cell; + if (row.Elements().Where(c => c.CellReference!.Value == excelParams.CellReference).Any()) + { + cell = row.Elements().Where(c => c.CellReference!.Value == excelParams.CellReference).First(); + } + else + { + + Cell? refCell = null; + foreach (Cell rowCell in row.Elements()) + { + if (string.Compare(rowCell.CellReference!.Value, excelParams.CellReference, true) > 0) + { + refCell = rowCell; + break; + } + } + + var newCell = new Cell() { CellReference = excelParams.CellReference }; + row.InsertBefore(newCell, refCell); + + cell = newCell; + } + + + _shareStringPart.SharedStringTable.AppendChild(new SharedStringItem(new Text(excelParams.Text))); + _shareStringPart.SharedStringTable.Save(); + + cell.CellValue = new CellValue((_shareStringPart.SharedStringTable.Elements().Count() - 1).ToString()); + cell.DataType = new EnumValue(CellValues.SharedString); + cell.StyleIndex = GetStyleValue(excelParams.StyleInfo); + } + + protected override 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); + } + + protected override void SaveExcel(ExcelInfoTeacher info) + { + if (_spreadsheetDocument == null) + { + return; + } + _spreadsheetDocument.WorkbookPart!.Workbook.Save(); + _spreadsheetDocument.Close(); + } + } +} \ No newline at end of file diff --git a/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/OfficePackage/Implements/SaveToPdfStudent.cs b/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/OfficePackage/Implements/SaveToPdfStudent.cs new file mode 100644 index 0000000..e4439a9 --- /dev/null +++ b/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/OfficePackage/Implements/SaveToPdfStudent.cs @@ -0,0 +1,114 @@ +using SchoolAgainStudyBusinessLogic.OfficePackage.HelperEnums; +using SchoolAgainStudyBusinessLogic.OfficePackage.HelperModels; +using MigraDoc.DocumentObjectModel; +using MigraDoc.DocumentObjectModel.Tables; +using MigraDoc.Rendering; + +namespace SchoolAgainStudyBusinessLogic.OfficePackage.Implements +{ + public class SaveToPdfStudent : AbstractSaveToPdfStudent + { + 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, + PdfParagraphAlignmentType.Rigth => ParagraphAlignment.Right, + _ => ParagraphAlignment.Justify, + }; + } + + /// + /// Создание стилей для документа + /// + /// + private static 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; + } + + protected override void CreatePdf(PdfInfoStudent info) + { + _document = new Document(); + DefineStyles(_document); + + _section = _document.AddSection(); + } + + protected override 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; + } + + protected override void CreateTable(List columns) + { + if (_document == null) + { + return; + } + _table = _document.LastSection.AddTable(); + + foreach (var elem in columns) + { + _table.AddColumn(elem); + } + } + + protected override 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; + } + } + + protected override void SavePdf(PdfInfoStudent info) + { + var renderer = new PdfDocumentRenderer(true) + { + Document = _document + }; + renderer.RenderDocument(); + renderer.PdfDocument.Save(info.FileName); + } + } +} \ No newline at end of file diff --git a/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/OfficePackage/Implements/SaveToPdfTeacher.cs b/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/OfficePackage/Implements/SaveToPdfTeacher.cs new file mode 100644 index 0000000..e82217f --- /dev/null +++ b/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/OfficePackage/Implements/SaveToPdfTeacher.cs @@ -0,0 +1,114 @@ +using SchoolAgainStudyBusinessLogic.OfficePackage.HelperEnums; +using SchoolAgainStudyBusinessLogic.OfficePackage.HelperModels; +using MigraDoc.DocumentObjectModel; +using MigraDoc.DocumentObjectModel.Tables; +using MigraDoc.Rendering; + +namespace SchoolAgainStudyBusinessLogic.OfficePackage.Implements +{ + public class SaveToPdfTeacher : AbstractSaveToPdfTeacher + { + 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, + PdfParagraphAlignmentType.Rigth => ParagraphAlignment.Right, + _ => ParagraphAlignment.Justify, + }; + } + + /// + /// Создание стилей для документа + /// + /// + private static 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; + } + + protected override void CreatePdf(PdfInfoTeacher info) + { + _document = new Document(); + DefineStyles(_document); + + _section = _document.AddSection(); + } + + protected override 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; + } + + protected override void CreateTable(List columns) + { + if (_document == null) + { + return; + } + _table = _document.LastSection.AddTable(); + + foreach (var elem in columns) + { + _table.AddColumn(elem); + } + } + + protected override 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; + } + } + + protected override void SavePdf(PdfInfoTeacher info) + { + var renderer = new PdfDocumentRenderer(true) + { + Document = _document + }; + renderer.RenderDocument(); + renderer.PdfDocument.Save(info.FileName); + } + } +} \ No newline at end of file diff --git a/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/OfficePackage/Implements/SaveToWordStudent.cs b/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/OfficePackage/Implements/SaveToWordStudent.cs new file mode 100644 index 0000000..2f50800 --- /dev/null +++ b/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/OfficePackage/Implements/SaveToWordStudent.cs @@ -0,0 +1,135 @@ +using SchoolAgainStudyBusinessLogic.OfficePackage.HelperEnums; +using SchoolAgainStudyBusinessLogic.OfficePackage.HelperModels; +using DocumentFormat.OpenXml; +using DocumentFormat.OpenXml.Packaging; +using DocumentFormat.OpenXml.Wordprocessing; + +namespace SchoolAgainStudyBusinessLogic.OfficePackage.Implements +{ + public class SaveToWordStudent : AbstractSaveToWordStudent + { + private WordprocessingDocument? _wordDocument; + + private Body? _docBody; + + /// + /// Получение типа выравнивания + /// + /// + /// + private static JustificationValues GetJustificationValues(WordJustificationType type) + { + return type switch + { + WordJustificationType.Both => JustificationValues.Both, + WordJustificationType.Center => JustificationValues.Center, + _ => JustificationValues.Left, + }; + } + + /// + /// Настройки страницы + /// + /// + private static SectionProperties CreateSectionProperties() + { + var properties = new SectionProperties(); + + var pageSize = new PageSize + { + Orient = PageOrientationValues.Portrait + }; + + properties.AppendChild(pageSize); + + return properties; + } + + /// + /// Задание форматирования для абзаца + /// + /// + /// + private static ParagraphProperties? CreateParagraphProperties(WordTextProperties? paragraphProperties) + { + if (paragraphProperties == null) + { + return null; + } + + var properties = new ParagraphProperties(); + + properties.AppendChild(new Justification() + { + Val = GetJustificationValues(paragraphProperties.JustificationType) + }); + + properties.AppendChild(new SpacingBetweenLines + { + LineRule = LineSpacingRuleValues.Auto + }); + + properties.AppendChild(new Indentation()); + + var paragraphMarkRunProperties = new ParagraphMarkRunProperties(); + if (!string.IsNullOrEmpty(paragraphProperties.Size)) + { + paragraphMarkRunProperties.AppendChild(new FontSize { Val = paragraphProperties.Size }); + } + properties.AppendChild(paragraphMarkRunProperties); + + return properties; + } + + protected override void CreateWord(WordInfoStudent info) + { + _wordDocument = WordprocessingDocument.Create(info.FileName, WordprocessingDocumentType.Document); + MainDocumentPart mainPart = _wordDocument.AddMainDocumentPart(); + mainPart.Document = new Document(); + _docBody = mainPart.Document.AppendChild(new Body()); + } + + protected override void CreateParagraph(WordParagraph paragraph) + { + if (_docBody == null || paragraph == null) + { + return; + } + var docParagraph = new Paragraph(); + + docParagraph.AppendChild(CreateParagraphProperties(paragraph.TextProperties)); + + foreach (var run in paragraph.Texts) + { + var docRun = new Run(); + + var properties = new RunProperties(); + properties.AppendChild(new FontSize { Val = run.Item2.Size }); + if (run.Item2.Bold) + { + properties.AppendChild(new Bold()); + } + docRun.AppendChild(properties); + + docRun.AppendChild(new Text { Text = run.Item1, Space = SpaceProcessingModeValues.Preserve }); + + docParagraph.AppendChild(docRun); + } + + _docBody.AppendChild(docParagraph); + } + + protected override void SaveWord(WordInfoStudent info) + { + if (_docBody == null || _wordDocument == null) + { + return; + } + _docBody.AppendChild(CreateSectionProperties()); + + _wordDocument.MainDocumentPart!.Document.Save(); + + _wordDocument.Close(); + } + } +} \ No newline at end of file diff --git a/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/OfficePackage/Implements/SaveToWordTeacher.cs b/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/OfficePackage/Implements/SaveToWordTeacher.cs new file mode 100644 index 0000000..3f4ef5f --- /dev/null +++ b/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/OfficePackage/Implements/SaveToWordTeacher.cs @@ -0,0 +1,135 @@ +using SchoolAgainStudyBusinessLogic.OfficePackage.HelperEnums; +using SchoolAgainStudyBusinessLogic.OfficePackage.HelperModels; +using DocumentFormat.OpenXml; +using DocumentFormat.OpenXml.Packaging; +using DocumentFormat.OpenXml.Wordprocessing; + +namespace SchoolAgainStudyBusinessLogic.OfficePackage.Implements +{ + public class SaveToWordTeacher : AbstractSaveToWordTeacher + { + private WordprocessingDocument? _wordDocument; + + private Body? _docBody; + + /// + /// Получение типа выравнивания + /// + /// + /// + private static JustificationValues GetJustificationValues(WordJustificationType type) + { + return type switch + { + WordJustificationType.Both => JustificationValues.Both, + WordJustificationType.Center => JustificationValues.Center, + _ => JustificationValues.Left, + }; + } + + /// + /// Настройки страницы + /// + /// + private static SectionProperties CreateSectionProperties() + { + var properties = new SectionProperties(); + + var pageSize = new PageSize + { + Orient = PageOrientationValues.Portrait + }; + + properties.AppendChild(pageSize); + + return properties; + } + + /// + /// Задание форматирования для абзаца + /// + /// + /// + private static ParagraphProperties? CreateParagraphProperties(WordTextProperties? paragraphProperties) + { + if (paragraphProperties == null) + { + return null; + } + + var properties = new ParagraphProperties(); + + properties.AppendChild(new Justification() + { + Val = GetJustificationValues(paragraphProperties.JustificationType) + }); + + properties.AppendChild(new SpacingBetweenLines + { + LineRule = LineSpacingRuleValues.Auto + }); + + properties.AppendChild(new Indentation()); + + var paragraphMarkRunProperties = new ParagraphMarkRunProperties(); + if (!string.IsNullOrEmpty(paragraphProperties.Size)) + { + paragraphMarkRunProperties.AppendChild(new FontSize { Val = paragraphProperties.Size }); + } + properties.AppendChild(paragraphMarkRunProperties); + + return properties; + } + + protected override void CreateWord(WordInfoTeacher info) + { + _wordDocument = WordprocessingDocument.Create(info.FileName, WordprocessingDocumentType.Document); + MainDocumentPart mainPart = _wordDocument.AddMainDocumentPart(); + mainPart.Document = new Document(); + _docBody = mainPart.Document.AppendChild(new Body()); + } + + protected override void CreateParagraph(WordParagraph paragraph) + { + if (_docBody == null || paragraph == null) + { + return; + } + var docParagraph = new Paragraph(); + + docParagraph.AppendChild(CreateParagraphProperties(paragraph.TextProperties)); + + foreach (var run in paragraph.Texts) + { + var docRun = new Run(); + + var properties = new RunProperties(); + properties.AppendChild(new FontSize { Val = run.Item2.Size }); + if (run.Item2.Bold) + { + properties.AppendChild(new Bold()); + } + docRun.AppendChild(properties); + + docRun.AppendChild(new Text { Text = run.Item1, Space = SpaceProcessingModeValues.Preserve }); + + docParagraph.AppendChild(docRun); + } + + _docBody.AppendChild(docParagraph); + } + + protected override void SaveWord(WordInfoTeacher info) + { + if (_docBody == null || _wordDocument == null) + { + return; + } + _docBody.AppendChild(CreateSectionProperties()); + + _wordDocument.MainDocumentPart!.Document.Save(); + + _wordDocument.Close(); + } + } +} \ No newline at end of file diff --git a/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/SchoolAgainStudyBusinessLogic.csproj b/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/SchoolAgainStudyBusinessLogic.csproj index f7f6cde..5645df8 100644 --- a/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/SchoolAgainStudyBusinessLogic.csproj +++ b/SchoolAgainStudy/SchoolAgainStudyBusinessLogic/SchoolAgainStudyBusinessLogic.csproj @@ -17,6 +17,9 @@ + + + diff --git a/SchoolAgainStudy/SchoolAgainStudyContracts/BindingModel/ReportBindingModel.cs b/SchoolAgainStudy/SchoolAgainStudyContracts/BindingModel/ReportBindingModel.cs index f89d3a8..1ec7801 100644 --- a/SchoolAgainStudy/SchoolAgainStudyContracts/BindingModel/ReportBindingModel.cs +++ b/SchoolAgainStudy/SchoolAgainStudyContracts/BindingModel/ReportBindingModel.cs @@ -1,4 +1,5 @@ -using System; +using SchoolAgainStudyContracts.ViewModel; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -10,6 +11,13 @@ namespace SchoolAgainStudyContracts.BindingModel { public string FileName { get; set; } = string.Empty; + public int? TeacherId { get; set; } + public int? StudentId { get; set; } + + public List? Materials { get; set; } + + public List? Interests { get; set; } + public DateTime? DateFrom { get; set; } public DateTime? DateTo { get; set; } diff --git a/SchoolAgainStudy/SchoolAgainStudyContracts/BusinessLogicContracts/IReportLogic.cs b/SchoolAgainStudy/SchoolAgainStudyContracts/BusinessLogicContracts/IReportLogic.cs index 3bab246..aee686b 100644 --- a/SchoolAgainStudy/SchoolAgainStudyContracts/BusinessLogicContracts/IReportLogic.cs +++ b/SchoolAgainStudy/SchoolAgainStudyContracts/BusinessLogicContracts/IReportLogic.cs @@ -10,11 +10,11 @@ namespace SchoolAgainStudyContracts.BusinessLogicContracts { public interface IReportLogic { - List GetInterestLesson(); + List GetInterestLesson(ReportBindingModel model); List GetInterests(ReportBindingModel model); - List GetDiyMaterial(); + List GetDiyMaterial(ReportBindingModel model); List GetLessonTask(ReportBindingModel model);