Compare commits
5 Commits
main
...
non-visual
| Author | SHA1 | Date | |
|---|---|---|---|
| 6c1b361fef | |||
| a69a7fa17d | |||
| a90c2b2cde | |||
| 05fd1f373b | |||
| 04a9c7bd89 |
48
FormsTesting/Form1.Designer.cs
generated
48
FormsTesting/Form1.Designer.cs
generated
@@ -28,6 +28,7 @@
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
components = new System.ComponentModel.Container();
|
||||
SelectComponent = new ShabComponentsLibrary.ShabSelectComponent();
|
||||
InputComponent = new ShabComponentsLibrary.ShabInputComponent();
|
||||
GridComponent = new ShabComponentsLibrary.ShabListOutputComponent();
|
||||
@@ -37,6 +38,12 @@
|
||||
ShowIntButton = new Button();
|
||||
groupBox3 = new GroupBox();
|
||||
PrintObjectButton = new Button();
|
||||
CreateDocumentWithTables = new Button();
|
||||
DocumentContextComponent = new ShabComponentsLibrary.ShabDocumentContextComponent(components);
|
||||
ConfigurableTableComponent = new ShabComponentsLibrary.ShabConfigurableTableComponent(components);
|
||||
CreateConfigurableTable = new Button();
|
||||
CreateHistogram = new Button();
|
||||
DiagramComponent = new ShabComponentsLibrary.ShabDiagramComponent(components);
|
||||
groupBox1.SuspendLayout();
|
||||
groupBox2.SuspendLayout();
|
||||
groupBox3.SuspendLayout();
|
||||
@@ -132,11 +139,44 @@
|
||||
PrintObjectButton.UseVisualStyleBackColor = true;
|
||||
PrintObjectButton.Click += PrintObjectButton_Click;
|
||||
//
|
||||
// CreateDocumentWithTables
|
||||
//
|
||||
CreateDocumentWithTables.Location = new Point(18, 592);
|
||||
CreateDocumentWithTables.Name = "CreateDocumentWithTables";
|
||||
CreateDocumentWithTables.Size = new Size(172, 42);
|
||||
CreateDocumentWithTables.TabIndex = 6;
|
||||
CreateDocumentWithTables.Text = "Документ с таблицами";
|
||||
CreateDocumentWithTables.UseVisualStyleBackColor = true;
|
||||
CreateDocumentWithTables.Click += CreateDocumentWithTables_Click;
|
||||
//
|
||||
// CreateConfigurableTable
|
||||
//
|
||||
CreateConfigurableTable.Location = new Point(213, 592);
|
||||
CreateConfigurableTable.Name = "CreateConfigurableTable";
|
||||
CreateConfigurableTable.Size = new Size(172, 42);
|
||||
CreateConfigurableTable.TabIndex = 7;
|
||||
CreateConfigurableTable.Text = "Документ с настраиваемой таблицей";
|
||||
CreateConfigurableTable.UseVisualStyleBackColor = true;
|
||||
CreateConfigurableTable.Click += CreateConfigurableTable_Click;
|
||||
//
|
||||
// CreateHistogram
|
||||
//
|
||||
CreateHistogram.Location = new Point(410, 592);
|
||||
CreateHistogram.Name = "CreateHistogram";
|
||||
CreateHistogram.Size = new Size(172, 42);
|
||||
CreateHistogram.TabIndex = 8;
|
||||
CreateHistogram.Text = "Документ с гистограммой";
|
||||
CreateHistogram.UseVisualStyleBackColor = true;
|
||||
CreateHistogram.Click += CreateHistogram_Click;
|
||||
//
|
||||
// Form1
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(637, 581);
|
||||
ClientSize = new Size(637, 660);
|
||||
Controls.Add(CreateHistogram);
|
||||
Controls.Add(CreateConfigurableTable);
|
||||
Controls.Add(CreateDocumentWithTables);
|
||||
Controls.Add(groupBox3);
|
||||
Controls.Add(groupBox2);
|
||||
Controls.Add(groupBox1);
|
||||
@@ -159,5 +199,11 @@
|
||||
private Button ShowIntButton;
|
||||
private GroupBox groupBox3;
|
||||
private Button PrintObjectButton;
|
||||
private Button CreateDocumentWithTables;
|
||||
private ShabComponentsLibrary.ShabDocumentContextComponent DocumentContextComponent;
|
||||
private ShabComponentsLibrary.ShabConfigurableTableComponent ConfigurableTableComponent;
|
||||
private Button CreateConfigurableTable;
|
||||
private Button CreateHistogram;
|
||||
private ShabComponentsLibrary.ShabDiagramComponent DiagramComponent;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using MigraDoc.DocumentObjectModel;
|
||||
using ShabComponentsLibrary;
|
||||
using ShabComponentsLibrary.Exceptions;
|
||||
|
||||
@@ -97,5 +98,67 @@ namespace FormsTesting
|
||||
var Test = GridComponent.GetSelectedObject<TestPerson>();
|
||||
MessageBox.Show(Test.ToString());
|
||||
}
|
||||
|
||||
private void CreateDocumentWithTables_Click(object sender, EventArgs e)
|
||||
{
|
||||
string[][] table1 =
|
||||
[
|
||||
["<22><><EFBFBD> 1 <20><><EFBFBD> 1", "<22><><EFBFBD> 1 <20><><EFBFBD> 2", "<22><><EFBFBD> 1 <20><><EFBFBD> 3"],
|
||||
["<22><><EFBFBD> 2 <20><><EFBFBD> 1", "<22><><EFBFBD> 2 <20><><EFBFBD> 2", "<22><><EFBFBD> 2 <20><><EFBFBD> 3"]
|
||||
];
|
||||
|
||||
string[][] table2 =
|
||||
[
|
||||
["<22><><EFBFBD> 1 <20><><EFBFBD> 1", "<22><><EFBFBD> 1 <20><><EFBFBD> 2", "<22><><EFBFBD> 1 <20><><EFBFBD> 3", "<22><><EFBFBD> 1 <20><><EFBFBD> 4", "<22><><EFBFBD> 1 <20><><EFBFBD> 5", "<22><><EFBFBD> 1 <20><><EFBFBD> 6"],
|
||||
["<22><><EFBFBD> 2 <20><><EFBFBD> 1", "<22><><EFBFBD> 2 <20><><EFBFBD> 2", "<22><><EFBFBD> 2 <20><><EFBFBD> 3", "<22><><EFBFBD> 2 <20><><EFBFBD> 4", "<22><><EFBFBD> 2 <20><><EFBFBD> 5", "<22><><EFBFBD> 2 <20><><EFBFBD> 6"],
|
||||
["<22><><EFBFBD> 3 <20><><EFBFBD> 1", "<22><><EFBFBD> 3 <20><><EFBFBD> 2", "<22><><EFBFBD> 3 <20><><EFBFBD> 3", "<22><><EFBFBD> 3 <20><><EFBFBD> 4", "<22><><EFBFBD> 3 <20><><EFBFBD> 5", "<22><><EFBFBD> 3 <20><><EFBFBD> 6"],
|
||||
["<22><><EFBFBD> 4 <20><><EFBFBD> 1", "<22><><EFBFBD> 4 <20><><EFBFBD> 2", "<22><><EFBFBD> 4 <20><><EFBFBD> 3", "<22><><EFBFBD> 4 <20><><EFBFBD> 4", "<22><><EFBFBD> 4 <20><><EFBFBD> 5", "<22><><EFBFBD> 4 <20><><EFBFBD> 6"],
|
||||
];
|
||||
|
||||
DocumentContextComponent.CreateDocument(
|
||||
@"C:\Comps\Doc1.pdf",
|
||||
"Sample text",
|
||||
new List<string[][]> { table1, table2 });
|
||||
}
|
||||
|
||||
private void CreateConfigurableTable_Click(object sender, EventArgs e)
|
||||
{
|
||||
List<TestPerson> Persons = new List<TestPerson>
|
||||
{
|
||||
new TestPerson(1, "<22><><EFBFBD><EFBFBD>", "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", 34),
|
||||
new TestPerson(2, "<22><><EFBFBD><EFBFBD>", "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", 44),
|
||||
new TestPerson(3, "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", 55),
|
||||
new TestPerson(4, "<22><><EFBFBD><EFBFBD><EFBFBD>", "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", 34),
|
||||
new TestPerson(5, "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", 44),
|
||||
};
|
||||
|
||||
ConfigurableTableComponent.CreateDocument(
|
||||
@"C:\Comps\Doc2.pdf", "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>",
|
||||
new List<(double, string, string)>
|
||||
{
|
||||
(3.0, "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", "LastName"),
|
||||
(2.0, "<22><><EFBFBD><EFBFBD><EFBFBD>.", "Id"),
|
||||
(3.0, "<22><><EFBFBD>", "FirstName"),
|
||||
(4.0, "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", "Age"),
|
||||
},
|
||||
new List<double> { 1.0, 0.6 },
|
||||
Persons);
|
||||
}
|
||||
|
||||
private void CreateHistogram_Click(object sender, EventArgs e)
|
||||
{
|
||||
var Data = new Dictionary<string, int[]>
|
||||
{
|
||||
{ "<22><><EFBFBD><EFBFBD><EFBFBD> 1", new[] { 10, 20, 30, 40 } },
|
||||
{ "<22><><EFBFBD><EFBFBD><EFBFBD> 2", new[] { 15, 25, 35, 45 } }
|
||||
};
|
||||
DiagramComponent.CreateDocument(
|
||||
@"C:\Comps\Doc3.pdf",
|
||||
"<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>",
|
||||
"<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>",
|
||||
ShabComponentsLibrary.Enums.LegendPosition.Bottom,
|
||||
Data
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,4 +117,13 @@
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<metadata name="DocumentContextComponent.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
<metadata name="ConfigurableTableComponent.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>233, 17</value>
|
||||
</metadata>
|
||||
<metadata name="DiagramComponent.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>447, 17</value>
|
||||
</metadata>
|
||||
</root>
|
||||
10
ShabComponentsLibrary/Enums/LegendPosition.cs
Normal file
10
ShabComponentsLibrary/Enums/LegendPosition.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace ShabComponentsLibrary.Enums
|
||||
{
|
||||
public enum LegendPosition
|
||||
{
|
||||
Top,
|
||||
Bottom,
|
||||
Left,
|
||||
Right
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace ShabComponentsLibrary.OfficePackage.HelperEnums
|
||||
{
|
||||
internal enum PdfParagraphAlignmentType
|
||||
{
|
||||
Center,
|
||||
Left,
|
||||
Rigth
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using ShabComponentsLibrary.Enums;
|
||||
|
||||
namespace ShabComponentsLibrary.OfficePackage.HelperModels
|
||||
{
|
||||
internal class PdfChartParameters
|
||||
{
|
||||
public Dictionary<string, int[]> Data = new();
|
||||
|
||||
public string Title = string.Empty;
|
||||
|
||||
public LegendPosition LegendPosition = LegendPosition.Bottom;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using ShabComponentsLibrary.OfficePackage.HelperEnums;
|
||||
|
||||
namespace ShabComponentsLibrary.OfficePackage.HelperModels
|
||||
{
|
||||
internal class PdfParagraph
|
||||
{
|
||||
public string Text { get; set; } = string.Empty;
|
||||
|
||||
public string Style { get; set; } = string.Empty;
|
||||
|
||||
public PdfParagraphAlignmentType ParagraphAlignment { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using ShabComponentsLibrary.OfficePackage.HelperEnums;
|
||||
|
||||
namespace ShabComponentsLibrary.OfficePackage.HelperModels
|
||||
{
|
||||
internal class PdfRowParameters
|
||||
{
|
||||
public List<string> Texts { get; set; } = new();
|
||||
|
||||
public string Style { get; set; } = string.Empty;
|
||||
|
||||
public string? FirstCellStyle { get; set; }
|
||||
|
||||
public PdfParagraphAlignmentType ParagraphAlignment { get; set; }
|
||||
|
||||
public PdfParagraphAlignmentType? FirstCellParagraphAlignment { get; set; }
|
||||
|
||||
public double? RowHeight { get; set; }
|
||||
}
|
||||
}
|
||||
161
ShabComponentsLibrary/OfficePackage/SaveToPdf.cs
Normal file
161
ShabComponentsLibrary/OfficePackage/SaveToPdf.cs
Normal file
@@ -0,0 +1,161 @@
|
||||
using MigraDoc.DocumentObjectModel;
|
||||
using MigraDoc.DocumentObjectModel.Shapes.Charts;
|
||||
using MigraDoc.DocumentObjectModel.Tables;
|
||||
using MigraDoc.Rendering;
|
||||
using ShabComponentsLibrary.Enums;
|
||||
using ShabComponentsLibrary.OfficePackage.HelperEnums;
|
||||
using ShabComponentsLibrary.OfficePackage.HelperModels;
|
||||
|
||||
namespace ShabComponentsLibrary.OfficePackage
|
||||
{
|
||||
internal class SaveToPdf
|
||||
{
|
||||
private Document? _document;
|
||||
private Section? _section;
|
||||
private Table? _table;
|
||||
|
||||
private static ParagraphAlignment GetParagraphAlignment(PdfParagraphAlignmentType Type)
|
||||
{
|
||||
return Type switch
|
||||
{
|
||||
PdfParagraphAlignmentType.Center => ParagraphAlignment.Center,
|
||||
PdfParagraphAlignmentType.Left => ParagraphAlignment.Left,
|
||||
PdfParagraphAlignmentType.Rigth => ParagraphAlignment.Right,
|
||||
_ => ParagraphAlignment.Justify,
|
||||
};
|
||||
}
|
||||
|
||||
private static void DefineStyles(Document Document)
|
||||
{
|
||||
var Style = Document.Styles["Normal"];
|
||||
Style.Font.Name = "Times New Roman";
|
||||
Style.Font.Size = 12;
|
||||
|
||||
Style = Document.Styles.AddStyle("NormalTitle", "Normal");
|
||||
Style.Font.Bold = true;
|
||||
}
|
||||
|
||||
public void CreatePdf()
|
||||
{
|
||||
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
|
||||
_document = new Document();
|
||||
DefineStyles(_document);
|
||||
|
||||
_section = _document.AddSection();
|
||||
}
|
||||
|
||||
public void CreateParagraph(PdfParagraph PdfParagraph)
|
||||
{
|
||||
if (_section == null)
|
||||
return;
|
||||
|
||||
var Paragraph = _section.AddParagraph(PdfParagraph.Text);
|
||||
|
||||
Paragraph.Format.SpaceAfter = "0.1cm";
|
||||
Paragraph.Format.Alignment = GetParagraphAlignment(PdfParagraph.ParagraphAlignment);
|
||||
Paragraph.Style = PdfParagraph.Style;
|
||||
}
|
||||
|
||||
public void CreateTable(List<double> ColumnWidths)
|
||||
{
|
||||
if (_document == null)
|
||||
return;
|
||||
|
||||
_table = _document.LastSection.AddTable();
|
||||
foreach (var ColumnWidth in ColumnWidths)
|
||||
{
|
||||
_table.AddColumn(Unit.FromCentimeter(ColumnWidth));
|
||||
}
|
||||
}
|
||||
|
||||
public void CreateRow(PdfRowParameters RowParameters)
|
||||
{
|
||||
if (_table == null)
|
||||
return;
|
||||
|
||||
var Row = _table.AddRow();
|
||||
for (int i = 0; i < RowParameters.Texts.Count; ++i)
|
||||
{
|
||||
Row.Cells[i].AddParagraph(RowParameters.Texts[i]);
|
||||
|
||||
if (i == 0 && !string.IsNullOrEmpty(RowParameters.FirstCellStyle))
|
||||
{
|
||||
Row.Cells[i].Style = RowParameters.FirstCellStyle;
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(RowParameters.Style))
|
||||
{
|
||||
Row.Cells[i].Style = RowParameters.Style;
|
||||
}
|
||||
|
||||
if (i == 0 && RowParameters.FirstCellParagraphAlignment != null)
|
||||
{
|
||||
Row.Cells[i].Format.Alignment = GetParagraphAlignment((PdfParagraphAlignmentType)RowParameters.FirstCellParagraphAlignment);
|
||||
}
|
||||
else
|
||||
{
|
||||
Row.Cells[i].Format.Alignment = GetParagraphAlignment(RowParameters.ParagraphAlignment);
|
||||
}
|
||||
|
||||
if (RowParameters.RowHeight is not null)
|
||||
{
|
||||
Row.Height = Unit.FromCentimeter((double)RowParameters.RowHeight);
|
||||
}
|
||||
|
||||
Unit borderWidth = 0.5;
|
||||
Row.Cells[i].Borders.Left.Width = borderWidth;
|
||||
Row.Cells[i].Borders.Right.Width = borderWidth;
|
||||
Row.Cells[i].Borders.Top.Width = borderWidth;
|
||||
Row.Cells[i].Borders.Bottom.Width = borderWidth;
|
||||
Row.Cells[i].VerticalAlignment = VerticalAlignment.Center;
|
||||
}
|
||||
}
|
||||
|
||||
public void CreateChart(PdfChartParameters ChartParameters)
|
||||
{
|
||||
if (_section == null)
|
||||
return;
|
||||
|
||||
Chart chart = new Chart(ChartType.Bar2D);
|
||||
chart.Width = "15cm";
|
||||
chart.Height = "8cm";
|
||||
|
||||
foreach (var dataSeries in ChartParameters.Data)
|
||||
{
|
||||
Series series = chart.SeriesCollection.AddSeries();
|
||||
series.Name = dataSeries.Key;
|
||||
series.Add(dataSeries.Value.Select(x => (double)x).ToArray());
|
||||
}
|
||||
|
||||
chart.TopArea.AddParagraph(ChartParameters.Title);
|
||||
|
||||
chart.XAxis.MajorTickMark = TickMarkType.Outside;
|
||||
chart.YAxis.MajorTickMark = TickMarkType.Outside;
|
||||
chart.YAxis.HasMajorGridlines = true;
|
||||
|
||||
_ = ChartParameters.LegendPosition switch
|
||||
{
|
||||
LegendPosition.Top => chart.TopArea.AddLegend(),
|
||||
LegendPosition.Right => chart.RightArea.AddLegend(),
|
||||
LegendPosition.Bottom => chart.BottomArea.AddLegend(),
|
||||
LegendPosition.Left => chart.LeftArea.AddLegend(),
|
||||
_ => chart.BottomArea.AddLegend(),
|
||||
};
|
||||
|
||||
chart.PlotArea.LineFormat.Width = 1;
|
||||
chart.PlotArea.LineFormat.Visible = true;
|
||||
|
||||
_section.Add(chart);
|
||||
}
|
||||
|
||||
public void SavePdf(string Filename)
|
||||
{
|
||||
var Renderer = new PdfDocumentRenderer(true)
|
||||
{
|
||||
Document = _document
|
||||
};
|
||||
|
||||
Renderer.RenderDocument();
|
||||
Renderer.PdfDocument.Save(Filename);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,4 +7,8 @@
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="PdfSharp.MigraDoc.Standard" Version="1.51.15" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
36
ShabComponentsLibrary/ShabConfigurableTableComponent.Designer.cs
generated
Normal file
36
ShabComponentsLibrary/ShabConfigurableTableComponent.Designer.cs
generated
Normal file
@@ -0,0 +1,36 @@
|
||||
namespace ShabComponentsLibrary
|
||||
{
|
||||
partial class ShabConfigurableTableComponent
|
||||
{
|
||||
/// <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 Component 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();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
95
ShabComponentsLibrary/ShabConfigurableTableComponent.cs
Normal file
95
ShabComponentsLibrary/ShabConfigurableTableComponent.cs
Normal file
@@ -0,0 +1,95 @@
|
||||
using ShabComponentsLibrary.OfficePackage;
|
||||
using ShabComponentsLibrary.OfficePackage.HelperEnums;
|
||||
using ShabComponentsLibrary.OfficePackage.HelperModels;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace ShabComponentsLibrary
|
||||
{
|
||||
/// <summary>
|
||||
/// Невизуальный компонент для создания документа с таблицей,
|
||||
/// у которой шапкой является первая строка и первый столбец
|
||||
/// </summary>
|
||||
public partial class ShabConfigurableTableComponent : Component
|
||||
{
|
||||
public ShabConfigurableTableComponent()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public ShabConfigurableTableComponent(IContainer Container)
|
||||
{
|
||||
Container.Add(this);
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public void CreateDocument<T>(string Filename, string Title,
|
||||
List<(double ColumnWidth, string TableHeader, string HeaderPropertyName)> ColumnData,
|
||||
List<double> RowHeights, List<T> Data)
|
||||
{
|
||||
if (string.IsNullOrEmpty(Filename))
|
||||
throw new ArgumentException("Filename cannot be empty");
|
||||
if (string.IsNullOrEmpty(Title))
|
||||
throw new ArgumentException("Title cannot be empty");
|
||||
if (ColumnData.Count == 0)
|
||||
throw new ArgumentException("Headers cannot be empty");
|
||||
if (Data.Count == 0)
|
||||
throw new ArgumentException("Data cannot be empty");
|
||||
if (RowHeights.Count != 2)
|
||||
throw new ArgumentException("Row heights should be specified for header row and other rows");
|
||||
|
||||
SaveToPdf Pdf = new SaveToPdf();
|
||||
Pdf.CreatePdf();
|
||||
Pdf.CreateParagraph(new PdfParagraph
|
||||
{
|
||||
Text = Title,
|
||||
Style = "NormalTitle",
|
||||
ParagraphAlignment = PdfParagraphAlignmentType.Left
|
||||
});
|
||||
|
||||
Pdf.CreateTable(ColumnData.Select(x => x.ColumnWidth).ToList());
|
||||
|
||||
// Шапка
|
||||
Pdf.CreateRow(new PdfRowParameters
|
||||
{
|
||||
Texts = ColumnData.Select(x => x.TableHeader).ToList(),
|
||||
Style = "NormalTitle",
|
||||
ParagraphAlignment = PdfParagraphAlignmentType.Center,
|
||||
RowHeight = RowHeights[0]
|
||||
});
|
||||
|
||||
// Данные
|
||||
foreach (var Object in Data)
|
||||
{
|
||||
List<string> Cells = new List<string>();
|
||||
|
||||
for (int ColumnIndex = 0; ColumnIndex < ColumnData.Count; ++ColumnIndex)
|
||||
{
|
||||
string PropertyName = ColumnData[ColumnIndex].HeaderPropertyName;
|
||||
var Property = typeof(T).GetProperty(PropertyName);
|
||||
if (Property is null)
|
||||
{
|
||||
throw new ArgumentException($"Failed to find property {PropertyName} in provided objects class");
|
||||
}
|
||||
|
||||
var PropertyValue = Property.GetValue(Object)?.ToString();
|
||||
if (PropertyValue is not null)
|
||||
{
|
||||
Cells.Add(PropertyValue);
|
||||
}
|
||||
}
|
||||
|
||||
Pdf.CreateRow(new PdfRowParameters
|
||||
{
|
||||
Texts = Cells,
|
||||
Style = "Normal",
|
||||
FirstCellStyle = "NormalTitle",
|
||||
ParagraphAlignment = PdfParagraphAlignmentType.Left,
|
||||
FirstCellParagraphAlignment = PdfParagraphAlignmentType.Center,
|
||||
RowHeight = RowHeights[1]
|
||||
});
|
||||
}
|
||||
|
||||
Pdf.SavePdf(Filename);
|
||||
}
|
||||
}
|
||||
}
|
||||
36
ShabComponentsLibrary/ShabDiagramComponent.Designer.cs
generated
Normal file
36
ShabComponentsLibrary/ShabDiagramComponent.Designer.cs
generated
Normal file
@@ -0,0 +1,36 @@
|
||||
namespace ShabComponentsLibrary
|
||||
{
|
||||
partial class ShabDiagramComponent
|
||||
{
|
||||
/// <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 Component 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();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
56
ShabComponentsLibrary/ShabDiagramComponent.cs
Normal file
56
ShabComponentsLibrary/ShabDiagramComponent.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
using ShabComponentsLibrary.OfficePackage.HelperEnums;
|
||||
using ShabComponentsLibrary.OfficePackage.HelperModels;
|
||||
using ShabComponentsLibrary.OfficePackage;
|
||||
using System.ComponentModel;
|
||||
using ShabComponentsLibrary.Enums;
|
||||
|
||||
namespace ShabComponentsLibrary
|
||||
{
|
||||
/// <summary>
|
||||
/// Невизуальный компонент для создания документа с гистограммой
|
||||
/// </summary>
|
||||
public partial class ShabDiagramComponent : Component
|
||||
{
|
||||
public ShabDiagramComponent()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public ShabDiagramComponent(IContainer Container)
|
||||
{
|
||||
Container.Add(this);
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public void CreateDocument(string Filename, string Title, string ChartTitle, LegendPosition LegendPosition,
|
||||
Dictionary<string, int[]> Data)
|
||||
{
|
||||
if (string.IsNullOrEmpty(Filename))
|
||||
throw new ArgumentException("Filename cannot be empty");
|
||||
if (string.IsNullOrEmpty(Title))
|
||||
throw new ArgumentException("Title cannot be empty");
|
||||
if (string.IsNullOrEmpty(ChartTitle))
|
||||
throw new ArgumentException("Chart title cannot be empty");
|
||||
if (Data.Count == 0)
|
||||
throw new ArgumentException("Data cannot be empty");
|
||||
|
||||
SaveToPdf Pdf = new SaveToPdf();
|
||||
Pdf.CreatePdf();
|
||||
Pdf.CreateParagraph(new PdfParagraph
|
||||
{
|
||||
Text = Title,
|
||||
Style = "NormalTitle",
|
||||
ParagraphAlignment = PdfParagraphAlignmentType.Left
|
||||
});
|
||||
|
||||
Pdf.CreateChart(new PdfChartParameters
|
||||
{
|
||||
Data = Data,
|
||||
Title = ChartTitle,
|
||||
LegendPosition = LegendPosition,
|
||||
});
|
||||
|
||||
Pdf.SavePdf(Filename);
|
||||
}
|
||||
}
|
||||
}
|
||||
36
ShabComponentsLibrary/ShabDocumentContextComponent.Designer.cs
generated
Normal file
36
ShabComponentsLibrary/ShabDocumentContextComponent.Designer.cs
generated
Normal file
@@ -0,0 +1,36 @@
|
||||
namespace ShabComponentsLibrary
|
||||
{
|
||||
partial class ShabDocumentContextComponent
|
||||
{
|
||||
/// <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 Component 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();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
65
ShabComponentsLibrary/ShabDocumentContextComponent.cs
Normal file
65
ShabComponentsLibrary/ShabDocumentContextComponent.cs
Normal file
@@ -0,0 +1,65 @@
|
||||
using ShabComponentsLibrary.OfficePackage;
|
||||
using ShabComponentsLibrary.OfficePackage.HelperEnums;
|
||||
using ShabComponentsLibrary.OfficePackage.HelperModels;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace ShabComponentsLibrary
|
||||
{
|
||||
/// <summary>
|
||||
/// Невизуальный компонент для создания документа с таблицами
|
||||
/// </summary>
|
||||
public partial class ShabDocumentContextComponent : Component
|
||||
{
|
||||
public ShabDocumentContextComponent()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public ShabDocumentContextComponent(IContainer Container)
|
||||
{
|
||||
Container.Add(this);
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public void CreateDocument(string Filename, string Title, List<string[][]> Tables)
|
||||
{
|
||||
if (string.IsNullOrEmpty(Filename))
|
||||
throw new ArgumentException("Filename cannot be empty");
|
||||
if (string.IsNullOrEmpty(Title))
|
||||
throw new ArgumentException("Title cannot be empty");
|
||||
if (Tables.Count == 0)
|
||||
throw new ArgumentException("Data cannot be empty");
|
||||
|
||||
SaveToPdf Pdf = new SaveToPdf();
|
||||
Pdf.CreatePdf();
|
||||
Pdf.CreateParagraph(new PdfParagraph
|
||||
{
|
||||
Text = Title,
|
||||
Style = "NormalTitle",
|
||||
ParagraphAlignment = PdfParagraphAlignmentType.Left
|
||||
});
|
||||
|
||||
foreach (string[][] Table in Tables)
|
||||
{
|
||||
if (Table.Length == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
Pdf.CreateTable(Enumerable.Repeat(3.0, Table[0].Length).ToList());
|
||||
foreach (string[] Row in Table)
|
||||
{
|
||||
Pdf.CreateRow(new PdfRowParameters
|
||||
{
|
||||
Texts = Row.ToList(),
|
||||
Style = "Normal",
|
||||
ParagraphAlignment = PdfParagraphAlignmentType.Left
|
||||
});
|
||||
}
|
||||
Pdf.CreateParagraph(new PdfParagraph());
|
||||
}
|
||||
|
||||
Pdf.SavePdf(Filename);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user