первый финал
This commit is contained in:
parent
0cd24d6b30
commit
1cd9ae93c9
15
ExexForm2/Form1.Designer.cs
generated
15
ExexForm2/Form1.Designer.cs
generated
@ -38,6 +38,8 @@
|
|||||||
lblDirectory = new Label();
|
lblDirectory = new Label();
|
||||||
btnCrTb = new Button();
|
btnCrTb = new Button();
|
||||||
pdfColGroupTable1 = new Library14Petrushin.PdfColGroupTable();
|
pdfColGroupTable1 = new Library14Petrushin.PdfColGroupTable();
|
||||||
|
pdfCirclDiagr1 = new Library14Petrushin.PdfCirclDiagr();
|
||||||
|
btnCircl = new Button();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
// btnSelectImages
|
// btnSelectImages
|
||||||
@ -104,11 +106,22 @@
|
|||||||
btnCrTb.UseVisualStyleBackColor = true;
|
btnCrTb.UseVisualStyleBackColor = true;
|
||||||
btnCrTb.Click += btnCreatePdfTable_Click;
|
btnCrTb.Click += btnCreatePdfTable_Click;
|
||||||
//
|
//
|
||||||
|
// btnCircl
|
||||||
|
//
|
||||||
|
btnCircl.Location = new Point(606, 28);
|
||||||
|
btnCircl.Name = "btnCircl";
|
||||||
|
btnCircl.Size = new Size(161, 29);
|
||||||
|
btnCircl.TabIndex = 7;
|
||||||
|
btnCircl.Text = "Создать диаграмму";
|
||||||
|
btnCircl.UseVisualStyleBackColor = true;
|
||||||
|
btnCircl.Click += btnCreatePdfCircl_Click;
|
||||||
|
//
|
||||||
// Form1
|
// Form1
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
ClientSize = new Size(800, 450);
|
ClientSize = new Size(800, 450);
|
||||||
|
Controls.Add(btnCircl);
|
||||||
Controls.Add(btnCrTb);
|
Controls.Add(btnCrTb);
|
||||||
Controls.Add(lblDirectory);
|
Controls.Add(lblDirectory);
|
||||||
Controls.Add(lstImages);
|
Controls.Add(lstImages);
|
||||||
@ -133,5 +146,7 @@
|
|||||||
private Label lblDirectory;
|
private Label lblDirectory;
|
||||||
private Button btnCrTb;
|
private Button btnCrTb;
|
||||||
private Library14Petrushin.PdfColGroupTable pdfColGroupTable1;
|
private Library14Petrushin.PdfColGroupTable pdfColGroupTable1;
|
||||||
|
private Library14Petrushin.PdfCirclDiagr pdfCirclDiagr1;
|
||||||
|
private Button btnCircl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using Library14Petrushin;
|
using Library14Petrushin;
|
||||||
|
using Library14Petrushin.Classes;
|
||||||
|
|
||||||
namespace ExexForm2
|
namespace ExexForm2
|
||||||
{
|
{
|
||||||
@ -8,6 +9,7 @@ namespace ExexForm2
|
|||||||
private List<ImageData> selectedImages;
|
private List<ImageData> selectedImages;
|
||||||
private string selectedDirectory;
|
private string selectedDirectory;
|
||||||
private PdfColGroupTable pdfTable;
|
private PdfColGroupTable pdfTable;
|
||||||
|
private PdfCirclDiagr pdfCirclDiagr;
|
||||||
|
|
||||||
public Form1()
|
public Form1()
|
||||||
{
|
{
|
||||||
@ -15,6 +17,7 @@ namespace ExexForm2
|
|||||||
pdfImg = new PdfImg();
|
pdfImg = new PdfImg();
|
||||||
selectedImages = new List<ImageData>();
|
selectedImages = new List<ImageData>();
|
||||||
pdfTable = new PdfColGroupTable();
|
pdfTable = new PdfColGroupTable();
|
||||||
|
pdfCirclDiagr = new PdfCirclDiagr();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void btnSelectImages_Click(object sender, EventArgs e)
|
private void btnSelectImages_Click(object sender, EventArgs e)
|
||||||
@ -55,13 +58,13 @@ namespace ExexForm2
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
string fileName = Path.Combine(selectedDirectory, "output.pdf");
|
string fileName = Path.Combine(selectedDirectory, "output1.pdf");
|
||||||
pdfImg.CreatePdfDocument(fileName, txtDocumentTitle.Text, selectedImages);
|
pdfImg.CreatePdfDocument(fileName, txtDocumentTitle.Text, selectedImages);
|
||||||
MessageBox.Show("PDF document created successfully!");
|
MessageBox.Show("PDF document created successfully!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// -------------------------------------------
|
// 2 -------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
private void btnCreatePdfTable_Click(object sender, EventArgs e)
|
private void btnCreatePdfTable_Click(object sender, EventArgs e)
|
||||||
@ -76,7 +79,7 @@ namespace ExexForm2
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
string fileName = Path.Combine(selectDirTable, "output.pdf");
|
string fileName = Path.Combine(selectDirTable, "output2.pdf");
|
||||||
|
|
||||||
var generator = new PdfColGroupTable();
|
var generator = new PdfColGroupTable();
|
||||||
|
|
||||||
@ -98,5 +101,36 @@ namespace ExexForm2
|
|||||||
|
|
||||||
generator.GeneratePdf(fileName, "Example Document", mergeCells, rowHeights, headers, commonHeaders, propertyNames, data1);
|
generator.GeneratePdf(fileName, "Example Document", mergeCells, rowHeights, headers, commonHeaders, propertyNames, data1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// 3 -------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
private void btnCreatePdfCircl_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
string selectDir = "";
|
||||||
|
|
||||||
|
using (FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog())
|
||||||
|
{
|
||||||
|
if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
selectDir = folderBrowserDialog.SelectedPath;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
string fileName = Path.Combine(selectDir, "output3.pdf");
|
||||||
|
|
||||||
|
var pdfCirclDiagr = new PdfCirclDiagr();
|
||||||
|
|
||||||
|
List<ChartData> chartData = new List<ChartData>
|
||||||
|
{
|
||||||
|
new ChartData { SeriesName = "Series 1", Value = 10 },
|
||||||
|
new ChartData { SeriesName = "Series 2", Value = 20 },
|
||||||
|
new ChartData { SeriesName = "Series 3", Value = 30 },
|
||||||
|
new ChartData { SeriesName = "Series 4", Value = 40 }
|
||||||
|
};
|
||||||
|
|
||||||
|
pdfCirclDiagr.GeneratePdf(fileName, "Document Title", "Chart Title", LegendPosition.Right, chartData);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -123,4 +123,7 @@
|
|||||||
<metadata name="pdfColGroupTable1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
<metadata name="pdfColGroupTable1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||||
<value>130, 17</value>
|
<value>130, 17</value>
|
||||||
</metadata>
|
</metadata>
|
||||||
|
<metadata name="pdfCirclDiagr1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||||
|
<value>315, 17</value>
|
||||||
|
</metadata>
|
||||||
</root>
|
</root>
|
14
Library14Petrushin/Classes/ChartData.cs
Normal file
14
Library14Petrushin/Classes/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 Library14Petrushin.Classes
|
||||||
|
{
|
||||||
|
public class ChartData
|
||||||
|
{
|
||||||
|
public string? SeriesName { get; set; }
|
||||||
|
public double Value { get; set; }
|
||||||
|
}
|
||||||
|
}
|
16
Library14Petrushin/Classes/LegendPosition.cs
Normal file
16
Library14Petrushin/Classes/LegendPosition.cs
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Library14Petrushin.Classes
|
||||||
|
{
|
||||||
|
public enum LegendPosition
|
||||||
|
{
|
||||||
|
Top,
|
||||||
|
Bottom,
|
||||||
|
Left,
|
||||||
|
Right
|
||||||
|
}
|
||||||
|
}
|
36
Library14Petrushin/PdfCirclDiagr.Designer.cs
generated
Normal file
36
Library14Petrushin/PdfCirclDiagr.Designer.cs
generated
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
namespace Library14Petrushin
|
||||||
|
{
|
||||||
|
partial class PdfCirclDiagr
|
||||||
|
{
|
||||||
|
/// <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
|
||||||
|
}
|
||||||
|
}
|
96
Library14Petrushin/PdfCirclDiagr.cs
Normal file
96
Library14Petrushin/PdfCirclDiagr.cs
Normal file
@ -0,0 +1,96 @@
|
|||||||
|
using Library14Petrushin.Classes;
|
||||||
|
using PdfSharp.Drawing;
|
||||||
|
using PdfSharp.Pdf;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Library14Petrushin
|
||||||
|
{
|
||||||
|
public partial class PdfCirclDiagr : Component
|
||||||
|
{
|
||||||
|
public void GeneratePdf(
|
||||||
|
string fileName,
|
||||||
|
string documentTitle,
|
||||||
|
string chartTitle,
|
||||||
|
LegendPosition legendPosition,
|
||||||
|
List<ChartData> chartData)
|
||||||
|
{
|
||||||
|
// Проверка на заполненность входных данных
|
||||||
|
if (string.IsNullOrEmpty(fileName) || string.IsNullOrEmpty(documentTitle) ||
|
||||||
|
string.IsNullOrEmpty(chartTitle) || chartData == null || !chartData.Any())
|
||||||
|
{
|
||||||
|
throw new ArgumentException("Все входные данные должны быть заполнены.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Создание документа
|
||||||
|
PdfDocument document = new PdfDocument();
|
||||||
|
PdfPage page = document.AddPage();
|
||||||
|
XGraphics gfx = XGraphics.FromPdfPage(page);
|
||||||
|
XFont font = new XFont("Verdana", 10);
|
||||||
|
|
||||||
|
// Отрисовка заголовка документа
|
||||||
|
gfx.DrawString(documentTitle, new XFont("Verdana", 16, XFontStyleEx.Bold), XBrushes.Black, new XRect(0, 0, page.Width, 50), XStringFormats.Center);
|
||||||
|
|
||||||
|
// Отрисовка заголовка диаграммы
|
||||||
|
gfx.DrawString(chartTitle, font, XBrushes.Black, new XRect(50, 50, page.Width - 100, 30), XStringFormats.Center);
|
||||||
|
|
||||||
|
// Отрисовка круговой диаграммы
|
||||||
|
DrawPieChart(gfx, new XRect(50, 100, 300, 300), chartData, legendPosition);
|
||||||
|
|
||||||
|
// Сохранение документа
|
||||||
|
document.Save(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DrawPieChart(XGraphics gfx, XRect rect, List<ChartData> chartData, LegendPosition legendPosition)
|
||||||
|
{
|
||||||
|
double total = chartData.Sum(d => d.Value);
|
||||||
|
double startAngle = 0;
|
||||||
|
int legendX = 0;
|
||||||
|
int legendY = 0;
|
||||||
|
|
||||||
|
// Определение расположения легенды
|
||||||
|
switch (legendPosition)
|
||||||
|
{
|
||||||
|
case LegendPosition.Top:
|
||||||
|
legendX = (int)rect.X + (int)rect.Width / 2;
|
||||||
|
legendY = (int)rect.Y - 50;
|
||||||
|
break;
|
||||||
|
case LegendPosition.Bottom:
|
||||||
|
legendX = (int)rect.X + (int)rect.Width / 2;
|
||||||
|
legendY = (int)rect.Y + (int)rect.Height + 20;
|
||||||
|
break;
|
||||||
|
case LegendPosition.Left:
|
||||||
|
legendX = (int)rect.X - 100;
|
||||||
|
legendY = (int)rect.Y + (int)rect.Height / 2;
|
||||||
|
break;
|
||||||
|
case LegendPosition.Right:
|
||||||
|
legendX = (int)rect.X + (int)rect.Width + 20;
|
||||||
|
legendY = (int)rect.Y + (int)rect.Height / 2;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Отрисовка секторов диаграммы
|
||||||
|
foreach (var data in chartData)
|
||||||
|
{
|
||||||
|
double sweepAngle = 360 * (data.Value / total);
|
||||||
|
gfx.DrawPie(GetRandomBrush(), rect, startAngle, sweepAngle);
|
||||||
|
startAngle += sweepAngle;
|
||||||
|
|
||||||
|
// Отрисовка легенды
|
||||||
|
gfx.DrawString(data.SeriesName, new XFont("Verdana", 8), XBrushes.Black, new XPoint(legendX, legendY));
|
||||||
|
legendY += 20;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private XBrush GetRandomBrush()
|
||||||
|
{
|
||||||
|
Random random = new Random();
|
||||||
|
return new XSolidBrush(XColor.FromArgb(random.Next(256), random.Next(256), random.Next(256)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user