revert 995ad1931049017b0889d926ea2d433a88919cff

revert Лабораторная работа 3 (со всеми изменениями)
This commit is contained in:
Есения Андрианова 2024-12-15 10:41:47 +04:00
parent 995ad19310
commit 6e8e5acbd8
5 changed files with 30 additions and 25 deletions

View File

@ -4,8 +4,8 @@ using Microsoft.Extensions.Logging;
internal class ChartReport internal class ChartReport
{ {
private readonly ICheckRepository _checkRepository; private readonly ICheckRepository _checkRepository; // Репозиторий для получения данных о чеках
private readonly IProductRepository _productRepository; private readonly IProductRepository _productRepository; // Репозиторий для получения данных о продуктах
private readonly ILogger<ChartReport> _logger; private readonly ILogger<ChartReport> _logger;
public ChartReport(ICheckRepository checkRepository, IProductRepository productRepository, ILoggerFactory loggerFactory) public ChartReport(ICheckRepository checkRepository, IProductRepository productRepository, ILoggerFactory loggerFactory)
@ -21,7 +21,7 @@ internal class ChartReport
{ {
new PdfBuilder(filePath) new PdfBuilder(filePath)
.AddHeader("Отчет по продажам товаров") .AddHeader("Отчет по продажам товаров")
.AddPieChart("Проданные товары", GetData(dateTime)) .AddPieChart("Проданные товары", GetData(dateTime)) // Диаграмма с продуктами
.Build(); .Build();
return true; return true;
@ -35,17 +35,17 @@ internal class ChartReport
private List<(string Caption, double Value)> GetData(DateTime dateTime) private List<(string Caption, double Value)> GetData(DateTime dateTime)
{ {
// Получаем все чеки, которые были оформлены в указанную дату
var checkData = _checkRepository var checkData = _checkRepository
.ReadAll() .ReadAll()
.Where(x => x.PurchaseDate.Date == dateTime.Date) .Where(x => x.PurchaseDate.Date == dateTime.Date) // Фильтрация по дате
.SelectMany(x => x.Products) .SelectMany(x => x.Products) // Получаем все продукты из всех чеков
.GroupBy(p => p.ProductID) .GroupBy(p => p.ProductID) // Группируем по ID продукта
.Select(g => .Select(g =>
{ {
// Получаем продукт по ProductID
var product = _productRepository.Read(g.Key); var product = _productRepository.Read(g.Key);
return (Caption: product.Name, Value: (double)g.Sum(p => p.Count)); return (Caption: product.Name, Value: (double)g.Sum(p => p.Count)); // Преобразуем Count в double
}) })
.ToList(); .ToList();

View File

@ -84,10 +84,10 @@ namespace CompShop.DocumentsBuilder
CustomWidth = true CustomWidth = true
})); }));
// Добавляем строки таблицы
for (int i = 0; i < data.Count; ++i) for (int i = 0; i < data.Count; ++i)
{ {
var isBoldRow = i == 0 || i == data.Count - 1; var isBoldRow = i == 0 || i == data.Count - 1; // Только заголовок и последняя строка жирные
var styleIndex = isBoldRow ? StyleIndex.BoldTextWithBorders : StyleIndex.SimpleTextWithBorders; var styleIndex = isBoldRow ? StyleIndex.BoldTextWithBorders : StyleIndex.SimpleTextWithBorders;
for (int j = 0; j < data[i].Length; ++j) for (int j = 0; j < data[i].Length; ++j)
@ -143,6 +143,7 @@ namespace CompShop.DocumentsBuilder
var workbookStylesPart = workbookPart.AddNewPart<WorkbookStylesPart>(); var workbookStylesPart = workbookPart.AddNewPart<WorkbookStylesPart>();
workbookStylesPart.Stylesheet = new Stylesheet(); workbookStylesPart.Stylesheet = new Stylesheet();
// Шрифты
var fonts = new Fonts() { Count = 2 }; var fonts = new Fonts() { Count = 2 };
fonts.Append(new DocumentFormat.OpenXml.Spreadsheet.Font fonts.Append(new DocumentFormat.OpenXml.Spreadsheet.Font
{ {
@ -156,16 +157,16 @@ namespace CompShop.DocumentsBuilder
FontName = new FontName() { Val = "Calibri" } FontName = new FontName() { Val = "Calibri" }
}); });
// Заполнение
var fills = new Fills() { Count = 1 }; var fills = new Fills() { Count = 1 };
fills.Append(new Fill fills.Append(new Fill
{ {
PatternFill = new PatternFill { PatternType = PatternValues.None } PatternFill = new PatternFill { PatternType = PatternValues.None }
}); });
// Границы
var borders = new Borders() { Count = 2 }; var borders = new Borders() { Count = 2 };
borders.Append(new Border()); borders.Append(new Border()); // Без границ
borders.Append(new Border borders.Append(new Border
{ {
LeftBorder = new LeftBorder { Style = BorderStyleValues.Thin }, LeftBorder = new LeftBorder { Style = BorderStyleValues.Thin },
@ -174,7 +175,7 @@ namespace CompShop.DocumentsBuilder
BottomBorder = new BottomBorder { Style = BorderStyleValues.Thin } BottomBorder = new BottomBorder { Style = BorderStyleValues.Thin }
}); });
// Форматы ячеек
var cellFormats = new CellFormats() { Count = 4 }; var cellFormats = new CellFormats() { Count = 4 };
cellFormats.Append(new CellFormat cellFormats.Append(new CellFormat
{ {
@ -182,14 +183,14 @@ namespace CompShop.DocumentsBuilder
FillId = 0, FillId = 0,
BorderId = 0, BorderId = 0,
ApplyFont = true ApplyFont = true
}); }); // Обычный текст без границ
cellFormats.Append(new CellFormat cellFormats.Append(new CellFormat
{ {
FontId = 1, FontId = 1,
FillId = 0, FillId = 0,
BorderId = 0, BorderId = 0,
ApplyFont = true ApplyFont = true
}); }); // Жирный текст без границ
cellFormats.Append(new CellFormat cellFormats.Append(new CellFormat
{ {
FontId = 0, FontId = 0,
@ -197,7 +198,7 @@ namespace CompShop.DocumentsBuilder
BorderId = 1, BorderId = 1,
ApplyFont = true, ApplyFont = true,
ApplyBorder = true ApplyBorder = true
}); }); // Обычный текст с границами
cellFormats.Append(new CellFormat cellFormats.Append(new CellFormat
{ {
FontId = 1, FontId = 1,
@ -205,7 +206,7 @@ namespace CompShop.DocumentsBuilder
BorderId = 1, BorderId = 1,
ApplyFont = true, ApplyFont = true,
ApplyBorder = true ApplyBorder = true
}); }); // Жирный текст с границами
workbookStylesPart.Stylesheet.Append(fonts); workbookStylesPart.Stylesheet.Append(fonts);
workbookStylesPart.Stylesheet.Append(fills); workbookStylesPart.Stylesheet.Append(fills);

View File

@ -1,6 +1,10 @@
using MigraDoc.DocumentObjectModel; using MigraDoc.DocumentObjectModel;
using MigraDoc.DocumentObjectModel.Shapes.Charts; using MigraDoc.DocumentObjectModel.Shapes.Charts;
using MigraDoc.Rendering; using MigraDoc.Rendering;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Chart = MigraDoc.DocumentObjectModel.Shapes.Charts.Chart; using Chart = MigraDoc.DocumentObjectModel.Shapes.Charts.Chart;

View File

@ -38,7 +38,7 @@ internal class TableReport
private List<string[]> GetData(int productId, DateTime startDate, DateTime endDate) private List<string[]> GetData(int productId, DateTime startDate, DateTime endDate)
{ {
// Получение данных о чеках, содержащих указанный товар
var checksWithProduct = _checkRepository var checksWithProduct = _checkRepository
.ReadAll() .ReadAll()
.Where(c => c.PurchaseDate >= startDate && c.PurchaseDate <= endDate .Where(c => c.PurchaseDate >= startDate && c.PurchaseDate <= endDate
@ -53,7 +53,7 @@ internal class TableReport
}) })
.OrderBy(x => x.Date); .OrderBy(x => x.Date);
// Формирование итоговой таблицы
return new List<string[]> { Headers } return new List<string[]> { Headers }
.Union( .Union(
checksWithProduct.Select(x => new string[] checksWithProduct.Select(x => new string[]

View File

@ -35,12 +35,12 @@ namespace CompShop.DocumentsBuilder
var paragraph = _body.AppendChild(new Paragraph()); var paragraph = _body.AppendChild(new Paragraph());
var run = paragraph.AppendChild(new Run()); var run = paragraph.AppendChild(new Run());
// Добавляем свойства для жирного текста
var runProperties = new RunProperties(); var runProperties = new RunProperties();
runProperties.AppendChild(new Bold()); runProperties.AppendChild(new Bold());
run.PrependChild(runProperties); run.PrependChild(runProperties);
// Добавляем текст заголовка
run.AppendChild(new Text(header)); run.AppendChild(new Text(header));
return this; return this;
@ -109,7 +109,7 @@ namespace CompShop.DocumentsBuilder
) )
)); ));
// Заголовок
var tr = new TableRow(); var tr = new TableRow();
for (var j = 0; j < widths.Length; ++j) for (var j = 0; j < widths.Length; ++j)
{ {
@ -124,7 +124,7 @@ namespace CompShop.DocumentsBuilder
} }
table.Append(tr); table.Append(tr);
// Данные
table.Append(data.Skip(1).Select(x => table.Append(data.Skip(1).Select(x =>
new TableRow(x.Select(y => new TableCell(new Paragraph(new new TableRow(x.Select(y => new TableCell(new Paragraph(new
Run(new Text(y)))))))); Run(new Text(y))))))));