Пример #1
0
        public async Task <IActionResult> GeneraXlsRicercaPerDataPostalizzazioneRaccomandata(DateTime dalGiorno, DateTime alGiorno)
        {
            try
            {
                _logger.LogInformation("Stored procedure execution: new_dettaglio_distinte_storico_cartelle");
                var nddscQuery = new DAL.StoredProcedure.SP_new_dettaglio_distinte_storico_cartelle(_context);
                var sFileName  = @"PostalizzazioneRaccomadata_" + $"{dalGiorno:yyyyMMdd}" + "-" + $"{alGiorno:yyyyMMdd}" + ".xlsx";
                _logger.LogInformation("Create XLSX file: " + sFileName);

                var stream = new MemoryStream();

                await Task.Run(() =>
                {
                    using (var package = new ExcelPackage(stream))
                    {
                        using (var worksheet = package.Workbook.Worksheets.Add(
                                   $"{dalGiorno:yyyyMMdd}" + " - " +
                                   $"{alGiorno:yyyyMMdd}"))
                        {
                            SetColumnWidth(worksheet, XlsTypes.DataPostalizzazioneRaccomandata);
                            //First add the headers
                            worksheet.Cells[1, 1].Value = "DISTINTA";
                            worksheet.Cells[1, 2].Value = "TOTALE LETTERE";
                            worksheet.Cells[1, 3].Value = "FILE RRDP30NO";
                            worksheet.Cells[1, 4].Value = "DATA POSTALIZZAZIONE";

                            using (var cells = worksheet.Cells[1, 1, 1, 4])
                            {
                                cells.Style.Font.Bold        = true;
                                cells.Style.Fill.PatternType = ExcelFillStyle.Solid;
                                cells.Style.Fill.BackgroundColor.SetColor(Color.LightGray);
                            }

                            //Add values
                            int numRigaCella = 2;

                            foreach (var item in nddscQuery.Get(dalGiorno, alGiorno).Result)
                            {
                                worksheet.Cells[numRigaCella, 1].Value = item.NumeroDistinta;
                                worksheet.Cells[numRigaCella, 2].Value = item.TotLettere;
                                worksheet.Cells[numRigaCella, 3].Value = item.FileName;
                                worksheet.Cells[numRigaCella, 4].Value = $"{item.DataSpedizione:dd/MM/yyyy}";
                                numRigaCella++;
                            }

                            package.Save(); //Save the workbook.
                        }
                    }
                });

                var fileName = AppendInfoToFile(sFileName, stream, out var fileType);
                return(File(stream, fileType, fileName));
            }
            catch (Exception ex)
            {
                _logger.LogError("Error generating xls: " + ex.Message);
                return(BadRequest(ex.Message));
            }
        }
Пример #2
0
        public async Task <IActionResult> RicercaPerDataPostalizzazioneRaccomadata(NewStoricoCartelle filtroRicerca)
        {
            // GET /StoricoCartelle/RicercaPerDataPostalizzazioneRaccomadata/2019-05-01/2019-05-21
            Task <IEnumerable <NewStoricoCartelle.Elenco_Distinte> > result = null;

            try
            {
                _logger.LogInformation("Stored procedure execution: new_dettaglio_distinte_storico_cartelle");
                var nddscQuery = new DAL.StoredProcedure.SP_new_dettaglio_distinte_storico_cartelle(RepositoryContext);

                result = nddscQuery.Get(Convert.ToDateTime(filtroRicerca.DalGiorno), Convert.ToDateTime(filtroRicerca.AlGiorno));
                filtroRicerca.ElencoDistinte = result.Result;
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, ex.Message);

                //return Content(ex.Message);
            }
            return(Ok(filtroRicerca));
        }