diff --git a/CheckedListBoxLibrary/Components/PdfDiagram/PdfDiagram.Designer.cs b/CheckedListBoxLibrary/Components/PdfDiagram/PdfDiagram.Designer.cs new file mode 100644 index 0000000..114f350 --- /dev/null +++ b/CheckedListBoxLibrary/Components/PdfDiagram/PdfDiagram.Designer.cs @@ -0,0 +1,36 @@ +namespace MyUserControls.Components.PdfDiagram +{ + partial class PdfDiagram + { + /// + /// Обязательная переменная конструктора. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Освободить все используемые ресурсы. + /// + /// истинно, если управляемый ресурс должен быть удален; иначе ложно. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Код, автоматически созданный конструктором компонентов + + /// + /// Требуемый метод для поддержки конструктора — не изменяйте + /// содержимое этого метода с помощью редактора кода. + /// + private void InitializeComponent() + { + components = new System.ComponentModel.Container(); + } + + #endregion + } +} diff --git a/CheckedListBoxLibrary/Components/PdfDiagram/PdfDiagram.cs b/CheckedListBoxLibrary/Components/PdfDiagram/PdfDiagram.cs new file mode 100644 index 0000000..3978246 --- /dev/null +++ b/CheckedListBoxLibrary/Components/PdfDiagram/PdfDiagram.cs @@ -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); + } + } +} + diff --git a/CheckedListBoxLibrary/Components/PdfDiagram/PdfDiagramInfo.cs b/CheckedListBoxLibrary/Components/PdfDiagram/PdfDiagramInfo.cs new file mode 100644 index 0000000..d11aadb --- /dev/null +++ b/CheckedListBoxLibrary/Components/PdfDiagram/PdfDiagramInfo.cs @@ -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."); + } + } +} diff --git a/CheckedListBoxLibrary/MyUserControls.csproj b/CheckedListBoxLibrary/MyUserControls.csproj index 09a8f03..f73b361 100644 --- a/CheckedListBoxLibrary/MyUserControls.csproj +++ b/CheckedListBoxLibrary/MyUserControls.csproj @@ -11,8 +11,4 @@ - - - - diff --git a/WinFormsApp1/Documents/PdfWithPieDiagram.pdf b/WinFormsApp1/Documents/PdfWithPieDiagram.pdf new file mode 100644 index 0000000..410d14a Binary files /dev/null and b/WinFormsApp1/Documents/PdfWithPieDiagram.pdf differ diff --git a/WinFormsApp1/Form1.Designer.cs b/WinFormsApp1/Form1.Designer.cs index bf8e714..a34db11 100644 --- a/WinFormsApp1/Form1.Designer.cs +++ b/WinFormsApp1/Form1.Designer.cs @@ -41,6 +41,8 @@ createPdfImages = new Button(); pdfTable = new MyUserControls.Components.PdfTable.PdfTable(components); createTable = new Button(); + pdfDiagram = new MyUserControls.Components.PdfDiagram.PdfDiagram(components); + createDiagram = new Button(); SuspendLayout(); // // smartCheckedListBox1 @@ -110,13 +112,13 @@ createPdfImages.Name = "createPdfImages"; createPdfImages.Size = new Size(184, 29); createPdfImages.TabIndex = 8; - createPdfImages.Text = "Создать пдф"; + createPdfImages.Text = "Создать картинки пдф"; createPdfImages.UseVisualStyleBackColor = true; createPdfImages.Click += createPdfImages_Click; // // createTable // - createTable.Location = new Point(330, 316); + createTable.Location = new Point(330, 305); createTable.Name = "createTable"; createTable.Size = new Size(184, 31); createTable.TabIndex = 9; @@ -124,11 +126,22 @@ createTable.UseVisualStyleBackColor = true; 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 // AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(1120, 474); + Controls.Add(createDiagram); Controls.Add(createTable); Controls.Add(createPdfImages); Controls.Add(chooseImage); @@ -157,5 +170,7 @@ private Button createPdfImages; private MyUserControls.Components.PdfTable.PdfTable pdfTable; private Button createTable; + private MyUserControls.Components.PdfDiagram.PdfDiagram pdfDiagram; + private Button createDiagram; } } diff --git a/WinFormsApp1/Form1.cs b/WinFormsApp1/Form1.cs index af090f0..67dd859 100644 --- a/WinFormsApp1/Form1.cs +++ b/WinFormsApp1/Form1.cs @@ -1,5 +1,6 @@ using MyUserControls; using MyUserControls.Components.office_package.Implements; +using MyUserControls.Components.PdfDiagram; using MyUserControls.Components.PdfImage; using MyUserControls.Components.PdfTable; 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 + { + { "Windows", 71.5 }, + { "OS X", 15.5 }, + { "Linux", 4.5 }, + { "Others", 8.5 }, + } + } + }); + MessageBox.Show("PDF !", " "); + } + catch (Exception ex) + { + MessageBox.Show($" : {ex.Message}"); + } + } + } } diff --git a/WinFormsApp1/Form1.resx b/WinFormsApp1/Form1.resx index 68b4e87..9e61fdc 100644 --- a/WinFormsApp1/Form1.resx +++ b/WinFormsApp1/Form1.resx @@ -126,4 +126,7 @@ 304, 17 + + 418, 17 + \ No newline at end of file diff --git a/WinFormsApp1/WinFormsApp1.csproj b/WinFormsApp1/WinFormsApp1.csproj index 87d28fe..f3803f8 100644 --- a/WinFormsApp1/WinFormsApp1.csproj +++ b/WinFormsApp1/WinFormsApp1.csproj @@ -12,8 +12,4 @@ - - - - \ No newline at end of file