271 lines
15 KiB
C#

using System;
using Consulenza.ReportWriter.Business;
using Consulenza.ReportWriter.Business.OBJ_PDF;
using System.Data;
using Consulenza.ReportCommon;
using System.Collections.Generic;
using System.Linq;
namespace Consulenza.ReportWriter.Manager.Section.Unica
{
/// <summary>
/// S51.CorrelazioneProdotti idSezione = 94
/// </summary>
public class S51 : Entity.Section
{
private const int NUMERO_PRODOTTI_MATRICE_MAX = 12;
public S51(EnvironmentFacade environmentFacade, int idSection)
: base(environmentFacade, idSection)
{
try
{
Draw();
}
catch (Exception ex)
{
SectionLogger.Write("S51", 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(15));
}
int aLabel = 25;
int lLabel = 160;
// 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;
#region Tabella (matrice)
var tabellaDati = new TablePDF(EnvironmentFacade.RendererFacade.XLeftLimit, dati.Tables["prodotti"])
{
Style = Style.ConsulenzaUnica,
Header = true,
HeaderHeight = lLabel,
Footer = false,
AlternateRow = false,
RowHeight = aLabel,
ShowSeparationLines = false,
ShowBorderLastLine = false ,
HeaderMargin = 3,
WhiteSpacesHorizontalSeparator = true,
AutoIncrementYWritable = false,
};
int nomeLenght = 42;
tabellaDati.Columns.Add(new ColumnPDF("Prodotto", lLabel, HorizontalAlignmentType.Sinistra, false, false, 7, ColumnType.Testo, "Prodotto", "") { FontSize = 7, HeaderFontColor = ColorPDF.Nero, HeaderFontBold = false, HeaderFontSize = 7, HeaderBackgroundColor = ColorPDF.Bianco, HeaderPaddingRight = 5, HeaderPaddingLeft = 5, PaddingRight=5 });
tabellaDati.Columns.Add(new ColumnPDF("Spazio0", 1, HorizontalAlignmentType.Sinistra, false, false, 7, ColumnType.Testo, "Spazio0", "") { FontSize = 7, HeaderBackgroundColor = ColorPDF.Bianco, BackgroundColor = ColorPDF.Bianco, HeaderFontColor = ColorPDF.Bianco, HeaderFontBold = false, HeaderFontSize = 7, HeaderTextVerticalDirection = true });
for (int r = 0; r < dati.Tables["prodotti"].Rows.Count; r++) {
DataRow dr = dati.Tables["prodotti"].Rows[r];
float leftMargin = dr[0].ToString().Length <= nomeLenght ? 2.5F : -0.5F;
int lenght = dr["Prodotto"].ToString().Length < nomeLenght ? dr["Prodotto"].ToString().Length : nomeLenght;
int lastIndexOfSpace = dr["Prodotto"].ToString().Substring(0, lenght).LastIndexOf(' ');
string nomeProdotto = dr["Prodotto"].ToString().Length <= nomeLenght ? dr["Prodotto"].ToString() : dr["Prodotto"].ToString().Substring(0, lastIndexOfSpace) + "<BR>" + dr["Prodotto"].ToString().Substring(lastIndexOfSpace);
tabellaDati.Columns.Add(new ColumnPDF("P" + (r + 1), aLabel, HorizontalAlignmentType.Centrato, false, false, 7, ColumnType.Testo, "P" + (r + 1), nomeProdotto) { FontSize = 7, HeaderFontColor = ColorPDF.Nero, HeaderFontBold = false, HeaderFontSize = 7, HeaderPaddingLeft = leftMargin, HeaderTextVerticalDirection = true, PaddingRight = 2, });
tabellaDati.Columns.Add(new ColumnPDF("Spazio" + (r + 1), 1, HorizontalAlignmentType.Sinistra, false, false, 7, ColumnType.Testo, "Spazio" + (r + 1), "") { FontSize = 7, HeaderBackgroundColor = ColorPDF.Bianco, BackgroundColor = ColorPDF.Bianco, HeaderFontColor = ColorPDF.Bianco, HeaderFontBold = false, HeaderFontSize = 7, HeaderTextVerticalDirection = true});
}
for (int r = 0; r < dati.Tables["prodotti"].Rows.Count; r++)
{
tabellaDati.Cells[0, r].BackgroundColor = ColorPDF.Standard_Grigio_SfondoColonnaTabella;
for (int c = 1; c < dati.Tables["prodotti"].Columns.Count; c++)
{
if (dati.Tables["prodotti"].Rows[r][c].ToString().Equals("1,00"))
{
tabellaDati.Cells[c, r].BackgroundColor = ColorPDF.Standard_Grigio_SfondoColonnaTabella;
}
else if (dati.Tables["prodotti"].Rows[r][c].ToString().Equals(""))
{
tabellaDati.Cells[c, r].BackgroundColor = ColorPDF.Bianco;
tabellaDati.Cells[c, r].Value = "";
}
else if (!dati.Tables["prodotti"].Rows[r][c].ToString().Equals(""))
{
string sValore= "n.c.";
//Test Fc "n.c."
if (!dati.Tables["prodotti"].Rows[r][c].ToString().Equals("n.c."))
{
decimal highThreshold = Convert.ToDecimal(dati.Tables["etichette"].Rows[0]["highThreshold"].ToString());
decimal mediumThreshold = Convert.ToDecimal(dati.Tables["etichette"].Rows[0]["mediumThreshold"].ToString());
decimal valore = Convert.ToDecimal(dati.Tables["prodotti"].Rows[r][c].ToString());
tabellaDati.Cells[c, r].BackgroundColor =
valore >= Convert.ToDecimal(0.70) && valore <= highThreshold
? new ColorPDF(255, 83, 82) ://ALTA
valore >= Convert.ToDecimal(0.31) && valore <= Convert.ToDecimal(0.69) ? new ColorPDF(254, 191, 20) ://MEDIA
valore <= Convert.ToDecimal(0.30) ? new ColorPDF(103, 208, 140) : ColorPDF.Bianco; //BASSA
//media
}
else
tabellaDati.Cells[c, r].Value = sValore;
}
tabellaDati.Cells[c, r].HorizontalAlignment = HorizontalAlignmentType.Destra;
}
}
AddElement(tabellaDati);
#endregion
#region legenda
AddElement(new RectanglePDF(EnvironmentFacade.RendererFacade.XLeftLimit, 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(EnvironmentFacade.RendererFacade.XLeftLimit, dtLegenda)
{
Style = Style.ConsulenzaUnica,
Header = false,
Footer = false,
AlternateRow = false,
RowHeight = 30,
ShowSeparationLines = false,
ShowBorderLastLine = false,
AutoIncrementYWritable = false
};
tabellaLegenda.Columns.Add(new ColumnPDF("Etichetta", 120, HorizontalAlignmentType.Sinistra, false, false, 7, ColumnType.Testo, "Etichetta", string.Empty) { FontSize = 7, PaddingLeft = 4 });
tabellaLegenda.Columns.Add(new ColumnPDF("rettangolo", 30, HorizontalAlignmentType.Centrato, false, false, 7, ColumnType.Objectpdf, "Rettangolo", string.Empty) { FontSize = 7, DeltaYContent = 4 });
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++;
}
#endregion
AddElement(tabellaLegenda);
}
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"));
int orizzonte = int.Parse(GetOption<Opzione5_1>().Valore);
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)));
//FC 02032017
if (orizzonteTemporale().anni != 1)
{
datiSeiUnico.rischioUnit_CorrelazioneProdotti(orizzonteTemporale().mesi);
}
var correlazioneProdotti = datiSeiUnico.rischioUnit().rischio.correlazioneProdotti;
ds.Tables["etichette"].Rows.Add("Correlazione Alta", 255, 83, 82, correlazioneProdotti.highThreshold,correlazioneProdotti.mediumThreshold);
ds.Tables["etichette"].Rows.Add("Correlazione Moderata", 254, 191, 20, correlazioneProdotti.highThreshold,correlazioneProdotti.mediumThreshold);
ds.Tables["etichette"].Rows.Add("Correlazione Bassa", 103, 208, 140, correlazioneProdotti.highThreshold, correlazioneProdotti.mediumThreshold);
int colmax = NUMERO_PRODOTTI_MATRICE_MAX;
ds.Tables["prodotti"].Columns.Add(new DataColumn("Prodotto", typeof(string)));
ds.Tables["prodotti"].Columns.Add(new DataColumn("Spazio0", typeof(string)));
for (int i = 0; i < correlazioneProdotti.items.Count() && i < colmax; i++)
{
// Test FC ds.Tables["prodotti"].Columns.Add(new DataColumn("P" + (i + 1), typeof(decimal)));
ds.Tables["prodotti"].Columns.Add(new DataColumn("P" + (i + 1), typeof(string)));
ds.Tables["prodotti"].Columns.Add(new DataColumn("Spazio" + (i + 1), typeof(string)));
}
//var prodotti = from c in correlazioneProdotti.items.Skip(0).Take(colmax)
// where c.correlations. <= DateTime.Now.AddYears(orzTempMesi) //dipende da quale opzione arriva: se si decide per mesi o anni...rivedi opzioni, metodo e where
// orderby c.dtRiferimento
// select new
// {
// c.dtRiferimento,
// quantileSup = c.quantileSup * 100,
// quantileInf = c.quantileInf * 100,
// quantileInter = c.quantileInter * 100
// };
//for (int i = 0; i < prodotti.items.Count() && i < colmax; i++)
//{
// ds.Tables["prodotti"].Rows.Add(item.dtRiferimento,
// Convert.ToDecimal(item.quantileSup),
// Convert.ToDecimal(item.quantileInf),
// Convert.ToDecimal(item.quantileInter)
// );
//}
for (int i = 0; i < correlazioneProdotti.items.Count() && i < colmax; i++)
{
DataRow dr = ds.Tables["prodotti"].NewRow();
dr["Prodotto"] = correlazioneProdotti.items[i].name;
string p;
for (int c = 0; c < correlazioneProdotti.items[i].correlations.Count() && c <= i; c++)
{
if (correlazioneProdotti.items[i].correlations[c].value == 0 && correlazioneProdotti.items[i].correlations[c].valueSpecified == false)
dr["P" + (c + 1)] = "n.c." ;
else
dr["P" + (c + 1)] = datiSeiUnico.FormatDecimal("{0}", correlazioneProdotti.items[i].correlations[c].value);
dr["Spazio" + (c + 1)] = "";
}
ds.Tables["prodotti"].Rows.Add(dr);
}
return ds;
}
public virtual string getTesto()
{
string nota = string.Format(GetText().Rows[0]["testo1"].ToString(), orizzonteTemporale().desc );//In questa scheda è riportata la matrice di correlazione a un anno dei principali fondi e/o gestioni patrimoniali, associati al nucleo, che i componenti detengono presso $/Banca/$. La correlazione fra due strumenti finanziari misura se e con quale intensità i loro rendimenti tendono a muoversi nella stessa direzione: si dice positiva quando i rendimenti si muovono nella stessa direzione, inversa nel caso contrario. Più in dettaglio, la correlazione può assumere valori compresi fra -1 (i due strumenti sono perfettamente anticorrelati, reagiscono alle oscillazioni dei mercati con performance di pari entità, ma di segno opposto) e 1 (i due strumenti sono perfettamente correlati, reagiscono alle oscillazioni di mercato con performance identiche sia per intensità che per segno). "In questa scheda è riportata la matrice di correlazione a " + orizzonteTemporale().desc + " dei principali fondi e/o gestioni patrimoniali che lei detiene presso $/Banca/$. La correlazione fra due strumenti finanziari misura se e con quale intensità i loro rendimenti tendono a muoversi nella stessa direzione: si dice positiva quando i rendimenti si muovono nella stessa direzione, inversa nel caso contrario. Più in dettaglio, la correlazione può assumere valori compresi fra -1 (i due strumenti sono perfettamente anticorrelati, reagiscono alle oscillazioni dei mercati con performance di pari entità, ma di segno opposto) e 1 (i due strumenti sono perfettamente correlati, reagiscono alle oscillazioni di mercato con performance identiche sia per intensità che per segno).";
return datiSeiUnico.FormatBanca(nota);
}
public virtual OrizzonteTemporale orizzonteTemporale()
{
return GetOption<Opzione5_1>().OrizzonteTemporale;
}
}
}