Pdf report implement & ReportLogic

This commit is contained in:
ShabOl 2024-05-05 22:32:34 +04:00
parent 10a344f0b1
commit 22b2783547
4 changed files with 88 additions and 9 deletions

View File

@ -13,16 +13,18 @@ namespace AutoWorkshopBusinessLogic.BusinessLogics
private readonly IComponentStorage _componentStorage;
private readonly IRepairStorage _RepairStorage;
private readonly IOrderStorage _orderStorage;
private readonly IShopStorage _shopStorage;
private readonly AbstractSaveToExcel _saveToExcel;
private readonly AbstractSaveToWord _saveToWord;
private readonly AbstractSaveToPdf _saveToPdf;
public ReportLogic(IRepairStorage RepairStorage, IComponentStorage ComponentStorage, IOrderStorage OrderStorage,
public ReportLogic(IRepairStorage RepairStorage, IComponentStorage ComponentStorage, IOrderStorage OrderStorage, IShopStorage ShopStorage,
AbstractSaveToExcel SaveToExcel, AbstractSaveToWord SaveToWord, AbstractSaveToPdf SaveToPdf)
{
_RepairStorage = RepairStorage;
_componentStorage = ComponentStorage;
_orderStorage = OrderStorage;
_shopStorage = ShopStorage;
_saveToExcel = SaveToExcel;
_saveToWord = SaveToWord;
@ -41,6 +43,26 @@ namespace AutoWorkshopBusinessLogic.BusinessLogics
.ToList();
}
public List<ReportShopsViewModel> GetShops()
{
return _shopStorage.GetFullList().Select(x => new ReportShopsViewModel
{
ShopName = x.ShopName,
Repairs = x.ShopRepairs.Select(x => (x.Value.Item1.RepairName, x.Value.Item2)).ToList(),
TotalCount = x.ShopRepairs.Select(x => x.Value.Item2).Sum()
}).ToList();
}
public List<ReportGroupedOrdersViewModel> GetGroupedOrders()
{
return _orderStorage.GetFullList().GroupBy(x => x.DateCreate.Date).Select(x => new ReportGroupedOrdersViewModel
{
Date = x.Key,
OrdersCount = x.Count(),
OrdersSum = x.Select(y => y.Sum).Sum()
}).ToList();
}
public List<ReportOrdersViewModel> GetOrders(ReportBindingModel Model)
{
return _orderStorage.GetFilteredList(new OrderSearchModel { DateFrom = Model.DateFrom, DateTo = Model.DateTo })
@ -77,7 +99,7 @@ namespace AutoWorkshopBusinessLogic.BusinessLogics
public void SaveOrdersToPdfFile(ReportBindingModel Model)
{
_saveToPdf.CreateDoc(new PdfInfo
_saveToPdf.CreateDoc(new PdfOrdersInfo
{
FileName = Model.FileName,
Title = "Список заказов",
@ -86,5 +108,35 @@ namespace AutoWorkshopBusinessLogic.BusinessLogics
Orders = GetOrders(Model)
});
}
public void SaveShopsToWordFile(ReportBindingModel model)
{
_saveToWord.CreateShopsDoc(new WordShopsInfo
{
FileName = model.FileName,
Title = "Список магазинов",
Shops = _shopStorage.GetFullList()
});
}
public void SaveShopsToExcelFile(ReportBindingModel model)
{
_saveToExcel.CreateShopPizzasReport(new ExcelShopsInfo
{
FileName = model.FileName,
Title = "Загруженность магазинов",
ShopRepairs = GetShops()
});
}
public void SaveGroupedOrdersToPdfFile(ReportBindingModel model)
{
_saveToPdf.CreateGroupedOrdersDoc(new PdfGroupedOrdersInfo
{
FileName = model.FileName,
Title = "Список заказов, объединенных по датам",
GroupedOrders = GetGroupedOrders()
});
}
}
}

View File

@ -5,7 +5,7 @@ namespace AutoWorkshopBusinessLogic.OfficePackage
{
public abstract class AbstractSaveToPdf
{
public void CreateDoc(PdfInfo Info)
public void CreateDoc(PdfOrdersInfo Info)
{
CreatePdf(Info);
CreateParagraph(new PdfParagraph { Text = Info.Title, Style = "NormalTitle", ParagraphAlignment = PdfParagraphAlignmentType.Center });
@ -33,8 +33,35 @@ namespace AutoWorkshopBusinessLogic.OfficePackage
SavePdf(Info);
}
protected abstract void CreatePdf(PdfInfo Info);
public void CreateGroupedOrdersDoc(PdfGroupedOrdersInfo Info)
{
CreatePdf(Info);
CreateParagraph(new PdfParagraph { Text = Info.Title, Style = "NormalTitle", ParagraphAlignment = PdfParagraphAlignmentType.Center });
CreateTable(new List<string> { "4cm", "3cm", "2cm" });
CreateRow(new PdfRowParameters
{
Texts = new List<string> { "Дата заказа", "Кол-во", "Сумма" },
Style = "NormalTitle",
ParagraphAlignment = PdfParagraphAlignmentType.Center
});
foreach (var groupedOrder in Info.GroupedOrders)
{
CreateRow(new PdfRowParameters
{
Texts = new List<string> { groupedOrder.Date.ToShortDateString(), groupedOrder.OrdersCount.ToString(), groupedOrder.OrdersSum.ToString() },
Style = "Normal",
ParagraphAlignment = PdfParagraphAlignmentType.Left
});
}
CreateParagraph(new PdfParagraph { Text = $"Итого: {Info.GroupedOrders.Sum(x => x.OrdersSum)}\t", Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Center });
SavePdf(Info);
}
protected abstract void CreatePdf(IDocumentInfo Info);
protected abstract void CreateParagraph(PdfParagraph Paragraph);
@ -42,6 +69,6 @@ namespace AutoWorkshopBusinessLogic.OfficePackage
protected abstract void CreateRow(PdfRowParameters RowParameters);
protected abstract void SavePdf(PdfInfo Info);
protected abstract void SavePdf(IDocumentInfo Info);
}
}

View File

@ -2,7 +2,7 @@
namespace AutoWorkshopBusinessLogic.OfficePackage.HelperModels
{
public class PdfInfo
public class PdfOrdersInfo : IDocumentInfo
{
public string FileName { get; set; } = string.Empty;

View File

@ -33,7 +33,7 @@ namespace AutoWorkshopBusinessLogic.OfficePackage.Implements
Style.Font.Bold = true;
}
protected override void CreatePdf(PdfInfo Info)
protected override void CreatePdf(IDocumentInfo Info)
{
_document = new Document();
DefineStyles(_document);
@ -94,7 +94,7 @@ namespace AutoWorkshopBusinessLogic.OfficePackage.Implements
}
}
protected override void SavePdf(PdfInfo Info)
protected override void SavePdf(IDocumentInfo Info)
{
var Renderer = new PdfDocumentRenderer(true)
{