using System;
using System.Web;
using System.Text;
using System.Data;

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


public class DSS165FondiAltriIstituti : IDataSection
{


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

        FormatNum conv = new FormatNum();
        DataSetS165 ds165 = new DataSetS165();
        string asterisco = string.Empty;


        DataTable dt = SectionManager.GetDataSection(tabelleSessione, querySql, dataThread);

        DataSetS165.FondiRow dr;
        DataSetS165.FondiTotaleRow drTot;
        bool primaRiga = true;
        foreach (DataRow row in dt.Rows)
        {
            dr = ds165.Fondi.NewFondiRow();

            dr.Intermediario = row["Intermediario"].ToString();
            dr.DataSottoscrizione = row["dataSottoscrizione"].ToString();
            dr.Descrizione = row["descrizione_prodotto"].ToString();
            dr.Controvalore = Convert.ToDecimal(row["controvalore"]);
            dr.TipoVersamento = row["tipo_versamento"].ToString();
            dr.Ammontare = Convert.ToDecimal(row["ammontare"]);

            //Hazem
            if (row["CreditRisk"] != DBNull.Value)
                dr.CreditRisk = row["CreditRiskString"].ToString();
            else
                dr.CreditRisk = UtilityBusinessLayer.GetRiskCreditClassName(row["CreditRisk"].ToString());

            if (row["var_prodottoString"] != DBNull.Value)
                dr.Var = row["var_prodottoString"].ToString();
            else
                dr.Var = conv.ConvertNum(row["var_prodotto"]);

            dr.VarProxato = row["ProdNonInCatalogo"].ToString();


            if (!string.IsNullOrEmpty(row["Copertura_Totale"].ToString()))
                dr.Copertura = row["Copertura_Totale"].ToString();


            ds165.Fondi.AddFondiRow(dr);

            if (primaRiga)
            {

                drTot = ds165.FondiTotale.NewFondiTotaleRow();
                drTot.Totale = "TOTALE FONDI PENSIONE";
                drTot.Controvalore = Convert.ToDecimal(row["somma_controval"]);

                if (row["var_totaleString"] != DBNull.Value)
                    drTot.Var = row["var_totaleString"].ToString();
                else
                    if (row["var_totale"] != DBNull.Value)
                        drTot.Var = conv.ConvertNum(row["var_totale"]);


                ds165.FondiTotale.AddFondiTotaleRow(drTot);
                primaRiga = false;
            }
        }

        dsr.DatiSezione = ds165;
        dsr.Esito = ds165.Fondi.Rows.Count;

        return dsr;
    }



}