diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/AbstractSaveToExcel.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/AbstractSaveToExcel.cs new file mode 100644 index 0000000..cc0054c --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/AbstractSaveToExcel.cs @@ -0,0 +1,101 @@ +using BlacksmithWorkshopBusinessLogic.OfficePackage.HelperEnums; +using BlacksmithWorkshopBusinessLogic.OfficePackage.HelperModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopBusinessLogic.OfficePackage +{ + public abstract class AbstractSaveToExcel + { + //Создание отчета. Описание методов ниже + 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 mwp in info.ManufactureWorkPieces) + { + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "A", + RowIndex = rowIndex, + Text = mwp.WorkPieceName, + StyleInfo = ExcelStyleInfoType.Text + }); + + rowIndex++; + + foreach (var (Manufacure, Count) in mwp.Manufactures) + { + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "B", + RowIndex = rowIndex, + Text = Manufacure, + 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 = mwp.TotalCount.ToString(), + StyleInfo = ExcelStyleInfoType.Text + }); + + rowIndex++; + } + + SaveExcel(info); + } + + //Создание excel-файла + 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/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/AbstractSaveToPdf.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/AbstractSaveToPdf.cs new file mode 100644 index 0000000..0da5b88 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/AbstractSaveToPdf.cs @@ -0,0 +1,74 @@ +using BlacksmithWorkshopBusinessLogic.OfficePackage.HelperEnums; +using BlacksmithWorkshopBusinessLogic.OfficePackage.HelperModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopBusinessLogic.OfficePackage +{ + public abstract class AbstractSaveToPdf + { + //публичный метод создания документа. Описание методов ниже + 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" }); + + 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.ManufactureName, 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/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/AbstractSaveToWord.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/AbstractSaveToWord.cs new file mode 100644 index 0000000..5d0f643 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/AbstractSaveToWord.cs @@ -0,0 +1,56 @@ +using BlacksmithWorkshopBusinessLogic.OfficePackage.HelperEnums; +using BlacksmithWorkshopBusinessLogic.OfficePackage.HelperModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopBusinessLogic.OfficePackage +{ + public abstract class AbstractSaveToWord + { + //метод создания документа + public void CreateDoc(WordInfo 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 workPiece in info.WorkPieces) + { + CreateParagraph(new WordParagraph + { + Texts = new List<(string, WordTextProperties)> { (workPiece.WorkPieceName, new WordTextProperties { Size = "24", }) }, + TextProperties = new WordTextProperties + { + Size = "24", + JustificationType = WordJustificationType.Both + } + }); + } + + SaveWord(info); + } + + // Создание doc-файла + protected abstract void CreateWord(WordInfo info); + + // Создание абзаца с текстом + protected abstract void CreateParagraph(WordParagraph paragraph); + + // Сохранение файла + protected abstract void SaveWord(WordInfo info); + + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperEnums/ExcelStyleInfoType.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperEnums/ExcelStyleInfoType.cs index 851b205..4b9b37f 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperEnums/ExcelStyleInfoType.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperEnums/ExcelStyleInfoType.cs @@ -16,6 +16,6 @@ namespace BlacksmithWorkshopBusinessLogic.OfficePackage.HelperEnums Text, //текст в рамке - TixtWithBorder + TextWithBroder } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperEnums/PdfParagraphAligmentType.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperEnums/PdfParagraphAlignmentType.cs similarity index 92% rename from BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperEnums/PdfParagraphAligmentType.cs rename to BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperEnums/PdfParagraphAlignmentType.cs index e7627f1..ec88914 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperEnums/PdfParagraphAligmentType.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperEnums/PdfParagraphAlignmentType.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; namespace BlacksmithWorkshopBusinessLogic.OfficePackage.HelperEnums { //вспомогательное перечисление для оформления pdf документа - public enum PdfParagraphAligmentType + public enum PdfParagraphAlignmentType { //либо по центру Center, diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/ExcelMergeParametrs.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/ExcelMergeParameters.cs similarity index 94% rename from BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/ExcelMergeParametrs.cs rename to BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/ExcelMergeParameters.cs index c39988a..d110ff2 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/ExcelMergeParametrs.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/ExcelMergeParameters.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; namespace BlacksmithWorkshopBusinessLogic.OfficePackage.HelperModels { //информация для объединения ячеек - public class ExcelMergeParametrs + public class ExcelMergeParameters { public string CellFromName { get; set; } = string.Empty; diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/PdfParagraph.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/PdfParagraph.cs index e7e51ad..1230049 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/PdfParagraph.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/PdfParagraph.cs @@ -15,6 +15,6 @@ namespace BlacksmithWorkshopBusinessLogic.OfficePackage.HelperModels public string Style { get; set; } = string.Empty; //информация по выравниванию текста в параграфе - public PdfParagraphAligmentType ParagraphAligment { get; set; } + public PdfParagraphAlignmentType ParagraphAlignment { get; set; } } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/PdfRowParametrs.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/PdfRowParameters.cs similarity index 84% rename from BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/PdfRowParametrs.cs rename to BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/PdfRowParameters.cs index 1b1dfb4..73fd449 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/PdfRowParametrs.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/PdfRowParameters.cs @@ -8,7 +8,7 @@ using System.Threading.Tasks; namespace BlacksmithWorkshopBusinessLogic.OfficePackage.HelperModels { //информация по параметрам строк таблицы - public class PdfRowParametrs + public class PdfRowParameters { //набор текстов public List Texts { get; set; } = new(); @@ -17,6 +17,6 @@ namespace BlacksmithWorkshopBusinessLogic.OfficePackage.HelperModels public string Style { get; set; } = string.Empty; //как выравниваем - public PdfParagraphAligmentType ParagraphAligment { get; set; } + public PdfParagraphAlignmentType ParagraphAlignment { get; set; } } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/WordParagraph.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/WordParagraph.cs index 79ed022..be18bda 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/WordParagraph.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/WordParagraph.cs @@ -10,7 +10,7 @@ namespace BlacksmithWorkshopBusinessLogic.OfficePackage.HelperModels public class WordParagraph { //набор текстов в абзаце (для случая, если в абзаце текст разных стилей) - public List<(string, WordParagraph)> Texts { get; set; } = new(); + public List<(string, WordTextProperties)> Texts { get; set; } = new(); //свойства параграфа, если они есть public WordTextProperties? TextProperties { get; set; }