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 S47 : ISezione {
    

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

        #region ISezione Members
         
        public void writeSezione(DataThread dataThread) {
            DocumentPDF document = dataThread.DocumentPDF;

            DatiTabella datitab = new DatiTabella();
            DataSetS47 set = (DataSetS47)dataThread.Data.DatiSezione;
            datitab.table = set.Tables["ContoCorrente"];
            DataView view = new DataView(datitab.table);
            view.RowFilter = "";
            datitab.table = view.ToTable(false, setTableForTable());

            datitab.setY(document.getLastPos());
            datitab.setIsLinee(1);
            datitab.setHeader();
            datitab.setHeaderFont(8);
            datitab.setCell(80, ceTe.DynamicPDF.TextAlign.Left, Globals.OpenTypeFontVerdana, false, 7);
            datitab.setCell(150, ceTe.DynamicPDF.TextAlign.Left, Globals.OpenTypeFontVerdana, false, 7);
            datitab.setCell(152, ceTe.DynamicPDF.TextAlign.Right, Globals.OpenTypeFontVerdana, false, 7);
            datitab.setCell(65, ceTe.DynamicPDF.TextAlign.Right, Globals.OpenTypeFontVerdana, false, 7);
            datitab.setCell(65, ceTe.DynamicPDF.TextAlign.Right, Globals.OpenTypeFontVerdana, false, 7);

            //eventuali operazioni sul dataset
            //calcola se entra nella pagina altrimenti aggiunge una nuova pagina.
            if (document.checkMargin(datitab.GetRowDim() * (datitab.getNumRow() + 2))) 
                document.addPage();

            document.setTitolo(dataThread.SezioneReport.Titolo);

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

            float dim = datitab.GetRowDim() * (datitab.getNumRow() + 1);
            datitab = new DatiTabella();
            datitab.table = set.Tables["TotaleConti"];

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


            datitab.setCell(230, ceTe.DynamicPDF.TextAlign.Left, Globals.OpenTypeFontVerdanaB, true, 8);
            datitab.setCell(152, ceTe.DynamicPDF.TextAlign.Right, Globals.OpenTypeFontVerdanaB, true, 8);
            datitab.setCell(130, ceTe.DynamicPDF.TextAlign.Right, Globals.OpenTypeFontVerdanaB, true, 8);

            document.InsertTable(tab.getTabella(datitab));

            ///// setto la posizione aggiornata
            document.setLastPos(datitab.GetRowDim() + dim);

        }

        private string[] setTableForTable() {
            //eventuali operazioni sul dataset
            string[] Columns = new String[5];
            Columns[0] = "Data";
            Columns[1] = "Numero";
            Columns[2] = "Saldo";
            Columns[3] = "CreditRisk";
            Columns[4] = "Var";
            return Columns;
        }

        #endregion
    }
}