Третий компонент вроде работает

This commit is contained in:
Kirill 2024-11-17 17:59:17 +04:00
parent 1cbc55bbe9
commit e43bb439a2
9 changed files with 167 additions and 10 deletions

View File

@ -0,0 +1,36 @@
namespace MyUserControls.Components.PdfDiagram
{
partial class PdfDiagram
{
/// <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,46 @@
using MyUserControls.Components.office_package.HelperEnums;
using MyUserControls.Components.office_package.HelperModels;
using MyUserControls.Components.office_package.Implements;
using MyUserControls.Components.office_package;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MyUserControls.Components.PdfDiagram
{
public partial class PdfDiagram : Component
{
ISaveToPdf SaveToPdf = new SaveToPdf();
public PdfDiagram()
{
InitializeComponent();
}
public PdfDiagram(IContainer container)
{
container.Add(this);
InitializeComponent();
}
public void CreateDiagram(PdfDiagramInfo info)
{
info.CheckFields();
SaveToPdf.CreatePdf(info);
SaveToPdf.CreateParagraph(new PdfParagraph
{
Text = info.Title,
Style = "NormalTitle",
ParagraphAlignment = PdfParagraphAlignmentType.Center
});
SaveToPdf.CreatePieChart(info);
SaveToPdf.SavePdf(info);
}
}
}

View File

@ -0,0 +1,29 @@
using MyUserControls.Components.office_package.HelperEnums;
using MyUserControls.Components.office_package.HelperModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MyUserControls.Components.PdfDiagram
{
public class PdfDiagramInfo : IPdfInfo, IPdfPieChartParameters
{
public string FileName { get; set; } = string.Empty;
public string Title { get; set; } = string.Empty;
public string ChartTitle { get; set; } = string.Empty;
public PdfDiagramLegendLocation LegendLocation { get; set; } = PdfDiagramLegendLocation.Right;
public PdfDiagramSeries Series { get; set; } = new();
public void CheckFields()
{
if (string.IsNullOrEmpty(FileName))
throw new ArgumentNullException(nameof(FileName), "File path and name cannot be null or empty.");
if (string.IsNullOrEmpty(Title))
throw new ArgumentNullException(nameof(Title), "Title cannot be null or empty.");
if (Series == null)
throw new ArgumentNullException(nameof(Series), "Series cannot be null or empty.");
}
}
}

View File

@ -11,8 +11,4 @@
<PackageReference Include="PDFsharp-MigraDoc-GDI" Version="6.1.1" /> <PackageReference Include="PDFsharp-MigraDoc-GDI" Version="6.1.1" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Folder Include="Components\PdfDiagram\" />
</ItemGroup>
</Project> </Project>

Binary file not shown.

View File

@ -41,6 +41,8 @@
createPdfImages = new Button(); createPdfImages = new Button();
pdfTable = new MyUserControls.Components.PdfTable.PdfTable(components); pdfTable = new MyUserControls.Components.PdfTable.PdfTable(components);
createTable = new Button(); createTable = new Button();
pdfDiagram = new MyUserControls.Components.PdfDiagram.PdfDiagram(components);
createDiagram = new Button();
SuspendLayout(); SuspendLayout();
// //
// smartCheckedListBox1 // smartCheckedListBox1
@ -110,13 +112,13 @@
createPdfImages.Name = "createPdfImages"; createPdfImages.Name = "createPdfImages";
createPdfImages.Size = new Size(184, 29); createPdfImages.Size = new Size(184, 29);
createPdfImages.TabIndex = 8; createPdfImages.TabIndex = 8;
createPdfImages.Text = "Создать пдф"; createPdfImages.Text = "Создать картинки пдф";
createPdfImages.UseVisualStyleBackColor = true; createPdfImages.UseVisualStyleBackColor = true;
createPdfImages.Click += createPdfImages_Click; createPdfImages.Click += createPdfImages_Click;
// //
// createTable // createTable
// //
createTable.Location = new Point(330, 316); createTable.Location = new Point(330, 305);
createTable.Name = "createTable"; createTable.Name = "createTable";
createTable.Size = new Size(184, 31); createTable.Size = new Size(184, 31);
createTable.TabIndex = 9; createTable.TabIndex = 9;
@ -124,11 +126,22 @@
createTable.UseVisualStyleBackColor = true; createTable.UseVisualStyleBackColor = true;
createTable.Click += createTable_Click; createTable.Click += createTable_Click;
// //
// createDiagram
//
createDiagram.Location = new Point(331, 351);
createDiagram.Name = "createDiagram";
createDiagram.Size = new Size(185, 29);
createDiagram.TabIndex = 10;
createDiagram.Text = "Создать диаграмму пдф";
createDiagram.UseVisualStyleBackColor = true;
createDiagram.Click += createDiagram_Click;
//
// Form1 // Form1
// //
AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1120, 474); ClientSize = new Size(1120, 474);
Controls.Add(createDiagram);
Controls.Add(createTable); Controls.Add(createTable);
Controls.Add(createPdfImages); Controls.Add(createPdfImages);
Controls.Add(chooseImage); Controls.Add(chooseImage);
@ -157,5 +170,7 @@
private Button createPdfImages; private Button createPdfImages;
private MyUserControls.Components.PdfTable.PdfTable pdfTable; private MyUserControls.Components.PdfTable.PdfTable pdfTable;
private Button createTable; private Button createTable;
private MyUserControls.Components.PdfDiagram.PdfDiagram pdfDiagram;
private Button createDiagram;
} }
} }

View File

@ -1,5 +1,6 @@
using MyUserControls; using MyUserControls;
using MyUserControls.Components.office_package.Implements; using MyUserControls.Components.office_package.Implements;
using MyUserControls.Components.PdfDiagram;
using MyUserControls.Components.PdfImage; using MyUserControls.Components.PdfImage;
using MyUserControls.Components.PdfTable; using MyUserControls.Components.PdfTable;
using System.ComponentModel; using System.ComponentModel;
@ -183,5 +184,40 @@ namespace WinFormsApp1
} }
} }
private void createDiagram_Click(object sender, EventArgs e)
{
try
{
string currentDirectory = Directory.GetCurrentDirectory();
string filePath = Path.Combine(currentDirectory, @"..\..\..\Documents\PdfWithPieDiagram.pdf");
pdfDiagram.CreateDiagram(new PdfDiagramInfo
{
FileName = filePath,
Title = "Title",
ChartTitle = "OS 2024",
LegendLocation = MyUserControls.Components.office_package.HelperEnums.PdfDiagramLegendLocation.Bottom,
Series = new MyUserControls.Components.office_package.HelperModels.PdfDiagramSeries
{
SeriesName = "DesctopOperatingSystemAugust2024",
Data = new Dictionary<string, double>
{
{ "Windows", 71.5 },
{ "OS X", 15.5 },
{ "Linux", 4.5 },
{ "Others", 8.5 },
}
}
});
MessageBox.Show("PDF óñïåøíî ñîçäàí!", "ïäô ñîçäàí");
}
catch (Exception ex)
{
MessageBox.Show($"íå óäàëîñü ñîçäàòü ïäô: {ex.Message}");
}
}
} }
} }

View File

@ -126,4 +126,7 @@
<metadata name="pdfTable.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> <metadata name="pdfTable.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>304, 17</value> <value>304, 17</value>
</metadata> </metadata>
<metadata name="pdfDiagram.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>418, 17</value>
</metadata>
</root> </root>

View File

@ -12,8 +12,4 @@
<ProjectReference Include="..\CheckedListBoxLibrary\MyUserControls.csproj" /> <ProjectReference Include="..\CheckedListBoxLibrary\MyUserControls.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Folder Include="Documents\" />
</ItemGroup>
</Project> </Project>