From 92f9e9f8e94e7b8f8cf5a69a96be3a1d23d3af38 Mon Sep 17 00:00:00 2001 From: kotcheshir73 Date: Tue, 20 Dec 2022 13:36:46 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BC=D0=B5=D0=BB=D0=BA=D0=B8=D0=B5=20=D0=BF?= =?UTF-8?q?=D1=80=D0=B0=D0=B2=D0=BA=D0=B8=20=D0=BF=D0=BE=20=D0=BF=D0=B0?= =?UTF-8?q?=D0=BA=D0=B5=D1=82=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Extensions/WordDocumentExtension.cs | 13 ++++++++++++ .../Extensions/WordParagraphExtension.cs | 20 ++++--------------- .../Extensions/WordRunExtension.cs | 14 +------------ .../Interfaces/Word/BuilderWordDocument.cs | 5 +++++ .../ModelWordDocumentWithHeaderAndTable.cs | 11 +++++++++- .../Word/{PageSizes.cs => WordPageSizes.cs} | 7 +++++-- .../StudentGroupBusinessLogic.cs | 2 +- 7 files changed, 39 insertions(+), 33 deletions(-) rename DepartmentPortal/Common/ToolsOffice/Interfaces/Word/{PageSizes.cs => WordPageSizes.cs} (88%) diff --git a/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Extensions/WordDocumentExtension.cs b/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Extensions/WordDocumentExtension.cs index d6019fb..c2e8712 100644 --- a/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Extensions/WordDocumentExtension.cs +++ b/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Extensions/WordDocumentExtension.cs @@ -1,6 +1,7 @@ using DocumentFormat.OpenXml; using DocumentFormat.OpenXml.Wordprocessing; using System; +using ToolsOffice.Interfaces; using ToolsOffice.Interfaces.Word.Models; namespace ToolsOffice.Implements.WordOpenXML.Extensions @@ -8,6 +9,7 @@ namespace ToolsOffice.Implements.WordOpenXML.Extensions public static class WordDocumentExtension { private static readonly int _coefToPoins = 567; + /// /// Добавление общих настроек документа /// @@ -70,5 +72,16 @@ namespace ToolsOffice.Implements.WordOpenXML.Extensions body.AppendChild(properties); } + + /// + /// Получение шрифта из FontNames + /// + /// + /// + public static (string Ascii, string HighAnsi, string ComplexScript) GetFontName(FontNames fn) => fn switch + { + FontNames.TimesNewRoman => ("Times New Roman", "Times New Roman", "Times New Roman"), + _ => default, + }; } } \ No newline at end of file diff --git a/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Extensions/WordParagraphExtension.cs b/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Extensions/WordParagraphExtension.cs index 82e011c..afc0759 100644 --- a/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Extensions/WordParagraphExtension.cs +++ b/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Extensions/WordParagraphExtension.cs @@ -2,7 +2,6 @@ using DocumentFormat.OpenXml.Wordprocessing; using System; using ToolsModule.ManagmentExtension; -using ToolsOffice.Interfaces; using ToolsOffice.Interfaces.Word.Models; namespace ToolsOffice.Implements.WordOpenXML.Extensions @@ -96,7 +95,7 @@ namespace ToolsOffice.Implements.WordOpenXML.Extensions var paragraphMarkRunProperties = new ParagraphMarkRunProperties(); if (model.FontName.HasValue) { - var font = GetFontName(model.FontName.Value); + var font = WordDocumentExtension.GetFontName(model.FontName.Value); paragraphMarkRunProperties.AppendChild(new RunFonts { Ascii = new StringValue(font.Ascii), @@ -138,37 +137,26 @@ namespace ToolsOffice.Implements.WordOpenXML.Extensions if (model.Text.IsNotEmpty()) { var text = new ModelWordText { Text = model.Text }; - CheckRunProps(model, text); + SyncRunProps(model, text); paragraph.AddRun(text); } else if (model.WordTexts != null) { foreach (var text in model.WordTexts) { - CheckRunProps(model, text); + SyncRunProps(model, text); paragraph.AddRun(text); } } return paragraph; } - /// - /// Получение шрифта из FontNames - /// - /// - /// - private static (string Ascii, string HighAnsi, string ComplexScript) GetFontName(FontNames fn) => fn switch - { - FontNames.TimesNewRoman => ("Times New Roman", "Times New Roman", "Times New Roman"), - _ => default, - }; - /// /// Пеоедача параметров текста из параметров абзаца, если не заданы параметры текста /// /// /// - private static void CheckRunProps(ModelWordParagraph paragraph, ModelWordText run) + private static void SyncRunProps(ModelWordParagraph paragraph, ModelWordText run) { if (run == null) { diff --git a/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Extensions/WordRunExtension.cs b/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Extensions/WordRunExtension.cs index b01b3dc..b8821d2 100644 --- a/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Extensions/WordRunExtension.cs +++ b/DepartmentPortal/Common/ToolsOffice/Implements/WordOpenXML/Extensions/WordRunExtension.cs @@ -1,6 +1,5 @@ using DocumentFormat.OpenXml; using DocumentFormat.OpenXml.Wordprocessing; -using ToolsOffice.Interfaces; using ToolsOffice.Interfaces.Word.Models; namespace ToolsOffice.Implements.WordOpenXML.Extensions @@ -52,7 +51,7 @@ namespace ToolsOffice.Implements.WordOpenXML.Extensions var properties = new RunProperties(); if (model.FontName.HasValue) { - var font = GetFontName(model.FontName.Value); + var font = WordDocumentExtension.GetFontName(model.FontName.Value); properties.AppendChild(new RunFonts { Ascii = new StringValue(font.Ascii), @@ -80,16 +79,5 @@ namespace ToolsOffice.Implements.WordOpenXML.Extensions run.AppendChild(properties); } } - - /// - /// Получение шрифта из FontNames - /// - /// - /// - private static (string Ascii, string HighAnsi, string ComplexScript) GetFontName(FontNames fn) => fn switch - { - FontNames.TimesNewRoman => ("Times New Roman", "Times New Roman", "Times New Roman"), - _ => default, - }; } } \ No newline at end of file diff --git a/DepartmentPortal/Common/ToolsOffice/Interfaces/Word/BuilderWordDocument.cs b/DepartmentPortal/Common/ToolsOffice/Interfaces/Word/BuilderWordDocument.cs index fbdf8a3..6e9c2b9 100644 --- a/DepartmentPortal/Common/ToolsOffice/Interfaces/Word/BuilderWordDocument.cs +++ b/DepartmentPortal/Common/ToolsOffice/Interfaces/Word/BuilderWordDocument.cs @@ -6,6 +6,11 @@ namespace ToolsOffice.Interfaces.Word { public abstract class BuilderWordDocument { + /// + /// Создание документа с заголовком и таблицей + /// + /// + /// public Stream CreateDocumentWithTable(ModelWordDocumentWithHeaderAndTable model) { if (model == null || model.Document == null || model.Header == null || model.Table == null) diff --git a/DepartmentPortal/Common/ToolsOffice/Interfaces/Word/Models/Cases/ModelWordDocumentWithHeaderAndTable.cs b/DepartmentPortal/Common/ToolsOffice/Interfaces/Word/Models/Cases/ModelWordDocumentWithHeaderAndTable.cs index 24bc2ef..f965a90 100644 --- a/DepartmentPortal/Common/ToolsOffice/Interfaces/Word/Models/Cases/ModelWordDocumentWithHeaderAndTable.cs +++ b/DepartmentPortal/Common/ToolsOffice/Interfaces/Word/Models/Cases/ModelWordDocumentWithHeaderAndTable.cs @@ -1,14 +1,23 @@ namespace ToolsOffice.Interfaces.Word.Models.Cases { /// - /// Модель для создания простого документа с шапкой и таблицей + /// Модель для создания простого документа с заголовком и таблицей /// public class ModelWordDocumentWithHeaderAndTable { + /// + /// Информация по документу + /// public ModelWordDocument Document { get; set; } + /// + /// Заголовок + /// public ModelWordParagraph Header { get; set; } + /// + /// Таблица + /// public ModelWordTable Table { get; set; } } } \ No newline at end of file diff --git a/DepartmentPortal/Common/ToolsOffice/Interfaces/Word/PageSizes.cs b/DepartmentPortal/Common/ToolsOffice/Interfaces/Word/WordPageSizes.cs similarity index 88% rename from DepartmentPortal/Common/ToolsOffice/Interfaces/Word/PageSizes.cs rename to DepartmentPortal/Common/ToolsOffice/Interfaces/Word/WordPageSizes.cs index 54bfe7d..71f4279 100644 --- a/DepartmentPortal/Common/ToolsOffice/Interfaces/Word/PageSizes.cs +++ b/DepartmentPortal/Common/ToolsOffice/Interfaces/Word/WordPageSizes.cs @@ -3,7 +3,10 @@ using System.Linq; namespace ToolsOffice.Interfaces.Word { - public class PageSizes + /// + /// Размеры страниц документов (портретная ориентация) + /// + public class WordPageSizes { private static readonly Dictionary _sizes = new() @@ -17,7 +20,7 @@ namespace ToolsOffice.Interfaces.Word private readonly string _key; - public PageSizes(string key) + public WordPageSizes(string key) { _hasKey = _sizes.ContainsKey(key); _key = key; diff --git a/DepartmentPortal/Department/DepartmentBusinessLogic/BusinessLogics/GenericBusinessLogic/StudentGroupBusinessLogic.cs b/DepartmentPortal/Department/DepartmentBusinessLogic/BusinessLogics/GenericBusinessLogic/StudentGroupBusinessLogic.cs index 8295a6f..a994c5e 100644 --- a/DepartmentPortal/Department/DepartmentBusinessLogic/BusinessLogics/GenericBusinessLogic/StudentGroupBusinessLogic.cs +++ b/DepartmentPortal/Department/DepartmentBusinessLogic/BusinessLogics/GenericBusinessLogic/StudentGroupBusinessLogic.cs @@ -149,7 +149,7 @@ namespace DepartmentBusinessLogic.BusinessLogics.GenericBusinessLogic rowIndex++; } - var pageSize = new PageSizes("А4"); + var pageSize = new WordPageSizes("А4"); var docModel = new ModelWordDocumentWithHeaderAndTable { Document = new ModelWordDocument