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 SelettoreCertificati : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void LinqServerModeDataSource1_Selecting(object sender, DevExpress.Data.Linq.LinqServerModeDataSourceSelectEventArgs e)
        {
            e.KeyExpression = "IDCertificates";
        }

        protected void ASPxExportPdf_Click(object sender, EventArgs e)
        {
            GeneraReportPdf();
        }

        private void GeneraReportPdf()
        {
            // Aggiorna VaR95 per il certificato selezionato , salvando il valore in tabella Certificates (db FS), varTit (db FS) e in tabella tit (db Guardian)
            string ISIN = ASPxSelettoreCertificati.GetRowValues(ASPxSelettoreCertificati.FocusedRowIndex, "ISIN").ToString();

            string result = "";
            try
            {
                result = CommonClass.CallWebApi(string.Format("https://api.smart-roots.net:4001/api/varCertificatesGDN?isin={0}", ISIN));
            }
            catch (Exception ex)
            {
                result = string.Format("[{0}] - " + "Eccezione rilevata in scarico var per Certificato {0} - Errore : {1} {2}", ISIN, ex.Message, ex.InnerException);
                ScriptManager.RegisterStartupScript(this, GetType(), "ServerControlScript", "alert(\"" + result + "\");", true);
            }

            // Genera report richiamando pagina CertReports.ReportFS
            string urlReport = $"https://reports.smart-roots.net:4004/ReportFS.aspx?isin={ISIN}&output=pdf";
            ScriptManager.RegisterStartupScript(Page, typeof(System.Web.UI.Page), "OpenWindow", "window.open('" + urlReport + "');", true);
        }
    }
}