PIbd-31_Danilov_V_V_COP-30/WinFormsTest/Form1.cs

179 lines
4.4 KiB
C#
Raw Permalink Normal View History

2024-09-20 08:45:39 +04:00
using Components;
2024-10-30 14:26:40 +04:00
using Components.NonVisual;
2024-10-03 21:07:20 +04:00
using Components.Object;
2024-10-30 14:26:40 +04:00
using Components.SaveToPdfHelpers;
using OxyPlot.Legends;
2024-09-20 08:45:39 +04:00
namespace WinFormsTest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
InitializeListBox();
2024-10-03 21:07:20 +04:00
InitializeDataGridView();
2024-09-20 08:45:39 +04:00
}
private void InitializeListBox()
{
customListBox.SetItems(new List<string>
{
"Hi 1",
"Hi 2",
"Hi 3",
"Hi 4",
"Hi 5",
});
}
2024-10-03 21:07:20 +04:00
private void InitializeDataGridView()
{
var columns = new List<(string HeaderText, string DataPropertyName, float FillWeight)>
{
("<22><><EFBFBD>", "Name", 1),
("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", "Age", 1),
("Email", "Email", 2)
};
customDataGridView1.ConfigureColumns(columns);
var data = new List<Person>
{
new Person ("<22><><EFBFBD><EFBFBD>", 30, "ivan@gmail.com" ),
new Person ("<22><><EFBFBD><EFBFBD><EFBFBD>", 25, "maria@gmail.com")
};
customDataGridView1.FillData(data);
}
2024-10-30 14:26:40 +04:00
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;
}
2024-10-30 14:26:40 +04:00
private void GeneratePdfButton_Click(object sender, EventArgs e)
{
string filePath = FilePath();
if (filePath == String.Empty)
{
MessageBox.Show("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>");
return;
}
2024-10-30 14:26:40 +04:00
var settings = new PdfDocumentData(
filePath,
2024-10-30 14:26:40 +04:00
"<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>",
new List<string[,]>
{
new string[,]
{
{ "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 1.1", "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 2.1", "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 3.1" },
{ "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 2.1", "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 2.2", "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 3.2" }
},
new string[,]
{
{ "<22><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 1", "<22><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 2" },
{ "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 1", "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 2" }
}
});
try
{
tablepdf1.GeneratePdf(settings);
MessageBox.Show("PDF-<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!", "<22><><EFBFBD><EFBFBD><EFBFBD>", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show($"<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: {ex.Message}", "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void btnGeneratePDF_Click(object sender, EventArgs e)
{
string filePath = FilePath();
if (filePath == String.Empty)
{
MessageBox.Show("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>");
return;
}
2024-10-30 14:26:40 +04:00
var settings = new PDFTableSettings<Person>
{
FilePath = filePath,
DocumentTitle = "<22><><EFBFBD><EFBFBD><EFBFBD>",
2024-10-30 14:26:40 +04:00
HeaderRowHeight = 1.0f,
DataRowHeight = 1.0f,
DataList = new List<Person>
{
new Person ( "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", 30, "Alex@mail.ru" ),
new Person ( "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>", 25, "221B_Baker_Street@mail.com" ),
new Person ("<22><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", 41, "Stas@gmail.com")
},
Columns = new List<(string, float, string, int)>
2024-10-30 14:26:40 +04:00
{
("<22><><EFBFBD>", 6.0f, nameof(Person.Name), 0),
("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", 2.0f, nameof(Person.Age), 1),
("<22><><EFBFBD><EFBFBD><EFBFBD>", 6.0f, nameof(Person.Email), 2)
2024-10-30 14:26:40 +04:00
}
};
try
{
headeredTablepdf1.GeneratePDFWithHead(settings);
MessageBox.Show("PDF-<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!", "<22><><EFBFBD><EFBFBD><EFBFBD>", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show($"<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: {ex.Message}");
}
}
private void btnGenerateHistogrammPdf_Click(object sender, EventArgs e)
{
string filePath = FilePath();
if (filePath == String.Empty)
{
MessageBox.Show("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>");
return;
}
2024-10-30 14:26:40 +04:00
var setting = new HistogramData
{
FilePath = filePath,
DocumentTitle = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>",
ChartTitle = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>",
LegendPosition = LegendPositions.Bottom,
2024-10-30 14:26:40 +04:00
ChartData = new List<ChartData>
2024-10-30 14:26:40 +04:00
{
new ChartData { SeriesName = "<22><><EFBFBD><EFBFBD><EFBFBD> 1", Data = new Dictionary<string, double> { { "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 1", 5 }, { "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 2", 10 } } },
new ChartData { SeriesName = "<22><><EFBFBD><EFBFBD><EFBFBD> 2", Data = new Dictionary<string, double> { { "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 1", 3 }, { "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 2", 8 } } },
new ChartData { SeriesName = "<22><><EFBFBD><EFBFBD><EFBFBD> 3", Data = new Dictionary<string, double> { { "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 1", 3 }, { "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 2", 8 } } }
}
};
try
{
histogrampdf1.CreateHistogramPdf(setting);
MessageBox.Show("PDF <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!", "<22><><EFBFBD><EFBFBD><EFBFBD>", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show($"<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: {ex.Message}", "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
2024-09-20 08:45:39 +04:00
}
}