2025-06-03 15:11:16 +02:00

245 lines
10 KiB
C#

using PDFGenerator.Presentation.Section;
using PDFGenerator.Presentation.Section.Tables;
using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing.Imaging;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Web;
namespace PDFGenerator.BusinessLayer.DataSection
{
public class S188 : ISezione
{
private static readonly NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
string ambiente = CACHE.AMBIENTE;
int circle_size = CACHE.circle_size;// int.Parse(@UtilityManager.getAppSetting("circle_size"));
string Titolo = string.Empty;
string _testotitolo;
string _testointroduttivo;
public string TestoIntroduttivo
{
get
{
return _testointroduttivo;
}
set
{
_testointroduttivo = value;
}
}
public void setTitolo(string label)
{
Titolo = label;
}
public string TestoTitolo
{
get
{
return _testotitolo;
}
set
{
_testotitolo = value;
}
}
/// <summary>
/// Analisi Portafoglio PAI Ambientali e Sociali
/// </summary>
/// <param name="dataThread"></param>
public void writeSezione(DataThread dataThread)
{
dataThread.SETDATA();
logger.Info("Inizio sezione S188 metodo writeSezione " + dataThread.CodiceFiscale);
DocumentPDF document = dataThread.DocumentPDF;
DSS188AnalisiPortafoglioPAI set = (DSS188AnalisiPortafoglioPAI)dataThread.Data.DatiSezione;
DatiTabella datitabSFRD = new DatiTabella();
DatiTabella datitabTAX = new DatiTabella();
Tabella tab = new Tabella(document.getMargineLeft(), document.getLastPos());
float riferimentoTabella1 = 90;
float riferimentoTabella2 = 90;
int posizioneCerchio1_Y = 240;
int posizioneCerchio2_Y = 380;
DataTable Ambientali = GetDati(set, "PAI Ambientali"); // set.Tables[0].AsEnumerable().Where(row => row.Field<String>("Tabella") == "SFDR").CopyToDataTable();
DataTable Sociali = GetDati(set, "PAI Sociali"); //set.Tables[0].AsEnumerable().Where(row => row.Field<String>("Tabella") == "Taxonomy").CopyToDataTable();
DataTable CERCHI = set.Tables[1];
datitabSFRD.table = Ambientali;
datitabTAX.table = Sociali;
#region Testo introduttivo Sezione S188
if (dataThread.Rete == "W")
_testointroduttivo = _testointroduttivo.Replace("$/Banca/$", "la Società");
else
_testointroduttivo = _testointroduttivo.Replace("$/Banca/$", "la Banca");
logger.Info("Titolo della sezione " + _testointroduttivo);
document.setLastPos(-40);
document.setChapterHeader(string.Concat(_testointroduttivo, "<br>"), 0, 520, 8);
#endregion
// SEZIONE "Ambientali"
document.setLastPos(2);
InsertIntestazioneTabella(document, "Analisi PAI Ambientali", document.getLastPos(), 90);
riferimentoTabella1 = WriteDati(document, datitabSFRD, document.getLastPos(), 100, 25);
//if (ambiente != "SVILUPPO") riferimentoTabella1 -= 10;
InsertTotaleTabella(document, document.getLastPos() + 43);
// SEZIONE "Sociali"
document.setLastPos(2);
InsertIntestazioneTabella(document, "Analisi PAI Sociali", document.getLastPos() + 20, 90);
riferimentoTabella2 = WriteDati(document, datitabTAX, document.getLastPos() + 13, 100, 25);
//if (ambiente != "SVILUPPO") riferimentoTabella2 -= 10;
InsertTotaleTabella(document, document.getLastPos() + 50);
//// CERCHI
///
bool primo = false;
int c = 0;
foreach (DataRow item in CERCHI.Rows)
{
string imageIN = item["PathImage"].ToString();
decimal Valore1 = Convert.ToDecimal(item["Valore"]);
decimal Valore2 = Convert.ToDecimal(item["ValoreDiCui"]);
FormatNum conv = new FormatNum();
conv.AggiornaValoriCerchi(ref Valore1, ref Valore2);
System.Drawing.Color colorBackground = System.Drawing.Color.FromArgb(255, 255, 255);
System.Drawing.Color colorForeControl = System.Drawing.Color.DimGray;
System.Drawing.Color colorBar1 = (System.Drawing.Color)item["ColoreValore"];
System.Drawing.Color colorBar2 = (System.Drawing.Color)item["ColoreValoreDiCui"];
var bm = CreateImage(imageIN, Valore1, 420,
primo == false ? posizioneCerchio1_Y : posizioneCerchio2_Y, 450,
Valore2, colorBackground, colorForeControl, colorBar1, colorBar2,
primo == false ? (int)riferimentoTabella1 * 3 : (int)riferimentoTabella2 * 3);
ceTe.DynamicPDF.PageElements.Image img_ = new
ceTe.DynamicPDF.PageElements.Image(bm, 450,
primo == false ? posizioneCerchio1_Y : posizioneCerchio2_Y);
img_.SetDpi(CACHE.resolution, CACHE.resolution);
img_.ID = $"S188_CIRCLE_{c}";
document.getCurrentPage().Elements.Add(img_);
primo = true;
c++;
}
logger.Info("Fine sezione S188 metodo writeSezione " + dataThread.CodiceFiscale);
document.addPage();
}
DataTable GetDati(DSS188AnalisiPortafoglioPAI set, string tabella)
{
return set.Tables[0].AsEnumerable().Where(row => row.Field<String>("Tabella") == tabella).CopyToDataTable();
}
Bitmap CreateImage(string ImageIN, decimal ValPercentuale, long PosX, long PosY, long Scale, decimal ValPercentuale2,
System.Drawing.Color Color1, System.Drawing.Color Color2, System.Drawing.Color Color3, System.Drawing.Color Color4, int Altezza)
{
//Graphics g = null;
System.Drawing.Color colorBackground = Color1;
System.Drawing.Color colorForeControl = Color2;
System.Drawing.Color colorBar1 = Color3;
System.Drawing.Color colorBar2 = Color4;
using (BarreCircolari _bc = new BarreCircolari(Altezza, Altezza, "", new System.Drawing.Font("Verdana", 10),
colorBackground, colorForeControl, colorBar1, colorBar2, new System.Drawing.Rectangle(0, 0, Altezza, Altezza),
(Int32)ValPercentuale, (Int32)ValPercentuale2))
{
_bc.pathImmagine = ImageIN;
_bc.OnPaintNew(ImageIN, "", false);
Bitmap outAnello = _bc.outImmagine;
//if (ambiente != "SVILUPPO")
//{
int w = circle_size, h = circle_size;
Bitmap nuova = new Bitmap(w, h);
System.Drawing.Image img = (System.Drawing.Image)outAnello;
System.Drawing.Rectangle rect = new System.Drawing.Rectangle(new Point(0, 0), new Size(w,h));
using (var g1 = Graphics.FromImage(nuova))
{
g1.DrawImage(img, rect);
}
return nuova;
//}
//else
// return outAnello;
}
}
void InsertIntestazioneTabella(DocumentPDF document, string Caption, float DeltaX, float DeltaY)
{
Tabella tabellaDatiSFRD_Tax = new Tabella(document.getMargineLeft(), DeltaX, DeltaY, -2, 0.2F);
document.setLastPos(2);
DatiTabella datiTabellaInstestazione = new DatiTabella();
DataTable dtSFDR_INTESTAZIONE = new DataTable();
dtSFDR_INTESTAZIONE.Columns.Add("Caption", typeof(System.String));
dtSFDR_INTESTAZIONE.Columns.Add("Peso", typeof(System.String));
datiTabellaInstestazione.table = dtSFDR_INTESTAZIONE;
dtSFDR_INTESTAZIONE.Rows.Add(Caption, "PESO (%)");
tabellaDatiSFRD_Tax.Header = false;
tabellaDatiSFRD_Tax.Colonne.Add(new Colonna("Caption", "", 295, TipoAllineamento.SINISTRA, true, 9, true, TipoColonna.TESTO));
tabellaDatiSFRD_Tax.Colonne.Add(new Colonna("Peso", "", 70, TipoAllineamento.SINISTRA, true, 9, true, TipoColonna.TESTO));
tabellaDatiSFRD_Tax.Draw(datiTabellaInstestazione, document);
}
float WriteDati(DocumentPDF document, DatiTabella datiTab, float x, float y, Int32 rowDim)
{
Tabella tabellaDati = new Tabella(document.getMargineLeft(), x, y, -2, 0.2F);
datiTab.SetRowDim(rowDim);
datiTab.setIsLinee(2);
document.setLastPos(2);
tabellaDati.Header = false;
tabellaDati.Colonne.Add(new Colonna("NomeFileCerchio", "", 20, TipoAllineamento.CENTRATO, false, 10, false, TipoColonna.IMMAGINE));
tabellaDati.Colonne.Add(new Colonna("Descrizione", "", 250, TipoAllineamento.SINISTRA, false, 9, false, TipoColonna.TESTO));
tabellaDati.Colonne.Add(new Colonna("ValMostrato", "", 90, TipoAllineamento.DESTRA, false, 9, false, TipoColonna.TESTO)); //45
tabellaDati.Draw(datiTab, document);
return tabellaDati.AltezzaTabella;
}
void InsertTotaleTabella(DocumentPDF document, float posizione)
{
Tabella tabellaTOT_SFRD_Tax = new Tabella(document.getMargineLeft(), posizione, 50, -2, 0.2F);
document.setLastPos(2);
DatiTabella datiTabellaTotale = new DatiTabella();
DataTable dtTotle = new DataTable();
dtTotle.Columns.Add("TOT", typeof(System.String));
dtTotle.Columns.Add("Peso", typeof(System.String));
datiTabellaTotale.table = dtTotle;
dtTotle.Rows.Add("TOTALE", "100,00");
tabellaTOT_SFRD_Tax.Header = false;
tabellaTOT_SFRD_Tax.Colonne.Add(new Colonna("TOT", "", 270, TipoAllineamento.SINISTRA, true, 9, true, TipoColonna.TESTO));
tabellaTOT_SFRD_Tax.Colonne.Add(new Colonna("Peso", "", 90, TipoAllineamento.DESTRA, true, 9, true, TipoColonna.TESTO));
tabellaTOT_SFRD_Tax.Draw(datiTabellaTotale, document);
}
}
}