using DevExpress.Web;
using DevExpress.XtraCharts;
using DevExpress.XtraCharts.Native;
using DevExpress.XtraCharts.Web;
using DevExpress.Pdf;
using DevExpress.XtraPrinting;
using DevExpress.XtraGrid;
using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DevExpress.Utils;
using DevExpress.XtraReports.UI;
using DevExpress.XtraReports.Web;
using System.Windows.Forms;

namespace OlympiaIntranet
{
    public partial class GPMDispRendRiskAPI : System.Web.UI.Page
    {
        string cod_ges = String.Empty;
        //string cod_adv = String.Empty;
        string cod_lin = String.Empty;

        protected void Page_Load(object sender, EventArgs e)
        {
            cod_ges = Request.QueryString["cod_ges"];
            //cod_adv = Request.QueryString["cod_adv"];
            cod_lin = Request.QueryString["cod_lin"];

            //Session["cod_ges"] = cod_ges; // serve per popolare gridlookupLinea!!                                             
            //if (String.IsNullOrEmpty(cod_ges) == true || String.IsNullOrEmpty(cod_adv) == true || String.IsNullOrEmpty(cod_lin) == true)
            //{
            //    CommonClass.MessageBox(this, "Parametri mancanti ricontrollare!");
            //    return;
            //}
            if (String.IsNullOrEmpty(cod_ges) == true || String.IsNullOrEmpty(cod_lin) == true)
            {
                CommonClass.MessageBox(this, "Parametri mancanti ricontrollare!");
                return;
            }

            PlottaPointChart();

            buttonEsportaPdf_Click(this, null);
        }

        private void PlottaPointChart()
        {

            //if (!(String.IsNullOrEmpty(cod_ges) == false && String.IsNullOrEmpty(cod_adv) == false && String.IsNullOrEmpty(cod_lin) == false)) return;
            if (!(String.IsNullOrEmpty(cod_ges) == false && String.IsNullOrEmpty(cod_lin) == false)) return;

            // nota: esiste pure GDN_GPMDispRendRisk_PointCharts1 e GDN_GPM_Gestori1 perchè Filippo voleva avere l'opzione -- TUTTI -- sui gestori, ma poi il grafico si vedeva tutto incasinato e abbiamo desistito (07/06/2022)
            DataTable dtPointsChartData = CommonClass.execQuery_Datatable_Sql("GDN_GPMDispRendRisk_PointCharts2", 
                                                                              Properties.Settings.Default.SqlConnection, 
                                                                              cod_ges, 
                                                                              "", 
                                                                              cod_lin, 
                                                                              -1, 
                                                                              -1, 
                                                                              CommonClass.AddBusinessDays(DateTime.Today.Date, -1), // prende l'ultimo giorno lavorativo del mese precedente
                                                                              "",
                                                                              "",
                                                                              null,
                                                                              ""); 
            Session["dtPointsChartData"] = dtPointsChartData;

            //var listAssetClass = (from r in dtPointsChartData.AsEnumerable()
            //                      select r);


            pointChart.DataSource = dtPointsChartData;

            // Cancella tutte le serie prima di plottare 
            pointChart.Series.Clear();

            // Cancella tutti i titoli della serie prima di plottare
            pointChart.Titles.Clear();

            // Rimuove legenda aggiuntiva dei portafogli
            pointChart.Legends.Clear();

            // Setta titolo del grafico
            SettaTitoloGrafico(pointChart);

            string seriesName = $"{cod_lin}";
            Series series = new Series(seriesName, ViewType.Point);
            series.ArgumentScaleType = ScaleType.Numerical;
            series.LabelsVisibility = DefaultBoolean.True;
            series.Label.TextPattern = "{HINT}";
            series.ArgumentDataMember = "VaR Medio 95";
            series.ValueDataMembers[0] = "Performance YTD";
            series.ShowInLegend = false;
            series.CrosshairContentShowMode = CrosshairContentShowMode.Default;
            series.CrosshairLabelPattern = "Var Medio 95%: {A:F2}% \r\n Perf YTD: {V:F2}%"; // ref link : https://docs.devexpress.com/CoreLibraries/DevExpress.XtraCharts.SeriesBase.CrosshairLabelPattern
            (series.Label as PointSeriesLabel).ResolveOverlappingMode = ResolveOverlappingMode.JustifyAroundPoint;
            foreach (DataRow row in dtPointsChartData.Rows)
            {
                SeriesPoint sp = new SeriesPoint(row["VaR Medio 95"], row["Performance YTD"]);
                if (row["Codice Portafoglio"].ToString() != "LIMITE VAR") sp.ToolTipHint = $"{row["Codice Portafoglio"]} - {row["Cliente"]}";
                series.Points.Add(sp);
            }

            pointChart.Series.Add(series);

            XYDiagram diagram = (XYDiagram)pointChart.Diagram;
            if (diagram != null)
            {
                diagram.AxisX.Title.Text = "VAR MEDIO 95%";
                diagram.AxisX.Title.Visibility = DefaultBoolean.True;
                diagram.AxisY.Title.Text = "PERFORMANCE YTD";
                diagram.AxisY.Title.Visibility = DefaultBoolean.True;

                // Setta var max sul grafico (plottato solo se una linea è selezionata)
                SettaVarMax(pointChart, dtPointsChartData, cod_lin);
            }
        }

        private void SettaVarMax(WebChartControl pointChart, DataTable dtPointsChartData, string Linea)
        {
            // Cancella eventuali precedenti linee verticali
            XYDiagram diagram = (XYDiagram)pointChart.Diagram;
            diagram.AxisX.ConstantLines.Clear();

            // Se è selezionata una singola linea, allora rileva il limite var prendendo il primo ptf in dtPointsChartData e leggendo il valore da tabraplim
            if (Linea != "-- TUTTI --")
            {
                double limiteVar = (from r in dtPointsChartData.AsEnumerable()
                                    select Convert.ToDouble(r["LimiteVar"])).FirstOrDefault();
                ConstantLine cl1 = new ConstantLine("Limite VaR");

                cl1.AxisValue = limiteVar;
                cl1.Visible = true;
                cl1.ShowBehind = false;
                cl1.Color = System.Drawing.Color.Red;
                cl1.LineStyle.DashStyle = DashStyle.Solid;
                cl1.LineStyle.Thickness = 2;
                cl1.ShowInLegend = false;

                diagram.AxisX.ConstantLines.Add(cl1);

                // Define the whole range for the X-axis. 
                //diagram.AxisX.WholeRange.Auto = false;
                //diagram.AxisX.WholeRange.SetMinMaxValues(0, limiteVar * 0.2);
            }
        }

        private void SettaTitoloGrafico(WebChartControl chartControl)
        {
            // Create chart titles.
            ChartTitle chartTitle1 = new ChartTitle();
            ChartTitle chartTitle2 = new ChartTitle();
            // Define the text for the titles.
            chartTitle1.Text = "<b>GPM DISPERSION RISK / REND</b>";

            chartTitle2.Text = TitoloFiltri();

            chartTitle2.WordWrap = true;
            chartTitle2.MaxLineCount = 2;

            // Define the alignment of the titles.
            chartTitle1.Alignment = StringAlignment.Center;
            chartTitle2.Alignment = StringAlignment.Center;

            // Place the titles where it's required.
            chartTitle1.Dock = ChartTitleDockStyle.Top;
            chartTitle2.Dock = ChartTitleDockStyle.Top;

            // Customize a title's appearance.
            chartTitle1.EnableAntialiasing = DevExpress.Utils.DefaultBoolean.True;
            chartTitle1.Font = new Font("Tahoma", 14, FontStyle.Bold);
            chartTitle1.TextColor = Color.Blue;
            chartTitle1.Indent = 10;

            // Customize a title's appearance.
            chartTitle2.EnableAntialiasing = DevExpress.Utils.DefaultBoolean.True;
            chartTitle2.Font = new Font("Arial", 10, FontStyle.Bold);
            chartTitle2.TextColor = Color.Black;
            chartTitle2.Indent = 10;

            // Add the titles to the chart.
            chartControl.Titles.AddRange(new ChartTitle[] { chartTitle1, chartTitle2 });
        }
        private string TitoloFiltri()
        {
            string filtro = String.Empty;
            if (String.IsNullOrEmpty(cod_ges) == true) { filtro += "Gestore: tutti "; } else { filtro += $"Gestore: {cod_ges} "; }
            //if (String.IsNullOrEmpty(cod_adv) == true) { filtro += "Advisor: tutti "; } else { filtro += $"Advisor: {cod_adv} "; }
            if (String.IsNullOrEmpty(cod_lin) == true) { filtro += "Linea: tutti "; } else { filtro += $"Linea: {cod_lin} "; }
            return (filtro);
        }

        protected void buttonGeneraGrafici_Click(object sender, EventArgs e)
        {
            PlottaPointChart();
        }

        protected void buttonEsportaPdf_Click(object sender, EventArgs e)
        {

            // Esporta grafico in pdf 
            /*
            var ps = new PrintingSystem();
            ps.PageSettings.Landscape = true;
            var link1 = new PrintableComponentLink();
            pointChart.DataBind();

            link1.Component = ((IChartContainer)pointChart).Chart;
            link1.Landscape = true;
            link1.PrintingSystem = ps;
            link1.CreateDocument();
            ps.Document.AutoFitToPagesWidth = 1; // Fit to page 

            using (var stream = new MemoryStream())
            {
                link1.PrintingSystem.ExportToPdf(stream);
                Response.Clear();
                Response.Buffer = false;
                Response.AppendHeader("Content-Type", "application/pdf");
                Response.AppendHeader("Content-Transfer-Encoding", "binary");
                Response.AppendHeader("Content-Disposition", $"attachment; filename=GPMDispRendRisk_{DateTime.Now.Date.ToString("yyyyMMdd")}.pdf");
                Response.BinaryWrite(stream.GetBuffer());
                Response.End();
            }
            ps.Dispose();
          */


            /*
            XtraReport r = new XtraReport();
            r.Bands.Add(new DetailBand());
            r.Bands[BandKind.Detail].Height = Convert.ToInt32(pointChart.Height.Value * pointChart.Width.Value / (r.PageWidth - r.Margins.Left - r.Margins.Right));
            XRChart chart = new XRChart();
            ((IChartContainer)chart).Assign(((IChartContainer)pointChart).Chart);
            r.Bands[BandKind.Detail].Controls.Add(chart);
            chart.Size = new Size(r.PageWidth - r.Margins.Left - r.Margins.Right, r.Bands[BandKind.Detail].Height);

            ReportViewer rv = new ReportViewer();
            rv.Report = r;
            r.ExportOptions.Pdf.ShowPrintDialogOnOpen = false;
            r.Landscape = true;
            rv.WritePdfTo(this.Response);
            */

            XtraReport r = new XtraReport();
            r.Bands.Add(new DetailBand());
            //int charts_height = Convert.ToInt32(pointChart.Height.Value * pointChart.Width.Value / (r.PageWidth - r.Margins.Left - r.Margins.Right));
            r.Bands[BandKind.Detail].Height = 720;
            XRChart chart = new XRChart();
            chart.Size = new Size(1280, 720);
            ((IChartContainer)chart).Assign(((IChartContainer)pointChart).Chart);
            r.ExportOptions.Pdf.ShowPrintDialogOnOpen = false;
            r.ExportOptions.Pdf.ConvertImagesToJpeg = true;
            r.PrintingSystem.Document.AutoFitToPagesWidth = 1;
            r.Landscape = true;
            r.Bands[BandKind.Detail].Controls.Add(chart);
            ReportViewer rv = new ReportViewer();
            rv.Report = r;
            rv.WritePdfTo(this.Response);
        }

        protected void gridLookupGestore_ValueChanged(object sender, EventArgs e)
        {
            // ref: https://supportcenter.devexpress.com/ticket/details/q340370/aspxgridlookup-how-to-refresh-the-control-after-some-data-is-changed
            // note: Per refreshare gridlookupLinea e gridlookupConsulente sulla base del valore di gridLookupGestore, salvo il valore gestore in una variabile di sessione Session["cod_ges"] 
            //       e poi il refresh/rebind di SqlDSLinee e SqlDSConsulente verrà effettuato nell'evento lato client EndCallBack

            //ASPxGridView grid = gridLookupGestore.GridView;
            //object objGestore = grid.GetRowValues(grid.FocusedRowIndex, new string[] { "Gestore" });

            //if (objGestore != null)
            //{
            //    Session["cod_ges"] = (string)objGestore;
            //}

        }

        protected void pointChart_DataBound(object sender, EventArgs e)
        {
            //foreach (Series series in pointChart.Series)
            //    foreach (SeriesPoint point in series.Points)
            //        point.ToolTipHint = "porca troia";
        }
    }
    //public partial class GPMDispRendRiskAPI : System.Web.UI.Page
    //{
    //    string cod_ges = String.Empty;
    //    string cod_pro = String.Empty;
    //    string cod_lin = String.Empty;

    //    protected void Page_Load(object sender, EventArgs e)
    //    {
    //        cod_ges = Request.QueryString["cod_ges"];
    //        cod_pro = Request.QueryString["cod_pro"];
    //        cod_lin = Request.QueryString["cod_lin"];

    //        Session["cod_ges"] = cod_ges; // serve per popolare gridlookupLinea!!                                             

    //        PlottaPointChart();

    //        buttonEsportaPdf_Click(this, null);
    //    }

    //    private void PlottaPointChart()
    //    {

    //        if (!(String.IsNullOrEmpty(cod_ges) == false && String.IsNullOrEmpty(cod_pro) == false && String.IsNullOrEmpty(cod_lin) == false)) return;

    //        // nota: esiste pure GDN_GPMDispRendRisk_PointCharts1 e GDN_GPM_Gestori1 perchè Filippo voleva avere l'opzione -- TUTTI -- sui gestori, ma poi il grafico si vedeva tutto incasinato e abbiamo desistito (07/06/2022)
    //        DataTable dtPointsChartData = CommonClass.execQuery_Datatable_Sql("GDN_GPMDispRendRisk_PointCharts", Properties.Settings.Default.SqlConnection, cod_ges, cod_pro, cod_lin, -1, -1, CommonClass.AddBusinessDays(DateTime.Today.Date,-1)); // prende l'ultimo giorno lavorativo del mese precedente
    //        Session["dtPointsChartData"] = dtPointsChartData;

    //        //var listAssetClass = (from r in dtPointsChartData.AsEnumerable()
    //        //                      select r);


    //        pointChart.DataSource = dtPointsChartData;

    //        // Cancella tutte le serie prima di plottare 
    //        pointChart.Series.Clear();

    //        // Cancella tutti i titoli della serie prima di plottare
    //        pointChart.Titles.Clear();

    //        // Rimuove legenda aggiuntiva dei portafogli
    //        pointChart.Legends.Clear();

    //        // Setta titolo del grafico
    //        SettaTitoloGrafico(pointChart);

    //        string seriesName = $"{cod_lin}";
    //        Series series = new Series(seriesName, ViewType.Point);
    //        series.ArgumentScaleType = ScaleType.Numerical;
    //        series.LabelsVisibility = DefaultBoolean.True;
    //        series.Label.TextPattern = "{HINT}";
    //        series.ArgumentDataMember = "VaR Medio 95";
    //        series.ValueDataMembers[0] = "Performance YTD";
    //        series.ShowInLegend = false;
    //        series.CrosshairContentShowMode = CrosshairContentShowMode.Default;
    //        series.CrosshairLabelPattern = "Var Medio 95%: {A:F2}% \r\n Perf YTD: {V:F2}%"; // ref link : https://docs.devexpress.com/CoreLibraries/DevExpress.XtraCharts.SeriesBase.CrosshairLabelPattern
    //        (series.Label as PointSeriesLabel).ResolveOverlappingMode = ResolveOverlappingMode.JustifyAroundPoint;
    //        foreach (DataRow row in dtPointsChartData.Rows)
    //        {
    //            SeriesPoint sp = new SeriesPoint(row["VaR Medio 95"], row["Performance YTD"]);
    //            if (row["Codice Portafoglio"].ToString() != "LIMITE VAR") sp.ToolTipHint = $"{row["Codice Portafoglio"]} - {row["Cliente"]}";
    //            series.Points.Add(sp);
    //        }

    //        pointChart.Series.Add(series);

    //        XYDiagram diagram = (XYDiagram)pointChart.Diagram;
    //        if (diagram != null)
    //        {
    //            diagram.AxisX.Title.Text = "VAR MEDIO 95%";
    //            diagram.AxisX.Title.Visibility = DefaultBoolean.True;
    //            diagram.AxisY.Title.Text = "PERFORMANCE YTD";
    //            diagram.AxisY.Title.Visibility = DefaultBoolean.True;

    //            // Setta var max sul grafico (plottato solo se una linea è selezionata)
    //            SettaVarMax(pointChart, dtPointsChartData, cod_lin);
    //        }
    //    }

    //    private void SettaVarMax(WebChartControl pointChart, DataTable dtPointsChartData, string Linea)
    //    {
    //        // Cancella eventuali precedenti linee verticali
    //        XYDiagram diagram = (XYDiagram)pointChart.Diagram;
    //        diagram.AxisX.ConstantLines.Clear();

    //        // Se è selezionata una singola linea, allora rileva il limite var prendendo il primo ptf in dtPointsChartData e leggendo il valore da tabraplim
    //        if (Linea != "-- TUTTI --")
    //        {
    //            double limiteVar = (from r in dtPointsChartData.AsEnumerable()
    //                                select Convert.ToDouble(r["LimiteVar"])).FirstOrDefault();
    //            ConstantLine cl1 = new ConstantLine("Limite VaR");

    //            cl1.AxisValue = limiteVar;
    //            cl1.Visible = true;
    //            cl1.ShowBehind = false;
    //            cl1.Color = System.Drawing.Color.Red;
    //            cl1.LineStyle.DashStyle = DashStyle.Solid;
    //            cl1.LineStyle.Thickness = 2;
    //            cl1.ShowInLegend = false;

    //            diagram.AxisX.ConstantLines.Add(cl1);

    //            // Define the whole range for the X-axis. 
    //            //diagram.AxisX.WholeRange.Auto = false;
    //            //diagram.AxisX.WholeRange.SetMinMaxValues(0, limiteVar * 0.2);
    //        }
    //    }

    //    private void SettaTitoloGrafico(WebChartControl chartControl)
    //    {
    //        // Create chart titles.
    //        ChartTitle chartTitle1 = new ChartTitle();
    //        ChartTitle chartTitle2 = new ChartTitle();
    //        // Define the text for the titles.
    //        chartTitle1.Text = "<b>GPM DISPERSION RISK / REND</b>";

    //        chartTitle2.Text = TitoloFiltri();

    //        chartTitle2.WordWrap = true;
    //        chartTitle2.MaxLineCount = 2;

    //        // Define the alignment of the titles.
    //        chartTitle1.Alignment = StringAlignment.Center;
    //        chartTitle2.Alignment = StringAlignment.Center;

    //        // Place the titles where it's required.
    //        chartTitle1.Dock = ChartTitleDockStyle.Top;
    //        chartTitle2.Dock = ChartTitleDockStyle.Top;

    //        // Customize a title's appearance.
    //        chartTitle1.EnableAntialiasing = DevExpress.Utils.DefaultBoolean.True;
    //        chartTitle1.Font = new Font("Tahoma", 14, FontStyle.Bold);
    //        chartTitle1.TextColor = Color.Blue;
    //        chartTitle1.Indent = 10;

    //        // Customize a title's appearance.
    //        chartTitle2.EnableAntialiasing = DevExpress.Utils.DefaultBoolean.True;
    //        chartTitle2.Font = new Font("Arial", 10, FontStyle.Bold);
    //        chartTitle2.TextColor = Color.Black;
    //        chartTitle2.Indent = 10;

    //        // Add the titles to the chart.
    //        chartControl.Titles.AddRange(new ChartTitle[] { chartTitle1, chartTitle2 });
    //    }
    //    private string TitoloFiltri()
    //    {
    //        string filtro = String.Empty;
    //        //if (String.IsNullOrEmpty(gridLookupGestore.Text) == true) { filtro += "Gestore: tutti "; } else { filtro += $"Gestore: {gridLookupGestore.Text} "; }
    //        //if (String.IsNullOrEmpty(gridLookupConsulente.Text) == true) { filtro += "Consulente: tutti "; } else { filtro += $"Consulente: {gridLookupConsulente.Text} "; }
    //        //if (String.IsNullOrEmpty(gridLookupLinea.Text) == true) { filtro += "Linea: tutti "; } else { filtro += $"Linea: {gridLookupLinea.Text} "; }
    //        if (String.IsNullOrEmpty(cod_ges) == true) { filtro += "Gestore: tutti "; } else { filtro += $"Gestore: {cod_ges} "; }
    //        if (String.IsNullOrEmpty(cod_pro) == true) { filtro += "Consulente: tutti "; } else { filtro += $"Consulente: {cod_pro} "; }
    //        if (String.IsNullOrEmpty(cod_lin) == true) { filtro += "Linea: tutti "; } else { filtro += $"Linea: {cod_lin} "; }
    //        return (filtro);
    //    }

    //    protected void buttonGeneraGrafici_Click(object sender, EventArgs e)
    //    {
    //        PlottaPointChart();
    //    }

    //    protected void buttonEsportaPdf_Click(object sender, EventArgs e)
    //    {

    //        // Esporta grafico in pdf 
    //        /*
    //        var ps = new PrintingSystem();
    //        ps.PageSettings.Landscape = true;
    //        var link1 = new PrintableComponentLink();
    //        pointChart.DataBind();

    //        link1.Component = ((IChartContainer)pointChart).Chart;
    //        link1.Landscape = true;
    //        link1.PrintingSystem = ps;
    //        link1.CreateDocument();
    //        ps.Document.AutoFitToPagesWidth = 1; // Fit to page 

    //        using (var stream = new MemoryStream())
    //        {
    //            link1.PrintingSystem.ExportToPdf(stream);
    //            Response.Clear();
    //            Response.Buffer = false;
    //            Response.AppendHeader("Content-Type", "application/pdf");
    //            Response.AppendHeader("Content-Transfer-Encoding", "binary");
    //            Response.AppendHeader("Content-Disposition", $"attachment; filename=GPMDispRendRisk_{DateTime.Now.Date.ToString("yyyyMMdd")}.pdf");
    //            Response.BinaryWrite(stream.GetBuffer());
    //            Response.End();
    //        }
    //        ps.Dispose();
    //      */


    //        /*
    //        XtraReport r = new XtraReport();
    //        r.Bands.Add(new DetailBand());
    //        r.Bands[BandKind.Detail].Height = Convert.ToInt32(pointChart.Height.Value * pointChart.Width.Value / (r.PageWidth - r.Margins.Left - r.Margins.Right));
    //        XRChart chart = new XRChart();
    //        ((IChartContainer)chart).Assign(((IChartContainer)pointChart).Chart);
    //        r.Bands[BandKind.Detail].Controls.Add(chart);
    //        chart.Size = new Size(r.PageWidth - r.Margins.Left - r.Margins.Right, r.Bands[BandKind.Detail].Height);

    //        ReportViewer rv = new ReportViewer();
    //        rv.Report = r;
    //        r.ExportOptions.Pdf.ShowPrintDialogOnOpen = false;
    //        r.Landscape = true;
    //        rv.WritePdfTo(this.Response);
    //        */

    //        XtraReport r = new XtraReport();
    //        r.Bands.Add(new DetailBand());
    //        //int charts_height = Convert.ToInt32(pointChart.Height.Value * pointChart.Width.Value / (r.PageWidth - r.Margins.Left - r.Margins.Right));
    //        r.Bands[BandKind.Detail].Height = 720;
    //        XRChart chart = new XRChart();
    //        chart.Size = new Size(1280, 720);
    //        ((IChartContainer)chart).Assign(((IChartContainer)pointChart).Chart);                               
    //        r.ExportOptions.Pdf.ShowPrintDialogOnOpen = false;
    //        r.ExportOptions.Pdf.ConvertImagesToJpeg = true;
    //        r.PrintingSystem.Document.AutoFitToPagesWidth = 1;
    //        r.Landscape = true;
    //        r.Bands[BandKind.Detail].Controls.Add(chart);
    //        ReportViewer rv = new ReportViewer();
    //        rv.Report = r;
    //        rv.WritePdfTo(this.Response);
    //    }

    //    protected void gridLookupGestore_ValueChanged(object sender, EventArgs e)
    //    {
    //        // ref: https://supportcenter.devexpress.com/ticket/details/q340370/aspxgridlookup-how-to-refresh-the-control-after-some-data-is-changed
    //        // note: Per refreshare gridlookupLinea e gridlookupConsulente sulla base del valore di gridLookupGestore, salvo il valore gestore in una variabile di sessione Session["cod_ges"] 
    //        //       e poi il refresh/rebind di SqlDSLinee e SqlDSConsulente verrà effettuato nell'evento lato client EndCallBack

    //        //ASPxGridView grid = gridLookupGestore.GridView;
    //        //object objGestore = grid.GetRowValues(grid.FocusedRowIndex, new string[] { "Gestore" });

    //        //if (objGestore != null)
    //        //{
    //        //    Session["cod_ges"] = (string)objGestore;
    //        //}

    //    }

    //    protected void pointChart_DataBound(object sender, EventArgs e)
    //    {
    //        //foreach (Series series in pointChart.Series)
    //        //    foreach (SeriesPoint point in series.Points)
    //        //        point.ToolTipHint = "porca troia";
    //    }
    //}
}