лаб2 сдана
This commit is contained in:
parent
381c248106
commit
e04e3ce0a9
@ -9,8 +9,8 @@ namespace CustomComponents.Helpers
|
||||
public class DataForPieChart
|
||||
{
|
||||
public string FilePath = string.Empty;
|
||||
public string DocumentTitle = string.Empty;//заголовок документа
|
||||
public string ChartTitle = 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;
|
||||
|
@ -28,7 +28,7 @@ namespace CustomComponents.NonVisualComponents
|
||||
}
|
||||
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("Недостаточно данных");
|
||||
@ -47,19 +47,19 @@ namespace CustomComponents.NonVisualComponents
|
||||
Chart chart = section.AddChart(ChartType.Pie2D);
|
||||
chart.Width = Unit.FromCentimeter(16);
|
||||
chart.Height = Unit.FromCentimeter(16);
|
||||
chart.HeaderArea.AddParagraph(dataForPDFPie.ChartTitle); // заголовок диаграммы
|
||||
chart.HeaderArea.AddParagraph(dataForPDFPie.ChartTitle);
|
||||
|
||||
Series series = chart.SeriesCollection.AddSeries();
|
||||
series.Name = dataForPDFPie.LegendName; // название сериии
|
||||
series.Name = dataForPDFPie.LegendName;
|
||||
XSeries xseries = chart.XValues.AddXSeries();
|
||||
|
||||
foreach ((double, string) el in dataForPDFPie.Items) // заполнение серии
|
||||
foreach ((double, string) el in dataForPDFPie.Items)
|
||||
{
|
||||
series.Add(el.Item1);
|
||||
xseries.Add(el.Item2);
|
||||
}
|
||||
|
||||
switch (dataForPDFPie.diagLegend) // позиция легенды
|
||||
switch (dataForPDFPie.diagLegend)
|
||||
{
|
||||
case DiagramLegendEnum.Top:
|
||||
chart.TopArea.AddLegend();
|
||||
|
@ -27,7 +27,7 @@ namespace CustomComponents.NonVisualComponents
|
||||
}
|
||||
public bool createTable<T>(DataForTable<T> 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("Недостаточно данных");
|
||||
@ -50,7 +50,7 @@ namespace CustomComponents.NonVisualComponents
|
||||
foreach ((string, string) el in dataForPDF.Headers)
|
||||
if (string.IsNullOrEmpty(el.Item2)) throw new ArgumentException("Элементы шапки не могут быть пустыми");
|
||||
|
||||
//создание документа
|
||||
|
||||
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
|
||||
|
||||
Document _document = new Document();
|
||||
@ -65,14 +65,14 @@ namespace CustomComponents.NonVisualComponents
|
||||
style.Font.Name = "Arial";
|
||||
style.Font.Size = 10;
|
||||
|
||||
//добавление заголовка
|
||||
|
||||
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;
|
||||
@ -85,20 +85,20 @@ namespace CustomComponents.NonVisualComponents
|
||||
column.Format.Alignment = ParagraphAlignment.Center;
|
||||
}
|
||||
|
||||
// создание шапки и заполнение контентом
|
||||
|
||||
|
||||
int mergeRange = 0; //размерность слияния
|
||||
int mergeIndex = 0; //стартовый индекс начала слияния
|
||||
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;
|
||||
@ -107,7 +107,7 @@ namespace CustomComponents.NonVisualComponents
|
||||
row.Cells[0].VerticalAlignment = VerticalAlignment.Center;
|
||||
row.Cells[0].MergeDown = mergeRange;
|
||||
|
||||
//с этого места создаются дочерние ячейки
|
||||
|
||||
for (int k = 0; k < mergeRange; k++)
|
||||
{
|
||||
i++;
|
||||
@ -125,10 +125,10 @@ namespace CustomComponents.NonVisualComponents
|
||||
AddTheContent<T>(dataForPDF.Data, table, dataForPDF.Headers[i].Item1, row.Index, 2);
|
||||
row.Cells[1].VerticalAlignment = VerticalAlignment.Center;
|
||||
}
|
||||
else //если элемент шапки не группируется по строкам
|
||||
else
|
||||
|
||||
{
|
||||
//стилизация ячейки
|
||||
|
||||
row = table.AddRow();
|
||||
row.Height = dataForPDF.Heights[i];
|
||||
row.Format.Font.Bold = true;
|
||||
@ -151,7 +151,7 @@ namespace CustomComponents.NonVisualComponents
|
||||
return true;
|
||||
}
|
||||
|
||||
//метод заполнения таблицы контентом, заполнение происходит построчно.
|
||||
|
||||
public void AddTheContent<T>(List<T> items, Table table, string header, int row_index, int cell_index)
|
||||
{
|
||||
foreach (Row r in table.Rows)
|
||||
|
@ -114,7 +114,7 @@ namespace WinFormForTest
|
||||
|
||||
if (pdfTable1.createTable(new DataForTable<Film>(path, "Òàáëèöà ôèëüìîâ", heights, merges, headers, films)))
|
||||
{
|
||||
MessageBox.Show("Success");
|
||||
MessageBox.Show("Success!");
|
||||
}
|
||||
}
|
||||
|
||||
@ -132,7 +132,7 @@ namespace WinFormForTest
|
||||
|
||||
if (pdfPieChart1.CreatePieChart(new DataForPieChart(path, "Êðóãîâàÿ äèàãðàììà", "Óñïåõ ïðîñìîòðà 100 ôèëüìîâ", DiagramLegendEnum.Bottom, "Ïðîñìîòðåíî", elements)))
|
||||
{
|
||||
MessageBox.Show("Success");
|
||||
MessageBox.Show("Success!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user