using System;
using ceTe.DynamicPDF;
using Consulenza.ReportCommon;
using Consulenza.ReportWriter.Business.OBJ_PDF;
using Consulenza.ReportWriter.Business;
using System.Data;
using System.Collections.Generic;

namespace Consulenza.ReportWriter.Manager.Chapter.Base.Proposta
{
    public class IntestazionePatrimonioNonRappresentabile : Entity.Chapter
    {
        public IntestazionePatrimonioNonRappresentabile(EnvironmentFacade environmentFacade, int idchapter)
            : base(environmentFacade, idchapter)
        {
            Draw();
        }

        public IntestazionePatrimonioNonRappresentabile(EnvironmentFacade environmentFacade, int idchapter, bool repeatoneachpage)
            : this(environmentFacade, idchapter)
        {
            RepeatOnEachPage = repeatoneachpage;
        }

        protected override sealed void Draw()
        {
            var dtP8 = GetDataTable();

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

            var data = new FormattedTextAreaPDF("Report prodotto il " + Helper.FormatDateMonthName(DateTime.Now), 315, 250, TextAlign.Left) { Y = 62, FontSize = 11, AbsolutePosition = true, AutoIncrementYWritable = false };
            var intestazione = new FormattedTextAreaPDF("PATRIMONIO NON RAPPRESENTABILE", 315, 250, TextAlign.Left) { Y = 75, FontSize = 13, FontBold = true, AbsolutePosition = true, AutoIncrementYWritable = false };

            AddElement(new PagePDF(PagePDF.PagePDFType.Generic));
            AddElement(data);
            AddElement(intestazione);
        }

        /// <summary>
        /// Recupera i dati dalla stored definita a livello database necessari al disegno dell'oggetto P8.
        /// </summary>
        /// <returns></returns>
        private 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_P8", parametri)
                : DataAccess.ExecuteDataTableStoredProcedure(DBProvider.SqlServerConsulenzaBase, "REP_Prop_P8", parametri);

        }

    }
}
