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.Threading;
using System.Globalization;
using System.Collections.Generic;
using Dundas.Charting.WebControl;
using ContrattoSei.Utilities;
using System.Linq;

namespace PDFGenerator.Presentation.Section
{
    class S147 : ISezione // valute
    {
        private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
        public S147()
        {
        }
        private string _testointroduttivo;
        private string _testointroduttivoAlternativo;

        /// <summary>
        /// Testo introduttivo della sezione
        /// </summary>
        public string TestoIntroduttivo
        {
            get { return _testointroduttivo; }
            set { _testointroduttivo = value; }
        }

        /// <summary>
        /// Testo introduttivo della sezione
        /// </summary>
        public string TestoIntroduttivoAlternativo
        {
            get { return _testointroduttivoAlternativo; }
            set { _testointroduttivoAlternativo = value; }
        }

        public void writeSezione(DataThread dataThread)
        {
            DocumentPDF document = dataThread.DocumentPDF;
            //DataSectionParameter dataSectionParameter = paramSez.getParam();
            FormatNum conv = new FormatNum();
            DatiTabella datitab = new DatiTabella();
            DataSetS147 set = (DataSetS147)dataThread.Data.DatiSezione;

            //*********************** Modifiche Andrea nuove valute******************************************
            foreach (var item in set.PesiValuteTotali.AsEnumerable())
            {
                if (item.Field<string>("VALUTA").ToString() == "XX1")
                    item.SetField<string>("VALUTA", "Non Disp");
                if (item.Field<string>("VALUTA").ToString() == "AP1")
                    item.SetField<string>("VALUTA", "Altre PE");
                if (item.Field<string>("VALUTA").ToString() == "AP2")
                    item.SetField<string>("VALUTA", "Altre PS");
            }
            foreach (var item1 in set.PesiValuteNegative.AsEnumerable())
            {
                if (item1.Field<string>("VALUTA").ToString() == "XX1")
                    item1.SetField<string>("VALUTA", "Non Disp");
                if (item1.Field<string>("VALUTA").ToString() == "AP1")
                    item1.SetField<string>("VALUTA", "Altre PE");
                if (item1.Field<string>("VALUTA").ToString() == "AP2")
                    item1.SetField<string>("VALUTA", "Altre PS");
            }
            foreach (var item2 in set.PesiValutePositive.AsEnumerable())
            {
                if (item2.Field<string>("VALUTA").ToString() == "XX1")
                    item2.SetField<string>("VALUTA", "Non Disp");
                if (item2.Field<string>("VALUTA").ToString() == "AP1")
                    item2.SetField<string>("VALUTA", "Altre PE");
                if (item2.Field<string>("VALUTA").ToString() == "AP2")
                    item2.SetField<string>("VALUTA", "Altre PS");
            }
            //*****************************************************************************
            ceTe.DynamicPDF.Merger.ImportedPage page = document.getCurrentPage();
            double copertura = Convert.ToDouble(set.PesiValuteTotali.Rows[0]["Copertura"]) * 100;
            //document.setHeaderSpace(40);
            int hCellTab = 23;//30--25
            int sFont = 8;
            int hBottRett = 18;//22
            int wBottRett = 258;//254
            int hBott = 10;//10
            int wBott = 40;//40
            document.setSezTitolo(dataThread.SezioneReport.Titolo.Replace("/$Banca$/", dataThread.NomeRete));
            document.setChapterHeader(dataThread.SezioneReport.TestoIntroduttivo.Replace("/$Banca$/", dataThread.NomeRete).Replace("classificazione del suo patrimonio", "classificazione del patrimonio").Replace("Sanpaolo Invest", "Fideuram S.p.A., commercializzato tramite la rete di private banker Sanpaolo Invest,"), 0, 520, 8);
            #region Tabella a destra della piramide
            // disegno la tabella a destra della piramide.
            #region datasource tabella
            //setta la datatable
            datitab.table = set.PesiValuteTotali;
            #endregion
            ////#region Nuova tabella
            decimal totalNegativeCurrentAccountValue = dataThread.Periodico ? dataThread.ContoCorrente : 0;
            decimal GPEligoFondi = dataThread.GPEligoFondi;
            decimal GPEligoTitoli = dataThread.GPEligoTitoli;
            //double GradoCopertura = copertura;
            decimal PatrBancaSez = dataThread.PatrimonioBancaFideuramCtvAlNettoContoCorrente - dataThread.PartiteViaggiantiInvestimento - dataThread.PartiteViaggiantiDisinvestimento - dataThread.PatrimonioNonRappresentabileFI;

            string banca = "/$Banca$/ (€)".Replace("/$Banca$/", dataThread.NomeRete);
            decimal valore = dataThread.PatrimonioBancaFideuramCtvAlNettoContoCorrente + dataThread.PartiteViaggiantiInvestimento + dataThread.PartiteViaggiantiDisinvestimento; // + dataThread.PatrimonioNonRappresentabile;
            decimal GradoCopertura = PatrBancaSez / valore * 100;
            //decimal valore = dataThread.PatrimonioBancaFideuramCtvAlNettoContoCorrente;
            decimal ProdottiNonRapp = dataThread.PatrimonioNonRappresentabileFI;
            decimal PartiteViaggianti = dataThread.PartiteViaggiantiInvestimento;
            ////Tabella Tabellactv = new Tabella();
            ////Tabellactv.Colonne.Add(new Colonna("Patrimonio", "Patrimonio" + banca, 40, TipoAllineamento.SINISTRA, true, sFont, true, TipoColonna.TESTO));
            ////Tabellactv.Colonne.Add(new Colonna("Valore", valore.ToString("N") , 40, TipoAllineamento.DESTRA, true, 6, true));
            ////Tabellactv.Draw(datitab, document); 
            page.Elements.Add(new ceTe.DynamicPDF.PageElements.Rectangle(35, 217, 187, 20, new RgbColor(232, 236, 237), new RgbColor(232, 236, 237)));
            page.Elements.Add(new ceTe.DynamicPDF.PageElements.Label("Patrimonio " + banca, 37, 220, 200, 20, Globals.OpenTypeFontVerdanaB, 8, ceTe.DynamicPDF.TextAlign.Left, ceTe.DynamicPDF.CmykColor.Black));
            if (totalNegativeCurrentAccountValue != 0 || GPEligoFondi < 0 || GPEligoTitoli < 0 || ((GradoCopertura >= 0 && GradoCopertura < 100) && (PartiteViaggianti != 0 || PartiteViaggianti != 0)))
            {
                page.Elements.Add(new ceTe.DynamicPDF.PageElements.Label("Patrimonio " + banca + "*", 37, 220, 200, 20, Globals.OpenTypeFontVerdanaB, 8, ceTe.DynamicPDF.TextAlign.Left, ceTe.DynamicPDF.CmykColor.Black));
            }
            else
            {
                page.Elements.Add(new ceTe.DynamicPDF.PageElements.Label("Patrimonio " + banca, 37, 220, 200, 20, Globals.OpenTypeFontVerdanaB, 8, ceTe.DynamicPDF.TextAlign.Left, ceTe.DynamicPDF.CmykColor.Black));

            }
            page.Elements.Add(new ceTe.DynamicPDF.PageElements.Label(valore.ToString("N"), 200, 220, 100, 20, Globals.OpenTypeFontVerdanaB, 8, ceTe.DynamicPDF.TextAlign.Right, ceTe.DynamicPDF.CmykColor.Black));

            ////#endregion

            Tabella tabella = new Tabella();
            tabella.LineeTabella = false;
            tabella.Y = document.getLastPos() + 40;
            tabella.X = document.getMargineLeft();
            tabella.Header = true;
            tabella.SaltoPagina = false;
            tabella.AltezzaCella = hCellTab;// 30;
            tabella.Datasource = datitab.table;
            datitab.setHeaderDim(hCellTab);
            datitab.setHeaderFont(sFont);
            tabella.Colonne.Add(new Colonna("Pallino", "Valuta", 40, TipoAllineamento.SINISTRA, false, sFont, false, TipoColonna.IMMAGINE_E_TESTO));
            tabella.Colonne.Add(new Colonna("Bandiera", "", 30, TipoAllineamento.SINISTRA, false, sFont, false, TipoColonna.IMMAGINE_E_TESTO));
            tabella.Colonne.Add(new Colonna("Valuta", "", 100, TipoAllineamento.SINISTRA, false, sFont, false));
            // tabella.Colonne.Add(new Colonna("Peso", "Peso %" + (copertura <100 ? " *" : ""), 80, TipoAllineamento.DESTRA, false, sFont, false));
            tabella.Colonne.Add(new Colonna("Peso", "Peso %", 80, TipoAllineamento.DESTRA, false, sFont, false)); // Modifica Andrea cancellazione asterisco
            tabella.Draw(datitab, document);

            #region Pallini Valute e Bandierine

            float xLabelCtv = document.getMargineLeft();
            float yLabelCtv = document.getLastPos() + 40;



            Dictionary<string, System.Drawing.Color> colori = this.getColorCurrencies();
            System.Drawing.Color colore;
            string pathImage = @UtilityManager.getAppSetting("pathGraf") + @"\Flags\";

            int numSimboli = 21;
            //float yPallino = 0;
            float yPallino = tabella.Y + 7 + numSimboli;
            foreach (DataRow drSimbolo in set.PesiValuteTotali.Rows)
            {

                try
                {
                    if (drSimbolo["VALUTA"].ToString().ToUpper() == "EUR")
                    {
                        colore = colori[drSimbolo["VALUTA"].ToString().ToUpper()];
                    }
                    else
                    {
                        colore = colori["ALTRE"];
                    }
                }
                catch (Exception e)
                {
                    logger.Error(String.Concat("colori", e.Message, dataThread.CodiceFiscale, dataThread.Rete));
                    colore = colori["ALTRE"];
                }
                RgbColor theColor = new RgbColor(colore.R, colore.G, colore.B);

                ceTe.DynamicPDF.PageElements.Circle simboloAI = new ceTe.DynamicPDF.PageElements.Circle(document.getMargineLeft() + 2, yPallino - 5, 8 / 1.414F, theColor, theColor);
                page.Elements.Add(simboloAI);
                try
                {
                    page.Elements.Add(new ceTe.DynamicPDF.PageElements.Image(pathImage + drSimbolo["VALUTA"].ToString() + ".png", document.getMargineLeft() + 25, yPallino - 10, 0.41F));
                }
                catch (Exception e)
                {
                    logger.Error(String.Concat(e.Message, "1", dataThread.CodiceFiscale, dataThread.Rete));
                }
                yPallino += hCellTab;
            }

            #endregion

            #endregion tabella a destra della piramide

            this.addNota1(document, 270, dataThread, copertura);
            //if (copertura< 100)
            //    page.Elements.Add(new ceTe.DynamicPDF.PageElements.Label("(*) Grado di copertura: " + conv.ConvertNum(copertura) + "%", document.getMargineLeft(), yPallino, 180, 10, Globals.OpenTypeFontVerdana, 7));

            document.setLastPos(0);

            #region Grafico a Farfalla

            #region Recupero i valori da assegnare alle serie del grafico

            List<IValoriSerie> listaValoriPesoNegativo = new List<IValoriSerie>();
            List<IValoriSerie> listaValoriPesoPositivo = new List<IValoriSerie>();

            bool presenzaValoriNegativi = false;
            double minValue = 0;
            foreach (DataRow row in set.PesiValuteNegative.Rows)
            {
                IValoriSerie IvaloriSeriePesoNegativo = new IValoriSerie();
                IvaloriSeriePesoNegativo.chiave = row["VALUTA"].ToString();
                IvaloriSeriePesoNegativo.valore = Convert.ToDecimal(row["Peso"]);
                if (IvaloriSeriePesoNegativo.valore > 0)
                    presenzaValoriNegativi = true;
                // ***************** Modifica Andrea aggiunta minimo valore ***********************//
                if (Convert.ToDouble(IvaloriSeriePesoNegativo.valore) > minValue)
                    minValue = Convert.ToDouble(IvaloriSeriePesoNegativo.valore);
                // ******************************************************************************//
                System.Drawing.Color c = colori["ALTRE"];
                try
                {
                    if (IvaloriSeriePesoNegativo.chiave == "EUR")
                    {
                        c = colori[IvaloriSeriePesoNegativo.chiave];
                    }
                    //else
                    //{
                    //    colore = colori["ALTRE"];
                    //}

                    //c = colori[IvaloriSeriePesoNegativo.chiave];
                }
                catch (Exception e)
                {
                    logger.Error(String.Concat(e.Message, " ", IvaloriSeriePesoNegativo.chiave));
                }
                IvaloriSeriePesoNegativo.colore = c;//System.Drawing.Color.FromArgb(Convert.ToInt32(row["Red"]), Convert.ToInt32(row["Green"]), Convert.ToInt32(row["Blue"]));
                listaValoriPesoNegativo.Add(IvaloriSeriePesoNegativo);
            }

            double maxValue = 0;
            //  double minValue = 0;

            foreach (DataRow row in set.PesiValutePositive.Rows)
            {
                IValoriSerie IvaloriSeriePesoPositivo = new IValoriSerie();
                IvaloriSeriePesoPositivo.chiave = row["VALUTA"].ToString();
                IvaloriSeriePesoPositivo.valore = Convert.ToDecimal(row["Peso"]);

                if (Convert.ToDouble(IvaloriSeriePesoPositivo.valore) > maxValue)
                    maxValue = Convert.ToDouble(IvaloriSeriePesoPositivo.valore);
                System.Drawing.Color c = colori["ALTRE"];
                try
                {
                    //c = colori[IvaloriSeriePesoPositivo.chiave];
                    if (IvaloriSeriePesoPositivo.chiave == "EUR")
                    {
                        c = colori[IvaloriSeriePesoPositivo.chiave];
                    }
                }
                catch (Exception e)
                {
                    logger.Error(String.Concat(e.Message, " ", IvaloriSeriePesoPositivo.chiave, dataThread.CodiceFiscale, dataThread.Rete));
                }
                IvaloriSeriePesoPositivo.colore = c;//System.Drawing.Color.FromArgb(Convert.ToInt32(row["Red"]), Convert.ToInt32(row["Green"]), Convert.ToInt32(row["Blue"]));
                listaValoriPesoPositivo.Add(IvaloriSeriePesoPositivo);
            }

            #endregion


            //double altezzaGraficoPesoRischio_Prodotto = 31 * (tabella.Datasource.Rows.Count + 0.5);
            double altezzaGraficoPesoRischio_Prodotto = 24 * (tabella.Datasource.Rows.Count + 0.5);
            //double altezzaGraficoPesoRischio_Prodotto = 180;
            double larghezzaGrafico = 500;

            if (presenzaValoriNegativi)
                if (minValue > 40)
                    larghezzaGrafico = 250;
                else
                    larghezzaGrafico = 500 - minValue * 8;
            //  larghezzaGrafico = 500 - (Convert.ToInt32((minValue + minValue * 0.1) * 5));
            //larghezzaGrafico = 500 - (50 + 2 * (minValue + minValue * 0.1));


            IstoFarfallaS110 graficoPesoRischio_Prodotto = graficoPesoRischio_Prodotto = new IstoFarfallaS110(larghezzaGrafico, altezzaGraficoPesoRischio_Prodotto);
            graficoPesoRischio_Prodotto.DocumentPDF = document;
            graficoPesoRischio_Prodotto.PositionX = 290;
            graficoPesoRischio_Prodotto.PositionY = Convert.ToInt32(tabella.Y + 15);//17
            //graficoPesoRischio_Prodotto.AxisY_LineColor = false;
            graficoPesoRischio_Prodotto.AxisY_Hide = false;
            graficoPesoRischio_Prodotto.AxysX_Increment = Convert.ToDecimal(0.5);

            SerieIstoFarfallaS110 seriePesoNegativo = new SerieIstoFarfallaS110();
            if (presenzaValoriNegativi)
            {

                seriePesoNegativo.Name = "PesoNegativo";
                seriePesoNegativo.Values = listaValoriPesoNegativo;
                seriePesoNegativo.ElementPosition = new Dundas.Charting.WebControl.ElementPosition(1F, -2F, 50.7F, 105F);
                seriePesoNegativo.ReverseAxisY = true;
                seriePesoNegativo.ShowLabelAsValue = false;
                // seriePesoNegativo.AxisY_MaximumValue = 100; // Modifica Andrea
                //seriePesoNegativo.Axisy_Interval = 20;
                //seriePesoNegativo.AxisY_MaximumValue = minValue;
                //seriePesoNegativo.Axisy_Interval = Convert.ToInt64(minValue / 5);
                // seriePesoNegativo.Axisy_Interval = Convert.ToInt64(maxValue / 5);
                if (minValue > 40)
                { 
                seriePesoNegativo.Axisy_Interval = Convert.ToInt64(maxValue / 5);
                seriePesoNegativo.AxisY_MaximumValue = maxValue;
                }
                else { 
                seriePesoNegativo.Axisy_Interval = Convert.ToInt64((minValue) / 2);
                seriePesoNegativo.AxisY_MaximumValue = minValue + minValue * 0.1;
                }
            }

            SerieIstoFarfallaS110 seriePesoPositivo = new SerieIstoFarfallaS110();
            seriePesoPositivo.Name = "PesoPositivo";
            seriePesoPositivo.Values = listaValoriPesoPositivo;
            if (presenzaValoriNegativi)
                // seriePesoPositivo.ElementPosition = new Dundas.Charting.WebControl.ElementPosition(49.3F, -2, 50.7F, 105F);
                if (minValue > 40)
                    seriePesoPositivo.ElementPosition = new Dundas.Charting.WebControl.ElementPosition(49.3F, -2, 50.7F, 105F);
                else
                    seriePesoPositivo.ElementPosition = new Dundas.Charting.WebControl.ElementPosition(Convert.ToInt16(minValue), -2, 50.7F, 105F); //Modifica Andrea
            else
                seriePesoPositivo.ElementPosition = new Dundas.Charting.WebControl.ElementPosition(1F, -2, 50.7F, 105F);
            //seriePesoPositivo.Axisy_Interval = 20;
            seriePesoPositivo.Axisy_Interval = Convert.ToInt64(maxValue / 5);
            if (presenzaValoriNegativi)
                seriePesoPositivo.Axisy_Interval = Convert.ToInt64(maxValue / 5);
            seriePesoPositivo.AxisY_MaximumValue = maxValue; // maxValue + 10 > 100 ? maxValue : maxValue + 10;     // Modifica Andrea 100   
            seriePesoPositivo.ShowLabelAsValue = false;

            if (presenzaValoriNegativi)
                graficoPesoRischio_Prodotto.SerieList.Add(seriePesoNegativo);
            graficoPesoRischio_Prodotto.SerieList.Add(seriePesoPositivo);

            // Disegno il grafico
            graficoPesoRischio_Prodotto.Draw();

            //rettangolo giusto 
            page.Elements.Add(new ceTe.DynamicPDF.PageElements.Rectangle(290.5F, (float)(tabella.Y + altezzaGraficoPesoRischio_Prodotto), wBottRett, hBottRett, RgbColor.LightGrey, RgbColor.LightGrey));

            float passo = 23.5F;
            float passoneg = 0F;
            if (presenzaValoriNegativi)
                passoneg = 40.25F;
            //label negative
            if (presenzaValoriNegativi)
                if (minValue > 40)
                    for (int i = -1; i >= -5; --i)
                        //for (int i = -1; i >= -2; --i)
                        page.Elements.Add(new ceTe.DynamicPDF.PageElements.Label((seriePesoNegativo.Axisy_Interval * i).ToString(), 407.5F + (passo * i), (float)(tabella.Y + altezzaGraficoPesoRischio_Prodotto), wBott, hBott, Globals.OpenTypeFontVerdana, sFont, ceTe.DynamicPDF.TextAlign.Left, ceTe.DynamicPDF.RgbColor.Black));
                else
                    // for (int i = -1; i >= -5; --i)
                    //for (int i = -1; i >= -2; --i)
                    //  //  page.Elements.Add(new ceTe.DynamicPDF.PageElements.Label((seriePesoNegativo.Axisy_Interval * i).ToString(), 407.5F + (passo * i), (float)(tabella.Y + altezzaGraficoPesoRischio_Prodotto), wBott, hBott, Globals.OpenTypeFontVerdana, sFont, ceTe.DynamicPDF.TextAlign.Left, ceTe.DynamicPDF.RgbColor.Black));
                    //     page.Elements.Add(new ceTe.DynamicPDF.PageElements.Label((seriePesoNegativo.Axisy_Interval * i).ToString(), 294.5F + Convert.ToInt16(60 + 2 * minValue + minValue * 0.1) + (passoneg * i), (float)(tabella.Y + altezzaGraficoPesoRischio_Prodotto), wBott, hBott, Globals.OpenTypeFontVerdana, sFont, ceTe.DynamicPDF.TextAlign.Left, ceTe.DynamicPDF.RgbColor.Black));
                    page.Elements.Add(new ceTe.DynamicPDF.PageElements.Label((seriePesoNegativo.Axisy_Interval * -2).ToString(), 294.5F - Convert.ToInt16(0.5 * minValue) + 15, (float)(tabella.Y + altezzaGraficoPesoRischio_Prodotto), wBott, hBott, Globals.OpenTypeFontVerdana, sFont, ceTe.DynamicPDF.TextAlign.Left, ceTe.DynamicPDF.RgbColor.Black));


            if (presenzaValoriNegativi)
                if (minValue > 40)
                    page.Elements.Add(new ceTe.DynamicPDF.PageElements.Label("0", 414.5F, (float)(tabella.Y + altezzaGraficoPesoRischio_Prodotto), wBott, hBott, Globals.OpenTypeFontVerdana, sFont, ceTe.DynamicPDF.TextAlign.Left, ceTe.DynamicPDF.RgbColor.Black));
                else
                    page.Elements.Add(new ceTe.DynamicPDF.PageElements.Label("0", 294.5F + Convert.ToInt16(2.1 * minValue) + 20, (float)(tabella.Y + altezzaGraficoPesoRischio_Prodotto), wBott, hBott, Globals.OpenTypeFontVerdana, sFont, ceTe.DynamicPDF.TextAlign.Left, ceTe.DynamicPDF.RgbColor.Black));

            else
            {
                page.Elements.Add(new ceTe.DynamicPDF.PageElements.Label("0", 294.5F, (float)(tabella.Y + altezzaGraficoPesoRischio_Prodotto), wBott, hBott, Globals.OpenTypeFontVerdana, sFont, ceTe.DynamicPDF.TextAlign.Left, ceTe.DynamicPDF.RgbColor.Black));
                passo *= 2;
            }
            //label positive
            for (int i = 1; i <= 5; ++i)
                if (presenzaValoriNegativi)
                    if (minValue > 40)
                    {
                        for (int j = 1; j <= 4; ++j)
                            page.Elements.Add(new ceTe.DynamicPDF.PageElements.Label((seriePesoPositivo.Axisy_Interval * i).ToString(), 414.5F + (passo * i), (float)(tabella.Y + altezzaGraficoPesoRischio_Prodotto), wBott, hBott, Globals.OpenTypeFontVerdana, sFont, ceTe.DynamicPDF.TextAlign.Left, ceTe.DynamicPDF.RgbColor.Black));

                    }
            else { 
            for (int j = 1; j <= 4; ++j)
                        //  page.Elements.Add(new ceTe.DynamicPDF.PageElements.Label((seriePesoPositivo.Axisy_Interval * i).ToString(), 414.5F + (passo * i), (float)(tabella.Y + altezzaGraficoPesoRischio_Prodotto),wBott , hBott, Globals.OpenTypeFontVerdana, sFont, ceTe.DynamicPDF.TextAlign.Left, ceTe.DynamicPDF.RgbColor.Black));
                        page.Elements.Add(new ceTe.DynamicPDF.PageElements.Label((Convert.ToInt64(maxValue / 5) * j).ToString(), 294.5F + 20 + Convert.ToInt32(2.1 * minValue) + (39F * j), (float)(tabella.Y + altezzaGraficoPesoRischio_Prodotto), wBott, hBott, Globals.OpenTypeFontVerdana, sFont, ceTe.DynamicPDF.TextAlign.Left, ceTe.DynamicPDF.RgbColor.Black));
                    }
                else
                    page.Elements.Add(new ceTe.DynamicPDF.PageElements.Label((seriePesoPositivo.Axisy_Interval * i).ToString(), 294.5F + (passo * i), (float)(tabella.Y + altezzaGraficoPesoRischio_Prodotto), wBott, hBott, Globals.OpenTypeFontVerdana, sFont, ceTe.DynamicPDF.TextAlign.Left, ceTe.DynamicPDF.RgbColor.Black));

            #endregion
        }


        private Dictionary<string, System.Drawing.Color> getColorCurrencies()
        {
            Dictionary<string, System.Drawing.Color> colori = new Dictionary<string, System.Drawing.Color>();
            colori.Add("EUR", System.Drawing.Color.FromArgb(217, 81, 33));
            //colori.Add("USD", System.Drawing.Color.FromArgb(82, 135, 197));
            //colori.Add("CHF", System.Drawing.Color.FromArgb(255, 200, 0));
            //colori.Add("GBP", System.Drawing.Color.FromArgb(255, 0, 255));
            //colori.Add("CNY", System.Drawing.Color.FromArgb(255, 0, 0));
            //colori.Add("JPY", System.Drawing.Color.FromArgb(0, 0, 0));
            colori.Add("ALTRE", System.Drawing.Color.FromArgb(131, 188, 180));



            return colori;

        }
        private void addNota1(DocumentPDF doc, int dim, DataThread dataThread, double copertura)
        {

            decimal totalNegativeCurrentAccountValue = dataThread.Periodico ? dataThread.ContoCorrente : 0;
            decimal GPEligoFondi = dataThread.GPEligoFondi;
            decimal GPEligoTitoli = dataThread.GPEligoTitoli;
            decimal ProdottiNonRapp = dataThread.PatrimonioNonRappresentabileFI;
            decimal PartiteViaggianti = dataThread.PartiteViaggiantiInvestimento;
            //double GradoCopertura = copertura;
            decimal valore = dataThread.PatrimonioBancaFideuramCtvAlNettoContoCorrente + dataThread.PartiteViaggiantiInvestimento + dataThread.PartiteViaggiantiDisinvestimento + dataThread.PatrimonioNonRappresentabileFI;
            decimal GradoCopertura = (dataThread.PatrimonioBancaFideuramCtvAlNettoContoCorrente - dataThread.PatrimonioNonRappresentabileFI) / valore * 100;
            List<string> notes = new List<string>();



            string nota = string.Empty;
            string nota1 = "";
            string token = "";



            //totalNegativeCurrentAccountValue = -1000.00M;
            //totaleSelfNegFO = -1000.00M;
            //totalePartiteViaggianti = 1000.00M;
            //GPEligoFondi = -500.00M;
            //GPEligoTitoli = -500.00M;
            //PatrimonioTerzi = -400.00M;
            //GradoCopertura = 70.00M;
            //PatrimonioTerziNonRapp = 100.00M;
            //ProdottiNonRapp = 20.00M;


            if (totalNegativeCurrentAccountValue != 0 || GPEligoFondi < 0 || GPEligoTitoli < 0 || ((GradoCopertura >= 0 && GradoCopertura < 100) && (ProdottiNonRapp != 0 || PartiteViaggianti != 0)))
            {
                nota = "(*) ";
            }

            if (totalNegativeCurrentAccountValue != 0 || GPEligoFondi < 0 || GPEligoTitoli < 0)
            {
                notes.Add("Il controvalore esclude il saldo negativo");
                token = " ";

                if (totalNegativeCurrentAccountValue < 0)
                {
                    notes.Add(string.Format(token + "dei conti correnti ({0} €)", totalNegativeCurrentAccountValue.ToString("N")));
                    token = ", ";
                }

                if (GPEligoFondi < 0)
                {
                    notes.Add(string.Format(token + "della liquidità sottostante GP Eligo Fondi ({0} €)", GPEligoFondi.ToString("N")));
                    token = ", ";
                }

                if (GPEligoTitoli < 0)
                {
                    notes.Add(string.Format(token + "della liquidità sottostante GP Eligo Titoli ({0} €)", GPEligoTitoli.ToString("N")));
                    token = ", ";
                }
                token = ". ";

            }
            if (ProdottiNonRapp != 0 || PartiteViaggianti != 0)
            {
                if (GradoCopertura >= 0 && GradoCopertura < 100)
                {
                    notes.Add(string.Format(token + "Grado di copertura (%) della rappresentazione grafica per esposizione valutaria pari a {0}", GradoCopertura.ToString("N")));
                    token = ": ";

                    if (ProdottiNonRapp != 0 || PartiteViaggianti != 0)
                    {
                        notes.Add(string.Format(token + "non sono considerati"));
                        token = " ";
                        if (ProdottiNonRapp != 0 || PartiteViaggianti != 0)
                        {
                            if (ProdottiNonRapp != 0)
                            {
                                notes.Add(string.Format(token + "i prodotti non rappresentabili ({0} €)", ProdottiNonRapp.ToString("N")));
                                token = ", ";
                            }
                            if (PartiteViaggianti != 0)
                            {
                                notes.Add(string.Format(token + "gli importi relativi alle operazioni in corso ({0} €)", PartiteViaggianti.ToString("N")));
                                token = ", ";
                            }
                        }
                    }
                    notes.Add(string.Format("."));
                }
            }
            nota1 += ".";
            token = " ";

            //int i = 0;
            nota += notes.FirstOrDefault<string>();
            if (notes.Count > 1)
            {
                foreach (var s in notes.Skip(1))
                {
                    nota += s;

                    //if (i == 0)
                    // nota += s;
                    //if (i > 0 && i < notes.Count - 1)
                    // nota += ", " + s;
                    //if (i == notes.Count - 1)
                    // nota += " e " + s;
                    //i++;
                }
            }
            //else
            //    nota += notes.FirstOrDefault<string>();

            if (!nota.Equals(""))
                //document.getCurrentPage().Elements.Add(new Label(nota, Xtable, Ytable, 512, 30F, Globals.OpenTypeFontVerdana, 7));
                doc.setSezFooter(nota, dim - 15);
        }
    }
}