255 lines
12 KiB
C#
255 lines
12 KiB
C#
using System;
|
|
using Consulenza.ReportWriter.Business;
|
|
using Consulenza.ReportWriter.Business.OBJ_PDF;
|
|
using System.Data;
|
|
using Consulenza.ReportCommon;
|
|
using System.Linq;
|
|
using System.Collections.Generic;
|
|
|
|
namespace Consulenza.ReportWriter.Manager.Section.Unica
|
|
{
|
|
public class S53 : Entity.Section
|
|
{
|
|
/// <summary>
|
|
///S53.CorrelazioneValute idSezione = 96
|
|
/// </summary>
|
|
private const int NUMERO_PRODOTTI_MATRICE_MAX = 10;
|
|
public S53(EnvironmentFacade environmentFacade, int idSection)
|
|
: base(environmentFacade, idSection)
|
|
{
|
|
try
|
|
{
|
|
Draw();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
SectionLogger.Write("S53", ex.Message, SectionLoggerMessageLevel.E, EnvironmentFacade.ReportEnvironment);
|
|
}
|
|
}
|
|
protected override sealed void Draw()
|
|
{
|
|
var dati = GetDataSet();
|
|
|
|
if (getTesto().Length > 0)
|
|
{
|
|
AddElement(new SpacePDF(20));
|
|
AddElement(new FormattedTextAreaPDF(getTesto(), EnvironmentFacade.RendererFacade.XLeftLimit) { FontSize = 7, TextHorizontalAlign = ceTe.DynamicPDF.TextAlign.Justify });
|
|
AddElement(new SpacePDF(20));
|
|
}
|
|
int aLabel = 25;
|
|
int lLabel = 160;
|
|
// Valore centrale è 523.00
|
|
float xtabellone = dati.Tables["prodotti"].Rows.Count <= 4 ? EnvironmentFacade.RendererFacade.XLeftLimit + 105 : dati.Tables["prodotti"].Rows.Count <= 7 ? EnvironmentFacade.RendererFacade.XLeftLimit + 50 : EnvironmentFacade.RendererFacade.XLeftLimit;
|
|
float valoreCentrale = 523 - dati.Tables["prodotti"].Columns.Count * 42.5F;
|
|
AddElement(new RectanglePDF(lLabel, lLabel, ColorPDF.Bianco) { AutoIncrementYWritable = false });
|
|
var dtLegenda = new DataTable();
|
|
dtLegenda.Columns.Add(new DataColumn("Etichetta", typeof(string)));
|
|
dtLegenda.Columns.Add(new DataColumn("Rettangolo", typeof(string)));
|
|
foreach (DataRow ro in dati.Tables["etichette"].Rows)
|
|
{
|
|
dtLegenda.Rows.Add(ro["Etichetta"].ToString(), "");
|
|
|
|
}
|
|
var tabellaLegenda = new TablePDF(xtabellone, dtLegenda)
|
|
{
|
|
Style = Style.ConsulenzaUnica,
|
|
Header = false,
|
|
Footer = false,
|
|
AlternateRow = false,
|
|
RowHeight = 30,
|
|
ShowSeparationLines = false,
|
|
ShowBorderLastLine = false,
|
|
AutoIncrementYWritable = true,
|
|
WhiteSpacesHorizontalSeparator = true
|
|
|
|
};
|
|
tabellaLegenda.Columns.Add(new ColumnPDF("Etichetta", 130, HorizontalAlignmentType.Sinistra, false, false, 7, ColumnType.Testo, "Etichetta", string.Empty) { FontSize = 7, PaddingLeft = 5 });
|
|
tabellaLegenda.Columns.Add(new ColumnPDF("rettangolo", 30, HorizontalAlignmentType.Centrato, false, false, 7, ColumnType.Objectpdf, "Rettangolo", string.Empty) { FontSize = 7, DeltaYContent = 5 });
|
|
|
|
int a = 0;
|
|
foreach (DataRow r in dati.Tables["etichette"].Rows)
|
|
{
|
|
ColorPDF colorPDF = new ColorPDF(int.Parse(r["Red"].ToString()), int.Parse(r["Green"].ToString()), int.Parse(r["Blue"].ToString()));
|
|
tabellaLegenda.Cells[1, a].ValueObject = new RectanglePDF(15, 35, colorPDF);
|
|
a++;
|
|
}
|
|
AddElement(tabellaLegenda);
|
|
#region Tabella (matrice)
|
|
|
|
DataTable originalDataTable = dati.Tables["prodotti"];
|
|
DataTable sourceDataTable = new DataTable();
|
|
sourceDataTable.Columns.Add("HorizontalFlagText", typeof(string));
|
|
sourceDataTable.Columns.Add("HorizontalFlagImg", typeof(string));
|
|
for (int i = 0; i < originalDataTable.Columns.Count - 1; i++)
|
|
{
|
|
sourceDataTable.Columns.Add(new DataColumn(string.Format("data{0}", i)));
|
|
sourceDataTable.Columns.Add(new DataColumn(string.Format("space{0}", i)));
|
|
}
|
|
|
|
DataRow flagsText = sourceDataTable.NewRow();
|
|
DataRow flagsImgs = sourceDataTable.NewRow();
|
|
for (int i = 0; i < originalDataTable.Rows.Count; i++)
|
|
{
|
|
flagsText[string.Format("data{0}", i)] = originalDataTable.Rows[i][0].ToString();
|
|
flagsImgs[string.Format("data{0}", i)] = string.Format("Flags\\{0}.png", originalDataTable.Rows[i][0].ToString());
|
|
}
|
|
sourceDataTable.Rows.Add(flagsText);
|
|
sourceDataTable.Rows.Add(flagsImgs);
|
|
for (int i = 0; i < originalDataTable.Rows.Count; i++)
|
|
{
|
|
DataRow dr = sourceDataTable.NewRow();
|
|
dr["HorizontalFlagText"] = originalDataTable.Rows[i][0].ToString();
|
|
dr["HorizontalFlagImg"] = string.Format("Flags\\{0}.png", originalDataTable.Rows[i][0].ToString());
|
|
for (int j = 0; j < originalDataTable.Columns.Count - 1; j++)
|
|
{
|
|
dr[string.Format("data{0}", j)] = originalDataTable.Rows[i][j + 1].ToString();
|
|
}
|
|
sourceDataTable.Rows.Add(dr);
|
|
}
|
|
|
|
var tabellaDati = new TablePDF(EnvironmentFacade.RendererFacade.XLeftLimit, sourceDataTable)
|
|
{
|
|
Style = Style.ConsulenzaUnica,
|
|
Header = false,
|
|
Footer = false,
|
|
AlternateRow = false,
|
|
RowHeight = 14,
|
|
ShowSeparationLines = false,
|
|
ShowBorderLastLine = false,
|
|
RowsPadding = 5,
|
|
AutoIncrementYWritable = false,
|
|
WhiteSpacesHorizontalSeparator = true
|
|
};
|
|
//tabellaDati.Cells[0,1].
|
|
for (int i = 0; i < sourceDataTable.Columns.Count; i++)
|
|
{
|
|
int width = 32;
|
|
if (sourceDataTable.Columns[i].ColumnName.Contains("space"))
|
|
{
|
|
width = 2;
|
|
}
|
|
tabellaDati.Columns.Add(new ColumnPDF(sourceDataTable.Columns[i].ColumnName, width, HorizontalAlignmentType.Centrato, false, false, 7, ColumnType.Testo, sourceDataTable.Columns[i].ColumnName, "")
|
|
{
|
|
ScaleColumnTypeImage = 0.6F,
|
|
HeaderBackgroundColor = ColorPDF.Bianco,
|
|
VerticalAlignment = VerticalAlignmentType.Centrato,
|
|
PaddingTopImage = 2,
|
|
HeaderPaddingRight = 4,
|
|
PaddingRight = 4,
|
|
FontSize = 7,
|
|
HeaderFontSize = 7
|
|
});
|
|
}
|
|
|
|
decimal highThreshold = Convert.ToDecimal(dati.Tables["etichette"].Rows[0]["highThreshold"].ToString());
|
|
decimal mediumThreshold = Convert.ToDecimal(dati.Tables["etichette"].Rows[0]["mediumThreshold"].ToString());
|
|
|
|
for (int i = 0; i < tabellaDati.Columns.Count; i++)
|
|
{
|
|
for (int j = 0; j < tabellaDati.RowsCount; j++)
|
|
{
|
|
decimal value = 0;
|
|
if (decimal.TryParse(tabellaDati.DataSource.Rows[j].ItemArray[i].ToString(), out value))
|
|
{
|
|
if (value == 1.0m)
|
|
{
|
|
tabellaDati.Cells[i, j].BackgroundColor = ColorPDF.Standard_Grigio_SfondoColonnaTabella;
|
|
}
|
|
else
|
|
{
|
|
//decimal mediumThreshold = Convert.ToDecimal(dati.Tables["etichette"].Rows[0]["mediumThreshold"].ToString());
|
|
// decimal valore = Convert.ToDecimal(dati.Tables["prodotti"].Rows[i][j].ToString());
|
|
|
|
tabellaDati.Cells[i, j].BackgroundColor =
|
|
value >= Convert.ToDecimal(0.70) && value <= highThreshold
|
|
? new ColorPDF(255, 83, 82) ://ALTA
|
|
|
|
value >= Convert.ToDecimal(0.31) && value <= Convert.ToDecimal(0.69) ? new ColorPDF(254, 191, 20) ://MEDIA
|
|
value <= Convert.ToDecimal(0.30) ? new ColorPDF(103, 208, 140) : ColorPDF.Bianco; //BASSA
|
|
}
|
|
tabellaDati.Cells[i, j].HorizontalAlignment = HorizontalAlignmentType.Destra;
|
|
tabellaDati.Cells[i, j].YContentOffset = 2.6F;
|
|
}
|
|
}
|
|
}
|
|
|
|
for (int i = 0; i < tabellaDati.Columns.Count; i++)
|
|
{
|
|
tabellaDati.Cells[i, 0].YContentOffset = 4;
|
|
}
|
|
|
|
AddElement(tabellaDati);
|
|
|
|
#endregion
|
|
}
|
|
protected sealed override DataTable GetDataTable()
|
|
{
|
|
return null;
|
|
}
|
|
protected sealed override DataSet GetDataSet()
|
|
{
|
|
var ds = new DataSet();
|
|
|
|
ds.Tables.Add(new DataTable("etichette"));
|
|
ds.Tables.Add(new DataTable("prodotti"));
|
|
|
|
ds.Tables["etichette"].Columns.Add(new DataColumn("Etichetta", typeof(string)));
|
|
ds.Tables["etichette"].Columns.Add(new DataColumn("Red", typeof(int)));
|
|
ds.Tables["etichette"].Columns.Add(new DataColumn("Green", typeof(int)));
|
|
ds.Tables["etichette"].Columns.Add(new DataColumn("Blue", typeof(int)));
|
|
ds.Tables["etichette"].Columns.Add(new DataColumn("highThreshold", typeof(decimal)));
|
|
ds.Tables["etichette"].Columns.Add(new DataColumn("mediumThreshold", typeof(decimal)));
|
|
|
|
if (orizzonteTemporale().anni != 1)
|
|
{
|
|
datiSeiUnico.rischioUnit_CorrelazioneEsposizioneValutaria(orizzonteTemporale().mesi);
|
|
}
|
|
var correlazioneEsposizioneValutaria = datiSeiUnico.rischioUnit().rischio.correlazioneEsposizioneValutaria;
|
|
|
|
|
|
ds.Tables["etichette"].Rows.Add("Correlazione Alta", 255, 83, 82, correlazioneEsposizioneValutaria.highThreshold, correlazioneEsposizioneValutaria.mediumThreshold);
|
|
ds.Tables["etichette"].Rows.Add("Correlazione Moderata", 254, 191, 20, correlazioneEsposizioneValutaria.highThreshold, correlazioneEsposizioneValutaria.mediumThreshold);
|
|
ds.Tables["etichette"].Rows.Add("Correlazione Bassa", 103, 208, 140, correlazioneEsposizioneValutaria.highThreshold, correlazioneEsposizioneValutaria.mediumThreshold);
|
|
|
|
|
|
|
|
int colmax = NUMERO_PRODOTTI_MATRICE_MAX;
|
|
ds.Tables["prodotti"].Columns.Add(new DataColumn("Prodotto", typeof(string)));
|
|
|
|
for (int i = 0; i < correlazioneEsposizioneValutaria.listaValuteCorrelate.Count() && i < colmax; i++)
|
|
{
|
|
|
|
ds.Tables["prodotti"].Columns.Add(new DataColumn("P" + (i + 1), typeof(decimal)));
|
|
// ds.Tables["prodotti"].Columns.Add(new DataColumn("Spazio" + (i + 1), typeof(string)));
|
|
|
|
}
|
|
|
|
|
|
for (int i = 0; i < correlazioneEsposizioneValutaria.listaValuteCorrelate.Count() && i < colmax; i++)
|
|
{
|
|
DataRow dr = ds.Tables["prodotti"].NewRow();
|
|
dr["Prodotto"] = correlazioneEsposizioneValutaria.listaValuteCorrelate[i].id;
|
|
|
|
for (int c = 0; c < correlazioneEsposizioneValutaria.listaValuteCorrelate[i].correlations.Count() && c <= i; c++)
|
|
{
|
|
|
|
dr["P" + (c + 1)] = datiSeiUnico.FormatDecimal("{0}", correlazioneEsposizioneValutaria.listaValuteCorrelate[i].correlations[c].value);
|
|
//dr["Spazio" + (c + 1)] = "";
|
|
}
|
|
ds.Tables["prodotti"].Rows.Add(dr);
|
|
}
|
|
|
|
return ds;
|
|
}
|
|
public virtual string getTesto()
|
|
{
|
|
return "In questa scheda è riportata la matrice di correlazione a " + orizzonteTemporale().desc + " dei principali tassi di cambio rispetto all'Euro. La correlazione fra due tassi di cambio misura se e con quale intensità le rispettive valute tendono a muoversi nella stessa direzione rispetto all'Euro: si dice positiva quando i tassi si muovono nella stessa direzione, inversa nel caso contrario. Più in dettaglio, la correlazione può assumere valori compresi fra -1 (le due valute sono perfettamente anticorrelate, reagiscono alle oscillazioni dei tassi di cambio con variazioni di pari entità, ma disegno opposto) e 1 (le due valute sono perfettamente correlate, reagiscono alle oscillazioni dei tassi di cambio con variazioni identiche sia per intensità che per segno).";
|
|
}
|
|
|
|
public virtual OrizzonteTemporale orizzonteTemporale()
|
|
{
|
|
return GetOption<Opzione5_2>().OrizzonteTemporale;
|
|
}
|
|
}
|
|
}
|