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;

namespace PDFGenerator.Presentation.Section
{
    public class S156 : ISezione
    {

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

        #region ISezione Members

        public void writeSezione(DataThread dataThread)
        {
            DocumentPDF document = dataThread.DocumentPDF;

            DatiTabella datitab = new DatiTabella();
            DataSetS156 set = (DataSetS156)dataThread.Data.DatiSezione;
            datitab.table = set.Tables["Patrimonio"];

            datitab.setY(document.getLastPos());
            datitab.setIsLinee(1);
            datitab.setHeader();
            datitab.setCell(140, ceTe.DynamicPDF.TextAlign.Left, Globals.OpenTypeFontVerdana, false);
            datitab.setCell(170, ceTe.DynamicPDF.TextAlign.Right, Globals.OpenTypeFontVerdana, false);
            datitab.setCell(200, ceTe.DynamicPDF.TextAlign.Right, Globals.OpenTypeFontVerdana, false);

            //eventuali operazioni sul dataset
            //calcola se entra nella pagina altrimenti aggiunge una nuova pagina.
            //if (document.checkMargin(datitab.GetRowDim() * (datitab.getNumRow() + 1))) document.addPage();
            /***************** Fix Trimestrale Report Diagnosi 15/07/2020 - Pino **************/
            //if (document.checkMargin(130))   //*** Originale***/
            if (document.checkMargin(document.getLastPos()))
                document.addPage();
            //********************************************************************************/

            //aggiorna l'indice
            //if (dataThread.TipoReport.ToUpper() == "DIAGNOSI")
            //    document.setSezTitoloDiagnosi(dataThread.SezioneReport.Titolo);
            //else
            document.setSezTitolo(dataThread.SezioneReport.Titolo);
            document.setChapterHeader(dataThread.SezioneReport.TestoIntroduttivo, 0, 520, 8);
            //document.setChapterHeader("Di seguito si riportano i dati relativi alle ulteriori proprietà che concorrono a determinare il suo patrimonio.", 0, 520, 8);
            //document.setSezHeader("Di seguito si riportano i dati relativi alle ulteriori proprietà che concorrono a determinare il suo patrimonio.");
            //document.page.Elements.Add(new ceTe.DynamicPDF.PageElements.Label(s, xMacroAsset + width, yLabel, (float)Convert.ToDouble(dati.campi[i]), heightLabel, (ceTe.DynamicPDF.Font)dati.font[i], fontSize, (ceTe.DynamicPDF.TextAlign)dati.align[i], ceTe.DynamicPDF.CmykColor.Black));

            datitab.setY(document.getLastPos());
            datitab.setX(document.getMargineLeft());
            datitab.setCellSpace(0);

            /***************** Fix Trimestrale Report Diagnosi 15/07/2020 - Pino **************/
            //Tabella tab = new Tabella();  //*** Originale***/
            Tabella tab = new Tabella(document.getMargineLeft(), document.getLastPos()); 
            tab.Header = true;
            //********************************************************************************/

            if (dataThread.TipoReport.ToUpper() == "DIAGNOSI") tab.HeaderFont = 8;
            //setta posizione tabella

            /***************** Fix Trimestrale Report Diagnosi 15/07/2020 - Pino **************/
            tab.Colonne.Add(new Colonna("Denominazione", "Denominazione", 158, TipoAllineamento.SINISTRA, false, 7, false));
            tab.Colonne.Add(new Colonna("Quote", "Numero Quote", 158, TipoAllineamento.SINISTRA, false, 7, false));
            tab.Colonne.Add(new Colonna("Valore", "Controvalore €", 158, TipoAllineamento.SINISTRA, false, 7, false));
            //********************************************************************************/

            /***************** Fix Trimestrale Report Diagnosi 15/07/2020 - Pino **************/
            //document.InsertTable(tab.getTabella(datitab));  /***** Originale ****/
            tab.Draw(datitab, document);     
            //********************************************************************************/

            float dim = datitab.GetRowDim() * (datitab.getNumRow() + 1);
            datitab = new DatiTabella();
            datitab.table = set.Tables["TotalePatrimonio"];

            /***************** Fix Trimestrale Report Diagnosi 15/07/2020 - Pino **************/
            //datitab.setY(document.getLastPos() + dim);  /***** Originale ****/
            datitab.setY(document.getLastPos() + dim + 5);
            //********************************************************************************/

            datitab.setX(document.getMargineLeft());
            datitab.setCell(420, ceTe.DynamicPDF.TextAlign.Left, Globals.OpenTypeFontVerdanaB, true);
            datitab.setCell(90, ceTe.DynamicPDF.TextAlign.Right, Globals.OpenTypeFontVerdanaB, true);

            document.InsertTable(tab.getTabella(datitab));

            ///// setto la posizione aggiornata
            document.setLastPos(datitab.GetRowDim() + dim);

        }


        #endregion
    }
}