ISEbd-21_Agliullov.D.A._Con.../ConfectionaryBusinessLogic/OfficePackage/AbstractSaveToWord.cs
2023-03-08 16:05:07 +04:00

106 lines
3.5 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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)
{
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()
{
("Название", 3000),
("Дата", null),
("Адрес открытия", 4500),
},
info.Shops
.Select(x => new List<string>
{
x.Name,
Convert.ToString(x.DateOpening),
x.Address,
})
.ToList());
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());
}
/// <summary>
/// Создание doc-файла
/// </summary>
/// <param name="info"></param>
protected abstract void CreateWord(WordInfoTable info);
/// <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);
/// <summary>
/// Сохранение файла
/// </summary>
/// <param name="info"></param>
protected abstract void SaveWord(WordInfoTable info);
}
}