using System;
using System.Web;
//using System.Web.Services;
//using System.Web.Services.Protocols;
using System.Text;
using System.Data;

using System.Collections;
using PDFGenerator.BusinessLayer.DataSection;
using System.Collections.Generic;
using PDFGenerator.BusinessLayer;
using PDFGenerator;


public class DSS49PolizzeAltriIstituti : IDataSection
{
    #region IDataSection Members
    public StructColor toBeFound = new StructColor();

    public DataSectionResult getDataSection(List<SessionStruct> tabelleSessione, string querySql, DataThread dataThread)
    {
        DataSectionResult dsr = new DataSectionResult();


        DataSetS49 ds49 = new DataSetS49();

        //Prepara la query
        DataTable dt = SectionManager.GetDataSection(tabelleSessione, querySql, dataThread);
        //DataRow[] drFiltrato = getData(dt, dataThread.Intermediario);


        Decimal prstTotale = 0;
        Decimal ammTotale = 0;
        DataRow dr;

        FormatNum conv = new FormatNum();

        foreach (DataRow row in dt.Rows)
        {
            dr = ds49.Polizze.NewRow();
            dr["Intermediario"] = row["intermediario"];
            if (row["dataDiSottoscrizione"] != DBNull.Value && row["dataDiSottoscrizione"] != null)
                dr["DataSottoscrizione"] = Convert.ToDateTime(row["dataDiSottoscrizione"]).ToShortDateString();
            //                dr["DataSottoscrizione"] = row["dataDisottoscrizione"];
            if (row["dataDiScadenza"] != DBNull.Value && row["dataDiScadenza"] != null)
                dr["DataScadenza"] = Convert.ToDateTime(row["dataDiScadenza"]).ToShortDateString();
            dr["Descrizione"] = row["descrizione"];
            dr["Tipologia"] = row["tipologiaPolizza"];
            dr["Prestazione"] = row["prestazioneAssicurata"];
            prstTotale += Convert.ToDecimal(row["prestazioneAssicurata"]);
            dr["TipoVersamento"] = row["tipoVersamento"];
            dr["Ammontare"] = row["AmmontareVersamento"];
            ammTotale += Convert.ToDecimal(row["AmmontareVersamento"]);

            ds49.Polizze.Rows.Add(dr);
        }

        DataRow drTot = ds49.Totali.NewRow();
        drTot["Descrizione"] = "TOTALE POLIZZE";
        drTot["Prestazione"] = prstTotale;
        drTot["Ammontare"] = ammTotale;
        //drTot["MinusPlus"] = 6789.66F;

        ds49.Totali.Rows.Add(drTot);

        dsr.DatiSezione = ds49;
        dsr.Esito = ds49.Polizze.Rows.Count;

        return dsr;
    }

    private DataRow[] getData(DataTable dt, string intermediario)
    {
        if (intermediario == string.Empty)
        {
            return dt.Select();
        }
        else
        {
            return dt.Select(" intermediario  = '" + intermediario.Replace("'", "''") + "'");
        }
    }

    #endregion
}