using System;
using System.Collections.Generic;
using System.Data;
using Consulenza.ReportWriter.Business.OBJ_PDF;
using Consulenza.ReportWriter.Business;

namespace Consulenza.ReportWriter.Manager.Section.Base.Proposta
{
    public class P7 : Entity.Section
    {
        public P7(EnvironmentFacade environmentFacade, int idSection)
            : base(environmentFacade, idSection)
        {
            try
            {
                Draw();
            }
            catch (Exception ex)
            {
                SectionLogger.Write("P7", ex.Message, SectionLoggerMessageLevel.E, EnvironmentFacade.ReportEnvironment);
            }
        }

        /// <summary>
        /// Disegna l'oggetto P7
        /// </summary>
        protected override sealed void Draw()
        {
            var dtP7 = GetDataTable();

            if (dtP7.Rows.Count <= 0) return;


            var tabella = new TablePDF(EnvironmentFacade.RendererFacade.XLeftLimit, dtP7)
            {
                ID = "Tabella_P7"
            };
            tabella.Columns.Add(new ColumnPDF("NomeProdotto", 223, HorizontalAlignmentType.Sinistra, false, false, 7, ColumnType.Testo, "NomeProdotto", string.Empty));
            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 = "SINTESI PORTAFOGLIO COMPLESSIVO ";
            tabella.Footer = false;
            tabella.ShowBorderLastLine = true;

            AddElement(tabella);
        }       

        /// <summary>
        /// Recupera i dati necessari alla Section restituendo un DataTable.
        /// </summary>
        /// <returns></returns>
        protected sealed override DataTable GetDataTable()
        {
            var parametri = new List<Parametro>();

            #region Definizione dei parametri

            var parametro = new Parametro
            {
                Direction = ParameterDirection.Input,
                DbType = DbType.Int64,
                ParameterName = "chiaveClientePB",
                Value = EnvironmentFacade.ReportEnvironment.Cliente.Chiave
            };
            parametri.Add(parametro);

            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_P7", parametri)
                : DataAccess.ExecuteDataTableStoredProcedure(DBProvider.SqlServerConsulenzaBase, "REP_Prop_P7", parametri);
        }

        /// <summary>
        /// Recupera i dati necessari alla Section restituendo un DataSet.
        /// </summary>
        /// <returns></returns>
        protected sealed override DataSet GetDataSet()
        {
            return null;
        }
    }
}