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 S150 : ISezione
    {
        public S150()
        {
        }
        #region ISezione Members

        public void writeSezione(DataThread dataThread)
        {
            DocumentPDF document = dataThread.DocumentPDF;
            DatiTabella datitab = new DatiTabella();
            DataSetS150 set = (DataSetS150)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);

            var currentY = document.getLastPos() -20;

            datitab.setY(currentY);
            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);

            currentY = currentY + datitab.GetRowDim();
            //datitab.setY(document.getLastPos() + datitab.GetRowDim());
            datitab.setY(currentY);


            datitab.setX(document.getMargineLeft());
            document.InsertTable(tab.getTabella(datitab));
            document.setLastPos(datitab.GetRowDim() * (datitab.getNumRow())+10);
            

        }
        #endregion
    }
}