using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Collections; using ceTe.DynamicPDF; using ceTe.DynamicPDF.Text; using PDFGenerator.Presentation.Section.Tables; using PDFGenerator.BusinessLayer.DataSection; using PDFGenerator.BusinessLayer; using System.Resources; using System.Reflection; using System.Collections.Generic; using System.Linq; using NLog; namespace PDFGenerator.Presentation.Section { public class FD133BIS : SIstogramma, ISezione { private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger(); private string _header = ""; private string _testointroduttivo; private string Titolo = string.Empty; public string Header { get { return _header; } set { _header = value; } } private TipologiaReport _tipologiaReport; public TipologiaReport TipologiaReport { get { return _tipologiaReport; } set { _tipologiaReport = value; } } /// /// Testo introduttivo della sezione. /// public string TestoIntroduttivo { get { return _testointroduttivo; } set { _testointroduttivo = value; } } public void setTitolo(string label) { Titolo = label; } public FD133BIS() { // // TODO: Add constructor logic here // } #region ISezione Members public void writeSezione(DataThread dataThread) { dataThread.SETDATA(); DocumentPDF document = dataThread.DocumentPDF; DataSetS133BIS set = (DataSetS133BIS)dataThread.Data.DatiSezione; DatiTabella datitab = new DatiTabella(); // Titolo della sezione logger.Info("Titolo della sezione " + _testointroduttivo); document.setLastPos(-40); document.setSezTitolo(dataThread.SezioneReport.Titolo); document.setChapterHeader(string.Concat(_testointroduttivo, "
"), 0, 520, 8); #region Test per l'impaginazione e inserimento grafico contestualmente 01/10/2023 - Pino /*** Divido il DataTable in più tabelle contenente solo 10 righe ognuna 29/09/2023 - Pino *****/ DataTable _dtParziale = set.Tables["PrincipaliProdotti"].Copy(); DataTable _PrimiDieciRecord = new DataTable(); int contaPagine = 1; int stepPaginazione = 20; int inizioDatiPaginazione = 0; int fineDatiPaginazione = 0; float ultimaPosizione = 0; var quantePagine = Math.Round(Convert.ToDouble((set.Tables["PrincipaliProdotti"].Rows.Count / stepPaginazione))); // Trovo il valore massimo double maxValPesoRelativo = Convert.ToDouble(_dtParziale.AsEnumerable().Max(m => m.Field("pesoRelativo"))); double maxValrischioRelativo =Convert.ToDouble(_dtParziale.AsEnumerable().Max(m => m.Field("rischioRelativo"))); if (quantePagine == 0) quantePagine = contaPagine; // Cicla sulle pagine e suddivido il dataset while (contaPagine <= quantePagine) { fineDatiPaginazione = stepPaginazione * contaPagine; _PrimiDieciRecord = _dtParziale.AsEnumerable().Skip(inizioDatiPaginazione).Take(stepPaginazione).CopyToDataTable(); datitab.table = _PrimiDieciRecord; //if (document.checkMargin(180)) // document.addPage(); //Disegno la tabella Tabella tabellaDati = new Tabella(document.getMargineLeft(), document.getLastPos() + ultimaPosizione); if (contaPagine == 1) tabellaDati.Header = true; else tabellaDati.Header = false; tabellaDati.HeaderFont = 8; tabellaDati.Datasource = datitab.table; tabellaDati.AltezzaCella = 15; tabellaDati.LineeTabella = true; //tabellaDati.Colonne.Add(new Colonna("DescrProdotto", "Prodotto", 262, TipoAllineamento.SINISTRA, false, 8, false, TipoColonna.IMMAGINE_E_TESTO)); tabellaDati.Colonne.Add(new Colonna("DescrProdotto", "Prodotto", 262, TipoAllineamento.SINISTRA, false, 8, false, TipoColonna.TESTO)); tabellaDati.Colonne.Add(new Colonna("VaRProdotto", "Rischio
(VaR%)", 60, TipoAllineamento.DESTRA, false, 8, false)); tabellaDati.Colonne.Add(new Colonna("pesoRelativo", "Peso relativo %", 95, TipoAllineamento.DESTRA, false, 8, false)); tabellaDati.Colonne.Add(new Colonna("rischioRelativo", "Rischio relativo %", 95, TipoAllineamento.SINISTRA, false, 8, false)); tabellaDati.ColoreDirectBankB = "green"; tabellaDati.Draw(datitab, document); #region Grafico a farfalla per Prodotti #region Recupero i valori da assegnare alle serie del grafico List listaValoriPesoRelativo = new List(); List listaValoriRischioRelativo = new List(); foreach (DataRow row in _PrimiDieciRecord.Rows) { IValoriSerie IvaloriSeriePesoRelativo = new IValoriSerie(); IvaloriSeriePesoRelativo.chiave = row["DescrProdotto"].ToString(); IvaloriSeriePesoRelativo.valore = Convert.ToDecimal(row["pesoRelativo"]); listaValoriPesoRelativo.Add(IvaloriSeriePesoRelativo); IValoriSerie IvaloriSerieRischioRelativo = new IValoriSerie(); IvaloriSerieRischioRelativo.chiave = row["DescrProdotto"].ToString(); IvaloriSerieRischioRelativo.valore = Convert.ToDecimal(row["rischioRelativo"]); listaValoriRischioRelativo.Add(IvaloriSerieRischioRelativo); } #endregion double altezzaGraficoPesoRischio_Prodotto = 15 * (_PrimiDieciRecord.Rows.Count); //15 * (tabellaDati.Datasource.Rows.Count + 0.01); //0.5 IstoFarfallaS133BIS graficoPesoRischio_Prodotto = new IstoFarfallaS133BIS((double)200, altezzaGraficoPesoRischio_Prodotto); graficoPesoRischio_Prodotto.DocumentPDF = document; graficoPesoRischio_Prodotto.PositionX = 365; graficoPesoRischio_Prodotto.PositionY = Convert.ToInt32(document.getLastPos() + 14); //542; graficoPesoRischio_Prodotto.AxisY_LineColor = false; graficoPesoRischio_Prodotto.AxisY_Hide = true; graficoPesoRischio_Prodotto.AxysX_Increment = Convert.ToDecimal(1); SerieIstoFarfallaS133BIS seriePesoRelativo = new SerieIstoFarfallaS133BIS(); SerieIstoFarfallaS133BIS serieRischioRelativo = new SerieIstoFarfallaS133BIS(); seriePesoRelativo = new SerieIstoFarfallaS133BIS(); seriePesoRelativo.Name = "pesoRelativo"; seriePesoRelativo.Values = listaValoriPesoRelativo; //seriePesoRelativo.ElementPosition = new Dundas.Charting.WebControl.ElementPosition(1F, -5F, 50.7F, 105F); seriePesoRelativo.ElementPosition = new Dundas.Charting.WebControl.ElementPosition(1F, -2.5F, 50.7F, 105F); //seriePesoRelativo.AxisY_CustumizedByValues = false; seriePesoRelativo.AxisY_CustumizedByValues = true; seriePesoRelativo.ReverseAxisY = true; //seriePesoRelativo.AxisY_MaximumValue = maxValPesoRelativo; serieRischioRelativo.Name = "rischioRelativo"; serieRischioRelativo.Values = listaValoriRischioRelativo; //serieRischioRelativo.ElementPosition = new Dundas.Charting.WebControl.ElementPosition(49.3F, -5, 50.7F, 105F); serieRischioRelativo.ElementPosition = new Dundas.Charting.WebControl.ElementPosition(49.3F, -2.5F, 50.7F, 105F); //serieRischioRelativo.AxisY_CustumizedByValues = false; serieRischioRelativo.AxisY_CustumizedByValues = true; //serieRischioRelativo.AxisY_MaximumValue = maxValrischioRelativo; graficoPesoRischio_Prodotto.SerieList.Add(seriePesoRelativo); graficoPesoRischio_Prodotto.SerieList.Add(serieRischioRelativo); try { // Disegno il grafico graficoPesoRischio_Prodotto.Draw(); } catch (Exception ex) { logger.Error("FD133BIS Grafico: " + ex.Message); } #endregion inizioDatiPaginazione = fineDatiPaginazione; _PrimiDieciRecord.Clear(); ultimaPosizione = (tabellaDati.AltezzaTabella + 25) * contaPagine; //((tabellaDati.AltezzaCella + 2) * stepPaginazione) * contaPagine; contaPagine++; document.setLastPos(document.getLastPos()); } //datitab.table = set.Tables["PrincipaliProdotti"]; /**********************************************************************************************/ #endregion //datitab.table = set.Tables["PrincipaliProdotti"]; //if (document.checkMargin(180)) // document.addPage(); ////Disegno la tabella //Tabella tabellaDati = new Tabella(document.getMargineLeft(), document.getLastPos()); //tabellaDati.Header = true; //tabellaDati.HeaderFont = 8; //tabellaDati.Datasource = datitab.table; //tabellaDati.AltezzaCella = 15; ////tabellaDati.Colonne.Add(new Colonna("DescrProdotto", "Prodotto", 262, TipoAllineamento.SINISTRA, false, 8, false, TipoColonna.IMMAGINE_E_TESTO)); //tabellaDati.Colonne.Add(new Colonna("DescrProdotto", "Prodotto", 262, TipoAllineamento.SINISTRA, false, 8, false, TipoColonna.TESTO)); //tabellaDati.Colonne.Add(new Colonna("VaRProdotto", "Rischio
(VaR%)", 60, TipoAllineamento.DESTRA, false, 8, false)); //tabellaDati.Colonne.Add(new Colonna("pesoRelativo", "Peso relativo %", 95, TipoAllineamento.DESTRA, false, 8, false)); //tabellaDati.Colonne.Add(new Colonna("rischioRelativo", "Rischio relativo %", 95, TipoAllineamento.SINISTRA, false, 8, false)); //#region Simboli del patrimonio ////int numSimboli = 13; ////string testoLetteraSimboloPatrimonio = string.Empty; ////foreach (DataRow row in tabellaDati.Datasource.Rows) ////{ //// document.getCurrentPage().Elements.Add(RecuperaSimboloAreaBisogno(document.getMargineLeft(), document.getLastPos() + numSimboli, row["codiceAreaBisogno"].ToString())); //// document.getCurrentPage().Elements.Add(new ceTe.DynamicPDF.PageElements.Label((RecuperaLetteraSimboloAreaBisogno(row["codiceAreaBisogno"].ToString())), GetX(row["codiceAreaBisogno"].ToString(), document.getMargineLeft() + 2), document.getLastPos() + numSimboli, 5, 10, Globals.OpenTypeFontVerdana, 10, ceTe.DynamicPDF.TextAlign.Center, CmykColor.White)); //// numSimboli += 15; ////} //#endregion //tabellaDati.ColoreDirectBankB = "green"; //tabellaDati.SezioneDiProvenienza = "FD133BIS"; //tabellaDati.documentPDF = document; //tabellaDati.Draw(datitab, document); #region Grafico a farfalla per Prodotti #region Recupero i valori da assegnare alle serie del grafico //List listaValoriPesoRelativo = new List(); //List listaValoriRischioRelativo = new List(); //foreach (DataRow row in set.Tables["PrincipaliProdotti"].Rows) //{ // IValoriSerie IvaloriSeriePesoRelativo = new IValoriSerie(); // IvaloriSeriePesoRelativo.chiave = row["DescrProdotto"].ToString(); // IvaloriSeriePesoRelativo.valore = Convert.ToDecimal(row["pesoRelativo"]); // listaValoriPesoRelativo.Add(IvaloriSeriePesoRelativo); // IValoriSerie IvaloriSerieRischioRelativo = new IValoriSerie(); // IvaloriSerieRischioRelativo.chiave = row["DescrProdotto"].ToString(); // IvaloriSerieRischioRelativo.valore = Convert.ToDecimal(row["rischioRelativo"]); // listaValoriRischioRelativo.Add(IvaloriSerieRischioRelativo); //} #endregion //double altezzaGraficoPesoRischio_Prodotto = 15 * (tabellaDati.Datasource.Rows.Count + 0.01); //0.5 //IstoFarfallaS133BIS graficoPesoRischio_Prodotto = new IstoFarfallaS133BIS((double)200, altezzaGraficoPesoRischio_Prodotto); //graficoPesoRischio_Prodotto.DocumentPDF = document; //graficoPesoRischio_Prodotto.PositionX = 365; //graficoPesoRischio_Prodotto.PositionY = Convert.ToInt32(document.getLastPos() + 14); //542; //graficoPesoRischio_Prodotto.AxisY_LineColor = false; //graficoPesoRischio_Prodotto.AxisY_Hide = true; //graficoPesoRischio_Prodotto.AxysX_Increment = Convert.ToDecimal(1); //SerieIstoFarfallaS133BIS seriePesoRelativo = new SerieIstoFarfallaS133BIS(); //SerieIstoFarfallaS133BIS serieRischioRelativo = new SerieIstoFarfallaS133BIS(); //seriePesoRelativo = new SerieIstoFarfallaS133BIS(); //seriePesoRelativo.Name = "pesoRelativo"; //seriePesoRelativo.Values = listaValoriPesoRelativo; ////seriePesoRelativo.ElementPosition = new Dundas.Charting.WebControl.ElementPosition(1F, -5F, 50.7F, 105F); //seriePesoRelativo.ElementPosition = new Dundas.Charting.WebControl.ElementPosition(1F, -2.5F, 50.7F, 105F); //seriePesoRelativo.AxisY_CustumizedByValues = true; //seriePesoRelativo.ReverseAxisY = true; //serieRischioRelativo.Name = "rischioRelativo"; //serieRischioRelativo.Values = listaValoriRischioRelativo; ////serieRischioRelativo.ElementPosition = new Dundas.Charting.WebControl.ElementPosition(49.3F, -5, 50.7F, 105F); //serieRischioRelativo.ElementPosition = new Dundas.Charting.WebControl.ElementPosition(49.3F, -2.5F, 50.7F, 105F); //serieRischioRelativo.AxisY_CustumizedByValues = true; //graficoPesoRischio_Prodotto.SerieList.Add(seriePesoRelativo); //graficoPesoRischio_Prodotto.SerieList.Add(serieRischioRelativo); //try //{ // // Disegno il grafico // //graficoPesoRischio_Prodotto.Draw(); //} //catch (Exception ex) //{ // logger.Error("FD133BIS Grafico: " + ex.Message); //} #endregion #region Legenda //float xLegenda = document.getMargineLeft(); //float yLegenda = document.getLastPos() + tabellaDati.AltezzaTabella; //if (set.Tables["PrincipaliProdotti"].Select("codiceAreaBisogno='Ext'").Length > 0) //{ // document.getCurrentPage().Elements.Add(RecuperaSimboloAreaBisogno(xLegenda, yLegenda, "Ext")); // document.getCurrentPage().Elements.Add(new ceTe.DynamicPDF.PageElements.Label("E", GetX("Ext", xLegenda + 2), yLegenda, 5, 10, Globals.OpenTypeFontVerdana, 10, ceTe.DynamicPDF.TextAlign.Center, ceTe.DynamicPDF.CmykColor.White)); // document.writeText(xLegenda + 15, yLegenda + 2, "Extra Rendimento", 8); // xLegenda += 100; //} //if (set.Tables["PrincipaliProdotti"].Select("codiceAreaBisogno='Inv'").Length > 0) //{ // document.getCurrentPage().Elements.Add(RecuperaSimboloAreaBisogno(xLegenda, yLegenda, "Inv")); // document.getCurrentPage().Elements.Add(new ceTe.DynamicPDF.PageElements.Label("I", GetX("Inv", xLegenda + 2), yLegenda, 5, 10, Globals.OpenTypeFontVerdana, 10, ceTe.DynamicPDF.TextAlign.Center, ceTe.DynamicPDF.CmykColor.White)); // document.writeText(xLegenda + 15, yLegenda + 2, "Investimento", 8); // xLegenda += 81; //} //if ((set.Tables["PrincipaliProdotti"].Select("codiceAreaBisogno='Pre'").Length > 0) || // (set.Tables["PrincipaliProdotti"].Select("codiceAreaBisogno='Pre1'").Length > 0) || // (set.Tables["PrincipaliProdotti"].Select("codiceAreaBisogno='Pre2'").Length > 0)) //{ // document.getCurrentPage().Elements.Add(RecuperaSimboloAreaBisogno(xLegenda, yLegenda, "Pre")); // document.getCurrentPage().Elements.Add(new ceTe.DynamicPDF.PageElements.Label("P", GetX("Pre", xLegenda + 2), yLegenda, 5, 10, Globals.OpenTypeFontVerdana, 10, ceTe.DynamicPDF.TextAlign.Center, ceTe.DynamicPDF.CmykColor.White)); // document.writeText(xLegenda + 15, yLegenda + 2, "Previdenza", 8); // xLegenda += 71; //} //if (set.Tables["PrincipaliProdotti"].Select("codiceAreaBisogno='Ris'").Length > 0) //{ // document.getCurrentPage().Elements.Add(RecuperaSimboloAreaBisogno(xLegenda, yLegenda, "Ris")); // document.getCurrentPage().Elements.Add(new ceTe.DynamicPDF.PageElements.Label("R", GetX("Ris", xLegenda + 2), yLegenda, 5, 10, Globals.OpenTypeFontVerdana, 10, ceTe.DynamicPDF.TextAlign.Center, ceTe.DynamicPDF.CmykColor.White)); // document.writeText(xLegenda + 15, yLegenda + 2, "Riserva", 8); // xLegenda += 57; //} //if (set.Tables["PrincipaliProdotti"].Select("codiceAreaBisogno='Liq'").Length > 0) //{ // document.getCurrentPage().Elements.Add(RecuperaSimboloAreaBisogno(xLegenda, yLegenda, "Liq")); // document.getCurrentPage().Elements.Add(new ceTe.DynamicPDF.PageElements.Label("L", GetX("Liq", xLegenda + 2), yLegenda, 5, 10, Globals.OpenTypeFontVerdana, 10, ceTe.DynamicPDF.TextAlign.Center, ceTe.DynamicPDF.CmykColor.White)); // document.writeText(xLegenda + 15, yLegenda + 2, "Liquidità", 8); // xLegenda += 61; //} //if (set.Tables["PrincipaliProdotti"].Select("codiceAreaBisogno='Na'").Length > 0) //{ // document.getCurrentPage().Elements.Add(RecuperaSimboloAreaBisogno(xLegenda, yLegenda, "Na")); // document.getCurrentPage().Elements.Add(new ceTe.DynamicPDF.PageElements.Label("!", GetX("Na", xLegenda + 2), yLegenda, 5, 10, Globals.OpenTypeFontVerdana, 10, ceTe.DynamicPDF.TextAlign.Center, ceTe.DynamicPDF.CmykColor.White)); // document.writeText(xLegenda + 15, yLegenda + 2, "Non Allocate", 8); //} #endregion document.setLastPos(600); } ///// ///// Aggiungo il simbolo dell'area di bisogno del prodotto ///// ///// ///// ///// ///// private ceTe.DynamicPDF.PageElements.Rectangle RecuperaSimboloAreaBisogno(float x, float y, string area) { System.Drawing.Color color = GetColors(area); ceTe.DynamicPDF.PageElements.Rectangle simbolo = new ceTe.DynamicPDF.PageElements.Rectangle(x, y, 13, 13, 1, new RgbColor(color.R, color.G, color.B)); simbolo.CornerRadius = 1; simbolo.BorderWidth = 0; return simbolo; } ///// ///// Recupera la lettera simbolo dell'area di bisogno passata in input ///// ///// ///// private string RecuperaLetteraSimboloAreaBisogno(string area) { string testoLetteraSimboloPatrimonio = string.Empty; #region Recupero la lettera simbolo di area di bisogno switch (area.ToString().ToUpper()) { case "INV": testoLetteraSimboloPatrimonio = "I"; break; case "EXT": testoLetteraSimboloPatrimonio = "E"; break; case "RIS": testoLetteraSimboloPatrimonio = "R"; break; case "LIQ": testoLetteraSimboloPatrimonio = "L"; break; case "PRE": testoLetteraSimboloPatrimonio = "P"; break; case "PRE1": testoLetteraSimboloPatrimonio = "P"; break; case "PRE2": testoLetteraSimboloPatrimonio = "P"; break; case "NA": testoLetteraSimboloPatrimonio = "!"; break; default: testoLetteraSimboloPatrimonio = ""; break; } #endregion return testoLetteraSimboloPatrimonio; } ///// ///// Recupera i colori a partire dal codice area. ///// ///// ///// private System.Drawing.Color GetColors(string area) { System.Drawing.Color c = System.Drawing.Color.FromArgb(0, 0, 0); switch (area.ToLower()) { case "inv": c = System.Drawing.Color.FromArgb(229, 119, 43); break; case "ext": c = System.Drawing.Color.FromArgb(222, 21, 44); break; case "ris": c = System.Drawing.Color.FromArgb(137, 142, 184); break; case "liq": c = System.Drawing.Color.FromArgb(57, 65, 132); break; case "pre": c = System.Drawing.Color.FromArgb(237, 180, 20); break; case "pre1": c = System.Drawing.Color.FromArgb(237, 180, 20); break; case "pre2": c = System.Drawing.Color.FromArgb(237, 180, 20); break; case "na": c = System.Drawing.Color.FromArgb(192, 192, 216); break; default: c = System.Drawing.Color.FromArgb(166, 166, 166); break; } return c; } ///// ///// Recupera la X, in modo da centrare il simbolo dell'area all'interno del tuo contenitore. ///// ///// ///// ///// private float GetX(string area, float x) { float returnX = x; switch (area.ToLower()) { case "inv": returnX = x + 2; break; case "ext": returnX = x + 1; break; case "ris": returnX = x + 1; break; case "liq": returnX = x + 1; break; case "pre": returnX = x + 1; break; case "pre1": returnX = x + 1; break; case "pre2": returnX = x + 1; break; case "na": returnX = x + 2; break; default: returnX = x; break; } return returnX; } //ceTe.DynamicPDF.Merger.ImportedPage page = document.getCurrentPage(); //document.setHeaderSpace(78); //document.setLastPos(tabellaDati.AltezzaTabella); #endregion } }