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;

namespace PDFGenerator.Presentation.Section
{
    class S128 : ISezione
    {
        private string _header = "";

        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; }
        }


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

        #region ISezione Members

        public void writeSezione(DataThread dataThread)
        {

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

            document.setSezTitolo(dataThread.SezioneReport.Titolo);
            string tempTesto = dataThread.SezioneReport.TestoIntroduttivo;

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

            document.setChapterHeader(tempTesto, 0, 520, 8);

            float YTable = document.getLastPos() - 13;
            float XTable = document.getMargineLeft();

            # region profilorischio
            DatiTabella profilofinanziarioDatiTab = new DatiTabella();
            profilofinanziarioDatiTab.table = set.Tables["ProfiloRischio"];
            profilofinanziarioDatiTab.SetRowDim(15);
            profilofinanziarioDatiTab.setIsLinee(1);
            profilofinanziarioDatiTab.setCell(140, ceTe.DynamicPDF.TextAlign.Left, Globals.OpenTypeFontVerdanaB, true);
            profilofinanziarioDatiTab.setCell(273, ceTe.DynamicPDF.TextAlign.Left, Globals.OpenTypeFontVerdana, false);
            profilofinanziarioDatiTab.setX(XTable);
            profilofinanziarioDatiTab.setY(YTable);
            Tabella profilofinanziarioTab = new Tabella();           
            document.InsertTable(profilofinanziarioTab.getTabella(profilofinanziarioDatiTab));           
            # endregion

            YTable += profilofinanziarioDatiTab.getNumRow() * profilofinanziarioDatiTab.GetRowDim();

            # region Colonne Red
            DatiTabella colonneRed = new DatiTabella();
            colonneRed.table = set.Tables["colonneRed"];
            colonneRed.SetRowDim(15);
            colonneRed.setCell(196, ceTe.DynamicPDF.TextAlign.Right, Globals.OpenTypeFontVerdanaB, true);
            colonneRed.setCell(166, ceTe.DynamicPDF.TextAlign.Right, Globals.OpenTypeFontVerdanaB, true);
            colonneRed.setX(XTable + 150);
            colonneRed.setY(YTable);
            Tabella tabRed = new Tabella();
            tabRed.LineaFineTabella = true;
            document.InsertTable(tabRed.getTabella(colonneRed));
            # endregion

            YTable += colonneRed.getNumRow() * colonneRed.GetRowDim();

            # region Adeguatezza
            DatiTabella datitab = new DatiTabella();
            datitab.table = set.Tables["ProfiliRischioAdeguatezza"];
            datitab.SetRowDim(15);
            datitab.setIsLinee(1);
            datitab.setCell(200, ceTe.DynamicPDF.TextAlign.Left, Globals.OpenTypeFontVerdanaB, false);
            datitab.setCell(146, ceTe.DynamicPDF.TextAlign.Right, Globals.OpenTypeFontVerdana, false);
            datitab.setCell(166, ceTe.DynamicPDF.TextAlign.Right, Globals.OpenTypeFontVerdana, false);
            datitab.setX(XTable);
            datitab.setY(YTable);
            Tabella tab = new Tabella();
            tab.LineaFineTabella = true;
            document.InsertTable(tab.getTabella(datitab));
            # endregion

            YTable += datitab.getNumRow() * datitab.GetRowDim();

            document.setLastPos(
                (profilofinanziarioDatiTab.getNumRow() * profilofinanziarioDatiTab.GetRowDim()) + 
                (colonneRed.getNumRow() * colonneRed.GetRowDim()) + 
                (datitab.getNumRow() * datitab.GetRowDim()) - 23);
          
        }

        #endregion

    }
}