Compare commits

...

7 Commits
main ... Lab2

Author SHA1 Message Date
Владимир Данилов
dc7bee82a0 Принятая 2 лабораторная работа 2024-11-02 18:51:07 +04:00
Владимир Данилов
2faa7bf7f9 Готово 2024-10-30 14:26:40 +04:00
Владимир Данилов
4d673aa1dc В процессе 2024-10-16 14:03:22 +04:00
Kirill
9b30023ed6 Принятая 1 лаба 2024-10-09 19:42:11 +04:00
Kirill
29ef211385 Что-то написал 2024-10-03 21:07:20 +04:00
Владимир Данилов
a46d1fefe8 компонент выбора 2024-09-20 08:45:39 +04:00
Владимир Данилов
9c83262c3e Компонент выбора 2024-09-20 08:33:51 +04:00
29 changed files with 1798 additions and 0 deletions

View File

@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<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>

31
Components/Components.sln Normal file
View File

@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.8.34330.188
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Components", "Components.csproj", "{D813A63B-837E-45AD-8F7D-B6A964F1B794}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WinFormsTest", "..\WinFormsTest\WinFormsTest.csproj", "{11845B59-2110-4F5C-B470-1AA2741A7F18}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{D813A63B-837E-45AD-8F7D-B6A964F1B794}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D813A63B-837E-45AD-8F7D-B6A964F1B794}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D813A63B-837E-45AD-8F7D-B6A964F1B794}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D813A63B-837E-45AD-8F7D-B6A964F1B794}.Release|Any CPU.Build.0 = Release|Any CPU
{11845B59-2110-4F5C-B470-1AA2741A7F18}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{11845B59-2110-4F5C-B470-1AA2741A7F18}.Debug|Any CPU.Build.0 = Debug|Any CPU
{11845B59-2110-4F5C-B470-1AA2741A7F18}.Release|Any CPU.ActiveCfg = Release|Any CPU
{11845B59-2110-4F5C-B470-1AA2741A7F18}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {C5C673BE-0306-44AF-9FA5-36E50BAD9083}
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Components.Exceptions
{
internal class NotIntegerException: Exception
{
public NotIntegerException(string message) : base(message) { }
}
}

View 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
}
}

View 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);
}
}
}

View 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
}
}

View 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, // Положение по умолчанию
};
}
}
}

View 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
}
}

View 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);
}
}
}

16
Components/Person.cs Normal file
View File

@ -0,0 +1,16 @@
namespace Components.Object
{
public class Person
{
public string Name { get; set; }
public int Age { get; set; }
public string Email { get; set; }
public Person(string name, int age, string email)
{
Name = name;
Age = age;
Email = email;
}
}
}

View 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; } // Ключ — категория, значение — значение для гистограммы
}
}

View 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; }
}
}

View 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
}
}

View 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; }
}
}

View 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));
}
}
}

View File

@ -0,0 +1,58 @@
namespace Components
{
partial class CustomDataGridView
{
/// <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()
{
dataGridView = new DataGridView();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
SuspendLayout();
//
// dataGridView
//
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView.Location = new Point(3, 3);
dataGridView.Name = "dataGridView";
dataGridView.Size = new Size(445, 363);
dataGridView.TabIndex = 0;
//
// ValueTableControl
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
Controls.Add(dataGridView);
Name = "ValueTableControl";
Size = new Size(451, 369);
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
ResumeLayout(false);
}
#endregion
private DataGridView dataGridView;
}
}

View File

@ -0,0 +1,113 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Components
{
public partial class CustomDataGridView : UserControl
{
public CustomDataGridView()
{
InitializeComponent();
ConfigureDataGridView();
}
private void ConfigureDataGridView()
{
dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dataGridView.MultiSelect = false;
dataGridView.RowHeadersVisible = false;
dataGridView.AllowUserToAddRows = false;
dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
}
public void ConfigureColumns(List<(string HeaderText, string DataPropertyName, float FillWeight)> columns)
{
dataGridView.Columns.Clear();
foreach (var column in columns)
{
dataGridView.Columns.Add(new DataGridViewTextBoxColumn
{
HeaderText = column.HeaderText,
DataPropertyName = column.DataPropertyName,
FillWeight = column.FillWeight
});
}
}
public void ClearRows()
{
dataGridView.Rows.Clear();
}
public int SelectedRowIndex
{
get => dataGridView.SelectedRows[0].Index;
set
{
if (value >= 0 && value < dataGridView.Rows.Count)
{
dataGridView.ClearSelection();
dataGridView.Rows[value].Selected = true;
}
}
}
public T GetSelectedObject<T>() where T : new()
{
if (dataGridView.SelectedRows.Count == 0)
throw new InvalidOperationException("Нет выбранной строки.");
var selectedRow = dataGridView.SelectedRows[0];
var obj = new T();
foreach (DataGridViewColumn column in dataGridView.Columns)
{
var prop = typeof(T).GetProperty(column.DataPropertyName);
if (prop != null)
{
var value = selectedRow.Cells[column.Index].Value;
prop.SetValue(obj, Convert.ChangeType(value, prop.PropertyType));
}
}
return obj;
}
public void FillData<T>(List<T> objects)
{
dataGridView.Rows.Clear();
if (objects == null || !objects.Any())
{
return;
}
var properties = typeof(T).GetProperties();
for (int i = 0; i < objects.Count; ++i)
{
var row = objects[i];
dataGridView.Rows.Add();
for (int j = 0; j < dataGridView.ColumnCount; ++j)
{
var property = properties.FirstOrDefault(p => p.Name == dataGridView.Columns[j].DataPropertyName);
if (property != null)
{
dataGridView.Rows[i].Cells[j].Value = property.GetValue(row, null);
}
}
}
}
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
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
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -0,0 +1,57 @@
namespace Components
{
partial class CustomListBox
{
/// <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()
{
listBox = new ListBox();
SuspendLayout();
//
// listBox
//
listBox.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
listBox.FormattingEnabled = true;
listBox.ItemHeight = 15;
listBox.Location = new Point(3, 5);
listBox.Name = "listBox";
listBox.Size = new Size(144, 139);
listBox.TabIndex = 0;
//
// CustomListBox
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
Controls.Add(listBox);
Name = "CustomListBox";
ResumeLayout(false);
}
#endregion
private ListBox listBox;
}
}

View File

@ -0,0 +1,50 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Components
{
public partial class CustomListBox : UserControl
{
private event EventHandler? _itemSelected;
public CustomListBox()
{
InitializeComponent();
}
public void SetItems(List<string> items)
{
listBox.Items.AddRange(items.ToArray());
}
public void ClearList()
{
listBox.Items.Clear();
}
public string SelectedItem
{
get { return (string?)listBox.SelectedItem ?? string.Empty; }
set
{
int index = listBox.Items.IndexOf(value);
if (index != -1)
{
listBox.SelectedIndex = index;
}
}
}
private void MainListBox_SelectedIndexChanged(object sender, EventArgs e)
{
_itemSelected?.Invoke(this, e);
}
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
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
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -0,0 +1,68 @@
namespace Components
{
partial class CustomTextBox
{
/// <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()
{
checkBoxNull = new CheckBox();
textBoxInteger = new TextBox();
SuspendLayout();
//
// checkBoxNull
//
checkBoxNull.AutoSize = true;
checkBoxNull.Location = new Point(13, 17);
checkBoxNull.Name = "checkBoxNull";
checkBoxNull.Size = new Size(15, 14);
checkBoxNull.TabIndex = 0;
checkBoxNull.UseVisualStyleBackColor = true;
//
// textBoxInteger
//
textBoxInteger.Location = new Point(34, 13);
textBoxInteger.Name = "textBoxInteger";
textBoxInteger.Size = new Size(100, 23);
textBoxInteger.TabIndex = 1;
//
// IntegerInputControl
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
Controls.Add(textBoxInteger);
Controls.Add(checkBoxNull);
Name = "IntegerInputControl";
Size = new Size(146, 49);
ResumeLayout(false);
PerformLayout();
}
#endregion
private CheckBox checkBoxNull;
private TextBox textBoxInteger;
}
}

View File

@ -0,0 +1,64 @@
using Components.Exceptions;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Components
{
public partial class CustomTextBox : UserControl
{
public event EventHandler ValueChanged;
public CustomTextBox()
{
InitializeComponent();
checkBoxNull.CheckedChanged += CheckBoxNull_CheckedChanged;
textBoxInteger.TextChanged += TextBoxInteger_TextChanged;
}
public int? Value
{
get
{
if (checkBoxNull.Checked)
{
return null;
}
else
{
if (int.TryParse(textBoxInteger.Text, out int result))
{
return result;
}
else
{
throw new NotIntegerException("Ожидается целое число.");
}
}
}
set
{
checkBoxNull.Checked = !value.HasValue;
textBoxInteger.Text = value.HasValue ? value.ToString() : string.Empty;
}
}
private void TextBoxInteger_TextChanged(object sender, EventArgs e)
{
ValueChanged?.Invoke(this, e);
}
private void CheckBoxNull_CheckedChanged(object sender, EventArgs e)
{
textBoxInteger.Enabled = !checkBoxNull.Checked;
ValueChanged?.Invoke(this, e);
}
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
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
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

124
WinFormsTest/Form1.Designer.cs generated Normal file
View File

@ -0,0 +1,124 @@
namespace WinFormsTest
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </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
//
customListBox.Location = new Point(41, 40);
customListBox.Name = "customListBox";
customListBox.SelectedItem = "";
customListBox.Size = new Size(150, 150);
customListBox.TabIndex = 0;
//
// customTextBox
//
customTextBox.Location = new Point(250, 40);
customTextBox.Name = "customTextBox";
customTextBox.Size = new Size(150, 150);
customTextBox.TabIndex = 1;
//
// customDataGridView1
//
customDataGridView1.Location = new Point(470, 50);
customDataGridView1.Name = "customDataGridView1";
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(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);
}
#endregion
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;
}
}

178
WinFormsTest/Form1.cs Normal file
View File

@ -0,0 +1,178 @@
using Components;
using Components.NonVisual;
using Components.Object;
using Components.SaveToPdfHelpers;
using OxyPlot.Legends;
namespace WinFormsTest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
InitializeListBox();
InitializeDataGridView();
}
private void InitializeListBox()
{
customListBox.SetItems(new List<string>
{
"Hi 1",
"Hi 2",
"Hi 3",
"Hi 4",
"Hi 5",
});
}
private void InitializeDataGridView()
{
var columns = new List<(string HeaderText, string DataPropertyName, float FillWeight)>
{
("Èìÿ", "Name", 1),
("Âîçðàñò", "Age", 1),
("Email", "Email", 2)
};
customDataGridView1.ConfigureColumns(columns);
var data = new List<Person>
{
new Person ("Èâàí", 30, "ivan@gmail.com" ),
new Person ("Ìàðèÿ", 25, "maria@gmail.com")
};
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("Ïðîèçîøëà îøèáêà: íå âûáðàí ïóòü äëÿ ôàéëà");
return;
}
var settings = new PdfDocumentData(
filePath,
"Íàçâàíèå äîêóìåíòà",
new List<string[,]>
{
new string[,]
{
{ "ß÷åéêà 1.1", "ß÷åéêà 2.1", "ß÷åéêà 3.1" },
{ "ß÷åéêà 2.1", "ß÷åéêà 2.2", "ß÷åéêà 3.2" }
},
new string[,]
{
{ "Íå ÿ÷åéêà 1", "Íå ÿ÷åéêà 2" },
{ "ß÷Àéêà 1", "ß÷Àéêà 2" }
}
});
try
{
tablepdf1.GeneratePdf(settings);
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)
{
string filePath = FilePath();
if (filePath == String.Empty)
{
MessageBox.Show("Ïðîèçîøëà îøèáêà: íå âûáðàí ïóòü äëÿ ôàéëà");
return;
}
var settings = new PDFTableSettings<Person>
{
FilePath = filePath,
DocumentTitle = "Îò÷åò",
HeaderRowHeight = 1.0f,
DataRowHeight = 1.0f,
DataList = new List<Person>
{
new Person ( "Àëåêñàíä Áóáûë¸â", 30, "Alex@mail.ru" ),
new Person ( "Øåðëîê Õîëìñ", 25, "221B_Baker_Street@mail.com" ),
new Person ("Ñòàñ Àñàôüåâ", 41, "Stas@gmail.com")
},
Columns = new List<(string, float, string, int)>
{
("ÔÈÎ", 6.0f, nameof(Person.Name), 0),
("Âîçðàñò", 2.0f, nameof(Person.Age), 1),
("Ïî÷òà", 6.0f, nameof(Person.Email), 2)
}
};
try
{
headeredTablepdf1.GeneratePDFWithHead(settings);
MessageBox.Show("PDF-äîêóìåíò óñïåøíî ñîçäàí!", "Óñïåõ", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show($"Îøèáêà: {ex.Message}");
}
}
private void btnGenerateHistogrammPdf_Click(object sender, EventArgs e)
{
string filePath = FilePath();
if (filePath == String.Empty)
{
MessageBox.Show("Ïðîèçîøëà îøèáêà: íå âûáðàí ïóòü äëÿ ôàéëà");
return;
}
var setting = new HistogramData
{
FilePath = filePath,
DocumentTitle = "Ãèñòîãðàììà",
ChartTitle = "Ïðèìåð ãèñòîãðàììû",
LegendPosition = LegendPositions.Bottom,
ChartData = new List<ChartData>
{
new ChartData { SeriesName = "Ñåðèÿ 1", Data = new Dictionary<string, double> { { "Êàòåãîðèÿ 1", 5 }, { "Êàòåãîðèÿ 2", 10 } } },
new ChartData { SeriesName = "Ñåðèÿ 2", Data = new Dictionary<string, double> { { "Êàòåãîðèÿ 1", 3 }, { "Êàòåãîðèÿ 2", 8 } } },
new ChartData { SeriesName = "Ñåðèÿ 3", Data = new Dictionary<string, double> { { "Êàòåãîðèÿ 1", 3 }, { "Êàòåãîðèÿ 2", 8 } } }
}
};
try
{
histogrampdf1.CreateHistogramPdf(setting);
MessageBox.Show("PDF óñïåøíî ñãåíåðèðîâàí!", "Óñïåõ", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show($"Îøèáêà: {ex.Message}", "Îøèáêà", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}

129
WinFormsTest/Form1.resx Normal file
View File

@ -0,0 +1,129 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
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
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<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>

17
WinFormsTest/Program.cs Normal file
View File

@ -0,0 +1,17 @@
namespace WinFormsTest
{
internal static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
Application.Run(new Form1());
}
}
}

View File

@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Components\Components.csproj" />
</ItemGroup>
</Project>