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 ContrattoSei.Utilities;

namespace PDFGenerator.Presentation.Section
{
    class S177 : ISezione
    {


        private string _header = "";
        string _testotitolo;

        public string Header
        {
            get { return _header; }
            set { _header = value; }
        }


        private TipoReport _tipologiaReport;
        public TipoReport TipologiaReport
        {
            get { return _tipologiaReport; }
            set { _tipologiaReport = value; }
        }

        private string _testoIntroduttivo = string.Empty;
        public string TestoIntroduttivo
        {
            get { return _testoIntroduttivo; }
            set { _testoIntroduttivo = value; }
        }

        private string _testoChiusura = string.Empty;
        public string TestoChiusura
        {
            get { return _testoChiusura; }
            set { _testoChiusura = value; }
        }

        /// <summary>
        /// Testo del titolo della sezione.
        /// </summary>
        public string TestoTitolo
        {
            get
            {
                return _testotitolo;
            }
            set
            {
                _testotitolo = value;
            }
        }


        public S177()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        #region ISezione Members

        public void writeSezione(DataThread dataThread)
        {

            DocumentPDF document = dataThread.DocumentPDF;
            DataSetS177 set = (DataSetS177)dataThread.Data.DatiSezione;

            //document.setSezTitolo(dataThread.SezioneReport.Titolo);
            //document.setChapterHeader(dataThread.SezioneReport.TestoIntroduttivo, 0, 520, 8);

            document.setSezTitoloDiagnosi(dataThread.SezioneReport.Titolo, "S177");

            //MIFID2 20180709 Modifica testo introduttivo
            // string tempTesto = dataThread.SezioneReport.TestoIntroduttivo;
            /* PEr Test Pino*/
            string tempTesto = dataThread.IsProffesionalClient ? dataThread.SezioneReport.TestoIntroduttivoAlternativo : dataThread.SezioneReport.TestoIntroduttivo;
            //--MIFID2

            //if (dataThread.Rete.ToUpper() == "S")
            //    tempTesto = tempTesto.Replace("Fideuram", "Sanpaolo Invest");

            //document.setChapterHeader(tempTesto.Replace("$/Banca/$", dataThread.NomeRete), 0, 520, 8);
            document.setChapterHeader(tempTesto.Replace("$/Banca/$", dataThread.NomeRete).Replace("Sanpaolo Invest", "Fideuram S.p.A., tramite la rete di private banker Sanpaolo Invest,"), 0, 520, 8, "S177", dataThread.TipoReport);



            #region profilofinanziario
            DatiTabella profilofinanziarioDatiTab = new DatiTabella();
            profilofinanziarioDatiTab.table = set.Tables["Profilofinanziario"];
            profilofinanziarioDatiTab.setIsLinee(1);
            //profilofinanziarioDatiTab.setCell(175, ceTe.DynamicPDF.TextAlign.Left, Globals.OpenTypeFontVerdanaB, true);
            //profilofinanziarioDatiTab.setCell(308, ceTe.DynamicPDF.TextAlign.Left, Globals.OpenTypeFontVerdana, false);
            profilofinanziarioDatiTab.setCell(190, ceTe.DynamicPDF.TextAlign.Left, Globals.OpenTypeFontVerdanaB, true);
            profilofinanziarioDatiTab.setCell(320, ceTe.DynamicPDF.TextAlign.Left, Globals.OpenTypeFontVerdana, false, 8); //273
            profilofinanziarioDatiTab.setX(document.getMargineLeft());
            Tabella profilofinanziarioTab = new Tabella();
            if (dataThread.TipoReport.ToUpper() == "DIAGNOSI") profilofinanziarioTab.HeaderFont = 8;
            profilofinanziarioTab.LineaFineTabella = true;
            //profilofinanziarioTab.
            #endregion



            //AdeguatezzaDatiTab.setY(document.getLastPos() + 30);

            #region ProfiloDate
            DatiTabella ProfiloDateDatiTab = new DatiTabella();
            ProfiloDateDatiTab.table = set.Tables["ProfiloDate"];
            //ProfiloDateDatiTab.table = set.Tables["ProfiloDate"].AsEnumerable().Where(d=>d.Field<string>("Descrizione")== "Data inizio validità del profilo").CopyToDataTable();
            ProfiloDateDatiTab.setIsLinee(1);
            //ProfiloDateDatiTab.setCell(175, ceTe.DynamicPDF.TextAlign.Left, Globals.OpenTypeFontVerdanaB, true);
            //ProfiloDateDatiTab.setCell(308, ceTe.DynamicPDF.TextAlign.Left, Globals.OpenTypeFontVerdana, false);
            ProfiloDateDatiTab.setCell(190, ceTe.DynamicPDF.TextAlign.Left, Globals.OpenTypeFontVerdanaB, true);
            ProfiloDateDatiTab.setCell(65, ceTe.DynamicPDF.TextAlign.Left, Globals.OpenTypeFontVerdana, false, 8);
            ProfiloDateDatiTab.setCell(190, ceTe.DynamicPDF.TextAlign.Left, Globals.OpenTypeFontVerdanaB, true); //273
            ProfiloDateDatiTab.setCell(65, ceTe.DynamicPDF.TextAlign.Left, Globals.OpenTypeFontVerdana, false, 8); //273
            ProfiloDateDatiTab.setX(document.getMargineLeft());
            Tabella ProfiloDateTab = new Tabella();
            if (dataThread.TipoReport.ToUpper() == "DIAGNOSI") ProfiloDateTab.HeaderFont = 8;
            ProfiloDateTab.LineaFineTabella = true;
            #endregion



            #region Adeguatezza: riserva e investimento lungo periodo
            DatiTabella AdeguatezzaDatiTab = new DatiTabella();
            AdeguatezzaDatiTab.table = set.Tables["Adeguatezza"];
            //ProfiloDateDatiTab.table = set.Tables["ProfiloDate"].AsEnumerable().Where(d=>d.Field<string>("Descrizione")== "Data inizio validità del profilo").CopyToDataTable();
            AdeguatezzaDatiTab.setIsLinee(1);
            //ProfiloDateDatiTab.setCell(175, ceTe.DynamicPDF.TextAlign.Left, Globals.OpenTypeFontVerdanaB, true);
            //ProfiloDateDatiTab.setCell(308, ceTe.DynamicPDF.TextAlign.Left, Globals.OpenTypeFontVerdana, false);
            AdeguatezzaDatiTab.setCell(190, ceTe.DynamicPDF.TextAlign.Left, Globals.OpenTypeFontVerdanaB, true);
            AdeguatezzaDatiTab.setCell(65, ceTe.DynamicPDF.TextAlign.Left, Globals.OpenTypeFontVerdana, false, 8);
            AdeguatezzaDatiTab.setCell(190, ceTe.DynamicPDF.TextAlign.Left, Globals.OpenTypeFontVerdanaB, true); //273
            AdeguatezzaDatiTab.setCell(65, ceTe.DynamicPDF.TextAlign.Left, Globals.OpenTypeFontVerdana, false, 8); //273
            AdeguatezzaDatiTab.setX(document.getMargineLeft());
            Tabella AdeguatezzaDateTab = new Tabella();
            if (dataThread.TipoReport.ToUpper() == "DIAGNOSI") AdeguatezzaDateTab.HeaderFont = 8;
            AdeguatezzaDateTab.LineaFineTabella = true;

            //AdeguatezzaDatiTab.setY(document.getLastPos());

            #endregion

            var currentY = document.getLastPos() - 8;

            profilofinanziarioDatiTab.SetRowDim(30);
            profilofinanziarioDatiTab.setY(currentY);
            document.InsertTable(profilofinanziarioTab.getTabella(profilofinanziarioDatiTab));

            //float ydatitab = document.getLastPos() + profilofinanziarioDatiTab.getNumRow() * profilofinanziarioDatiTab.GetRowDim();
            //datitab.setY(ydatitab);

            //float yAdeguatezza = currentY + 15;


            currentY = currentY + 24;
            //float yProfiloDateDatiTab = yAdeguatezza + 30;
            //ProfiloDateDatiTab.SetRowDim(30);
            ProfiloDateDatiTab.setY(currentY);

            //float yFooter = yProfiloDateDatiTab + ProfiloDateDatiTab.getNumRow() * ProfiloDateDatiTab.GetRowDim() ;
            //float yFooter = ProfiloDateDatiTab.GetRowDim() * 3;
            float yFooter = (ProfiloDateDatiTab.GetRowDim() * (float)2.8);
            //float yFooter = (ProfiloDateDatiTab.GetRowDim());


            ceTe.DynamicPDF.Merger.ImportedPage page = document.getCurrentPage();

            //string relativePath = UtilityManager.getAppSetting("Slider");
            //System.Reflection.Assembly thisExe;
            //thisExe = System.Reflection.Assembly.GetExecutingAssembly();
            //System.IO.Stream fileSlider = thisExe.GetManifestResourceStream(relativePath);
            //page.Elements.Add(new ceTe.DynamicPDF.PageElements.Image(fileSlider, 57 + 150 + 85 + 25, document.getLastPos() + datitab.GetRowDim() * 0.7F, 0.25F));

            //datitab.setY(document.getLastPos());
            //relativePath = UtilityManager.getAppSetting("SliderRischioCredito");
            //System.IO.Stream fileRischioCreditoSlider = thisExe.GetManifestResourceStream(relativePath);
            //page.Elements.Add(new ceTe.DynamicPDF.PageElements.Image(fileRischioCreditoSlider, 57 + 150 + 85 + 25, document.getLastPos() + datitab.GetRowDim() * 0.7F + datitab.GetRowDim(), 0.25F));
            //relativePath = UtilityManager.getAppSetting("MarkerLarge");
            //System.IO.Stream fileMarker = thisExe.GetManifestResourceStream(relativePath);

            //float VaRMassimo = Convert.ToSingle(datitab.table.Rows[0]["Valore"]);
            //float xMarker = getX(VaRMassimo.ToString());
            //float yMarker = document.getLastPos() + datitab.GetRowDim() * 0.7F;

            decimal totalePartiteViaggianti = dataThread.PartiteViaggiantiInvestimento + dataThread.PartiteViaggiantiDisinvestimento;
            FormatNum conv = new FormatNum();
            #region IMPORTANT COMMENTI

            //IMPORTANT
            //V When doing S95 Remove from here and make the right value into the DSS95 

            //datitab.table.Rows[0]["Valore"] = conv.ConvertNum(Convert.ToDouble(datitab.table.Rows[0]["Valore"])) + "%";

            //MIFID2 20180503 Eliminate note
            //if (dataThread.ReportType().TipoReport == TipoReport.MONITORAGGIO)
            //{
            //    string note = string.Empty;
            //    //note = getExperinceLevel(datitab.table.Rows[2]["Valore"].ToString(), dataThread.NomeRete);

            //    //datitab.table.Rows[2].Delete();
            //    //document.InsertTable(tab.getTabella(datitab));

            //    document.InsertTable(ProfiloDateTab.getTabella(ProfiloDateDatiTab));

            //    if (dataThread.TotalNegativeCurrentAccountValue >= 0 && totalePartiteViaggianti == 0)
            //    {
            //        #region TOTALE PATRIMONIO
            //        page.Elements.Add(new ceTe.DynamicPDF.PageElements.Label(string.Format(Resource.S95_NotaOperazioniInCorsZero, dataThread.NomeRete), ProfiloDateDatiTab.getX(), document.getLastPos() + ProfiloDateDatiTab.GetRowDim() * 4, 500F, 30F, Globals.OpenTypeFontVerdana, 8));

            //        DatiTabella totalitab = new DatiTabella();
            //        totalitab.table = set.Tables["Totali"];

            //        Tabella tabellaTotale = new Tabella(document.getMargineLeft(), document.getLastPos() + ProfiloDateDatiTab.GetRowDim() * 7);
            //        if (dataThread.TipoReport.ToUpper() == "DIAGNOSI") tabellaTotale.HeaderFont = 8;
            //        tabellaTotale.SaltoPagina = false;
            //        tabellaTotale.Header = false;

            //        tabellaTotale.Colonne.Add(new Colonna("Descrizione", "", 130, TipoAllineamento.SINISTRA, true, 9, true));
            //        tabellaTotale.Colonne.Add(new Colonna("Controvalore", "", 150, TipoAllineamento.DESTRA, true, 9, true));

            //        tabellaTotale.Draw(totalitab, document);

            //        document.setSezFooter(string.Format(Resource.S95_Monitoring_Note, dataThread.NomeRete) + " " + note, ProfiloDateDatiTab.GetRowDim() * 6 + totalitab.GetRowDim(), 0, 9);

            //        #endregion
            //    }
            //    else if (dataThread.TotalNegativeCurrentAccountValue < 0 && totalePartiteViaggianti == 0)
            //    {
            //        page.Elements.Add(new ceTe.DynamicPDF.PageElements.Label(string.Format(Resource.S95_NotaOperazioniInCorsoZero_CCNegativo, dataThread.NomeRete), ProfiloDateDatiTab.getX(), document.getLastPos() + ProfiloDateDatiTab.GetRowDim() * 4, 500F, 30F, Globals.OpenTypeFontVerdana, 8));
            //        page.Elements.Add(new ceTe.DynamicPDF.PageElements.Line(document.getMargineLeft() - 5, document.getLastPos() + ProfiloDateDatiTab.GetRowDim() * 4 + 30, document.getMargineLeft() + 285, document.getLastPos() + ProfiloDateDatiTab.GetRowDim() * 4 + 30, 2F, new RgbColor(232, 236, 237)));

            //        DatiTabella ctvdatitab = new DatiTabella();
            //        ctvdatitab.table = set.Tables["Dati"];

            //        Tabella tabellaDati = new Tabella(document.getMargineLeft(), document.getLastPos() + ProfiloDateDatiTab.GetRowDim() * 7);
            //        if (dataThread.TipoReport.ToUpper() == "DIAGNOSI") tabellaDati.HeaderFont = 8;
            //        tabellaDati.DimensioneLinea = 2;

            //        tabellaDati.Colonne.Add(new Colonna("Descrizione", "", 130, TipoAllineamento.SINISTRA, false, 8, false));
            //        tabellaDati.Colonne.Add(new Colonna("Controvalore", "", 150, TipoAllineamento.DESTRA, false, 8, false));

            //        tabellaDati.Draw(ctvdatitab, document);

            //        DatiTabella totalitab = new DatiTabella();
            //        totalitab.table = set.Tables["Totali"];

            //        //Tabella tabellaTotale = new Tabella(document.getMargineLeft(), document.getLastPos() + ProfiloDateDatiTab.GetRowDim() * 7 + datitab.GetRowDim() * 2);
            //        Tabella tabellaTotale = new Tabella(document.getMargineLeft(), document.getLastPos() + ProfiloDateDatiTab.GetRowDim() * 7);

            //        if (dataThread.TipoReport.ToUpper() == "DIAGNOSI") tabellaTotale.HeaderFont = 8;
            //        tabellaTotale.Colonne.Add(new Colonna("Descrizione", "", 130, TipoAllineamento.SINISTRA, true, 9, true));
            //        tabellaTotale.Colonne.Add(new Colonna("Controvalore", "", 150, TipoAllineamento.DESTRA, true, 9, true));

            //        tabellaTotale.Draw(totalitab, document);

            //        //document.setSezFooter(string.Format(Resource.S95_Monitoring_Note, dataThread.NomeRete) + " " + note, ProfiloDateDatiTab.GetRowDim() * 6 + datitab.GetRowDim() * 2 + totalitab.GetRowDim(), 0, 9);
            //        document.setSezFooter(string.Format(Resource.S95_Monitoring_Note, dataThread.NomeRete) + " " + note, ProfiloDateDatiTab.GetRowDim() * 6 + totalitab.GetRowDim(), 0, 9);
            //    }
            //    else if (dataThread.TotalNegativeCurrentAccountValue < 0 && totalePartiteViaggianti != 0)
            //    {
            //        page.Elements.Add(new ceTe.DynamicPDF.PageElements.Label(string.Format(Resource.S95_NotaOperazioniInCorsoNotZero_CCNegativo, dataThread.NomeRete), ProfiloDateDatiTab.getX(), document.getLastPos() + ProfiloDateDatiTab.GetRowDim() * 4, 500F, 30F, Globals.OpenTypeFontVerdana, 8));
            //        page.Elements.Add(new ceTe.DynamicPDF.PageElements.Line(document.getMargineLeft() - 5, document.getLastPos() + ProfiloDateDatiTab.GetRowDim() * 4 + 30, document.getMargineLeft() + 285, document.getLastPos() + ProfiloDateDatiTab.GetRowDim() * 4 + 30, 2F, new RgbColor(232, 236, 237)));

            //        DatiTabella ctvdatitab = new DatiTabella();
            //        ctvdatitab.table = set.Tables["Dati"];

            //        Tabella tabellaDati = new Tabella(document.getMargineLeft(), document.getLastPos() + ProfiloDateDatiTab.GetRowDim() * 7);
            //        if (dataThread.TipoReport.ToUpper() == "DIAGNOSI") tabellaDati.HeaderFont = 8;
            //        tabellaDati.DimensioneLinea = 2;

            //        tabellaDati.Colonne.Add(new Colonna("Descrizione", "", 130, TipoAllineamento.SINISTRA, false, 9, false));
            //        tabellaDati.Colonne.Add(new Colonna("Controvalore", "", 150, TipoAllineamento.DESTRA, false, 9, false));

            //        tabellaDati.Draw(ctvdatitab, document);

            //        DatiTabella totalitab = new DatiTabella();
            //        totalitab.table = set.Tables["Totali"];

            //        //Tabella tabellaTotale = new Tabella(document.getMargineLeft(), document.getLastPos() + ProfiloDateDatiTab.GetRowDim() * 7 + datitab.GetRowDim() * 3);
            //        Tabella tabellaTotale = new Tabella(document.getMargineLeft(), document.getLastPos() + ProfiloDateDatiTab.GetRowDim() * 7 );
            //        if (dataThread.TipoReport.ToUpper() == "DIAGNOSI") tabellaTotale.HeaderFont = 8;
            //        tabellaTotale.Colonne.Add(new Colonna("Descrizione", "", 130, TipoAllineamento.SINISTRA, true, 9, true));
            //        tabellaTotale.Colonne.Add(new Colonna("Controvalore", "", 150, TipoAllineamento.DESTRA, true, 9, true));

            //        tabellaTotale.Draw(totalitab, document);

            //        //document.setSezFooter(string.Format(Resource.S95_Monitoring_Note, dataThread.NomeRete) + " " + note, ProfiloDateDatiTab.GetRowDim() * 6 + datitab.GetRowDim() * 3 + totalitab.GetRowDim(), 0, 9);
            //        document.setSezFooter(string.Format(Resource.S95_Monitoring_Note, dataThread.NomeRete) + " " + note, ProfiloDateDatiTab.GetRowDim() * 6 + totalitab.GetRowDim(), 0, 9);
            //    }
            //    else if (dataThread.TotalNegativeCurrentAccountValue == 0 && totalePartiteViaggianti != 0)
            //    {
            //        page.Elements.Add(new ceTe.DynamicPDF.PageElements.Label(string.Format(Resource.S95_NotaOperazioniInCorsoNotZero_CCNegativo, dataThread.NomeRete), ProfiloDateDatiTab.getX(), document.getLastPos() + ProfiloDateDatiTab.GetRowDim() * 4, 500F, 30F, Globals.OpenTypeFontVerdana, 8));
            //        page.Elements.Add(new ceTe.DynamicPDF.PageElements.Line(document.getMargineLeft() - 5, document.getLastPos() + ProfiloDateDatiTab.GetRowDim() * 4 + 30, document.getMargineLeft() + 285, document.getLastPos() + ProfiloDateDatiTab.GetRowDim() * 4 + 30, 2F, new RgbColor(232, 236, 237)));

            //        DatiTabella ctvdatitab = new DatiTabella();
            //        ctvdatitab.table = set.Tables["Dati"];

            //        Tabella tabellaDati = new Tabella(document.getMargineLeft(), document.getLastPos() + ProfiloDateDatiTab.GetRowDim() * 7);
            //        if (dataThread.TipoReport.ToUpper() == "DIAGNOSI") tabellaDati.HeaderFont = 8;
            //        tabellaDati.DimensioneLinea = 2;

            //        tabellaDati.Colonne.Add(new Colonna("Descrizione", "", 130, TipoAllineamento.SINISTRA, false, 9, false));
            //        tabellaDati.Colonne.Add(new Colonna("Controvalore", "", 150, TipoAllineamento.DESTRA, false, 9, false));

            //        tabellaDati.Draw(ctvdatitab, document);

            //        DatiTabella totalitab = new DatiTabella();
            //        totalitab.table = set.Tables["Totali"];

            //        //Tabella tabellaTotale = new Tabella(document.getMargineLeft(), document.getLastPos() + ProfiloDateDatiTab.GetRowDim() * 7 + datitab.GetRowDim() * 2);
            //        Tabella tabellaTotale = new Tabella(document.getMargineLeft(), document.getLastPos() + ProfiloDateDatiTab.GetRowDim() * 7 );
            //        if (dataThread.TipoReport.ToUpper() == "DIAGNOSI") tabellaTotale.HeaderFont = 8;
            //        tabellaTotale.Colonne.Add(new Colonna("Descrizione", "", 130, TipoAllineamento.SINISTRA, true, 9, true));
            //        tabellaTotale.Colonne.Add(new Colonna("Controvalore", "", 150, TipoAllineamento.DESTRA, true, 9, true));

            //        tabellaTotale.Draw(totalitab, document);

            //        //document.setSezFooter(string.Format(Resource.S95_Monitoring_Note, dataThread.NomeRete) + " " + note, ProfiloDateDatiTab.GetRowDim() * 6 + datitab.GetRowDim() * 2 + totalitab.GetRowDim(), 0, 9);
            //        document.setSezFooter(string.Format(Resource.S95_Monitoring_Note, dataThread.NomeRete) + " " + note, ProfiloDateDatiTab.GetRowDim() * 6 + totalitab.GetRowDim(), 0, 9);
            //    }
            //}
            //else
            //{
            //    //datitab.table.Rows[2].Delete();
            //    //document.InsertTable(tab.getTabella(datitab));

            //    document.InsertTable(ProfiloDateTab.getTabella(ProfiloDateDatiTab));

            //}
            #endregion
            document.InsertTable(ProfiloDateTab.getTabella(ProfiloDateDatiTab));
            //--MIFID2


            //Inserimento Tabella Adeguatezza
            currentY = currentY + 24;
            AdeguatezzaDatiTab.setY(currentY);
            document.InsertTable(AdeguatezzaDateTab.getTabella(AdeguatezzaDatiTab));

            #region ProfiloRischio
            //MIFID2 Va inserita, sia per Diagnosi, sia per Monitoraggio, la riga relativa al livello di esperienza, eccetto per i clienti Professionali
            //DatiTabella datitab = new DatiTabella();
            //datitab.table = set.Tables["ProfiloRischio"];
            //datitab.setIsLinee(1);
            //datitab.setCell(165, ceTe.DynamicPDF.TextAlign.Left, Globals.OpenTypeFontVerdanaB, true);
            //datitab.setCell(273, ceTe.DynamicPDF.TextAlign.Left, Globals.OpenTypeFontVerdana, false);
            //datitab.setX(document.getMargineLeft() + 45);
            //Tabella tab = new Tabella();
            //if (dataThread.TipoReport.ToUpper() == "DIAGNOSI") tab.HeaderFont = 8;
            //tab.LineaFineTabella = true;

            //Leone : nuovi requisiti 09/05/2023
            //if (!dataThread.IsProffesionalClient)
            //{
            DatiTabella ProfiloRischioDatiTab = new DatiTabella();

            // $$$ Modifica per Aggiunta Nota
            string nota2b = "";
            if (!set.Tables["ProfiloRischio"].Rows[2]["Valore"].ToString().Equals("-"))
            {

                //MIFID2 CR Napolitano: inserita nuova nota relativa al Limite Massimo Complessità per le persone giuridiche con delegati profilati
                if (!dataThread.IsProffesionalClient && dataThread.Flagpg.Equals(1) && dataThread.Flagnqp.Equals("S") && dataThread.Flagprlrde.Equals("S"))
                {
                    string ast = "*";
                    set.Tables["ProfiloRischio"].Rows[3]["Valore"] += ast;
                    nota2b = string.Format("({0}) Livello di Esperienza e Conoscenza più alto tra quelli associati ai singoli Legali Rappresentanti/Delegati profilati", ast);
                }
            }
            // Fine Modifica

            ProfiloRischioDatiTab.table = set.Tables["ProfiloRischio"].AsEnumerable().Where(
                x => x.Field<string>("Descrizione").ToLower().Equals("livello di esperienza e conoscenza in materia di investimenti")
                ).CopyToDataTable();

            ProfiloRischioDatiTab.setIsLinee(1);
            //ProfiloRischioDatiTab.setCell(175, ceTe.DynamicPDF.TextAlign.Left, Globals.OpenTypeFontVerdanaB, true);
            //ProfiloRischioDatiTab.setCell(308, ceTe.DynamicPDF.TextAlign.Left, Globals.OpenTypeFontVerdana, false);
            ProfiloRischioDatiTab.setCell(190, ceTe.DynamicPDF.TextAlign.Left, Globals.OpenTypeFontVerdanaB, true);
            //ProfiloRischioDatiTab.setCell(273, ceTe.DynamicPDF.TextAlign.Left, Globals.OpenTypeFontVerdana, false);
            ProfiloRischioDatiTab.setCell(320, ceTe.DynamicPDF.TextAlign.Left, Globals.OpenTypeFontVerdana, false, 8);
            ProfiloRischioDatiTab.setX(document.getMargineLeft());
            Tabella ProfiloRischioTab = new Tabella();
            if (dataThread.TipoReport.ToUpper() == "DIAGNOSI") ProfiloRischioTab.HeaderFont = 8;
            ProfiloRischioTab.LineaFineTabella = true;
            //ProfiloRischioDatiTab.SetRowDim(30);
            //ProfiloRischioDatiTab.SetRowDim(30);
            //ProfiloRischioDatiTab.setY(document.getLastPos() + profilofinanziarioDatiTab.getNumRow() * profilofinanziarioDatiTab.GetRowDim()+ProfiloDateDatiTab.getNumRow() * ProfiloDateDatiTab.GetRowDim());
            currentY = currentY + 24;
            ProfiloRischioDatiTab.setY(currentY);
            document.InsertTable(ProfiloRischioTab.getTabella(ProfiloRischioDatiTab));

            yFooter += ProfiloRischioDatiTab.GetRowDim();

            // $$$ Modifica per Aggiunta Nota
            if (!string.IsNullOrEmpty(nota2b))
            {
                document.writeText(document.getMargineLeft(), document.getLastPos() + yFooter - 20, nota2b, 6, 520, ceTe.DynamicPDF.TextAlign.Justify);
            }
            // Fine Modifica

            //}
            //--MIFID2

            #endregion

            //page.Elements.Add(new ceTe.DynamicPDF.PageElements.Image(fileMarker, xMarker, yMarker , 0.25F));

            //document.setLastPos(yFooter);
            //document.setLastPos(yFooter - 20);
            document.setLastPos(yFooter - 25);
        }

        #endregion

        /// <summary>
        /// Ritorna la x sulla quale andrà posizionato il marker (barra nera) in funzione del VaR massimo del profilo.
        /// Il posizionamento della x in questa sezione è fisso e non graduale.
        /// La funzione è valida per le fasce di profilo 1.5 , 3.5 , 7.5 , 12 , 23
        /// </summary>
        /// <param name="varmassimo">var massimo del profilo</param>
        /// <returns></returns>
        private float getX(string varmassimo)
        {
            float xPartenza = 292;
            if (varmassimo == SoglieVar.sVar1) return xPartenza + 7 + 25;
            if (varmassimo == SoglieVar.sVar2) return xPartenza + 21 + 25;
            if (varmassimo == SoglieVar.sVar3) return xPartenza + 42 + 25;
            if (varmassimo == SoglieVar.sVar4) return xPartenza + 70 + 25;
            if (varmassimo == SoglieVar.sVar5 || varmassimo == "50" || varmassimo == "50,00") return xPartenza + 107 + 25;
            return xPartenza;
        }




        /// <summary>
        /// Return the Experince Level depending on the passed value 
        /// <Owner> Marian Zaki</Owner>
        /// <Date> 04052010 </Date>
        /// </summary>
        /// <param name="experinceLevel">
        ///     case 1: low
        ///     case 2: medium
        ///     case 3: high
        /// </param>
        /// <returns> The footer note depend on the experince level </returns>
        private string getExperinceLevel(string experinceLevel, string reteName)
        {
            int experinceLevelValue;
            string experinceLevelName = string.Empty;
            if (int.TryParse(experinceLevel, out experinceLevelValue))
            {

                switch (experinceLevel)
                {
                    case "1":
                        //experinceLevelName = Resource.S95_Monitoring_Note_ExperinceLevel_Low;
                        experinceLevelName = string.Format(Resource.S95_Monitoring_Note_ExperinceLevel_Low, reteName);
                        break;
                    case "2":
                        //experinceLevelName = Resource.S95_Monitoring_Note_ExperinceLevel_Medium;
                        experinceLevelName = string.Format(Resource.S95_Monitoring_Note_ExperinceLevel_Medium, reteName);
                        break;
                    case "3":
                        //experinceLevelName = Resource.S95_Monitoring_Note_ExperinceLevel_High;
                        experinceLevelName = string.Format(Resource.S95_Monitoring_Note_ExperinceLevel_High, reteName);
                        break;
                    default:
                        experinceLevelName = string.Empty;
                        break;

                }

                return experinceLevelName;
            }
            else
                return string.Empty;
        }
    }
}