diff --git a/FurnitureFactory/FurnitureContracts/ViewModel/ReportSalesSalonViewModel.cs b/FurnitureFactory/FurnitureContracts/ViewModel/ReportSalesSalonViewModel.cs index 2e60cdc..fff3c88 100644 --- a/FurnitureFactory/FurnitureContracts/ViewModel/ReportSalesSalonViewModel.cs +++ b/FurnitureFactory/FurnitureContracts/ViewModel/ReportSalesSalonViewModel.cs @@ -8,9 +8,9 @@ namespace FurnitureContracts.ViewModel { public class ReportSalesSalonViewModel { - public string SalesSalpnTitle { get; set; } = string.Empty; + public string SalesSalonTitle { get; set; } = string.Empty; public string OrderTitle { get; set; } = string.Empty; - public DateTime Date { get; set; } + public DateTime DateCreateOrder { get; set; } public string HeadsetTitle { get; set; } = string.Empty; } } diff --git a/FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/AbstractSaveToExcelManager.cs b/FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/AbstractSaveToExcelManager.cs new file mode 100644 index 0000000..27cc194 --- /dev/null +++ b/FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/AbstractSaveToExcelManager.cs @@ -0,0 +1,89 @@ +using FurnitureFactoryBusinessLogic.OfficePackage.HelperEnums; +using FurnitureFactoryBusinessLogic.OfficePackage.HelperModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureFactoryBusinessLogic.OfficePackage +{ + public abstract class AbstractSaveToExcelManager + { + public void CreateReport(ExcelInfoManager 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.SalesSalonsFurniture) + { + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "A", + RowIndex = rowIndex, + Text = pc.Name, + StyleInfo = ExcelStyleInfoType.Text + }); + rowIndex++; + + foreach (var furniture in pc.Furniture) + { + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "B", + RowIndex = rowIndex, + Text = furniture, + StyleInfo = ExcelStyleInfoType.TextWithBroder + }); + + + + rowIndex++; + } + + + rowIndex++; + } + + SaveExcel(info); + } + + /// + /// Создание excel-файла + /// + /// + protected abstract void CreateExcel(ExcelInfoManager info); + + /// + /// Добавляем новую ячейку в лист + /// + /// + protected abstract void InsertCellInWorksheet(ExcelCellParameters excelParams); + + /// + /// Объединение ячеек + /// + /// + protected abstract void MergeCells(ExcelMergeParameters excelParams); + + /// + /// Сохранение файла + /// + /// + protected abstract void SaveExcel(ExcelInfoManager info); + } +} diff --git a/FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/Implements/AbstractSaveToPdfManager.cs b/FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/AbstractSaveToPdfManager.cs similarity index 73% rename from FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/Implements/AbstractSaveToPdfManager.cs rename to FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/AbstractSaveToPdfManager.cs index 8588319..7c6a9d7 100644 --- a/FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/Implements/AbstractSaveToPdfManager.cs +++ b/FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/AbstractSaveToPdfManager.cs @@ -4,24 +4,23 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -using FurnitureFactoryBusinessLogic.OfficePackage.HelperEnums; using FurnitureFactoryBusinessLogic.OfficePackage.HelperModels; namespace FurnitureFactoryBusinessLogic.OfficePackage.Implements { - internal class AbstractSaveToPdfManager + public abstract class AbstractSaveToPdfManager { public void CreateDoc(PdfInfoManager 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 }); + 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 { "Интерес", "Изделие", "Дата", "Поделка", "Дата" }, + Texts = new List { "Салоны продаж", "Заказы", "Дата", "Гарнитур" }, Style = "NormalTitle", ParagraphAlignment = PdfParagraphAlignmentType.Center }); @@ -30,7 +29,7 @@ namespace FurnitureFactoryBusinessLogic.OfficePackage.Implements { CreateRow(new PdfRowParameters { - Texts = new List { interest.InterestTitle, interest.ProductTitle, interest.DateCreateProduct.ToShortDateString(), interest.DiyTitle, interest.DateCreateDiy.ToShortDateString() }, + Texts = new List { interest.SalesSalonTitle, interest.OrderTitle, interest.DateCreateOrder.ToShortDateString(), interest.HeadsetTitle }, Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Left }); @@ -44,7 +43,7 @@ namespace FurnitureFactoryBusinessLogic.OfficePackage.Implements /// Создание doc-файла /// /// - protected abstract void CreatePdf(PdfInfoStudent info); + protected abstract void CreatePdf(PdfInfoManager info); /// /// Создание параграфа с текстом @@ -70,6 +69,6 @@ namespace FurnitureFactoryBusinessLogic.OfficePackage.Implements /// Сохранение файла /// /// - protected abstract void SavePdf(PdfInfoStudent info); + protected abstract void SavePdf(PdfInfoManager info); } } diff --git a/FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/AbstractSaveToWordManager.cs b/FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/AbstractSaveToWordManager.cs new file mode 100644 index 0000000..7afaa1b --- /dev/null +++ b/FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/AbstractSaveToWordManager.cs @@ -0,0 +1,76 @@ +using FurnitureFactoryBusinessLogic.OfficePackage.HelperEnums; +using FurnitureFactoryBusinessLogic.OfficePackage.HelperModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureFactoryBusinessLogic.OfficePackage +{ + public abstract class AbstractSaveToWordManager + { + public void CreateDoc(WordInfoManager 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.SalesSalonsFurniture) + { + CreateParagraph(new WordParagraph + { + Texts = new List<(string, WordTextProperties)> { (interest.Name, new WordTextProperties { Size = "24", Bold = true, }) }, + TextProperties = new WordTextProperties + { + Size = "24", + JustificationType = WordJustificationType.Both + } + }); + foreach (var lesson in interest.Furniture) + { + 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(WordInfoManager info); + + /// + /// Создание абзаца с текстом + /// + /// + /// + protected abstract void CreateParagraph(WordParagraph paragraph); + + /// + /// Сохранение файла + /// + /// + protected abstract void SaveWord(WordInfoManager info); + + } +} diff --git a/FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/HelperModels/ExcelCellParameters.cs b/FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/HelperModels/ExcelCellParameters.cs index 7d55216..d8316c3 100644 --- a/FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/HelperModels/ExcelCellParameters.cs +++ b/FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/HelperModels/ExcelCellParameters.cs @@ -8,7 +8,7 @@ using FurnitureFactoryBusinessLogic.OfficePackage.HelperEnums; namespace FurnitureFactoryBusinessLogic.OfficePackage.HelperModels { - internal class ExcelCellParameters + public class ExcelCellParameters { public string ColumnName { get; set; } = string.Empty; diff --git a/FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/HelperModels/ExcelInfoManager.cs b/FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/HelperModels/ExcelInfoManager.cs index dd7a952..4ac90a4 100644 --- a/FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/HelperModels/ExcelInfoManager.cs +++ b/FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/HelperModels/ExcelInfoManager.cs @@ -11,7 +11,7 @@ using System.ComponentModel; namespace FurnitureFactoryBusinessLogic.OfficePackage.HelperModels { - internal class ExcelInfoManager + public class ExcelInfoManager { public string FileName { get; set; } = string.Empty; diff --git a/FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/HelperModels/ExcelMergeParameters.cs b/FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/HelperModels/ExcelMergeParameters.cs index cf2a426..92fe18f 100644 --- a/FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/HelperModels/ExcelMergeParameters.cs +++ b/FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/HelperModels/ExcelMergeParameters.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace FurnitureFactoryBusinessLogic.OfficePackage.HelperEnums { - internal class ExcelMergeParameters + public class ExcelMergeParameters { public string CellFromName { get; set; } = string.Empty; diff --git a/FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/HelperModels/WordInfoManager.cs b/FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/HelperModels/WordInfoManager.cs index cbdb111..fa15674 100644 --- a/FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/HelperModels/WordInfoManager.cs +++ b/FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/HelperModels/WordInfoManager.cs @@ -7,7 +7,7 @@ using FurnitureContracts.ViewModel; namespace FurnitureFactoryBusinessLogic.OfficePackage.HelperModels { - internal class WordInfoManager + public class WordInfoManager { public string FileName { get; set; } = string.Empty; diff --git a/FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/HelperModels/WordTextProperties.cs b/FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/HelperModels/WordTextProperties.cs index aa793b0..62a2987 100644 --- a/FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/HelperModels/WordTextProperties.cs +++ b/FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/HelperModels/WordTextProperties.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; namespace FurnitureFactoryBusinessLogic.OfficePackage.HelperModels { - internal class WordTextProperties + public class WordTextProperties { public string Size { get; set; } = string.Empty; diff --git a/FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/Implements/SaveToExcelManager.cs b/FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/Implements/SaveToExcelManager.cs index 0a83c18..be28ea4 100644 --- a/FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/Implements/SaveToExcelManager.cs +++ b/FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/Implements/SaveToExcelManager.cs @@ -10,7 +10,7 @@ using DocumentFormat.OpenXml.Spreadsheet; namespace FurnitureFactoryBusinessLogic.OfficePackage.Implements { - internal class SaveToExcelManager + public class SaveToExcelManager { private SpreadsheetDocument? _spreadsheetDocument; @@ -152,7 +152,7 @@ namespace FurnitureFactoryBusinessLogic.OfficePackage.Implements }; } - protected override void CreateExcel(ExcelInfoStudent info) + protected override void CreateExcel(ExcelInfoManager info) { _spreadsheetDocument = SpreadsheetDocument.Create(info.FileName, SpreadsheetDocumentType.Workbook); diff --git a/FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/Implements/SaveToPdfManager.cs b/FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/Implements/SaveToPdfManager.cs new file mode 100644 index 0000000..cb60f39 --- /dev/null +++ b/FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/Implements/SaveToPdfManager.cs @@ -0,0 +1,124 @@ +using FurnitureFactoryBusinessLogic.OfficePackage.HelperEnums; +using MigraDoc.DocumentObjectModel; +using MigraDoc.Rendering; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using FurnitureFactoryBusinessLogic.OfficePackage.HelperModels; +using static System.Net.Mime.MediaTypeNames; +using DocumentFormat.OpenXml; +using DocumentFormat.OpenXml.Office2010.Excel; +using DocumentFormat.OpenXml.Office2013.Excel; +using DocumentFormat.OpenXml.Packaging; +using DocumentFormat.OpenXml.Spreadsheet; + +namespace FurnitureFactoryBusinessLogic.OfficePackage.Implements +{ + internal class SaveToPdfManager + { + 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(PdfInfoManager 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(PdfInfoManager info) + { + var renderer = new PdfDocumentRenderer(true) + { + Document = _document + }; + renderer.RenderDocument(); + renderer.PdfDocument.Save(info.FileName); + } + } +} diff --git a/FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/Implements/SaveToWordManager.cs b/FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/Implements/SaveToWordManager.cs new file mode 100644 index 0000000..4e6b12c --- /dev/null +++ b/FurnitureFactory/FurnitureFactoryBusinessLogic/OfficePackage/Implements/SaveToWordManager.cs @@ -0,0 +1,140 @@ +using DocumentFormat.OpenXml.Packaging; +using DocumentFormat.OpenXml.Wordprocessing; +using DocumentFormat.OpenXml; +using FurnitureFactoryBusinessLogic.OfficePackage.HelperEnums; +using FurnitureFactoryBusinessLogic.OfficePackage.HelperModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureFactoryBusinessLogic.OfficePackage.Implements +{ + public class SaveToWordManager + { + 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(WordInfoManager 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(WordInfoManager info) + { + if (_docBody == null || _wordDocument == null) + { + return; + } + _docBody.AppendChild(CreateSectionProperties()); + + _wordDocument.MainDocumentPart!.Document.Save(); + + _wordDocument.Close(); + } + } +}