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