2023-04-11 11:12:55 +04:00

80 lines
2.9 KiB
C#

using DocumentFormat.OpenXml.Wordprocessing;
using SushiBarBusinessLogic.OfficePackage.HelpersEnum;
using SushiBarBusinessLogic.OfficePackage.HelpersModels;
namespace SushiBarBusinessLogic.OfficePackage;
public abstract class AbstractSaveToWord
{
public void CreateTableDoc(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
}
});
var rows = info.Stores
.Select(store => CreateRow(
new()
{
CreateCell(new WordCell { Text = store.StoreName }),
CreateCell(new WordCell { Text = store.StoreAddress }),
CreateCell(new WordCell { Text = store.OpeningDate.ToShortDateString()})
})).ToList();
rows.Insert(0, CreateRow(new ()
{
CreateCell(new WordCell{ Text = "Store name", Width = 3000 }),
CreateCell(new WordCell{ Text = "Store Address", Width = 2000 }),
CreateCell(new WordCell{ Text = "Opening Date", Width = 3000 }),
}));
CreateTable(rows);
SaveWord(info);
}
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 sushi in info.Sushi)
{
CreateParagraph(new WordParagraph
{
Texts = new List<(string, WordTextProperties)> {
(sushi.SushiName, new WordTextProperties { Bold = true, Size = "24" }),
($" {sushi.Price}", new WordTextProperties { Size = "24", JustificationType = WordJustificationType.Right }) },
TextProperties = new WordTextProperties
{
Size = "24",
JustificationType = WordJustificationType.Both
}
});
}
SaveWord(info);
}
protected abstract void CreateWord(WordInfo info);
protected abstract void CreateParagraph(WordParagraph? paragraph);
protected abstract void SaveWord(WordInfo info);
protected abstract void CreateTable(List<TableRow> rows);
protected abstract TableRow CreateRow(List<TableCell> cells);
protected abstract TableCell CreateCell(WordCell cell);
}