Word report implement

This commit is contained in:
ShabOl 2024-05-05 22:16:39 +04:00
parent 6d525876bc
commit 8428b895a8
9 changed files with 189 additions and 8 deletions

View File

@ -57,7 +57,7 @@ namespace AutoWorkshopBusinessLogic.BusinessLogics
public void SaveRepairsToWordFile(ReportBindingModel Model)
{
_saveToWord.CreateDoc(new WordInfo
_saveToWord.CreateRepairsDoc(new WordRepairsInfo
{
FileName = Model.FileName,
Title = "Список ремонтов",

View File

@ -5,7 +5,7 @@ namespace AutoWorkshopBusinessLogic.OfficePackage
{
public abstract class AbstractSaveToWord
{
public void CreateDoc(WordInfo Info)
public void CreateRepairsDoc(WordRepairsInfo Info)
{
CreateWord(Info);
@ -37,11 +37,57 @@ namespace AutoWorkshopBusinessLogic.OfficePackage
SaveWord(Info);
}
protected abstract void CreateWord(WordInfo Info);
public void CreateShopsDoc(WordShopsInfo 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 WordRowParameters
{
Texts = new List<string> { "Название", "Адрес", "Дата открытия" },
TextProperties = new WordTextProperties
{
Size = "24",
Bold = true,
JustificationType = WordJustificationType.Center
}
});
foreach (var Shop in Info.Shops)
{
CreateRow(new WordRowParameters
{
Texts = new List<string> { Shop.ShopName, Shop.Address, Shop.OpeningDate.ToString() },
TextProperties = new WordTextProperties
{
Size = "22",
JustificationType = WordJustificationType.Both
}
});
}
SaveWord(Info);
}
protected abstract void CreateWord(IWordInfo Info);
protected abstract void CreateParagraph(WordParagraph Paragraph);
protected abstract void SaveWord(WordInfo Info);
protected abstract void SaveWord(IWordInfo Info);
protected abstract void CreateTable(List<string> Colums);
protected abstract void CreateRow(WordRowParameters RowParameters);
}
}

View File

@ -0,0 +1,13 @@
using AutoWorkshopContracts.ViewModels;
namespace AutoWorkshopBusinessLogic.OfficePackage.HelperModels
{
public class ExcelShop : IWordInfo
{
public string FileName { get; set; } = string.Empty;
public string Title { get; set; } = string.Empty;
public List<ReportShopsViewModel> ShopRepairs { get; set; } = new();
}
}

View File

@ -0,0 +1,9 @@
namespace AutoWorkshopBusinessLogic.OfficePackage.HelperModels
{
public interface IWordInfo
{
public string FileName { get; set; }
public string Title { get; set; }
}
}

View File

@ -0,0 +1,17 @@
using AutoWorkshopContracts.ViewModels;
namespace AutoWorkshopBusinessLogic.OfficePackage.HelperModels
{
public class PdfGroupedOrdersInfo : IWordInfo
{
public string FileName { get; set; } = string.Empty;
public string Title { get; set; } = string.Empty;
public DateTime DateFrom { get; set; }
public DateTime DateTo { get; set; }
public List<ReportGroupedOrdersViewModel> GroupedOrders { get; set; } = new();
}
}

View File

@ -2,7 +2,7 @@
namespace AutoWorkshopBusinessLogic.OfficePackage.HelperModels
{
public class WordInfo
public class WordRepairsInfo : IWordInfo
{
public string FileName { get; set; } = string.Empty;

View File

@ -0,0 +1,9 @@
namespace AutoWorkshopBusinessLogic.OfficePackage.HelperModels
{
public class WordRowParameters
{
public List<string> Texts { get; set; } = new();
public WordTextProperties TextProperties { get; set; } = new();
}
}

View File

@ -0,0 +1,13 @@
using AutoWorkshopContracts.ViewModels;
namespace AutoWorkshopBusinessLogic.OfficePackage.HelperModels
{
public class WordShopsInfo : IWordInfo
{
public string FileName { get; set; } = string.Empty;
public string Title { get; set; } = string.Empty;
public List<ShopViewModel> Shops { get; set; } = new();
}
}

View File

@ -64,7 +64,7 @@ namespace AutoWorkshopBusinessLogic.OfficePackage.Implements
return Properties;
}
protected override void CreateWord(WordInfo Info)
protected override void CreateWord(IWordInfo Info)
{
_wordDocument = WordprocessingDocument.Create(Info.FileName, WordprocessingDocumentType.Document);
MainDocumentPart mainPart = _wordDocument.AddMainDocumentPart();
@ -103,7 +103,7 @@ namespace AutoWorkshopBusinessLogic.OfficePackage.Implements
_docBody.AppendChild(DocParagraph);
}
protected override void SaveWord(WordInfo Info)
protected override void SaveWord(IWordInfo Info)
{
if (_docBody == null || _wordDocument == null)
{
@ -114,5 +114,79 @@ namespace AutoWorkshopBusinessLogic.OfficePackage.Implements
_wordDocument.MainDocumentPart!.Document.Save();
_wordDocument.Close();
}
private Table? _lastTable;
protected override void CreateTable(List<string> Columns)
{
if (_docBody == null)
return;
_lastTable = new Table();
var TableProp = new TableProperties();
TableProp.AppendChild(new TableLayout { Type = TableLayoutValues.Fixed });
TableProp.AppendChild(new TableBorders(
new TopBorder() { Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 4 },
new LeftBorder() { Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 4 },
new RightBorder() { Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 4 },
new BottomBorder() { Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 4 },
new InsideHorizontalBorder() { Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 4 },
new InsideVerticalBorder() { Val = new EnumValue<BorderValues>(BorderValues.Single), Size = 4 }
));
TableProp.AppendChild(new TableWidth { Type = TableWidthUnitValues.Auto });
_lastTable.AppendChild(TableProp);
TableGrid TableGrid = new TableGrid();
foreach (var Column in Columns)
{
TableGrid.AppendChild(new GridColumn() { Width = Column });
}
_lastTable.AppendChild(TableGrid);
_docBody.AppendChild(_lastTable);
}
protected override void CreateRow(WordRowParameters RowParameters)
{
if (_docBody == null || _lastTable == null)
return;
TableRow DocRow = new TableRow();
foreach (var Column in RowParameters.Texts)
{
var DocParagraph = new Paragraph();
WordParagraph Paragraph = new WordParagraph
{
Texts = new List<(string, WordTextProperties)> { (Column, RowParameters.TextProperties) },
TextProperties = RowParameters.TextProperties
};
DocParagraph.AppendChild(CreateParagraphProperties(Paragraph.TextProperties));
foreach (var Run in Paragraph.Texts)
{
var DocRun = new Run();
var Properties = new RunProperties();
Properties.AppendChild(new FontSize { Val = Run.Item2.Size });
if (Run.Item2.Bold)
{
Properties.AppendChild(new Bold());
}
DocRun.AppendChild(Properties);
DocRun.AppendChild(new Text { Text = Run.Item1, Space = SpaceProcessingModeValues.Preserve });
DocParagraph.AppendChild(DocRun);
}
TableCell docCell = new TableCell();
docCell.AppendChild(DocParagraph);
DocRow.AppendChild(docCell);
}
_lastTable.AppendChild(DocRow);
}
}
}