179 lines
4.4 KiB
C#
179 lines
4.4 KiB
C#
using Components;
|
|
using Components.NonVisual;
|
|
using Components.Object;
|
|
using Components.SaveToPdfHelpers;
|
|
using OxyPlot.Legends;
|
|
|
|
namespace WinFormsTest
|
|
{
|
|
public partial class Form1 : Form
|
|
{
|
|
public Form1()
|
|
{
|
|
InitializeComponent();
|
|
|
|
InitializeListBox();
|
|
InitializeDataGridView();
|
|
}
|
|
|
|
private void InitializeListBox()
|
|
{
|
|
customListBox.SetItems(new List<string>
|
|
{
|
|
"Hi 1",
|
|
"Hi 2",
|
|
"Hi 3",
|
|
"Hi 4",
|
|
"Hi 5",
|
|
});
|
|
}
|
|
|
|
private void InitializeDataGridView()
|
|
{
|
|
var columns = new List<(string HeaderText, string DataPropertyName, float FillWeight)>
|
|
{
|
|
("Èìÿ", "Name", 1),
|
|
("Âîçðàñò", "Age", 1),
|
|
("Email", "Email", 2)
|
|
};
|
|
customDataGridView1.ConfigureColumns(columns);
|
|
|
|
var data = new List<Person>
|
|
{
|
|
new Person ("Èâàí", 30, "ivan@gmail.com" ),
|
|
new Person ("Ìàðèÿ", 25, "maria@gmail.com")
|
|
};
|
|
customDataGridView1.FillData(data);
|
|
}
|
|
|
|
private string FilePath()
|
|
{
|
|
using (SaveFileDialog saveFileDialog = new SaveFileDialog())
|
|
{
|
|
saveFileDialog.InitialDirectory = "d:\\tmp";
|
|
saveFileDialog.Filter = "Excel files (*.pdf)|*.pdf|All files (*.*)|*.*";
|
|
saveFileDialog.FilterIndex = 1;
|
|
saveFileDialog.RestoreDirectory = true;
|
|
|
|
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
|
{
|
|
return saveFileDialog.FileName;
|
|
}
|
|
}
|
|
return String.Empty;
|
|
}
|
|
|
|
private void GeneratePdfButton_Click(object sender, EventArgs e)
|
|
{
|
|
string filePath = FilePath();
|
|
|
|
if (filePath == String.Empty)
|
|
{
|
|
MessageBox.Show("Ïðîèçîøëà îøèáêà: íå âûáðàí ïóòü äëÿ ôàéëà");
|
|
return;
|
|
}
|
|
|
|
var settings = new PdfDocumentData(
|
|
filePath,
|
|
"Íàçâàíèå äîêóìåíòà",
|
|
new List<string[,]>
|
|
{
|
|
new string[,]
|
|
{
|
|
{ "ß÷åéêà 1.1", "ß÷åéêà 2.1", "ß÷åéêà 3.1" },
|
|
{ "ß÷åéêà 2.1", "ß÷åéêà 2.2", "ß÷åéêà 3.2" }
|
|
},
|
|
new string[,]
|
|
{
|
|
{ "Íå ÿ÷åéêà 1", "Íå ÿ÷åéêà 2" },
|
|
{ "ß÷Àéêà 1", "ß÷Àéêà 2" }
|
|
}
|
|
});
|
|
try
|
|
{
|
|
tablepdf1.GeneratePdf(settings);
|
|
MessageBox.Show("PDF-äîêóìåíò óñïåøíî ñîçäàí!", "Óñïåõ", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show($"Ïðîèçîøëà îøèáêà: {ex.Message}", "Îøèáêà", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
}
|
|
}
|
|
private void btnGeneratePDF_Click(object sender, EventArgs e)
|
|
{
|
|
string filePath = FilePath();
|
|
|
|
if (filePath == String.Empty)
|
|
{
|
|
MessageBox.Show("Ïðîèçîøëà îøèáêà: íå âûáðàí ïóòü äëÿ ôàéëà");
|
|
return;
|
|
}
|
|
|
|
var settings = new PDFTableSettings<Person>
|
|
{
|
|
FilePath = filePath,
|
|
DocumentTitle = "Îò÷åò",
|
|
HeaderRowHeight = 1.0f,
|
|
DataRowHeight = 1.0f,
|
|
DataList = new List<Person>
|
|
{
|
|
new Person ( "Àëåêñàíä Áóáûë¸â", 30, "Alex@mail.ru" ),
|
|
new Person ( "Øåðëîê Õîëìñ", 25, "221B_Baker_Street@mail.com" ),
|
|
new Person ("Ñòàñ Àñàôüåâ", 41, "Stas@gmail.com")
|
|
},
|
|
Columns = new List<(string, float, string, int)>
|
|
{
|
|
("ÔÈÎ", 6.0f, nameof(Person.Name), 0),
|
|
("Âîçðàñò", 2.0f, nameof(Person.Age), 1),
|
|
("Ïî÷òà", 6.0f, nameof(Person.Email), 2)
|
|
}
|
|
};
|
|
|
|
try
|
|
{
|
|
headeredTablepdf1.GeneratePDFWithHead(settings);
|
|
MessageBox.Show("PDF-äîêóìåíò óñïåøíî ñîçäàí!", "Óñïåõ", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show($"Îøèáêà: {ex.Message}");
|
|
}
|
|
}
|
|
private void btnGenerateHistogrammPdf_Click(object sender, EventArgs e)
|
|
{
|
|
string filePath = FilePath();
|
|
|
|
if (filePath == String.Empty)
|
|
{
|
|
MessageBox.Show("Ïðîèçîøëà îøèáêà: íå âûáðàí ïóòü äëÿ ôàéëà");
|
|
return;
|
|
}
|
|
|
|
var setting = new HistogramData
|
|
{
|
|
FilePath = filePath,
|
|
DocumentTitle = "Ãèñòîãðàììà",
|
|
ChartTitle = "Ïðèìåð ãèñòîãðàììû",
|
|
LegendPosition = LegendPositions.Bottom,
|
|
|
|
ChartData = new List<ChartData>
|
|
{
|
|
new ChartData { SeriesName = "Ñåðèÿ 1", Data = new Dictionary<string, double> { { "Êàòåãîðèÿ 1", 5 }, { "Êàòåãîðèÿ 2", 10 } } },
|
|
new ChartData { SeriesName = "Ñåðèÿ 2", Data = new Dictionary<string, double> { { "Êàòåãîðèÿ 1", 3 }, { "Êàòåãîðèÿ 2", 8 } } },
|
|
new ChartData { SeriesName = "Ñåðèÿ 3", Data = new Dictionary<string, double> { { "Êàòåãîðèÿ 1", 3 }, { "Êàòåãîðèÿ 2", 8 } } }
|
|
}
|
|
};
|
|
try
|
|
{
|
|
|
|
histogrampdf1.CreateHistogramPdf(setting);
|
|
MessageBox.Show("PDF óñïåøíî ñãåíåðèðîâàí!", "Óñïåõ", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show($"Îøèáêà: {ex.Message}", "Îøèáêà", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
}
|
|
}
|
|
}
|
|
}
|