using DevExpress.Data.Extensions;
using DevExpress.DataProcessing.InMemoryDataProcessor;
using System.Linq;
using DevExpress.XtraReports.Parameters;
namespace SwaggerAntifraude.Servicios
{
    public class tsXtraReport
    {
        public static void ExportarAPDF(byte[] Plantilla, object Datos, string FicheroPDF)
        {
            DevExpress.XtraReports.UI.XtraReport xr;
            string s = System.Text.Encoding.UTF8.GetString(Plantilla);
            using (StreamWriter sw = new StreamWriter(new MemoryStream()))
            {
                sw.Write(s);
                sw.Flush();

                xr = DevExpress.XtraReports.UI.XtraReport.FromStream(sw.BaseStream, true);
            }
            try
            {             

                var pr = xr.Parameters.Cast<DevExpress.XtraReports.Parameters.Parameter>()
                      .FirstOrDefault(p => p.Name == "Fecha");

               
                pr.Value = DateTime.Now;
                pr.Visible = false;
            }
            catch (Exception ex)
            {
            }
            xr.DataSource = Datos;
            xr.CreateDocument();
            xr.ExportToPdf(FicheroPDF);
        }

    }
}
