RestAPI: new methods + files saving logic was changed.
This commit is contained in:
parent
5f7994beaa
commit
2ebbe9789f
@ -146,9 +146,9 @@ namespace ComputerStoreBusinessLogic.BusinessLogic
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SaveConsignmentsToExcelFile(ReportComponentsBindingModel model)
|
public byte[] SaveConsignmentsToExcelFile(ReportComponentsBindingModel model)
|
||||||
{
|
{
|
||||||
_saveToExcel.CreateReport(new ExcelInfo
|
return _saveToExcel.CreateReport(new ExcelInfo
|
||||||
{
|
{
|
||||||
FileName = model.FileName,
|
FileName = model.FileName,
|
||||||
Title = "Consignments list",
|
Title = "Consignments list",
|
||||||
@ -156,9 +156,9 @@ namespace ComputerStoreBusinessLogic.BusinessLogic
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SaveConsignmentsToWordFile(ReportComponentsBindingModel model)
|
public byte[] SaveConsignmentsToWordFile(ReportComponentsBindingModel model)
|
||||||
{
|
{
|
||||||
_saveToWord.CreateDoc(new WordInfo
|
return _saveToWord.CreateDoc(new WordInfo
|
||||||
{
|
{
|
||||||
FileName = model.FileName,
|
FileName = model.FileName,
|
||||||
Title = "Consignments list",
|
Title = "Consignments list",
|
||||||
|
@ -10,8 +10,9 @@ namespace ComputerStoreBusinessLogic.OfficePackage
|
|||||||
{
|
{
|
||||||
public abstract class AbstractSaveToExcel
|
public abstract class AbstractSaveToExcel
|
||||||
{
|
{
|
||||||
public void CreateReport(ExcelInfo info)
|
public byte[] CreateReport(ExcelInfo info)
|
||||||
{
|
{
|
||||||
|
|
||||||
CreateExcel(info);
|
CreateExcel(info);
|
||||||
InsertCellInWorksheet(new ExcelCellParameters
|
InsertCellInWorksheet(new ExcelCellParameters
|
||||||
{
|
{
|
||||||
@ -70,7 +71,9 @@ namespace ComputerStoreBusinessLogic.OfficePackage
|
|||||||
});
|
});
|
||||||
rowIndex++;
|
rowIndex++;
|
||||||
}
|
}
|
||||||
SaveExcel(info);
|
return SaveExcel(info);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract void CreateExcel(ExcelInfo info);
|
protected abstract void CreateExcel(ExcelInfo info);
|
||||||
@ -79,6 +82,6 @@ namespace ComputerStoreBusinessLogic.OfficePackage
|
|||||||
|
|
||||||
protected abstract void MergeCells(ExcelMergeParameters excelParams);
|
protected abstract void MergeCells(ExcelMergeParameters excelParams);
|
||||||
|
|
||||||
protected abstract void SaveExcel(ExcelInfo info);
|
protected abstract byte[] SaveExcel(ExcelInfo info);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ namespace ComputerStoreBusinessLogic.OfficePackage
|
|||||||
{
|
{
|
||||||
public abstract class AbstractSaveToWord
|
public abstract class AbstractSaveToWord
|
||||||
{
|
{
|
||||||
public void CreateDoc(WordInfo info)
|
public byte[] CreateDoc(WordInfo info)
|
||||||
{
|
{
|
||||||
CreateWord(info);
|
CreateWord(info);
|
||||||
CreateParagraph(new WordParagraph
|
CreateParagraph(new WordParagraph
|
||||||
@ -48,11 +48,11 @@ namespace ComputerStoreBusinessLogic.OfficePackage
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
SaveWord(info);
|
return SaveWord(info);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract void CreateWord(WordInfo info);
|
protected abstract void CreateWord(WordInfo info);
|
||||||
protected abstract void CreateParagraph(WordParagraph paragraph);
|
protected abstract void CreateParagraph(WordParagraph paragraph);
|
||||||
protected abstract void SaveWord(WordInfo info);
|
protected abstract byte[] SaveWord(WordInfo info);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ namespace ComputerStoreBusinessLogic.OfficePackage.Implements
|
|||||||
private SpreadsheetDocument? _spreadsheetDocument;
|
private SpreadsheetDocument? _spreadsheetDocument;
|
||||||
private SharedStringTablePart? _shareStringPart;
|
private SharedStringTablePart? _shareStringPart;
|
||||||
private Worksheet? _worksheet;
|
private Worksheet? _worksheet;
|
||||||
|
private MemoryStream? mem;
|
||||||
private static void CreateStyles(WorkbookPart workbookpart)
|
private static void CreateStyles(WorkbookPart workbookpart)
|
||||||
{
|
{
|
||||||
var sp = workbookpart.AddNewPart<WorkbookStylesPart>();
|
var sp = workbookpart.AddNewPart<WorkbookStylesPart>();
|
||||||
@ -211,8 +211,8 @@ namespace ComputerStoreBusinessLogic.OfficePackage.Implements
|
|||||||
|
|
||||||
protected override void CreateExcel(ExcelInfo info)
|
protected override void CreateExcel(ExcelInfo info)
|
||||||
{
|
{
|
||||||
_spreadsheetDocument = SpreadsheetDocument.Create(info.FileName,
|
mem = new MemoryStream();
|
||||||
SpreadsheetDocumentType.Workbook);
|
_spreadsheetDocument = SpreadsheetDocument.Create(mem, SpreadsheetDocumentType.Workbook);
|
||||||
|
|
||||||
var workbookpart = _spreadsheetDocument.AddWorkbookPart();
|
var workbookpart = _spreadsheetDocument.AddWorkbookPart();
|
||||||
workbookpart.Workbook = new Workbook();
|
workbookpart.Workbook = new Workbook();
|
||||||
@ -341,14 +341,16 @@ namespace ComputerStoreBusinessLogic.OfficePackage.Implements
|
|||||||
mergeCells.Append(mergeCell);
|
mergeCells.Append(mergeCell);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void SaveExcel(ExcelInfo info)
|
protected override byte[] SaveExcel(ExcelInfo info)
|
||||||
{
|
{
|
||||||
if (_spreadsheetDocument == null)
|
if (_spreadsheetDocument == null)
|
||||||
{
|
{
|
||||||
return;
|
return null;
|
||||||
}
|
}
|
||||||
_spreadsheetDocument.WorkbookPart!.Workbook.Save();
|
_spreadsheetDocument.WorkbookPart!.Workbook.Save();
|
||||||
_spreadsheetDocument.Dispose();
|
_spreadsheetDocument.Dispose();
|
||||||
|
|
||||||
|
return mem.ToArray();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ namespace ComputerStoreBusinessLogic.OfficePackage.Implements
|
|||||||
{
|
{
|
||||||
private WordprocessingDocument? _wordDocument;
|
private WordprocessingDocument? _wordDocument;
|
||||||
private Body? _docBody;
|
private Body? _docBody;
|
||||||
|
private MemoryStream mem;
|
||||||
private static JustificationValues GetJustificationValues(WordJustificationType type)
|
private static JustificationValues GetJustificationValues(WordJustificationType type)
|
||||||
{
|
{
|
||||||
return type switch
|
return type switch
|
||||||
@ -96,21 +96,23 @@ namespace ComputerStoreBusinessLogic.OfficePackage.Implements
|
|||||||
|
|
||||||
protected override void CreateWord(WordInfo info)
|
protected override void CreateWord(WordInfo info)
|
||||||
{
|
{
|
||||||
_wordDocument = WordprocessingDocument.Create(info.FileName, WordprocessingDocumentType.Document);
|
mem = new MemoryStream();
|
||||||
|
_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());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void SaveWord(WordInfo info)
|
protected override byte[] SaveWord(WordInfo 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,7 +15,7 @@ namespace ComputerStoreContracts.BusinessLogicContracts
|
|||||||
List<ReportConsignmentsViewModel> GetConsignmentsByComponents(ReportComponentsBindingModel model);
|
List<ReportConsignmentsViewModel> GetConsignmentsByComponents(ReportComponentsBindingModel model);
|
||||||
|
|
||||||
void SavePCsAndProductsToPdfFile(ReportDateBindingModel model);
|
void SavePCsAndProductsToPdfFile(ReportDateBindingModel model);
|
||||||
void SaveConsignmentsToExcelFile(ReportComponentsBindingModel model);
|
byte[] SaveConsignmentsToExcelFile(ReportComponentsBindingModel model);
|
||||||
void SaveConsignmentsToWordFile(ReportComponentsBindingModel model);
|
byte[] SaveConsignmentsToWordFile(ReportComponentsBindingModel model);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
using ComputerStoreContracts.BusinessLogicContracts;
|
using ComputerStoreContracts.BusinessLogicContracts;
|
||||||
using ComputerStoreContracts.SearchModels;
|
using ComputerStoreContracts.SearchModels;
|
||||||
using ComputerStoreContracts.ViewModels;
|
using ComputerStoreContracts.ViewModels;
|
||||||
|
using DocumentFormat.OpenXml.Packaging;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
|
|
||||||
@ -508,5 +509,25 @@ namespace ComputerStoreRestAPI.Controllers
|
|||||||
{
|
{
|
||||||
return _employeeReportLogic.GetConsignmentsByComponents(model);
|
return _employeeReportLogic.GetConsignmentsByComponents(model);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
[HttpGet]
|
||||||
|
public byte[] SaveReportConsignmentsToExcel(ReportComponentsBindingModel model)
|
||||||
|
{
|
||||||
|
return _employeeReportLogic.SaveConsignmentsToExcelFile(new ReportComponentsBindingModel
|
||||||
|
{
|
||||||
|
FileName = "ReportConsignments",
|
||||||
|
Components = model.Components
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
public byte[] SaveReportConsignmentsToWord(ReportComponentsBindingModel model)
|
||||||
|
{
|
||||||
|
return _employeeReportLogic.SaveConsignmentsToWordFile(new ReportComponentsBindingModel
|
||||||
|
{
|
||||||
|
FileName = "ReportConsignments",
|
||||||
|
Components = model.Components
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user