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 { public class S52 : Entity.Section { private const int NUMERO_PRODOTTI_MATRICE_MAX = 12; /// ///S52.CorrelazioneAssetClass idSezione = 95 /// public S52(EnvironmentFacade environmentFacade, int idSection) : base(environmentFacade, idSection) { try { Draw(); } catch (Exception ex) { SectionLogger.Write("S52", 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)); } #region Tabella (matrice) int aLabel = 25; int lLabel = 160; // float xtabellone = dati.Tables["prodotti"].Rows.Count <= 4 ? EnvironmentFacade.RendererFacade.XLeftLimit + 120 : dati.Tables["prodotti"].Rows.Count <= 7 ? EnvironmentFacade.RendererFacade.XLeftLimit + 55 : EnvironmentFacade.RendererFacade.XLeftLimit; 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, AutoIncrementYWritable = false, WhiteSpacesHorizontalSeparator = true }; tabellaDati.Columns.Add(new ColumnPDF("Prodotto", lLabel, HorizontalAlignmentType.Sinistra, false, false, 7, ColumnType.Testo, "Prodotto", "") { FontSize = 7, HeaderFontColor = ColorPDF.Nero, HeaderFontBold = false, HeaderFontSize = 7, HeaderPaddingRight = 5, HeaderPaddingLeft = 5, HeaderBackgroundColor = ColorPDF.Bianco }); 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]; tabellaDati.Columns.Add(new ColumnPDF("P" + (r + 1), aLabel, HorizontalAlignmentType.Centrato, false, false, 7, ColumnType.Testo, "P" + (r + 1), dr["Prodotto"].ToString()) {FontSize=7, HeaderFontColor = ColorPDF.Nero, HeaderFontBold = false, HeaderFontSize = 7, HeaderPaddingRight =10, HeaderPaddingLeft=3,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("")) { 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 } tabellaDati.Cells[c, r].HorizontalAlignment = HorizontalAlignmentType.Destra; } } AddElement(new SpacePDF(15)); AddElement(tabellaDati); #endregion 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(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 = 5 }); 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++; } AddElement(tabellaLegenda); } /// /// Recupera i dati necessari alla Section restituendo un DataSet. /// /// 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_CorrelazioneAsset(orizzonteTemporale().mesi); } var correlazioneProdotti = datiSeiUnico.rischioUnit().rischio.correlazioneAsset; 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.listaAssetCorrelate.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 < correlazioneProdotti.listaAssetCorrelate.Count() && i < colmax; i++) { DataRow dr = ds.Tables["prodotti"].NewRow(); dr["Prodotto"] = correlazioneProdotti.listaAssetCorrelate[i].name; for (int c = 0; c < correlazioneProdotti.listaAssetCorrelate[i].correlations.Count() && c <= i; c++) { dr["P" + (c + 1)] = datiSeiUnico.FormatDecimal("{0}", correlazioneProdotti.listaAssetCorrelate[i].correlations[c].value); dr["Spazio" + (c + 1)] = ""; } ds.Tables["prodotti"].Rows.Add(dr); } return ds; } /// /// Recupera il testo introduttivo /// /// public virtual string getTesto() { string testo = "In questa scheda è riportata la matrice di correlazione a " + orizzonteTemporale().desc + " dei principali mercati finanziari (asset class) monetari, obbligazionari e azionari. La correlazione fra due asset class 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 (le due asset class sono perfettamente anticorrelate, reagiscono alle oscillazioni dei mercati con performance di pari entità, ma di segno opposto) e 1 (le due asset class sono perfettamente correlate, reagiscono alle oscillazioni di mercato con performance identiche sia per intensità che per segno)."; return testo; } public virtual OrizzonteTemporale orizzonteTemporale() { return GetOption().OrizzonteTemporale; } protected sealed override DataTable GetDataTable() {return null;} } }