сдано тип
This commit is contained in:
parent
1128ffdc1a
commit
db32ab60ce
36
FormLibrary/ComponentHistogramToPdf.Designer.cs
generated
Normal file
36
FormLibrary/ComponentHistogramToPdf.Designer.cs
generated
Normal file
@ -0,0 +1,36 @@
|
||||
namespace FormLibrary
|
||||
{
|
||||
partial class ComponentHistogramToPdf
|
||||
{
|
||||
/// <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
|
||||
}
|
||||
}
|
101
FormLibrary/ComponentHistogramToPdf.cs
Normal file
101
FormLibrary/ComponentHistogramToPdf.cs
Normal file
@ -0,0 +1,101 @@
|
||||
using FormLibrary.HelperClasses;
|
||||
using MigraDoc.DocumentObjectModel;
|
||||
using MigraDoc.Rendering;
|
||||
using OxyPlot.Series;
|
||||
using OxyPlot;
|
||||
using System.ComponentModel;
|
||||
using OxyPlot.WindowsForms;
|
||||
using OxyPlot.Legends;
|
||||
|
||||
|
||||
namespace FormLibrary
|
||||
{
|
||||
public partial class ComponentHistogramToPdf : Component
|
||||
{
|
||||
public ComponentHistogramToPdf()
|
||||
{
|
||||
InitializeComponent();
|
||||
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
|
||||
}
|
||||
|
||||
public ComponentHistogramToPdf(IContainer container)
|
||||
{
|
||||
container.Add(this);
|
||||
|
||||
InitializeComponent();
|
||||
}
|
||||
public void CreateHistogramPdf(string filePath, string documentTitle, string chartTitle, LegendPosition legendPosition, List<ChartData> chartData)
|
||||
{
|
||||
if (string.IsNullOrEmpty(filePath))
|
||||
throw new ArgumentException("Путь к файлу не должен быть пустым.");
|
||||
if (string.IsNullOrEmpty(documentTitle))
|
||||
throw new ArgumentException("Название документа не должно быть пустым.");
|
||||
if (string.IsNullOrEmpty(chartTitle))
|
||||
throw new ArgumentException("Заголовок диаграммы не должен быть пустым.");
|
||||
if (chartData == null || chartData.Count == 0)
|
||||
throw new ArgumentException("Набор данных не должен быть пустым.");
|
||||
|
||||
foreach (var data in chartData)
|
||||
{
|
||||
if (string.IsNullOrEmpty(data.SeriesName) || data.Data == null || data.Data.Count == 0)
|
||||
throw new ArgumentException($"Набор данных для серии '{data.SeriesName}' некорректен.");
|
||||
}
|
||||
|
||||
// создание графика
|
||||
var plotModel = new PlotModel { Title = chartTitle };
|
||||
|
||||
foreach (var data in 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, 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 = documentTitle;
|
||||
document.Info.Subject = "Гистограмма";
|
||||
|
||||
Section section = document.AddSection();
|
||||
section.AddParagraph(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(filePath);
|
||||
|
||||
File.Delete("chart.png");
|
||||
}
|
||||
|
||||
//добавление легенды
|
||||
private void AddLegend(PlotModel plotModel, LegendPosition legendPosition)
|
||||
{
|
||||
// Создание легенды
|
||||
var legend = new OxyPlot.Legends.Legend
|
||||
{
|
||||
LegendPlacement = LegendPlacement.Outside,
|
||||
LegendPosition = legendPosition,
|
||||
LegendOrientation = LegendOrientation.Vertical
|
||||
};
|
||||
|
||||
plotModel.Legends.Add(legend);
|
||||
}
|
||||
}
|
||||
}
|
@ -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>
|
||||
|
14
FormLibrary/HelperClasses/ChartData.cs
Normal file
14
FormLibrary/HelperClasses/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 FormLibrary.HelperClasses
|
||||
{
|
||||
public class ChartData
|
||||
{
|
||||
public string SeriesName { get; set; }
|
||||
public Dictionary<string, double> Data { get; set; } // Ключ — категория, значение — значение для гистограммы
|
||||
}
|
||||
}
|
16
FormLibrary/HelperClasses/LegendPositions.cs
Normal file
16
FormLibrary/HelperClasses/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 FormLibrary.HelperClasses
|
||||
{
|
||||
public enum LegendPositions
|
||||
{
|
||||
Top,
|
||||
Bottom,
|
||||
Left,
|
||||
Right
|
||||
}
|
||||
}
|
19
FormLibrary/HelperClasses/PDFTableSettings.cs
Normal file
19
FormLibrary/HelperClasses/PDFTableSettings.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FormLibrary.HelperClasses
|
||||
{
|
||||
public class PDFTableSettings<T>
|
||||
{
|
||||
public string FilePath { get; set; }
|
||||
public string DocumentTitle { get; set; }
|
||||
public List<(string HeaderTitle, float Width, string PropertyName, int ColumnIndex)> Columns { get; set; }
|
||||
public float HeaderRowHeight { get; set; }
|
||||
public float DataRowHeight { get; set; }
|
||||
public List<T> DataList { get; set; }
|
||||
}
|
||||
|
||||
}
|
23
FormLibrary/HelperClasses/PdfDocumentData.cs
Normal file
23
FormLibrary/HelperClasses/PdfDocumentData.cs
Normal file
@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FormLibrary.HelperClasses
|
||||
{
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -8,6 +8,7 @@ namespace FormLibrary.HelperClasses
|
||||
{
|
||||
public class Student
|
||||
{
|
||||
public int Number { get; set; }
|
||||
public string Group { get; set; }
|
||||
public string FullName { get; set; }
|
||||
public int Course { get; set; }
|
||||
|
36
FormLibrary/PDFTable.Designer.cs
generated
Normal file
36
FormLibrary/PDFTable.Designer.cs
generated
Normal file
@ -0,0 +1,36 @@
|
||||
namespace FormLibrary
|
||||
{
|
||||
partial class PDFTable
|
||||
{
|
||||
/// <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
|
||||
}
|
||||
}
|
71
FormLibrary/PDFTable.cs
Normal file
71
FormLibrary/PDFTable.cs
Normal file
@ -0,0 +1,71 @@
|
||||
using FormLibrary.HelperClasses;
|
||||
using MigraDoc.DocumentObjectModel;
|
||||
using MigraDoc.DocumentObjectModel.Tables;
|
||||
using MigraDoc.Rendering;
|
||||
using System.ComponentModel;
|
||||
using Document = MigraDoc.DocumentObjectModel.Document;
|
||||
|
||||
|
||||
namespace FormLibrary
|
||||
{
|
||||
public partial class PDFTable : Component
|
||||
{
|
||||
public PDFTable()
|
||||
{
|
||||
InitializeComponent();
|
||||
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
|
||||
|
||||
}
|
||||
|
||||
public PDFTable(IContainer container)
|
||||
{
|
||||
container.Add(this);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
36
FormLibrary/PDFTableCustom.Designer.cs
generated
Normal file
36
FormLibrary/PDFTableCustom.Designer.cs
generated
Normal file
@ -0,0 +1,36 @@
|
||||
namespace FormLibrary
|
||||
{
|
||||
partial class PDFTableCustom
|
||||
{
|
||||
/// <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
|
||||
}
|
||||
}
|
95
FormLibrary/PDFTableCustom.cs
Normal file
95
FormLibrary/PDFTableCustom.cs
Normal file
@ -0,0 +1,95 @@
|
||||
using FormLibrary.HelperClasses;
|
||||
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;
|
||||
|
||||
namespace FormLibrary
|
||||
{
|
||||
public partial class PDFTableCustom : Component
|
||||
{
|
||||
public PDFTableCustom()
|
||||
{
|
||||
InitializeComponent();
|
||||
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
|
||||
}
|
||||
|
||||
public PDFTableCustom(IContainer container)
|
||||
{
|
||||
container.Add(this);
|
||||
|
||||
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();
|
||||
section.AddParagraph(settings.DocumentTitle, "Heading1");
|
||||
|
||||
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 columnIndex = 0; columnIndex < settings.Columns.Count; columnIndex++)
|
||||
{
|
||||
var (headerTitle, _, _, _) = settings.Columns[columnIndex];
|
||||
headerRow.Cells[columnIndex].AddParagraph(headerTitle);
|
||||
headerRow.Cells[columnIndex].Format.Font.Bold = true;
|
||||
headerRow.Cells[columnIndex].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);
|
||||
}
|
||||
}
|
||||
}
|
49
Forms/MainForm.Designer.cs
generated
49
Forms/MainForm.Designer.cs
generated
@ -28,6 +28,7 @@
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
components = new System.ComponentModel.Container();
|
||||
customListBox1 = new FormLibrary.CustomListBox();
|
||||
button1 = new Button();
|
||||
button2 = new Button();
|
||||
@ -39,6 +40,12 @@
|
||||
button5 = new Button();
|
||||
button6 = new Button();
|
||||
button7 = new Button();
|
||||
pdfTable1 = new FormLibrary.PDFTable(components);
|
||||
button8 = new Button();
|
||||
pdfTableCustom1 = new FormLibrary.PDFTableCustom(components);
|
||||
button9 = new Button();
|
||||
button11 = new Button();
|
||||
componentHistogramToPdf1 = new FormLibrary.ComponentHistogramToPdf(components);
|
||||
SuspendLayout();
|
||||
//
|
||||
// customListBox1
|
||||
@ -107,7 +114,6 @@
|
||||
//
|
||||
valueTableControl1.Location = new Point(487, 12);
|
||||
valueTableControl1.Name = "valueTableControl1";
|
||||
valueTableControl1.SelectedRowIndex = -1;
|
||||
valueTableControl1.Size = new Size(450, 369);
|
||||
valueTableControl1.TabIndex = 7;
|
||||
//
|
||||
@ -141,11 +147,44 @@
|
||||
button7.UseVisualStyleBackColor = true;
|
||||
button7.Click += ButtonShowData_Click;
|
||||
//
|
||||
// button8
|
||||
//
|
||||
button8.Location = new Point(26, 481);
|
||||
button8.Name = "button8";
|
||||
button8.Size = new Size(139, 23);
|
||||
button8.TabIndex = 11;
|
||||
button8.Text = "Create PDF";
|
||||
button8.UseVisualStyleBackColor = true;
|
||||
button8.Click += GeneratePdfButton_Click;
|
||||
//
|
||||
// button9
|
||||
//
|
||||
button9.Location = new Point(189, 481);
|
||||
button9.Name = "button9";
|
||||
button9.Size = new Size(139, 23);
|
||||
button9.TabIndex = 12;
|
||||
button9.Text = "Create customPDF";
|
||||
button9.UseVisualStyleBackColor = true;
|
||||
button9.Click += btnGeneratePDF_Click;
|
||||
//
|
||||
// button11
|
||||
//
|
||||
button11.Location = new Point(347, 481);
|
||||
button11.Name = "button11";
|
||||
button11.Size = new Size(139, 23);
|
||||
button11.TabIndex = 13;
|
||||
button11.Text = "Create Histogram PDF";
|
||||
button11.UseVisualStyleBackColor = true;
|
||||
button11.Click += btnGenerateHistogrammPdf_Click;
|
||||
//
|
||||
// MainForm
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(949, 450);
|
||||
ClientSize = new Size(944, 625);
|
||||
Controls.Add(button11);
|
||||
Controls.Add(button9);
|
||||
Controls.Add(button8);
|
||||
Controls.Add(button7);
|
||||
Controls.Add(button6);
|
||||
Controls.Add(button5);
|
||||
@ -176,5 +215,11 @@
|
||||
private Button button5;
|
||||
private Button button6;
|
||||
private Button button7;
|
||||
private FormLibrary.PDFTable pdfTable1;
|
||||
private Button button8;
|
||||
private FormLibrary.PDFTableCustom pdfTableCustom1;
|
||||
private Button button9;
|
||||
private Button button11;
|
||||
private FormLibrary.ComponentHistogramToPdf componentHistogramToPdf1;
|
||||
}
|
||||
}
|
@ -12,6 +12,7 @@ using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using System.Windows.Forms.VisualStyles;
|
||||
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Header;
|
||||
using OxyPlot.Legends;
|
||||
|
||||
namespace Forms
|
||||
{
|
||||
@ -98,9 +99,9 @@ namespace Forms
|
||||
|
||||
var students = new List<Student>
|
||||
{
|
||||
new Student { Group = "Пибд-31", FullName = "Иванов Иван Иванович", Course = 3 },
|
||||
new Student { Group = "Пибд-31", FullName = "Петров Петр Петрович", Course = 2 },
|
||||
new Student { Group = "Пибд-31", FullName = "Антонов Антон Антонович", Course = 1 }
|
||||
new Student { Group = "Пибд-31", FullName = "Алексеев Иван Сергеевич", Course = 3 },
|
||||
new Student { Group = "Пибд-31", FullName = "Анисин Руслан Сергеевич", Course = 3 },
|
||||
new Student { Group = "Пибд-31", FullName = "Афанасьев Степан Сергеевич", Course = 3 }
|
||||
};
|
||||
|
||||
valueTableControl1.FillData(students);
|
||||
@ -126,5 +127,93 @@ namespace Forms
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
private void GeneratePdfButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
var pdfData = new PdfDocumentData(
|
||||
"C:\\Users\\Admin\\Downloads\\Отчёт.pdf",
|
||||
"Название документа",
|
||||
new List<string[,]>
|
||||
{
|
||||
new string[,]
|
||||
{
|
||||
{ "Ячейка 1", "Ячейка 2", "Ячейка 3" },
|
||||
{ "Ячейка 4", "Ячейка 5", "Ячейка 6" }
|
||||
},
|
||||
new string[,]
|
||||
{
|
||||
{ "Ячейка 1", "Ячейка 2" },
|
||||
{ "Ячейка 1", "Ячейка 2" }
|
||||
}
|
||||
});
|
||||
|
||||
var documentGenerator = new PDFTable();
|
||||
documentGenerator.GeneratePdf(pdfData);
|
||||
|
||||
MessageBox.Show("PDF-документ успешно создан!", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show($"Произошла ошибка: {ex.Message}", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
private void btnGeneratePDF_Click(object sender, EventArgs e)
|
||||
{
|
||||
var settings = new PDFTableSettings<Student>
|
||||
{
|
||||
FilePath = "C:\\Users\\Admin\\Downloads\\Отчет2.pdf",
|
||||
DocumentTitle = "Отчет по студентам",
|
||||
HeaderRowHeight = 1.0f,
|
||||
DataRowHeight = 1.0f,
|
||||
DataList = new List<Student>
|
||||
{
|
||||
new Student { Number = 1, Group = "Пибд-31", FullName = "Алексеев Иван", Course = 3 },
|
||||
new Student { Number = 2, Group = "Пибд-31", FullName = "Анисин Руслан", Course = 3 },
|
||||
new Student { Number = 3, Group = "Пибд-31", FullName = "Афанасьев Степан", Course = 3 }
|
||||
},
|
||||
Columns = new List<(string, float, string, int)>
|
||||
{
|
||||
("№", 1.0f, nameof(Student.Number), 0),
|
||||
("Группа", 4.0f, nameof(Student.Group), 1),
|
||||
("ФИО", 6.0f, nameof(Student.FullName), 2),
|
||||
("Курс", 2.0f, nameof(Student.Course), 3)
|
||||
}
|
||||
};
|
||||
|
||||
try
|
||||
{
|
||||
pdfTableCustom1.GeneratePDFWithHead(settings);
|
||||
MessageBox.Show("PDF-документ успешно создан!", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show($"Ошибка: {ex.Message}");
|
||||
}
|
||||
}
|
||||
private void btnGenerateHistogrammPdf_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
var histogramGenerator = new ComponentHistogramToPdf();
|
||||
|
||||
var chartData = new List<ChartData>
|
||||
{
|
||||
new ChartData { SeriesName = "Серияd 1", Data = new Dictionary<string, double> { { "Категорияz 1", 2 }, { "Категорияx 2", 10 } } },
|
||||
new ChartData { SeriesName = "Серияs 2", Data = new Dictionary<string, double> { { "Категорияa 1", 3 }, { "Категорияs 2", 5 } } },
|
||||
new ChartData { SeriesName = "Серияs 3", Data = new Dictionary<string, double> { { "Категорияa 1", 3 }, { "Категорияs 2", 8 } } }
|
||||
};
|
||||
|
||||
string filePath = "C:\\Users\\Admin\\Downloads\\Гистограмма.pdf";
|
||||
|
||||
histogramGenerator.CreateHistogramPdf(filePath, "Название документа", "Заголовок гистограммы", LegendPosition.BottomCenter, chartData);
|
||||
|
||||
MessageBox.Show("PDF успешно сгенерирован!", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show($"Ошибка: {ex.Message}", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
@ -48,7 +48,7 @@
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
@ -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="pdfTable1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
<metadata name="pdfTableCustom1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>122, 17</value>
|
||||
</metadata>
|
||||
<metadata name="componentHistogramToPdf1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>269, 17</value>
|
||||
</metadata>
|
||||
</root>
|
@ -1,3 +1,4 @@
|
||||
using System.Text;
|
||||
namespace Forms
|
||||
{
|
||||
internal static class Program
|
||||
@ -10,6 +11,7 @@ namespace Forms
|
||||
{
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new MainForm());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user