using DevExpress.Export;
using DevExpress.Web;
using DevExpress.XtraPrinting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace OlympiaIntranet
{
    public partial class CapienzaOrdiniSella : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack) {
                gvCapienzaOrdiniSella.DataBind();
            }
        }

        protected void buttonCaricaDati_Click(object sender, EventArgs e)
        {
            if (Session["cod_ges"] != null && Session["filtra_negativi"] != null)
            {
                //SqlDSCapienzaOrdiniSella.SelectCommand = "GDN_CapienzaOrdiniSella";
                //SqlDSCapienzaOrdiniSella.SelectCommandType = SqlDataSourceCommandType.StoredProcedure;
                //Parameter p = SqlDSCapienzaOrdiniSella.SelectParameters["cod_ges"];
                //SqlDSCapienzaOrdiniSella.SelectParameters.Remove(p);
                //SqlDSCapienzaOrdiniSella.SelectParameters.Add("cod_ges", (string)objGestore);
                //Parameter q = SqlDSCapienzaOrdiniSella.SelectParameters["filtra_negativi"];
                //SqlDSCapienzaOrdiniSella.SelectParameters.Remove(q);
                //SqlDSCapienzaOrdiniSella.SelectParameters.Add("filtra_negativi", rblFiltraNegativi.SelectedIndex.ToString());
                gvCapienzaOrdiniSella.DataBind();
                  
            }
        }

        protected void buttonEsportaExcel_Click(object sender, EventArgs e)
        {
            ASPxGridViewExporter1.ExportSelectedRowsOnly = false;
            ASPxGridViewExporter1.FileName = DateTime.Now.ToString("yyyyMMdd_HHmm") + " - Capienza Ordini Fondi Sella";
            XlsxExportOptionsEx op = new XlsxExportOptionsEx() { ExportType = ExportType.DataAware }; // in DataAware mode l'evento ASPxGridViewExporter_RenderBrick non viene eseguito!!
            ASPxGridViewExporter1.WriteXlsxToResponse(op);
        }

        protected void gridLookupGestore_ValueChanged(object sender, EventArgs e)
        {
            ASPxGridView grid = gridLookupGestore.GridView;
            object objGestore = grid.GetRowValues(grid.FocusedRowIndex, new string[] { "Gestore" });

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

        protected void gvOrdiniSella_DataBound(object sender, EventArgs e)
        {

        }

        protected void rblFiltraNegativi_ValueChanged(object sender, EventArgs e)
        {
            Session["filtra_negativi"] = rblFiltraNegativi.SelectedIndex;
        }
    }
}