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 S25 : ISezione {
      
        public S25() {
            //
            // TODO: Add constructor logic here
            //
        }

        #region ISezione Members

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

            datitab.table = set.Tables["DatiAnagrafici"];
            //eventuali operazioni sul dataset
            DataView view = new DataView(datitab.table);
            view.RowFilter = "Descrizione = 'Cliente'";
            DataTable newTable = view.ToTable();
           
            // Non aggiunge la riga vuota nel caso di cliente di tipo fiduciarie
            if (!newTable.Rows[0]["Valore"].ToString().Contains("-"))
                newTable.Rows.Add(newTable.NewRow());

            datitab.table = newTable;


            //calcola se entra nella pagina altrimenti aggiunge una nuova pagina. In questa sezione il # di righe � fissato
                if (document.checkMargin(datitab.GetRowDim() * datitab.getNumRow())) 
                    document.addPage();

            datitab.SetRowDim(25);
            datitab.setIsLinee(2);
            datitab.setCell(170, ceTe.DynamicPDF.TextAlign.Left, Globals.OpenTypeFontVerdanaB, true);
            datitab.setCell(343, ceTe.DynamicPDF.TextAlign.Left, Globals.OpenTypeFontVerdanaB, false);
            
            if (dataThread.TipoReport.ToUpper() == "DIAGNOSI")
                document.setSezTitoloDiagnosi(dataThread.SezioneReport.Titolo);
            else
                document.setSezTitolo(dataThread.SezioneReport.Titolo);

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

            Tabella tab = new Tabella();
            if (dataThread.TipoReport.ToUpper() == "DIAGNOSI") tab.HeaderFont = 8;
            //setta posizione tabella
            document.InsertTable(tab.getTabella(datitab));

            datitab = new DatiTabella();
            datitab.table = set.Tables["DatiAnagrafici"];

            view = new DataView(datitab.table);
            view.RowFilter = "Descrizione <> 'Cliente'";
            datitab.table = view.ToTable();

            datitab.SetRowDim(25);
            datitab.setIsLinee(2);
            datitab.setCell(170, ceTe.DynamicPDF.TextAlign.Left, Globals.OpenTypeFontVerdanaB, true);
            datitab.setCell(343, ceTe.DynamicPDF.TextAlign.Left, Globals.OpenTypeFontVerdana, false);

            datitab.setY(document.getLastPos() + datitab.GetRowDim());
            datitab.setX(document.getMargineLeft());

            document.InsertTable(tab.getTabella(datitab));
            
            //aggiorno il puntatore alla posizione da cui si pu� scrivere
            if (dataThread.TipoReport.ToUpper() == "DIAGNOSI") 
                document.setLastPos(datitab.GetRowDim() * (datitab.getNumRow() + 1));
            else
                document.setLastPos(datitab.GetRowDim() * (datitab.getNumRow())+10);

            ////
            //TabellaPDF t = new TabellaPDF(document.getMargineLeft(), document.getLastPos(), 512, document);

            //t.Colonne.Add(new ColonnaPDF("Descrizione", "Descrizione", 200, TipoAllineamento.SINISTRA, false, 8, false));
            //t.Colonne.Add(new ColonnaPDF("Valore", "Valore", 312, TipoAllineamento.SINISTRA, false, 8, false));                



            //t.Datasource = datitab.table;
            //t.Draw();

            //document.setLastPos(t.Height);

            ////

        }               
        #endregion
    }
}