docx Report exp
This commit is contained in:
parent
642291fa0a
commit
1e4ea0c6d7
@ -73,7 +73,7 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
|
|||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] SavePaymeantToExcelFile(ReportBindingModel? model, int _clientID)
|
public byte[] SavePaymeantToExcelFile(int _clientID)
|
||||||
{
|
{
|
||||||
var document = _saveToExcel.CreateReport(new ExcelInfoClient
|
var document = _saveToExcel.CreateReport(new ExcelInfoClient
|
||||||
{
|
{
|
||||||
@ -83,14 +83,13 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
|
|||||||
return document;
|
return document;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SavePaymeantToWordFile(ReportBindingModel model)
|
public byte[] SavePaymeantToWordFile(int _clientID)
|
||||||
{
|
{
|
||||||
_saveToWord.CreateDoc(new WordInfoClient
|
var document = _saveToWord.CreateDoc(new WordInfoClient {
|
||||||
{
|
|
||||||
//FileName = model.ProductName,
|
|
||||||
Title = "Список оплат",
|
Title = "Список оплат",
|
||||||
ListPaymeant = _paymeantstorage.GetFullList(),
|
ListPaymeant = _paymeantstorage.GetFillteredList(new PaymeantSearchModel { ClientID = _clientID }),
|
||||||
});
|
});
|
||||||
|
return document;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -7,7 +7,7 @@ namespace ElectronicsShopBusinessLogic.OfficePackage
|
|||||||
{
|
{
|
||||||
public abstract class AbstractSaveToExcelClient
|
public abstract class AbstractSaveToExcelClient
|
||||||
{
|
{
|
||||||
public byte[] CreateReport(ExcelInfoClient info) {
|
public byte[]? CreateReport(ExcelInfoClient info) {
|
||||||
CreateExcel(info);
|
CreateExcel(info);
|
||||||
|
|
||||||
InsertCellInWorksheet(new ExcelCellParameters {
|
InsertCellInWorksheet(new ExcelCellParameters {
|
||||||
@ -76,6 +76,6 @@ namespace ElectronicsShopBusinessLogic.OfficePackage
|
|||||||
protected abstract void MergeCells(ExcelMergeParameters excelParams);
|
protected abstract void MergeCells(ExcelMergeParameters excelParams);
|
||||||
|
|
||||||
// Сохранение файла
|
// Сохранение файла
|
||||||
protected abstract byte[] SaveExcel(ExcelInfoClient info);
|
protected abstract byte[]? SaveExcel(ExcelInfoClient info);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ namespace ElectronicsShopBusinessLogic.OfficePackage
|
|||||||
{
|
{
|
||||||
public abstract class AbstractSaveToWordClient
|
public abstract class AbstractSaveToWordClient
|
||||||
{
|
{
|
||||||
public void CreateDoc(WordInfoClient info)
|
public byte[]? CreateDoc(WordInfoClient info)
|
||||||
{
|
{
|
||||||
CreateWord(info);
|
CreateWord(info);
|
||||||
|
|
||||||
@ -49,26 +49,17 @@ namespace ElectronicsShopBusinessLogic.OfficePackage
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
SaveWord(info);
|
var document = SaveWord(info);
|
||||||
|
return document;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
// Создание doc-файла
|
||||||
/// Создание doc-файла
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="info"></param>
|
|
||||||
protected abstract void CreateWord(WordInfoClient info);
|
protected abstract void CreateWord(WordInfoClient info);
|
||||||
|
|
||||||
/// <summary>
|
// Создание абзаца с текстом
|
||||||
/// Создание абзаца с текстом
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="paragraph"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
protected abstract void CreateParagraph(WordParagraph paragraph);
|
protected abstract void CreateParagraph(WordParagraph paragraph);
|
||||||
|
|
||||||
/// <summary>
|
// Сохранение файла
|
||||||
/// Сохранение файла
|
protected abstract byte[]? SaveWord(WordInfoClient info);
|
||||||
/// </summary>
|
|
||||||
/// <param name="info"></param>
|
|
||||||
protected abstract void SaveWord(WordInfoClient info);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -275,7 +275,7 @@ namespace ElectronicsShopBusinessLogic.OfficePackage.Implements
|
|||||||
mergeCells.Append(mergeCell);
|
mergeCells.Append(mergeCell);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override byte[] SaveExcel(ExcelInfoClient info)
|
protected override byte[]? SaveExcel(ExcelInfoClient info)
|
||||||
{
|
{
|
||||||
if (_spreadsheetDocument == null)
|
if (_spreadsheetDocument == null)
|
||||||
{
|
{
|
||||||
|
@ -12,11 +12,9 @@ namespace ElectronicsShopBusinessLogic.OfficePackage.Implements
|
|||||||
|
|
||||||
private Body? _docBody;
|
private Body? _docBody;
|
||||||
|
|
||||||
/// <summary>
|
private MemoryStream _mem = new MemoryStream();
|
||||||
/// Получение типа выравнивания
|
|
||||||
/// </summary>
|
// Получение типа выравнивания
|
||||||
/// <param name="type"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
private static JustificationValues GetJustificationValues(WordJustificationType type)
|
private static JustificationValues GetJustificationValues(WordJustificationType type)
|
||||||
{
|
{
|
||||||
return type switch
|
return type switch
|
||||||
@ -27,10 +25,7 @@ namespace ElectronicsShopBusinessLogic.OfficePackage.Implements
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
// Настройки страницы
|
||||||
/// Настройки страницы
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
private static SectionProperties CreateSectionProperties()
|
private static SectionProperties CreateSectionProperties()
|
||||||
{
|
{
|
||||||
var properties = new SectionProperties();
|
var properties = new SectionProperties();
|
||||||
@ -45,11 +40,7 @@ namespace ElectronicsShopBusinessLogic.OfficePackage.Implements
|
|||||||
return properties;
|
return properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
// Задание форматирования для абзаца
|
||||||
/// Задание форматирования для абзаца
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="paragraphProperties"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
private static ParagraphProperties? CreateParagraphProperties(WordTextProperties? paragraphProperties)
|
private static ParagraphProperties? CreateParagraphProperties(WordTextProperties? paragraphProperties)
|
||||||
{
|
{
|
||||||
if (paragraphProperties == null)
|
if (paragraphProperties == null)
|
||||||
@ -83,7 +74,7 @@ namespace ElectronicsShopBusinessLogic.OfficePackage.Implements
|
|||||||
|
|
||||||
protected override void CreateWord(WordInfoClient info)
|
protected override void CreateWord(WordInfoClient info)
|
||||||
{
|
{
|
||||||
_wordDocument = WordprocessingDocument.Create(info.FileName, WordprocessingDocumentType.Document);
|
_wordDocument = WordprocessingDocument.Create(_mem, WordprocessingDocumentType.Document);
|
||||||
MainDocumentPart mainPart = _wordDocument.AddMainDocumentPart();
|
MainDocumentPart mainPart = _wordDocument.AddMainDocumentPart();
|
||||||
mainPart.Document = new Document();
|
mainPart.Document = new Document();
|
||||||
_docBody = mainPart.Document.AppendChild(new Body());
|
_docBody = mainPart.Document.AppendChild(new Body());
|
||||||
@ -119,17 +110,19 @@ namespace ElectronicsShopBusinessLogic.OfficePackage.Implements
|
|||||||
_docBody.AppendChild(docParagraph);
|
_docBody.AppendChild(docParagraph);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void SaveWord(WordInfoClient info)
|
protected override byte[]? SaveWord(WordInfoClient info)
|
||||||
{
|
{
|
||||||
if (_docBody == null || _wordDocument == null)
|
if (_docBody == null || _wordDocument == null)
|
||||||
{
|
{
|
||||||
return;
|
return null;
|
||||||
}
|
}
|
||||||
_docBody.AppendChild(CreateSectionProperties());
|
_docBody.AppendChild(CreateSectionProperties());
|
||||||
|
|
||||||
_wordDocument.MainDocumentPart!.Document.Save();
|
_wordDocument.MainDocumentPart!.Document.Save();
|
||||||
|
|
||||||
_wordDocument.Dispose();
|
_wordDocument.Dispose();
|
||||||
|
|
||||||
|
return _mem.ToArray();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,9 +15,9 @@ namespace ElectronicsShopContracts.BusinessLogicContracts
|
|||||||
List<ReportPaymeantProductsViewModel> GetPaymeantProducts(int _clientID);
|
List<ReportPaymeantProductsViewModel> GetPaymeantProducts(int _clientID);
|
||||||
// получения списка оплат
|
// получения списка оплат
|
||||||
List<ReportPaymeantsViewModel> GetPaymeants(ReportBindingModel model);
|
List<ReportPaymeantsViewModel> GetPaymeants(ReportBindingModel model);
|
||||||
void SavePaymeantToWordFile(ReportBindingModel model);
|
byte[] SavePaymeantToWordFile(int _clientID);
|
||||||
|
|
||||||
// Сохранение компонент с указанием отчета в .excel
|
// Сохранение компонент с указанием отчета в .excel
|
||||||
byte[] SavePaymeantToExcelFile(ReportBindingModel? model, int _clientID);
|
byte[] SavePaymeantToExcelFile(int _clientID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -98,7 +98,19 @@ namespace ElectronicsShopRestAPI.Controllers {
|
|||||||
[HttpGet]
|
[HttpGet]
|
||||||
public byte[] CreateXlsxReport (int _clientID) {
|
public byte[] CreateXlsxReport (int _clientID) {
|
||||||
try {
|
try {
|
||||||
var document = _reportLogic.SavePaymeantToExcelFile (null, _clientID);
|
var document = _reportLogic.SavePaymeantToExcelFile (_clientID);
|
||||||
|
return document;
|
||||||
|
}
|
||||||
|
catch (Exception ex) {
|
||||||
|
_logger.LogError(ex, $"Ошибка создания файла");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
public byte[] CreateDocxReport (int _clientID) {
|
||||||
|
try {
|
||||||
|
var document = _reportLogic.SavePaymeantToWordFile (_clientID);
|
||||||
return document;
|
return document;
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
|
@ -313,7 +313,23 @@ namespace ElectronicsShopUserApp.Controllers {
|
|||||||
[HttpGet]
|
[HttpGet]
|
||||||
public IActionResult CreateExcelReport() {
|
public IActionResult CreateExcelReport() {
|
||||||
var fileMemStream = APIClient.GetRequset<byte[]>($"api/Client/CreateXlsxReport?_clientID={APIClient.Client.ID}");
|
var fileMemStream = APIClient.GetRequset<byte[]>($"api/Client/CreateXlsxReport?_clientID={APIClient.Client.ID}");
|
||||||
|
|
||||||
|
if (fileMemStream == null) {
|
||||||
|
throw new Exception("Îøèáêà ñîçäàíèÿ îò÷åòà");
|
||||||
|
}
|
||||||
|
|
||||||
return File(fileMemStream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "Report.xlsx");
|
return File(fileMemStream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "Report.xlsx");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
public IActionResult CreateWordReport() {
|
||||||
|
var fileMemStream = APIClient.GetRequset<byte[]>($"api/client/CreateDocxReport?_clientID={APIClient.Client.ID}");
|
||||||
|
|
||||||
|
if (fileMemStream == null) {
|
||||||
|
throw new Exception("Îøèáêà ñîçäàíèÿ îò÷åòà");
|
||||||
|
}
|
||||||
|
|
||||||
|
return File(fileMemStream, "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "Report.docx");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -25,9 +25,9 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-8">
|
<div class="col-8">
|
||||||
<a class="btn btn-primary btn-sm" asp-action="CreateWordReport" style="background-color:#335a95;">Создать отчет в .xlsx</a>
|
<a class="btn btn-primary btn-sm" asp-action="CreateWordReport" style="background-color:#335a95;">Экспорт отчета в .xlsx</a>
|
||||||
<a class="btn btn-primary btn-sm" asp-action="CreateExcelReport" style="background-color:#04713A;">Создать отчет в .docx</a>
|
<a class="btn btn-primary btn-sm" asp-action="CreateExcelReport" style="background-color:#04713A;">Экспорт отчета в .docx</a>
|
||||||
<a class="btn btn-primary btn-sm" asp-action="CreatePdfReport" style="background-color:#ad0d09;">Создать отчет в .pdf</a>
|
<a class="btn btn-primary btn-sm" asp-action="CreatePdfReport" style="background-color:#ad0d09;">отправить на Email отчет в .pdf</a>
|
||||||
</div>
|
</div>
|
||||||
</h1>
|
</h1>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user