283 lines
12 KiB
C#
283 lines
12 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using System.Data;
|
|
using System.Collections;
|
|
|
|
namespace PDFGenerator.BusinessLayer.DataSection
|
|
{
|
|
class DSS86MacroAssetClass : IDataSection
|
|
{
|
|
private bool _hasselectedpatrimnonrap = true;
|
|
|
|
/// <summary>
|
|
/// Filtro il datatable comprensivo di tutte le aree/progetto per il solo area/progetto corrente.
|
|
/// </summary>
|
|
/// <param name="dt"></param>
|
|
/// <param name="area"></param>
|
|
/// <param name="nomeprogetto"></param>
|
|
/// <returns></returns>
|
|
private DataRow[] getRowMacroAsset(DataTable dt, string area, string nomeprogetto, Int32? ordinamento)
|
|
{
|
|
try
|
|
{
|
|
DataRow[] rowArray = null;
|
|
|
|
if (dt != null)
|
|
{
|
|
if (dt.Rows.Count > 0)
|
|
{
|
|
|
|
if (area.ToUpper() == "INV")
|
|
{
|
|
// Progetti
|
|
if(ordinamento == null)
|
|
rowArray = dt.Select(" nome_progetto = '" + nomeprogetto.Replace("'", "''") + "' and NEED_AREA = '" + area.Replace("'", "''") + "'");
|
|
else
|
|
rowArray = dt.Select(" ord_progetto = " + ordinamento.ToString() + " and nome_progetto = '" + nomeprogetto.Replace("'", "''") + "' and NEED_AREA = '" + area.Replace("'", "''") + "'");
|
|
}
|
|
else
|
|
{
|
|
// no progetti
|
|
rowArray = dt.Select(" NEED_AREA = '" + area.Replace("'", "''") + "'");
|
|
|
|
}
|
|
}
|
|
}
|
|
return rowArray;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ritorna il patrimonio non rappresentabile per area/progetto
|
|
/// </summary>
|
|
/// <param name="DatatablePatrimonioNonRappresentabile"></param>
|
|
/// <param name="area"></param>
|
|
/// <param name="nomeprogetto"></param>
|
|
/// <returns></returns>
|
|
private Decimal getPatrimonioNonRappresentabile(DataTable DatatablePatrimonioNonRappresentabile, string area, string nomeprogetto, Int32? ordinamento)
|
|
{
|
|
try
|
|
{
|
|
decimal patNonRapp = 0;
|
|
DataRow[] rowArray = null;
|
|
|
|
if (DatatablePatrimonioNonRappresentabile != null)
|
|
if (DatatablePatrimonioNonRappresentabile.Rows.Count > 0)
|
|
{
|
|
|
|
if (area.ToUpper() == "INV")
|
|
{
|
|
// Progetti
|
|
if(ordinamento == null)
|
|
rowArray = DatatablePatrimonioNonRappresentabile.Select(" progetto = '" + nomeprogetto.Replace("'", "''") + "' and needarea = '" + area.Replace("'", "''") + "'");
|
|
else
|
|
rowArray = DatatablePatrimonioNonRappresentabile.Select(" ord_progetto = " + ordinamento.ToString() + " and progetto = '" + nomeprogetto.Replace("'", "''") + "' and needarea = '" + area.Replace("'", "''") + "'");
|
|
}
|
|
else
|
|
{
|
|
// no progetti
|
|
rowArray = DatatablePatrimonioNonRappresentabile.Select(" needarea = '" + area.Replace("'", "''") + "'");
|
|
}
|
|
}
|
|
|
|
|
|
if ((rowArray != null) && (rowArray.Length > 0))
|
|
{
|
|
foreach (DataRow dr in rowArray)
|
|
{
|
|
if (dr["controvalore"] != DBNull.Value)
|
|
patNonRapp += (decimal)dr["controvalore"];
|
|
|
|
}
|
|
}
|
|
|
|
return patNonRapp;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
private Int32? _ordinamentoProgettoPerAreeMonitorate;
|
|
|
|
public Int32? OrdinamentoProgettoPerAreeMonitorate { set { _ordinamentoProgettoPerAreeMonitorate = value; } }
|
|
|
|
public StructColor toBeFound = new StructColor();
|
|
|
|
/// <summary>
|
|
/// Imposta o recupera la selezione dell'utente della stampa del patrimonio non rappresentabile.
|
|
/// Nel modello corrente che si stampa per il report di monitoraggio questa selezione è sempre richesta.
|
|
/// Di default true.
|
|
/// </summary>
|
|
public bool HasSelectedPatrimNonRap
|
|
{
|
|
set { _hasselectedpatrimnonrap = value; }
|
|
get { return _hasselectedpatrimnonrap; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// Recupero i dati per la S86
|
|
/// </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)
|
|
{
|
|
try
|
|
{
|
|
|
|
DataTable dt = SectionManager.GetDataSection(tabelleSessione, querySql, dataThread);
|
|
|
|
Decimal ctvTotale = 0; // controvalore totale preso come somma di tutti i controvalori presi dalla strored della S86.
|
|
DataSectionResult dsr = new DataSectionResult();
|
|
|
|
#region Recupero il Patrimonio non rappresentabile
|
|
|
|
DataTable datatablePatrimonioNonRappresentabile = new DataTable();
|
|
datatablePatrimonioNonRappresentabile = SectionManager.GetDataSection(tabelleSessione, "[C6MartPeriodico].[PL_S76AlternativaPatrimonioNonRappresentabileAssettClass]", dataThread);
|
|
Decimal patrimonioNonRappresentabile = getPatrimonioNonRappresentabile(datatablePatrimonioNonRappresentabile, dataThread.Area, dataThread.Progetto, _ordinamentoProgettoPerAreeMonitorate);
|
|
|
|
#endregion
|
|
|
|
toBeFound.Tipo = "MacroAssetClass";
|
|
DataSetS86 ds86 = new DataSetS86();
|
|
DataSetS86.MacroAssetClassRow drMacroAsset;
|
|
ds86.MacroAssetClass.ControvaloreColumn.Caption = "Controvalore <br> (€) ";
|
|
|
|
#region Filtro per area/progetto
|
|
|
|
DataRow[] MacroAssetClassRows = getRowMacroAsset(dt, dataThread.Area, dataThread.Progetto, _ordinamentoProgettoPerAreeMonitorate);
|
|
|
|
#endregion
|
|
|
|
if (MacroAssetClassRows != null)
|
|
{
|
|
if (MacroAssetClassRows.Length > 0)
|
|
{
|
|
//V
|
|
DataSetS86.MacroAssetClassRow tuplaMaggiore = null;
|
|
decimal valoreCTV_tuplaMaggiore = 0;
|
|
decimal residuoPercentuale = 100;
|
|
//
|
|
foreach (DataRow dr in MacroAssetClassRows)
|
|
{
|
|
drMacroAsset = ds86.MacroAssetClass.NewMacroAssetClassRow();
|
|
drMacroAsset.Descrizione = dr["assetclassname"].ToString();
|
|
drMacroAsset.Controvalore = (decimal)dr["controvalore"];
|
|
//V
|
|
if (drMacroAsset.Controvalore > valoreCTV_tuplaMaggiore)
|
|
{
|
|
valoreCTV_tuplaMaggiore = drMacroAsset.Controvalore;
|
|
tuplaMaggiore = drMacroAsset;
|
|
}
|
|
//
|
|
drMacroAsset.Percentuale = (decimal)dr["percentuale"];
|
|
residuoPercentuale -= drMacroAsset.Percentuale;
|
|
|
|
toBeFound.Codice = dr["AssetClassId"].ToString();
|
|
int foundIdx = ClsFunzioniGeneriche.findRightColors(toBeFound);
|
|
drMacroAsset.Red = ClsFunzioniGeneriche.Colors[foundIdx].Red;
|
|
drMacroAsset.Green = ClsFunzioniGeneriche.Colors[foundIdx].Green;
|
|
drMacroAsset.Blue = ClsFunzioniGeneriche.Colors[foundIdx].Blue;
|
|
|
|
|
|
ctvTotale += (Decimal)dr["controvalore"];
|
|
ds86.MacroAssetClass.Rows.Add(drMacroAsset);
|
|
}
|
|
//V
|
|
//Riallineamento della percentuale a 100
|
|
if (residuoPercentuale != 0 && tuplaMaggiore != null)
|
|
{
|
|
tuplaMaggiore.Percentuale += residuoPercentuale;
|
|
|
|
}
|
|
|
|
decimal temp = 0;
|
|
|
|
#region Allineamento del controvalore totale con il dataThread.ControvaloriTotali
|
|
|
|
DataView dwCTV = new DataView(dataThread.ControvaloriTotali);
|
|
dwCTV.RowFilter = " ORDINAMENTO_PROGETTO=" + _ordinamentoProgettoPerAreeMonitorate + " and AreaBisogno='" + dataThread.Area + "' and NomeProgetto= '" + dataThread.Progetto.Replace("'", "''") + "'";
|
|
DataTable CTV = dwCTV.ToTable();
|
|
decimal controvaloreTotale = Convert.ToDecimal(CTV.Rows[0]["ControvaloreTotale"]) - patrimonioNonRappresentabile; // va sottratto il patrimonioNonRappresentabile perche nel totale che allinea tutti gli altri (dataThread.ControvaloriTotali) è già compreso.
|
|
temp = controvaloreTotale - ctvTotale;
|
|
|
|
#endregion
|
|
|
|
ctvTotale += temp;
|
|
if(ctvTotale == 0)
|
|
throw new Exception("ERRORE S86 - Controvalore totale = 0");
|
|
|
|
|
|
//if (temp > 2) //2 la soglia pattuita con Magri massima di approssimazione
|
|
// throw new Exception("ERRORE S86 - La soglia di approssimazione è maggiore di 2E.");
|
|
|
|
tuplaMaggiore.Controvalore += temp;
|
|
|
|
if(tuplaMaggiore.Controvalore < 0)
|
|
throw new Exception("ERRORE S86- Assett Negativa");
|
|
|
|
#region Riga del patrimonio non rappresentabile
|
|
|
|
if (patrimonioNonRappresentabile > 0)
|
|
{
|
|
DataSetS86.PatrimonioNonRappresentabileRow drPatrimonioNonRappresentabile;
|
|
drPatrimonioNonRappresentabile = ds86.PatrimonioNonRappresentabile.NewPatrimonioNonRappresentabileRow();
|
|
if (_hasselectedpatrimnonrap)
|
|
drPatrimonioNonRappresentabile.Descrizione = Resource.PatrimonioNonRappresentabile_label;
|
|
else
|
|
drPatrimonioNonRappresentabile.Descrizione = Resource.PatrimonioNonRappresentabile_label_NoNota;
|
|
drPatrimonioNonRappresentabile.ControValore = patrimonioNonRappresentabile;
|
|
|
|
ds86.PatrimonioNonRappresentabile.Rows.Add(drPatrimonioNonRappresentabile);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Riga del Totale
|
|
|
|
DataSetS86.MacroAssetTotaleRow drTot = ds86.MacroAssetTotale.NewMacroAssetTotaleRow();
|
|
if (patrimonioNonRappresentabile > 0)
|
|
drTot.Totale = Resource.DSS86MacroAssetClass_Totale;
|
|
else
|
|
drTot.Totale = Resource.Totale;
|
|
|
|
drTot.Controvalore = ctvTotale;
|
|
drTot.Percentuale = 100.00M;
|
|
ds86.MacroAssetTotale.Rows.Add(drTot);
|
|
|
|
if (patrimonioNonRappresentabile > 0)
|
|
{
|
|
DataSetS86.TotaleRow drTotale;
|
|
drTotale = ds86.Totale.NewTotaleRow();
|
|
drTotale.Descrizione = Resource.Totale;
|
|
|
|
drTotale.ControValore = (ctvTotale + patrimonioNonRappresentabile);
|
|
if (patrimonioNonRappresentabile > 0)
|
|
ds86.Totale.Rows.Add(drTotale);
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|
|
}
|
|
dsr.DatiSezione = ds86;
|
|
dsr.Esito = ds86.MacroAssetClass.Rows.Count;
|
|
|
|
return dsr;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
}
|
|
}
|