Финал 2 лаба

This commit is contained in:
GokaPek 2024-10-01 11:57:07 +04:00
parent cbc230e0a2
commit b9e819f309
2 changed files with 14 additions and 19 deletions

View File

@ -103,9 +103,12 @@ namespace ExexForm2
new Person { FirstName = "Jane", LastName = "Smith", Age = 25 }
};
var headers = new List<string> { "First Name", "Last Name", "Age" };
var commonHeaders = new List<string> { "Name", "", "" };
var propertyNames = new List<string> { "FirstName", "LastName", "Age" };
var headersNames = new List<(string, string)> {
("First Name","FirstName"),
("Last Name", "LastName"),
("Age", "Age")
};
var rowHeights = new List<double> { 20, 20 };
var mergeCells = new List<(int startRow, int endRow, int startColumn, int endColumn)>
{
@ -113,7 +116,7 @@ namespace ExexForm2
(2, 2, 0, 1)
};
generator.GeneratePdf(fileName, "Example Document", mergeCells, rowHeights, headers, commonHeaders, propertyNames, data1);
generator.GeneratePdf(fileName, "Example Document", mergeCells, rowHeights, headersNames, commonHeaders, data1);
}
}

View File

@ -17,25 +17,17 @@ namespace Library14Petrushin
string documentTitle,
List<(int startRow, int endRow, int startColumn, int endColumn)> mergeCells,
List<double> rowHeights,
List<string> headers,
List<(string, string)> headersNames,
List<string> commonHeaders,
List<string> propertyNames,
List<T> data)
{
// Проверка на заполненность входных данных
if (string.IsNullOrEmpty(fileName) || string.IsNullOrEmpty(documentTitle) ||
mergeCells == null || rowHeights == null || headers == null ||
propertyNames == null || data == null)
mergeCells == null || rowHeights == null || headersNames == null || data == null)
{
throw new ArgumentException("Все входные данные должны быть заполнены.");
}
// Проверка на соответствие количества заголовков и свойств
if (headers.Count != propertyNames.Count)
{
throw new ArgumentException("Количество заголовков должно совпадать с количеством свойств.");
}
// Проверка на соответствие количества строк и высот строк
if (rowHeights.Count != data.Count)
{
@ -56,7 +48,7 @@ namespace Library14Petrushin
double x = margin;
double y = 70;
double rowHeight = 20; // Фиксированная высота строки
double columnWidth = (page.Width - 2 * margin) / (headers.Count + 1); // Ширина столбца
double columnWidth = (page.Width - 2 * margin) / (headersNames.Count + 1); // Ширина столбца
// Отрисовка шапки
@ -68,9 +60,9 @@ namespace Library14Petrushin
x += columnWidth;
for (int col = 0; col < headers.Count; col++)
for (int col = 0; col < headersNames.Count; col++)
{
gfx.DrawString(headers[col], font, XBrushes.Black, new XRect(x, y + col * rowHeight, columnWidth, rowHeight), XStringFormats.CenterLeft);
gfx.DrawString(headersNames[col].Item1, font, XBrushes.Black, new XRect(x, y + col * rowHeight, columnWidth, rowHeight), XStringFormats.CenterLeft);
gfx.DrawRectangle(XPens.Black, new XRect(x, y + col * rowHeight, columnWidth, rowHeight)); // Добавляем рамку
}
@ -79,10 +71,10 @@ namespace Library14Petrushin
// Отрисовка данных
for (int col = 0; col < data.Count; col++)
{
for (int row = 0; row < propertyNames.Count; row++)
for (int row = 0; row < headersNames.Count; row++)
{
var item = data[col];
var property = item.GetType().GetProperty(propertyNames[row]);
var property = item.GetType().GetProperty(headersNames[row].Item2);
if (property != null)
{
var value = property.GetValue(item)?.ToString() ?? string.Empty;
@ -107,7 +99,7 @@ namespace Library14Petrushin
}
else
{
gfx.DrawString(headers[startRow], font, XBrushes.Black, new XRect(mergeX, mergeY, mergeWidth, mergeHeight), XStringFormats.Center);
gfx.DrawString(headersNames[startRow].Item1, font, XBrushes.Black, new XRect(mergeX, mergeY, mergeWidth, mergeHeight), XStringFormats.Center);
}
}