private void DescargarReporte(Reporte reporte) { try { Token token = (Token)Session["token"]; _reporteService = new ReporteService(token.access_token); string base64 = _reporteService.Obtener(reporte); byte[] pdfBytes = Convert.FromBase64String(base64); string tipoInforme = Reporte.GetTiposReporte()[reporte.IdReporte]; string pdflocation = "C:\\Storage\\"; string nombrePDF = $"Reporte de {tipoInforme} - {DateTime.Now:yyyy-MM-dd}.pdf"; string ruta = Path.Combine(pdflocation, nombrePDF); FileStream file = File.Create(ruta); file.Write(pdfBytes, 0, pdfBytes.Length); file.Close(); ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Notificacion", "window.open('VerReporte.aspx?nombre=" + nombrePDF + "','_blank');", true); } catch (Exception ex) { string mensaje = ex != null && ex.Message != null ? ex.Message : "Ocurrió un error inesperado. Intente nuevamente"; ScriptManager.RegisterStartupScript(Page, Page.GetType(), "error", "Swal.fire('Error', '" + mensaje + "', 'error');", true); } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { ValidarSesion(); DateTime fecha = DateTime.Now; txtFechaInicio.Text = fecha.ToString("yyyy-MM-dd"); txtFechaFin.Text = fecha.ToString("yyyy-MM-dd"); txtFechaInicio.Attributes["max"] = fecha.ToString("yyyy-MM-dd"); txtFechaFin.Attributes["max"] = fecha.ToString("yyyy-MM-dd"); var tipoReportes = Reporte.GetTiposReporte(); ddlTipoReporte.DataSource = tipoReportes; ddlTipoReporte.DataValueField = "Key"; ddlTipoReporte.DataTextField = "Value"; ddlTipoReporte.DataBind(); ddlTipoReporte.Items.Insert(0, new ListItem("Seleccionar", "0")); ddlTipoReporte.SelectedIndex = 0; } }