diff --git a/ProjectAutoenterprise/ProjectAutoenterprise/Forms/FormItinerary.cs b/ProjectAutoenterprise/ProjectAutoenterprise/Forms/FormItinerary.cs index b757a9c..8db3e7e 100644 --- a/ProjectAutoenterprise/ProjectAutoenterprise/Forms/FormItinerary.cs +++ b/ProjectAutoenterprise/ProjectAutoenterprise/Forms/FormItinerary.cs @@ -66,7 +66,6 @@ public partial class FormItinerary : Form } list.Add(ItineraryRoute.CreateElement(0,Convert.ToInt32(row.Cells["ColumnRoute"].Value))); } - // DO return list .GroupBy(route => new { route.ItineraryId, route.RouteId }) .Select(group => ItineraryRoute.CreateElement(group.Key.ItineraryId, group.Key.RouteId)) diff --git a/ProjectAutoenterprise/ProjectAutoenterprise/Reports/ExcelBuilder.cs b/ProjectAutoenterprise/ProjectAutoenterprise/Reports/ExcelBuilder.cs index 8d0ed31..bec3562 100644 --- a/ProjectAutoenterprise/ProjectAutoenterprise/Reports/ExcelBuilder.cs +++ b/ProjectAutoenterprise/ProjectAutoenterprise/Reports/ExcelBuilder.cs @@ -29,7 +29,7 @@ internal class ExcelBuilder public ExcelBuilder AddHeader(string header, int startIndex, int count) { - CreateCell(startIndex, _rowIndex, header, StyleIndex.SimpleTextWithoutBorder); + CreateCell(startIndex, _rowIndex, header, StyleIndex.BoldTextWithoutBorder); for (int i = startIndex + 1; i < startIndex + count; ++i) { CreateCell(i, _rowIndex, "", StyleIndex.SimpleTextWithoutBorder); @@ -57,9 +57,9 @@ internal class ExcelBuilder { throw new ArgumentNullException(nameof(data)); } - if (data.Any(x => x.Length > columnsWidths.Length)) + if (data.Any(x => x.Length != columnsWidths.Length)) { - throw new InvalidOperationException("widths.Length != data.Length"); + throw new InvalidOperationException("columnsWidths.Length != data.Length"); } uint counter = 1; int coef = 2; @@ -72,22 +72,20 @@ internal class ExcelBuilder })); for (var j = 0; j < data.First().Length; ++j) { - CreateCell(j, _rowIndex, data.First()[j], - StyleIndex.SimpleTextWithoutBorder); + CreateCell(j, _rowIndex, data.First()[j], StyleIndex.BoldTextWithBorder); } _rowIndex++; for (var i = 1; i < data.Count - 1; ++i) { for (var j = 0; j < data[i].Length; ++j) { - CreateCell(j, _rowIndex, data[i][j], - StyleIndex.SimpleTextWithoutBorder); + CreateCell(j, _rowIndex, data[i][j], StyleIndex.SimpleTextWithBorder); } _rowIndex++; } for (var j = 0; j < data.Last().Length; ++j) { - CreateCell(j, _rowIndex, data.Last()[j], StyleIndex.SimpleTextWithoutBorder); + CreateCell(j, _rowIndex, data.Last()[j], StyleIndex.BoldTextWithBorder); } _rowIndex++; return this; @@ -105,20 +103,17 @@ internal class ExcelBuilder worksheetPart.Worksheet.Append(_columns); } worksheetPart.Worksheet.Append(_sheetData); - var sheets = - spreadsheetDocument.WorkbookPart!.Workbook.AppendChild(new Sheets()); + var sheets = spreadsheetDocument.WorkbookPart!.Workbook.AppendChild(new Sheets()); var sheet = new Sheet() { - Id = - spreadsheetDocument.WorkbookPart.GetIdOfPart(worksheetPart), + Id = spreadsheetDocument.WorkbookPart.GetIdOfPart(worksheetPart), SheetId = 1, Name = "Лист 1" }; sheets.Append(sheet); if (_mergeCells.HasChildren) { - worksheetPart.Worksheet.InsertAfter(_mergeCells, - worksheetPart.Worksheet.Elements().First()); + worksheetPart.Worksheet.InsertAfter(_mergeCells, worksheetPart.Worksheet.Elements().First()); } } private static void GenerateStyle(WorkbookPart workbookPart) @@ -131,33 +126,23 @@ internal class ExcelBuilder FontSize = new FontSize() { Val = 11 }, FontName = new FontName() { Val = "Calibri" }, FontFamilyNumbering = new FontFamilyNumbering() { Val = 2 }, - FontScheme = new FontScheme() - { - Val = new EnumValue(FontSchemeValues.Minor) - } + FontScheme = new FontScheme() { Val = new EnumValue(FontSchemeValues.Minor) } }); - // DO добавить шрифт с жирным fonts.Append(new DocumentFormat.OpenXml.Spreadsheet.Font { FontSize = new FontSize() { Val = 11 }, FontName = new FontName() { Val = "Calibri" }, FontFamilyNumbering = new FontFamilyNumbering() { Val = 2 }, - FontScheme = new FontScheme() - { - Val = new EnumValue(FontSchemeValues.Minor) - }, + FontScheme = new FontScheme() { Val = new EnumValue(FontSchemeValues.Minor) }, Bold = new Bold() { Val = true } }); - // workbookStylesPart.Stylesheet.Append(fonts); // Default Fill var fills = new Fills() { Count = 1 }; fills.Append(new Fill { - PatternFill = new PatternFill() { - PatternType = new EnumValue(PatternValues.None) - } + PatternFill = new PatternFill() { PatternType = new EnumValue(PatternValues.None) } }); workbookStylesPart.Stylesheet.Append(fills); @@ -171,7 +156,6 @@ internal class ExcelBuilder BottomBorder = new BottomBorder(), DiagonalBorder = new DiagonalBorder() }); - // DO добавить настройку с границами borders.Append(new Border { LeftBorder = new LeftBorder() { Style = BorderStyleValues.Thin }, @@ -180,7 +164,6 @@ internal class ExcelBuilder BottomBorder = new BottomBorder() { Style = BorderStyleValues.Thin }, DiagonalBorder = new DiagonalBorder() }); - // workbookStylesPart.Stylesheet.Append(borders); // Default cell format and a date cell format @@ -199,7 +182,35 @@ internal class ExcelBuilder WrapText = true } }); - // DO дополнить форматы + cellFormats.Append(new CellFormat + { + NumberFormatId = 0, + FormatId = 0, + FontId = 0, + BorderId = 1, + FillId = 0, + Alignment = new Alignment() + { + Horizontal = HorizontalAlignmentValues.Center, + Vertical = VerticalAlignmentValues.Center, + WrapText = true + } + }); + + cellFormats.Append(new CellFormat + { + NumberFormatId = 0, + FormatId = 0, + FontId = 1, + BorderId = 0, + FillId = 0, + Alignment = new Alignment() + { + Horizontal = HorizontalAlignmentValues.Center, + Vertical = VerticalAlignmentValues.Center, + WrapText = true + } + }); cellFormats.Append(new CellFormat { NumberFormatId = 0, @@ -214,17 +225,14 @@ internal class ExcelBuilder WrapText = true } }); - // workbookStylesPart.Stylesheet.Append(cellFormats); } private enum StyleIndex { SimpleTextWithoutBorder = 0, - // DO дополнить стили SimpleTextWithBorder = 1, BoldTextWithoutBorder = 2, BoldTextWithBorder = 3, - // } private void CreateCell(int columnIndex, uint rowIndex, string text, StyleIndex styleIndex) { @@ -243,11 +251,9 @@ internal class ExcelBuilder Cell? refCell = null; foreach (Cell cell in row.Elements()) { - if (cell.CellReference?.Value != null && - cell.CellReference.Value.Length == cellReference.Length) + if (cell.CellReference?.Value != null && cell.CellReference.Value.Length == cellReference.Length) { - if (string.Compare(cell.CellReference.Value, - cellReference, true) > 0) + if (string.Compare(cell.CellReference.Value, cellReference, true) > 0) { refCell = cell; break; @@ -270,8 +276,7 @@ internal class ExcelBuilder while (dividend > 0) { modulo = (dividend - 1) % 26; - columnName = Convert.ToChar(65 + modulo).ToString() + - columnName; + columnName = Convert.ToChar(65 + modulo).ToString() + columnName; dividend = (dividend - modulo) / 26; } return columnName; diff --git a/ProjectAutoenterprise/ProjectAutoenterprise/Reports/PdfBuilder.cs b/ProjectAutoenterprise/ProjectAutoenterprise/Reports/PdfBuilder.cs index 4556863..41f1898 100644 --- a/ProjectAutoenterprise/ProjectAutoenterprise/Reports/PdfBuilder.cs +++ b/ProjectAutoenterprise/ProjectAutoenterprise/Reports/PdfBuilder.cs @@ -64,7 +64,6 @@ internal class PdfBuilder } private void DefineStyles() { - // DO задать стиль для заголовка (жирный) var headerStyle = _document.Styles.AddStyle("NormalBold", "Normal"); headerStyle.Font.Bold = true; headerStyle.Font.Size = 14; diff --git a/ProjectAutoenterprise/ProjectAutoenterprise/Reports/TableReport.cs b/ProjectAutoenterprise/ProjectAutoenterprise/Reports/TableReport.cs index 5c30e8e..e74aa44 100644 --- a/ProjectAutoenterprise/ProjectAutoenterprise/Reports/TableReport.cs +++ b/ProjectAutoenterprise/ProjectAutoenterprise/Reports/TableReport.cs @@ -10,8 +10,7 @@ internal class TableReport private readonly IItineraryRepository _itineraryRepository; private readonly IBusRepository _busRepository; private readonly ILogger _logger; - internal static readonly string[] item = ["Дата", "Id Автобуса", "Id Водителя", "Id Кондуктора","Кол-во поездок по маршруту"]; - //internal static readonly string[] item = ["Автобус","Дата", "Кол-во мест"]; + internal static readonly string[] item = ["Дата", "Id Автобуса", "Id Водителя", "Id Кондуктора", "Кол-во маршрутов"]; public TableReport(IItineraryRepository itineraryRepository, IBusRepository busRepository, ILogger logger) { @@ -30,7 +29,7 @@ internal class TableReport new ExcelBuilder(filePath) .AddHeader("Сводка по поездкам автобуса", 0, 5) .AddParagraph("за период", 0) - .AddTable([10, 10, 10, 10, 15], GetData(busId, startDate, endDate)) + .AddTable([10, 10, 10, 10, 10], GetData(busId, startDate, endDate)) .Build(); return true; } @@ -61,7 +60,7 @@ internal class TableReport data .Select(x => new string[] { x.Date.ToString("dd-MM-yyyy"), x.BusId.ToString(), x.DriverId.ToString(), x.ConductorId.ToString(), x.CountRoutes.ToString()})) .Union( - [["Всего", "", data.Sum(x => x.CountRoutes ?? 0).ToString()]]) + [["Всего", "", "", "", data.Sum(x => x.CountRoutes ?? 0).ToString()]]) .ToList(); } } \ No newline at end of file diff --git a/ProjectAutoenterprise/ProjectAutoenterprise/Reports/WordBuilder.cs b/ProjectAutoenterprise/ProjectAutoenterprise/Reports/WordBuilder.cs index d809c34..3b4eca2 100644 --- a/ProjectAutoenterprise/ProjectAutoenterprise/Reports/WordBuilder.cs +++ b/ProjectAutoenterprise/ProjectAutoenterprise/Reports/WordBuilder.cs @@ -26,10 +26,8 @@ internal class WordBuilder { var paragraph = _body.AppendChild(new Paragraph()); var run = paragraph.AppendChild(new Run()); - // DO прописать настройки под жирный текст var runProperties = run.AppendChild(new RunProperties()); runProperties.AppendChild(new Bold()); - // run.AppendChild(new Text(header)); return this; }