diff --git a/CompShop/CompShop/DocumentsBuilder/ChartReport.cs b/CompShop/CompShop/DocumentsBuilder/ChartReport.cs index 163a597..060f1cb 100644 --- a/CompShop/CompShop/DocumentsBuilder/ChartReport.cs +++ b/CompShop/CompShop/DocumentsBuilder/ChartReport.cs @@ -4,8 +4,8 @@ using Microsoft.Extensions.Logging; internal class ChartReport { - private readonly ICheckRepository _checkRepository; // Репозиторий для получения данных о чеках - private readonly IProductRepository _productRepository; // Репозиторий для получения данных о продуктах + private readonly ICheckRepository _checkRepository; + private readonly IProductRepository _productRepository; private readonly ILogger _logger; public ChartReport(ICheckRepository checkRepository, IProductRepository productRepository, ILoggerFactory loggerFactory) @@ -21,7 +21,7 @@ internal class ChartReport { new PdfBuilder(filePath) .AddHeader("Отчет по продажам товаров") - .AddPieChart("Проданные товары", GetData(dateTime)) // Диаграмма с продуктами + .AddPieChart("Проданные товары", GetData(dateTime)) .Build(); return true; @@ -35,17 +35,17 @@ internal class ChartReport private List<(string Caption, double Value)> GetData(DateTime dateTime) { - // Получаем все чеки, которые были оформлены в указанную дату + var checkData = _checkRepository .ReadAll() - .Where(x => x.PurchaseDate.Date == dateTime.Date) // Фильтрация по дате - .SelectMany(x => x.Products) // Получаем все продукты из всех чеков - .GroupBy(p => p.ProductID) // Группируем по ID продукта + .Where(x => x.PurchaseDate.Date == dateTime.Date) + .SelectMany(x => x.Products) + .GroupBy(p => p.ProductID) .Select(g => { - // Получаем продукт по ProductID + var product = _productRepository.Read(g.Key); - return (Caption: product.Name, Value: (double)g.Sum(p => p.Count)); // Преобразуем Count в double + return (Caption: product.Name, Value: (double)g.Sum(p => p.Count)); }) .ToList(); diff --git a/CompShop/CompShop/DocumentsBuilder/ExcelBuilder.cs b/CompShop/CompShop/DocumentsBuilder/ExcelBuilder.cs index b8aac0f..3ebbae9 100644 --- a/CompShop/CompShop/DocumentsBuilder/ExcelBuilder.cs +++ b/CompShop/CompShop/DocumentsBuilder/ExcelBuilder.cs @@ -84,10 +84,10 @@ namespace CompShop.DocumentsBuilder CustomWidth = true })); - // Добавляем строки таблицы + 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; for (int j = 0; j < data[i].Length; ++j) @@ -143,7 +143,6 @@ namespace CompShop.DocumentsBuilder var workbookStylesPart = workbookPart.AddNewPart(); workbookStylesPart.Stylesheet = new Stylesheet(); - // Шрифты var fonts = new Fonts() { Count = 2 }; fonts.Append(new DocumentFormat.OpenXml.Spreadsheet.Font { @@ -157,16 +156,16 @@ namespace CompShop.DocumentsBuilder FontName = new FontName() { Val = "Calibri" } }); - // Заполнение + var fills = new Fills() { Count = 1 }; fills.Append(new Fill { PatternFill = new PatternFill { PatternType = PatternValues.None } }); - // Границы + var borders = new Borders() { Count = 2 }; - borders.Append(new Border()); // Без границ + borders.Append(new Border()); borders.Append(new Border { LeftBorder = new LeftBorder { Style = BorderStyleValues.Thin }, @@ -175,7 +174,7 @@ namespace CompShop.DocumentsBuilder BottomBorder = new BottomBorder { Style = BorderStyleValues.Thin } }); - // Форматы ячеек + var cellFormats = new CellFormats() { Count = 4 }; cellFormats.Append(new CellFormat { @@ -183,14 +182,14 @@ namespace CompShop.DocumentsBuilder FillId = 0, BorderId = 0, ApplyFont = true - }); // Обычный текст без границ + }); cellFormats.Append(new CellFormat { FontId = 1, FillId = 0, BorderId = 0, ApplyFont = true - }); // Жирный текст без границ + }); cellFormats.Append(new CellFormat { FontId = 0, @@ -198,7 +197,7 @@ namespace CompShop.DocumentsBuilder BorderId = 1, ApplyFont = true, ApplyBorder = true - }); // Обычный текст с границами + }); cellFormats.Append(new CellFormat { FontId = 1, @@ -206,7 +205,7 @@ namespace CompShop.DocumentsBuilder BorderId = 1, ApplyFont = true, ApplyBorder = true - }); // Жирный текст с границами + }); workbookStylesPart.Stylesheet.Append(fonts); workbookStylesPart.Stylesheet.Append(fills); diff --git a/CompShop/CompShop/DocumentsBuilder/PdfBuilder.cs b/CompShop/CompShop/DocumentsBuilder/PdfBuilder.cs index edb7136..73f21e2 100644 --- a/CompShop/CompShop/DocumentsBuilder/PdfBuilder.cs +++ b/CompShop/CompShop/DocumentsBuilder/PdfBuilder.cs @@ -1,10 +1,6 @@ using MigraDoc.DocumentObjectModel; using MigraDoc.DocumentObjectModel.Shapes.Charts; using MigraDoc.Rendering; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; using System.Threading.Tasks; using Chart = MigraDoc.DocumentObjectModel.Shapes.Charts.Chart; diff --git a/CompShop/CompShop/DocumentsBuilder/TableReport.cs b/CompShop/CompShop/DocumentsBuilder/TableReport.cs index 938cfb1..03b476b 100644 --- a/CompShop/CompShop/DocumentsBuilder/TableReport.cs +++ b/CompShop/CompShop/DocumentsBuilder/TableReport.cs @@ -38,7 +38,7 @@ internal class TableReport private List GetData(int productId, DateTime startDate, DateTime endDate) { - // Получение данных о чеках, содержащих указанный товар + var checksWithProduct = _checkRepository .ReadAll() .Where(c => c.PurchaseDate >= startDate && c.PurchaseDate <= endDate @@ -53,7 +53,7 @@ internal class TableReport }) .OrderBy(x => x.Date); - // Формирование итоговой таблицы + return new List { Headers } .Union( checksWithProduct.Select(x => new string[] diff --git a/CompShop/CompShop/DocumentsBuilder/WordBuilder.cs b/CompShop/CompShop/DocumentsBuilder/WordBuilder.cs index ba919d3..df01cbe 100644 --- a/CompShop/CompShop/DocumentsBuilder/WordBuilder.cs +++ b/CompShop/CompShop/DocumentsBuilder/WordBuilder.cs @@ -35,12 +35,12 @@ namespace CompShop.DocumentsBuilder var paragraph = _body.AppendChild(new Paragraph()); var run = paragraph.AppendChild(new Run()); - // Добавляем свойства для жирного текста + var runProperties = new RunProperties(); runProperties.AppendChild(new Bold()); run.PrependChild(runProperties); - // Добавляем текст заголовка + run.AppendChild(new Text(header)); return this; @@ -109,7 +109,7 @@ namespace CompShop.DocumentsBuilder ) )); - // Заголовок + var tr = new TableRow(); for (var j = 0; j < widths.Length; ++j) { @@ -124,7 +124,7 @@ namespace CompShop.DocumentsBuilder } table.Append(tr); - // Данные + table.Append(data.Skip(1).Select(x => new TableRow(x.Select(y => new TableCell(new Paragraph(new Run(new Text(y))))))));