1279 lines
58 KiB
C#
1279 lines
58 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.Text;
|
||
using System.Data;
|
||
using System.Collections.Specialized;
|
||
using System.Globalization;
|
||
using System.Resources;
|
||
using ContrattoSei.Utilities;
|
||
using DataAccessLayer;
|
||
using System.Data.SqlClient;
|
||
using System.Data.Common;
|
||
using System.Threading.Tasks;
|
||
using System.Threading;
|
||
using System.Configuration;
|
||
using System.Linq;
|
||
using System.Reflection;
|
||
using System.ComponentModel;
|
||
|
||
namespace PDFGenerator.BusinessLayer
|
||
{
|
||
/// <summary>
|
||
/// Risk Credit Classes.
|
||
/// <Owner> Marian Zaki</Owner>
|
||
/// <Date> 04052010 </Date>
|
||
/// </summary>
|
||
/*public enum RiskCreditClass
|
||
{
|
||
/// <summary>
|
||
/// Class 1
|
||
/// </summary>
|
||
Classe1,
|
||
|
||
/// <summary>
|
||
/// Class 2
|
||
/// </summary>
|
||
Classe2,
|
||
|
||
/// <summary>
|
||
/// Class 3
|
||
/// </summary>
|
||
Classe3
|
||
}*/
|
||
public class UtilityBusinessLayer : IDisposable
|
||
{
|
||
private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
|
||
|
||
private static DataThread ConstructFromDataReader(IDataReader reader)
|
||
{
|
||
//pk
|
||
try {
|
||
logger.Debug("Starting getting data for {0} {1} {2}", reader["codiceFiscale"].ToString(), reader["rete"].ToString(), reader["Tip_Contratto"].ToString());
|
||
}
|
||
catch { }
|
||
DataThread dataThread = new DataThread(DBProvider.SqlServerStampeC6);
|
||
//RETE
|
||
dataThread.DataLotto = ConfigurationManager.AppSettings["DataLotto"].ToString();
|
||
dataThread.Rete = reader["Rete"].ToString();
|
||
dataThread.NomeRete = reader["NomeRete"].ToString();
|
||
// *** //
|
||
//AGENTE
|
||
dataThread.Agente = reader["Agente"].ToString();
|
||
dataThread.CognomeAgente = reader["CognomeAgente"].ToString();
|
||
dataThread.NomeAgente = reader["NomeAgente"].ToString();
|
||
dataThread.IndirizzoAgente = reader["IndirizzoAgente"].ToString();
|
||
dataThread.CapAgente = reader["CapAgente"].ToString();
|
||
dataThread.CittaAgente = reader["CittaAgente"].ToString();
|
||
dataThread.TelefonoAgente = reader["TelefonoAgente"].ToString();
|
||
//CLIENTE
|
||
dataThread.CodiceFiscale = reader["codiceFiscale"].ToString();
|
||
dataThread.CognomeCliente = reader["CognomeCliente"].ToString();
|
||
dataThread.NomeCliente = reader["NomeCliente"].ToString();
|
||
//PATRIMONI CLIENTE
|
||
dataThread.profiloIsAct = Convert.ToBoolean(reader["ProfiloIsAct"]);
|
||
//PATRIMONIO NON RAPPRESENTABILE
|
||
//dataThread.PatrimonioNonRappresentabileAI = (decimal)reader["PatrimonioNonRappresentabileAI"]; // Commentata Andrea Prova
|
||
//dataThread.PatrimonioNonRappresentabileCompl = (decimal)reader["PatrimonioNonRappresentabileCompl"]; // Commentata Andrea Prova
|
||
//dataThread.PatrimonioNonRappresentabileFI = (decimal)reader["PatrimonioNonRappresentabileFI"]; // Commentata Andrea Prova
|
||
//PARTITE VIAGGIANTI
|
||
dataThread.PartiteViaggiantiInvestimento = (decimal)reader["PartiteViaggiantiInv"];
|
||
dataThread.PartiteViaggiantiDisinvestimento = (decimal)reader["PartiteViaggiantiDisinv"]; //d.lisena
|
||
//**********prova1
|
||
dataThread.PatrimonioNonRappresentabile = (decimal)reader["PatrimonioNonRappresentabile"]; // Commentata Andrea Prova // old Prova Andrea
|
||
|
||
/************************************* Fix per aggiunta patrimonio totale 13/12/2021 - Andrea *******************************/
|
||
dataThread.Patrimoniocomplessivototalectv = (decimal)reader["Patrimoniocomplessivototalectv"];
|
||
/****************************************************************************************************************************/
|
||
|
||
dataThread.ContoCorrente = (decimal)reader["ContoCorrente"];
|
||
dataThread.Patrimonioaltroctv = (decimal)reader["Patrimonioaltroctv"];
|
||
dataThread.Patrimonioimmobiliarectv = (decimal)reader["Patrimonioimmobiliarectv"];
|
||
dataThread.Patrimonioterzictv = (decimal)reader["Patrimonioterzictv"];
|
||
dataThread.PatrimonioTerziContoCorrente = (decimal)reader["PatrimonioTerziContoCorrente"];
|
||
dataThread.PatrimonioterzictvAlNettoContoCorrente = (decimal)reader["PatrimonioterzictvAlNettoContoCorrente"];
|
||
dataThread.Patrimoniobancafideuramctv = (decimal)reader["Patrimoniobancafideuramctv"];
|
||
dataThread.PatrimonioBancaFideuramCtvAlNettoContoCorrente = (decimal)reader["patrimoniobancafideuramctvalnettocontocorrente"];
|
||
dataThread.NumeroIntermediari = (int)reader["NumeroIntermediari"];
|
||
dataThread.RisorseNonAssociate = (decimal)reader["RisorseNonAssociate"];
|
||
dataThread.VaRRisorseNonAssociate = (decimal)reader["VaRRisorseNonAssociate"];
|
||
dataThread.CoperturaRisorseNonAssociate = (decimal)reader["CoperturaRisorseNonAssociate"];
|
||
dataThread.VaRTotaleRisorseFinanziarie = (decimal)reader["VaRTotaleRisorseFinanziarie"];
|
||
dataThread.CoperturaTotaleRisorseFinanziarie = (decimal)reader["CoperturaTotaleRisorseFinanziarie"];
|
||
//dataThread.TipoContratto = reader["Tip_Contratto"].ToString().Equals("2") ? TipoContratto.Private : reader["Tip_Contratto"].ToString().Equals("1") ? TipoContratto.Affluent : TipoContratto.Old;
|
||
dataThread.TipoContratto = reader["Tip_Contratto"].ToString().Equals("2") ? TipoContratto.Private : reader["Tip_Contratto"].ToString().Equals("1") ? TipoContratto.Affluent : reader["Tip_Contratto"].ToString().Equals("3") ? TipoContratto.Dadvisory : TipoContratto.Old;
|
||
dataThread.ContrattoOld = reader["Contrattoold"].ToString().Equals("1") ? true : false;
|
||
dataThread.NoMonitoraggio = reader["NoMonitoraggio"].ToString().Equals("1") ? true : false;
|
||
//CONTRATTO
|
||
// dataThread.GeneraDiagnosi = Convert.ToBoolean(reader["generaDiagnosi"]);
|
||
|
||
dataThread.Flagnqp = reader["flagnqp"].ToString();
|
||
dataThread.Flagprlrde = reader["flagprlrde"].ToString();
|
||
dataThread.Flgprof = reader["Flgprof"].ToString();
|
||
|
||
//TemplateGeneratorFactory.ListaVariabili.Add(new TemplateGeneratorFactory.Variabili
|
||
//{
|
||
// CodiceFiscale = dataThread.CodiceFiscale,
|
||
// Rete = dataThread.Rete
|
||
//});
|
||
|
||
|
||
|
||
try
|
||
{
|
||
dataThread.Flagpg = int.Parse(reader["flagpg"].ToString());
|
||
}
|
||
catch { //call stored procedure
|
||
}
|
||
|
||
dataThread.IdReportPDFDiagnosi = (Int32)reader["IdReportPDFDiagnosi"];
|
||
dataThread.IdReportPDFMonitoraggio = (Int32)reader["IdReportPDFMonitoraggio"];
|
||
|
||
dataThread.CodiceContratto = reader["CodiceContratto"].ToString();
|
||
|
||
logger.Info(string.Concat("idReportDiagnosi dal DB: ", reader["idModelloDiagnosi"].ToString(), " CF: ", dataThread.CodiceFiscale," Periodico: ", dataThread.Periodico.ToString()));
|
||
|
||
int idReportDiagnosi = (Int32)reader["idModelloDiagnosi"]; //reader["idReportDiagnosi"];
|
||
if (idReportDiagnosi != -1)
|
||
{
|
||
ReportType reportType = new ReportType();
|
||
reportType.IdReport = (Int32)reader["idReportDiagnosi"];
|
||
reportType.IdModello = (Int32)reader["idModelloDiagnosi"];
|
||
reportType.Descrizione = reader["descrizioneDiagnosi"].ToString();
|
||
reportType.TipoReport = TipoReport.DIAGNOSI;
|
||
dataThread.ReportsType.Add(reportType);
|
||
}
|
||
|
||
int idReportMonitoraggio = (Int32)reader["idReportMonitoraggio"];
|
||
|
||
if (idReportMonitoraggio != -1)
|
||
{
|
||
ReportType reportType = new ReportType();
|
||
reportType.IdReport = (Int32)reader["idReportMonitoraggio"];
|
||
reportType.IdModello = (Int32)reader["idModelloMonitoraggio"];
|
||
reportType.Descrizione = reader["descrizioneMonitoraggio"].ToString();
|
||
reportType.TipoReport = TipoReport.MONITORAGGIO;
|
||
dataThread.ReportsType.Add(reportType);
|
||
|
||
DateTimeFormatInfo dfi = new CultureInfo("it-IT", false).DateTimeFormat;
|
||
dataThread.DataFineTrimestreCorrente = Convert.ToDateTime(UtilityManager.getAppSetting("DataFineTrimestreCorrente"), dfi);
|
||
|
||
}
|
||
dataThread.AdesioneSuccessivaAvanzato = Convert.ToBoolean(reader["adesioneSuccessivaAvanzato"]);
|
||
dataThread.Periodico = UtilityManager.getAppSetting("Periodico") == "0" ? false : true;
|
||
try
|
||
{
|
||
dataThread.RiskArea = GetRiskArea(dataThread.CodiceFiscale, dataThread.Rete);
|
||
}
|
||
catch(Exception ex)
|
||
{
|
||
dataThread.RiskArea = 0;
|
||
}
|
||
try {
|
||
logger.Debug("Getting data for {0} {1} {2} finished", reader["codiceFiscale"].ToString(), reader["rete"].ToString(), reader["Tip_Contratto"].ToString());
|
||
}
|
||
catch { }
|
||
return dataThread;
|
||
}
|
||
|
||
|
||
public static int GetRiskArea(string fiscalCode, string rete)
|
||
{
|
||
int res = 0;
|
||
List<Parametro> parameters = new List<Parametro>()
|
||
{
|
||
new Parametro() {Value = rete, ParameterName ="Rete" },
|
||
new Parametro() {Value = fiscalCode, ParameterName ="CodiceFiscale" },
|
||
};
|
||
|
||
string spName = UtilityManager.getAppSetting("Periodico").Equals("0") ? "C6Mart.GetRiskArea" : "C6martPeriodico.GetRiskArea";
|
||
|
||
using (DataAccessDE de = new DataAccessDE(DBProvider.SqlServerStampeC6))
|
||
{
|
||
DataTable dt = de.ExecuteDataTableStoredProcedure(DBProvider.SqlServerStampeC6, spName, parameters);
|
||
foreach (DataRow r in dt.Rows)
|
||
{
|
||
if (Int32.Parse(r["profiloCode"].ToString()) > res)
|
||
{
|
||
res = Int32.Parse(r["profiloCode"].ToString());
|
||
}
|
||
}
|
||
}
|
||
|
||
return res;
|
||
}
|
||
public List<DataThread> getDataThreads(int number)
|
||
{
|
||
List<DataThread> dataThreads = new List<DataThread>();
|
||
try
|
||
{
|
||
DataThread dataThread = null;
|
||
// 20190125 AC
|
||
//string queryGetContratti = UtilityManager.getAppSetting("QueryContratti");
|
||
//--20190125 AC
|
||
string queryGetContratti = UtilityManager.getAppSetting("QueryContratti").Trim();
|
||
DbParameter[] pa = new SqlParameter[1] { new SqlParameter("volThreads", number) };
|
||
using (DataAccessDE dataAccess = new DataAccessDE(DBProvider.SqlServerStampeC6))
|
||
{
|
||
|
||
/*** ATTENZIONE FORZATURA per DirectBank Lettere di Benvenuto 13/03/2023 - Pino ***/
|
||
//queryGetContratti = "[C6Mart].[GESTIONE_SELECT_PDF_GETDATATHREADS_NA_A]"; //"[C6Mart].[GESTIONE_SELECT_PDF_GETDATATHREADS_NA_A]";
|
||
/**************************************************/
|
||
|
||
/*** ATTENZIONE FORZATURA per ESG3 13/06/2023 - Pino ***/
|
||
//queryGetContratti = "[C6MartPeriodico].[GESTIONE_SELECT_PDF_GETDATATHREADS_CAMPIONE2]";
|
||
/**************************************************/
|
||
|
||
/**** ATTENZIONE NUOVO Codice per interrogare il db - 01/03/2023 - Pino ***/
|
||
//SqlCommand cmd = new SqlCommand();
|
||
//IDataReader reader;
|
||
//try
|
||
//{
|
||
// cmd.CommandTimeout = 200;
|
||
// cmd.Connection = dataAccess.Connection;
|
||
// cmd.CommandText = queryGetContratti;
|
||
// cmd.CommandType = CommandType.StoredProcedure;
|
||
// //cmd.Parameters.AddRange(pa);
|
||
// reader = cmd.ExecuteReader();
|
||
// cmd.Parameters.Clear();
|
||
|
||
// while (reader.Read())
|
||
// {
|
||
// dataThread = ConstructFromDataReader(reader);
|
||
// dataThreads.Add(dataThread);
|
||
// }
|
||
// reader.Close();
|
||
|
||
//}
|
||
//catch (Exception ex)
|
||
//{
|
||
// try
|
||
// {
|
||
// //logger.Error(String.Concat(_commandText, ":", ex.Message, paramsToString(pa)));
|
||
// }
|
||
// catch { }
|
||
// if (cmd != null)
|
||
// cmd.Dispose();
|
||
//}
|
||
|
||
|
||
//cmd.Dispose();
|
||
|
||
/********************************************************************/
|
||
SqlCommand cmd;
|
||
|
||
using (IDataReader reader = dataAccess.ExecuteDataReader(CommandType.StoredProcedure, queryGetContratti, pa, out cmd))
|
||
{
|
||
while (reader.Read())
|
||
{
|
||
dataThread = ConstructFromDataReader(reader);
|
||
dataThreads.Add(dataThread);
|
||
}
|
||
reader.Close();
|
||
}
|
||
|
||
cmd.Dispose();
|
||
|
||
System.Threading.Tasks.Parallel.ForEach(dataThreads, t =>
|
||
{
|
||
if (t.Periodico)
|
||
{
|
||
RischioRelativo_PesoPercentuale r = new RischioRelativo_PesoPercentuale();
|
||
r.DataSource = recuperaDatiCalcoloPeso_Rischio(t.DataAccess, t.Rete, t.CodiceFiscale);
|
||
t.PesoPercentuale = r.calcolaPeso();
|
||
t.RischioRelativo = r.calcolaRischio();
|
||
t.ControvaloriTotali = r.calcolaControvaloriAttuali();
|
||
t.TotalNegativeCurrentAccountValue = getClientNegativeCurrentAccountsValue(t.DataAccess, t.Rete, t.CodiceFiscale);
|
||
t.TotalSelfNegCurrentAccountValue = getClientSelfNegCurrentAccountValue(t.DataAccess, t.Rete, t.CodiceFiscale);
|
||
// ******************************** Aggiunta Andrea al Data Thread **************************//
|
||
t.GPEligoFondi = getGPEligoNeg(t.DataAccess, t.Rete, t.CodiceFiscale, "L191");
|
||
t.GPEligoTitoli = getGPEligoNeg(t.DataAccess, t.Rete, t.CodiceFiscale, "L192");
|
||
t.GradoCoperturaMacroAssetInterno = getGradoCoperturaMacroAssetInterno(t.DataAccess, t.Rete, t.CodiceFiscale);
|
||
t.GradoCoperturaMacroAssetTotale = getGradoCoperturaMacroAssetTotale(t.DataAccess, t.Rete, t.CodiceFiscale);
|
||
t.GradoCoperturaMacroAssetAltri = getGradoCoperturaMacroAssetAltri(t.DataAccess, t.Rete, t.CodiceFiscale);
|
||
// t.PatrimonioNonRappresentabileAI = getPatrimonioNonRappresentabile(t.DataAccess, t.Rete, t.CodiceFiscale, "Altri Istituti");
|
||
t.PatrimonioNonRappresentabileCompl = getPatrimonioNonRappresentabile(t.DataAccess, t.Rete, t.CodiceFiscale, "Complessivo");
|
||
if (t.Rete == "F")
|
||
{
|
||
t.PatrimonioNonRappresentabileFI = getPatrimonioNonRappresentabile(t.DataAccess, t.Rete, t.CodiceFiscale, "Fideuram");
|
||
}
|
||
else if (t.Rete == "S")
|
||
{
|
||
t.PatrimonioNonRappresentabileFI = getPatrimonioNonRappresentabile(t.DataAccess, t.Rete, t.CodiceFiscale, "Sanpaolo Invest");
|
||
}
|
||
else
|
||
{
|
||
t.PatrimonioNonRappresentabileFI = getPatrimonioNonRappresentabile(t.DataAccess, t.Rete, t.CodiceFiscale, "IW Private Investments"); //cecco prova
|
||
}
|
||
|
||
t.PatrimonioNonRappresentabileAI = t.PatrimonioNonRappresentabileCompl - t.PatrimonioNonRappresentabileFI;
|
||
// *****************************************************************************************//
|
||
|
||
// MIOFOGLIO 20181130
|
||
t.SelfNegativeValue = getClientSelfNegative(t.DataAccess, t.Rete, t.CodiceFiscale);
|
||
|
||
if (t.SelfNegativeValue == null) {
|
||
t.SelfNegativeValue = new List<Tuple<string, string, decimal>>();
|
||
}
|
||
|
||
//--MIOFOGLIO 20181130
|
||
|
||
}
|
||
});
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
if(ex.Message == "Thread was being aborted.")
|
||
{
|
||
return null;
|
||
}
|
||
try {
|
||
logger.Error(String.Concat(ex.Message,", number: ", number.ToString()));
|
||
}
|
||
catch { }
|
||
}
|
||
if (dataThreads != null && dataThreads.Count > 0)
|
||
return dataThreads;
|
||
else
|
||
return null;
|
||
}
|
||
|
||
public Task obtainDataThreadsAsync(List<DataThread> dataThreads, int number)
|
||
{
|
||
Task t = Task.Factory.StartNew(() =>
|
||
{
|
||
List<DataThread> result = getDataThreads(number);
|
||
dataThreads.Clear();
|
||
if (result != null)
|
||
{
|
||
foreach (DataThread dt in result)
|
||
{
|
||
dataThreads.Add(dt);
|
||
}
|
||
}
|
||
});
|
||
return t;
|
||
}
|
||
|
||
/// <summary>
|
||
/// Recupero il datatable sul quale effettuare il calcolo del peso e del rischo relativo a livello di area/progetto.
|
||
/// Dalla [C6MartPeriodico].[PL_S82DatiSintetici] prendo i dati per le aree non d'investimento.
|
||
/// Dalla [C6MartPeriodico].[PL_S82BisDatiSintetici] prendo i dati per le aree d'investimento.
|
||
/// Oltre a dtDatiAREA e dtDatiPROGETTO vanno considerati anche i prodotti non associati a progetti.
|
||
/// Ottengo 3 datatable e il datatable di return sar<61> il merge dei 3.
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
private DataTable recuperaDatiCalcoloPeso_Rischio(DataAccessDE dataAccess, string rete, string codiceFiscale)
|
||
{
|
||
#region Settaggio parametri
|
||
|
||
List<Parametro> parameters = new List<Parametro>()
|
||
{
|
||
new Parametro() {Value = rete, ParameterName ="Rete" },
|
||
new Parametro() {Value = codiceFiscale, ParameterName ="CodiceFiscale" },
|
||
};
|
||
|
||
#endregion
|
||
|
||
DataTable dtDatiAREA = dataAccess.ExecuteDataTableStoredProcedure(DBProvider.SqlServerStampeC6, "[C6MartPeriodico].[PL_S82DatiSintetici]", parameters);
|
||
dtDatiAREA = dtDatiAREA.DefaultView.ToTable(false, "NEED_AREA", "CONTROVALOREATTUALE", "VAR_NEEDAREA", "VAR_NEEDAREASTRING", "ORDINAMENTO_PROGETTO");
|
||
|
||
DataTable dtDatiPROGETTO = dataAccess.ExecuteDataTableStoredProcedure(DBProvider.SqlServerStampeC6, "[C6MartPeriodico].[PL_S82BisDatiSintetici]", parameters);
|
||
dtDatiPROGETTO = dtDatiPROGETTO.DefaultView.ToTable(false, "NEED_AREA", "NOME_PROGETTO", "CONTROVALOREATTUALE", "VAR_NEEDAREA", "VAR_NEEDAREASTRING", "ORDINAMENTO_PROGETTO");
|
||
|
||
// Oltre a dtDatiAREA e dtDatiPROGETTO vanno considerati anche i prodotti non associati a progetti.
|
||
DataTable dtProdottiNonAssociati = dataAccess.ExecuteDataTableStoredProcedure(DBProvider.SqlServerStampeC6, "[C6MartPeriodico].[PL_Prodotti_Non_Associati_Area_Inv]", parameters);
|
||
|
||
#region Creazione e popolamento DataTable dtProdottiNonAssociati
|
||
DataTable dtDatiProdottiNonAssociati = new DataTable();
|
||
|
||
if (dtProdottiNonAssociati.Rows.Count > 0)
|
||
{
|
||
dtDatiProdottiNonAssociati.Columns.Add("need_area", typeof(string));
|
||
dtDatiProdottiNonAssociati.Columns.Add("NOME_PROGETTO", typeof(string));
|
||
dtDatiProdottiNonAssociati.Columns.Add("ControvaloreAttuale", typeof(decimal));
|
||
dtDatiProdottiNonAssociati.Columns.Add("var_needarea", typeof(decimal));
|
||
dtDatiProdottiNonAssociati.Columns.Add("var_needareaString", typeof(string));
|
||
dtDatiProdottiNonAssociati.Columns.Add("ORDINAMENTO_PROGETTO", typeof(int));
|
||
|
||
DataRow drDatiProdottiNonAssociati = dtDatiProdottiNonAssociati.NewRow();
|
||
drDatiProdottiNonAssociati["NEED_AREA"] = dtProdottiNonAssociati.Rows[0]["NEED_AREA"];
|
||
drDatiProdottiNonAssociati["NOME_PROGETTO"] = dtProdottiNonAssociati.Rows[0]["NOME_PROGETTO"];
|
||
drDatiProdottiNonAssociati["CONTROVALOREATTUALE"] = dtProdottiNonAssociati.Compute("Sum(CONTROVALOREATTUALE)", string.Empty);
|
||
drDatiProdottiNonAssociati["var_needarea"] = dtProdottiNonAssociati.Rows[0]["var_needarea"];
|
||
drDatiProdottiNonAssociati["var_needareaString"] = dtProdottiNonAssociati.Rows[0]["var_needareaString"];
|
||
//drDatiProdottiNonAssociati["ORDINAMENTO_PROGETTO"] = Convert.ToInt32(dtDatiProdottiNonAssociati.Rows[0]["ORDINAMENTO_PROGETTO"]);
|
||
drDatiProdottiNonAssociati["ORDINAMENTO_PROGETTO"] = Convert.ToInt32(dtProdottiNonAssociati.Rows[0]["ORDINAMENTO_PROGETTO"]);
|
||
dtDatiProdottiNonAssociati.Rows.Add(drDatiProdottiNonAssociati);
|
||
}
|
||
|
||
#endregion
|
||
|
||
DataTable dtDati = new DataTable(); // datatable di return
|
||
dtDati = dtDatiAREA;
|
||
dtDati.Merge(dtDatiPROGETTO);
|
||
|
||
if (dtDatiProdottiNonAssociati.Rows.Count > 0) // se ho prodotti non associati a progetti li aggiungo nel calcolo finale del peso percentuale e rischio relativo
|
||
dtDati.Merge(dtDatiProdottiNonAssociati);
|
||
|
||
return dtDati;
|
||
}
|
||
private static decimal getClientSelfNegCurrentAccountValue(DataAccessDE dataAccess, string rete, string codiceFiscale)
|
||
{
|
||
#region Settaggio parametri
|
||
|
||
List<Parametro> parameters = new List<Parametro>()
|
||
{
|
||
new Parametro() {Value = rete, ParameterName ="Rete" },
|
||
new Parametro() {Value = codiceFiscale, ParameterName ="CodiceFiscale" },
|
||
};
|
||
|
||
#endregion
|
||
|
||
object ClientSelfNegCurrentAccountValue;
|
||
if (UtilityManager.getAppSetting("Periodico") == "0")
|
||
{
|
||
ClientSelfNegCurrentAccountValue = dataAccess.ExecuteScalarStoredProcedure(DBProvider.SqlServerStampeC6, "[C6Mart].[PL_GetClientSelfNegCurrentAccountValue]", parameters);
|
||
}
|
||
else
|
||
{
|
||
ClientSelfNegCurrentAccountValue = dataAccess.ExecuteScalarStoredProcedure(DBProvider.SqlServerStampeC6, "[C6MartPeriodico].[PL_GetClientSelfNegCurrentAccountValue]", parameters);
|
||
}
|
||
|
||
|
||
|
||
if (ClientSelfNegCurrentAccountValue != null)
|
||
return decimal.Parse(ClientSelfNegCurrentAccountValue.ToString());
|
||
else
|
||
return 0;
|
||
}
|
||
|
||
// MIOFOGLIO 20181130
|
||
private static List<Tuple<string, string, decimal>> getClientSelfNegative(DataAccessDE dataAccess, string rete, string codiceFiscale)
|
||
{
|
||
#region Settaggio parametri
|
||
|
||
List<Parametro> parameters = new List<Parametro>()
|
||
{
|
||
new Parametro() {Value = rete, ParameterName ="Rete" },
|
||
new Parametro() {Value = codiceFiscale, ParameterName ="CodiceFiscale" },
|
||
};
|
||
|
||
#endregion
|
||
|
||
List<Tuple<string, string, decimal>> tuples = new List<Tuple<string, string, decimal>>();
|
||
|
||
DataTable ClientSelfNegative;
|
||
if (UtilityManager.getAppSetting("Periodico") == "0")
|
||
{
|
||
ClientSelfNegative = dataAccess.ExecuteDataTableStoredProcedure(DBProvider.SqlServerStampeC6, "[C6Mart].[PL_GetClientSelfNegative]", parameters);
|
||
}
|
||
else
|
||
{
|
||
ClientSelfNegative = dataAccess.ExecuteDataTableStoredProcedure(DBProvider.SqlServerStampeC6, "[C6MartPeriodico].[PL_GetClientSelfNegative]", parameters);
|
||
}
|
||
|
||
/********************** modifica per Trimestrale del 01-2021 - Pino ***************************************/
|
||
if (ClientSelfNegative!=null && ClientSelfNegative.Rows!=null && ClientSelfNegative.Rows.Count > 0)
|
||
{
|
||
// Originale senza l'If
|
||
foreach (DataRow row in ClientSelfNegative.Rows)
|
||
{
|
||
tuples.Add(new Tuple<string, string, decimal>(row["CodInterno"].ToString(), row["Descrizione"].ToString(), Convert.ToDecimal(row["CTV"])));
|
||
}
|
||
}
|
||
else
|
||
{
|
||
tuples.Add(new Tuple<string, string, decimal>("", "", 0));
|
||
}
|
||
/****************************************************************************************************/
|
||
|
||
return tuples;
|
||
}
|
||
//--MIOFOGLIO 20181130
|
||
|
||
private static decimal getClientNegativeCurrentAccountsValue(DataAccessDE dataAccess, string rete, string codiceFiscale)
|
||
{
|
||
#region Settaggio parametri
|
||
|
||
List<Parametro> parameters = new List<Parametro>()
|
||
{
|
||
new Parametro() {Value = rete, ParameterName ="Rete" },
|
||
new Parametro() {Value = codiceFiscale, ParameterName ="CodiceFiscale" },
|
||
};
|
||
|
||
#endregion
|
||
|
||
object clientNegativeCurrentAccountsValue;
|
||
if (UtilityManager.getAppSetting("Periodico") == "0")
|
||
{
|
||
clientNegativeCurrentAccountsValue = dataAccess.ExecuteScalarStoredProcedure(DBProvider.SqlServerStampeC6, "[C6Mart].[PL_GetClientNegativeCurrentAccountsValue]", parameters);
|
||
}
|
||
else
|
||
{
|
||
clientNegativeCurrentAccountsValue = dataAccess.ExecuteScalarStoredProcedure(DBProvider.SqlServerStampeC6, "[C6MartPeriodico].[PL_GetClientNegativeCurrentAccountsValue]", parameters);
|
||
}
|
||
//object clientNegativeCurrentAccountsValue = DataAccess.ExecuteScalarStoredProcedure(DBProvider.SqlServerStampeC6, "[C6MartPeriodico].[PL_GetClientNegativeCurrentAccountsValue]", parametri);
|
||
|
||
|
||
|
||
if (clientNegativeCurrentAccountsValue != null)
|
||
return decimal.Parse(clientNegativeCurrentAccountsValue.ToString());
|
||
else
|
||
return 0;
|
||
}
|
||
|
||
// ***************************** Prova Andrea aggiunta Data Thread **********************************************//
|
||
private static decimal getGPEligoNeg(DataAccessDE dataAccess, string rete, string codiceFiscale, string codice)
|
||
{
|
||
#region Settaggio parametri
|
||
|
||
List<Parametro> parameters = new List<Parametro>()
|
||
{
|
||
new Parametro() {Value = rete, ParameterName ="Rete" },
|
||
new Parametro() {Value = codiceFiscale, ParameterName ="CodiceFiscale" },
|
||
new Parametro() {Value = codice, ParameterName ="Codsottoprodotto" },
|
||
};
|
||
|
||
#endregion
|
||
|
||
object Eligo_neg;
|
||
if (UtilityManager.getAppSetting("Periodico") == "0")
|
||
{
|
||
Eligo_neg = dataAccess.ExecuteScalarStoredProcedure(DBProvider.SqlServerStampeC6, "[C6MartPeriodico].[PL_GetClientNegativeGPEligo]", parameters);
|
||
}
|
||
else
|
||
{
|
||
Eligo_neg = dataAccess.ExecuteScalarStoredProcedure(DBProvider.SqlServerStampeC6, "[C6MartPeriodico].[PL_GetClientNegativeGPEligo]", parameters);
|
||
}
|
||
//object clientNegativeCurrentAccountsValue = DataAccess.ExecuteScalarStoredProcedure(DBProvider.SqlServerStampeC6, "[C6MartPeriodico].[PL_GetClientNegativeCurrentAccountsValue]", parametri);
|
||
|
||
|
||
|
||
if (Eligo_neg != null)
|
||
return decimal.Parse(Eligo_neg.ToString());
|
||
else
|
||
return 0;
|
||
}
|
||
//************************** Modifica Andrea per Grado di Copertura **********************************//
|
||
private static decimal getGradoCoperturaMacroAssetInterno(DataAccessDE dataAccess, string rete, string codiceFiscale)
|
||
{
|
||
#region Settaggio parametri
|
||
|
||
List<Parametro> parameters = new List<Parametro>()
|
||
{
|
||
new Parametro() {Value = rete, ParameterName ="Rete" },
|
||
new Parametro() {Value = codiceFiscale, ParameterName ="CodiceFiscale" },
|
||
// new Parametro() {Value = codice, ParameterName ="codice" },
|
||
};
|
||
|
||
#endregion
|
||
|
||
object Grado_Copertura_MA;
|
||
if (UtilityManager.getAppSetting("Periodico") == "0")
|
||
{
|
||
Grado_Copertura_MA = dataAccess.ExecuteScalarStoredProcedure(DBProvider.SqlServerStampeC6, "[C6MartPeriodico].[PL_S75GradoCoperturaInterno]", parameters);
|
||
}
|
||
else
|
||
{
|
||
Grado_Copertura_MA = dataAccess.ExecuteScalarStoredProcedure(DBProvider.SqlServerStampeC6, "[C6MartPeriodico].[PL_S75GradoCoperturaInterno]", parameters);
|
||
}
|
||
|
||
if (Grado_Copertura_MA != null)
|
||
return decimal.Parse(Grado_Copertura_MA.ToString());
|
||
else
|
||
return 0;
|
||
}
|
||
//*********************
|
||
private static decimal getGradoCoperturaMacroAssetTotale(DataAccessDE dataAccess, string rete, string codiceFiscale)
|
||
{
|
||
#region Settaggio parametri
|
||
|
||
List<Parametro> parameters = new List<Parametro>()
|
||
{
|
||
new Parametro() {Value = rete, ParameterName ="Rete" },
|
||
new Parametro() {Value = codiceFiscale, ParameterName ="CodiceFiscale" },
|
||
// new Parametro() {Value = codice, ParameterName ="codice" },
|
||
};
|
||
|
||
#endregion
|
||
|
||
object Grado_Copertura_MA_TOT;
|
||
if (UtilityManager.getAppSetting("Periodico") == "0")
|
||
{
|
||
Grado_Copertura_MA_TOT = dataAccess.ExecuteScalarStoredProcedure(DBProvider.SqlServerStampeC6, "[C6MartPeriodico].[PL_S75GradoCoperturaCompl]", parameters);
|
||
}
|
||
else
|
||
{
|
||
Grado_Copertura_MA_TOT = dataAccess.ExecuteScalarStoredProcedure(DBProvider.SqlServerStampeC6, "[C6MartPeriodico].[PL_S75GradoCoperturaCompl]", parameters);
|
||
}
|
||
|
||
if (Grado_Copertura_MA_TOT != null)
|
||
return decimal.Parse(Grado_Copertura_MA_TOT.ToString());
|
||
else
|
||
return 0;
|
||
}
|
||
//*****************
|
||
private static decimal getGradoCoperturaMacroAssetAltri(DataAccessDE dataAccess, string rete, string codiceFiscale)
|
||
{
|
||
#region Settaggio parametri
|
||
|
||
List<Parametro> parameters = new List<Parametro>()
|
||
{
|
||
new Parametro() {Value = rete, ParameterName ="Rete" },
|
||
new Parametro() {Value = codiceFiscale, ParameterName ="CodiceFiscale" },
|
||
// new Parametro() {Value = codice, ParameterName ="codice" },
|
||
};
|
||
|
||
#endregion
|
||
|
||
object Grado_Copertura_MA_TRZ;
|
||
if (UtilityManager.getAppSetting("Periodico") == "0")
|
||
{
|
||
Grado_Copertura_MA_TRZ = dataAccess.ExecuteScalarStoredProcedure(DBProvider.SqlServerStampeC6, "[C6MartPeriodico].[PL_S75GradoCoperturaTerzi]", parameters);
|
||
}
|
||
else
|
||
{
|
||
Grado_Copertura_MA_TRZ = dataAccess.ExecuteScalarStoredProcedure(DBProvider.SqlServerStampeC6, "[C6MartPeriodico].[PL_S75GradoCoperturaTerzi]", parameters);
|
||
}
|
||
|
||
if (Grado_Copertura_MA_TRZ != null)
|
||
return decimal.Parse(Grado_Copertura_MA_TRZ.ToString());
|
||
else
|
||
return 100;
|
||
}
|
||
|
||
|
||
private static decimal getPatrimonioNonRappresentabile(DataAccessDE dataAccess, string rete, string codiceFiscale, string filtro)
|
||
{
|
||
decimal CtvNotCovered = 0;
|
||
|
||
#region Settaggio parametri
|
||
|
||
List<Parametro> parameters = new List<Parametro>()
|
||
{
|
||
new Parametro() {Value = rete, ParameterName ="Rete" },
|
||
new Parametro() {Value = codiceFiscale, ParameterName ="CodiceFiscale" },
|
||
// new Parametro() {Value = codice, ParameterName ="codice" },
|
||
};
|
||
|
||
#endregion
|
||
|
||
DataTable Patrimonio_Non_Rapp;
|
||
if (UtilityManager.getAppSetting("Periodico") == "0")
|
||
{
|
||
//Patrimonio_Non_Rapp = dataAccess.ExecuteScalarStoredProcedure(DBProvider.SqlServerStampeC6, "[C6MartPeriodico].[PL_D2_S167DistribuzioneRischioCredito]", parameters);
|
||
|
||
Patrimonio_Non_Rapp = DataAccess.ExecuteDataTableStoredProcedure(DBProvider.SqlServerStampeC6, "[C6Mart].[PL_D2_S167DistribuzioneRischioCredito]", parameters);
|
||
}
|
||
else
|
||
{
|
||
//Patrimonio_Non_Rapp = dataAccess.ExecuteScalarStoredProcedure(DBProvider.SqlServerStampeC6, "[C6MartPeriodico].[PL_D2_S167DistribuzioneRischioCredito]", parameters);
|
||
Patrimonio_Non_Rapp = DataAccess.ExecuteDataTableStoredProcedure(DBProvider.SqlServerStampeC6, "[C6MartPeriodico].[PL_D2_S167DistribuzioneRischioCredito]", parameters);
|
||
}
|
||
|
||
|
||
// if (Patrimonio_Non_Rapp != null)
|
||
if (Patrimonio_Non_Rapp.Rows.Count != 0)
|
||
{
|
||
List<CtvNotCoverede> _ListCtv = new List<CtvNotCoverede>();
|
||
_ListCtv = ConvertTo<CtvNotCoverede>(Patrimonio_Non_Rapp);
|
||
CtvNotCovered = _ListCtv.Where(f => f.INTERMEDIARIO == filtro).Select(s => s.CTV_notCovered).First();
|
||
if (CtvNotCovered == null)
|
||
CtvNotCovered = 0;
|
||
}
|
||
else
|
||
{
|
||
CtvNotCovered = 0;
|
||
}
|
||
|
||
return CtvNotCovered;
|
||
}
|
||
// *****************************************************************************************************************************//
|
||
|
||
public static StringCollection getMTQueries(ReportType reportType, DataAccessDE dataAccess)
|
||
{
|
||
StringCollection stringCollection = new StringCollection();
|
||
List<Parametro> parametri = new List<Parametro>();
|
||
Parametro parametro = new Parametro();
|
||
parametro.ParameterName = "idReport";
|
||
parametro.DbType = DbType.Int32;
|
||
parametro.Value = reportType.IdReport;
|
||
parametri.Add(parametro);
|
||
parametro = new Parametro();
|
||
parametro.ParameterName = "idModello";
|
||
parametro.DbType = DbType.Int32;
|
||
parametro.Value = reportType.IdModello;
|
||
parametri.Add(parametro);
|
||
bool checkPeriodico = (UtilityManager.getAppSetting("Periodico") == "1") ? true : false;
|
||
if (checkPeriodico)
|
||
{
|
||
parametro = new Parametro();
|
||
parametro.ParameterName = "periodicita";
|
||
parametro.DbType = DbType.String;
|
||
parametro.Value = 'T';
|
||
parametri.Add(parametro);
|
||
|
||
}
|
||
|
||
using (IDataReader reader = dataAccess.ExecuteDataReaderStoredProcedure(DBProvider.SqlServerStampeC6, "[C6MartPeriodico].[GESTIONE_C6_S_Generator]", parametri))
|
||
{
|
||
string queryLetta;
|
||
while (reader.Read())
|
||
{
|
||
queryLetta = reader["querySqlSezione"].ToString();
|
||
if (!string.IsNullOrEmpty(queryLetta))
|
||
stringCollection.Add(reader["querySqlSezione"].ToString());
|
||
}
|
||
}
|
||
return stringCollection;
|
||
}
|
||
public static int getEndThread(DataThread dataThread, int idReport, int docPage)
|
||
{
|
||
if (UtilityManager.getAppSetting("SavePDFtoDISK") == "1")
|
||
return 0;
|
||
|
||
List<Parametro> parametri = new List<Parametro>();
|
||
Parametro parametro = new Parametro();
|
||
parametro.ParameterName = "Rete";
|
||
parametro.DbType = DbType.AnsiStringFixedLength;
|
||
parametro.Value = dataThread.Rete;
|
||
parametri.Add(parametro);
|
||
|
||
parametro = new Parametro();
|
||
parametro.ParameterName = "CodiceFiscale";
|
||
parametro.DbType = DbType.String;
|
||
parametro.Value = dataThread.CodiceFiscale;
|
||
parametri.Add(parametro);
|
||
|
||
parametro = new Parametro();
|
||
parametro.ParameterName = "TipoReport";
|
||
parametro.DbType = DbType.String;
|
||
parametro.Value = dataThread.TipoReport;
|
||
parametri.Add(parametro);
|
||
|
||
string queryInserimento = UtilityManager.getAppSetting("SP_GESTIONE_INSERT_PDF_FTP_GET_ID");
|
||
//DataAccess.ExecuteNonQueryStoredProcedure(DBProvider.SqlServerStampeC6, queryInserimento, parametri);
|
||
try
|
||
{
|
||
return Convert.ToInt32(dataThread.DataAccess.ExecuteScalarStoredProcedure(DBProvider.SqlServerStampeC6, queryInserimento, parametri));
|
||
}
|
||
catch (Exception)
|
||
{
|
||
|
||
return -1;
|
||
|
||
}
|
||
}
|
||
public static int setEndThread(DataThread dataThread, int idReport, int docPage)
|
||
{
|
||
if (UtilityManager.getAppSetting("SavePDFtoDISK") == "1")
|
||
return 0;
|
||
|
||
List<Parametro> parametri = new List<Parametro>();
|
||
Parametro parametro = new Parametro();
|
||
parametro.ParameterName = "Rete";
|
||
parametro.DbType = DbType.AnsiStringFixedLength;
|
||
parametro.Value = dataThread.Rete;
|
||
parametri.Add(parametro);
|
||
|
||
parametro = new Parametro();
|
||
parametro.ParameterName = "CodiceFiscale";
|
||
parametro.DbType = DbType.String;
|
||
parametro.Value = dataThread.CodiceFiscale;
|
||
parametri.Add(parametro);
|
||
|
||
//FC Gestione Parallelizzazione Processi
|
||
// idReport <20> gestito dalla SP inserimento Gestione_Pdf_Ftp
|
||
|
||
int idReportPdf = dataThread.TipoReport == TipoReport.DIAGNOSI.ToString() ? dataThread.IdReportPDFDiagnosi : dataThread.IdReportPDFMonitoraggio;
|
||
idReportPdf = idReportPdf == 0 ? idReport : idReportPdf;
|
||
parametro = new Parametro();
|
||
parametro.ParameterName = "idReport";
|
||
parametro.DbType = DbType.Int32;
|
||
parametro.Value = idReportPdf;
|
||
parametri.Add(parametro);
|
||
|
||
parametro = new Parametro();
|
||
parametro.ParameterName = "NomeFile";
|
||
parametro.DbType = DbType.String;
|
||
parametro.Value = dataThread.NomeFileReport;
|
||
parametri.Add(parametro);
|
||
|
||
parametro = new Parametro();
|
||
parametro.ParameterName = "TipoReport";
|
||
parametro.DbType = DbType.String;
|
||
parametro.Value = dataThread.TipoReport;
|
||
parametri.Add(parametro);
|
||
|
||
parametro = new Parametro();
|
||
parametro.ParameterName = "NumeroPagine";
|
||
parametro.DbType = DbType.Int32;
|
||
parametro.Value = docPage;
|
||
parametri.Add(parametro);
|
||
|
||
//V Se <20> un report periodico salvo anche l'RFA in GESTIONE_PDF_FTP
|
||
if (dataThread.Periodico)
|
||
{
|
||
parametro = new Parametro();
|
||
parametro.ParameterName = "RFA";
|
||
parametro.DbType = DbType.Decimal;
|
||
parametro.Value = dataThread.Patrimoniobancafideuramctv;
|
||
parametri.Add(parametro);
|
||
|
||
|
||
parametro = new Parametro();
|
||
parametro.ParameterName = "CodiceContratto";
|
||
parametro.DbType = DbType.String;
|
||
parametro.Value = dataThread.CodiceContratto;
|
||
parametri.Add(parametro);
|
||
|
||
|
||
}
|
||
|
||
|
||
string queryInserimento = UtilityManager.getAppSetting("QueryInserimentoPDF_FTP");
|
||
//DataAccess.ExecuteNonQueryStoredProcedure(DBProvider.SqlServerStampeC6, queryInserimento, parametri);
|
||
var r = new object() ;
|
||
try
|
||
{
|
||
r = dataThread.DataAccess.ExecuteScalarStoredProcedure(DBProvider.SqlServerStampeC6, queryInserimento, parametri);
|
||
return Convert.ToInt32(r);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
logger.Error(ex.Message + "::" + idReportPdf.ToString() + " " + dataThread.CodiceFiscale + " " + dataThread.TipoReport + r.ToString());
|
||
return -1;
|
||
|
||
}
|
||
|
||
}
|
||
|
||
public static string ReplaceVariables(string testodarimpiazzare, DataThread _dataThread)
|
||
{
|
||
string testoOriginale = testodarimpiazzare;
|
||
|
||
testoOriginale = testoOriginale.Replace("$/Area/$", _dataThread.AreaEstesa);
|
||
|
||
if (_dataThread.Area != "Inv")
|
||
testoOriginale = testoOriginale.Replace("$/AreaProgetto/$", _dataThread.AreaEstesa);
|
||
else
|
||
testoOriginale = testoOriginale.Replace("$/AreaProgetto/$", _dataThread.Progetto);
|
||
|
||
if (_dataThread.Area != "Inv")
|
||
testoOriginale = testoOriginale.Replace("$/AreaProgettoA/$", "all'area di " + _dataThread.AreaEstesa);
|
||
else
|
||
testoOriginale = testoOriginale.Replace("$/AreaProgettoA/$", "al progetto " + _dataThread.Progetto);
|
||
|
||
if (_dataThread.Area != "Inv")
|
||
testoOriginale = testoOriginale.Replace("$/AreaProgettoD/$", "dell'area di " + _dataThread.AreaEstesa);
|
||
else
|
||
testoOriginale = testoOriginale.Replace("$/AreaProgettoD/$", "del progetto " + _dataThread.Progetto);
|
||
|
||
testoOriginale = testoOriginale.Replace("$/Progetto/$", _dataThread.Progetto);
|
||
|
||
if (_dataThread.Intermediario == "Altro")
|
||
testoOriginale = testoOriginale.Replace("$/Intermediario/$", "Altro intermediario");
|
||
else
|
||
testoOriginale = testoOriginale.Replace("$/Intermediario/$", _dataThread.Intermediario);
|
||
|
||
//if (_dataThread.Rete == "F")
|
||
// //FC 26062015 Aggionamento nuova Ragione Sociale
|
||
// //testoOriginale = testoOriginale.Replace("$/Banca/$", "Banca Fideuram");
|
||
// testoOriginale = testoOriginale.Replace("$/Banca/$", "Fideuram");
|
||
//else
|
||
// testoOriginale = testoOriginale.Replace("$/Banca/$", "Sanpaolo Invest");
|
||
|
||
//************************************ Cecco modifiche dicitura IWBANK*******************************
|
||
switch (_dataThread.Rete)
|
||
{
|
||
case "F":
|
||
{
|
||
testoOriginale = testoOriginale.Replace("$/Banca/$", "Fideuram");
|
||
break;
|
||
}
|
||
case "S":
|
||
{
|
||
testoOriginale = testoOriginale.Replace("$/Banca/$", "Sanpaolo Invest");
|
||
// ************ Rosaspina modifica Andrea ****************************//
|
||
//testoOriginale = testoOriginale.Replace("$/Banca/$", "Fideuram S.p.A., commercializzato tramite la rete di private banker Sanpaolo Invest");
|
||
break;
|
||
}
|
||
case "W":
|
||
{
|
||
testoOriginale = testoOriginale.Replace("$/Banca/$", "IW Private Investments");
|
||
break;
|
||
}
|
||
}
|
||
|
||
//********************************************************************************************************
|
||
|
||
testoOriginale = testoOriginale.Replace("$/FontSize/$", "</font><font pointSize='6'>font size, </font>");
|
||
|
||
return testoOriginale;
|
||
}
|
||
|
||
/// <summary>
|
||
/// Sostituisce le variabili presenti nel testo (indicate con $/...../$ con il valore corrispondente
|
||
/// I dati vengono presi dalle propriet<65> dell'oggetto sezione passato in input.
|
||
/// </summary>
|
||
/// <param name="testodarimpiazzare"></param>
|
||
/// <returns></returns>
|
||
public static string ReplaceVariables(string testodarimpiazzare, SezioneReport sezione)
|
||
{
|
||
string testoOriginale = testodarimpiazzare;
|
||
char[] define = { '$', '/', ',', '.' };
|
||
|
||
const char Space = ' ';
|
||
|
||
char[] delimiters = new char[]
|
||
{
|
||
Space
|
||
};
|
||
|
||
|
||
// split the string and then iterate over the
|
||
// resulting array of strings
|
||
if (testodarimpiazzare != " ")
|
||
foreach (string variabile in testodarimpiazzare.Split(delimiters))
|
||
{
|
||
string app = variabile.TrimStart(define);
|
||
app = app.TrimEnd(define);
|
||
switch (app)
|
||
{
|
||
#region Area
|
||
case "Area":
|
||
testoOriginale = testoOriginale.Replace("$/Area/$", sezione.AreaProgettoDescrizione);
|
||
break;
|
||
#endregion
|
||
|
||
#region AreaProgetto
|
||
case "AreaProgetto":
|
||
if (sezione.AreaProgettoCodice.ToLower() != "inv")
|
||
testoOriginale = testoOriginale.Replace("$/AreaProgetto/$", sezione.AreaProgettoDescrizione);
|
||
else
|
||
testoOriginale = testoOriginale.Replace("$/AreaProgetto/$", sezione.NomeProgetto);
|
||
|
||
break;
|
||
#endregion
|
||
}
|
||
}
|
||
|
||
return testoOriginale;
|
||
}
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// Sostituisce le variabili presenti nel testo (indicate con $/...../$ con il valore corrispondente
|
||
/// I dati vengono presi dalle propriet<65> dell'oggetto sezione passato in input.
|
||
/// Aggiunge gli apici all'inizio e alla fine del testo da rimpiazzato (solo per i nomi dei progetti investimento).
|
||
/// </summary>
|
||
/// <param name="testodarimpiazzare">testo</param>
|
||
/// <param name="sezione">oggetto sezione da cui prendere i dati</param>
|
||
/// <param name="aggiuntaapici">Se true aggiunge le virgolette (apici) prima e dopo il testo sostituito</param>
|
||
/// <returns></returns>
|
||
public static string ReplaceVariables(string testodarimpiazzare, SezioneReport sezione, bool aggiuntaapici)
|
||
{
|
||
string testoOriginale = testodarimpiazzare;
|
||
char[] define = { '$', '/', ',', '.' };
|
||
|
||
const char Space = ' ';
|
||
|
||
char[] delimiters = new char[]
|
||
{
|
||
Space
|
||
};
|
||
|
||
|
||
// split the string and then iterate over the
|
||
// resulting array of strings
|
||
if (testodarimpiazzare != " ")
|
||
foreach (string variabile in testodarimpiazzare.Split(delimiters))
|
||
{
|
||
string app = variabile.TrimStart(define);
|
||
app = app.TrimEnd(define);
|
||
switch (app)
|
||
{
|
||
#region Area
|
||
case "Area":
|
||
testoOriginale = testoOriginale.Replace("$/Area/$", sezione.AreaProgettoDescrizione);
|
||
break;
|
||
#endregion
|
||
|
||
#region AreaProgetto
|
||
case "AreaProgetto":
|
||
if (sezione.AreaProgettoCodice.ToLower() != "inv")
|
||
testoOriginale = testoOriginale.Replace("$/AreaProgetto/$", sezione.AreaProgettoDescrizione);
|
||
else
|
||
{
|
||
if (aggiuntaapici)
|
||
testoOriginale = testoOriginale.Replace("$/AreaProgetto/$", "''" + sezione.NomeProgetto + "''");
|
||
else
|
||
testoOriginale = testoOriginale.Replace("$/AreaProgetto/$", sezione.NomeProgetto);
|
||
}
|
||
break;
|
||
#endregion
|
||
}
|
||
}
|
||
|
||
return testoOriginale;
|
||
}
|
||
|
||
/// <summary>
|
||
/// Return the Risk Class depending on the passed value
|
||
/// <Owner> Marian Zaki</Owner>
|
||
/// <Date> 04052010 </Date>
|
||
/// </summary>
|
||
/// <param name="riskCreditClass">
|
||
/// case 1: Class 1
|
||
/// case 2: Class 2
|
||
/// case 3: Class 3
|
||
/// </param>
|
||
/// <returns> The class name </returns>
|
||
public static string GetRiskCreditClassName(string riskCreditClass)
|
||
{
|
||
float riskCreditClassFloatValue;
|
||
int riskCreditClassValue = 0;
|
||
string className = string.Empty;
|
||
if (float.TryParse(riskCreditClass, out riskCreditClassFloatValue))
|
||
{
|
||
riskCreditClassValue = Convert.ToInt32(riskCreditClassFloatValue);
|
||
}
|
||
else if (int.TryParse(riskCreditClass, out riskCreditClassValue)) { }
|
||
|
||
if (riskCreditClassValue != 0)
|
||
{
|
||
|
||
switch (riskCreditClassValue)
|
||
{
|
||
case 1:
|
||
className = Resource.RiskCreditClass1;
|
||
break;
|
||
case 2:
|
||
className = Resource.RiskCreditClass2;
|
||
break;
|
||
case 3:
|
||
className = Resource.RiskCreditClass3;
|
||
break;
|
||
case 4:
|
||
className = Resource.RiskCreditOltreClasse3;
|
||
break;
|
||
default:
|
||
className = string.Empty;
|
||
break;
|
||
|
||
}
|
||
|
||
return className;
|
||
}
|
||
else
|
||
return string.Empty;
|
||
}
|
||
|
||
|
||
public static string GetRiskCreditEmitClassName(string riskCreditClass)
|
||
{
|
||
float riskCreditClassFloatValue;
|
||
int riskCreditClassValue = 0;
|
||
string className = string.Empty;
|
||
if (float.TryParse(riskCreditClass, out riskCreditClassFloatValue))
|
||
{
|
||
riskCreditClassValue = Convert.ToInt32(riskCreditClassFloatValue);
|
||
}
|
||
else if (int.TryParse(riskCreditClass, out riskCreditClassValue)) { }
|
||
|
||
if (riskCreditClassValue != 0)
|
||
{
|
||
|
||
switch (riskCreditClassValue)
|
||
{
|
||
case 1:
|
||
className = Resource.RiskCreditClassEmit1;
|
||
break;
|
||
case 2:
|
||
className = Resource.RiskCreditClassEmit2;
|
||
break;
|
||
case 3:
|
||
className = Resource.RiskCreditClassEmit3;
|
||
break;
|
||
case 4:
|
||
className = Resource.RiskCreditClassEmit4;
|
||
break;
|
||
case 5:
|
||
className = Resource.RiskCreditClassEmit5;
|
||
break;
|
||
case 6:
|
||
className = Resource.RiskCreditClassEmit6;
|
||
break;
|
||
case 7:
|
||
className = Resource.RiskCreditClassEmit7;
|
||
break;
|
||
case 8:
|
||
className = Resource.RiskCreditClassEmit8;
|
||
break;
|
||
case 9:
|
||
className = Resource.RiskCreditClassEmit9;
|
||
break;
|
||
case 10:
|
||
className = Resource.RiskCreditClassEmit10;
|
||
break;
|
||
default:
|
||
className = string.Empty;
|
||
break;
|
||
|
||
}
|
||
|
||
return className;
|
||
}
|
||
else
|
||
return string.Empty;
|
||
}
|
||
|
||
/****************** coversione tabella\lista per store procedure Pino 14/12/2021 *****************************************************/
|
||
public static List<T> ConvertTo<T>(DataTable datatable) where T : new()
|
||
{
|
||
List<T> Temp = new List<T>();
|
||
try
|
||
{
|
||
List<string> columnsNames = new List<string>();
|
||
foreach (DataColumn DataColumn in datatable.Columns)
|
||
columnsNames.Add(DataColumn.ColumnName);
|
||
Temp = datatable.AsEnumerable().ToList().ConvertAll<T>(row => getObject<T>(row, columnsNames));
|
||
return Temp;
|
||
}
|
||
catch
|
||
{
|
||
return Temp;
|
||
}
|
||
}
|
||
|
||
public static T getObject<T>(DataRow row, List<string> columnsName) where T : new()
|
||
{
|
||
T obj = new T();
|
||
try
|
||
{
|
||
string columnname = "";
|
||
string value = "";
|
||
PropertyInfo[] Properties;
|
||
Properties = typeof(T).GetProperties();
|
||
foreach (PropertyInfo objProperty in Properties)
|
||
{
|
||
columnname = columnsName.Find(name => name.ToLower() == objProperty.Name.ToLower());
|
||
if (!string.IsNullOrEmpty(columnname))
|
||
{
|
||
value = row[columnname].ToString();
|
||
if (!string.IsNullOrEmpty(value))
|
||
{
|
||
if (Nullable.GetUnderlyingType(objProperty.PropertyType) != null)
|
||
{
|
||
value = row[columnname].ToString().Replace("$", "").Replace(",", "");
|
||
objProperty.SetValue(obj, Convert.ChangeType(value, Type.GetType(Nullable.GetUnderlyingType(objProperty.PropertyType).ToString())), null);
|
||
}
|
||
else
|
||
{
|
||
value = row[columnname].ToString().Replace("%", "");
|
||
objProperty.SetValue(obj, Convert.ChangeType(value, Type.GetType(objProperty.PropertyType.ToString())), null);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
return obj;
|
||
}
|
||
catch
|
||
{
|
||
return obj;
|
||
}
|
||
}
|
||
|
||
public static DataTable ToDataTable<T>(IList<T> data)
|
||
{
|
||
PropertyDescriptorCollection props = TypeDescriptor.GetProperties(typeof(T));
|
||
DataTable table = new DataTable();
|
||
for (int i = 0; i < props.Count; i++)
|
||
{
|
||
PropertyDescriptor prop = props[i];
|
||
table.Columns.Add(prop.Name, Nullable.GetUnderlyingType(prop.PropertyType) ?? prop.PropertyType);
|
||
}
|
||
object[] values = new object[props.Count];
|
||
foreach (T item in data)
|
||
{
|
||
for (int i = 0; i < values.Length; i++)
|
||
values[i] = props[i].GetValue(item) ?? DBNull.Value;
|
||
table.Rows.Add(values);
|
||
}
|
||
return table;
|
||
}
|
||
/**************************************************************************************************************************************/
|
||
|
||
/**************** ESG - formattazione valore con n numeri decimali - Pino**********************/
|
||
public static string FormatDecimal(string value, int decimals)
|
||
{
|
||
decimal decimalValue;
|
||
var stringReturn = value;
|
||
var sdecimals = new string('0', decimals);
|
||
|
||
if (!Decimal.TryParse(value, NumberStyles.Number, null, out decimalValue)) return stringReturn;
|
||
//var stringFormat = "{0:0." + String.Format("{0}", sdecimals) + "}";
|
||
|
||
//stringReturn = String.Format(stringFormat, decimalValue);
|
||
|
||
stringReturn = decimalValue.ToString("#,##0.00", CultureInfo.CurrentCulture.NumberFormat);
|
||
|
||
|
||
return stringReturn;
|
||
}
|
||
/**********************************************************************************************/
|
||
|
||
public static float GetWidthProportional(float value, float maxvalue, float width)
|
||
{
|
||
return (width * value) / maxvalue;
|
||
}
|
||
|
||
public static string FormatCurrency(string value)
|
||
{
|
||
decimal decimalValue;
|
||
var stringReturn = value;
|
||
|
||
|
||
|
||
if (Decimal.TryParse(value, NumberStyles.Number, null, out decimalValue))
|
||
stringReturn = Convert.ToDecimal(value).ToString("#,##0.00");
|
||
|
||
|
||
|
||
return stringReturn;
|
||
}
|
||
|
||
public void Dispose()
|
||
{
|
||
|
||
}
|
||
}
|
||
|
||
public class CtvNotCoverede
|
||
{
|
||
public string RETE { get; set; }
|
||
public string COD_FISCALE { get; set; }
|
||
public string INTERMEDIARIO { get; set; }
|
||
public string ORDINE { get; set; }
|
||
public decimal CTV_TOT { get; set; }
|
||
public decimal CTV_notCovered { get; set; }
|
||
public decimal CTV_CreditRisk { get; set; }
|
||
public string CTV_Na { get; set; }
|
||
public decimal PERK_CreditRisk { get; set; }
|
||
public string PERK_NA { get; set; }
|
||
|
||
//public string RETE1 { get => RETE; set => RETE = value; }
|
||
//public string COD_FISCALE1 { get => COD_FISCALE; set => COD_FISCALE = value; }
|
||
//public string INTERMEDIARIO1 { get => INTERMEDIARIO; set => INTERMEDIARIO = value; }
|
||
//public string ORDINE1 { get => ORDINE; set => ORDINE = value; }
|
||
//public decimal CTV_TOT1 { get => CTV_TOT; set => CTV_TOT = value; }
|
||
//public decimal CTV_notCovered1 { get => CTV_notCovered; set => CTV_notCovered = value; }
|
||
//public decimal CTV_CreditRisk1 { get => CTV_CreditRisk; set => CTV_CreditRisk = value; }
|
||
//public string CTV_Na1 { get => CTV_Na; set => CTV_Na = value; }
|
||
//public decimal PERK_CreditRisk1 { get => PERK_CreditRisk; set => PERK_CreditRisk = value; }
|
||
//public string PERK_NA1 { get => PERK_NA; set => PERK_NA = value; }
|
||
}
|
||
}
|