PIbd-21_MasenkinMS_Aircraft.../AircraftPlant/AircraftPlantBusinessLogic/OfficePackage/AbstractSaveToWord.cs

132 lines
4.4 KiB
C#
Raw Normal View History

2024-03-25 00:53:24 +04:00
using AircraftPlantBusinessLogic.OfficePackage.HelperEnums;
using AircraftPlantBusinessLogic.OfficePackage.HelperModels;
2024-04-08 00:02:59 +04:00
using DocumentFormat.OpenXml.Wordprocessing;
2024-03-25 00:53:24 +04:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AircraftPlantBusinessLogic.OfficePackage
{
/// <summary>
/// Абстрактный класс для сохранения Word-файла
/// </summary>
public abstract class AbstractSaveToWord
{
/// <summary>
/// Создание отчета в Word-формате
/// </summary>
/// <param name="info"></param>
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 plane in info.Planes)
{
CreateParagraph(new WordParagraph
{
Texts = new List<(string, WordTextProperties)>
{
(plane.PlaneName, new WordTextProperties { Size = "24", Bold = true}),
("\t" + plane.Price.ToString(), new WordTextProperties{Size = "24"})
},
TextProperties = new WordTextProperties
{
Size = "24",
JustificationType = WordJustificationType.Both
}
});
}
SaveWord(info);
}
2024-04-08 00:02:59 +04:00
/// <summary>
/// Создание отчета по магазинам в doc-формате
/// </summary>
/// <param name="info"></param>
public void CreateShopsDoc(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
}
});
CreateTable(new List<string> { "3000", "3000", "3000" });
CreateRow(new WordRow
{
Texts = new List<string> { "Название", "Адрес", "Дата открытия" },
TextProperties = new WordTextProperties
{
Size = "24",
Bold = true,
JustificationType = WordJustificationType.Center
}
});
foreach (var shop in info.Shops)
{
CreateRow(new WordRow
{
Texts = new List<string> { shop.ShopName, shop.Address, shop.DateOpening.ToString() },
TextProperties = new WordTextProperties
{
Size = "22",
JustificationType = WordJustificationType.Both
}
});
}
SaveWord(info);
}
2024-03-25 00:53:24 +04:00
/// <summary>
/// Создание doc-файла
/// </summary>
/// <param name="info"></param>
protected abstract void CreateWord(WordInfo info);
/// <summary>
/// Создание абзаца с текстом
/// </summary>
/// <param name="paragraph"></param>
protected abstract void CreateParagraph(WordParagraph paragraph);
2024-04-08 00:02:59 +04:00
/// <summary>
/// Создание таблицы
/// </summary>
/// <param name="columns"></param>
protected abstract void CreateTable(List<string> columns);
/// <summary>
/// Создание строки
/// </summary>
/// <param name="row"></param>
protected abstract void CreateRow(WordRow row);
2024-03-25 00:53:24 +04:00
/// <summary>
/// Сохранение файла
/// </summary>
/// <param name="info"></param>
protected abstract void SaveWord(WordInfo info);
}
}