Pdf Report Client
This commit is contained in:
parent
1e4ea0c6d7
commit
93e0fe9524
@ -6,6 +6,9 @@ using ElectronicsShopContracts.BusinessLogicContracts;
|
|||||||
using ElectronicsShopContracts.SearchModels;
|
using ElectronicsShopContracts.SearchModels;
|
||||||
using ElectronicsShopContracts.StorageContracts;
|
using ElectronicsShopContracts.StorageContracts;
|
||||||
using ElectronicsShopContracts.ViewModels;
|
using ElectronicsShopContracts.ViewModels;
|
||||||
|
using MigraDoc.DocumentObjectModel;
|
||||||
|
using PdfSharp.Pdf;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace ElectronicsShopBusinessLogic.BusinessLogic
|
namespace ElectronicsShopBusinessLogic.BusinessLogic
|
||||||
{
|
{
|
||||||
@ -14,20 +17,49 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
|
|||||||
private readonly IPaymeantStorage _paymeantstorage;
|
private readonly IPaymeantStorage _paymeantstorage;
|
||||||
private readonly IProductStorage _productstorage;
|
private readonly IProductStorage _productstorage;
|
||||||
private readonly IOrderStorage _orderStorage;
|
private readonly IOrderStorage _orderStorage;
|
||||||
|
private readonly ICostItemStorage _costItemStorage;
|
||||||
private readonly AbstractSaveToExcelClient _saveToExcel;
|
private readonly AbstractSaveToExcelClient _saveToExcel;
|
||||||
private readonly AbstractSaveToWordClient _saveToWord;
|
private readonly AbstractSaveToWordClient _saveToWord;
|
||||||
|
private readonly AbstractSaveToPdfClient _saveToPdf;
|
||||||
|
|
||||||
public ReportClientLogic(AbstractSaveToExcelClient abstractSaveToExcelClient, AbstractSaveToWordClient abstractSaveToWordClient,
|
public ReportClientLogic(AbstractSaveToExcelClient abstractSaveToExcelClient, AbstractSaveToWordClient abstractSaveToWordClient,
|
||||||
IPaymeantStorage paymeantStorage, IProductStorage productStorage, IOrderStorage orderStorage) {
|
IPaymeantStorage paymeantStorage, IProductStorage productStorage, IOrderStorage orderStorage,
|
||||||
|
AbstractSaveToPdfClient abstractSaveToPdfClient, ICostItemStorage costItemStorage) {
|
||||||
_saveToExcel = abstractSaveToExcelClient;
|
_saveToExcel = abstractSaveToExcelClient;
|
||||||
_saveToWord= abstractSaveToWordClient;
|
_saveToWord= abstractSaveToWordClient;
|
||||||
_paymeantstorage = paymeantStorage;
|
_paymeantstorage = paymeantStorage;
|
||||||
_productstorage = productStorage;
|
_productstorage = productStorage;
|
||||||
_orderStorage = orderStorage;
|
_orderStorage = orderStorage;
|
||||||
|
_costItemStorage = costItemStorage;
|
||||||
|
_saveToPdf = abstractSaveToPdfClient;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Получение списка оплаченных товаров за период
|
||||||
|
public List<ReportProductsViewModel>? GetProducts (ReportBindingModel model) {
|
||||||
|
var paymeants = _paymeantstorage.GetFillteredList(new PaymeantSearchModel {
|
||||||
|
DateFrom = model.DateFrom,
|
||||||
|
DateTo = model.DateTo,
|
||||||
|
});
|
||||||
|
|
||||||
|
List<ReportProductsViewModel>? products = new();
|
||||||
|
|
||||||
|
foreach (var paymeant in paymeants) {
|
||||||
|
var order = _orderStorage.GetElement(new OrderSearchModel { ID = paymeant.OrderID });
|
||||||
|
foreach (var product in order.ProductList) {
|
||||||
|
products.Add(new ReportProductsViewModel {
|
||||||
|
ID = product.Value.Item1.ID,
|
||||||
|
ProductName = product.Value.Item1.ProductName,
|
||||||
|
Price = product.Value.Item1.Price,
|
||||||
|
CostItemName = _costItemStorage.GetElement(new CostItemSearchModel { ID = product.Value.Item1.CostItemID }).Name
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return products;
|
||||||
}
|
}
|
||||||
|
|
||||||
// получение списка оплат за период
|
// получение списка оплат за период
|
||||||
public List<ReportPaymeantsViewModel> GetPaymeants(ReportBindingModel model)
|
public List<ReportPaymeantsViewModel>? GetPaymeants(ReportBindingModel model)
|
||||||
{
|
{
|
||||||
return _paymeantstorage.GetFillteredList(new PaymeantSearchModel {
|
return _paymeantstorage.GetFillteredList(new PaymeantSearchModel {
|
||||||
DateFrom = model.DateFrom,
|
DateFrom = model.DateFrom,
|
||||||
@ -73,7 +105,7 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
|
|||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] SavePaymeantToExcelFile(int _clientID)
|
public byte[]? SavePaymeantToExcelFile(int _clientID)
|
||||||
{
|
{
|
||||||
var document = _saveToExcel.CreateReport(new ExcelInfoClient
|
var document = _saveToExcel.CreateReport(new ExcelInfoClient
|
||||||
{
|
{
|
||||||
@ -83,12 +115,23 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
|
|||||||
return document;
|
return document;
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] SavePaymeantToWordFile(int _clientID)
|
public byte[]? SavePaymeantToWordFile(int _clientID)
|
||||||
{
|
{
|
||||||
var document = _saveToWord.CreateDoc(new WordInfoClient {
|
var document = _saveToWord.CreateDoc(new WordInfoClient {
|
||||||
Title = "Список оплат",
|
Title = "Список оплат и товаров",
|
||||||
ListPaymeant = _paymeantstorage.GetFillteredList(new PaymeantSearchModel { ClientID = _clientID }),
|
ListPaymeant = _paymeantstorage.GetFillteredList(new PaymeantSearchModel { ClientID = _clientID }),
|
||||||
});
|
});
|
||||||
|
return document;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PdfDocument SaveProductToPdfFile(ReportBindingModel model) {
|
||||||
|
var document = _saveToPdf.CreteDoc(new PdfInfoClient {
|
||||||
|
Title = "Список оплаченных товаров",
|
||||||
|
FileName = "Report",
|
||||||
|
DateFrom = model.DateFrom,
|
||||||
|
DateTo = model.DateTo,
|
||||||
|
Products = GetProducts(model)
|
||||||
|
});
|
||||||
return document;
|
return document;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.1" />
|
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.1" />
|
||||||
<PackageReference Include="MigraDocCore.DocumentObjectModel" Version="1.3.63" />
|
<PackageReference Include="MigraDocCore.DocumentObjectModel" Version="1.3.63" />
|
||||||
<PackageReference Include="MigraDocCore.Rendering" Version="1.3.63" />
|
<PackageReference Include="MigraDocCore.Rendering" Version="1.3.63" />
|
||||||
|
<PackageReference Include="PdfSharp.MigraDoc.Standard" Version="1.51.15" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -10,12 +10,14 @@ using System.Threading.Tasks;
|
|||||||
using ElectronicsShopContracts.BindingModels;
|
using ElectronicsShopContracts.BindingModels;
|
||||||
using MailKit.Net.Pop3;
|
using MailKit.Net.Pop3;
|
||||||
using MailKit.Security;
|
using MailKit.Security;
|
||||||
|
using MigraDoc.DocumentObjectModel;
|
||||||
|
|
||||||
namespace ElectronicsShopBusinessLogic.MailWorker
|
namespace ElectronicsShopBusinessLogic.MailWorker
|
||||||
{
|
{
|
||||||
public class MailKitWorker : AbstractMailWorker
|
public class MailKitWorker : AbstractMailWorker
|
||||||
{
|
{
|
||||||
public MailKitWorker(ILogger<MailKitWorker> logger, IMessageInfoLogic messageInfoLogic, IClientLogic clientLogic) : base(logger, messageInfoLogic, clientLogic) { }
|
public MailKitWorker(ILogger<MailKitWorker> logger, IMessageInfoLogic messageInfoLogic,
|
||||||
|
IClientLogic clientLogic) : base(logger, messageInfoLogic, clientLogic) { }
|
||||||
|
|
||||||
protected override async Task SendMailAsync(MailSendInfoBindingModel info)
|
protected override async Task SendMailAsync(MailSendInfoBindingModel info)
|
||||||
{
|
{
|
||||||
@ -27,6 +29,12 @@ namespace ElectronicsShopBusinessLogic.MailWorker
|
|||||||
objMailMessage.To.Add(new MailAddress(info.MailAddress));
|
objMailMessage.To.Add(new MailAddress(info.MailAddress));
|
||||||
objMailMessage.Subject = info.Subject;
|
objMailMessage.Subject = info.Subject;
|
||||||
objMailMessage.Body = info.Text;
|
objMailMessage.Body = info.Text;
|
||||||
|
|
||||||
|
Attachment attachment = new Attachment(new MemoryStream(info.document), name: "Report.pdf");
|
||||||
|
if (attachment != null) {
|
||||||
|
objMailMessage.Attachments.Add(attachment);
|
||||||
|
}
|
||||||
|
|
||||||
objMailMessage.SubjectEncoding = Encoding.UTF8;
|
objMailMessage.SubjectEncoding = Encoding.UTF8;
|
||||||
objMailMessage.BodyEncoding = Encoding.UTF8;
|
objMailMessage.BodyEncoding = Encoding.UTF8;
|
||||||
|
|
||||||
|
@ -0,0 +1,65 @@
|
|||||||
|
using ElectronicsShopBusinessLogic.OfficePackage.HelperEnums;
|
||||||
|
using ElectronicsShopBusinessLogic.OfficePackage.HelperModels;
|
||||||
|
using MigraDoc.DocumentObjectModel;
|
||||||
|
using PdfSharp.Pdf;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ElectronicsShopBusinessLogic.OfficePackage
|
||||||
|
{
|
||||||
|
public abstract class AbstractSaveToPdfClient {
|
||||||
|
public PdfDocument CreteDoc (PdfInfoClient info) {
|
||||||
|
CretePdf(info);
|
||||||
|
|
||||||
|
CreateParagraph(new PdfParagraph {
|
||||||
|
Text = info.Title,
|
||||||
|
Style = "NormalTitle",
|
||||||
|
alignmentType = PdfParagraphAlignmentType.Center,
|
||||||
|
});
|
||||||
|
CreateParagraph(new PdfParagraph {
|
||||||
|
Text = $"c {info.DateFrom.ToShortDateString()} по {info.DateTo.ToShortDateString()}",
|
||||||
|
Style = "Normal",
|
||||||
|
alignmentType = PdfParagraphAlignmentType.Right
|
||||||
|
});
|
||||||
|
|
||||||
|
CreateTable(new List<string> { "2cm", "6cm", "4cm", "6cm"});
|
||||||
|
|
||||||
|
CreateRow(new PdfRowParameters {
|
||||||
|
Text = new List<string> { "Номер", "Товар", "Цена", "Статья затрат" },
|
||||||
|
Style = "NormalTittle",
|
||||||
|
alignmentType = PdfParagraphAlignmentType.Center,
|
||||||
|
});
|
||||||
|
|
||||||
|
foreach (var products in info.Products) {
|
||||||
|
CreateRow(new PdfRowParameters {
|
||||||
|
Text = new List<string> { products.ID.ToString(), products.ProductName.ToString(), products.Price.ToString(),
|
||||||
|
products.CostItemName.ToString()},
|
||||||
|
Style = "Normal",
|
||||||
|
alignmentType = PdfParagraphAlignmentType.Left,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
CreateParagraph(new PdfParagraph {
|
||||||
|
Text = $"Итого: {info.Products.Sum(x => x.Price)}\t",
|
||||||
|
Style = "Normal",
|
||||||
|
alignmentType = PdfParagraphAlignmentType.Right
|
||||||
|
});
|
||||||
|
|
||||||
|
var document = SavePdf(info);
|
||||||
|
return document;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Создание doc-файла
|
||||||
|
protected abstract void CretePdf (PdfInfoClient info);
|
||||||
|
// Создание параграфа с текстом
|
||||||
|
protected abstract void CreateParagraph(PdfParagraph paragraph);
|
||||||
|
// Создание таблицы
|
||||||
|
protected abstract void CreateTable(List<string> columns);
|
||||||
|
// Создание и заполнение строки
|
||||||
|
protected abstract void CreateRow(PdfRowParameters rowParameters);
|
||||||
|
// Сохранение файла
|
||||||
|
protected abstract PdfDocument SavePdf(PdfInfoClient info);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ElectronicsShopBusinessLogic.OfficePackage.HelperEnums {
|
||||||
|
public enum PdfParagraphAlignmentType {
|
||||||
|
Center,
|
||||||
|
Left,
|
||||||
|
Right,
|
||||||
|
}
|
||||||
|
}
|
@ -4,7 +4,6 @@ namespace ElectronicsShopBusinessLogic.OfficePackage.HelperModels
|
|||||||
{
|
{
|
||||||
public class ExcelInfoClient
|
public class ExcelInfoClient
|
||||||
{
|
{
|
||||||
public string FileName { get; set; } = string.Empty;
|
|
||||||
public string Title { get; set; } = string.Empty;
|
public string Title { get; set; } = string.Empty;
|
||||||
public List<ReportPaymeantProductsViewModel> PaymeantProducts { get; set; } = new();
|
public List<ReportPaymeantProductsViewModel> PaymeantProducts { get; set; } = new();
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,16 @@
|
|||||||
|
using ElectronicsShopContracts.ViewModels;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ElectronicsShopBusinessLogic.OfficePackage.HelperModels {
|
||||||
|
public class PdfInfoClient {
|
||||||
|
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<ReportProductsViewModel>? Products { get; set; } = new();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
using ElectronicsShopBusinessLogic.OfficePackage.HelperEnums;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ElectronicsShopBusinessLogic.OfficePackage.HelperModels {
|
||||||
|
public class PdfParagraph {
|
||||||
|
public string Text { get; set; } = string.Empty;
|
||||||
|
public string Style { get; set; } = string.Empty;
|
||||||
|
public PdfParagraphAlignmentType alignmentType { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
using ElectronicsShopBusinessLogic.OfficePackage.HelperEnums;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ElectronicsShopBusinessLogic.OfficePackage.HelperModels {
|
||||||
|
public class PdfRowParameters {
|
||||||
|
public List<string> Text { get; set; } = new();
|
||||||
|
public string Style { get; set; } = string.Empty;
|
||||||
|
public PdfParagraphAlignmentType alignmentType { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -5,10 +5,7 @@ namespace ElectronicsShopBusinessLogic.OfficePackage.HelperModels
|
|||||||
{
|
{
|
||||||
public class WordInfoClient
|
public class WordInfoClient
|
||||||
{
|
{
|
||||||
public string FileName { get; set; } = string.Empty;
|
|
||||||
|
|
||||||
public string Title { get; set; } = string.Empty;
|
public string Title { get; set; } = string.Empty;
|
||||||
|
|
||||||
public List<PaymeantViewModel> ListPaymeant { get; set; } = new();
|
public List<PaymeantViewModel> ListPaymeant { get; set; } = new();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,98 @@
|
|||||||
|
using DocumentFormat.OpenXml.Bibliography;
|
||||||
|
using ElectronicsShopBusinessLogic.OfficePackage.HelperEnums;
|
||||||
|
using ElectronicsShopBusinessLogic.OfficePackage.HelperModels;
|
||||||
|
using MigraDoc.DocumentObjectModel;
|
||||||
|
using MigraDoc.DocumentObjectModel.Tables;
|
||||||
|
using MigraDoc.Rendering;
|
||||||
|
using PdfSharp.Pdf;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ElectronicsShopBusinessLogic.OfficePackage.Implements {
|
||||||
|
public class SaveToPdfClient : AbstractSaveToPdfClient {
|
||||||
|
|
||||||
|
private Document? _document;
|
||||||
|
private Section? _section;
|
||||||
|
private Table? _table;
|
||||||
|
|
||||||
|
// Типы выравнивания
|
||||||
|
private static ParagraphAlignment GetParagraphAlignment(PdfParagraphAlignmentType type) {
|
||||||
|
return type switch {
|
||||||
|
PdfParagraphAlignmentType.Center => ParagraphAlignment.Center,
|
||||||
|
PdfParagraphAlignmentType.Left => ParagraphAlignment.Left,
|
||||||
|
PdfParagraphAlignmentType.Right => ParagraphAlignment.Right,
|
||||||
|
_ => ParagraphAlignment.Justify
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Создание стилей для документа
|
||||||
|
private static void DefineStyles(Document document) {
|
||||||
|
var style = document.Styles["Normal"];
|
||||||
|
style.Font.Name = "Times New Roman";
|
||||||
|
style.Font.Size = 14;
|
||||||
|
style = document.Styles.AddStyle("NormalTitle", "Normal");
|
||||||
|
style.Font.Bold = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void CreateParagraph(PdfParagraph pdfParagraph) {
|
||||||
|
if (_section == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var paragraph = _section.AddParagraph(pdfParagraph.Text);
|
||||||
|
paragraph.Format.SpaceAfter = "1cm";
|
||||||
|
paragraph.Format.Alignment = GetParagraphAlignment(pdfParagraph.alignmentType);
|
||||||
|
paragraph.Style = pdfParagraph.Style;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void CreateRow(PdfRowParameters rowParameters) {
|
||||||
|
if (_table == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var row = _table.AddRow();
|
||||||
|
for (int i = 0; i < rowParameters.Text.Count; ++i) {
|
||||||
|
// заполнение ячейки (добавление параграфа в ячейку)
|
||||||
|
row.Cells[i].AddParagraph(rowParameters.Text[i]);
|
||||||
|
if (!string.IsNullOrEmpty(rowParameters.Style)) {
|
||||||
|
row.Cells[i].Style = rowParameters.Style;
|
||||||
|
}
|
||||||
|
Unit borderWidth = 0.5;
|
||||||
|
row.Cells[i].Borders.Left.Width = borderWidth;
|
||||||
|
row.Cells[i].Borders.Right.Width = borderWidth;
|
||||||
|
row.Cells[i].Borders.Top.Width = borderWidth;
|
||||||
|
row.Cells[i].Borders.Bottom.Width = borderWidth;
|
||||||
|
|
||||||
|
row.Cells[i].Format.Alignment = GetParagraphAlignment(rowParameters.alignmentType);
|
||||||
|
row.Cells[i].VerticalAlignment = VerticalAlignment.Center;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void CreateTable(List<string> columns) {
|
||||||
|
if (_document == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_table = _document.LastSection.AddTable();
|
||||||
|
foreach (var elem in columns) {
|
||||||
|
_table.AddColumn(elem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void CretePdf(PdfInfoClient info) {
|
||||||
|
_document = new Document();
|
||||||
|
DefineStyles(_document);
|
||||||
|
// Ссылка нп первую секцию
|
||||||
|
_section = _document.AddSection();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override PdfDocument SavePdf(PdfInfoClient info) {
|
||||||
|
var renderer = new PdfDocumentRenderer(true) {
|
||||||
|
Document = _document,
|
||||||
|
};
|
||||||
|
renderer.RenderDocument();
|
||||||
|
renderer.PdfDocument.Save(info.FileName);
|
||||||
|
return renderer.PdfDocument;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,5 @@
|
|||||||
using System;
|
using MigraDoc.DocumentObjectModel;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
@ -11,5 +12,6 @@ namespace ElectronicsShopContracts.BindingModels
|
|||||||
public string MailAddress { get; set; } = string.Empty;
|
public string MailAddress { get; set; } = string.Empty;
|
||||||
public string Subject { get; set; } = string.Empty;
|
public string Subject { get; set; } = string.Empty;
|
||||||
public string Text { get; set; } = string.Empty;
|
public string Text { get; set; } = string.Empty;
|
||||||
|
public byte[]? document { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,8 +10,8 @@ namespace ElectronicsShopContracts.BindingModels
|
|||||||
{
|
{
|
||||||
public class ReportBindingModel
|
public class ReportBindingModel
|
||||||
{
|
{
|
||||||
public string FileName { get; set; } = string.Empty;
|
public string ClientEmail { get; set; } = string.Empty;
|
||||||
public DateTime? DateFrom { get; set; }
|
public DateTime DateFrom { get; set; }
|
||||||
public DateTime? DateTo { get; set; }
|
public DateTime DateTo { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
using DocumentFormat.OpenXml.Packaging;
|
using ElectronicsShopContracts.BindingModels;
|
||||||
using ElectronicsShopContracts.BindingModels;
|
|
||||||
using ElectronicsShopContracts.ViewModels;
|
using ElectronicsShopContracts.ViewModels;
|
||||||
|
using MigraDoc.DocumentObjectModel;
|
||||||
|
using PdfSharp.Pdf;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@ -12,12 +13,17 @@ namespace ElectronicsShopContracts.BusinessLogicContracts
|
|||||||
public interface IReportClientLogic
|
public interface IReportClientLogic
|
||||||
{
|
{
|
||||||
// получение списка товаров с указанием, в какие оплаты товар входит
|
// получение списка товаров с указанием, в какие оплаты товар входит
|
||||||
List<ReportPaymeantProductsViewModel> GetPaymeantProducts(int _clientID);
|
List<ReportPaymeantProductsViewModel>? GetPaymeantProducts(int _clientID);
|
||||||
// получения списка оплат
|
// получения списка оплат
|
||||||
List<ReportPaymeantsViewModel> GetPaymeants(ReportBindingModel model);
|
List<ReportPaymeantsViewModel>? GetPaymeants(ReportBindingModel model);
|
||||||
byte[] SavePaymeantToWordFile(int _clientID);
|
|
||||||
|
|
||||||
// Сохранение компонент с указанием отчета в .excel
|
// Сохранение отчета оплат в .word
|
||||||
byte[] SavePaymeantToExcelFile(int _clientID);
|
byte[]? SavePaymeantToWordFile(int _clientID);
|
||||||
|
|
||||||
|
// Сохранение отчета оплат с товарами в .excel
|
||||||
|
byte[]? SavePaymeantToExcelFile(int _clientID);
|
||||||
|
|
||||||
|
// Отчет оплаченных товаров в .pdf
|
||||||
|
PdfDocument SaveProductToPdfFile(ReportBindingModel model);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="DocumentFormat.OpenXml" Version="3.0.2" />
|
<PackageReference Include="DocumentFormat.OpenXml" Version="3.0.2" />
|
||||||
|
<PackageReference Include="PdfSharp.MigraDoc.Standard" Version="1.51.15" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -9,7 +9,9 @@ namespace ElectronicsShopContracts.ViewModels
|
|||||||
{
|
{
|
||||||
public class ReportProductsViewModel
|
public class ReportProductsViewModel
|
||||||
{
|
{
|
||||||
|
public int ID { get; set; }
|
||||||
public string ProductName { get; set; } = string.Empty;
|
public string ProductName { get; set; } = string.Empty;
|
||||||
public List<ProductViewModel> Products { get; set; } = new();
|
public double Price { get; set; }
|
||||||
|
public string CostItemName { get; set; } = string.Empty;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,14 @@
|
|||||||
using DocumentFormat.OpenXml.Drawing.Diagrams;
|
using DocumentFormat.OpenXml.Drawing.Diagrams;
|
||||||
using DocumentFormat.OpenXml.Packaging;
|
using DocumentFormat.OpenXml.Packaging;
|
||||||
|
using ElectronicsShopBusinessLogic.BusinessLogic;
|
||||||
|
using ElectronicsShopBusinessLogic.MailWorker;
|
||||||
using ElectronicsShopContracts.BindingModels;
|
using ElectronicsShopContracts.BindingModels;
|
||||||
using ElectronicsShopContracts.BusinessLogicContracts;
|
using ElectronicsShopContracts.BusinessLogicContracts;
|
||||||
using ElectronicsShopContracts.SearchModels;
|
using ElectronicsShopContracts.SearchModels;
|
||||||
using ElectronicsShopContracts.ViewModels;
|
using ElectronicsShopContracts.ViewModels;
|
||||||
|
using ElectronicsShopDataBaseImplement.Models;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using MigraDoc.Rendering;
|
||||||
|
|
||||||
namespace ElectronicsShopRestAPI.Controllers {
|
namespace ElectronicsShopRestAPI.Controllers {
|
||||||
|
|
||||||
@ -17,12 +21,15 @@ namespace ElectronicsShopRestAPI.Controllers {
|
|||||||
private readonly IClientLogic _logic;
|
private readonly IClientLogic _logic;
|
||||||
private readonly IPaymeantLogic _payLogic;
|
private readonly IPaymeantLogic _payLogic;
|
||||||
private readonly IReportClientLogic _reportLogic;
|
private readonly IReportClientLogic _reportLogic;
|
||||||
|
private readonly AbstractMailWorker _mailWorker;
|
||||||
|
|
||||||
public ClientController(ILogger<ClientController> logger, IClientLogic logic, IPaymeantLogic payLogic, IReportClientLogic reportlogic) {
|
public ClientController(ILogger<ClientController> logger, IClientLogic logic, IPaymeantLogic payLogic, IReportClientLogic reportlogic,
|
||||||
|
AbstractMailWorker mailWorker) {
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_logic = logic;
|
_logic = logic;
|
||||||
_payLogic = payLogic;
|
_payLogic = payLogic;
|
||||||
_reportLogic = reportlogic;
|
_reportLogic = reportlogic;
|
||||||
|
_mailWorker = mailWorker;
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
@ -81,11 +88,11 @@ namespace ElectronicsShopRestAPI.Controllers {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public List<ReportPaymeantsViewModel>? GetReport(DateTime _start, DateTime _end) {
|
public List<ReportPaymeantsViewModel>? GetReport(string _start,string _end) {
|
||||||
try {
|
try {
|
||||||
var dataSource = _reportLogic.GetPaymeants(new ReportBindingModel {
|
var dataSource = _reportLogic.GetPaymeants(new ReportBindingModel {
|
||||||
DateFrom = _start,
|
DateFrom = DateTime.Parse(_start),
|
||||||
DateTo = _end
|
DateTo = DateTime.Parse(_end)
|
||||||
});
|
});
|
||||||
return dataSource;
|
return dataSource;
|
||||||
}
|
}
|
||||||
@ -118,5 +125,31 @@ namespace ElectronicsShopRestAPI.Controllers {
|
|||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public void SendReportMail (ReportBindingModel model) {
|
||||||
|
try {
|
||||||
|
|
||||||
|
var doc = _reportLogic.SaveProductToPdfFile(model);
|
||||||
|
|
||||||
|
MemoryStream stream = new MemoryStream();
|
||||||
|
doc.Save(stream, true);
|
||||||
|
byte[] data = stream.ToArray();
|
||||||
|
|
||||||
|
|
||||||
|
_mailWorker.MailSendAsync(new() {
|
||||||
|
MailAddress = model.ClientEmail,
|
||||||
|
Subject = "Отчет",
|
||||||
|
Text = $"Отчет оплаченных товаров с {model.DateFrom} по {model.DateTo}",
|
||||||
|
document = data
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception ex) {
|
||||||
|
_logger.LogError(ex, $"Ошибка создания файла");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,7 @@ builder.Services.AddTransient<AbstractSaveToExcelClient, SaveToExcelClient>();
|
|||||||
builder.Services.AddTransient<AbstractSaveToExcelEmployee, SaveToExcelEmployee>();
|
builder.Services.AddTransient<AbstractSaveToExcelEmployee, SaveToExcelEmployee>();
|
||||||
builder.Services.AddTransient<AbstractSaveToWordClient, SaveToWordClient>();
|
builder.Services.AddTransient<AbstractSaveToWordClient, SaveToWordClient>();
|
||||||
builder.Services.AddTransient<AbstractSaveToWordEmployee, SaveToWordEmployee>();
|
builder.Services.AddTransient<AbstractSaveToWordEmployee, SaveToWordEmployee>();
|
||||||
|
builder.Services.AddTransient<AbstractSaveToPdfClient, SaveToPdfClient>();
|
||||||
|
|
||||||
builder.Services.AddTransient<IClientLogic, ClientLogic>();
|
builder.Services.AddTransient<IClientLogic, ClientLogic>();
|
||||||
builder.Services.AddTransient<IEmployeeLogic, EmployeeLogic>();
|
builder.Services.AddTransient<IEmployeeLogic, EmployeeLogic>();
|
||||||
|
BIN
ElectronicsShop/ElectronicsShopRestAPI/Report
Normal file
BIN
ElectronicsShop/ElectronicsShopRestAPI/Report
Normal file
Binary file not shown.
Binary file not shown.
@ -9,6 +9,7 @@ using ElectronicsShopUserApp.Models;
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using System.Globalization;
|
||||||
using System.Net.Mime;
|
using System.Net.Mime;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Runtime.Serialization;
|
using System.Runtime.Serialization;
|
||||||
@ -215,28 +216,23 @@ namespace ElectronicsShopUserApp.Controllers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public IActionResult Message()
|
public IActionResult Message() {
|
||||||
{
|
|
||||||
//ViewBag.Reports = APIClient.GetRequset<List<ProductViewModel>>($"api/main/getproducts"); Ïèñåì òàê æå ïîêà íåìà
|
//ViewBag.Reports = APIClient.GetRequset<List<ProductViewModel>>($"api/main/getproducts"); Ïèñåì òàê æå ïîêà íåìà
|
||||||
return View();
|
return View();
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public IActionResult Payment(int id)
|
public IActionResult Payment(int id) {
|
||||||
{
|
if (APIClient.Client == null) {
|
||||||
if (APIClient.Client == null)
|
|
||||||
{
|
|
||||||
return Redirect("~/Home/Enter");
|
return Redirect("~/Home/Enter");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (id == 0)
|
if (id == 0) {
|
||||||
{
|
|
||||||
return Redirect("~/Home/Index");
|
return Redirect("~/Home/Index");
|
||||||
}
|
}
|
||||||
var products = APIClient.GetRequset<List<List<string>>>($"api/main/getorderproducts?_orderid={id}");
|
var products = APIClient.GetRequset<List<List<string>>>($"api/main/getorderproducts?_orderid={id}");
|
||||||
|
|
||||||
foreach (var pr in products)
|
foreach (var pr in products) {
|
||||||
{
|
|
||||||
var product = JsonConvert.DeserializeObject<ProductViewModel>(pr[0]);
|
var product = JsonConvert.DeserializeObject<ProductViewModel>(pr[0]);
|
||||||
int count = JsonConvert.DeserializeObject<int>(pr[1]);
|
int count = JsonConvert.DeserializeObject<int>(pr[1]);
|
||||||
_productList.Add(product.ID, (product, count));
|
_productList.Add(product.ID, (product, count));
|
||||||
@ -299,14 +295,15 @@ namespace ElectronicsShopUserApp.Controllers {
|
|||||||
if (DateTo == DateTime.MinValue || DateFrom > DateTo) {
|
if (DateTo == DateTime.MinValue || DateFrom > DateTo) {
|
||||||
throw new Exception("Íåêîðåêòíî óêàçàí âðåìåííîé èíòåðâàë");
|
throw new Exception("Íåêîðåêòíî óêàçàí âðåìåííîé èíòåðâàë");
|
||||||
}
|
}
|
||||||
Response.Redirect($"ReportSearch?_datefrom={DateFrom}&_dateTo={DateTo}");
|
Response.Redirect($"ReportSearch?_datefrom={DateFrom}&_dateto={DateTo}");
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public IActionResult ReportSearch(DateTime _datefrom, DateTime _dateto) {
|
public IActionResult ReportSearch(string _datefrom, string _dateto) {
|
||||||
|
|
||||||
var reports = APIClient.GetRequset<List<PaymeantViewModel>>($"api/client/getreport?_start={_datefrom}&_end={_dateto}");
|
var reports = APIClient.GetRequset<List<PaymeantViewModel>>($"api/client/getreport?_start={_datefrom}&_end={_dateto}");
|
||||||
|
|
||||||
(DateTime, DateTime, List<PaymeantViewModel>) tuple = (_datefrom, _dateto, reports);
|
(DateTime, DateTime, List<PaymeantViewModel>?) tuple = (DateTime.Parse(_datefrom), DateTime.Parse(_dateto), reports);
|
||||||
return View(tuple);
|
return View(tuple);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -331,5 +328,15 @@ namespace ElectronicsShopUserApp.Controllers {
|
|||||||
|
|
||||||
return File(fileMemStream, "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "Report.docx");
|
return File(fileMemStream, "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "Report.docx");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
public IActionResult CreatePdfReport(string DateFrom, string DateTo) {
|
||||||
|
APIClient.PostRequest("api/client/SendReportMail", new ReportBindingModel {
|
||||||
|
ClientEmail = APIClient.Client.Email,
|
||||||
|
DateFrom = DateTime.Parse(DateFrom),
|
||||||
|
DateTo = DateTime.Parse(DateTo)
|
||||||
|
});
|
||||||
|
return View("Report");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -27,7 +27,8 @@
|
|||||||
<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;">отправить на Email отчет в .pdf</a>
|
<a class="btn btn-primary btn-sm" asp-action="CreatePdfReport" asp-route-DateFrom="@Model.Item1"
|
||||||
|
asp-route-DateTo="@Model.Item2" style="background-color:#ad0d09;">отправить на Email отчет в .pdf</a>
|
||||||
</div>
|
</div>
|
||||||
</h1>
|
</h1>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user