PIbd-21_BatylkinaAO_MusoevD.../Canteen/CanteenBusinessLogic/OfficePackage/AbstractSaveToWord.cs

147 lines
5.9 KiB
C#
Raw Normal View History

2023-05-20 12:11:48 +04:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CanteenBusinessLogic.OfficePackage.HelperEnums;
using CanteenBusinessLogic.OfficePackage.HelperModels;
2023-06-19 09:12:18 +04:00
using DocumentFormat.OpenXml.EMMA;
2023-05-20 12:11:48 +04:00
namespace CanteenBusinessLogic.OfficePackage
{
public abstract class AbstractSaveToWord
{
2023-06-22 02:38:03 +04:00
public byte[] CreateCooksDoc(WordInfo info)
2023-05-20 12:11:48 +04:00
{
CreateWord(info);
CreateParagraph(new WordParagraph
{
2023-06-14 22:47:30 +04:00
Texts = new List<(string, WordTextProperties)> { (info.Title, new WordTextProperties { Bold = true, Size = "24" }) },
2023-05-20 12:11:48 +04:00
TextProperties = new WordTextProperties
{
Size = "24",
JustificationType = WordJustificationType.Center
}
});
2023-06-14 22:47:30 +04:00
foreach (var reportCookView in info.Cooks)
2023-05-20 12:11:48 +04:00
{
CreateParagraph(new WordParagraph
{
2023-06-14 22:47:30 +04:00
Texts = new List<(string, WordTextProperties)>
{
("Обед: ", new WordTextProperties { Bold = true, Size = "24" }),
(reportCookView.Lunch.LunchName, new WordTextProperties { Bold = false, Size = "24" }),
(" Дата создания: ", new WordTextProperties { Bold = true, Size = "24" }),
(reportCookView.Lunch.DateCreate.ToString(), new WordTextProperties { Bold = false, Size = "24" })
},
TextProperties = new WordTextProperties
{
Size = "24",
JustificationType = WordJustificationType.Both
}
});
CreateParagraph(new WordParagraph
{
Texts = new List<(string, WordTextProperties)>
{
("Повара: ", new WordTextProperties { Bold = true, Size = "24" })
},
2023-05-20 12:11:48 +04:00
TextProperties = new WordTextProperties
{
Size = "24",
JustificationType = WordJustificationType.Both
}
});
2023-06-14 22:47:30 +04:00
foreach (var cook in reportCookView.Cooks)
{
CreateParagraph(new WordParagraph
{
Texts = new List<(string, WordTextProperties)>
{
(cook.FIO, new WordTextProperties { Bold = false, Size = "24" })
},
TextProperties = new WordTextProperties
{
Size = "24",
JustificationType = WordJustificationType.Both
}
});
}
2023-05-20 12:11:48 +04:00
}
2023-06-22 02:38:03 +04:00
return GetFile();
2023-05-20 12:11:48 +04:00
}
2023-06-22 02:38:03 +04:00
public byte[] CreateOrdersDoc(WordInfo info)
2023-06-19 09:12:18 +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
}
});
foreach (var reportOrderView in info.Orders)
{
CreateParagraph(new WordParagraph
{
Texts = new List<(string, WordTextProperties)>
{
("Продукт: ", new WordTextProperties { Bold = true, Size = "24" }),
(reportOrderView.Product.Id.ToString(), new WordTextProperties { Bold = false, Size = "24" }),
("Название: ", new WordTextProperties { Bold = true, Size = "24" }),
(reportOrderView.Product.ProductName.ToString(), new WordTextProperties { Bold = false, Size = "24" })
},
TextProperties = new WordTextProperties
{
Size = "24",
JustificationType = WordJustificationType.Both
}
});
CreateParagraph(new WordParagraph
{
Texts = new List<(string, WordTextProperties)>
{
("Заказы: ", new WordTextProperties { Bold = true, Size = "24" })
},
TextProperties = new WordTextProperties
{
Size = "24",
JustificationType = WordJustificationType.Both
}
});
foreach (var order in reportOrderView.Orders)
{
CreateParagraph(new WordParagraph
{
Texts = new List<(string, WordTextProperties)>
{
("Заказ: ", new WordTextProperties { Bold = false, Size = "24" }),
(order.Id.ToString(), new WordTextProperties { Bold = false, Size = "24" })
},
TextProperties = new WordTextProperties
{
Size = "24",
JustificationType = WordJustificationType.Both
}
});
}
}
2023-06-14 22:47:30 +04:00
2023-06-22 02:38:03 +04:00
return GetFile();
2023-06-19 09:12:18 +04:00
}
2023-05-20 12:11:48 +04:00
protected abstract void CreateWord(WordInfo info);
protected abstract void CreateParagraph(WordParagraph paragraph);
2023-06-22 02:38:03 +04:00
protected abstract void SaveWord();
protected abstract byte[] GetFile();
2023-05-20 12:11:48 +04:00
}
}