using System;
using System.Collections.Generic;
using System.Text;
using ceTe.DynamicPDF.Text;
using System.Collections;
using ceTe.DynamicPDF;
using PDFGenerator.Presentation.Section.Tables;
using PDFGenerator.Presentation.Section.Charts;
using PDFGenerator.BusinessLayer.DataSection;
using System.Data;
using PDFGenerator.BusinessLayer;
using ceTe.DynamicPDF.PageElements;


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

        public void writeSezione(DataThread dataThread)
        {
            DocumentPDF document = dataThread.DocumentPDF;
            DataSetS144 set = (DataSetS144)dataThread.Data.DatiSezione;
            DatiTabella datitab = new DatiTabella(set.Scadenza);


            float Xtable = document.getMargineLeft();
            float Ytable = document.getLastPos();
            int dFont = 9;
            int wCol1 = 100;
            int wCol2 = 95;
            int wCol3 = 65;
            int hGrafico = 150;

            if (document.checkMargin(250))
                document.addPage();

            document.setSezTitolo(dataThread.SezioneReport.Titolo);
            document.setChapterHeader(dataThread.SezioneReport.TestoIntroduttivo.Replace("/$Banca$/", dataThread.NomeRete), 0, 520, 8);

            Ytable = document.getLastPos();


            #region  GRAFICO
            DatiGrafico dati = new DatiGrafico();
            dati.dataTab = set.Scadenza;
            dati.setHeight(hGrafico);
            dati.setWidth(hGrafico);
            Torta isto = new Torta();
            document.InsertGrafico(isto.getGrafico(dati), Xtable + wCol1 + wCol2 + wCol3 + 50, Ytable - 11);
            #endregion

            #region Tabella Rating
           

            Tabella tabellaDati = new Tabella(Xtable, Ytable);
            tabellaDati.Header = true;
            tabellaDati.Colonne.Add(new Colonna("Scadenza", "Scadenza", wCol1, TipoAllineamento.SINISTRA, false, dFont, false, TipoColonna.IMMAGINE_E_TESTO));
            tabellaDati.Colonne.Add(new Colonna("Controvalore", "Controvalore €", wCol2, TipoAllineamento.DESTRA, false, dFont, false));
            tabellaDati.Colonne.Add(new Colonna("Percentage", "Peso %", wCol3, TipoAllineamento.DESTRA, false, dFont, false));
            tabellaDati.Draw(datitab, document);
            //SIMBOLI
            int nPallino = 1;
            float yPallino = Ytable + tabellaDati.AltezzaCella;
            float xPallino = Xtable;
            ceTe.DynamicPDF.Merger.ImportedPage page = document.getCurrentPage();
            foreach (DataRow drSimbolo in tabellaDati.Datasource.Rows)
            {
                RgbColor color =
                    new RgbColor(byte.Parse(drSimbolo["Red"].ToString()), byte.Parse(drSimbolo["Green"].ToString()), byte.Parse(drSimbolo["Blue"].ToString()));
                ceTe.DynamicPDF.PageElements.Circle simbolo =
                    new ceTe.DynamicPDF.PageElements.Circle(xPallino, yPallino, 10 / 1.8F, color, color);
                page.Elements.Add(simbolo);
                yPallino += tabellaDati.AltezzaCella;
                nPallino++;
            }
            Ytable += (datitab.GetRowDim() * (datitab.getNumRow() + 1)) + document.getSectionSpace(); 
            //TOTALE
            tabellaDati = new Tabella(Xtable, Ytable);
            tabellaDati.Header = false;
            tabellaDati.Colonne.Add(new Colonna("Descrizione", "", wCol1, TipoAllineamento.SINISTRA, true, dFont, true));
            tabellaDati.Colonne.Add(new Colonna("Controvalore", "", wCol2, TipoAllineamento.DESTRA, true, dFont, true));
            tabellaDati.Colonne.Add(new Colonna("Percentage", "", wCol3, TipoAllineamento.DESTRA, true, dFont, true));
            tabellaDati.Draw(new DatiTabella(set.Totale), document);


            #endregion


            document.setLastPos(hGrafico);



        }
    }
}