234 lines
8.4 KiB
C#
234 lines
8.4 KiB
C#
using System;
|
|
using System.Data;
|
|
using PDFGenerator.BusinessLayer.DataSection;
|
|
using PDFGenerator.BusinessLayer;
|
|
using System.Collections.Generic;
|
|
using PDFGenerator;
|
|
|
|
|
|
/// <summary>
|
|
/// Summary description for DSS82DatiSintetici
|
|
/// </summary>
|
|
public class DSS82DatiSinteticiBIS : IDataSection
|
|
{
|
|
FormatNum conv;
|
|
private decimal calcolaTotaleCTV(DataTable dt)
|
|
{
|
|
object sumExt = dt.Compute("Sum(CONTROVALOREATTUALE)", "NEED_AREA='Ext'");
|
|
if (sumExt.ToString() == string.Empty)
|
|
sumExt = 0M;
|
|
|
|
object sumInv = dt.Compute("Sum(CONTROVALOREATTUALE)", "NEED_AREA='Inv'");
|
|
if (sumInv.ToString() == string.Empty)
|
|
sumInv = 0M;
|
|
|
|
|
|
object sumLiq = dt.Compute("Sum(CONTROVALOREATTUALE)", "NEED_AREA='Liq'");
|
|
if (sumLiq.ToString() == string.Empty)
|
|
sumLiq = 0M;
|
|
|
|
object sumPre = dt.Compute("Sum(CONTROVALOREATTUALE)", "NEED_AREA='Pre'");
|
|
if (sumPre.ToString() == string.Empty)
|
|
sumPre = 0M;
|
|
|
|
object sumRis = dt.Compute("Sum(CONTROVALOREATTUALE)", "NEED_AREA='Ris'");
|
|
if (sumRis.ToString() == string.Empty)
|
|
sumRis = 0M;
|
|
|
|
|
|
decimal totale = Convert.ToDecimal(sumExt) +
|
|
Convert.ToDecimal(sumInv) +
|
|
Convert.ToDecimal(sumLiq) +
|
|
Convert.ToDecimal(sumRis) +
|
|
Convert.ToDecimal(sumPre);
|
|
return totale;
|
|
}
|
|
private decimal calcolaPesoPercentuale(decimal ctvArea, DataTable dt)
|
|
{
|
|
|
|
decimal peso = (ctvArea / this.calcolaTotaleCTV(dt)) * 100;
|
|
return peso;
|
|
}
|
|
private DataRow getRowDatiSintesi(DataTable dt, string area, string nomeprogetto, Int32? ordinamento)
|
|
{
|
|
DataRow[] rowArray = null;
|
|
|
|
if (dt == null)
|
|
return null;
|
|
|
|
if (area.ToUpper() == "INV")
|
|
{
|
|
// Progetti
|
|
if (ordinamento == null)
|
|
rowArray = dt.Select(" nome_progetto = '" + nomeprogetto.Replace("'", "''") + "' and NEED_AREA = '" + area.Replace("'", "''") + "'");
|
|
else
|
|
rowArray = dt.Select(" ordinamento_progetto = " + ordinamento.ToString() + " and nome_progetto = '" + nomeprogetto.Replace("'", "''") + "' and NEED_AREA = '" + area.Replace("'", "''") + "'");
|
|
}
|
|
else
|
|
{
|
|
// no progetti
|
|
rowArray = dt.Select(" NEED_AREA = '" + area.Replace("'", "''") + "'");
|
|
|
|
}
|
|
|
|
if (rowArray.Length > 0)
|
|
{
|
|
return rowArray[0];
|
|
}
|
|
else
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
private Int32? _ordinamentoProgettoPerAreeMonitorate;
|
|
|
|
public Int32? OrdinamentoProgettoPerAreeMonitorate { set { _ordinamentoProgettoPerAreeMonitorate = value; } }
|
|
public DataSectionResult getDataSection(List<SessionStruct> tabelleSessione, string querySql, DataThread dataThread)
|
|
{
|
|
DataSectionResult dsr = new DataSectionResult();
|
|
|
|
conv = new FormatNum();
|
|
string var = conv.ConvertNum(0, 2);
|
|
string copertura = string.Empty;
|
|
decimal ctvArea = 0;
|
|
|
|
DataTable dt = SectionManager.GetDataSection(tabelleSessione, querySql, dataThread);
|
|
|
|
if(dt.Rows.Count==0)
|
|
return dsr;
|
|
|
|
|
|
|
|
DataSetS82 ds82 = new DataSetS82();
|
|
DataSetS82.DatiSintetici_DettaglioRow drDettaglio;
|
|
DataSetS82.DT_CoperturaRow drCopertura;
|
|
DataSetS82.HeaderRow hRow;
|
|
DataSetS82.SeparatoreRow separatore;
|
|
DataSetS82.DT_TabellaBassaRow tabBassa;
|
|
DataSetS82.HeaderTemporaleRow htemporaleRow;
|
|
DataSetS82.DT_OrizTemporaleRow tabOriz;
|
|
|
|
|
|
// Filtro su area/progetto
|
|
DataRow rowDatiSintesi = getRowDatiSintesi(dt, dataThread.Area, dataThread.Progetto, _ordinamentoProgettoPerAreeMonitorate);
|
|
|
|
// Recupero copertura e VaR
|
|
copertura = rowDatiSintesi["copertura_needareaString"]==DBNull.Value ? conv.ConvertNum(rowDatiSintesi["copertura_needarea"].ToString()) : rowDatiSintesi["copertura_needarea"].ToString();
|
|
var = rowDatiSintesi["var_needareaString"] == DBNull.Value ? conv.ConvertNum(rowDatiSintesi["var_needarea"].ToString()) : rowDatiSintesi["var_needareastring"].ToString();
|
|
|
|
|
|
drDettaglio = ds82.DatiSintetici_Dettaglio.NewDatiSintetici_DettaglioRow();
|
|
drDettaglio.Descrizione = "Controvalore";
|
|
if (rowDatiSintesi != null)
|
|
{
|
|
if (rowDatiSintesi["controvaloreAttuale"] != DBNull.Value)
|
|
{
|
|
drDettaglio.Valore = conv.ConvertNum(rowDatiSintesi["controvaloreAttuale"], 2) + " €";
|
|
ctvArea = Convert.ToDecimal(rowDatiSintesi["controvaloreAttuale"]);
|
|
}
|
|
else
|
|
{
|
|
drDettaglio.Valore = conv.ConvertNum(0, 2) + " €";
|
|
ctvArea = 0;
|
|
}
|
|
}
|
|
ds82.DatiSintetici_Dettaglio.Rows.Add(drDettaglio);
|
|
|
|
|
|
|
|
|
|
#region Popolo il dataset dati sintetici di grafico
|
|
|
|
//Header.. Controvalore e Rischio
|
|
hRow = ds82.Header.NewHeaderRow();
|
|
hRow.Descrizione = "Controvalore e Rischio";
|
|
ds82.Header.AddHeaderRow(hRow);
|
|
|
|
separatore = ds82.Separatore.NewSeparatoreRow();
|
|
separatore.Descrizione = "";
|
|
ds82.Separatore.AddSeparatoreRow(separatore);
|
|
|
|
// VAR ATTUALE
|
|
drDettaglio = ds82.DatiSintetici_Dettaglio.NewDatiSintetici_DettaglioRow();
|
|
drDettaglio.Descrizione = "Rischio Mercato (VaR %)";
|
|
if (var.ToLower() == "n.c.")
|
|
drDettaglio.Valore = var;
|
|
else
|
|
drDettaglio.Valore = var + " %";
|
|
|
|
ds82.DatiSintetici_Dettaglio.Rows.Add(drDettaglio);
|
|
|
|
|
|
//GRADO COPERTURA
|
|
|
|
drCopertura = ds82.DT_Copertura.NewDT_CoperturaRow();
|
|
drCopertura.Descrizione = "Copertura";
|
|
drCopertura.Valore = copertura + " %";
|
|
if (copertura != "100,00")
|
|
ds82.DT_Copertura.Rows.Add(drCopertura);
|
|
|
|
|
|
//Peso PErcentuale ctv
|
|
tabBassa = ds82.DT_TabellaBassa.NewDT_TabellaBassaRow();
|
|
tabBassa.Descrizione = "Peso percentuale controvalore";
|
|
|
|
DataView dwPeso = new DataView(dataThread.PesoPercentuale);
|
|
dwPeso.RowFilter = " AreaBisogno='" + dataThread.Area + "' and NomeProgetto= '" + dataThread.Progetto.Replace("'", "''") + "'";
|
|
DataTable dtPeso = dwPeso.ToTable();
|
|
tabBassa.Valore = conv.ConvertNum(Convert.ToDecimal(dtPeso.Rows[0]["PesoPercentuale"])) + " %";
|
|
|
|
|
|
ds82.DT_TabellaBassa.Rows.Add(tabBassa);
|
|
|
|
//Rischio Relativo
|
|
//RischioRelativo rischio = new RischioRelativo();
|
|
tabBassa = ds82.DT_TabellaBassa.NewDT_TabellaBassaRow();
|
|
tabBassa.Descrizione = "Rischio relativo";
|
|
|
|
DataView dwRischio = new DataView(dataThread.RischioRelativo);
|
|
dwRischio.RowFilter = " AreaBisogno='" + dataThread.Area + "' and NomeProgetto= '" + dataThread.Progetto.Replace("'", "''") + "'";
|
|
DataTable dtRischio = dwRischio.ToTable();
|
|
tabBassa.Valore = dtRischio.Rows[0]["RischioRelativoString"].ToString().ToLower() == "n.c." ? "n.c." : conv.ConvertNum(Convert.ToDecimal(dtRischio.Rows[0]["RischioRelativo"]), 2) + " %";
|
|
|
|
ds82.DT_TabellaBassa.Rows.Add(tabBassa);
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
#region Popolo la tabella degli Orizzonti Temporali
|
|
//Header.. Controvalore e Rischio
|
|
htemporaleRow = ds82.HeaderTemporale.NewHeaderTemporaleRow();
|
|
htemporaleRow.Descrizione = "Orizzonte temporale";
|
|
ds82.HeaderTemporale.AddHeaderTemporaleRow(htemporaleRow);
|
|
|
|
//Orizzonte Temporale
|
|
tabOriz = ds82.DT_OrizTemporale.NewDT_OrizTemporaleRow();
|
|
tabOriz.Descrizione = "Orizzonte pianificato";
|
|
if (rowDatiSintesi == null)
|
|
tabOriz.Valore = "0 anni";
|
|
else
|
|
tabOriz.Valore = rowDatiSintesi["Orizzonte_Pianificato"].ToString();
|
|
ds82.DT_OrizTemporale.Rows.Add(tabOriz);
|
|
|
|
//Durata Residua
|
|
tabOriz = ds82.DT_OrizTemporale.NewDT_OrizTemporaleRow();
|
|
tabOriz.Descrizione = "Durata residua";
|
|
if (dt.Rows.Count.Equals(0))
|
|
tabOriz.Valore = "0 mesi";
|
|
else
|
|
tabOriz.Valore = rowDatiSintesi["durataResidua"].ToString();
|
|
ds82.DT_OrizTemporale.Rows.Add(tabOriz);
|
|
#endregion
|
|
|
|
dsr.DatiSezione = ds82;
|
|
dsr.Esito = ds82.DatiSintetici_Dettaglio.Rows.Count;
|
|
|
|
return dsr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|