using System;
using System.Collections.Generic;
using System.Linq;
using Consulenza.ExternalServices;
using Consulenza.ReportWriter.Business;
using Consulenza.ReportWriter.Business.OBJ_PDF;
using System.Data;
using Consulenza.ReportWriter.Business.CHART_PDF;
using Consulenza.ReportCommon;
using Consulenza.ReportWriter.Business.Entity;
using System.Text;
using System.Drawing;
using Dundas.Charting.WebControl;
using System.Globalization;
using System.IO;
using System.Drawing.Imaging;

namespace Consulenza.ReportWriter.Manager.Section.Immobiliare.MonitoraggioNucleo
{
    /// <summary>
    /// Scheda 14
    /// </summary>
    public class S14 : Monitoraggio.S14
    {

        public S14(EnvironmentFacade environmentFacade, int idSection)
            : base(environmentFacade, idSection)
        {
        }

        protected override DataSet GetDataSet()
        {
            var parametri = new List<Parametro>
            {
                new Parametro
                {
                    Direction = ParameterDirection.Input,
                    DbType = DbType.Int32,
                    ParameterName = "chiaveNucleo",
                    Value = EnvironmentFacade.ReportEnvironment.Cliente.Chiave
                }
            };

            return DataAccess.ExecuteDataSetStoredProcedure(DBProvider.SqlServerConsulenzaUnica, "REP_ImmobiliareMonitoraggio_S14_MapDistrGeografica_NEW", parametri);
        }

        public override Stream getImageFromStored()
        {
            var parametri = new List<Parametro>
            {
                new Parametro
                {
                    Direction = ParameterDirection.Input,
                    DbType = DbType.Int32,
                    ParameterName = "chiaveClientePB",
                    Value = 0
                },
                new Parametro
                {
                    Direction = ParameterDirection.Input,
                    DbType = DbType.Int32,
                    ParameterName = "chiaveNucleo",
                    Value = EnvironmentFacade.ReportEnvironment.NucleoImmobiliare.ChiaveNucleo
                }
            };

            var data = DataAccess.ExecuteDataSetStoredProcedure(DBProvider.SqlServerConsulenzaUnica, "REP_ImmobiliareMonitoraggio_S14_MapDistrGeografica_Image", parametri);

            byte[] imageBytes = (byte[])data.Tables[0].Rows[0][0];
            MemoryStream ms = new MemoryStream(imageBytes, 0, imageBytes.Length);
            ms.Write(imageBytes, 0, imageBytes.Length);
            return ms;
        }
    }
}
