Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dc7bee82a0 | ||
|
|
2faa7bf7f9 | ||
|
|
4d673aa1dc |
@@ -7,4 +7,11 @@
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="OxyPlot.Core" Version="2.2.0" />
|
||||
<PackageReference Include="OxyPlot.WindowsForms" Version="2.2.0" />
|
||||
<PackageReference Include="OxyPlot.Wpf" Version="2.2.0" />
|
||||
<PackageReference Include="PdfSharp.MigraDoc.Standard" Version="1.51.15" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
36
Components/NonVisual/HeaderedTablePDF.Designer.cs
generated
Normal file
36
Components/NonVisual/HeaderedTablePDF.Designer.cs
generated
Normal file
@@ -0,0 +1,36 @@
|
||||
namespace Components.NonVisual
|
||||
{
|
||||
partial class HeaderedTablePDF
|
||||
{
|
||||
/// <summary>
|
||||
/// Обязательная переменная конструктора.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Освободить все используемые ресурсы.
|
||||
/// </summary>
|
||||
/// <param name="disposing">истинно, если управляемый ресурс должен быть удален; иначе ложно.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Код, автоматически созданный конструктором компонентов
|
||||
|
||||
/// <summary>
|
||||
/// Требуемый метод для поддержки конструктора — не изменяйте
|
||||
/// содержимое этого метода с помощью редактора кода.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
components = new System.ComponentModel.Container();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
98
Components/NonVisual/HeaderedTablePDF.cs
Normal file
98
Components/NonVisual/HeaderedTablePDF.cs
Normal file
@@ -0,0 +1,98 @@
|
||||
using MigraDoc.DocumentObjectModel.Tables;
|
||||
using MigraDoc.DocumentObjectModel;
|
||||
using MigraDoc.Rendering;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Components.SaveToPdfHelpers;
|
||||
|
||||
namespace Components.NonVisual
|
||||
{
|
||||
public partial class HeaderedTablePDF : Component
|
||||
{
|
||||
public HeaderedTablePDF()
|
||||
{
|
||||
InitializeComponent();
|
||||
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
|
||||
}
|
||||
|
||||
public HeaderedTablePDF(IContainer container)
|
||||
{
|
||||
container.Add(this);
|
||||
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
|
||||
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public void GeneratePDFWithHead<T>(PDFTableSettings<T> settings)
|
||||
{
|
||||
if (settings == null ||
|
||||
string.IsNullOrEmpty(settings.FilePath) ||
|
||||
string.IsNullOrEmpty(settings.DocumentTitle) ||
|
||||
settings.Columns == null || settings.Columns.Count == 0 ||
|
||||
settings.DataList == null)
|
||||
throw new ArgumentException("Заполнены не все необходимые данные для генерации документа.");
|
||||
|
||||
Document document = new Document();
|
||||
Section section = document.AddSection();
|
||||
Paragraph titleParagraph = section.AddParagraph(settings.DocumentTitle, "Heading1");
|
||||
titleParagraph.Format.Font.Bold = true;
|
||||
|
||||
Table table = new Table();
|
||||
table.Borders.Width = 0.75;
|
||||
|
||||
// столбцы
|
||||
foreach (var (_, width, _, _) in settings.Columns)
|
||||
{
|
||||
Column column = table.AddColumn(Unit.FromCentimeter(width));
|
||||
column.Format.Alignment = ParagraphAlignment.Center;
|
||||
}
|
||||
|
||||
// заголовки
|
||||
Row headerRow = table.AddRow();
|
||||
headerRow.Height = Unit.FromCentimeter(settings.HeaderRowHeight);
|
||||
|
||||
for (int i = 0; i < settings.Columns.Count; i++)
|
||||
{
|
||||
var (headerTitle, _, _, _) = settings.Columns[i];
|
||||
headerRow.Cells[i].AddParagraph(headerTitle);
|
||||
headerRow.Cells[i].Format.Font.Bold = true;
|
||||
headerRow.Cells[i].Format.Alignment = ParagraphAlignment.Center;
|
||||
}
|
||||
|
||||
// данные
|
||||
foreach (var dataItem in settings.DataList)
|
||||
{
|
||||
Row row = table.AddRow();
|
||||
row.Height = Unit.FromCentimeter(settings.DataRowHeight);
|
||||
|
||||
for (int columnIndex = 0; columnIndex < settings.Columns.Count; columnIndex++)
|
||||
{
|
||||
var (_, _, propertyName, _) = settings.Columns[columnIndex];
|
||||
|
||||
PropertyInfo propertyInfo = typeof(T).GetProperty(propertyName);
|
||||
if (propertyInfo == null)
|
||||
throw new ArgumentException($"Свойство {propertyName} не найдено в классе {typeof(T).Name}.");
|
||||
|
||||
object value = propertyInfo.GetValue(dataItem);
|
||||
if (columnIndex == 0)
|
||||
{
|
||||
row.Cells[columnIndex].Format.Font.Bold = true;
|
||||
}
|
||||
row.Cells[columnIndex].AddParagraph(value != null ? value.ToString() : "");
|
||||
}
|
||||
}
|
||||
|
||||
section.Add(table);
|
||||
|
||||
PdfDocumentRenderer renderer = new PdfDocumentRenderer(true) { Document = document };
|
||||
renderer.RenderDocument();
|
||||
renderer.Save(settings.FilePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
36
Components/NonVisual/HistogramPDF.Designer.cs
generated
Normal file
36
Components/NonVisual/HistogramPDF.Designer.cs
generated
Normal file
@@ -0,0 +1,36 @@
|
||||
namespace Components.NonVisual
|
||||
{
|
||||
partial class HistogramPDF
|
||||
{
|
||||
/// <summary>
|
||||
/// Обязательная переменная конструктора.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Освободить все используемые ресурсы.
|
||||
/// </summary>
|
||||
/// <param name="disposing">истинно, если управляемый ресурс должен быть удален; иначе ложно.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Код, автоматически созданный конструктором компонентов
|
||||
|
||||
/// <summary>
|
||||
/// Требуемый метод для поддержки конструктора — не изменяйте
|
||||
/// содержимое этого метода с помощью редактора кода.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
components = new System.ComponentModel.Container();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
119
Components/NonVisual/HistogramPDF.cs
Normal file
119
Components/NonVisual/HistogramPDF.cs
Normal file
@@ -0,0 +1,119 @@
|
||||
using Components.SaveToPdfHelpers;
|
||||
using MigraDoc.DocumentObjectModel;
|
||||
using MigraDoc.Rendering;
|
||||
using OxyPlot.Series;
|
||||
using OxyPlot;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using OxyPlot.WindowsForms;
|
||||
using OxyPlot.Legends;
|
||||
|
||||
namespace Components.NonVisual
|
||||
{
|
||||
public partial class HistogramPDF : Component
|
||||
{
|
||||
public HistogramPDF()
|
||||
{
|
||||
InitializeComponent();
|
||||
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
|
||||
}
|
||||
public HistogramPDF(IContainer container)
|
||||
{
|
||||
container.Add(this);
|
||||
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public void CreateHistogramPdf(HistogramData histogramData)
|
||||
{
|
||||
if (string.IsNullOrEmpty(histogramData.FilePath))
|
||||
throw new ArgumentException("Путь к файлу не может быть пустым.");
|
||||
if (string.IsNullOrEmpty(histogramData.DocumentTitle))
|
||||
throw new ArgumentException("Название документа не может быть пустым.");
|
||||
if (string.IsNullOrEmpty(histogramData.ChartTitle))
|
||||
throw new ArgumentException("Заголовок диаграммы не может быть пустым.");
|
||||
if (histogramData.ChartData == null || histogramData.ChartData.Count == 0)
|
||||
throw new ArgumentException("Набор данных не может быть пустым.");
|
||||
|
||||
foreach (var data in histogramData.ChartData)
|
||||
{
|
||||
if (string.IsNullOrEmpty(data.SeriesName) || data.Data == null || data.Data.Count == 0)
|
||||
throw new ArgumentException($"Набор данных для серии '{data.SeriesName}' некорректен.");
|
||||
}
|
||||
|
||||
// создание графика
|
||||
var plotModel = new PlotModel { Title = histogramData.ChartTitle };
|
||||
|
||||
foreach (var data in histogramData.ChartData)
|
||||
{
|
||||
var barSeries = new BarSeries { Title = data.SeriesName };
|
||||
foreach (var item in data.Data)
|
||||
{
|
||||
barSeries.Items.Add(new BarItem(item.Value));
|
||||
}
|
||||
plotModel.Series.Add(barSeries);
|
||||
}
|
||||
|
||||
// Добавление легенды
|
||||
AddLegend(plotModel, histogramData.LegendPosition);
|
||||
|
||||
// сохранение графика в изображение
|
||||
var pngExporter = new PngExporter { Width = 600, Height = 400 };
|
||||
using (var stream = new MemoryStream())
|
||||
{
|
||||
pngExporter.Export(plotModel, stream);
|
||||
File.WriteAllBytes("chart.png", stream.ToArray());
|
||||
}
|
||||
|
||||
// создание документа
|
||||
Document document = new Document();
|
||||
document.Info.Title = histogramData.DocumentTitle;
|
||||
document.Info.Subject = "Гистограмма";
|
||||
|
||||
Section section = document.AddSection();
|
||||
section.AddParagraph(histogramData.ChartTitle, "Heading1");
|
||||
|
||||
// вставка изображения в PDF
|
||||
var image = section.AddImage("chart.png");
|
||||
image.Width = Unit.FromCentimeter(15);
|
||||
|
||||
PdfDocumentRenderer renderer = new PdfDocumentRenderer(true) { Document = document };
|
||||
renderer.RenderDocument();
|
||||
renderer.PdfDocument.Save(histogramData.FilePath);
|
||||
|
||||
File.Delete("chart.png");
|
||||
}
|
||||
|
||||
//добавление легенды
|
||||
private void AddLegend(PlotModel plotModel, LegendPositions legendPosition)
|
||||
{
|
||||
// Создание легенды
|
||||
var legend = new OxyPlot.Legends.Legend
|
||||
{
|
||||
LegendPlacement = LegendPlacement.Outside,
|
||||
LegendPosition = ConvertLegendPosition(legendPosition),
|
||||
LegendOrientation = LegendOrientation.Vertical
|
||||
};
|
||||
|
||||
plotModel.Legends.Add(legend);
|
||||
}
|
||||
|
||||
// конвертация позиции легенды
|
||||
private OxyPlot.Legends.LegendPosition ConvertLegendPosition(LegendPositions legendPosition)
|
||||
{
|
||||
return legendPosition switch
|
||||
{
|
||||
LegendPositions.Top => OxyPlot.Legends.LegendPosition.TopCenter,
|
||||
LegendPositions.Bottom => OxyPlot.Legends.LegendPosition.BottomCenter,
|
||||
LegendPositions.Left => OxyPlot.Legends.LegendPosition.LeftTop,
|
||||
LegendPositions.Right => OxyPlot.Legends.LegendPosition.RightTop,
|
||||
_ => OxyPlot.Legends.LegendPosition.TopCenter, // Положение по умолчанию
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
36
Components/NonVisual/TablePDF.Designer.cs
generated
Normal file
36
Components/NonVisual/TablePDF.Designer.cs
generated
Normal file
@@ -0,0 +1,36 @@
|
||||
namespace Components.NonVisual
|
||||
{
|
||||
partial class TablePDF
|
||||
{
|
||||
/// <summary>
|
||||
/// Обязательная переменная конструктора.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Освободить все используемые ресурсы.
|
||||
/// </summary>
|
||||
/// <param name="disposing">истинно, если управляемый ресурс должен быть удален; иначе ложно.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Код, автоматически созданный конструктором компонентов
|
||||
|
||||
/// <summary>
|
||||
/// Требуемый метод для поддержки конструктора — не изменяйте
|
||||
/// содержимое этого метода с помощью редактора кода.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
components = new System.ComponentModel.Container();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
76
Components/NonVisual/TablePDF.cs
Normal file
76
Components/NonVisual/TablePDF.cs
Normal file
@@ -0,0 +1,76 @@
|
||||
using MigraDoc.DocumentObjectModel.Tables;
|
||||
using MigraDoc.DocumentObjectModel;
|
||||
using MigraDoc.Rendering;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Document = MigraDoc.DocumentObjectModel.Document;
|
||||
using Components.SaveToPdfHelpers;
|
||||
|
||||
namespace Components.NonVisual
|
||||
{
|
||||
public partial class TablePDF : Component
|
||||
{
|
||||
public TablePDF()
|
||||
{
|
||||
InitializeComponent();
|
||||
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
|
||||
}
|
||||
|
||||
public TablePDF(IContainer container)
|
||||
{
|
||||
container.Add(this);
|
||||
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
|
||||
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public void GeneratePdf(PdfDocumentData pdfData)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(pdfData.FileName)) throw new ArgumentException("Имя файла не может быть пустым.");
|
||||
if (string.IsNullOrWhiteSpace(pdfData.DocumentTitle)) throw new ArgumentException("Название документа не может быть пустым.");
|
||||
if (pdfData.Tables == null || pdfData.Tables.Count == 0) throw new ArgumentException("Необходимо передать хотя бы одну таблицу.");
|
||||
|
||||
Document document = new Document();
|
||||
Section section = document.AddSection();
|
||||
|
||||
Paragraph title = section.AddParagraph();
|
||||
title.AddFormattedText(pdfData.DocumentTitle, TextFormat.Bold);
|
||||
title.Format.Alignment = ParagraphAlignment.Center;
|
||||
section.AddParagraph();
|
||||
|
||||
foreach (var tableData in pdfData.Tables)
|
||||
{
|
||||
Table table = section.AddTable();
|
||||
int columnsCount = tableData.GetLength(1);
|
||||
|
||||
for (int i = 0; i < columnsCount; i++)
|
||||
{
|
||||
Column column = table.AddColumn(Unit.FromCentimeter(3));
|
||||
}
|
||||
|
||||
table.Borders.Width = 0.75;
|
||||
table.Borders.Color = Colors.Black;
|
||||
|
||||
for (int i = 0; i < tableData.GetLength(0); i++)
|
||||
{
|
||||
Row row = table.AddRow();
|
||||
for (int j = 0; j < tableData.GetLength(1); j++)
|
||||
{
|
||||
row.Cells[j].AddParagraph(tableData[i, j]);
|
||||
}
|
||||
}
|
||||
|
||||
section.AddParagraph();
|
||||
}
|
||||
PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer(true);
|
||||
pdfRenderer.Document = document;
|
||||
pdfRenderer.RenderDocument();
|
||||
pdfRenderer.PdfDocument.Save(pdfData.FileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
14
Components/SaveToPdfHelpers/ChartData.cs
Normal file
14
Components/SaveToPdfHelpers/ChartData.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Components.SaveToPdfHelpers
|
||||
{
|
||||
public class ChartData
|
||||
{
|
||||
public string SeriesName { get; set; } = string.Empty;
|
||||
public Dictionary<string, double>? Data { get; set; } // Ключ — категория, значение — значение для гистограммы
|
||||
}
|
||||
}
|
||||
17
Components/SaveToPdfHelpers/HistogramData.cs
Normal file
17
Components/SaveToPdfHelpers/HistogramData.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Components.SaveToPdfHelpers
|
||||
{
|
||||
public class HistogramData
|
||||
{
|
||||
public string FilePath { get; set; } = string.Empty;
|
||||
public string DocumentTitle { get; set; } = string.Empty;
|
||||
public string ChartTitle { get; set; } = string.Empty;
|
||||
public LegendPositions LegendPosition { get; set; }
|
||||
public List<ChartData>? ChartData { get; set; }
|
||||
}
|
||||
}
|
||||
16
Components/SaveToPdfHelpers/LegendPositions.cs
Normal file
16
Components/SaveToPdfHelpers/LegendPositions.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Components.SaveToPdfHelpers
|
||||
{
|
||||
public enum LegendPositions
|
||||
{
|
||||
Top,
|
||||
Bottom,
|
||||
Left,
|
||||
Right
|
||||
}
|
||||
}
|
||||
18
Components/SaveToPdfHelpers/PDFTableSettings.cs
Normal file
18
Components/SaveToPdfHelpers/PDFTableSettings.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Components.SaveToPdfHelpers
|
||||
{
|
||||
public class PDFTableSettings<T>
|
||||
{
|
||||
public string FilePath { get; set; } = string.Empty;
|
||||
public string DocumentTitle { get; set; } = string.Empty;
|
||||
public List<(string HeaderTitles, float Widht, string PropertyName, int ColumnIndex)> Columns { get; set; }
|
||||
public float HeaderRowHeight { get; set; }
|
||||
public float DataRowHeight { get; set; }
|
||||
public List<T>? DataList { get; set; }
|
||||
}
|
||||
}
|
||||
22
Components/SaveToPdfHelpers/PdfDocumentData.cs
Normal file
22
Components/SaveToPdfHelpers/PdfDocumentData.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Components.SaveToPdfHelpers
|
||||
{
|
||||
public class PdfDocumentData
|
||||
{
|
||||
public string FileName { get; set; }
|
||||
public string DocumentTitle { get; set; }
|
||||
public List<string[,]> Tables { get; set; }
|
||||
|
||||
public PdfDocumentData(string fileName, string documentTitle, List<string[,]> tables)
|
||||
{
|
||||
FileName = fileName ?? throw new ArgumentNullException(nameof(fileName));
|
||||
DocumentTitle = documentTitle ?? throw new ArgumentNullException(nameof(documentTitle));
|
||||
Tables = tables ?? throw new ArgumentNullException(nameof(tables));
|
||||
}
|
||||
}
|
||||
}
|
||||
49
WinFormsTest/Form1.Designer.cs
generated
49
WinFormsTest/Form1.Designer.cs
generated
@@ -28,9 +28,16 @@
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
components = new System.ComponentModel.Container();
|
||||
customListBox = new Components.CustomListBox();
|
||||
customTextBox = new Components.CustomTextBox();
|
||||
customDataGridView1 = new Components.CustomDataGridView();
|
||||
buttonCreateTable = new Button();
|
||||
buttonCreateHeaderedTable = new Button();
|
||||
buttonCreateHistogram = new Button();
|
||||
tablepdf1 = new Components.NonVisual.TablePDF(components);
|
||||
histogrampdf1 = new Components.NonVisual.HistogramPDF(components);
|
||||
headeredTablepdf1 = new Components.NonVisual.HeaderedTablePDF(components);
|
||||
SuspendLayout();
|
||||
//
|
||||
// customListBox
|
||||
@@ -55,14 +62,47 @@
|
||||
customDataGridView1.Size = new Size(449, 150);
|
||||
customDataGridView1.TabIndex = 2;
|
||||
//
|
||||
// buttonCreateTable
|
||||
//
|
||||
buttonCreateTable.Location = new Point(41, 235);
|
||||
buttonCreateTable.Name = "buttonCreateTable";
|
||||
buttonCreateTable.Size = new Size(139, 44);
|
||||
buttonCreateTable.TabIndex = 11;
|
||||
buttonCreateTable.Text = "Документ с контекстом";
|
||||
buttonCreateTable.UseVisualStyleBackColor = true;
|
||||
buttonCreateTable.Click += GeneratePdfButton_Click;
|
||||
//
|
||||
// buttonCreateHeaderedTable
|
||||
//
|
||||
buttonCreateHeaderedTable.Location = new Point(204, 231);
|
||||
buttonCreateHeaderedTable.Name = "buttonCreateHeaderedTable";
|
||||
buttonCreateHeaderedTable.Size = new Size(139, 53);
|
||||
buttonCreateHeaderedTable.TabIndex = 12;
|
||||
buttonCreateHeaderedTable.Text = "Документ с настраиваемой таблицей";
|
||||
buttonCreateHeaderedTable.UseVisualStyleBackColor = true;
|
||||
buttonCreateHeaderedTable.Click += btnGeneratePDF_Click;
|
||||
//
|
||||
// buttonCreateHistogram
|
||||
//
|
||||
buttonCreateHistogram.Location = new Point(362, 235);
|
||||
buttonCreateHistogram.Name = "buttonCreateHistogram";
|
||||
buttonCreateHistogram.Size = new Size(139, 44);
|
||||
buttonCreateHistogram.TabIndex = 13;
|
||||
buttonCreateHistogram.Text = "Документ с диаграммой";
|
||||
buttonCreateHistogram.UseVisualStyleBackColor = true;
|
||||
buttonCreateHistogram.Click += btnGenerateHistogrammPdf_Click;
|
||||
//
|
||||
// Form1
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(1003, 257);
|
||||
ClientSize = new Size(934, 296);
|
||||
Controls.Add(customDataGridView1);
|
||||
Controls.Add(customTextBox);
|
||||
Controls.Add(customListBox);
|
||||
Controls.Add(buttonCreateTable);
|
||||
Controls.Add(buttonCreateHeaderedTable);
|
||||
Controls.Add(buttonCreateHistogram);
|
||||
Name = "Form1";
|
||||
Text = "Form1";
|
||||
ResumeLayout(false);
|
||||
@@ -73,5 +113,12 @@
|
||||
private Components.CustomListBox customListBox;
|
||||
private Components.CustomTextBox customTextBox;
|
||||
private Components.CustomDataGridView customDataGridView1;
|
||||
|
||||
private Button buttonCreateTable;
|
||||
private Button buttonCreateHeaderedTable;
|
||||
private Button buttonCreateHistogram;
|
||||
private Components.NonVisual.TablePDF tablepdf1;
|
||||
private Components.NonVisual.HistogramPDF histogrampdf1;
|
||||
private Components.NonVisual.HeaderedTablePDF headeredTablepdf1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
using Components;
|
||||
using Components.NonVisual;
|
||||
using Components.Object;
|
||||
using Components.SaveToPdfHelpers;
|
||||
using OxyPlot.Legends;
|
||||
|
||||
namespace WinFormsTest
|
||||
{
|
||||
@@ -42,5 +45,134 @@ namespace WinFormsTest
|
||||
};
|
||||
customDataGridView1.FillData(data);
|
||||
}
|
||||
|
||||
private string FilePath()
|
||||
{
|
||||
using (SaveFileDialog saveFileDialog = new SaveFileDialog())
|
||||
{
|
||||
saveFileDialog.InitialDirectory = "d:\\tmp";
|
||||
saveFileDialog.Filter = "Excel files (*.pdf)|*.pdf|All files (*.*)|*.*";
|
||||
saveFileDialog.FilterIndex = 1;
|
||||
saveFileDialog.RestoreDirectory = true;
|
||||
|
||||
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
return saveFileDialog.FileName;
|
||||
}
|
||||
}
|
||||
return String.Empty;
|
||||
}
|
||||
|
||||
private void GeneratePdfButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
string filePath = FilePath();
|
||||
|
||||
if (filePath == String.Empty)
|
||||
{
|
||||
MessageBox.Show("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>");
|
||||
return;
|
||||
}
|
||||
|
||||
var settings = new PdfDocumentData(
|
||||
filePath,
|
||||
"<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>",
|
||||
new List<string[,]>
|
||||
{
|
||||
new string[,]
|
||||
{
|
||||
{ "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 1.1", "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 2.1", "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 3.1" },
|
||||
{ "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 2.1", "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 2.2", "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 3.2" }
|
||||
},
|
||||
new string[,]
|
||||
{
|
||||
{ "<22><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 1", "<22><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 2" },
|
||||
{ "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 1", "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 2" }
|
||||
}
|
||||
});
|
||||
try
|
||||
{
|
||||
tablepdf1.GeneratePdf(settings);
|
||||
MessageBox.Show("PDF-<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!", "<22><><EFBFBD><EFBFBD><EFBFBD>", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show($"<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: {ex.Message}", "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
private void btnGeneratePDF_Click(object sender, EventArgs e)
|
||||
{
|
||||
string filePath = FilePath();
|
||||
|
||||
if (filePath == String.Empty)
|
||||
{
|
||||
MessageBox.Show("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>");
|
||||
return;
|
||||
}
|
||||
|
||||
var settings = new PDFTableSettings<Person>
|
||||
{
|
||||
FilePath = filePath,
|
||||
DocumentTitle = "<22><><EFBFBD><EFBFBD><EFBFBD>",
|
||||
HeaderRowHeight = 1.0f,
|
||||
DataRowHeight = 1.0f,
|
||||
DataList = new List<Person>
|
||||
{
|
||||
new Person ( "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", 30, "Alex@mail.ru" ),
|
||||
new Person ( "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>", 25, "221B_Baker_Street@mail.com" ),
|
||||
new Person ("<22><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", 41, "Stas@gmail.com")
|
||||
},
|
||||
Columns = new List<(string, float, string, int)>
|
||||
{
|
||||
("<22><><EFBFBD>", 6.0f, nameof(Person.Name), 0),
|
||||
("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", 2.0f, nameof(Person.Age), 1),
|
||||
("<22><><EFBFBD><EFBFBD><EFBFBD>", 6.0f, nameof(Person.Email), 2)
|
||||
}
|
||||
};
|
||||
|
||||
try
|
||||
{
|
||||
headeredTablepdf1.GeneratePDFWithHead(settings);
|
||||
MessageBox.Show("PDF-<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!", "<22><><EFBFBD><EFBFBD><EFBFBD>", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show($"<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: {ex.Message}");
|
||||
}
|
||||
}
|
||||
private void btnGenerateHistogrammPdf_Click(object sender, EventArgs e)
|
||||
{
|
||||
string filePath = FilePath();
|
||||
|
||||
if (filePath == String.Empty)
|
||||
{
|
||||
MessageBox.Show("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>");
|
||||
return;
|
||||
}
|
||||
|
||||
var setting = new HistogramData
|
||||
{
|
||||
FilePath = filePath,
|
||||
DocumentTitle = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>",
|
||||
ChartTitle = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>",
|
||||
LegendPosition = LegendPositions.Bottom,
|
||||
|
||||
ChartData = new List<ChartData>
|
||||
{
|
||||
new ChartData { SeriesName = "<22><><EFBFBD><EFBFBD><EFBFBD> 1", Data = new Dictionary<string, double> { { "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 1", 5 }, { "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 2", 10 } } },
|
||||
new ChartData { SeriesName = "<22><><EFBFBD><EFBFBD><EFBFBD> 2", Data = new Dictionary<string, double> { { "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 1", 3 }, { "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 2", 8 } } },
|
||||
new ChartData { SeriesName = "<22><><EFBFBD><EFBFBD><EFBFBD> 3", Data = new Dictionary<string, double> { { "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 1", 3 }, { "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 2", 8 } } }
|
||||
}
|
||||
};
|
||||
try
|
||||
{
|
||||
|
||||
histogrampdf1.CreateHistogramPdf(setting);
|
||||
MessageBox.Show("PDF <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!", "<22><><EFBFBD><EFBFBD><EFBFBD>", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show($"<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: {ex.Message}", "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,4 +117,13 @@
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<metadata name="tablepdf1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
<metadata name="histogrampdf1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>121, 17</value>
|
||||
</metadata>
|
||||
<metadata name="headeredTablepdf1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>253, 17</value>
|
||||
</metadata>
|
||||
</root>
|
||||
Reference in New Issue
Block a user