using System; using System.Collections.Generic; using System.Text; using System.Data; namespace PDFGenerator.BusinessLayer.DataSection { /// /// Summary description for DSS57BISConfrontoPiramideAttualeModello /// public class DSS157ConfrontoPiramideAttualeModello : IDataSection { public DSS157ConfrontoPiramideAttualeModello() { // // TODO: Add constructor logic here // } /// /// Recupera i dati per la stampa della S57BIS. /// /// /// /// /// public DataSectionResult getDataSection(List tabelleSessione, string querySql, DataThread dataThread) { DataSetS157 dataset157 = new DataSetS157(); 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; DataSetS157.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 DataSetS157.GraficoPiramideRow rowDSS157GraficoPiramide; rowDSS157GraficoPiramide = dataset157.GraficoPiramide.NewGraficoPiramideRow(); rowDSS157GraficoPiramide.AreaBisogno = row["needarea"].ToString(); rowDSS157GraficoPiramide.Controvalore = conv.ConvertNum(row["controvaloreAttuale"].ToString()); totaleRisorseAllocate += Convert.ToDecimal(row["controvaloreAttuale"]); rowDSS157GraficoPiramide.Rischio = row["var_needareaString"] == DBNull.Value ? conv.ConvertNum(row["var_needarea"].ToString()) : row["var_needareaString"].ToString(); rowDSS157GraficoPiramide.Copertura = row["copertura_needareaString"] == DBNull.Value ? conv.ConvertNum(row["copertura_needarea"].ToString()) : row["copertura_needareaString"].ToString(); if ((Convert.ToDecimal(rowDSS157GraficoPiramide.Controvalore) == 0) || (Convert.ToDecimal(rowDSS157GraficoPiramide.Controvalore) == 0M) || (Convert.ToDecimal(rowDSS157GraficoPiramide.Controvalore) == 0M)) { rowDSS157GraficoPiramide.Rischio = "0,00"; rowDSS157GraficoPiramide.Copertura = "100,00"; } dataset157.GraficoPiramide.AddGraficoPiramideRow(rowDSS157GraficoPiramide); //Grafico Farfalla DataSetS157.GraficoFarfallaRow rowDSS157GraficoFarfalla; rowDSS157GraficoFarfalla = dataset157.GraficoFarfalla.NewGraficoFarfallaRow(); rowDSS157GraficoFarfalla.PercentualeAttuale = row["percentualeAttuale"] == DBNull.Value ? 0 : decimal.Round(Convert.ToDecimal(row["percentualeAttuale"]), 2); if (rowDSS157GraficoFarfalla.PercentualeAttuale > valorePercMaggiore) { tupla_maggiore = rowDSS157GraficoFarfalla; valorePercMaggiore = rowDSS157GraficoFarfalla.PercentualeAttuale; } residuo -= rowDSS157GraficoFarfalla.PercentualeAttuale; rowDSS157GraficoFarfalla.PercentualeModello = row["percentualeModello"] == DBNull.Value ? 0 : Convert.ToDecimal(row["percentualeModello"]); rowDSS157GraficoFarfalla.NeedArea = row["needarea"].ToString().ToLower(); rowDSS157GraficoFarfalla.OrderNeedArea = iOrderNeedArea++; dataset157.GraficoFarfalla.AddGraficoFarfallaRow(rowDSS157GraficoFarfalla); } } if (residuo != 0 && tupla_maggiore != null) { tupla_maggiore.PercentualeAttuale += residuo; } #endregion #region Risorse Allocate DataSetS157.RisorseAllocateRow rowDSS157RisorseAllocate; rowDSS157RisorseAllocate = dataset157.RisorseAllocate.NewRisorseAllocateRow(); rowDSS157RisorseAllocate.Descrizione = "TOTALE RISORSE ALLOCATE"; rowDSS157RisorseAllocate.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 rowDSS157RisorseAllocate.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(); rowDSS157RisorseAllocate.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(rowDSS157RisorseAllocate.Controvalore) == 0) { rowDSS157RisorseAllocate.Rischio = "0,00"; rowDSS157RisorseAllocate.Copertura = "100,00"; } // #endregion #region Risorse non allocate decimal rischioRisorsenonAllocate = 0; decimal coperturaRisorseNonAllocate = -1; decimal ctvRisorseNonAllocate = 0; DataSetS157.RisorseNonAllocateRow rowDSS157RisorseNonAllocate; rowDSS157RisorseNonAllocate = dataset157.RisorseNonAllocate.NewRisorseNonAllocateRow(); rowDSS157RisorseNonAllocate.Descrizione = "Risorse non allocate"; DataRow[] drRisorseNonAllocate = dt.Select(" NeedArea='Na'"); if (drRisorseNonAllocate.Length > 0) { rowDSS157RisorseNonAllocate.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"]); } } rowDSS157RisorseNonAllocate.Controvalore = conv.ConvertNum(ctvRisorseNonAllocate); rowDSS157RisorseNonAllocate.Rischio = conv.ConvertNum(rischioRisorsenonAllocate); rowDSS157RisorseNonAllocate.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) { dataset157.RisorseAllocate.AddRisorseAllocateRow(rowDSS157RisorseAllocate); dataset157.RisorseNonAllocate.AddRisorseNonAllocateRow(rowDSS157RisorseNonAllocate); } #endregion #region Risorse Finanziarie // totale delle Risorse Finanziarie DataSetS157.RisorseFinanziarieRow rowDSS157RisorseFinanziarie; rowDSS157RisorseFinanziarie = dataset157.RisorseFinanziarie.NewRisorseFinanziarieRow(); rowDSS157RisorseFinanziarie.Descrizione = "TOTALE RISORSE FINANZIARIE"; rowDSS157RisorseFinanziarie.Controvalore = conv.ConvertNum(totaleRisorseAllocate + ctvRisorseNonAllocate); rowDSS157RisorseFinanziarie.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); rowDSS157RisorseFinanziarie.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) { rowDSS157RisorseFinanziarie.Rischio = "0,00"; rowDSS157RisorseFinanziarie.Copertura = "100,00"; } dataset157.RisorseFinanziarie.AddRisorseFinanziarieRow(rowDSS157RisorseFinanziarie); #endregion #region Conto Corrente Negativo decimal ctvContoCorrente = 0; DataSetS157.ContoCorrenteRow rowDSS157ContoCorrente; rowDSS157ContoCorrente = dataset157.ContoCorrente.NewContoCorrenteRow(); //rowDSS57BISContoCorrente.Descrizione = "Conto corrente"; rowDSS157ContoCorrente.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; rowDSS157ContoCorrente.Controvalore = conv.ConvertNum(ctvContoCorrente); rowDSS157ContoCorrente.Rischio = "0,00"; rowDSS157ContoCorrente.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"); dataset157.ContoCorrente.AddContoCorrenteRow(rowDSS157ContoCorrente); #endregion #region Linea Self Negativa // MIOFOGLIO 20181129 QUI VA CHIAMATA LA [C6MartPeriodico].[PL_S43LineaSelfBF] (VEDI DSS160) DataTable dt_B = null; if (dataThread.Periodico) dt_B = SectionManager.GetDataSection(tabelleSessione, "[C6MartPeriodico].[PL_S43LineaSelfBF]", dataThread); else dt_B = SectionManager.GetDataSection(tabelleSessione, "[C6Mart].[PL_S43LineaSelfBF]", dataThread); DataSetS157.LineaSelfRow dr_B; #region New Section Data Load decimal ctvLineaSelfNegativa = 0; foreach (DataRow row in dt_B.Rows) { dr_B = dataset157.LineaSelf.NewLineaSelfRow(); dr_B.Descrizione = row["CodInterno"].Equals("XY") ? "Liquidità negativa \"Linee GP Eligo\"" : string.Format("Liquidità negativa \"{0}\"", row["NomeProdotto"]); ctvLineaSelfNegativa += Convert.ToDecimal( row["ControValore"]); dr_B.Controvalore = conv.ConvertNum(Convert.ToDecimal(row["ControValore"])); dr_B.Rischio = "n.c."; dr_B.Copertura = "100,00"; // acquisire anche i due campi nuovi (CodInterno e CodSottoprodotto)?? //dr_B.CodInterno = row["CodInterno"].ToString(); //dr_B.CodSottoprodotto = row["CodSottoprodotto"].ToString(); dataset157.LineaSelf.AddLineaSelfRow(dr_B); } //--MIOFOGLIO 20181129 //decimal ctvLineaSelfNegativa = 0; //DataSetS157.LineaSelfRow rowDSS157LineaSelfNegativa; //rowDSS157LineaSelfNegativa = dataset157.LineaSelf.NewLineaSelfRow(); //rowDSS157LineaSelfNegativa.Descrizione = "Liquidità negativa \"Linee GP Eligo\""; //ctvLineaSelfNegativa = dataThread.TotalSelfNegCurrentAccountValue; //rowDSS157LineaSelfNegativa.Controvalore = conv.ConvertNum(ctvLineaSelfNegativa); //rowDSS157LineaSelfNegativa.Rischio = "n.c."; //rowDSS157LineaSelfNegativa.Copertura = "100,00"; //dataset157.LineaSelf.AddLineaSelfRow(rowDSS157LineaSelfNegativa); #endregion #endregion #region PartiteViaggianti DataSetS157.PartiteViaggiantiRow rowDSS157PartiteViaggianti; rowDSS157PartiteViaggianti = dataset157.PartiteViaggianti.NewPartiteViaggiantiRow(); rowDSS157PartiteViaggianti.Descrizione = Resource.PartiteViaggianti; decimal totalePartiteViaggianti = dataThread.PartiteViaggiantiInvestimento + dataThread.PartiteViaggiantiDisinvestimento; rowDSS157PartiteViaggianti.ControValore = conv.ConvertNum(totalePartiteViaggianti); if (totalePartiteViaggianti != 0) dataset157.PartiteViaggianti.AddPartiteViaggiantiRow(rowDSS157PartiteViaggianti); #endregion #region Totale Patrimonio DataSetS157.TotalePatrimonioRow rowDSS157TotalePatrimonio; rowDSS157TotalePatrimonio = dataset157.TotalePatrimonio.NewTotalePatrimonioRow(); rowDSS157TotalePatrimonio.Descrizione = "TOTALE PATRIMONIO"; decimal totalePatrimonio = totaleRisorseAllocate + ctvContoCorrente + totalePartiteViaggianti + ctvRisorseNonAllocate + ctvLineaSelfNegativa; rowDSS157TotalePatrimonio.ControValore = conv.ConvertNum(totalePatrimonio); //V Settato per le approsimazioni ctvTotale = totaleRisorseAllocate; //Hazem if (dt.Rows[0]["var_totString"] != DBNull.Value) rowDSS157TotalePatrimonio.Rischio = dt.Rows[0]["var_totString"].ToString(); else rowDSS157TotalePatrimonio.Rischio = conv.ConvertNum(dt.Rows[0]["var_tot"]); if (dt.Rows[0]["copertura_totString"] != DBNull.Value) rowDSS157TotalePatrimonio.Copertura = dt.Rows[0]["copertura_totString"].ToString(); else rowDSS157TotalePatrimonio.Copertura = conv.ConvertNum(dt.Rows[0]["copertura_tot"]); dataset157.TotalePatrimonio.AddTotalePatrimonioRow(rowDSS157TotalePatrimonio); #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(dataset157.GraficoPiramide); dwMostraColonnaCopertura.RowFilter = "Copertura <> '100,00'"; dtMostraColonnaCopertura = dwMostraColonnaCopertura.ToTable(); _mostracolonnacopertura = (dtMostraColonnaCopertura.Rows.Count > 0 || (coperturaRisorseNonAllocate != 100M && coperturaRisorseNonAllocate != -1M)); DataSetS157.ResultSetRow rowDSS157ResultSet; rowDSS157ResultSet = dataset157.ResultSet.NewResultSetRow(); rowDSS157ResultSet.MostraColonnaCopertura = _mostracolonnacopertura; dataset157.ResultSet.AddResultSetRow(rowDSS157ResultSet); #endregion } //V condizione presente nella S57 non riportata nella bis dataThread.TotaleS57 = ctvTotale + ctvNA + dataThread.ContoCorrente - dataThread.PatrimonioNonRappresentabile; } dsr.DatiSezione = dataset157; dsr.Esito = dataset157.GraficoPiramide.Rows.Count; return dsr; } } }