From 527ece513aa92c0f12b95bdb8f4edd440f4d8835 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=98=D0=BB=D1=8C=D1=8F=20=D0=A4=D0=B5=D0=B4=D0=BE=D1=82?= =?UTF-8?q?=D0=BE=D0=B2?= Date: Wed, 3 Apr 2024 20:22:35 +0400 Subject: [PATCH 1/2] Base.01 --- .../BindingModels/ReportBindingModel.cs | 15 ++++ .../BusinessLogicsContracts/IReportLogic.cs | 24 ++++++ .../SearchModels/OrderSearchModel.cs | 2 + .../ViewModels/ReportOrdersViewModel.cs | 16 ++++ .../ViewModels/ReportSnackFoodsViewModel.cs | 15 ++++ .../OfficePackage/AbstractSaveToExcel.cs | 84 +++++++++++++++++++ .../OfficePackage/AbstractSaveToWord.cs | 43 ++++++++++ .../HelperEnums/ExcelStyleInfoType.cs | 15 ++++ .../HelperEnums/PdfParagraphAlignmentType.cs | 15 ++++ .../HelperEnums/WordJustificationType.cs | 14 ++++ .../HelperModels/ExcelCellParameters.cs | 18 ++++ .../OfficePackage/HelperModels/ExcelInfo.cs | 17 ++++ .../HelperModels/ExcelMergeParameters.cs | 15 ++++ .../OfficePackage/HelperModels/PdfInfo.cs | 19 +++++ .../HelperModels/PdfParagraph.cs | 16 ++++ .../HelperModels/PdfRowParameters.cs | 16 ++++ .../OfficePackage/HelperModels/WordInfo.cs | 16 ++++ .../HelperModels/WordParagraph.cs | 14 ++++ .../HelperModels/WordTextProperties.cs | 16 ++++ 19 files changed, 390 insertions(+) create mode 100644 Diner/DinerContracts/BindingModels/ReportBindingModel.cs create mode 100644 Diner/DinerContracts/BusinessLogicsContracts/IReportLogic.cs create mode 100644 Diner/DinerContracts/ViewModels/ReportOrdersViewModel.cs create mode 100644 Diner/DinerContracts/ViewModels/ReportSnackFoodsViewModel.cs create mode 100644 Diner/DineryBusinessLogic/OfficePackage/AbstractSaveToExcel.cs create mode 100644 Diner/DineryBusinessLogic/OfficePackage/AbstractSaveToWord.cs create mode 100644 Diner/DineryBusinessLogic/OfficePackage/HelperEnums/ExcelStyleInfoType.cs create mode 100644 Diner/DineryBusinessLogic/OfficePackage/HelperEnums/PdfParagraphAlignmentType.cs create mode 100644 Diner/DineryBusinessLogic/OfficePackage/HelperEnums/WordJustificationType.cs create mode 100644 Diner/DineryBusinessLogic/OfficePackage/HelperModels/ExcelCellParameters.cs create mode 100644 Diner/DineryBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs create mode 100644 Diner/DineryBusinessLogic/OfficePackage/HelperModels/ExcelMergeParameters.cs create mode 100644 Diner/DineryBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs create mode 100644 Diner/DineryBusinessLogic/OfficePackage/HelperModels/PdfParagraph.cs create mode 100644 Diner/DineryBusinessLogic/OfficePackage/HelperModels/PdfRowParameters.cs create mode 100644 Diner/DineryBusinessLogic/OfficePackage/HelperModels/WordInfo.cs create mode 100644 Diner/DineryBusinessLogic/OfficePackage/HelperModels/WordParagraph.cs create mode 100644 Diner/DineryBusinessLogic/OfficePackage/HelperModels/WordTextProperties.cs diff --git a/Diner/DinerContracts/BindingModels/ReportBindingModel.cs b/Diner/DinerContracts/BindingModels/ReportBindingModel.cs new file mode 100644 index 0000000..dcab5ea --- /dev/null +++ b/Diner/DinerContracts/BindingModels/ReportBindingModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DinerContracts.BindingModels +{ + public class ReportBindingModel + { + public string FileName { get; set; } = string.Empty; + public DateTime? DateFrom { get; set; } + public DateTime? DateTo { get; set;} + } +} diff --git a/Diner/DinerContracts/BusinessLogicsContracts/IReportLogic.cs b/Diner/DinerContracts/BusinessLogicsContracts/IReportLogic.cs new file mode 100644 index 0000000..32c17af --- /dev/null +++ b/Diner/DinerContracts/BusinessLogicsContracts/IReportLogic.cs @@ -0,0 +1,24 @@ +using DinerContracts.BindingModels; +using DinerContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DinerContracts.BusinessLogicsContracts +{ + public interface IReportLogic + { + // Получение списка компонент с указанием, в каких изделиях используются + List GetProductComponent(); + // Получение списка заказов за определенный период + List GetOrders(ReportBindingModel model); + // Сохранение компонент в файл-Word + void SaveComponentsToWorldFile(ReportBindingModel model); + // Сохранение компонент с указаеним продуктов в файл-Excel + void SaveProductComponentToExcelFile(ReportBindingModel model); + // Сохранение заказов в файл-Pdf + void SaveOrdersToPdfFile(ReportBindingModel model); + } +} diff --git a/Diner/DinerContracts/SearchModels/OrderSearchModel.cs b/Diner/DinerContracts/SearchModels/OrderSearchModel.cs index 4b7490d..13bd858 100644 --- a/Diner/DinerContracts/SearchModels/OrderSearchModel.cs +++ b/Diner/DinerContracts/SearchModels/OrderSearchModel.cs @@ -9,5 +9,7 @@ namespace DinerContracts.SearchModels public class OrderSearchModel { public int? ID { get; set; } + public DateTime? DateFrom { get; set; } + public DateTime? DateTo { get; set; } } } diff --git a/Diner/DinerContracts/ViewModels/ReportOrdersViewModel.cs b/Diner/DinerContracts/ViewModels/ReportOrdersViewModel.cs new file mode 100644 index 0000000..97939e6 --- /dev/null +++ b/Diner/DinerContracts/ViewModels/ReportOrdersViewModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DinerContracts.ViewModels +{ + public class ReportOrdersViewModel + { + public int ID { get; set; } + public DateTime DateCreate { get; set; } + public string ProductName { get; set; } = string.Empty; + public double Sum { get; set; } + } +} diff --git a/Diner/DinerContracts/ViewModels/ReportSnackFoodsViewModel.cs b/Diner/DinerContracts/ViewModels/ReportSnackFoodsViewModel.cs new file mode 100644 index 0000000..e1232ff --- /dev/null +++ b/Diner/DinerContracts/ViewModels/ReportSnackFoodsViewModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DinerContracts.ViewModels +{ + public class ReportSnackFoodsViewModel + { + public string ComponentName { get; set; } = string.Empty; + public int TotalCount { get; set; } + public List<(string Product, int count)> Products { get; set; } = new(); + } +} diff --git a/Diner/DineryBusinessLogic/OfficePackage/AbstractSaveToExcel.cs b/Diner/DineryBusinessLogic/OfficePackage/AbstractSaveToExcel.cs new file mode 100644 index 0000000..9715ecd --- /dev/null +++ b/Diner/DineryBusinessLogic/OfficePackage/AbstractSaveToExcel.cs @@ -0,0 +1,84 @@ +using DineryBusinessLogic.OfficePackage.HelperEnums; +using DineryBusinessLogic.OfficePackage.HelperModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DineryBusinessLogic.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 pc in info.ProductComponents) { + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "A", + RowIndex = rowIndex, + Text = pc.ComponentName, + StyleInfo = ExcelStyleInfoType.Title + }); + rowIndex++; + foreach (var (Product, Count) in pc.Products) { + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "B", + RowIndex = rowIndex, + Text = Product, + StyleInfo = ExcelStyleInfoType.TextWithBorder + }); + + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "C", + RowIndex = rowIndex, + Text = Count.ToString(), + StyleInfo = ExcelStyleInfoType.TextWithBorder + }); + rowIndex++; + } + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "A", + RowIndex = rowIndex, + Text = "Итого", + StyleInfo = ExcelStyleInfoType.Title + }); + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "C", + RowIndex = rowIndex, + Text = pc.TotalCount.ToString(), + StyleInfo = ExcelStyleInfoType.Title + }); + rowIndex++; + } + SaveExcel(info); + } + // Создание excel-файла + protected abstract void CreateExcel(ExcelInfo info); + // Добавляем новую ячейку в лист + protected abstract void InsertCellInWorksheet(ExcelCellParameters excelParameters); + // Объединение ячеек + protected abstract void MergeCells(ExcelMergeParameters mergeParams); + // Сохранение файла + protected abstract void SaveExcel(ExcelInfo info); + } +} diff --git a/Diner/DineryBusinessLogic/OfficePackage/AbstractSaveToWord.cs b/Diner/DineryBusinessLogic/OfficePackage/AbstractSaveToWord.cs new file mode 100644 index 0000000..6ebc4d4 --- /dev/null +++ b/Diner/DineryBusinessLogic/OfficePackage/AbstractSaveToWord.cs @@ -0,0 +1,43 @@ +using DineryBusinessLogic.OfficePackage.HelperEnums; +using DineryBusinessLogic.OfficePackage.HelperModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DineryBusinessLogic.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 component in info.Components) { + CreateParagraph(new WordParagraph + { + Texts = new List<(string, WordTextProperties)> { (component.ComponentName, new WordTextProperties { Size = "24", }) }, + TextProperties = new WordTextProperties + { + Size = "24", + JustificationType = WordJustificationType.both + } + }); + } + } + // Создание doc-файла + protected abstract void CreateWord(WordInfo info); + // Создание абзаца с текстом + protected abstract void CreateParagraph(WordParagraph paragraph); + // Сохранение файла + protected abstract void SaveWord(WordInfo info); + } +} diff --git a/Diner/DineryBusinessLogic/OfficePackage/HelperEnums/ExcelStyleInfoType.cs b/Diner/DineryBusinessLogic/OfficePackage/HelperEnums/ExcelStyleInfoType.cs new file mode 100644 index 0000000..25b799c --- /dev/null +++ b/Diner/DineryBusinessLogic/OfficePackage/HelperEnums/ExcelStyleInfoType.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DineryBusinessLogic.OfficePackage.HelperEnums +{ + public enum ExcelStyleInfoType + { + Title, + Text, + TextWithBorder + } +} diff --git a/Diner/DineryBusinessLogic/OfficePackage/HelperEnums/PdfParagraphAlignmentType.cs b/Diner/DineryBusinessLogic/OfficePackage/HelperEnums/PdfParagraphAlignmentType.cs new file mode 100644 index 0000000..b7aaeb7 --- /dev/null +++ b/Diner/DineryBusinessLogic/OfficePackage/HelperEnums/PdfParagraphAlignmentType.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DineryBusinessLogic.OfficePackage.HelperEnums +{ + public enum PdfParagraphAlignmentType + { + Center, + Left, + Right + } +} diff --git a/Diner/DineryBusinessLogic/OfficePackage/HelperEnums/WordJustificationType.cs b/Diner/DineryBusinessLogic/OfficePackage/HelperEnums/WordJustificationType.cs new file mode 100644 index 0000000..d4ce216 --- /dev/null +++ b/Diner/DineryBusinessLogic/OfficePackage/HelperEnums/WordJustificationType.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DineryBusinessLogic.OfficePackage.HelperEnums +{ + public enum WordJustificationType + { + Center, + both + } +} diff --git a/Diner/DineryBusinessLogic/OfficePackage/HelperModels/ExcelCellParameters.cs b/Diner/DineryBusinessLogic/OfficePackage/HelperModels/ExcelCellParameters.cs new file mode 100644 index 0000000..b776988 --- /dev/null +++ b/Diner/DineryBusinessLogic/OfficePackage/HelperModels/ExcelCellParameters.cs @@ -0,0 +1,18 @@ +using DineryBusinessLogic.OfficePackage.HelperEnums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DineryBusinessLogic.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; } + } +} diff --git a/Diner/DineryBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs b/Diner/DineryBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs new file mode 100644 index 0000000..5cc810e --- /dev/null +++ b/Diner/DineryBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs @@ -0,0 +1,17 @@ +using DinerContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Security.Cryptography.X509Certificates; +using System.Text; +using System.Threading.Tasks; + +namespace DineryBusinessLogic.OfficePackage.HelperModels +{ + public class ExcelInfo + { + public string FileName { get; set; } = string.Empty; + public string Title { get; set; } = string.Empty; + public List ProductComponents { get; set; } = new(); + } +} diff --git a/Diner/DineryBusinessLogic/OfficePackage/HelperModels/ExcelMergeParameters.cs b/Diner/DineryBusinessLogic/OfficePackage/HelperModels/ExcelMergeParameters.cs new file mode 100644 index 0000000..1e51fbd --- /dev/null +++ b/Diner/DineryBusinessLogic/OfficePackage/HelperModels/ExcelMergeParameters.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DineryBusinessLogic.OfficePackage.HelperModels +{ + public class ExcelMergeParameters + { + public string CellFromName { get; set; } = string.Empty; + public string CellToName { get; set; } = string.Empty; + public string Merge => $"{CellFromName}:{CellToName}"; + } +} diff --git a/Diner/DineryBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs b/Diner/DineryBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs new file mode 100644 index 0000000..f4b948a --- /dev/null +++ b/Diner/DineryBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs @@ -0,0 +1,19 @@ +using DinerContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Text; +using System.Threading.Tasks; + +namespace DineryBusinessLogic.OfficePackage.HelperModels +{ + public class PdfInfo + { + 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 Orders { get; set; } = new(); + } +} diff --git a/Diner/DineryBusinessLogic/OfficePackage/HelperModels/PdfParagraph.cs b/Diner/DineryBusinessLogic/OfficePackage/HelperModels/PdfParagraph.cs new file mode 100644 index 0000000..067323e --- /dev/null +++ b/Diner/DineryBusinessLogic/OfficePackage/HelperModels/PdfParagraph.cs @@ -0,0 +1,16 @@ +using DineryBusinessLogic.OfficePackage.HelperEnums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DineryBusinessLogic.OfficePackage.HelperModels +{ + public class PdfParagraph + { + public string Text { get; set; } = string.Empty; + public string Style { get; set; } = string.Empty; + public PdfParagraphAlignmentType ParagraphAlignment { get; set; } + } +} diff --git a/Diner/DineryBusinessLogic/OfficePackage/HelperModels/PdfRowParameters.cs b/Diner/DineryBusinessLogic/OfficePackage/HelperModels/PdfRowParameters.cs new file mode 100644 index 0000000..710aae9 --- /dev/null +++ b/Diner/DineryBusinessLogic/OfficePackage/HelperModels/PdfRowParameters.cs @@ -0,0 +1,16 @@ +using DineryBusinessLogic.OfficePackage.HelperEnums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DineryBusinessLogic.OfficePackage.HelperModels +{ + public class PdfRowParameters + { + public List Text { get; set; } = new(); + public string Style { get; set; } = string.Empty; + public PdfParagraphAlignmentType ParagraphAlignment { get; set; } + } +} diff --git a/Diner/DineryBusinessLogic/OfficePackage/HelperModels/WordInfo.cs b/Diner/DineryBusinessLogic/OfficePackage/HelperModels/WordInfo.cs new file mode 100644 index 0000000..cb39efa --- /dev/null +++ b/Diner/DineryBusinessLogic/OfficePackage/HelperModels/WordInfo.cs @@ -0,0 +1,16 @@ +using DinerContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DineryBusinessLogic.OfficePackage.HelperModels +{ + public class WordInfo + { + public string FileName { get; set; } = string.Empty; + public string Title { get; set; } = string.Empty; + public List Components { get; set; } = new(); + } +} diff --git a/Diner/DineryBusinessLogic/OfficePackage/HelperModels/WordParagraph.cs b/Diner/DineryBusinessLogic/OfficePackage/HelperModels/WordParagraph.cs new file mode 100644 index 0000000..dc10037 --- /dev/null +++ b/Diner/DineryBusinessLogic/OfficePackage/HelperModels/WordParagraph.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DineryBusinessLogic.OfficePackage.HelperModels +{ + public class WordParagraph + { + public List<(string, WordTextProperties)> Texts { get; set; } = new(); + public WordTextProperties? TextProperties { get; set; } + } +} diff --git a/Diner/DineryBusinessLogic/OfficePackage/HelperModels/WordTextProperties.cs b/Diner/DineryBusinessLogic/OfficePackage/HelperModels/WordTextProperties.cs new file mode 100644 index 0000000..64e00bb --- /dev/null +++ b/Diner/DineryBusinessLogic/OfficePackage/HelperModels/WordTextProperties.cs @@ -0,0 +1,16 @@ +using DineryBusinessLogic.OfficePackage.HelperEnums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DineryBusinessLogic.OfficePackage.HelperModels +{ + public class WordTextProperties + { + public string Size { get; set; } = string.Empty; + public bool Bold { get; set; } + public WordJustificationType JustificationType { get; set; } + } +} From e86d28879b1948025092d2d853a4a07bdf43198e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=98=D0=BB=D1=8C=D1=8F=20=D0=A4=D0=B5=D0=B4=D0=BE=D1=82?= =?UTF-8?q?=D0=BE=D0=B2?= Date: Thu, 4 Apr 2024 22:51:48 +0400 Subject: [PATCH 2/2] Base.02 --- .../DineryBusinessLogic.csproj | 1 + .../OfficePackage/AbstractSaveToPdf.cs | 65 +++++++++ .../OfficePackage/Implements/SaveToExcel.cs | 131 ++++++++++++++++++ .../OfficePackage/Implements/SaveToWord.cs | 108 +++++++++++++++ 4 files changed, 305 insertions(+) create mode 100644 Diner/DineryBusinessLogic/OfficePackage/AbstractSaveToPdf.cs create mode 100644 Diner/DineryBusinessLogic/OfficePackage/Implements/SaveToExcel.cs create mode 100644 Diner/DineryBusinessLogic/OfficePackage/Implements/SaveToWord.cs diff --git a/Diner/DineryBusinessLogic/DineryBusinessLogic.csproj b/Diner/DineryBusinessLogic/DineryBusinessLogic.csproj index 6c5b7ff..6b910ea 100644 --- a/Diner/DineryBusinessLogic/DineryBusinessLogic.csproj +++ b/Diner/DineryBusinessLogic/DineryBusinessLogic.csproj @@ -7,6 +7,7 @@ + diff --git a/Diner/DineryBusinessLogic/OfficePackage/AbstractSaveToPdf.cs b/Diner/DineryBusinessLogic/OfficePackage/AbstractSaveToPdf.cs new file mode 100644 index 0000000..a5ff7c4 --- /dev/null +++ b/Diner/DineryBusinessLogic/OfficePackage/AbstractSaveToPdf.cs @@ -0,0 +1,65 @@ +using DineryBusinessLogic.OfficePackage.HelperEnums; +using DineryBusinessLogic.OfficePackage.HelperModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection.Emit; +using System.Text; +using System.Threading.Tasks; + +namespace DineryBusinessLogic.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 = $"c {info.DateFrom.ToShortDateString()} по {info.DateTo.ToShortDateString()}", + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Right + }); + CreateTable(new List { "2cm", "3cm", "6cm", "3cm" }); + CreateRow(new PdfRowParameters + { + Text = new List { "Номер", "Дата заказа", "Изделие", "Сумма" }, + Style = "NormalTittle", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + + foreach (var order in info.Orders) { + CreateRow(new PdfRowParameters + { + Text = new List { order.ID.ToString(), order.DateCreate.ToShortTimeString(), + order.ProductName, 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/Diner/DineryBusinessLogic/OfficePackage/Implements/SaveToExcel.cs b/Diner/DineryBusinessLogic/OfficePackage/Implements/SaveToExcel.cs new file mode 100644 index 0000000..9673131 --- /dev/null +++ b/Diner/DineryBusinessLogic/OfficePackage/Implements/SaveToExcel.cs @@ -0,0 +1,131 @@ +using DineryBusinessLogic.OfficePackage.HelperModels; +using DocumentFormat.OpenXml.Packaging; +using DocumentFormat.OpenXml.Spreadsheet; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DineryBusinessLogic.OfficePackage.Implements +{ + internal class SaveToExcel : AbstractSaveToExcel + { + private SpreadsheetDocument? _spreadsheetDocument; + private SharedStringTablePart? _shareStringPart; + private Worksheet? worksheet; + + private static void CreateStyles(WorksheetPart worksheetpart) { + var sp = worksheetpart.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 fontTittle = new Font(); + fontTittle.Append(new Bold()); + fontTittle.Append(new FontSize() { Val = 14D }); + fontTittle.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Theme = 1U }); + fontTittle.Append(new FontName() { Val = "Times New Roman" }); + fontTittle.Append(new FontFamilyNumbering() { Val = 2 }); + fontTittle.Append(new FontScheme() { Val = FontSchemeValues.Minor }); + fonts.Append(fontUsual); + fonts.Append(fontTittle); + 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 = 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 cellFormat = 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 = 0U, + FillId = 1U, + BorderId = 0U, + FormatId = 0U, + Alignment = new Alignment() + { + Vertical = VerticalAlignmentValues.Center, + WrapText = true, + Horizontal = HorizontalAlignmentValues.Center + }, + ApplyFont = true, + }; + cellFormat.Append(cellFormatFont); + cellFormat.Append(cellFormatFontAndBorder); + cellFormat.Append(cellFormatTitle); + } + + protected override void CreateExcel(ExcelInfo info) + { + throw new NotImplementedException(); + } + + protected override void InsertCellInWorksheet(ExcelCellParameters excelParameters) + { + throw new NotImplementedException(); + } + + protected override void MergeCells(ExcelMergeParameters mergeParams) + { + throw new NotImplementedException(); + } + + protected override void SaveExcel(ExcelInfo info) + { + throw new NotImplementedException(); + } + } +} diff --git a/Diner/DineryBusinessLogic/OfficePackage/Implements/SaveToWord.cs b/Diner/DineryBusinessLogic/OfficePackage/Implements/SaveToWord.cs new file mode 100644 index 0000000..2c0b897 --- /dev/null +++ b/Diner/DineryBusinessLogic/OfficePackage/Implements/SaveToWord.cs @@ -0,0 +1,108 @@ +using DineryBusinessLogic.OfficePackage.HelperEnums; +using DineryBusinessLogic.OfficePackage.HelperModels; +using DocumentFormat.OpenXml; +using DocumentFormat.OpenXml.ExtendedProperties; +using DocumentFormat.OpenXml.Packaging; +using DocumentFormat.OpenXml.Wordprocessing; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DineryBusinessLogic.OfficePackage.Implements +{ + public class SaveToWord : AbstractSaveToWord + { + 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 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 CreateWord(WordInfo 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 SaveWord(WordInfo info) + { + if (_docBody == null || _wordDocument == null) { + return; + } + _docBody.AppendChild(CreateSectionProperties()); + _wordDocument.MainDocumentPart!.Document.Save(); + _wordDocument.Clone(); + } + } +}