Изменена логика получения списка Word

This commit is contained in:
prodigygirl 2023-03-26 09:42:14 +04:00
parent ca519fe8c8
commit fe89fc9399
5 changed files with 78 additions and 28 deletions

View File

@ -9,26 +9,46 @@ namespace FurnitureAssemblyBusinessLogic.OfficePackage
{ {
public void CreateTableDoc(WordInfo wordInfo) { public void CreateTableDoc(WordInfo wordInfo) {
CreateWord(wordInfo); CreateWord(wordInfo);
var list = new List<string>(); CreateParagraph(new WordParagraph
foreach (var shop in wordInfo.Shops) {
list.Add(shop.ShopName);
list.Add(shop.Address);
list.Add(shop.DateOpening.ToString());
}
//list.AddRange(wordInfo.Shops.Select(x => (x.ShopName, new WordTextProperties { Bold = true, Size = "24" })));
var wordTable = new WordTable
{ {
Headers = new List<string> { Texts = new List<(string, WordTextProperties)> { (wordInfo.Title, new WordTextProperties { Bold = true, Size = "24", }) },
"Название", TextProperties = new WordTextProperties
"Адрес", {
"Дата открытия"}, Size = "24",
Texts = list JustificationType = WordJustificationType.Center
}; }
});
WordTable wordTable = new();
if (wordInfo is WordInfoShops infoShops)
{
wordTable = CreateTableDocShops(infoShops);
}
CreateTable(wordTable); CreateTable(wordTable);
SaveWord(wordInfo); SaveWord(wordInfo);
} }
private WordTable CreateTableDocShops(WordInfoShops wordInfo)
{
var list = new List<string>();
foreach (var shop in wordInfo.Shops)
{
list.Add(shop.ShopName);
list.Add(shop.Address);
list.Add(shop.DateOpening.ToString());
}
var wordTable = new WordTable
{
Headers = new List<string> {
"Название",
"Адрес",
"Дата открытия"},
Texts = list
};
return wordTable;
}
public void CreateDoc(WordInfo info) public void CreateDoc(WordInfo info)
{ {
CreateWord(info); CreateWord(info);
@ -41,18 +61,22 @@ namespace FurnitureAssemblyBusinessLogic.OfficePackage
JustificationType = WordJustificationType.Center JustificationType = WordJustificationType.Center
} }
}); });
foreach (var furniture in info.Furnitures) if (info is WordInfoFurnitures infoFurnitures) {
{ foreach (var furniture in infoFurnitures.Furnitures)
CreateParagraph(new WordParagraph
{
Texts = new List<(string, WordTextProperties)> { (furniture.FurnitureName, new WordTextProperties { Size = "24", Bold=true}), (" - " + furniture.Price.ToString(), new WordTextProperties { Size = "24", }) },
TextProperties = new WordTextProperties
{ {
Size = "24", CreateParagraph(new WordParagraph
JustificationType = WordJustificationType.Both {
} Texts = new List<(string, WordTextProperties)> { (furniture.FurnitureName,
}); new WordTextProperties { Size = "24", Bold=true}), (" - " + furniture.Price.ToString(),
new WordTextProperties { Size = "24", }) },
TextProperties = new WordTextProperties
{
Size = "24",
JustificationType = WordJustificationType.Both
}
});
}
} }
SaveWord(info); SaveWord(info);
} }

View File

@ -5,8 +5,6 @@ namespace FurnitureAssemblyBusinessLogic.OfficePackage.HelperModels
public class WordInfo public class WordInfo
{ {
public string FileName { get; set; } = string.Empty; public string FileName { get; set; } = string.Empty;
public string Title { get; set; } = string.Empty; public string Title { get; set; } = string.Empty;
public List<FurnitureViewModel> Furnitures { get; set; } = new();
public List<ShopViewModel> Shops { get; set; } = new();
} }
} }

View File

@ -0,0 +1,14 @@
using FurnitureAssemblyContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FurnitureAssemblyBusinessLogic.OfficePackage.HelperModels
{
public class WordInfoFurnitures : WordInfo
{
public List<FurnitureViewModel> Furnitures { get; set; } = new();
}
}

View File

@ -0,0 +1,14 @@
using FurnitureAssemblyContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FurnitureAssemblyBusinessLogic.OfficePackage.HelperModels
{
public class WordInfoShops : WordInfo
{
public List<ShopViewModel> Shops { get; set; } = new();
}
}

View File

@ -196,7 +196,7 @@ namespace FurnitureAssemblyBusinessLogic.OfficePackage.Implements
} }
private TableCell CreateTableCell(string element) { private TableCell CreateTableCell(string element) {
var tableParagraph = new Paragraph(); var tableParagraph = new Paragraph();
var run = new Run(); var run = new Run();
run.AppendChild(new Text { Text = element }); run.AppendChild(new Text { Text = element });
tableParagraph.AppendChild(run); tableParagraph.AppendChild(run);