diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BlacksmithWorkshopBusinessLogic.csproj b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BlacksmithWorkshopBusinessLogic.csproj index 11e5aef..36c88e5 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BlacksmithWorkshopBusinessLogic.csproj +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/BlacksmithWorkshopBusinessLogic.csproj @@ -15,7 +15,6 @@ - diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/AbstractSaveToExcel.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/AbstractSaveToExcel.cs new file mode 100644 index 0000000..272f95e --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/AbstractSaveToExcel.cs @@ -0,0 +1,176 @@ +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.ManufactureName, + StyleInfo = ExcelStyleInfoType.Text + }); + + rowIndex++; + + foreach (var (WorkPiece, Count) in mwp.WorkPieces) + { + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "B", + RowIndex = rowIndex, + Text = WorkPiece, + 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.Text + }); + + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "C", + RowIndex = rowIndex, + Text = mwp.TotalCount.ToString(), + StyleInfo = ExcelStyleInfoType.Text + }); + + rowIndex++; + } + + SaveExcel(info); + } + + public void CreateShopReport(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 sm in info.ShopManufactures) + { + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "A", + RowIndex = rowIndex, + Text = sm.ShopName, + StyleInfo = ExcelStyleInfoType.Text + }); + + rowIndex++; + + foreach (var (Manufacture, Count) in sm.Manufactures) + { + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "B", + RowIndex = rowIndex, + Text = Manufacture, + 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.Text + }); + + InsertCellInWorksheet(new ExcelCellParameters + { + ColumnName = "C", + RowIndex = rowIndex, + Text = sm.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..0bc6496 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/AbstractSaveToPdf.cs @@ -0,0 +1,90 @@ +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", "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.OrderStatus, order.Sum.ToString() }, + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Left + }); + } + + CreateParagraph(new PdfParagraph { Text = $"Итого: {info.Orders.Sum(x => x.Sum)}\t", Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Rigth }); + + SavePdf(info); + } + + public void CreateGroupedDoc(PdfInfo info) + { + CreatePdf(info); + + CreateParagraph(new PdfParagraph { Text = info.Title, Style = "NormalTitle", ParagraphAlignment = PdfParagraphAlignmentType.Center }); + + CreateTable(new List { "3cm", "3cm", "3cm" }); + + CreateRow(new PdfRowParameters + { + Texts = new List { "Дата заказа", "Количество заказов", "Сумма" }, + Style = "NormalTitle", + ParagraphAlignment = PdfParagraphAlignmentType.Center + }); + + foreach (var order in info.GroupedOrders) + { + CreateRow(new PdfRowParameters + { + Texts = new List { order.DateCreate.ToShortDateString(), order.Count.ToString(), order.Sum.ToString() }, + Style = "Normal", + ParagraphAlignment = PdfParagraphAlignmentType.Left + }); + } + + CreateParagraph(new PdfParagraph { Text = $"Итого: {info.GroupedOrders.Sum(x => x.Sum)}\t", Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Center }); + + 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..02e0714 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/AbstractSaveToWord.cs @@ -0,0 +1,105 @@ +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 manufacture in info.Manufactures) + { + CreateParagraph(new WordParagraph + { + Texts = new List<(string, WordTextProperties)> { (manufacture.ManufactureName + " ", new WordTextProperties { Bold = true, Size = "24" }), + (manufacture.Price.ToString(), new WordTextProperties { Size = "24" }) }, + TextProperties = new WordTextProperties + { + Size = "24", + JustificationType = WordJustificationType.Both + } + }); + } + + SaveWord(info); + } + + public void CreateTable(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 + } + }); + + List> rowList = new() + { + new() + { + new("Название", new WordTextProperties { Bold = true, Size = "24" } ), + new("Адрес", new WordTextProperties { Bold = true, Size = "24" } ), + new("Дата открытия", new WordTextProperties { Bold = true, Size = "24" } ) + } + }; + + foreach (var shop in info.Shops) + { + List<(string, WordTextProperties)> cellList = new() + { + new(shop.ShopName, new WordTextProperties { Size = "24" }), + new(shop.Address, new WordTextProperties { Size = "24" }), + new(shop.DateOpen.ToShortDateString(), new WordTextProperties { Size = "24"}) + }; + + rowList.Add(cellList); + } + + CreateTable(new WordParagraph + { + RowTexts = rowList, + TextProperties = new WordTextProperties + { + Size = "24", + JustificationType = WordJustificationType.Center + } + }); + + SaveWord(info); + } + + //Создание doc-файла + protected abstract void CreateWord(WordInfo info); + + //Создание абзаца с текстом + protected abstract void CreateParagraph(WordParagraph paragraph); + + //Создание таблицы + protected abstract void CreateTable(WordParagraph paragraph); + + //Сохранение файла + protected abstract void SaveWord(WordInfo info); + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/ExcelCellParameters.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/ExcelCellParameters.cs new file mode 100644 index 0000000..799d817 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/ExcelCellParameters.cs @@ -0,0 +1,22 @@ +using BlacksmithWorkshopBusinessLogic.OfficePackage.HelperEnums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopBusinessLogic.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/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs new file mode 100644 index 0000000..012b968 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs @@ -0,0 +1,28 @@ +using BlacksmithWorkshopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopBusinessLogic.OfficePackage.HelperModels +{ + public class ExcelInfo + { + public string FileName { get; set; } = string.Empty; + + public string Title { get; set; } = string.Empty; + + public List ManufactureWorkPieces + { + get; + set; + } = new(); + + public List ShopManufactures + { + get; + set; + } = new(); + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/ExcelMergeParameters.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/ExcelMergeParameters.cs new file mode 100644 index 0000000..18491b8 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/ExcelMergeParameters.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopBusinessLogic.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/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs new file mode 100644 index 0000000..be3141c --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs @@ -0,0 +1,24 @@ +using BlacksmithWorkshopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopBusinessLogic.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(); + + public List GroupedOrders { get; set; } = new(); + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/PdfParagraph.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/PdfParagraph.cs new file mode 100644 index 0000000..a682e9d --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/PdfParagraph.cs @@ -0,0 +1,18 @@ +using BlacksmithWorkshopBusinessLogic.OfficePackage.HelperEnums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopBusinessLogic.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/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/PdfRowParameters.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/PdfRowParameters.cs new file mode 100644 index 0000000..0bb8d72 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/PdfRowParameters.cs @@ -0,0 +1,18 @@ +using BlacksmithWorkshopBusinessLogic.OfficePackage.HelperEnums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopBusinessLogic.OfficePackage.HelperModels +{ + public class PdfRowParameters + { + public List Texts { get; set; } = new(); + + public string Style { get; set; } = string.Empty; + + public PdfParagraphAlignmentType ParagraphAlignment { get; set; } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/WordInfo.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/WordInfo.cs new file mode 100644 index 0000000..d4245c0 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/WordInfo.cs @@ -0,0 +1,20 @@ +using BlacksmithWorkshopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopBusinessLogic.OfficePackage.HelperModels +{ + public class WordInfo + { + public string FileName { get; set; } = string.Empty; + + public string Title { get; set; } = string.Empty; + + public List Manufactures { get; set; } = new(); + + public List Shops { get; set; } = new(); + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/WordParagraph.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/WordParagraph.cs new file mode 100644 index 0000000..37838e9 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/WordParagraph.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopBusinessLogic.OfficePackage.HelperModels +{ + public class WordParagraph + { + public List<(string, WordTextProperties)> Texts { get; set; } = new(); + + public WordTextProperties? TextProperties { get; set; } + + public List> RowTexts { get; set; } = new(); + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/WordTextProperties.cs b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/WordTextProperties.cs new file mode 100644 index 0000000..5ba1dbd --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopBusinessLogic/OfficePackage/HelperModels/WordTextProperties.cs @@ -0,0 +1,18 @@ +using BlacksmithWorkshopBusinessLogic.OfficePackage.HelperEnums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BlacksmithWorkshopBusinessLogic.OfficePackage.HelperModels +{ + public class WordTextProperties + { + public string Size { get; set; } = string.Empty; + + public bool Bold { get; set; } + + public WordJustificationType JustificationType { get; set; } + } +}