Exemple #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            // Scelta del modello in base al flag di attivazione Corte dei Conti
            string stampaUnioneStr = Request["stampaUnione"];

            this.hlScaricaDoc.Attributes.Add("onclick", "dialogArguments.window.open('ZipDocumenti.aspx');");
            if (!string.IsNullOrEmpty(stampaUnioneStr) && "true".Equals(stampaUnioneStr))
            {
                StampaUnione             = true;
                this.grdAllegati.Visible = false;
                this.tpAllegati.Visible  = false;
                this.grdArrivo.Visible   = false;
                this.tpArrivo.Visible    = false;
            }
            // Scelta del modello in base al flag di attivazione Corte dei Conti

            if (ImportDocumentsUtils.importazionePregressiAbilitata())
            {
                this.hlLink_preg.Visible     = true;
                this.hlLink_preg.NavigateUrl = "ImportDocumenti_pregressi.xls";
                this.hlLink_preg.Text        = "Pregressi";
            }

            /*
             * if (ImportDocumentsUtils.IsEnabledPregressi())
             * {
             *  this.hlLink.NavigateUrl = "ImportDocumenti_CdC.xls";
             * }
             *
             * else
             */
            {
                if (StampaUnione)
                {
                    this.hlLink.NavigateUrl = "ImportDocumenti_StampaUnione.xls";
                }
                else
                {
                    this.hlLink.NavigateUrl   = "ImportDocumenti.xls";
                    this.hlScaricaDoc.Visible = false;
                }
            }
        }
Exemple #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            // Si prova a prelevare dal call context il report
            ResultsContainer report = CallContextStack.CurrentContext.ContextState["report"] as ResultsContainer;

            byte[] temp = null;
            try
            {
                temp = ImportDocumentsUtils.CreateZipFromReport(report, UserManager.getInfoUtente());
            }
            catch (Exception) { }
            Response.ContentType = "zip";
            Response.AddHeader("content-disposition", "attachment; filename=documenti.zip");
            if (temp != null)
            {
                Response.AddHeader("content-length", "" + temp.Length);
                Response.BinaryWrite(temp);
            }
            else
            {
                Response.AddHeader("content-length", "0");
            }
            Response.Flush();
        }
Exemple #3
0
        /// <summary>
        /// Alla pressione sul bottone di creazione documenti viene avviata la procedura
        /// per la creazione dei documenti
        /// </summary>
        protected void btnCreaDocumenti_Click(object sender, EventArgs e)
        {
            #region Definizione variabili

            // Un booleano utilizzato per determinare la validità del
            // file excel
            bool canImport;

            // Il file postato
            HttpPostedFile postedFile;

            // Il content del documento
            byte[] content;

            // Il nome da attribuire al file temporaneo
            string temporaryFileName;

            // Il server path
            string serverPath;

            // L'eventuale errore avvenuto durante la lettura dei dati dal foglio
            string error;

            // L'oggetto con le informazioni sui documenti da importare
            DocumentRowDataContainer drdc;

            // L'oggetto cui delegare l'esecuzione dell'importazione
            AsyncImportDocumentExecutor importExecutor;

            // Oggetto per specificare un thread con parametri
            ParameterizedThreadStart entry;

            // Thread
            Thread thread;

            // Oggetto in cui memorizzare i parametri
            object[] parameters;

            // Il numero massimo di documenti che è possibile importare
            int maxNumber = 0;

            #endregion

            // Prelevamento del file postato
            postedFile = this.fileUploader.PostedFile;

            // Verifica del content type e dell'estensione del file al fine
            // di verificarne la validità
            //canImport = (postedFile.ContentType == "application/vnd.ms-excel")
            //    && postedFile.FileName.ToLower().EndsWith("xls");
            canImport = postedFile.FileName.ToLower().EndsWith("xls");
            // Se la verifica ha avuto esito positivo...
            if (canImport)
            {
                // Prelevamento del contenuto del file
                content = this.GetContent();

                // Creazione del nome per il file temporaneo
                temporaryFileName = String.Format("{0}.xls",
                                                  Guid.NewGuid().ToString());

                // Prelevamento del serverPath
                serverPath = Utils.getHttpFullPath();

                try
                {
                    // Pulizia del call context
                    CallContextStack.CurrentContext.ContextState["documentExporter"] = null;
                    CallContextStack.CurrentContext.ContextState["reportImport"]     = null;

                    // Reset del campo nascosto con il valore da raggiungere.
                    this.hfTargetPerc.Value = "0";

                    // Disassociazione delle sorgenti dati
                    this.grdAllegati.DataSource = null;
                    this.grdArrivo.DataSource   = null;
                    this.grdGenerale.DataSource = null;
                    this.grdGrigi.DataSource    = null;
                    this.grdInterni.DataSource  = null;
                    this.grdPartenza.DataSource = null;
                    this.grdAllegati.DataBind();
                    this.grdArrivo.DataBind();
                    this.grdGenerale.DataBind();
                    this.grdGrigi.DataBind();
                    this.grdInterni.DataBind();
                    this.grdPartenza.DataBind();

                    // Reperimento delle informazioni sui documenti da importare
                    drdc = ImportDocumentsUtils.ReadDocumentDataFromExcelFile(
                        content,
                        UserManager.getInfoUtente(),
                        UserManager.getRuolo(),
                        !StampaUnione,
                        out error);


                    if (String.IsNullOrEmpty(error))
                    {
                        // Reperimento del numero massimo di documenti importabili
                        maxNumber = ImportDocumentsUtils.GetMaxDocumentsNumber(UserManager.getInfoUtente());

                        // Se maxNumber è più minore del numero di documenti estratti dal foglio excel
                        if (maxNumber < drdc.AttachmentDocument.Length +
                            drdc.GrayDocument.Length +
                            drdc.InDocument.Length +
                            drdc.OutDocument.Length +
                            drdc.OwnDocument.Length)
                        {
                            throw new Exception(String.Format(
                                                    "E' possibile importare al massimo {0} documenti per volta.", maxNumber));
                        }

                        // Creazione di un nuovo oggetto cui delegare l'importazione dei documenti
                        importExecutor = new AsyncImportDocumentExecutor(StampaUnione);

                        // Salvataggio dell'oggetto esecutore nel CallContext
                        CallContextStack.CurrentContext.ContextState["documentExporter"] = importExecutor;

                        // Creazione del thread con parametri
                        //entry = new ParameterizedThreadStart(importExecutor.ExecuteImport);

                        // Creazione del thread
                        //thread = new Thread(entry);

                        // Creazione dell'array dei parametri
                        //parameters = new object[] {
                        //    drdc,
                        //    Utils.getHttpFullPath(),
                        //    UserManager.getInfoUtente(),
                        //    UserManager.getRuolo()
                        //};

                        // Partenza del thread
                        //thread.Start(parameters);

                        // Avvio del timer
                        //this.tmrUpdateInfo.Enabled = true;

                        importExecutor.ExecuteImport(
                            new object[] {
                            drdc,
                            Utils.getHttpFullPath(),
                            UserManager.getInfoUtente(),
                            UserManager.getRuolo()
                        });

                        int analyzedDocument, totalDocument;
                        // Si richiedono le statistiche
                        importExecutor.GetStatistics(out analyzedDocument, out totalDocument);

                        // Viene prelevato il report
                        report = importExecutor.GetReport();
                    }
                    else
                    {
                        report            = new ResultsContainer();
                        report.General    = new ImportResult[1];
                        report.General[0] = new ImportResult()
                        {
                            Outcome = OutcomeEnumeration.KO,
                            Message = error
                        };
                    }
                    // Se il report Generale non contiene elementi, viene aggiunto un
                    // result positivo
                    if (report.General == null || report.General.Length == 0)
                    {
                        report.General = new ImportResult[1];

                        report.General[0] = new ImportResult()
                        {
                            Outcome = OutcomeEnumeration.NONE,
                            Message = "Il processo di importazione è terminato."
                        };
                    }

                    // Associazione degli array dei risultati alle varie griglia
                    this.grdGenerale.DataSource = report.General;
                    this.grdArrivo.DataSource   = report.InDocument;
                    this.grdPartenza.DataSource = report.OutDocument;
                    this.grdInterni.DataSource  = report.OwnDocument;
                    this.grdGrigi.DataSource    = report.GrayDocument;
                    this.grdAllegati.DataSource = report.Attachment;

                    // Binding delle sorgenti dati
                    this.grdGenerale.DataBind();
                    this.grdArrivo.DataBind();
                    this.grdPartenza.DataBind();
                    this.grdInterni.DataBind();
                    this.grdGrigi.DataBind();
                    this.grdAllegati.DataBind();

                    // Creazione del data set per l'esportazione del report di importazione
                    DataSet dataSet = this.GenerateDataSet(report);

                    // Path e nome file del template
                    string templateFilePath = Server.MapPath("formatPdfExport.xml");

                    // Aggiunta nell call context del file documento  con le informazioni
                    // da scivere nel report
                    CallContextStack.CurrentContext.ContextState["reportImport"] =
                        global::ProspettiRiepilogativi.Frontend.PdfReport.do_MakePdfReport(
                            global::ProspettiRiepilogativi.Frontend.ReportDisponibili.ReportLogMassiveImport,
                            templateFilePath,
                            dataSet,
                            null);

                    // Abilitazione pulsante esportazione
                    this.btnEsportaReport.Enabled = true;

                    // Aggiornamento pannello bottoniera
                    this.upButtons.Update();

                    //link di scarica zip
                    if (StampaUnione)
                    {
                        CallContextStack.CurrentContext.ContextState["report"] = report;
                        this.hlScaricaDoc.Visible = true;
                        this.upScarica.Update();
                    }
                }
                catch (Exception ex)
                {
                    // Creazione di un array di result con un solo elemento
                    // che conterrà il dettaglio dell'eccezione
                    report = new ResultsContainer();

                    report.General = new ImportResult[1];

                    report.General[0] = new ImportResult
                    {
                        Outcome = OutcomeEnumeration.KO,
                        Message = ex.Message,
                    };

                    this.grdGenerale.DataSource = report.General;
                    this.grdGenerale.DataBind();
                }
            }
            else
            {
                report            = new ResultsContainer();
                report.General    = new ImportResult[1];
                report.General[0] = new ImportResult
                {
                    Outcome = OutcomeEnumeration.KO,
                    Message = "Estensione del file non valida."
                };
            }


            // Si nasconde il popup
            this.mdlPopupWait.Hide();
        }