ISEbd-21_Agliullov.D.A._Con.../ConfectionaryBusinessLogic/OfficePackage/AbstractSaveToWord.cs

106 lines
3.5 KiB
C#
Raw Normal View History

2023-03-01 16:42:58 +04:00
using ConfectioneryBusinessLogic.OfficePackage.HelperEnums;
using ConfectioneryBusinessLogic.OfficePackage.HelperModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConfectioneryBusinessLogic.OfficePackage
{
public abstract class AbstractSaveToWord
{
public void CreateDocTable(WordInfoTable info)
2023-03-01 16:42:58 +04:00
{
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
}
});
CreateTable(new()
2023-03-01 16:42:58 +04:00
{
("Название", 3000),
("Дата", null),
("Адрес открытия", 4500),
},
info.Shops
.Select(x => new List<string>
{
x.Name,
Convert.ToString(x.DateOpening),
x.Address,
})
.ToList());
2023-03-01 16:42:58 +04:00
SaveWord(info);
}
public void CreateDoc(WordInfo info)
{
CreateWord(new() { FileName = info.FileName });
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 pastry in info.Pastries)
{
CreateParagraph(new WordParagraph
{
Texts = new List<(string, WordTextProperties)>
{
(pastry.PastryName , new WordTextProperties { Size = "24", Bold = true}),
(" - цена: " + pastry.Price.ToString(), new WordTextProperties { Size = "24" })
},
TextProperties = new WordTextProperties
{
Size = "24",
JustificationType = WordJustificationType.Both
}
});
}
SaveWord(new());
}
2023-03-01 16:42:58 +04:00
/// <summary>
/// Создание doc-файла
/// </summary>
/// <param name="info"></param>
protected abstract void CreateWord(WordInfoTable info);
2023-03-01 16:42:58 +04:00
/// <summary>
/// Создание абзаца с текстом
/// </summary>
/// <param name="paragraph"></param>
/// <returns></returns>
protected abstract void CreateParagraph(WordParagraph paragraph);
/// <summary>
/// Создание таблицы в файле
/// </summary>
/// <param name="nameAndWidthColumns">Строчка заголовок таблицы, определяет текст и ширину каждого столбца</param>
/// <param name="rows">The rows.</param>
protected abstract void CreateTable(List<(string, int?)> nameAndWidthColumns, List<List<string>> rows);
2023-03-01 16:42:58 +04:00
/// <summary>
/// Сохранение файла
/// </summary>
/// <param name="info"></param>
protected abstract void SaveWord(WordInfoTable info);
2023-03-01 16:42:58 +04:00
}
}