2025-04-15 12:10:19 +02:00

308 lines
16 KiB
C#

using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
namespace PDFGenerator.BusinessLayer.DataSection
{
class DSS132ProfiloRischioAdeguatezza : IDataSection
{
#region IDataSection Members
private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
public DataSectionResult getDataSection(List<SessionStruct> tabelleSessione, string querySql, DataThread dataThread)
{
try
{
DataSectionResult dsr = new DataSectionResult();
//DataSectionResult customerProfiliRischioAdeguatezzaDataSectionResult = new DataSectionResult();
DataSetS132 ds132 = new DataSetS132();
//DataSetS132 customerProfiliRischioAdeguatezzaRecordsDataSetS132 = new DataSetS132();
DataTable dt = SectionManager.GetDataSection(tabelleSessione, querySql, dataThread);
//DataTable customerProfiliRischioAdeguatezzaDataTable = SectionManager.GetDataSection(tabelleSessione, querySql, dataThread);
FormatNum conv = new FormatNum();
DataSetS132.DatiGraficoRow row;
DataSetS132.DatiTabellaDiagnosiRow rowTableDiagnosi;
DataSetS132.DatiTabellaMonitoraggioRow rowTableMonit;
DataSetS132.IndicatoriRow rowIndicatori;
DataRow customerProfiliRischioAdeguatezzaDataRow;
DataRow customerProfiloDateDataRow;
if (dataThread.profiloIsAct && dt.Rows.Count > 0)
{
int profiloRischioClienteAssegnato = Convert.ToInt32(dt.Rows[0]["codiceProfilo"]);
#region Creazione righe datatable ProfiloRischio
// Profilo di Rischio
customerProfiliRischioAdeguatezzaDataRow = ds132.ProfiloRischio.NewRow();
customerProfiliRischioAdeguatezzaDataRow["Descrizione"] = "Profilo Finanziario";
customerProfiliRischioAdeguatezzaDataRow["Valore"] = dt.Rows[0]["codiceProfilo"].ToString() + " " + dt.Rows[0]["nomeProfilo"].ToString();
ds132.ProfiloRischio.Rows.Add(customerProfiliRischioAdeguatezzaDataRow);
#endregion
#region Creazione righe datatable ProfiloDate
// Data Ultimo Aggiornamento
customerProfiloDateDataRow = ds132.ProfiloDate.NewRow();
// FC 09062015
// Aggiornamneto Label Descrizione
// New Label Da inserire:
customerProfiloDateDataRow["Descrizione"] = "Data inizio validità profilo";
//customerProfiloDateDataRow["Descrizione"] = "Ultimo aggiornamento questionario";
customerProfiloDateDataRow["Valore"] = dt.Rows[0]["dataInizioValidita"].ToString();
ds132.ProfiloDate.Rows.Add(customerProfiloDateDataRow);
#endregion
bool isMonit = dataThread.TipoReport.ToUpper() == "MONITORAGGIO";
DataView dw = new DataView(dt);
DataTable table;
if (dt.Rows.Count < 3)
dw.RowFilter = "InstituteName <> 'Patrimonio Complessivo'";
table = dw.ToTable();
#region Precalcolo degli Intermediari
decimal tempPerc = 0;
decimal controvaloreIntermediarioDiRete = 0;
decimal percentualeIntermediarioDiRete = 0;
decimal controvaloreAltriIntermediari = 0;
decimal percentualeAltriIntermediari = 0;
//Contrazioni delle stringhe di controllo con cui sono marcate le tuple ritornate nella sezione s6:
string s6_DescrizioneIntermediarioFideuram = "BANCAFIDEURAM";
string s6_DescrizioneIntermediarioSanPaolo = "SANPAOLOINVEST";
string s6_DescrizioneDiControllo = string.Empty;
//Contrazioni delle stringhe di controllo con cui sono marcate le tuple ritornate nella sezione s96:
string s96_DescrizioneIntermediarioFideuram = "PATRIMONIOBANCAFIDEURAM";
string s96_DescrizioneIntermediarioSanPaolo = "PATRIMONIOSANPAOLOINVEST";
string s96_DescrizioneAltriIstituti = "PATRIMONIOALTRIISTITUTI";
string s96_DescrizioneDiControllo = string.Empty;
//Descrizioni usate nelle logiche di flusso:
string descrizioneCorrente = string.Empty;
//Se nel DataThread la DataTable relativa agli intermediari è diversa da NULL significa che la DSS6 è stata elaborata:
//Nel caso abbia righe devo utilizzare i suoi controvalori e le sue percentuali per un calcolo di accorpamento in base alla rete.
//Tale valore confluisce poi nella valorizzazione delle righe di diagnosi in questa classe.
if (dataThread.DtDSS6Intermediari != null && dataThread.DtDSS6Intermediari.Rows.Count > 0)
{
//Specifica delle stringhe di controllo degli intermediari per le tuple sia per la DSS6 che per la DSS96:
if (dataThread.Rete.ToUpper().Equals("F"))
{
s6_DescrizioneDiControllo = s6_DescrizioneIntermediarioFideuram;
s96_DescrizioneDiControllo = s96_DescrizioneIntermediarioFideuram;
}
else if (dataThread.Rete.ToUpper().Equals("S"))
{
s6_DescrizioneDiControllo = s6_DescrizioneIntermediarioSanPaolo;
s96_DescrizioneDiControllo = s96_DescrizioneIntermediarioSanPaolo;
}
for (int i = 0; i < dataThread.DtDSS6Intermediari.Rows.Count; i++)
{
descrizioneCorrente = dataThread.DtDSS6Intermediari.Rows[i]["Descrizione"].ToString().Replace(" ", string.Empty).ToUpper();
if (descrizioneCorrente.Equals(s6_DescrizioneDiControllo))
{
controvaloreIntermediarioDiRete += Convert.ToDecimal(dataThread.DtDSS6Intermediari.Rows[i]["Controvalore"]);
percentualeIntermediarioDiRete += Convert.ToDecimal(dataThread.DtDSS6Intermediari.Rows[i]["Percentuale"]);
}
else
{
controvaloreAltriIntermediari += Convert.ToDecimal(dataThread.DtDSS6Intermediari.Rows[i]["Controvalore"]);
percentualeAltriIntermediari += Convert.ToDecimal(dataThread.DtDSS6Intermediari.Rows[i]["Percentuale"]);
}
}
}
#endregion
foreach (DataRow dtRow in table.Rows)
{
row = ds132.DatiGrafico.NewDatiGraficoRow();
rowTableDiagnosi = ds132.DatiTabellaDiagnosi.NewDatiTabellaDiagnosiRow();
rowTableMonit = ds132.DatiTabellaMonitoraggio.NewDatiTabellaMonitoraggioRow();
rowIndicatori = ds132.Indicatori.NewIndicatoriRow();
#region popolamento dataSet del grafico e dati tabella comuni
row.DescrizionePatrimonio = dtRow["InstituteName"].ToString();
if (isMonit)
{
rowTableMonit.DescrizionePatrimonio = " " + dtRow["InstituteName"].ToString();
}
else
{
rowTableDiagnosi.DescrizionePatrimonio = " " + dtRow["InstituteName"].ToString();
}
if (dtRow["riskClassString"] != DBNull.Value)
{
row.ClasseRischioCreditoStr = dtRow["riskClassString"].ToString();
if (isMonit)
rowTableMonit.RischioCredito = row.ClasseRischioCreditoStr;
else
rowTableDiagnosi.RischioCredito = row.ClasseRischioCreditoStr;
}
else
{
row.ClasseRischioCredito = Convert.ToInt16(dtRow["riskClass"]);
if (isMonit)
rowTableMonit.RischioCredito = UtilityBusinessLayer.GetRiskCreditClassName(row.ClasseRischioCredito.ToString());
else
rowTableDiagnosi.RischioCredito = UtilityBusinessLayer.GetRiskCreditClassName(row.ClasseRischioCredito.ToString());
}
//V attenzione vedere come si comporta il componente grafico, altrimenti inserire il riskClassMaxString
if (dtRow["riskClassMax"] == DBNull.Value)
row.RischioCreditoMaxStr = "N.C.";
else
row.RischioCreditoMax = Convert.ToInt16(dtRow["riskClassMax"]);
if (dtRow["varString"] != DBNull.Value)
{
row.RischioMercatoStr = dtRow["varString"].ToString();
if (isMonit)
rowTableMonit.RischioMercato = row.RischioMercatoStr;
else
rowTableDiagnosi.RischioMercato = row.RischioMercatoStr;
}
else
{
row.RischioMercato = Math.Round(Convert.ToDecimal(dtRow["var"]), 2);
if (isMonit)
rowTableMonit.RischioMercato = row.RischioMercato.ToString();
else
rowTableDiagnosi.RischioMercato = row.RischioMercato.ToString();
}
if (dtRow["varMax"] == DBNull.Value)
row.RischioMercatoMaxStr = "N.C.";
else
row.RischioMercatoMax = Convert.ToDecimal(SoglieVar.ConvOld(dtRow["varMax"]));
if (dtRow["coverageString"] != DBNull.Value)
{
row.CoperturaStr = dtRow["coverageString"].ToString();
if (isMonit)
rowTableMonit.Copertura = row.CoperturaStr;
else
rowTableDiagnosi.Copertura = row.CoperturaStr;
}
else
{
row.Copertura = Math.Round(Convert.ToDecimal(dtRow["coverage"]), 2);
if (isMonit)
rowTableMonit.Copertura = row.Copertura.ToString();
else
rowTableDiagnosi.Copertura = row.Copertura.ToString();
}
if (dtRow["riskClassString"] != DBNull.Value)
row.UllyPrec = 0.01M;
else
row.UllyPrec = Convert.ToDecimal(dtRow["Ully_perc"]);
//V verificare
if (dataThread.profiloIsAct)
row.Profilo = "A";
ds132.DatiGrafico.AddDatiGraficoRow(row);
#endregion
#region Totale Patrimonio
decimal risorseFinanziarie = dataThread.PatrimonioBancaFideuramCtvAlNettoContoCorrente;
decimal CC= dataThread.ContoCorrente;
decimal investimentiInCorso= dataThread.PartiteViaggiantiInvestimento + dataThread.PartiteViaggiantiDisinvestimento;
decimal totale = risorseFinanziarie + CC + investimentiInCorso + dataThread.TotalSelfNegCurrentAccountValue;
//rowTableMonit.TotalePatrimonio = totale.ToString();
rowTableMonit.TotalePatrimonio = conv.ConvertNum(totale);
#endregion
#region popolamento parte diagnosi
if (!isMonit)
{
if (dataThread.DtDSS6Intermediari != null && dataThread.DtDSS6Intermediari.Rows.Count > 0)
{
descrizioneCorrente = dtRow["InstituteName"].ToString().Replace(" ", string.Empty).ToUpper();
if (descrizioneCorrente.Equals(s96_DescrizioneDiControllo))
{
//V Lo prendo sempre dalla query il patrimonio casa, la s6 esclude solo il cc negativo e in caso di ppvv avrei una rapp
//errata
rowTableDiagnosi.Controvalore = Convert.ToDecimal(dtRow["CTV"]);//controvaloreIntermediarioDiRete;
tempPerc = percentualeIntermediarioDiRete;
}
else if (descrizioneCorrente.Equals(s96_DescrizioneAltriIstituti))
{
rowTableDiagnosi.Controvalore = controvaloreAltriIntermediari;
tempPerc = percentualeAltriIntermediari;
}
else
{
rowTableDiagnosi.Controvalore = Convert.ToDecimal(dtRow["CTV"]);
tempPerc = Math.Round(Convert.ToDecimal(dtRow["percentage"]), 2, MidpointRounding.AwayFromZero);
}
}
else
{
rowTableDiagnosi.Controvalore = Convert.ToDecimal(dtRow["CTV"]);
tempPerc = Math.Round(Convert.ToDecimal(dtRow["percentage"]), 2, MidpointRounding.AwayFromZero);
}
rowTableDiagnosi.Percentuale = tempPerc;
ds132.DatiTabellaDiagnosi.AddDatiTabellaDiagnosiRow(rowTableDiagnosi);
}
#endregion
#region popolamento parte monitoraggio
if (isMonit)
{
rowIndicatori.Complessita = Convert.ToBoolean(dtRow["ComplexityIsOk"]);
rowIndicatori.RischioMercato = Convert.ToBoolean(dtRow["VarIsOk"]);
rowIndicatori.RischioCredito = Convert.ToBoolean(dtRow["RiskClassIsOk"]);
ds132.DatiTabellaMonitoraggio.AddDatiTabellaMonitoraggioRow(rowTableMonit);
ds132.Indicatori.AddIndicatoriRow(rowIndicatori);
}
#endregion
}
}
dsr.DatiSezione = ds132;
//dsr.Esito = ds132.ProfiloRischio.Rows.Count;
dsr.Esito = ds132.DatiGrafico.Rows.Count;
return dsr;
}
catch (Exception ex)
{
try {
logger.Error(String.Concat(ex.Message, " ", dataThread.CodiceFiscale));
}
catch { }
throw ex;
}
}
#endregion
}
}