318 lines
17 KiB
C#
318 lines
17 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using System.Data;
|
|
|
|
namespace PDFGenerator.BusinessLayer.DataSection
|
|
{
|
|
|
|
/// <summary>
|
|
/// Summary description for DSS57BISConfrontoPiramideAttualeModello
|
|
/// </summary>
|
|
public class DSS57BISConfrontoPiramideAttualeModello : IDataSection
|
|
{
|
|
|
|
public DSS57BISConfrontoPiramideAttualeModello()
|
|
{
|
|
//
|
|
// TODO: Add constructor logic here
|
|
//
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Recupera i dati per la stampa della S57BIS.
|
|
/// </summary>
|
|
/// <param name="tabelleSessione"></param>
|
|
/// <param name="querySql"></param>
|
|
/// <param name="dataThread"></param>
|
|
/// <returns></returns>
|
|
public DataSectionResult getDataSection(List<SessionStruct> tabelleSessione, string querySql, DataThread dataThread)
|
|
{
|
|
DataSetS57BIS dataset57BIS = new DataSetS57BIS();
|
|
FormatNum conv = new FormatNum();
|
|
DataSectionResult dsr = new DataSectionResult();
|
|
|
|
Random rnd = new Random();
|
|
DataTable dt = new DataTable();
|
|
|
|
bool _mostracolonnacopertura = false;
|
|
|
|
if (dataThread.Patrimoniobancafideuramctv != 0)
|
|
{
|
|
|
|
Decimal ctvTotale = 0;
|
|
// Decimal ctvCC = 0;
|
|
Decimal ctvNA = 0;
|
|
|
|
dt = SectionManager.GetDataSection(tabelleSessione, querySql, dataThread);
|
|
|
|
decimal residuo = 100;
|
|
decimal valorePercMaggiore = 0;
|
|
DataSetS57BIS.GraficoFarfallaRow tupla_maggiore = null;
|
|
|
|
//Se il cliente ha solo CC presso BF la query ritorna solo 2 righe e non bisogna visualizzare niente
|
|
if (dt.Rows.Count > 3)
|
|
{
|
|
|
|
#region Tabella del GraficoPiramide
|
|
|
|
decimal totaleRisorseAllocate = 0;
|
|
int iOrderNeedArea = 0;
|
|
|
|
foreach (DataRow row in dt.Rows)
|
|
{
|
|
// escludo risorse non allocate (na), contocorrente (cc) , pro, pre1 e pre2
|
|
if (row["needarea"].ToString().ToLower() != "na" && row["needarea"].ToString().ToLower() != "cc" && row["needarea"].ToString().ToLower() != "pro" && row["needarea"].ToString().ToLower() != "pre1" && row["needarea"].ToString().ToLower() != "pre2")
|
|
{
|
|
|
|
//Grafico Piramide
|
|
DataSetS57BIS.GraficoPiramideRow rowDSS57BISGraficoPiramide;
|
|
rowDSS57BISGraficoPiramide = dataset57BIS.GraficoPiramide.NewGraficoPiramideRow();
|
|
rowDSS57BISGraficoPiramide.AreaBisogno = row["needarea"].ToString();
|
|
rowDSS57BISGraficoPiramide.Controvalore = conv.ConvertNum(row["controvaloreAttuale"].ToString());
|
|
totaleRisorseAllocate += Convert.ToDecimal(row["controvaloreAttuale"]);
|
|
rowDSS57BISGraficoPiramide.Rischio = row["var_needareaString"] == DBNull.Value ? conv.ConvertNum(row["var_needarea"].ToString()) : row["var_needareaString"].ToString();
|
|
rowDSS57BISGraficoPiramide.Copertura = row["copertura_needareaString"] == DBNull.Value ? conv.ConvertNum(row["copertura_needarea"].ToString()) : row["copertura_needareaString"].ToString();
|
|
|
|
if ((Convert.ToDecimal(rowDSS57BISGraficoPiramide.Controvalore) == 0) || (Convert.ToDecimal(rowDSS57BISGraficoPiramide.Controvalore) == 0M) || (Convert.ToDecimal(rowDSS57BISGraficoPiramide.Controvalore) == 0M))
|
|
{
|
|
rowDSS57BISGraficoPiramide.Rischio = "0,00";
|
|
rowDSS57BISGraficoPiramide.Copertura = "100,00";
|
|
}
|
|
|
|
dataset57BIS.GraficoPiramide.AddGraficoPiramideRow(rowDSS57BISGraficoPiramide);
|
|
|
|
|
|
//Grafico Farfalla
|
|
DataSetS57BIS.GraficoFarfallaRow rowDSS57BISGraficoFarfalla;
|
|
rowDSS57BISGraficoFarfalla = dataset57BIS.GraficoFarfalla.NewGraficoFarfallaRow();
|
|
|
|
if (dataThread.TipoReport.ToUpper() == "MONITORAGGIO")
|
|
{
|
|
object percentualeAttualeTotale = null;
|
|
//Recupero la percentuale attuale da dataThread.PesoPercentuale (presa da li per far combaciare i valori con S82 , S82BIS)
|
|
if (dataThread.PesoPercentuale != null)
|
|
{
|
|
DataView dwPeso = new DataView(dataThread.PesoPercentuale);
|
|
DataTable dtPeso = dwPeso.ToTable();
|
|
percentualeAttualeTotale = dtPeso.Compute("Sum(PesoPercentuale)", "AreaBisogno='" + row["needarea"].ToString() + "'");
|
|
rowDSS57BISGraficoFarfalla.PercentualeAttuale = percentualeAttualeTotale != null && percentualeAttualeTotale.ToString() == string.Empty ? 0 : Convert.ToDecimal(percentualeAttualeTotale);
|
|
}
|
|
else
|
|
rowDSS57BISGraficoFarfalla.PercentualeAttuale = 0;
|
|
|
|
}
|
|
else if (dataThread.TipoReport.ToUpper() == "DIAGNOSI")
|
|
{
|
|
rowDSS57BISGraficoFarfalla.PercentualeAttuale = row["percentualeAttuale"] == DBNull.Value ? 0 : decimal.Round(Convert.ToDecimal(row["percentualeAttuale"]),2);
|
|
if (rowDSS57BISGraficoFarfalla.PercentualeAttuale > valorePercMaggiore)
|
|
{
|
|
tupla_maggiore = rowDSS57BISGraficoFarfalla;
|
|
valorePercMaggiore = rowDSS57BISGraficoFarfalla.PercentualeAttuale;
|
|
}
|
|
residuo -= rowDSS57BISGraficoFarfalla.PercentualeAttuale;
|
|
}
|
|
|
|
rowDSS57BISGraficoFarfalla.PercentualeModello = row["percentualeModello"] == DBNull.Value ? 0 : Convert.ToDecimal(row["percentualeModello"]);
|
|
rowDSS57BISGraficoFarfalla.NeedArea = row["needarea"].ToString().ToLower();
|
|
rowDSS57BISGraficoFarfalla.OrderNeedArea = iOrderNeedArea++;
|
|
|
|
dataset57BIS.GraficoFarfalla.AddGraficoFarfallaRow(rowDSS57BISGraficoFarfalla);
|
|
}
|
|
|
|
}
|
|
|
|
//V Approssimazione diagnosi
|
|
if (dataThread.TipoReport.ToUpper() == "DIAGNOSI")
|
|
{
|
|
if (residuo != 0 && tupla_maggiore != null)
|
|
{
|
|
tupla_maggiore.PercentualeAttuale += residuo;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Risorse Allocate
|
|
DataSetS57BIS.RisorseAllocateRow rowDSS57BISRisorseAllocate;
|
|
rowDSS57BISRisorseAllocate = dataset57BIS.RisorseAllocate.NewRisorseAllocateRow();
|
|
rowDSS57BISRisorseAllocate.Descrizione = "TOTALE RISORSE ALLOCATE";
|
|
rowDSS57BISRisorseAllocate.Controvalore = conv.ConvertNum(totaleRisorseAllocate);
|
|
//V Cambiato il puntamento alla query per prendere il var della piramide invece che quello complessivo che tiene conto delle risorse non associate
|
|
rowDSS57BISRisorseAllocate.Rischio = dt.Rows[0]["var_tot_pirString"] == DBNull.Value ? conv.ConvertNum(dt.Rows[0]["var_tot_pir"].ToString()) : dt.Rows[0]["var_tot_pirString"].ToString();
|
|
|
|
rowDSS57BISRisorseAllocate.Copertura = dt.Rows[0]["copertura_tot_pirString"] == DBNull.Value ? conv.ConvertNum(dt.Rows[0]["copertura_tot_pir"].ToString()) : dt.Rows[0]["copertura_tot_pirString"].ToString();
|
|
|
|
if (Convert.ToDecimal(rowDSS57BISRisorseAllocate.Controvalore) == 0)
|
|
{
|
|
rowDSS57BISRisorseAllocate.Rischio = "0,00";
|
|
rowDSS57BISRisorseAllocate.Copertura = "100,00";
|
|
}
|
|
//
|
|
|
|
|
|
#endregion
|
|
|
|
#region Risorse non allocate
|
|
|
|
decimal rischioRisorsenonAllocate = 0;
|
|
decimal coperturaRisorseNonAllocate = -1;
|
|
decimal ctvRisorseNonAllocate = 0;
|
|
DataSetS57BIS.RisorseNonAllocateRow rowDSS57BISRisorseNonAllocate;
|
|
rowDSS57BISRisorseNonAllocate = dataset57BIS.RisorseNonAllocate.NewRisorseNonAllocateRow();
|
|
rowDSS57BISRisorseNonAllocate.Descrizione = "Risorse non allocate";
|
|
|
|
DataRow[] drRisorseNonAllocate = dt.Select(" NeedArea='Na'");
|
|
if (drRisorseNonAllocate.Length > 0)
|
|
{
|
|
|
|
rowDSS57BISRisorseNonAllocate.Controvalore = conv.ConvertNum(drRisorseNonAllocate[0]["controvaloreAttuale"]);
|
|
ctvRisorseNonAllocate = drRisorseNonAllocate[0]["controvaloreAttuale"] == DBNull.Value ? 0 : Convert.ToDecimal(drRisorseNonAllocate[0]["controvaloreAttuale"]);
|
|
if (ctvRisorseNonAllocate != 0)
|
|
{
|
|
|
|
rischioRisorsenonAllocate = drRisorseNonAllocate[0]["var_needarea"] == DBNull.Value ? 0 : Convert.ToDecimal(drRisorseNonAllocate[0]["var_needarea"]);
|
|
coperturaRisorseNonAllocate = drRisorseNonAllocate[0]["copertura_needarea"] == DBNull.Value ? 0 : Convert.ToDecimal(drRisorseNonAllocate[0]["copertura_needarea"]);
|
|
|
|
|
|
}
|
|
}
|
|
|
|
rowDSS57BISRisorseNonAllocate.Controvalore = conv.ConvertNum(ctvRisorseNonAllocate);
|
|
rowDSS57BISRisorseNonAllocate.Rischio = conv.ConvertNum(rischioRisorsenonAllocate);
|
|
rowDSS57BISRisorseNonAllocate.Copertura = conv.ConvertNum(coperturaRisorseNonAllocate);
|
|
|
|
//V lo setto per le approsimazioni
|
|
ctvNA = ctvRisorseNonAllocate;
|
|
|
|
// In caso in cui le risorse non allocate siano uguali a 0 non deve essere mostrata la riga;
|
|
// non deve essere mostrata nemmeno la riga delle risorse allocate, ma direttamente delle risorse finanziarie
|
|
if (ctvRisorseNonAllocate != 0M)
|
|
{
|
|
dataset57BIS.RisorseAllocate.AddRisorseAllocateRow(rowDSS57BISRisorseAllocate);
|
|
dataset57BIS.RisorseNonAllocate.AddRisorseNonAllocateRow(rowDSS57BISRisorseNonAllocate);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Risorse Finanziarie
|
|
// totale delle Risorse Finanziarie
|
|
DataSetS57BIS.RisorseFinanziarieRow rowDSS57BISRisorseFinanziarie;
|
|
rowDSS57BISRisorseFinanziarie = dataset57BIS.RisorseFinanziarie.NewRisorseFinanziarieRow();
|
|
rowDSS57BISRisorseFinanziarie.Descrizione = "TOTALE RISORSE FINANZIARIE";
|
|
rowDSS57BISRisorseFinanziarie.Controvalore = conv.ConvertNum(totaleRisorseAllocate + ctvRisorseNonAllocate);
|
|
rowDSS57BISRisorseFinanziarie.Rischio = dt.Rows[0]["var_risfinString"] == DBNull.Value ? conv.ConvertNum(dt.Rows[0]["var_risfin"].ToString()) : dt.Rows[0]["var_risfinString"].ToString(); //D //conv.ConvertNum(ptfTotaleBF.misureRischio.varp);
|
|
rowDSS57BISRisorseFinanziarie.Copertura = dt.Rows[0]["copertura_risfinString"] == DBNull.Value ? conv.ConvertNum(dt.Rows[0]["copertura_risfin"].ToString()) : dt.Rows[0]["copertura_risfinString"].ToString(); //D
|
|
|
|
//V Setto copertura = 100 e var = 0 nel caso il ctv sia uguale a 0
|
|
if (totaleRisorseAllocate + ctvRisorseNonAllocate == 0)
|
|
{
|
|
rowDSS57BISRisorseFinanziarie.Rischio = "0,00";
|
|
rowDSS57BISRisorseFinanziarie.Copertura = "100,00";
|
|
}
|
|
|
|
dataset57BIS.RisorseFinanziarie.AddRisorseFinanziarieRow(rowDSS57BISRisorseFinanziarie);
|
|
|
|
#endregion
|
|
|
|
#region Conto Corrente
|
|
|
|
decimal ctvContoCorrente = 0;
|
|
DataSetS57BIS.ContoCorrenteRow rowDSS57BISContoCorrente;
|
|
rowDSS57BISContoCorrente = dataset57BIS.ContoCorrente.NewContoCorrenteRow();
|
|
//rowDSS57BISContoCorrente.Descrizione = "Conto corrente";
|
|
rowDSS57BISContoCorrente.Descrizione = "C/C a saldo negativo";
|
|
//DataRow[] drContoCorrente = dt.Select(" NeedArea='CC'");
|
|
//if (drContoCorrente.Length > 0)
|
|
// ctvContoCorrente = drContoCorrente[0]["controvaloreAttuale"] == DBNull.Value ? 0 : Convert.ToDecimal(drContoCorrente[0]["controvaloreAttuale"]);
|
|
|
|
ctvContoCorrente = dataThread.ContoCorrente;
|
|
rowDSS57BISContoCorrente.Controvalore = conv.ConvertNum(ctvContoCorrente);
|
|
rowDSS57BISContoCorrente.Rischio = "0,00";
|
|
rowDSS57BISContoCorrente.Copertura = "100,00";
|
|
//Hazem
|
|
//if (dt.Rows[0]["var_needareaString"] != DBNull.Value)
|
|
// rowDSS57BISContoCorrente.Rischio = dt.Rows[0]["var_needareaString"].ToString();
|
|
//else
|
|
// rowDSS57BISContoCorrente.Rischio = conv.ConvertNum("0.00");
|
|
|
|
dataset57BIS.ContoCorrente.AddContoCorrenteRow(rowDSS57BISContoCorrente);
|
|
|
|
|
|
#endregion
|
|
|
|
#region PartiteViaggianti
|
|
DataSetS57BIS.PartiteViaggiantiRow rowDSS57BISPartiteViaggianti;
|
|
rowDSS57BISPartiteViaggianti = dataset57BIS.PartiteViaggianti.NewPartiteViaggiantiRow();
|
|
rowDSS57BISPartiteViaggianti.Descrizione = Resource.PartiteViaggianti;
|
|
decimal totalePartiteViaggianti = dataThread.PartiteViaggiantiInvestimento + dataThread.PartiteViaggiantiDisinvestimento;
|
|
rowDSS57BISPartiteViaggianti.ControValore = conv.ConvertNum(totalePartiteViaggianti);
|
|
if (totalePartiteViaggianti != 0)
|
|
dataset57BIS.PartiteViaggianti.AddPartiteViaggiantiRow(rowDSS57BISPartiteViaggianti);
|
|
|
|
#endregion
|
|
|
|
#region Totale Patrimonio
|
|
DataSetS57BIS.TotalePatrimonioRow rowDSS57BISTotalePatrimonio;
|
|
rowDSS57BISTotalePatrimonio = dataset57BIS.TotalePatrimonio.NewTotalePatrimonioRow();
|
|
rowDSS57BISTotalePatrimonio.Descrizione = "TOTALE PATRIMONIO";
|
|
|
|
decimal totalePatrimonio = totaleRisorseAllocate + ctvContoCorrente + totalePartiteViaggianti + ctvRisorseNonAllocate;
|
|
rowDSS57BISTotalePatrimonio.ControValore = conv.ConvertNum(totalePatrimonio);
|
|
|
|
//V Settato per le approsimazioni
|
|
ctvTotale = totaleRisorseAllocate;
|
|
|
|
//Hazem
|
|
if (dt.Rows[0]["var_totString"] != DBNull.Value)
|
|
rowDSS57BISTotalePatrimonio.Rischio = dt.Rows[0]["var_totString"].ToString();
|
|
else
|
|
rowDSS57BISTotalePatrimonio.Rischio = conv.ConvertNum(dt.Rows[0]["var_tot"]);
|
|
|
|
if (dt.Rows[0]["copertura_totString"] != DBNull.Value)
|
|
rowDSS57BISTotalePatrimonio.Copertura = dt.Rows[0]["copertura_totString"].ToString();
|
|
else
|
|
rowDSS57BISTotalePatrimonio.Copertura = conv.ConvertNum(dt.Rows[0]["copertura_tot"]);
|
|
|
|
|
|
dataset57BIS.TotalePatrimonio.AddTotalePatrimonioRow(rowDSS57BISTotalePatrimonio);
|
|
|
|
|
|
#endregion
|
|
|
|
#region Resulset
|
|
|
|
// verifico se nel datatable GraficoPiramide almeno 1 grado copertura è diverso da 100 e il grado di copertura delle risorse non allocate è diverso da 100
|
|
// se si verrà disegnata la colonna relativa al grado di coperura.
|
|
DataTable dtMostraColonnaCopertura;
|
|
DataView dwMostraColonnaCopertura = new DataView(dataset57BIS.GraficoPiramide);
|
|
dwMostraColonnaCopertura.RowFilter = "Copertura <> '100,00'";
|
|
dtMostraColonnaCopertura = dwMostraColonnaCopertura.ToTable();
|
|
_mostracolonnacopertura = (dtMostraColonnaCopertura.Rows.Count > 0 || (coperturaRisorseNonAllocate != 100M && coperturaRisorseNonAllocate != -1M));
|
|
|
|
DataSetS57BIS.ResultSetRow rowDSS57BISResultSet;
|
|
rowDSS57BISResultSet = dataset57BIS.ResultSet.NewResultSetRow();
|
|
rowDSS57BISResultSet.MostraColonnaCopertura = _mostracolonnacopertura;
|
|
dataset57BIS.ResultSet.AddResultSetRow(rowDSS57BISResultSet);
|
|
|
|
#endregion
|
|
|
|
}
|
|
//V condizione presente nella S57 non riportata nella bis
|
|
dataThread.TotaleS57 = ctvTotale + ctvNA + dataThread.ContoCorrente - dataThread.PatrimonioNonRappresentabile;
|
|
}
|
|
|
|
|
|
dsr.DatiSezione = dataset57BIS;
|
|
dsr.Esito = dataset57BIS.GraficoPiramide.Rows.Count;
|
|
|
|
|
|
return dsr;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
}
|