80 lines
2.9 KiB
C#
Raw Normal View History

2023-04-11 11:12:55 +04:00
using DocumentFormat.OpenXml.Wordprocessing;
2023-04-11 08:33:53 +04:00
using SushiBarBusinessLogic.OfficePackage.HelpersEnum;
2023-03-12 20:49:40 +04:00
using SushiBarBusinessLogic.OfficePackage.HelpersModels;
2023-04-11 08:33:53 +04:00
namespace SushiBarBusinessLogic.OfficePackage;
public abstract class AbstractSaveToWord
2023-03-12 20:49:40 +04:00
{
2023-04-11 11:12:55 +04:00
public void CreateTableDoc(WordInfo info)
2023-03-12 20:49:40 +04:00
{
2023-04-11 08:33:53 +04:00
CreateWord(info);
2023-04-11 11:12:55 +04:00
CreateParagraph(new WordParagraph
{
Texts = new List<(string, WordTextProperties)> { (info.Title, new WordTextProperties { Bold = true, Size = "24", }) },
TextProperties = new WordTextProperties
{
Size = "24",
JustificationType = WordJustificationType.Center
}
});
2023-03-12 20:49:40 +04:00
2023-04-11 08:33:53 +04:00
var rows = info.Stores
.Select(store => CreateRow(
2023-04-11 11:12:55 +04:00
new()
2023-04-11 08:33:53 +04:00
{
CreateCell(new WordCell { Text = store.StoreName }),
CreateCell(new WordCell { Text = store.StoreAddress }),
2023-04-11 11:12:55 +04:00
CreateCell(new WordCell { Text = store.OpeningDate.ToShortDateString()})
2023-04-11 08:33:53 +04:00
})).ToList();
2023-04-11 11:12:55 +04:00
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 }),
}));
2023-03-12 20:49:40 +04:00
2023-04-11 08:33:53 +04:00
CreateTable(rows);
SaveWord(info);
2023-03-12 20:49:40 +04:00
}
2023-04-11 08:33:53 +04:00
2023-04-11 11:12:55 +04:00
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);
}
2023-04-11 08:33:53 +04:00
protected abstract void CreateWord(WordInfo info);
protected abstract void CreateParagraph(WordParagraph? paragraph);
protected abstract void SaveWord(WordInfo info);
2023-04-11 11:12:55 +04:00
protected abstract void CreateTable(List<TableRow> rows);
protected abstract TableRow CreateRow(List<TableCell> cells);
protected abstract TableCell CreateCell(WordCell cell);
2023-04-11 08:33:53 +04:00
}