using System; using System.Collections.Generic; using System.Data; using Consulenza.ReportWriter.Business.OBJ_PDF; using Consulenza.ReportCommon; using Consulenza.ReportWriter.Business; using System.Linq; namespace Consulenza.ReportWriter.Manager.Section.Base.Proposta { public class P4 : Entity.Section { public P4(EnvironmentFacade environmentFacade, int idSection) : base(environmentFacade, idSection) { try { Draw(); } catch (Exception ex) { SectionLogger.Write("P4", ex.Message, SectionLoggerMessageLevel.E, EnvironmentFacade.ReportEnvironment); } } /// /// Disegna l'oggetto P4 /// protected override sealed void Draw() { var dtP4 = GetDataTable(); var testi = GetText(); if (dtP4.Rows.Count <= 0) return; var totaleControvaloreAttuale = Convert.ToDecimal(dtP4.Compute("Sum(Ctv_Attuale)", string.Empty)); var totaleControvaloreProspettico = Convert.ToDecimal(dtP4.Compute("Sum(Ctv_Prospettico)", string.Empty)); var totaleVersamentiAggiuntivi = totaleControvaloreProspettico - totaleControvaloreAttuale; var tabella = new TablePDF(EnvironmentFacade.RendererFacade.XLeftLimit, dtP4); tabella.Columns.Add(new ColumnPDF("NomeProdotto", 223, HorizontalAlignmentType.Sinistra, false, false, 7, ColumnType.Testo, "NomeProdotto", "Nome prodotto")); tabella.Columns.Add(new ColumnPDF("Ctv_Attuale", 150, HorizontalAlignmentType.Destra, false, false, 7, ColumnType.Decimale, "Ctv_Attuale", "Controvalore attuale (€)")); tabella.Columns.Add(new ColumnPDF("Ctv_Prospettico", 150, HorizontalAlignmentType.Destra, false, false, 7, ColumnType.Decimale, "Ctv_Prospettico", "Controvalore prospettico (€)")); tabella.TitleRow = true; tabella.TitleRowText = "VERSAMENTI AGGIUNTIVI: " + Helper.FormatCurrency(totaleVersamentiAggiuntivi.ToString()) + " €"; #region Note Linea Protetta (AssetNoRischio) var dtP4AssetNoRischio = dtP4.Select("flag_tipocontratto = 1"); var presenzaNotaAssetNoRischio = dtP4AssetNoRischio.Any(); if (presenzaNotaAssetNoRischio) { var nomeLinea = string.Join(", ", (from DataRow row in dtP4AssetNoRischio select row["nomelinea"]).Distinct()); var testoNota = testi.Rows[0]["testo1"].ToString().Replace("@NomeLinea", nomeLinea); var campiAsterisco = new[] { "NomeProdotto" }; // campi del datasource su cui aggiungere gli asterischi di rimando alla note. var notaAssetNoRischio = new TableNotePDF(TableNotePDF.TableNotePositionType.PièDiTabella, testoNota, campiAsterisco, "flag_tipocontratto=1"); tabella.Notes.Add(notaAssetNoRischio); } #endregion // Footer tabella.FooterColumns.Add(new ColumnPDF("Totale", 223, HorizontalAlignmentType.Sinistra, false, true, 8, ColumnType.Testo)); tabella.FooterColumns.Add(new ColumnPDF("Totale Controvalore Attuale", 150, HorizontalAlignmentType.Destra, false, true, 8, ColumnType.Decimale)); tabella.FooterColumns.Add(new ColumnPDF("Totale Controvalore Prospettico", 150, HorizontalAlignmentType.Destra, false, true, 8, ColumnType.Decimale)); tabella.FooterCells[0, 0].Value = "Totale"; tabella.FooterCells[1, 0].Value = totaleControvaloreAttuale.ToString(); tabella.FooterCells[2, 0].Value = totaleControvaloreProspettico.ToString(); AddElement(tabella); AddElement(new SpacePDF(20)); } /// /// Recupera i dati necessari alla Section restituendo un DataTable. /// /// protected sealed override DataTable GetDataTable() { var parametri = new List(); #region Definizione dei parametri var parametro = new Parametro { Direction = ParameterDirection.Input, DbType = DbType.Int32, ParameterName = "chiaveProposta", Value = EnvironmentFacade.ReportEnvironment.Proposta.Chiave }; parametri.Add(parametro); #endregion return EnvironmentFacade.ReportEnvironment.Proposta.PropostaCBUnica ? DataAccess.ExecuteDataTableStoredProcedure(DBProvider.SqlServerConsulenzaUnica, "REP_Prop_P4", parametri) : DataAccess.ExecuteDataTableStoredProcedure(DBProvider.SqlServerConsulenzaBase, "REP_Prop_P4", parametri); } /// /// Recupera i dati necessari alla Section restituendo un DataSet. /// /// protected sealed override DataSet GetDataSet() { return null; } } }