using System;
using System.Data;
using ReportVS;
using System.Collections.Generic;
using ConsulenzaEvoluta;
//ISPB using bancafideuram.traceoperation;
public partial class showStoredPDF : System.Web.UI.Page
{
    public int identificativoPDF;
    public int pdfC6;
    public string codiceFiscale;
    public string stampaDiretta = "";
    public DocumentPDF documentPDF;

    protected void Page_Load(object sender, EventArgs e)
    {
        identificativoPDF = Convert.ToInt32(Request.QueryString.Get("pdfID"));
        pdfC6 = Convert.ToInt32(Request.QueryString.Get("pdfC6"));
        codiceFiscale = Request.QueryString.Get("codiceFiscale");

        #region Log TraceOperation

        if (WebConfigParameter.getParameter("Ambiente").ToUpper() == "ESTERNO")
        {
            try
            { 
                //ISPB >>>>
                //TraceOperation operation = new TraceOperation();
                //operation.Url = WebConfigParameter.getParameter("WSTRACEOPERATION").ToString();

                //string codiceUtenteWindows = "0000000";
                //if (User.Identity.Name.Length > 0)
                //{
                //    int pos = User.Identity.Name.IndexOf("\\") + 1;
                //    codiceUtenteWindows = User.Identity.Name.Substring(pos, User.Identity.Name.Length - pos).ToUpper();
                //}

                //operation.WriteLog(new LogDataTypeWS()
                //{
                //    Acronimo = WebConfigParameter.getParameter("CODICEAPPLICAZIONE").ToString(),
                //    CodFiscalePiva = codiceFiscale,
                //    CodIban = null,
                //    CodNdg = null,
                //    CodRapporto = null,
                //    CodSndg = null,
                //    CodTerminale = Request.Url.Host,
                //    CodTipoRichiesta = "S",
                //    DataRichiesta = DateTime.Now.ToString("yyyyMMddHHmmss"),
                //    DesRichiesta = Request.Url.ToString().Length > 4000 ? Request.Url.ToString().Substring(0, 4000) : Request.Url.ToString(),
                //    IdInput = "0",
                //    MatricolaUtente = codiceUtenteWindows
                //});
                //ISPB <<<<<<
            }
            catch (Exception ex)
            {
                #region Scrivo l'errore nella tabella REP_Errori di CE.

                List<Parametro> parametri = new List<Parametro>();
                Parametro parametro = new Parametro();
                parametro.DbType = DbType.String;
                parametro.Value = User.Identity.Name;
                parametro.ParameterName = "utentewindows";
                parametri.Add(parametro);

                parametro = new Parametro();
                parametro.DbType = DbType.String;
                parametro.Value = string.Format("{0}{1} {2}", "TraceOperation.", User.Identity.Name, ex.Message);
                parametro.ParameterName = "errore";
                parametri.Add(parametro);

                parametro = new Parametro();
                parametro.DbType = DbType.String;
                parametro.Value = string.Format("{0}{1} {2}", "TraceOperation.", User.Identity.Name, ex.Message);
                parametro.ParameterName = "errorebreve";
                parametri.Add(parametro);

                BusinessManager.ExecuteStoredProcedure_ConsulenzaEvoluta("REP_TracciaErrore", parametri);

                #endregion
            }
        }

        #endregion

        readPDF();
    }

    protected void readPDF()
    {
        documentPDF = new DocumentPDF(true); //lo chiamo con il bool per evitare che carichi INUTILMENTE il mondo
        documentPDF.renderPDFFromDB(identificativoPDF, pdfC6);
    }
}