diff --git a/Components/Components.csproj b/Components/Components.csproj index 3e210aa..f0cc98f 100644 --- a/Components/Components.csproj +++ b/Components/Components.csproj @@ -7,4 +7,9 @@ enable + + + + + diff --git a/Components/Components/NonVisualComponents/HelperModels/DataForImage.cs b/Components/Components/NonVisualComponents/HelperModels/DataForImage.cs new file mode 100644 index 0000000..dac2be4 --- /dev/null +++ b/Components/Components/NonVisualComponents/HelperModels/DataForImage.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Components.Components.NonVisualComponents.HelperModels +{ + public class DataForImage + { + public DataForImage(string filepath, string header, string[] imagepaths) + { + this.filepath = filepath; + this.header = header; + this.imagepaths = imagepaths; + } + + public string filepath; + public string header; + public string[] imagepaths; + + } +} diff --git a/Components/Components/NonVisualComponents/HelperModels/DataForPieChart.cs b/Components/Components/NonVisualComponents/HelperModels/DataForPieChart.cs new file mode 100644 index 0000000..84c88e8 --- /dev/null +++ b/Components/Components/NonVisualComponents/HelperModels/DataForPieChart.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Components.Components.NonVisualComponents.HelperModels +{ + public class DataForPieChart + { + public string FilePath = string.Empty; + public string DocumentTitle = string.Empty;//заголовок документа + public string ChartTitle = string.Empty;//заголовок диаграммы + public DiagramLegendEnum diagLegend; + public string LegendName = string.Empty; + public List<(double, string)> Items; + + public DataForPieChart(string filePath, string documentTitle, string charttitle, DiagramLegendEnum diagLegend, string legendName, List<(double, string)> items) + { + FilePath = filePath; + DocumentTitle = documentTitle; + ChartTitle = charttitle; + this.diagLegend = diagLegend; + LegendName = legendName; + Items = items; + } + + } +} diff --git a/Components/Components/NonVisualComponents/HelperModels/DataForTable.cs b/Components/Components/NonVisualComponents/HelperModels/DataForTable.cs new file mode 100644 index 0000000..312fcc1 --- /dev/null +++ b/Components/Components/NonVisualComponents/HelperModels/DataForTable.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Components.Components.NonVisualComponents.HelperModels +{ + public class DataForTable + { + public string FilePath = string.Empty; + public string DocumentTitle = string.Empty; //заголовок документа + public List Heights; // высота строк + public List<(int, int)> Merges; // информаци о объединении ячеек + public List<(string props, string heads)> Headers; //заголовки шапки таблицы + public List Data; + public DataForTable(string filePath, string documentTitle, List heights, List<(int, int)> merges, List<(string, string)> headers, List data) + { + FilePath = filePath; + DocumentTitle = documentTitle; + Heights = heights; + Merges = merges; + Headers = headers; + Data = data; + } + + } +} diff --git a/Components/Components/NonVisualComponents/HelperModels/DiagramLegendEnum.cs b/Components/Components/NonVisualComponents/HelperModels/DiagramLegendEnum.cs new file mode 100644 index 0000000..b367600 --- /dev/null +++ b/Components/Components/NonVisualComponents/HelperModels/DiagramLegendEnum.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Components.Components.NonVisualComponents.HelperModels +{ + public enum DiagramLegendEnum + { + Top = 0, + Bottom = 1, + Right = 2, + Left = 3, + } + +} diff --git a/Components/Components/NonVisualComponents/PdfImage.Designer.cs b/Components/Components/NonVisualComponents/PdfImage.Designer.cs new file mode 100644 index 0000000..bc8accc --- /dev/null +++ b/Components/Components/NonVisualComponents/PdfImage.Designer.cs @@ -0,0 +1,36 @@ +namespace Components.Components.NonVisualComponents +{ + partial class PdfImage + { + /// + /// Обязательная переменная конструктора. + /// + 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/Components/Components/NonVisualComponents/PdfImage.cs b/Components/Components/NonVisualComponents/PdfImage.cs new file mode 100644 index 0000000..bb222fe --- /dev/null +++ b/Components/Components/NonVisualComponents/PdfImage.cs @@ -0,0 +1,75 @@ +using Components.Components.NonVisualComponents.HelperModels; +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.Text.RegularExpressions; +using System.Threading.Tasks; +using System.Xml.Linq; + + +namespace Components.Components.NonVisualComponents +{ + public partial class PdfImage : Component + { + public PdfImage() + { + InitializeComponent(); + } + + public PdfImage(IContainer container) + { + container.Add(this); + + InitializeComponent(); + } + + public bool CreatePdfDoc(DataForImage dataForImage) + { + Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); + CheckFileExsists(dataForImage); + // создание документа + Document _document = new Document(); + var style = _document.Styles["Normal"]; + style.Font.Name = "Arial"; + style.Font.Size = 25; + style = _document.Styles.AddStyle("NormalTitle", "Normal"); + style.Font.Bold = true; + + //добавление заголовка + var section = _document.AddSection(); + var paragraph = section.AddParagraph(dataForImage.header); + paragraph.Format.Alignment = ParagraphAlignment.Center; + paragraph.Format.SpaceAfter = "2cm"; + + //добавление изображений + foreach (string path in dataForImage.imagepaths) + if (File.Exists(path)) section.AddImage(path); + + //сохранение документа + PdfDocumentRenderer renderer = new PdfDocumentRenderer(true); + renderer.Document = _document; + renderer.RenderDocument(); + renderer.PdfDocument.Save(dataForImage.filepath); + + return true; + } + + private void CheckFileExsists(DataForImage dataForImage) + { + if (string.IsNullOrEmpty(dataForImage.filepath) || string.IsNullOrEmpty(dataForImage.header) || dataForImage.imagepaths.Length == 0) + { + throw new ArgumentNullException(); + } + if (!File.Exists(dataForImage.filepath)) + { + throw new FileNotFoundException(dataForImage.filepath); + } + } + + } +} diff --git a/Components/Components/NonVisualComponents/PdfPieChart.Designer.cs b/Components/Components/NonVisualComponents/PdfPieChart.Designer.cs new file mode 100644 index 0000000..71606fb --- /dev/null +++ b/Components/Components/NonVisualComponents/PdfPieChart.Designer.cs @@ -0,0 +1,36 @@ +namespace Components.Components.NonVisualComponents +{ + partial class PdfPieChart + { + /// + /// Обязательная переменная конструктора. + /// + 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/Components/Components/NonVisualComponents/PdfPieChart.cs b/Components/Components/NonVisualComponents/PdfPieChart.cs new file mode 100644 index 0000000..5f73c98 --- /dev/null +++ b/Components/Components/NonVisualComponents/PdfPieChart.cs @@ -0,0 +1,86 @@ +using Components.Components.NonVisualComponents.HelperModels; +using MigraDoc.DocumentObjectModel; +using MigraDoc.DocumentObjectModel.Shapes.Charts; +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; + +namespace Components.Components.NonVisualComponents +{ + public partial class PdfPieChart : Component + { + public PdfPieChart() + { + InitializeComponent(); + } + + public PdfPieChart(IContainer container) + { + container.Add(this); + + InitializeComponent(); + } + + public bool CreatePieChart(DataForPieChart dataForPDFPie) + { + // проверки + if (string.IsNullOrEmpty(dataForPDFPie.FilePath) || string.IsNullOrEmpty(dataForPDFPie.DocumentTitle) || string.IsNullOrEmpty(dataForPDFPie.ChartTitle) + || string.IsNullOrEmpty(dataForPDFPie.LegendName) + || dataForPDFPie.Items.Count == 0) throw new ArgumentException("Недостаточно данных"); + + Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); + + Document _document = new Document(); + var section = _document.AddSection(); + var paragraph = section.AddParagraph(dataForPDFPie.DocumentTitle); + paragraph.Format.Alignment = ParagraphAlignment.Center; + paragraph.Format.SpaceAfter = "2cm"; + + Chart chart = section.AddChart(ChartType.Pie2D); + chart.Width = Unit.FromCentimeter(16); + chart.Height = Unit.FromCentimeter(12); + chart.HeaderArea.AddParagraph(dataForPDFPie.ChartTitle); // заголовок диаграммы + + Series series = chart.SeriesCollection.AddSeries(); + series.Name = dataForPDFPie.LegendName; // название сериии + XSeries xseries = chart.XValues.AddXSeries(); + + foreach ((double, string) el in dataForPDFPie.Items) // заполнение серии + { + series.Add(el.Item1); + xseries.Add(el.Item2); + } + + switch (dataForPDFPie.diagLegend) // позиция легенды + { + case DiagramLegendEnum.Top: + chart.TopArea.AddLegend(); + break; + case DiagramLegendEnum.Bottom: + chart.BottomArea.AddLegend(); + break; + case DiagramLegendEnum.Right: + chart.RightArea.AddLegend(); + break; + case DiagramLegendEnum.Left: + chart.LeftArea.AddLegend(); + break; + } + + chart.DataLabel.Type = DataLabelType.Percent; + chart.DataLabel.Position = DataLabelPosition.OutsideEnd; + + PdfDocumentRenderer renderer = new PdfDocumentRenderer(true); + renderer.Document = _document; + renderer.RenderDocument(); + renderer.PdfDocument.Save(dataForPDFPie.FilePath); + + return true; + } + } +} diff --git a/Components/Components/NonVisualComponents/PdfTable.Designer.cs b/Components/Components/NonVisualComponents/PdfTable.Designer.cs new file mode 100644 index 0000000..2094fd3 --- /dev/null +++ b/Components/Components/NonVisualComponents/PdfTable.Designer.cs @@ -0,0 +1,36 @@ +namespace Components.Components.NonVisualComponents +{ + partial class PdfTable + { + /// + /// Обязательная переменная конструктора. + /// + 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/Components/Components/NonVisualComponents/PdfTable.cs b/Components/Components/NonVisualComponents/PdfTable.cs new file mode 100644 index 0000000..aa52897 --- /dev/null +++ b/Components/Components/NonVisualComponents/PdfTable.cs @@ -0,0 +1,178 @@ +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 Components.Components.NonVisualComponents.HelperModels; + +namespace Components.Components.NonVisualComponents +{ + public partial class PdfTable : Component + { + public PdfTable() + { + InitializeComponent(); + } + + public PdfTable(IContainer container) + { + container.Add(this); + + InitializeComponent(); + } + + public bool createTable(DataForTable dataForPDF) + { + //проверки + if (dataForPDF.Merges.Count == 0 || dataForPDF.Heights.Count == 0 || dataForPDF.Headers.Count == 0 + || dataForPDF.Data.Count == 0 || string.IsNullOrEmpty(dataForPDF.FilePath) + || string.IsNullOrEmpty(dataForPDF.DocumentTitle)) throw new ArgumentException("Недостаточно данных"); + + int[] cellsArray = new int[dataForPDF.Heights.Count]; + + foreach (var merge in dataForPDF.Merges) + { + if (merge.Item1 >= merge.Item2) throw new ArgumentException("Неправильно заполнены объединения строк"); + for (int i = merge.Item1; i < merge.Item2; i++) + { + cellsArray[i]++; + } + } + foreach (int cell in cellsArray) + { + if (cell > 1) throw new ArgumentException("Объединения заходят друг на друга"); + } + + foreach ((string, string) el in dataForPDF.Headers) + if (string.IsNullOrEmpty(el.Item2)) throw new ArgumentException("Элементы шапки не могут быть пустыми"); + + //создание документа + Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); + + Document _document = new Document(); + var style = _document.Styles["Normal"]; + + style = _document.Styles.AddStyle("NormalTitle", "Normal"); + style.Font.Name = "Arial"; + style.Font.Size = 25; + style.Font.Bold = true; + + style = _document.Styles.AddStyle("Table", "Normal"); + style.Font.Name = "Times New Roman"; + style.Font.Size = 12; + + //добавление заголовка + var section = _document.AddSection(); + var paragraph = section.AddParagraph(dataForPDF.DocumentTitle); + paragraph.Format.Alignment = ParagraphAlignment.Center; + paragraph.Format.SpaceAfter = "2cm"; + paragraph.Style = "NormalTitle"; + + //добавление таблицы + Table table = section.AddTable(); + table.Style = "Table"; + table.Borders.Width = 0.25; + + Column column; + + for (int i = 0; i < dataForPDF.Data.Count + 2; i++) + { + column = table.AddColumn(); + column.Format.Alignment = ParagraphAlignment.Center; + } + + // создание шапки и заполнение контентом + + int mergeRange = 0; //размерность слияния + int mergeIndex = 0; //стартовый индекс начала слияния + Row row; + for (int i = 0; i < dataForPDF.Headers.Count; i++) + { + //если элемент шапки группируются по строкам + if (dataForPDF.Merges.Select(x => x.Item1).Contains(mergeIndex)) + { + mergeRange = dataForPDF.Merges.Find(x => x.Item1 == mergeIndex).Item2 - mergeIndex; + mergeIndex = dataForPDF.Merges.Find(x => x.Item1 == mergeIndex).Item2 + 1; + + //стилизация ячейки. в этом блоке кода (до цикла) создаётся объединяющая ячейка + row = table.AddRow(); + row.Height = dataForPDF.Heights[i]; + row.Format.Alignment = ParagraphAlignment.Center; + row.Format.Font.Bold = true; + row.Cells[0].AddParagraph(dataForPDF.Headers[i].Item2); + row.Cells[0].VerticalAlignment = VerticalAlignment.Center; + row.Cells[0].MergeDown = mergeRange; + + //с этого места создаются дочерние ячейки + for (int k = 0; k < mergeRange; k++) + { + i++; + row.Cells[1].AddParagraph(dataForPDF.Headers[i].Item2); + AddTheContent(dataForPDF.Data, table, dataForPDF.Headers[i].Item1, row.Index, 2); + row.Cells[1].VerticalAlignment = VerticalAlignment.Center; + row = table.AddRow(); + row.Height = dataForPDF.Heights[i]; + row.Format.Font.Bold = true; + row.Format.Alignment = ParagraphAlignment.Center; + } + + i++; + row.Cells[1].AddParagraph(dataForPDF.Headers[i].Item2); + AddTheContent(dataForPDF.Data, table, dataForPDF.Headers[i].Item1, row.Index, 2); + row.Cells[1].VerticalAlignment = VerticalAlignment.Center; + } + else //если элемент шапки не группируется по строкам + + { + //стилизация ячейки + row = table.AddRow(); + row.Height = dataForPDF.Heights[i]; + row.Format.Font.Bold = true; + row.Format.Alignment = ParagraphAlignment.Center; + row.Cells[0].AddParagraph(dataForPDF.Headers[i].Item2); + row.Cells[0].VerticalAlignment = VerticalAlignment.Center; + row.Cells[0].MergeRight = 1; + + AddTheContent(dataForPDF.Data, table, dataForPDF.Headers[i].Item1, row.Index, 2); + + mergeIndex++; + } + } + + PdfDocumentRenderer renderer = new PdfDocumentRenderer(true); + renderer.Document = _document; + renderer.RenderDocument(); + renderer.PdfDocument.Save(dataForPDF.FilePath); + + return true; + } + + //метод заполнения таблицы контентом, заполнение происходит построчно. + public void AddTheContent(List items, Table table, string header, int row_index, int cell_index) + { + foreach (Row r in table.Rows) + { + for (int i = 0; i < items.Count; i++) + { + if (r.Index == row_index && row_index == 0) r.Cells[cell_index + i].AddParagraph((i + 1).ToString()); + else if (row_index != 0 && r.Index == row_index) + { + T item = items[i]; + var type = typeof(T); + var fields = type.GetFields(); + var field = fields.FirstOrDefault(x => x.Name.Equals(header)); + r.Cells[cell_index + i].AddParagraph(field.GetValue(item).ToString()); + r.Cells[cell_index + i].VerticalAlignment = VerticalAlignment.Center; + } + } + } + + } + + } +} diff --git a/Components/Components/VisualComponents/Classes/CharacterInfo.cs b/Components/Components/VisualComponents/Classes/CharacterInfo.cs new file mode 100644 index 0000000..54dd7c9 --- /dev/null +++ b/Components/Components/VisualComponents/Classes/CharacterInfo.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Components.Components.VisualComponents.Classes +{ + public class CharacterInfo + { + public string Age; + public string Name; + public string AKA; + public string Height; + public string Weight; + + public CharacterInfo(string age, string name, string aka, string height, string weight) + { + Age = age; + Name = name; + AKA = aka; + Height = height; + Weight = weight; + } + } +} diff --git a/Components/Components/VisualComponents/UserCheckedListBox.cs b/Components/Components/VisualComponents/UserCheckedListBox.cs index 4b982fa..d96ee2b 100644 --- a/Components/Components/VisualComponents/UserCheckedListBox.cs +++ b/Components/Components/VisualComponents/UserCheckedListBox.cs @@ -63,15 +63,8 @@ namespace Components { get { - if (checkedListBox.Items.Count == 0) - { - return ""; - } - if (checkedListBox.Items.Count == null) - { - return ""; - } - return checkedListBox.SelectedItem.ToString()!; + return checkedListBox.SelectedItem?.ToString() ?? string.Empty; + } set { diff --git a/Components/Components/VisualComponents/UserTextBox.cs b/Components/Components/VisualComponents/UserTextBox.cs index 63aaac5..c549e18 100644 --- a/Components/Components/VisualComponents/UserTextBox.cs +++ b/Components/Components/VisualComponents/UserTextBox.cs @@ -52,14 +52,8 @@ namespace Components.Components.VisualComponents } } - /* - private void textBox_Enter(object sender, EventArgs e) - { - ToolTip tt = new ToolTip(); - tt.Show(examp, textBox, 30, -20, 2000); - }*/ - public string? TextBoxValue + public string TextBoxValue { get { @@ -81,7 +75,6 @@ namespace Components.Components.VisualComponents if (value.Length >= MinValue && value.Length <= MaxValue) { textBox.Text = value; - _changeEvent?.Invoke(this, EventArgs.Empty); } } } diff --git a/Components/Components/VisualComponents/UserTreeView.cs b/Components/Components/VisualComponents/UserTreeView.cs index 756bbb5..c4a0df8 100644 --- a/Components/Components/VisualComponents/UserTreeView.cs +++ b/Components/Components/VisualComponents/UserTreeView.cs @@ -14,42 +14,34 @@ namespace Components.Components.VisualComponents public partial class UserTreeView : UserControl { private List hierarchy; - private Dictionary forcedNewBranch; public UserTreeView() { InitializeComponent(); hierarchy = new List(); - forcedNewBranch = new Dictionary(); } - public void SetHierarchy(List hierarchy, Dictionary forcedNewBranch) + public void SetHierarchy(List hierarchy) { this.hierarchy = hierarchy; - this.forcedNewBranch = forcedNewBranch; } - public void AddObjectToTree(T obj, string stopAtProperty) + public void AddObjectToTree(T obj) { TreeNode currentNode = treeView.Nodes.Count > 0 ? treeView.Nodes[0] : treeView.Nodes.Add(""); foreach (var property in hierarchy) { var value = obj.GetType().GetProperty(property).GetValue(obj, null).ToString(); - bool createNewBranch = forcedNewBranch.ContainsKey(property) && forcedNewBranch[property]; var childNode = currentNode.Nodes.Cast().FirstOrDefault(n => n.Text == value); - if (childNode == null || createNewBranch) + if (childNode == null) { childNode = currentNode.Nodes.Add(value); } currentNode = childNode; - if (property == stopAtProperty) - { - break; - } } } diff --git a/TestForm/Form1.Designer.cs b/TestForm/Form1.Designer.cs index 8f46066..deddd70 100644 --- a/TestForm/Form1.Designer.cs +++ b/TestForm/Form1.Designer.cs @@ -28,9 +28,17 @@ /// private void InitializeComponent() { + components = new System.ComponentModel.Container(); userCheckedListBox1 = new Components.UserCheckedListBox(); userTextBox1 = new Components.Components.VisualComponents.UserTextBox(); userTreeView1 = new Components.Components.VisualComponents.UserTreeView(); + pdfTable1 = new Components.Components.NonVisualComponents.PdfTable(components); + pdfPieChart1 = new Components.Components.NonVisualComponents.PdfPieChart(components); + pdfImage1 = new Components.Components.NonVisualComponents.PdfImage(components); + PdfImage = new Button(); + PdfTable = new Button(); + PdfChart = new Button(); + openFileDialog1 = new OpenFileDialog(); SuspendLayout(); // // userCheckedListBox1 @@ -49,20 +57,58 @@ userTextBox1.Name = "userTextBox1"; userTextBox1.Size = new Size(396, 76); userTextBox1.TabIndex = 1; - userTextBox1.TextBoxValue = null; // // userTreeView1 // userTreeView1.Location = new Point(225, 84); userTreeView1.Name = "userTreeView1"; + userTreeView1.SelectedNodeIndex = -1; userTreeView1.Size = new Size(550, 329); userTreeView1.TabIndex = 2; // + // PdfImage + // + PdfImage.Location = new Point(31, 453); + PdfImage.Name = "PdfImage"; + PdfImage.Size = new Size(201, 29); + PdfImage.TabIndex = 3; + PdfImage.Text = "Create PdfImage"; + PdfImage.UseVisualStyleBackColor = true; + PdfImage.Click += PdfImage_Click; + // + // PdfTable + // + PdfTable.Location = new Point(263, 453); + PdfTable.Name = "PdfTable"; + PdfTable.Size = new Size(201, 29); + PdfTable.TabIndex = 4; + PdfTable.Text = "Create PdfTable"; + PdfTable.UseVisualStyleBackColor = true; + PdfTable.Click += PdfTable_Click; + // + // PdfChart + // + PdfChart.Location = new Point(501, 453); + PdfChart.Name = "PdfChart"; + PdfChart.Size = new Size(180, 29); + PdfChart.TabIndex = 5; + PdfChart.Text = "Create PdfChart"; + PdfChart.UseVisualStyleBackColor = true; + PdfChart.Click += PdfChart_Click; + // + // openFileDialog1 + // + openFileDialog1.FileName = "openFileDialog1"; + openFileDialog1.Multiselect = true; + // // Form1 // AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(800, 450); + ClientSize = new Size(1005, 490); + Controls.Add(PdfChart); + Controls.Add(PdfTable); + Controls.Add(PdfImage); Controls.Add(userTreeView1); Controls.Add(userTextBox1); Controls.Add(userCheckedListBox1); @@ -76,5 +122,12 @@ private Components.UserCheckedListBox userCheckedListBox1; private Components.Components.VisualComponents.UserTextBox userTextBox1; private Components.Components.VisualComponents.UserTreeView userTreeView1; + private Components.Components.NonVisualComponents.PdfTable pdfTable1; + private Components.Components.NonVisualComponents.PdfPieChart pdfPieChart1; + private Components.Components.NonVisualComponents.PdfImage pdfImage1; + private Button PdfImage; + private Button PdfTable; + private Button PdfChart; + private OpenFileDialog openFileDialog1; } } diff --git a/TestForm/Form1.cs b/TestForm/Form1.cs index 7484cbf..e986d25 100644 --- a/TestForm/Form1.cs +++ b/TestForm/Form1.cs @@ -1,4 +1,7 @@ +using Components.Components.NonVisualComponents.HelperModels; using Components.Components.VisualComponents.Classes; +using System.Windows.Forms; +using static System.Reflection.Metadata.BlobBuilder; namespace TestForm { @@ -16,8 +19,7 @@ namespace TestForm userTextBox1.MaxValue = 15; var hierarchy = new List { "Race", "Class", "FullName" }; - var forcedNewBranch = new Dictionary { { "FullName", true } }; - userTreeView1.SetHierarchy(hierarchy, forcedNewBranch); + userTreeView1.SetHierarchy(hierarchy); var characters = new List() { new Character { Race = "Dwarf", Class = "Warrior", FullName = "Gimli" }, @@ -28,7 +30,71 @@ namespace TestForm foreach (var character in characters) { - userTreeView1.AddObjectToTree(character, hierarchy.Last()); + userTreeView1.AddObjectToTree(character); + } + } + + private void PdfImage_Click(object sender, EventArgs e) + { + var res = openFileDialog1.ShowDialog(this); + if (res != DialogResult.OK) return; + var files = openFileDialog1.FileNames; + openFileDialog1.Dispose(); + string path = "C:\\testImage.pdf"; + MessageBox.Show(path); + if (pdfImage1.CreatePdfDoc(new DataForImage(path, "Images", files))) MessageBox.Show("Success!"); + else MessageBox.Show("Error"); + + } + + private void PdfTable_Click(object sender, EventArgs e) + { + List charactersinfo = new List() + { + new CharacterInfo("139", "Gimli", "Elf-friend", "4'9", "196 lbs"), + new CharacterInfo("2931", "Legolas", "Greenleaf", "6'0", "150 lbs"), + new CharacterInfo("87", "Aragorn", "Strider", "6'6", "210 lbs"), + new CharacterInfo("41", "Boromir", "Captain of Gondor", "6'4", "225 lbs") + }; + + List<(int, int)> merges = new List<(int, int)>(); + merges.Add((2, 3)); + + List heights = new List { 10, 40, 60, 20, 25, 15, 20 }; + + string path = "C:\\testTable.pdf"; + + List<(string, string)> headers = new List<(string, string)> + { + ("id", "Id"), + ("Age", "Age"), + ("", "Heroes of Middle-earth"), + ("Name", "Name"), + ("AKA", "AKA"), + ("Height", "Height"), + ("Weight", "Weight") + }; + + if (pdfTable1.createTable(new DataForTable(path, "Table", heights, merges, headers, charactersinfo))) + { + MessageBox.Show("Success"); + } + } + + private void PdfChart_Click(object sender, EventArgs e) + { + string path = "C:\\testChart.pdf"; + List<(double, string)> elements = new List<(double, string)> + { + (42, "Gimli"), + (41, "Legolas"), + (214, "Aragorn"), + (1, "Boromir") + }; + + if (pdfPieChart1.CreatePieChart(new DataForPieChart(path, "Title", "Pie chart", DiagramLegendEnum.Top, "Orcs killed", elements))) + { + MessageBox.Show("Success"); } } } diff --git a/TestForm/Form1.resx b/TestForm/Form1.resx index 8b2ff64..ff35700 100644 --- a/TestForm/Form1.resx +++ b/TestForm/Form1.resx @@ -117,4 +117,16 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 17, 17 + + + 139, 17 + + + 281, 17 + + + 410, 17 + \ No newline at end of file