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.Presentation.Section.Charts;
using PDFGenerator.BusinessLayer.DataSection;
using PDFGenerator.BusinessLayer;
using System.Resources;
using System.Reflection;
using System.Collections.Generic;



namespace PDFGenerator.Presentation.Section
{
    
    class S148 :  STorta, ISezione
    {


        DataSetS148 set = new DataSetS148();
        public S148()
        {
            //
            // TODO: Add constructor logic here
            //
        }
        #region ISezione Members

        public new void writeSezione(DataThread datathread)
        {
            
            document = datathread.DocumentPDF;
           
                            document.addPage();         

            set = (DataSetS148)datathread.Data.DatiSezione;

            tabTortaTabella = set.Tables["MacroAssetClass"];
            tabTortaTotali = set.Tables["MacroAssetTotale"];
            tabTortaPatrimonioNonRappresentabile = set.Tables["PatrimonioNonRappresentabile"];
            tabTortaContoCorrenteBancaFideuram = set.Tables["ContoCorrenteBancaFideuram"];
            tabTortaPartiteViaggianti = set.Tables["PartiteViaggianti"];
            tabTotale = set.Tables["Totale"];

            base.writeSezione(datathread);

            if (set.Tables["PatrimonioNonRappresentabile"].Rows.Count > 0)
            {
                if (dim > ChartHeigth)
                {
                    this.addNota(document, (int)dim);
                }
                else
                {
                    this.addNota(document, ChartHeigth);
                }
            }


            if (dim > ChartHeigth)
            {
                document.setLastPos(dim);
            }
            else
            {
                document.setLastPos(ChartHeigth);
            }
        }
        #endregion

        public void writeSezioneCombo(DataThread datathread)
        {

            document = datathread.DocumentPDF;

            set = (DataSetS148)datathread.Data.DatiSezione;

            tabTortaTabella = set.Tables["MacroAssetClass"];
            tabTortaTotali = set.Tables["MacroAssetTotale"];
            tabTortaPatrimonioNonRappresentabile = set.Tables["PatrimonioNonRappresentabile"];
            tabTortaContoCorrenteBancaFideuram = set.Tables["ContoCorrenteBancaFideuram"];
            tabTortaPartiteViaggianti = set.Tables["PartiteViaggianti"];
            tabTotale = set.Tables["Totale"];

            base.writeSezioneComboSX(datathread);

            if (salto)
                document.returnLastPage();

            document.setPotenzialeLastPos(datitab.GetRowDim() * datitab.getNumRow() + dim, salto);

        }

        private void addNota(DocumentPDF doc, int dim)
        {
            doc.setSezFooter("(*) Il dettaglio del Patrimonio non rappresentabile per Asset class viene riportato in fondo al documento.", dim);
        }

        public void writeSezione_old(DataThread datathread) {
            document = datathread.DocumentPDF;
            DataSetS148 set = (DataSetS148)datathread.Data.DatiSezione;
            if (document.checkMargin(250))
                            document.addPage();           
            tabTortaTabella = set.MacroAssetClass;
            tabTortaTotali = set.MacroAssetTotale;    
            base.writeSezione(datathread);            
        }

        //public void writeSezione_old(DataThread dataThread)
        //{
        //    DocumentPDF document = dataThread.DocumentPDF;           
        //    DataSetS148 set = (DataSetS148)dataThread.Data.DatiSezione;
        //    DatiTabella datitab = new DatiTabella(set.AssetClass);

        //    float Xtable = document.getMargineLeft();
        //    float Ytable = document.getLastPos();
        //    int dFont = 9;
        //    int wCol1 = 160;
        //    int wCol2 = 90;
        //    int wCol3 = 60;
        //    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();
           
        //   ceTe.DynamicPDF.Merger.ImportedPage page = document.getCurrentPage();

        //   #region  GRAFICO
        //   DatiGrafico dati = new DatiGrafico();
        //   dati.dataTab = set.AssetClass;
        //   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("AssetClassName", "Asset Class", wCol1, TipoAllineamento.SINISTRA, false, dFont, false, TipoColonna.IMMAGINE_E_TESTO));
        //    tabellaDati.Colonne.Add(new Colonna("Controvalore", "Controvalore<BR>€", wCol2, TipoAllineamento.DESTRA, false, dFont, false));
        //    tabellaDati.Colonne.Add(new Colonna("Percentuale", "Peso<BR>%", wCol3, TipoAllineamento.DESTRA, false, dFont, false));
        //    tabellaDati.Draw(datitab, document);
            


        //    //SIMBOLI
        //    int nPallino = 1;
        //    float yPallino = Ytable + tabellaDati.AltezzaCella;
        //    float xPallino = Xtable;

        //    float ycambio = tabellaDati.YCambioPagina;
        //    bool saltoPagina = tabellaDati.SaltoPaginaEffettuato;

        //    ceTe.DynamicPDF.Merger.ImportedPage pageTable = 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.414F, color, color);
        //        page.Elements.Add(simbolo);
        //        if (saltoPagina && nPallino > 20 && page != pageTable)
        //        {
        //            page = pageTable;
        //            yPallino = ycambio + tabellaDati.AltezzaCella;
        //            //nPallino++;
        //        }
        //        else
        //        {
        //            yPallino += tabellaDati.AltezzaCella;
        //            nPallino++;
        //        }

        //    }


        //    document.setLastPos(datitab.GetRowDim() * (datitab.getNumRow() + 1));
        //    Ytable = document.getLastPos();
        //    //TOTALE
        //    tabellaDati = new Tabella(Xtable, Ytable);
        //    tabellaDati.Header = false;
        //    tabellaDati.Colonne.Add(new Colonna("Totale", "", wCol1, TipoAllineamento.SINISTRA, true, dFont, true));
        //    tabellaDati.Colonne.Add(new Colonna("Controvalore", "", wCol2, TipoAllineamento.DESTRA, true, dFont, true));
        //    tabellaDati.Colonne.Add(new Colonna("Percentuale", "", wCol3, TipoAllineamento.DESTRA, true, dFont, true));
        //    tabellaDati.Draw(new DatiTabella(set.AssetTotale), document);


        //    #endregion

        //    document.setLastPos(datitab.GetRowDim());
        //}
    }
}