From b9e819f3095d66ab248f276f36185ba159abb6fa Mon Sep 17 00:00:00 2001 From: GokaPek Date: Tue, 1 Oct 2024 11:57:07 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A4=D0=B8=D0=BD=D0=B0=D0=BB=202=20=D0=BB?= =?UTF-8?q?=D0=B0=D0=B1=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ExexForm2/Form1.cs | 9 ++++++--- Library14Petrushin/PdfColGroupTable.cs | 24 ++++++++---------------- 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/ExexForm2/Form1.cs b/ExexForm2/Form1.cs index 9a8781b..82861c0 100644 --- a/ExexForm2/Form1.cs +++ b/ExexForm2/Form1.cs @@ -103,9 +103,12 @@ namespace ExexForm2 new Person { FirstName = "Jane", LastName = "Smith", Age = 25 } }; - var headers = new List { "First Name", "Last Name", "Age" }; var commonHeaders = new List { "Name", "", "" }; - var propertyNames = new List { "FirstName", "LastName", "Age" }; + var headersNames = new List<(string, string)> { + ("First Name","FirstName"), + ("Last Name", "LastName"), + ("Age", "Age") + }; var rowHeights = new List { 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); } } diff --git a/Library14Petrushin/PdfColGroupTable.cs b/Library14Petrushin/PdfColGroupTable.cs index 85a87c3..942cb33 100644 --- a/Library14Petrushin/PdfColGroupTable.cs +++ b/Library14Petrushin/PdfColGroupTable.cs @@ -17,25 +17,17 @@ namespace Library14Petrushin string documentTitle, List<(int startRow, int endRow, int startColumn, int endColumn)> mergeCells, List rowHeights, - List headers, + List<(string, string)> headersNames, List commonHeaders, - List propertyNames, List 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); } }