941 lines
43 KiB
C#
941 lines
43 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.Collections.Specialized;
|
||
using System.Configuration;
|
||
using System.Data;
|
||
using System.Diagnostics;
|
||
using System.Globalization;
|
||
using System.Threading;
|
||
using Amib.Threading;
|
||
using PDFGenerator.BusinessLayer;
|
||
using PipelineLib;
|
||
using NUnit.Framework;
|
||
using System.IO;
|
||
using DataAccessLayer;
|
||
using System.Collections;
|
||
using NLog;
|
||
using System.Data.SqlClient;
|
||
using System.Text;
|
||
using System.Xml.Linq;
|
||
|
||
namespace PDFGenerator
|
||
{
|
||
public class PDFGenerator
|
||
{
|
||
private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
|
||
|
||
private SmartThreadPool _smartThreadPool;
|
||
private DataThread _dataThread;
|
||
private ReportTipo _reportType;
|
||
private string _tipoReport;
|
||
private int _maxPDFGeneratorThreads;
|
||
private List<SessionStruct> _tabelleSessione;
|
||
|
||
public PDFGenerator()
|
||
{
|
||
Thread.CurrentThread.CurrentCulture = new CultureInfo(CACHE.CultureToUse);
|
||
Thread.CurrentThread.CurrentUICulture = new CultureInfo(CACHE.CultureToUse);
|
||
}
|
||
|
||
public PDFGenerator(List<SessionStruct> tabelleSessione, DataThread dataThread) : this()
|
||
{
|
||
_dataThread = dataThread;
|
||
_tipoReport = dataThread.TipoReport;
|
||
_reportType = dataThread.ReportType();
|
||
_tabelleSessione = tabelleSessione;
|
||
}
|
||
|
||
public int Create()
|
||
{
|
||
//string ambiente = CACHE.AMBIENTE;
|
||
//string cawTo_Bin = ConfigurationManager.AppSettings["cawTo_Bin"];
|
||
string includeCommercialLetter = ConfigurationManager.AppSettings["IncludeCommercialLetter"];
|
||
bool bScrittoPDf = false;
|
||
DocumentPDF docPDF = null;
|
||
|
||
var sqlparameters = new List<SqlParameter>()
|
||
{ new SqlParameter("Rete",_dataThread.Rete),
|
||
new SqlParameter("CodiceFiscale",_dataThread.CodiceFiscale)
|
||
};
|
||
|
||
try
|
||
{
|
||
|
||
docPDF = new DocumentPDF(_dataThread, _tipoReport);
|
||
_dataThread.DocumentPDF = docPDF;
|
||
|
||
//Thread POOL PER LE QUERY
|
||
docPDF.insertCliente();
|
||
bool bCreaReport = this.createReport(docPDF);
|
||
if (bCreaReport)
|
||
{
|
||
docPDF.inserisciLettera();
|
||
}
|
||
|
||
if (CACHE.includecommercialletter)
|
||
{
|
||
docPDF.inserisciCommercialeLettera();
|
||
}
|
||
|
||
int identificativo = 0;
|
||
if (CACHE.SavePDFtoDISK==0)
|
||
{// LETTERE MASSIVO
|
||
identificativo = docPDF.insertIntoDB(_dataThread);
|
||
}
|
||
|
||
int identityReport = 0;
|
||
|
||
//gestione Rigenerazione Report
|
||
if (CACHE.Periodico)
|
||
{
|
||
// lettura IDentityReport
|
||
identityReport = docPDF.getIdentityReport(_dataThread.Rete, _dataThread.CodiceFiscale, _dataThread.TipoReport.Substring(0, 1));
|
||
// Verifca e Cancellazione Del Report
|
||
docPDF.deleteReportSuFileSystem(identityReport, _dataThread.NomeFileReport);
|
||
// Fine Gestione rigenerazione Report
|
||
}
|
||
|
||
if (CACHE.QueryInserimentoPDF_FTP != "")
|
||
{
|
||
identificativo = UtilityBusinessLayer.setEndThread(_dataThread, identificativo, docPDF.NumPage);
|
||
}
|
||
|
||
if (identityReport < 0)
|
||
{
|
||
try
|
||
{
|
||
logger.Debugs(identityReport.ToString());
|
||
string sp = ConfigurationManager.AppSettings.Get("SP_GESTIONE_PDF_REVERT_FISCAL_CODE");
|
||
using (SQLServer db = new SQLServer())
|
||
{
|
||
db.executeNonQueryWT(sp, sqlparameters);
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
logger.Errors(ex);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (docPDF != null)
|
||
{
|
||
bScrittoPDf = docPDF.scriviSuFileSystem(identificativo);
|
||
}
|
||
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
logger.Errors(ex);
|
||
}
|
||
finally
|
||
{
|
||
_dataThread.DocumentPDF = docPDF;
|
||
docPDF = null;
|
||
}
|
||
|
||
return (bScrittoPDf ? 0 : -1);
|
||
|
||
}
|
||
|
||
public int InserisciTest(DataThread th)
|
||
{// RECUPEROPDF
|
||
int esito = 0;
|
||
DocumentPDF doc = new DocumentPDF();
|
||
{
|
||
try
|
||
{
|
||
esito = doc.insertIntoDBTest(th);
|
||
if (esito > 0)
|
||
{
|
||
logger.Debug("Inserito record in C6ReportFisico con identificativo=" + esito.ToString());
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
logger.Debugs($"Errore nell'inserimento in C6ReportFisico relativo al CF='{th.CodiceFiscale}' e Rete='{th.Rete}'");
|
||
logger.Errors(ex);
|
||
}
|
||
}
|
||
doc = null;
|
||
return esito;
|
||
}
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// Popola l'oggetto Report.
|
||
/// </summary>
|
||
/// <param name="doc"></param>
|
||
/// <returns></returns>
|
||
private bool createReport(DocumentPDF doc)
|
||
{
|
||
// Creo l'oggetto REPORT al quale aggiungero i Capitoli
|
||
Report report = new Report(_reportType.TipoReport);
|
||
|
||
// recupero gli eventuali intermediari
|
||
DataTable dtIntermediari = new DataTable();
|
||
dtIntermediari = GetIntermediari();
|
||
|
||
DataSet dsProdottiProtetti = new DataSet();
|
||
if (report.Tipo == TipologiaReport.MONITORAGGIO)
|
||
{
|
||
DataTable dtProdottiProtetti = GetProdottiProtetti();
|
||
if (dtProdottiProtetti != null)
|
||
{
|
||
dtProdottiProtetti.TableName = "ProdottiProtetti";
|
||
dsProdottiProtetti.Tables.Add(dtProdottiProtetti.Copy());
|
||
}
|
||
}
|
||
|
||
DataSet dsBonus = new DataSet();
|
||
if (report.Tipo == TipologiaReport.MONITORAGGIO)
|
||
{
|
||
DataTable dtBonus = GetBonus();
|
||
if (dtBonus != null)
|
||
{
|
||
dtBonus.TableName = "Bonus";
|
||
dsBonus.Tables.Add(dtBonus.Copy());
|
||
}
|
||
|
||
}
|
||
|
||
DataSet dsAreeBisognoProgetto = new DataSet();
|
||
if (report.Tipo == TipologiaReport.MONITORAGGIO)
|
||
{
|
||
// recupero le aree/progetto da stampare per il dettaglio del monitoraggio
|
||
DataTable dtAreeProgettiMonitorati = GetAreeMonitorate();
|
||
|
||
if (dtAreeProgettiMonitorati == null)
|
||
{
|
||
dtAreeProgettiMonitorati = new DataTable("AreeMonitorate");
|
||
dtAreeProgettiMonitorati.Columns.Add(new DataColumn("NEED_AREA", typeof(string)));
|
||
dtAreeProgettiMonitorati.Columns.Add(new DataColumn("NEED_ESTESA", typeof(string)));
|
||
dtAreeProgettiMonitorati.Columns.Add(new DataColumn("NOME_PROGETTO", typeof(string)));
|
||
dtAreeProgettiMonitorati.Columns.Add(new DataColumn("ORDINAMENTO_PROGETTO", typeof(string)));
|
||
dtAreeProgettiMonitorati.Columns.Add(new DataColumn("ORDINE", typeof(int)));
|
||
dtAreeProgettiMonitorati.Columns.Add(new DataColumn("AREAPROGETTOSOTTOMONITORAGGIO", typeof(Int32)));
|
||
}
|
||
|
||
dtAreeProgettiMonitorati.TableName = "AreeMonitorate";
|
||
//MIFID2 20180529 inserimento del numero delle aree nel document
|
||
doc.AreasCount = dtAreeProgettiMonitorati.Rows.Count;
|
||
doc.Areas = dtAreeProgettiMonitorati;
|
||
//--MIFID2
|
||
dsAreeBisognoProgetto.Tables.Add(dtAreeProgettiMonitorati.Copy());
|
||
}
|
||
|
||
//Recupero tutti i dati sia dei capitoli, sia dei paragrafi che delle sezioni
|
||
DataTable tabellaDati = getData(_reportType.IdReport, _reportType.IdModello);
|
||
|
||
|
||
/********************************** Fix Ramo parallelo per SP delle Percentuali 23/10/2020 --Pino *********************************************/
|
||
if (tabellaDati != null)
|
||
{
|
||
foreach (var item in tabellaDati.AsEnumerable())
|
||
{
|
||
if ((item.Field<int>("idSezione") == 13) && (item.Field<string>("codiceSezione") == "S80ALT"))
|
||
{
|
||
string Banca = "";
|
||
if (_dataThread.Rete == "W")
|
||
Banca = "IW Private Investments.";
|
||
else if (_dataThread.Rete == "S")
|
||
Banca = "Fideuram S.p.A., commercializzato tramite la rete di private banker Sanpaolo Invest.";
|
||
else
|
||
Banca = "Fideuram.";
|
||
item.SetField<string>("querySqlSezione", "[C6MartPeriodico].PL_S80Alternativa_perc");
|
||
string testoSezione = string.Concat("Nella tabella pu<70> verificare come si <20> evoluto l<>ammontare del Suo patrimonio dall<6C>attivazione del monitoraggio. Sono inoltre riportate, per ogni area di bisogno, l'allocazione ottimale (", @"""Piramide Modello""", ") corrente, al precedente invio del report e all<6C>attivazione del monitoraggio, delle risorse finanziarie che lei detiene presso " + Banca);
|
||
item.SetField<string>("testoSezione", testoSezione);
|
||
}
|
||
}
|
||
}
|
||
|
||
_dataThread.Schema = tabellaDati;
|
||
|
||
//Recupero tutti i vincoli delle sezioni
|
||
DataTable tabellaVincoli = getDataVincoli(_reportType.IdModello);
|
||
|
||
// Associo l'oggetto DocumentPDF gi<67> creato alla propriet<65> DocumentPDF del Report.
|
||
report.DocumentPDF = doc;
|
||
|
||
//Recupero i capitoli.
|
||
DataView viewCapitoli = new DataView(tabellaDati);
|
||
DataTable tabellaCapitoli = viewCapitoli.ToTable(true, "idCapitolo", "titoloCapitolo", "testoCapitolo", "testoCapitoloAlternativo", "querySqlCapitolo", "nuovaPaginaCapitolo");
|
||
|
||
//Aggiungo tutti i capitoli al report.
|
||
foreach (DataRow rowCapitoli in tabellaCapitoli.Rows)
|
||
{
|
||
CapitoloReport capitolo;
|
||
if (rowCapitoli["querySqlCapitolo"].ToString().ToLower() == "intermediario")
|
||
{
|
||
if (dtIntermediari.Rows.Count == 1)
|
||
{
|
||
capitolo = new CapitoloReport(Convert.ToInt32(rowCapitoli["idCapitolo"]), rowCapitoli);
|
||
capitolo.Intermediario = dtIntermediari.Rows[0]["Intermediario"].ToString();
|
||
|
||
if (capitolo.Intermediario.ToLower() == "altro")
|
||
capitolo.Titolo = "Dettaglio Altro intermediario";
|
||
else
|
||
{
|
||
capitolo.Titolo = "Dettaglio " + capitolo.Intermediario;
|
||
capitolo.TestoIntroduttivo = "Questo capitolo fornisce una rappresentazione del patrimonio finanziario che Lei detiene presso " + capitolo.Intermediario + ".";
|
||
}
|
||
|
||
AddParagrafiToCapitolo(capitolo, tabellaDati, tabellaVincoli, null);
|
||
// aggiunge il capitolo al report
|
||
report.Add(capitolo);
|
||
}
|
||
else
|
||
{
|
||
capitolo = new CapitoloReport(Convert.ToInt32(rowCapitoli["idCapitolo"]), rowCapitoli);
|
||
AddParagrafiToCapitolo(capitolo, tabellaDati, tabellaVincoli, null);
|
||
// aggiunge il capitolo al report
|
||
report.Add(capitolo);
|
||
}
|
||
}
|
||
|
||
//Adriano 20171109 per gestire l'esclusione dei prodotto a capitale protetto se non esistono per il cliente corrente.
|
||
else if (rowCapitoli["querySqlCapitolo"].ToString().ToLower().Equals("prodottiprotetti"))
|
||
{
|
||
|
||
if (dsProdottiProtetti.Tables.Count > 0 && dsProdottiProtetti.Tables[0].Rows.Count > 0)
|
||
{
|
||
capitolo = new CapitoloReport(Convert.ToInt32(rowCapitoli["idCapitolo"]), rowCapitoli);
|
||
capitolo.Intermediario = string.Empty;
|
||
AddParagrafiToCapitolo(capitolo, tabellaDati, tabellaVincoli, dsProdottiProtetti);
|
||
// aggiunge il capitolo al report
|
||
report.Add(capitolo);
|
||
}
|
||
|
||
}
|
||
//--Adriano
|
||
|
||
//Adriano 20171117 per gestire l'esclusione dei bonus se non esistono per il cliente corrente.
|
||
else if (rowCapitoli["querySqlCapitolo"].ToString().ToLower().Equals("bonus"))
|
||
{
|
||
|
||
if (dsBonus.Tables.Count > 0 && dsBonus.Tables[0].Rows.Count > 0)
|
||
{
|
||
capitolo = new CapitoloReport(Convert.ToInt32(rowCapitoli["idCapitolo"]), rowCapitoli);
|
||
capitolo.Intermediario = string.Empty;
|
||
AddParagrafiToCapitolo(capitolo, tabellaDati, tabellaVincoli, dsBonus);
|
||
// aggiunge il capitolo al report
|
||
report.Add(capitolo);
|
||
}
|
||
|
||
}
|
||
//--Adriano
|
||
|
||
else if (rowCapitoli["querySqlCapitolo"].ToString() == string.Empty)
|
||
{
|
||
capitolo = new CapitoloReport(Convert.ToInt32(rowCapitoli["idCapitolo"]), rowCapitoli);
|
||
capitolo.Intermediario = string.Empty;
|
||
AddParagrafiToCapitolo(capitolo, tabellaDati, tabellaVincoli, dsAreeBisognoProgetto);
|
||
// aggiunge il capitolo al report
|
||
report.Add(capitolo);
|
||
}
|
||
}
|
||
|
||
// Disegno il Report.
|
||
report.Disegna();
|
||
return true;
|
||
|
||
}
|
||
|
||
/// <summary>
|
||
/// Aggiunge i paragrafi al capitolo passato in input.
|
||
/// </summary>
|
||
/// <param name="capitolo"></param>
|
||
/// <param name="tabellaDati"></param>
|
||
/// <param name="tabellaVincoli"></param>
|
||
/// <param name="dsAreeBisognoProgetto"></param>
|
||
private void AddParagrafiToCapitolo(CapitoloReport capitolo, DataTable tabellaDati, DataTable tabellaVincoli, DataSet dsAreeBisognoProgetto)
|
||
{
|
||
//Recupero i paragrafi per ogni capitolo.
|
||
DataView viewParagrafo = new DataView(tabellaDati);
|
||
viewParagrafo.RowFilter = "idCapitolo = " + capitolo.Id.ToString();
|
||
DataTable tabellaParagrafi = viewParagrafo.ToTable(true, "idParagrafo", "ordineParagrafo", "titoloParagrafo", "sottoTitoloParagrafo", "testoParagrafo", "querySqlParagrafo", "indicizzatoParagrafo", "SpazioNecessarioSezioneSuccessiva");
|
||
|
||
ParagrafoReport paragrafo = null;
|
||
int idParagrafo = -1;
|
||
|
||
foreach (DataRow rowParagrafi in tabellaParagrafi.Rows)
|
||
{
|
||
idParagrafo = Convert.ToInt32(rowParagrafi["idParagrafo"]);
|
||
paragrafo = new ParagrafoReport(Convert.ToInt32(rowParagrafi["idParagrafo"]), rowParagrafi);
|
||
paragrafo.SpazioNecessarioSezioneSuccessiva = rowParagrafi["SpazioNecessarioSezioneSuccessiva"] == DBNull.Value ? 0 : Convert.ToInt32(rowParagrafi["SpazioNecessarioSezioneSuccessiva"]);
|
||
|
||
#region Rischio Credito
|
||
if (rowParagrafi["querySqlParagrafo"].ToString().ToLower() == "rischiocredito")
|
||
{
|
||
if (_tipoReport.ToUpper() == "DIAGNOSI")
|
||
{
|
||
// recupero gli eventuali intermediari
|
||
DataTable dtIntermediari = new DataTable();
|
||
dtIntermediari = GetIntermediari();
|
||
|
||
//Se ho solo un intermediario faccio vedere solo la 102 e 103 per fideuram, altrimenti devo mostrare complessivo, fideuram e altri instituti
|
||
if (dtIntermediari.Rows.Count >= 1)
|
||
{
|
||
//COMPLESSIVO
|
||
paragrafo = new ParagrafoReport(Convert.ToInt32(rowParagrafi["idParagrafo"]), rowParagrafi);
|
||
//Per come <20> fatto il paragrafo del rischio credito il titolo lo metto a codice altrimenti dovevo aggiungere un capitolo non indicizzato
|
||
paragrafo.Titolo = "Approfondimento Rischio Credito";
|
||
paragrafo.SpazioNecessarioSezioneSuccessiva = rowParagrafi["SpazioNecessarioSezioneSuccessiva"] == DBNull.Value ? 0 : Convert.ToInt32(rowParagrafi["SpazioNecessarioSezioneSuccessiva"]);
|
||
paragrafo.IntermediarioPar = "Complessivo";
|
||
AddSezioniToParagrafo(capitolo, paragrafo, tabellaDati, tabellaVincoli);
|
||
capitolo.Add(paragrafo);
|
||
|
||
//FIDEURAM
|
||
paragrafo = new ParagrafoReport(Convert.ToInt32(rowParagrafi["idParagrafo"]), rowParagrafi);
|
||
paragrafo.SpazioNecessarioSezioneSuccessiva = rowParagrafi["SpazioNecessarioSezioneSuccessiva"] == DBNull.Value ? 0 : Convert.ToInt32(rowParagrafi["SpazioNecessarioSezioneSuccessiva"]);
|
||
paragrafo.IntermediarioPar = "BF";
|
||
AddSezioniToParagrafo(capitolo, paragrafo, tabellaDati, tabellaVincoli);
|
||
capitolo.Add(paragrafo);
|
||
|
||
foreach (DataRow inter in dtIntermediari.Rows)
|
||
{
|
||
paragrafo = new ParagrafoReport(Convert.ToInt32(rowParagrafi["idParagrafo"]), rowParagrafi);
|
||
paragrafo.SpazioNecessarioSezioneSuccessiva = rowParagrafi["SpazioNecessarioSezioneSuccessiva"] == DBNull.Value ? 0 : Convert.ToInt32(rowParagrafi["SpazioNecessarioSezioneSuccessiva"]);
|
||
paragrafo.IntermediarioPar = inter["Intermediario"].ToString();
|
||
AddSezioniToParagrafo(capitolo, paragrafo, tabellaDati, tabellaVincoli);
|
||
capitolo.Add(paragrafo);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
paragrafo.Titolo = "Approfondimento Rischio Credito";
|
||
paragrafo.IntermediarioPar = "BF";
|
||
AddSezioniToParagrafo(capitolo, paragrafo, tabellaDati, tabellaVincoli);
|
||
// aggiunge il paragrafo al capitolo
|
||
capitolo.Add(paragrafo);
|
||
}
|
||
}
|
||
else //Monitoraggio
|
||
{
|
||
paragrafo.Titolo = "Approfondimento Rischio Credito";
|
||
|
||
AddSezioniToParagrafo(capitolo, paragrafo, tabellaDati, tabellaVincoli);
|
||
// aggiunge il paragrafo al capitolo
|
||
capitolo.Add(paragrafo);
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region Rischio Credito New
|
||
|
||
else if (rowParagrafi["querySqlParagrafo"].ToString().ToLower() == "rischiocreditonew")
|
||
{
|
||
if (_tipoReport.ToUpper() == "DIAGNOSI")
|
||
{
|
||
// recupero gli eventuali intermediari
|
||
DataTable dtIntermediari = new DataTable();
|
||
dtIntermediari = GetIntermediari();
|
||
|
||
//Se ho solo un intermediario faccio vedere solo la 102 e 103 per fideuram, altrimenti devo mostrare complessivo, fideuram e altri instituti
|
||
if (dtIntermediari.Rows.Count >= 1)
|
||
{
|
||
|
||
|
||
//FIDEURAM
|
||
paragrafo = new ParagrafoReport(Convert.ToInt32(rowParagrafi["idParagrafo"]), rowParagrafi);
|
||
paragrafo.SpazioNecessarioSezioneSuccessiva = rowParagrafi["SpazioNecessarioSezioneSuccessiva"] == DBNull.Value ? 0 : Convert.ToInt32(rowParagrafi["SpazioNecessarioSezioneSuccessiva"]);
|
||
paragrafo.IntermediarioPar = "BF";
|
||
AddSezioniToParagrafo(capitolo, paragrafo, tabellaDati, tabellaVincoli);
|
||
capitolo.Add(paragrafo);
|
||
|
||
//foreach (DataRow inter in dtIntermediari.Rows)
|
||
//{
|
||
paragrafo = new ParagrafoReport(Convert.ToInt32(rowParagrafi["idParagrafo"]), rowParagrafi);
|
||
paragrafo.SpazioNecessarioSezioneSuccessiva = rowParagrafi["SpazioNecessarioSezioneSuccessiva"] == DBNull.Value ? 0 : Convert.ToInt32(rowParagrafi["SpazioNecessarioSezioneSuccessiva"]);
|
||
//paragrafo.IntermediarioPar = inter["Intermediario"].ToString();
|
||
paragrafo.IntermediarioPar = "Altri Istituti";
|
||
AddSezioniToParagrafo(capitolo, paragrafo, tabellaDati, tabellaVincoli);
|
||
capitolo.Add(paragrafo);
|
||
//}
|
||
|
||
//COMPLESSIVO
|
||
paragrafo = new ParagrafoReport(Convert.ToInt32(rowParagrafi["idParagrafo"]), rowParagrafi);
|
||
//Per come <20> fatto il paragrafo del rischio credito il titolo lo metto a codice altrimenti dovevo aggiungere un capitolo non indicizzato
|
||
paragrafo.Titolo = "Approfondimento Rischio Credito";
|
||
paragrafo.SpazioNecessarioSezioneSuccessiva = rowParagrafi["SpazioNecessarioSezioneSuccessiva"] == DBNull.Value ? 0 : Convert.ToInt32(rowParagrafi["SpazioNecessarioSezioneSuccessiva"]);
|
||
paragrafo.IntermediarioPar = "Complessivo";
|
||
AddSezioniToParagrafo(capitolo, paragrafo, tabellaDati, tabellaVincoli);
|
||
capitolo.Add(paragrafo);
|
||
}
|
||
else
|
||
{
|
||
paragrafo.Titolo = "Approfondimento Rischio Credito";
|
||
paragrafo.IntermediarioPar = "BF";
|
||
AddSezioniToParagrafo(capitolo, paragrafo, tabellaDati, tabellaVincoli);
|
||
// aggiunge il paragrafo al capitolo
|
||
capitolo.Add(paragrafo);
|
||
}
|
||
}
|
||
else //Monitoraggio
|
||
{
|
||
paragrafo.Titolo = "Approfondimento Rischio Credito";
|
||
|
||
AddSezioniToParagrafo(capitolo, paragrafo, tabellaDati, tabellaVincoli);
|
||
// aggiunge il paragrafo al capitolo
|
||
capitolo.Add(paragrafo);
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region Aree Monitorate
|
||
else if (rowParagrafi["querySqlParagrafo"].ToString().ToLower() == "areemonitorate") // duplica i paragrafi per ogni area monitorata.
|
||
{
|
||
int numeroProgettiInvestimento = 0;
|
||
DataRow[] drTotaleProgettiInvestimento = dsAreeBisognoProgetto.Tables["AreeMonitorate"].Select(" Need_Area = 'Inv'");
|
||
int totaleProgettiInvestimento = drTotaleProgettiInvestimento.Length;
|
||
// 28/10/2015 federicaluca
|
||
//int titoloParagrafoInvestimento = 0;
|
||
//
|
||
foreach (DataRow rAreeeMonitorate in dsAreeBisognoProgetto.Tables["AreeMonitorate"].Rows)
|
||
{
|
||
paragrafo = new ParagrafoReport(idParagrafo, rowParagrafi);
|
||
// MIOFOGLIO 20181205 per le Self
|
||
paragrafo.Titolo = rAreeeMonitorate["Need_Estesa"].ToString();
|
||
paragrafo.AreaProgettoDescrizione = rAreeeMonitorate["Need_Estesa"].ToString();
|
||
paragrafo.CodiceAreaSelf = rAreeeMonitorate["Nome_Progetto"].ToString() != null ? rAreeeMonitorate["Nome_Progetto"].ToString() : "";
|
||
//paragrafo.Titolo = rAreeeMonitorate["Need_Estesa"].ToString();
|
||
//paragrafo.AreaProgettoDescrizione = rAreeeMonitorate["Need_Estesa"].ToString();
|
||
//--MIOFOGLIO 20181205 per le Self
|
||
paragrafo.AreaProgettoCodice = rAreeeMonitorate["Need_Area"].ToString();
|
||
paragrafo.AreaProgettoSottoMonitoraggio = rAreeeMonitorate["areaprogettosottomonitoraggio"] == DBNull.Value ? false : Convert.ToBoolean(rAreeeMonitorate["areaprogettosottomonitoraggio"]);
|
||
|
||
//V Spostasto fuori dall'IF se l'area <20> inv
|
||
//Ordinamento progetto (ambito Aree Monitorate) ZINZERI:
|
||
if (//V Il filtro va fatto anche per le aree senza monit altrimenti la S86 non pu<70> filtrare correttamente paragrafo.AreaProgettoSottoMonitoraggio &&
|
||
rAreeeMonitorate["Ordinamento_Progetto"] != null &&
|
||
!rAreeeMonitorate["Ordinamento_Progetto"].Equals(System.DBNull.Value))
|
||
paragrafo.OrdinamentoProgettoPerAreeMonitorate = Convert.ToInt32(rAreeeMonitorate["Ordinamento_Progetto"]);
|
||
|
||
|
||
if (rAreeeMonitorate["Need_Area"].ToString().ToLower() != "inv")
|
||
paragrafo.NomeProgetto = "Default";// string.Empty;
|
||
else // <20> un area di investimento quindi mi recupero anche il nome del progetto.
|
||
{
|
||
//Nome progetto:
|
||
paragrafo.NomeProgetto = rAreeeMonitorate["Nome_Progetto"].ToString();
|
||
|
||
|
||
// Se c'<27> un solo progetto in investimento chiamato "progetto investimento"
|
||
// non deve essere stampato il nome di questo progetto come intestazione del paragrafo (propriet<65> SottoTitolo dell'oggettp paragrafo)
|
||
//if ((totaleProgettiInvestimento == 1 && rAreeeMonitorate["Nome_Progetto"].ToString().ToLower() == "progetto investimento") || (rAreeeMonitorate == null))
|
||
if ((totaleProgettiInvestimento == 1 && rAreeeMonitorate["Nome_Progetto"].ToString().ToLower() == "progetto investimento"))
|
||
|
||
paragrafo.SottoTitolo = string.Empty;
|
||
else
|
||
paragrafo.SottoTitolo = rAreeeMonitorate["Nome_Progetto"].ToString();
|
||
|
||
//Le sezioni useranno questo valore per impostare titoletti ed aspetti vari connessi:
|
||
paragrafo.NumeroProgettiInvestimento = drTotaleProgettiInvestimento.Length;
|
||
|
||
// va indicizzato solo il primo dei paragrafi di investimento nel caso ci siano + progetti.
|
||
// ogni progetto di investimento <20> considerato un paragrafo nuovo.
|
||
|
||
//Modifica per S43BIS, S43 e per Tipo Contratto != 0
|
||
if (numeroProgettiInvestimento > 0)
|
||
paragrafo.Indicizzato = false;
|
||
|
||
if (paragrafo.Id == 61)
|
||
{
|
||
if (paragrafo.AreaProgettoSottoMonitoraggio == true)
|
||
{
|
||
numeroProgettiInvestimento++;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
|
||
numeroProgettiInvestimento++;
|
||
}
|
||
}
|
||
|
||
AddSezioniToParagrafo(capitolo, paragrafo, tabellaDati, tabellaVincoli);
|
||
|
||
// aggiunge il paragrafo al capitolo
|
||
capitolo.Add(paragrafo);
|
||
}
|
||
}
|
||
|
||
#endregion
|
||
|
||
// Adriano 20171117 Gestione del capitale protetto
|
||
#region Prodotti Protetti
|
||
else
|
||
{
|
||
if (rowParagrafi["querySqlParagrafo"].ToString().ToLower() == "prodottiprotetti") // duplica i paragrafi per ogni prodotto protetto.
|
||
{
|
||
foreach (DataRow rProdotti in dsAreeBisognoProgetto.Tables["ProdottiProtetti"].Rows)
|
||
{
|
||
if (rowParagrafi["SottoTitoloParagrafo"].ToString().Equals(rProdotti["TipoParagrafo"]))
|
||
{
|
||
paragrafo = new ParagrafoReport(idParagrafo, rowParagrafi);
|
||
paragrafo.Titolo = (!string.IsNullOrEmpty(rProdotti["Contratto"].ToString())) ?
|
||
string.Concat(rProdotti["DescrizioneProdotto"].ToString(), " - contratto ", rProdotti["Contratto"].ToString()) :
|
||
rProdotti["DescrizioneProdotto"].ToString();
|
||
paragrafo.AreaProgettoCodice = rProdotti["TipoProdotto"].ToString();
|
||
paragrafo.TestoIntroduttivo = paragrafo.TestoIntroduttivo.Replace("$/Prodotto/$", paragrafo.Titolo);
|
||
paragrafo.AreaProgettoDescrizione = rProdotti["Contratto"].ToString();
|
||
AddSezioniToParagrafo(capitolo, paragrafo, tabellaDati, tabellaVincoli);
|
||
// aggiunge il paragrafo al capitolo
|
||
capitolo.Add(paragrafo);
|
||
|
||
}
|
||
}
|
||
}
|
||
#endregion
|
||
//--Adriano
|
||
|
||
else
|
||
{
|
||
AddSezioniToParagrafo(capitolo, paragrafo, tabellaDati, tabellaVincoli);
|
||
// aggiunge il paragrafo al capitolo
|
||
capitolo.Add(paragrafo);
|
||
}
|
||
}
|
||
|
||
|
||
}
|
||
//capitolo.
|
||
}
|
||
|
||
/// <summary>
|
||
/// Aggiunge le sezioni al paragrafo.
|
||
/// Di ciascuna sezione recupera e imposta i vincoli settati a livello di database.
|
||
/// </summary>
|
||
/// <param name="capitolo"></param>
|
||
/// <param name="paragrafo"></param>
|
||
/// <param name="tabellaDati"></param>
|
||
/// <param name="tabellaVincoli"></param>
|
||
private void AddSezioniToParagrafo(CapitoloReport capitolo, ParagrafoReport paragrafo, DataTable tabellaDati, DataTable tabellaVincoli)
|
||
{
|
||
//Recupero le sezioni per ogni paragrafo
|
||
DataView viewSezioni = new DataView(tabellaDati);
|
||
viewSezioni.RowFilter = "idParagrafo = " + paragrafo.Id.ToString() + " AND idCapitolo= " + capitolo.Id.ToString(); // aggiungere il filtro del capitolo
|
||
DataTable tabellaSezioni =
|
||
viewSezioni.ToTable(true, "idSezione", "codiceSezione", "titoloSezione", "testoSezione",
|
||
"testoSezioneAlternativo", "notaSezione", "notaSezioneAlternativo", "querySqlSezione",
|
||
"indicizzatoSezione", "filtroSezione", "nuovaPaginaDopo");
|
||
foreach (DataRow rowSezioni in tabellaSezioni.Rows)
|
||
{
|
||
SezioneReport sezione;
|
||
string codiceSez = rowSezioni["codiceSezione"].ToString();
|
||
|
||
sezione = new SezioneReport(_dataThread, _tabelleSessione, rowSezioni["codiceSezione"].ToString(), rowSezioni);
|
||
sezione.FiltroSezione = rowSezioni["filtroSezione"].ToString();
|
||
//Assegno alla sezione (dovrebbero essere la 102 e 103) l'intermediario definito nel paragrafop
|
||
if (paragrafo.IntermediarioPar != null)
|
||
sezione.IntermediarioSez = paragrafo.IntermediarioPar;
|
||
sezione.AreaProgettoDescrizione = paragrafo.AreaProgettoDescrizione;
|
||
sezione.AreaProgettoCodice = paragrafo.AreaProgettoCodice;
|
||
sezione.NomeProgetto = paragrafo.NomeProgetto;
|
||
sezione.AreaProgettoSottoMonitoraggio = paragrafo.AreaProgettoSottoMonitoraggio;
|
||
sezione.NumeroProgettiInvestimento = paragrafo.NumeroProgettiInvestimento;
|
||
sezione.OrdinamentoProgettoPerAreeMonitorate = paragrafo.OrdinamentoProgettoPerAreeMonitorate;
|
||
sezione.NuovaPaginaDopo = (Boolean)rowSezioni["nuovaPaginaDopo"];
|
||
|
||
// TUOFOGLIO 20181213
|
||
sezione.CodiceAreaSelf = paragrafo.CodiceAreaSelf;
|
||
//--TUOFOGLIO 20181213
|
||
|
||
// recupero i vincoli della sezione e setto la propriet<65> vincolo della stessa.
|
||
if (tabellaVincoli != null)
|
||
{
|
||
DataView viewVincoli = new DataView(tabellaVincoli);
|
||
viewVincoli.RowFilter = ("SezioneFisica = '" + sezione.Codice.Replace("'", "''") + "'");
|
||
DataTable datatableVincoli = viewVincoli.ToTable("datatableVincoli");
|
||
|
||
// Aggiungo i vincoli alla Sezione.
|
||
sezione.ImpostaVincoli(datatableVincoli);
|
||
}
|
||
|
||
//Bido Jan 2011 release
|
||
if (paragrafo.AreaProgettoCodice.ToLower() == "cc")
|
||
{
|
||
//paragrafo.Titolo = "Conti correnti a saldo negativo";
|
||
if (sezione.Codice == "S43BIS")
|
||
{
|
||
sezione.Titolo = string.Empty;
|
||
paragrafo.Add(sezione);
|
||
}
|
||
}
|
||
//End of Bido Jan 2011 release
|
||
|
||
else
|
||
// aggiunge la sezione al paragrafo.
|
||
if (paragrafo.AreaProgettoCodice.ToLower() == "na")
|
||
{
|
||
paragrafo.Titolo = "Risorse non allocate";
|
||
paragrafo.TestoIntroduttivo = "Nella tabella sono elencati i prodotti non ancora allocati sulle aree di bisogno.";
|
||
|
||
if (sezione.Codice == "S43BIS")
|
||
{
|
||
sezione.Titolo = string.Empty;
|
||
if (capitolo.Children.Count > 0)
|
||
{
|
||
ParagrafoReport pervParagrafo = capitolo.Children[capitolo.Children.Count - 1];
|
||
SezioneReport lastSezione = pervParagrafo.Children[pervParagrafo.Children.Count - 1];
|
||
lastSezione.NuovaPaginaDopo = false;
|
||
}
|
||
paragrafo.Add(sezione);
|
||
}
|
||
}
|
||
|
||
else
|
||
|
||
// Per il progetto d'investimento "Prodotti non associati a progetti" stampo solo la S43BIS
|
||
if (sezione.AreaProgettoCodice.ToLower() == "inv" && sezione.NomeProgetto.ToLower() == "prodotti non associati a progetti")
|
||
{
|
||
if (sezione.Codice == "S43BIS")
|
||
paragrafo.Add(sezione);
|
||
}
|
||
//else
|
||
//{
|
||
// paragrafo.Add(sezione);
|
||
//}
|
||
|
||
|
||
|
||
else
|
||
//Adriano 20171115 Gestione prodotti protetti, per inserire la sezione S172 in base al tipo di prodotto (1: Italfund, 2: Fonditalia)
|
||
|
||
if (paragrafo.QuerySql.ToLower().Equals("prodottiprotetti"))
|
||
{
|
||
|
||
switch (paragrafo.AreaProgettoCodice)
|
||
{
|
||
|
||
case "TipoProdotto1":
|
||
{
|
||
sezione.QuerySql = "1";
|
||
break;
|
||
}
|
||
|
||
case "TipoProdotto2":
|
||
{
|
||
sezione.QuerySql = "2";
|
||
sezione.FiltroSezione = paragrafo.AreaProgettoDescrizione;
|
||
break;
|
||
}
|
||
|
||
case "TipoProdotto3":
|
||
{
|
||
sezione.QuerySql = "3";
|
||
sezione.FiltroSezione = paragrafo.AreaProgettoDescrizione;
|
||
break;
|
||
}
|
||
}
|
||
|
||
paragrafo.Add(sezione);
|
||
|
||
}
|
||
|
||
else
|
||
{
|
||
if (sezione.Codice == "S170")
|
||
{
|
||
paragrafo.Titolo = rowSezioni["titoloSezione"].ToString();
|
||
paragrafo.Add(sezione);
|
||
}
|
||
else
|
||
paragrafo.Add(sezione);
|
||
|
||
//paragrafo.Add(sezione);
|
||
}
|
||
//--Adriano
|
||
}
|
||
}
|
||
|
||
|
||
//Adriano 20171113: inserite per gestire l'inclusione dei capitoli sul Capitale Protetto e sul Bonus in base alla presenza di prodotti a capitale protetto e bonus
|
||
|
||
/// <summary>
|
||
/// Recupera eventuali prodotti protetti.
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
private DataTable GetProdottiProtetti()
|
||
{
|
||
|
||
return SectionManager.GetDataSection(_tabelleSessione, "[C6MartPeriodico].[Gestione_ProdottiProtetti]", _dataThread);
|
||
|
||
}
|
||
|
||
/// <summary>
|
||
/// Recupera eventuali bonus.
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
private DataTable GetBonus()
|
||
{
|
||
|
||
return SectionManager.GetDataSection(_tabelleSessione, "[C6MartPeriodico].[Gestione_Bonus]", _dataThread);
|
||
|
||
}
|
||
//--Adriano
|
||
|
||
/// <summary>
|
||
/// Recupera gli intermediari.
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
private DataTable GetIntermediari()
|
||
{
|
||
if (!CACHE.Periodico) // utilizzo come giornaliero
|
||
return SectionManager.GetDataSection(_tabelleSessione, "[C6Mart].[GESTIONE_S_Intermediari]", _dataThread);
|
||
else
|
||
return SectionManager.GetDataSection(_tabelleSessione, "[C6MartPeriodico].[GESTIONE_S_Intermediari]", _dataThread);
|
||
|
||
}
|
||
|
||
/// <summary>
|
||
/// Recupera le aree/progetti da stampare nel dettaglio del monitoraggio.
|
||
/// Originariamente non tutte le aree/progetti venivano stampati e il filtro veniva fatto direttamente sulla [C6MartPeriodico].[PL_AreeMonitorate].
|
||
/// Attualmente la richiesta <20> che devono essere stampate nel dettaglio anche le aree non oggetto di monitoraggio.
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
private DataTable GetAreeMonitorate()
|
||
{
|
||
return SectionManager.GetDataSection(_tabelleSessione, "[C6MartPeriodico].[PL_AreeMonitorate]", _dataThread);
|
||
}
|
||
|
||
/// <summary>
|
||
/// Lancia la R6_S_Generator e recupera i dati di tutto il report.
|
||
/// </summary>
|
||
/// <param name="IdReport"></param>
|
||
/// <param name="IdModello"></param>
|
||
/// <returns></returns>
|
||
private DataTable getData(int IdReport, int IdModello)
|
||
{
|
||
string nomeStoredProcedure = "C6Mart.GESTIONE_C6_S_Generator";
|
||
var parameters = new List<SqlParameter>()
|
||
{
|
||
new SqlParameter
|
||
{
|
||
ParameterName="idReport",
|
||
Value=IdReport
|
||
},
|
||
new SqlParameter
|
||
{
|
||
ParameterName="idModello",
|
||
Value=IdModello
|
||
}
|
||
};
|
||
|
||
if (CACHE.Periodico)
|
||
{
|
||
parameters.Add
|
||
(
|
||
new SqlParameter
|
||
{
|
||
ParameterName = "periodicita",
|
||
Value = "T"
|
||
});
|
||
nomeStoredProcedure = "C6MartPeriodico.GESTIONE_C6_S_Generator";
|
||
}
|
||
|
||
DataTable DtResult = null;
|
||
try
|
||
{
|
||
using (SQLServer db = new SQLServer())
|
||
{
|
||
DtResult = db.GetDataTableFromProcedure(nomeStoredProcedure, parameters);
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
|
||
}
|
||
|
||
return DtResult;
|
||
|
||
}
|
||
|
||
/// <summary>
|
||
/// Lancia la R6_S_Vincoli e recupera i vincoli di tutte le sezioni
|
||
/// </summary>
|
||
/// <param name="IdModello"></param>
|
||
/// <returns></returns>
|
||
private DataTable getDataVincoli(int IdModello)
|
||
{
|
||
List<SqlParameter> parametri = new List<SqlParameter>
|
||
{
|
||
new SqlParameter
|
||
{
|
||
ParameterName="idModello",
|
||
Value = IdModello
|
||
}
|
||
};
|
||
DataTable vincoli = null;
|
||
using (SQLServer db = new SQLServer())
|
||
{
|
||
vincoli = db.GetDataTableFromProcedure("[C6Mart].[GESTIONE_C6_S_Vincoli]", parametri);
|
||
}
|
||
return vincoli;
|
||
}
|
||
|
||
private int getIntFromBitArray(BitArray bitArray)
|
||
{
|
||
if (bitArray.Length > 32)
|
||
throw new ArgumentException("Argument length shall be at most 32 bits.");
|
||
int[] array = new int[1];
|
||
bitArray.CopyTo(array, 0);
|
||
return array[0];
|
||
}
|
||
}
|
||
|
||
public class Worker : Task
|
||
{
|
||
|
||
string query;
|
||
DataThread dataThread;
|
||
List<SessionStruct> tabelleSessione;
|
||
|
||
public Worker(string query, DataThread dt, List<SessionStruct> tabSess)
|
||
{
|
||
this.query = query;
|
||
this.dataThread = dt;
|
||
this.tabelleSessione = tabSess;
|
||
this.taskData = new PipelineContext(dt.CodiceFiscale + "_" + query, this);
|
||
}
|
||
|
||
public override object Elaborate(Dictionary<String, Object> input)
|
||
{
|
||
|
||
SectionManager.GetDataSection(tabelleSessione, query, dataThread);
|
||
return null;
|
||
}
|
||
}
|
||
|
||
public static class PDFEx
|
||
{
|
||
private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
|
||
public static void SETDATA(this DataThread dt)
|
||
{
|
||
if (!CACHE.SetData) return;
|
||
|
||
string traccia = $"[{dt.CodiceFiscale}_{dt.Rete}]";
|
||
if (dt != null && dt.CapitoloReport != null)
|
||
{
|
||
traccia += $"_{dt.CapitoloReport.Titolo}";
|
||
}
|
||
if (dt != null && dt.ParagrafoReport != null)
|
||
{
|
||
traccia += $"_{dt.ParagrafoReport.Titolo}";
|
||
}
|
||
if (dt != null && dt.SezioneReport != null)
|
||
{
|
||
traccia += $"_{dt.SezioneReport.Codice}";
|
||
}
|
||
if (dt != null)
|
||
{
|
||
dt.DocumentPDF.getCurrentPage().Elements.ID = traccia;
|
||
logger.Infos(traccia);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|