350 lines
19 KiB
C#
350 lines
19 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
|
|
namespace PDFGenerator.BusinessLayer.DataSection
|
|
{
|
|
|
|
/// <summary>
|
|
/// Summary description for DSS172ProtezioneCapitaleAreeBisogno
|
|
/// </summary>
|
|
public class DSS172ProtezioneCapitaleAreeBisogno : IDataSection
|
|
{
|
|
|
|
public DSS172ProtezioneCapitaleAreeBisogno()
|
|
{
|
|
//
|
|
// TODO: Add constructor logic here
|
|
//
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Recupera i dati per la stampa della S172.
|
|
/// </summary>
|
|
/// <param name="tabelleSessione"></param>
|
|
/// <param name="querySql"></param>
|
|
/// <param name="dataThread"></param>
|
|
/// <returns></returns>
|
|
public DataSectionResult getDataSection(List<SessionStruct> tabelleSessione, string querySql, DataThread dataThread)
|
|
{
|
|
DataSetS172 dataset172 = new DataSetS172();
|
|
FormatNum conv = new FormatNum();
|
|
DataSectionResult dsr = new DataSectionResult();
|
|
|
|
|
|
#region DataSetS172Bis LineeProtette
|
|
|
|
DataSetS172Bis dataset172bis = new DataSetS172Bis();
|
|
DataSectionResult dsr172bis = new DataSectionResult();
|
|
|
|
DataTable dtLineeProtette = SectionManager.GetDataSection(tabelleSessione, "[C6MartPeriodico].[PL_S172ProtezioneCapitaleLineeProdotti]", dataThread);
|
|
|
|
#endregion
|
|
|
|
|
|
Random rnd = new Random();
|
|
DataTable dt = new DataTable();
|
|
|
|
bool _mostracolonnacopertura = false;
|
|
|
|
if (dataThread.Patrimoniobancafideuramctv != 0)
|
|
{
|
|
|
|
Decimal ctvTotale = 0;
|
|
//Decimal ctvCC = 0;
|
|
Decimal ctvNA = 0;
|
|
|
|
dt = SectionManager.GetDataSection(tabelleSessione, querySql, dataThread);
|
|
|
|
decimal residuo = 100;
|
|
//decimal valorePercMaggiore = 0;
|
|
DataSetS172.GraficoFarfallaRow tupla_maggiore = null;
|
|
|
|
//Se il cliente ha solo CC presso BF la query ritorna solo 2 righe e non bisogna visualizzare niente
|
|
if (dt.Rows.Count > 3)
|
|
{
|
|
|
|
#region Tabella del GraficoPiramide
|
|
|
|
decimal totaleRisorseAllocate = 0;
|
|
decimal totaleControvaloreProtetto = 0;
|
|
int iOrderNeedArea = 1;
|
|
|
|
foreach(DataRow row in dtLineeProtette.Rows)
|
|
{
|
|
DataSetS172.LineeProtetteRow newRow;
|
|
newRow = dataset172.LineeProtette.NewLineeProtetteRow();
|
|
newRow.Linea = row["Linea"].ToString();
|
|
newRow.Contratto = row["Contratto"].ToString();
|
|
newRow.VersatoNetto = Convert.ToDecimal(row["VersatoNetto"]);
|
|
newRow.Controvalore = Convert.ToDecimal(row["Controvalore"]);
|
|
newRow.ComponentePerformance = Convert.ToDecimal(row["ComponentePerformance"]);
|
|
newRow.ComponenteProtezione = Convert.ToDecimal(row["ComponenteProtezione"]);
|
|
newRow.ControvaloreProtetto = Convert.ToDecimal(row["ControvaloreProtetto"]);
|
|
newRow.DataRiferimento = row["DataRiferimento"].ToString();
|
|
newRow.PercentualePerformance = Convert.ToDecimal(row["PercentualePerformance"]);
|
|
newRow.PercentualeProtezione = Convert.ToDecimal(row["PercentualeProtezione"]);
|
|
|
|
dataset172.LineeProtette.AddLineeProtetteRow(newRow);
|
|
}
|
|
|
|
foreach (DataRow row in dt.Rows)
|
|
{
|
|
// escludo risorse non allocate (na), contocorrente (cc) , pro, pre1 e pre2
|
|
if (row["needarea"].ToString().ToLower() != "na" && row["needarea"].ToString().ToLower() != "cc" && row["needarea"].ToString().ToLower() != "pro" && row["needarea"].ToString().ToLower() != "pre1" && row["needarea"].ToString().ToLower() != "pre2")
|
|
{
|
|
//Grafico Piramide
|
|
DataSetS172.GraficoPiramideRow rowDSS172GraficoPiramide;
|
|
rowDSS172GraficoPiramide = dataset172.GraficoPiramide.NewGraficoPiramideRow();
|
|
rowDSS172GraficoPiramide.AreaBisogno = row["needarea"].ToString();
|
|
rowDSS172GraficoPiramide.Controvalore = conv.ConvertNum(row["controvaloreAttuale"].ToString());
|
|
rowDSS172GraficoPiramide.ControvaloreProtetto = conv.ConvertNum(row["capprot"].ToString());
|
|
rowDSS172GraficoPiramide.ContributoProtezione = "";
|
|
rowDSS172GraficoPiramide.ContributoProtezioneColumn = "";
|
|
totaleRisorseAllocate += Convert.ToDecimal(row["controvaloreAttuale"]);
|
|
totaleControvaloreProtetto += Convert.ToDecimal(row["capprot"].ToString());
|
|
rowDSS172GraficoPiramide.Rischio = row["var_needareaString"] == DBNull.Value ? conv.ConvertNum(row["var_needarea"].ToString()) : row["var_needareaString"].ToString();
|
|
rowDSS172GraficoPiramide.Copertura = row["copertura_needareaString"] == DBNull.Value ? conv.ConvertNum(row["copertura_needarea"].ToString()) : row["copertura_needareaString"].ToString();
|
|
|
|
if ((Convert.ToDecimal(rowDSS172GraficoPiramide.Controvalore) == 0) || (Convert.ToDecimal(rowDSS172GraficoPiramide.Controvalore) == 0M) || (Convert.ToDecimal(rowDSS172GraficoPiramide.Controvalore) == 0M))
|
|
{
|
|
rowDSS172GraficoPiramide.Rischio = "0,00";
|
|
rowDSS172GraficoPiramide.Copertura = "100,00";
|
|
}
|
|
|
|
rowDSS172GraficoPiramide.OrderNeedArea = iOrderNeedArea;
|
|
|
|
dataset172.GraficoPiramide.AddGraficoPiramideRow(rowDSS172GraficoPiramide);
|
|
|
|
#region istogramma a barre
|
|
//Istogramma a barre
|
|
DataSetS172.GraficoBarreRow rowDSS172ContributoProtezione;
|
|
rowDSS172ContributoProtezione = dataset172.GraficoBarre.NewGraficoBarreRow();
|
|
|
|
rowDSS172ContributoProtezione.NeedArea = row["needarea"].ToString().ToLower();
|
|
rowDSS172ContributoProtezione.OrderNeedArea = iOrderNeedArea;
|
|
|
|
dataset172.GraficoBarre.AddGraficoBarreRow(rowDSS172ContributoProtezione);
|
|
|
|
//--Istogramma a barre
|
|
#endregion
|
|
|
|
iOrderNeedArea++;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
//V Approssimazione diagnosi
|
|
if (dataThread.TipoReport.ToUpper() == "DIAGNOSI")
|
|
{
|
|
if (residuo != 0 && tupla_maggiore != null)
|
|
{
|
|
tupla_maggiore.PercentualeAttuale += residuo;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Risorse Allocate
|
|
DataSetS172.RisorseAllocateRow rowDSS172RisorseAllocate;
|
|
rowDSS172RisorseAllocate = dataset172.RisorseAllocate.NewRisorseAllocateRow();
|
|
rowDSS172RisorseAllocate.Descrizione = "TOTALE RISORSE ALLOCATE";
|
|
rowDSS172RisorseAllocate.Controvalore = conv.ConvertNum(totaleRisorseAllocate);
|
|
rowDSS172RisorseAllocate.ControvaloreProtetto = conv.ConvertNum(totaleControvaloreProtetto);
|
|
//V Cambiato il puntamento alla query per prendere il var della piramide invece che quello complessivo che tiene conto delle risorse non associate
|
|
rowDSS172RisorseAllocate.Rischio = dt.Rows[0]["var_tot_pirString"] == DBNull.Value ? conv.ConvertNum(dt.Rows[0]["var_tot_pir"].ToString()) : dt.Rows[0]["var_tot_pirString"].ToString();
|
|
|
|
rowDSS172RisorseAllocate.Copertura = dt.Rows[0]["copertura_tot_pirString"] == DBNull.Value ? conv.ConvertNum(dt.Rows[0]["copertura_tot_pir"].ToString()) : dt.Rows[0]["copertura_tot_pirString"].ToString();
|
|
|
|
rowDSS172RisorseAllocate.ContributoProtezione = "";
|
|
if (Convert.ToDecimal(rowDSS172RisorseAllocate.Controvalore) == 0)
|
|
{
|
|
rowDSS172RisorseAllocate.Rischio = "0,00";
|
|
rowDSS172RisorseAllocate.Copertura = "100,00";
|
|
}
|
|
//
|
|
|
|
#endregion
|
|
|
|
#region Risorse non allocate
|
|
|
|
decimal rischioRisorsenonAllocate = 0;
|
|
decimal coperturaRisorseNonAllocate = -1;
|
|
decimal ctvRisorseNonAllocate = 0;
|
|
DataSetS172.RisorseNonAllocateRow rowDSS172RisorseNonAllocate;
|
|
rowDSS172RisorseNonAllocate = dataset172.RisorseNonAllocate.NewRisorseNonAllocateRow();
|
|
rowDSS172RisorseNonAllocate.Descrizione = "Risorse non allocate";
|
|
|
|
DataRow[] drRisorseNonAllocate = dt.Select(" NeedArea='Na'");
|
|
if (drRisorseNonAllocate.Length > 0)
|
|
{
|
|
|
|
rowDSS172RisorseNonAllocate.Controvalore = conv.ConvertNum(drRisorseNonAllocate[0]["controvaloreAttuale"]);
|
|
ctvRisorseNonAllocate = drRisorseNonAllocate[0]["controvaloreAttuale"] == DBNull.Value ? 0 : Convert.ToDecimal(drRisorseNonAllocate[0]["controvaloreAttuale"]);
|
|
if (ctvRisorseNonAllocate != 0)
|
|
{
|
|
|
|
rischioRisorsenonAllocate = drRisorseNonAllocate[0]["var_needarea"] == DBNull.Value ? 0 : Convert.ToDecimal(drRisorseNonAllocate[0]["var_needarea"]);
|
|
coperturaRisorseNonAllocate = drRisorseNonAllocate[0]["copertura_needarea"] == DBNull.Value ? 0 : Convert.ToDecimal(drRisorseNonAllocate[0]["copertura_needarea"]);
|
|
|
|
}
|
|
}
|
|
|
|
rowDSS172RisorseNonAllocate.Controvalore = conv.ConvertNum(ctvRisorseNonAllocate);
|
|
rowDSS172RisorseNonAllocate.ControvaloreProtetto = "-";
|
|
rowDSS172RisorseNonAllocate.Rischio = conv.ConvertNum(rischioRisorsenonAllocate);
|
|
rowDSS172RisorseNonAllocate.Copertura = conv.ConvertNum(coperturaRisorseNonAllocate);
|
|
|
|
//V lo setto per le approsimazioni
|
|
ctvNA = ctvRisorseNonAllocate;
|
|
|
|
// In caso in cui le risorse non allocate siano uguali a 0 non deve essere mostrata la riga;
|
|
// non deve essere mostrata nemmeno la riga delle risorse allocate, ma direttamente delle risorse finanziarie
|
|
if (ctvRisorseNonAllocate != 0M)
|
|
{
|
|
dataset172.RisorseAllocate.AddRisorseAllocateRow(rowDSS172RisorseAllocate);
|
|
dataset172.RisorseNonAllocate.AddRisorseNonAllocateRow(rowDSS172RisorseNonAllocate);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Risorse Finanziarie
|
|
// totale delle Risorse Finanziarie
|
|
DataSetS172.RisorseFinanziarieRow rowDSS172RisorseFinanziarie;
|
|
rowDSS172RisorseFinanziarie = dataset172.RisorseFinanziarie.NewRisorseFinanziarieRow();
|
|
rowDSS172RisorseFinanziarie.Descrizione = "TOTALE RISORSE FINANZIARIE";
|
|
rowDSS172RisorseFinanziarie.Controvalore = conv.ConvertNum(totaleRisorseAllocate + ctvRisorseNonAllocate);
|
|
rowDSS172RisorseFinanziarie.Rischio = dt.Rows[0]["var_risfinString"] == DBNull.Value ? conv.ConvertNum(dt.Rows[0]["var_risfin"].ToString()) : dt.Rows[0]["var_risfinString"].ToString(); //D //conv.ConvertNum(ptfTotaleBF.misureRischio.varp);
|
|
rowDSS172RisorseFinanziarie.Copertura = dt.Rows[0]["copertura_risfinString"] == DBNull.Value ? conv.ConvertNum(dt.Rows[0]["copertura_risfin"].ToString()) : dt.Rows[0]["copertura_risfinString"].ToString(); //D
|
|
rowDSS172RisorseFinanziarie.ControvaloreProtetto = "-";
|
|
rowDSS172RisorseFinanziarie.ContributoProtezione = "";
|
|
|
|
|
|
//V Setto copertura = 100 e var = 0 nel caso il ctv sia uguale a 0
|
|
if (totaleRisorseAllocate + ctvRisorseNonAllocate == 0)
|
|
{
|
|
rowDSS172RisorseFinanziarie.Rischio = "0,00";
|
|
rowDSS172RisorseFinanziarie.Copertura = "100,00";
|
|
}
|
|
|
|
dataset172.RisorseFinanziarie.AddRisorseFinanziarieRow(rowDSS172RisorseFinanziarie);
|
|
|
|
#endregion
|
|
|
|
#region Conto Corrente
|
|
|
|
decimal ctvContoCorrente = 0;
|
|
DataSetS172.ContoCorrenteRow rowDSS172ContoCorrente;
|
|
rowDSS172ContoCorrente = dataset172.ContoCorrente.NewContoCorrenteRow();
|
|
rowDSS172ContoCorrente.Descrizione = "C/C a saldo negativo";
|
|
ctvContoCorrente = dataThread.ContoCorrente;
|
|
rowDSS172ContoCorrente.Controvalore = conv.ConvertNum(ctvContoCorrente);
|
|
rowDSS172ContoCorrente.Rischio = "0,00";
|
|
rowDSS172ContoCorrente.Copertura = "100,00";
|
|
rowDSS172ContoCorrente.ControvaloreProtetto = "-";
|
|
dataset172.ContoCorrente.AddContoCorrenteRow(rowDSS172ContoCorrente);
|
|
|
|
#endregion
|
|
|
|
#region Linea Self Negativa
|
|
decimal ctvLineaSelfNegativa = 0;
|
|
DataSetS172.LineaSelfRow rowDSS172LineaSelfNegativa;
|
|
rowDSS172LineaSelfNegativa = dataset172.LineaSelf.NewLineaSelfRow();
|
|
rowDSS172LineaSelfNegativa.Descrizione = "Liquidità negativa \"Linee GP Eligo\" ";
|
|
ctvLineaSelfNegativa = dataThread.TotalSelfNegCurrentAccountValue;
|
|
rowDSS172LineaSelfNegativa.Controvalore = conv.ConvertNum(ctvLineaSelfNegativa);
|
|
rowDSS172LineaSelfNegativa.Rischio = "n.c.";
|
|
rowDSS172LineaSelfNegativa.Copertura = "100,00";
|
|
rowDSS172LineaSelfNegativa.ControvaloreProtetto = "-";
|
|
dataset172.LineaSelf.AddLineaSelfRow(rowDSS172LineaSelfNegativa);
|
|
|
|
#endregion
|
|
|
|
#region PartiteViaggianti
|
|
DataSetS172.PartiteViaggiantiRow rowDSS172PartiteViaggianti;
|
|
rowDSS172PartiteViaggianti = dataset172.PartiteViaggianti.NewPartiteViaggiantiRow();
|
|
rowDSS172PartiteViaggianti.Descrizione = Resource.PartiteViaggianti;
|
|
rowDSS172PartiteViaggianti.ControvaloreProtetto = "-";
|
|
decimal totalePartiteViaggianti = dataThread.PartiteViaggiantiInvestimento + dataThread.PartiteViaggiantiDisinvestimento;
|
|
rowDSS172PartiteViaggianti.ControValore = conv.ConvertNum(totalePartiteViaggianti);
|
|
if (totalePartiteViaggianti != 0)
|
|
dataset172.PartiteViaggianti.AddPartiteViaggiantiRow(rowDSS172PartiteViaggianti);
|
|
|
|
#endregion
|
|
|
|
#region Totale Patrimonio
|
|
DataSetS172.TotalePatrimonioRow rowDSS172TotalePatrimonio;
|
|
rowDSS172TotalePatrimonio = dataset172.TotalePatrimonio.NewTotalePatrimonioRow();
|
|
rowDSS172TotalePatrimonio.Descrizione = "TOTALE PATRIMONIO";
|
|
|
|
decimal totalePatrimonio = totaleRisorseAllocate + ctvContoCorrente + totalePartiteViaggianti + ctvRisorseNonAllocate + ctvLineaSelfNegativa;
|
|
rowDSS172TotalePatrimonio.ControValore = conv.ConvertNum(totalePatrimonio);
|
|
rowDSS172TotalePatrimonio.ControvaloreProtetto = conv.ConvertNum(totaleControvaloreProtetto);
|
|
|
|
//V Settato per le approsimazioni
|
|
ctvTotale = totaleRisorseAllocate;
|
|
|
|
//Hazem
|
|
if (dt.Rows[0]["var_totString"] != DBNull.Value)
|
|
rowDSS172TotalePatrimonio.Rischio = dt.Rows[0]["var_totString"].ToString();
|
|
else
|
|
rowDSS172TotalePatrimonio.Rischio = conv.ConvertNum(dt.Rows[0]["var_tot"]);
|
|
|
|
if (dt.Rows[0]["copertura_totString"] != DBNull.Value)
|
|
rowDSS172TotalePatrimonio.Copertura = dt.Rows[0]["copertura_totString"].ToString();
|
|
else
|
|
rowDSS172TotalePatrimonio.Copertura = conv.ConvertNum(dt.Rows[0]["copertura_tot"]);
|
|
|
|
rowDSS172TotalePatrimonio.ContributoProtezione = "";
|
|
|
|
|
|
dataset172.TotalePatrimonio.AddTotalePatrimonioRow(rowDSS172TotalePatrimonio);
|
|
|
|
foreach (DataRow row in dataset172.GraficoPiramide.Rows)
|
|
{
|
|
//row["ContributoProtezione"] = (Convert.ToDouble( row["ControvaloreProtetto"])/Convert.ToDouble(dataset172.TotalePatrimonio.Rows[0]["Controvalore"]) * 100.00).ToString();
|
|
if (Convert.ToDouble(totaleControvaloreProtetto) > 0)
|
|
row["ContributoProtezione"] = ((Convert.ToDouble(row["ControvaloreProtetto"]) / Convert.ToDouble(totaleControvaloreProtetto)) * 100.00).ToString();
|
|
else
|
|
row["ContributoProtezione"] = 0;
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
#region Resulset
|
|
|
|
// verifico se nel datatable GraficoPiramide almeno 1 grado copertura è diverso da 100 e il grado di copertura delle risorse non allocate è diverso da 100
|
|
// se si verrà disegnata la colonna relativa al grado di coperura.
|
|
DataTable dtMostraColonnaCopertura;
|
|
DataView dwMostraColonnaCopertura = new DataView(dataset172.GraficoPiramide);
|
|
dwMostraColonnaCopertura.RowFilter = "Copertura <> '100,00'";
|
|
dtMostraColonnaCopertura = dwMostraColonnaCopertura.ToTable();
|
|
_mostracolonnacopertura = (dtMostraColonnaCopertura.Rows.Count > 0 || (coperturaRisorseNonAllocate != 100M && coperturaRisorseNonAllocate != -1M));
|
|
|
|
DataSetS172.ResultSetRow rowDSS172ResultSet;
|
|
rowDSS172ResultSet = dataset172.ResultSet.NewResultSetRow();
|
|
rowDSS172ResultSet.MostraColonnaCopertura = _mostracolonnacopertura;
|
|
dataset172.ResultSet.AddResultSetRow(rowDSS172ResultSet);
|
|
|
|
#endregion
|
|
|
|
}
|
|
//V condizione presente nella S57 non riportata nella bis
|
|
//dataThread.TotaleS57 = ctvTotale + ctvNA + dataThread.ContoCorrente - dataThread.PatrimonioNonRappresentabile;
|
|
}
|
|
|
|
|
|
|
|
dsr.DatiSezione = dataset172;
|
|
dsr.Esito = dataset172.GraficoPiramide.Rows.Count;
|
|
|
|
|
|
return dsr;
|
|
|
|
}
|
|
}
|
|
}
|