fistlove159 发表于 2020-4-4 09:50:39

H5转JSViewer后,提示Report not found: XXX.rdlx

环境:vs2019+ar13,mvc5
在项目中使用H5方式完全正常,当使用JSViewer方式后,js和css都能加载,但在展示页总是提示:Report not found: xxx.rdlx。调试了很久都没解决。
项目中的Startup1文件为:
using System;
using System.Data;
using System.IO;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Web.Routing;
using GrapeCity.ActiveReports;
using GrapeCity.ActiveReports.Aspnet.Viewer;
using GrapeCity.ActiveReports.PageReportModel;
using GrapeCity.Enterprise.Data.DataEngine.Expressions;
using Microsoft.Owin;
using Owin;



namespace Ntnet.Application.Web
{
    public class Startup1
    {
      public object GetReport(string P)
      {
            PageReport rep = BuildReportLayout();
            rep = AddDataSetDataSource(rep);

            rep.Report.Name = P;
            string path = System.Web.Hosting.HostingEnvironment.MapPath("~/");
            creatReportFile(rep, @"" + path + "Reports/" + P);

            rep.Load(new FileInfo(@"" + path + "Reports/" + P));
            return rep.Report;
      }

      /// <summary>
      /// UseCustomStore方式
      /// </summary>
      /// <param name="app"></param>
      public void Configuration1(IAppBuilder app)
      {
            app.UseReporting(settings =>
            {
                settings.UseCompression = true;
                settings.UseCustomStore(GetReport);
                settings.LocateDataSource = args =>
                {
                  if (args.Report.Name.ToString() == "静态报表.rdlx")
                  {
                        if (args.DataSet.Query.DataSourceName == "DataSource1")
                        {
                            if (args.DataSet.Name == "DataSet1")
                            {
                              return GetData();
                            }
                        }
                        return null;
                  }
                  else if (args.Report.Name.ToString() == "动态报表.rdlx")
                  {
                        if (args.DataSet.Query.DataSourceName == "DataSource1")
                        {
                            if (args.DataSet.Name == "DataSet1")
                            {
                              return GetData();
                            }
                        }
                        return null;
                  }
                  else
                  {
                        return null;
                  }

                };


            });
      }

      /// <summary>
      /// UseFileStore模式
      /// </summary>
      /// <param name="app"></param>
      public void Configuration(IAppBuilder app)
      {
            app.UseReporting(settings =>
            {
                settings.UseCompression = true;
                string path = System.Web.Hosting.HostingEnvironment.MapPath("~/");
                settings.UseFileStore(new DirectoryInfo(@"" + path + "Reports"));
                settings.LocateDataSource = args =>
                {
                  if (args.Report.Name.ToString() == "静态报表.rdlx")
                  {
                        if (args.DataSet.Query.DataSourceName == "DataSource1")
                        {
                            if (args.DataSet.Name == "DataSet1")
                            {
                              return GetData();
                            }
                        }
                        return null;
                  }
                  else if (args.Report.Name.ToString() == "动态报表.rdlx")
                  {
                        if (args.DataSet.Query.DataSourceName == "DataSource1")
                        {
                            if (args.DataSet.Name == "DataSet1")
                            {
                              return GetData();
                            }
                        }
                        return null;
                  }
                  else
                  {
                        return null;
                  }

                };


            });
      }

      #region创建UI界面元素
      /// <summary>
      /// 创建UI界面元素
      /// </summary>
      /// <returns></returns>
      public static PageReport BuildReportLayout()
      {
            PageReport report = new PageReport();
            report.Report.Body.Height = "5cm";
            report.Report.Width = "20cm";

            //创建table
            Table table = new Table();
            table.Name = "Table1";
            table.Top = "1cm";
            table.Left = "0.635cm";
            table.Style.BackgroundColor = ExpressionInfo.FromString("Transparent");
            GrapeCity.ActiveReports.PageReportModel.Border border = new GrapeCity.ActiveReports.PageReportModel.Border();
            border.Color = ExpressionInfo.FromString("DarkGray");
            border.Style = ExpressionInfo.FromString("Solid");
            border.Width = ExpressionInfo.FromString("1pt");
            table.Style.Border = border;

            //创建行
            TableRow[] tableRows = new TableRow;
            tableRows.SetValue(new TableRow(), 0);
            tableRows.Height = "1.25cm";
            table.Height += "1.25cm";
            tableRows.SetValue(new TableRow(), 1);
            tableRows.Height = "1.25cm";
            table.Height += "1.25cm";


            //创建列
            TableColumn[] tableColumns = new TableColumn;

            tableColumns.SetValue(new TableColumn(), 0);
            tableColumns.Width = "3cm";
            table.Width += "3cm";
            table.TableColumns.Add(tableColumns);

            tableColumns.SetValue(new TableColumn(), 1);
            tableColumns.Width = "3cm";
            table.Width += "3cm";
            table.TableColumns.Add(tableColumns);

            tableColumns.SetValue(new TableColumn(), 2);
            tableColumns.Width = "3cm";
            table.Width += "3cm";
            table.TableColumns.Add(tableColumns);

            //创建单元格
            TableCell[] tableCells = new TableCell;
            tableCells.SetValue(new TableCell(), 0);
            tableCells.SetValue(new TableCell(), 1);
            tableCells.SetValue(new TableCell(), 2);
            tableCells.SetValue(new TableCell(), 3);
            tableCells.SetValue(new TableCell(), 4);
            tableCells.SetValue(new TableCell(), 5);

            //创建文本框并将文本框添加到单元格中
            TextBox[] tableTextBoxes = new TextBox;
            tableTextBoxes.SetValue(new TextBox(), 0);
            tableTextBoxes.Name = "textBox0";
            tableTextBoxes.Value = ExpressionInfo.FromString("用户姓名");
            tableTextBoxes.Style.TextAlign = ExpressionInfo.FromString("Right");
            tableTextBoxes.Style.VerticalAlign = ExpressionInfo.FromString("Middle");
            tableTextBoxes.Style.FontWeight = ExpressionInfo.FromString("Bold");
            tableTextBoxes.Style.FontSize = ExpressionInfo.FromString("10pt");
            GrapeCity.ActiveReports.PageReportModel.Border border0 = new GrapeCity.ActiveReports.PageReportModel.Border();
            border0.Color = ExpressionInfo.FromString("DarkGray");
            border0.Style = ExpressionInfo.FromString("Solid");
            border0.Width = ExpressionInfo.FromString("1pt");
            tableTextBoxes.Style.Border = border0;
            tableCells.ReportItems.Add(tableTextBoxes);


            tableTextBoxes.SetValue(new TextBox(), 1);
            tableTextBoxes.Name = "textBox1";
            tableTextBoxes.Value = ExpressionInfo.FromString("用户密码");
            tableTextBoxes.Style.TextAlign = ExpressionInfo.FromString("Right");
            tableTextBoxes.Style.VerticalAlign = ExpressionInfo.FromString("Middle");
            tableTextBoxes.Style.FontWeight = ExpressionInfo.FromString("Bold");
            tableTextBoxes.Style.FontSize = ExpressionInfo.FromString("10pt");
            GrapeCity.ActiveReports.PageReportModel.Border border1 = new GrapeCity.ActiveReports.PageReportModel.Border();
            border1.Color = ExpressionInfo.FromString("DarkGray");
            border1.Style = ExpressionInfo.FromString("Solid");
            border1.Width = ExpressionInfo.FromString("1pt");
            tableTextBoxes.Style.Border = border1;
            tableCells.ReportItems.Add(tableTextBoxes);

            tableTextBoxes.SetValue(new TextBox(), 2);
            tableTextBoxes.Name = "textBox2";
            tableTextBoxes.Value = ExpressionInfo.FromString("用户年龄");
            tableTextBoxes.Style.TextAlign = ExpressionInfo.FromString("Right");
            tableTextBoxes.Style.VerticalAlign = ExpressionInfo.FromString("Middle");
            tableTextBoxes.Style.FontWeight = ExpressionInfo.FromString("Bold");
            tableTextBoxes.Style.FontSize = ExpressionInfo.FromString("10pt");
            GrapeCity.ActiveReports.PageReportModel.Border border2 = new GrapeCity.ActiveReports.PageReportModel.Border();
            border2.Color = ExpressionInfo.FromString("DarkGray");
            border2.Style = ExpressionInfo.FromString("Solid");
            border2.Width = ExpressionInfo.FromString("1pt");
            tableTextBoxes.Style.Border = border2;
            tableCells.ReportItems.Add(tableTextBoxes);

            tableTextBoxes.SetValue(new TextBox(), 3);
            tableTextBoxes.Name = "textBox3";
            tableTextBoxes.Value = ExpressionInfo.FromString("=Fields!user_name.Value");
            tableTextBoxes.Style.TextAlign = ExpressionInfo.FromString("Right");
            tableTextBoxes.Style.VerticalAlign = ExpressionInfo.FromString("Middle");
            GrapeCity.ActiveReports.PageReportModel.Border border3 = new GrapeCity.ActiveReports.PageReportModel.Border();
            border3.Color = ExpressionInfo.FromString("DarkGray");
            border3.Style = ExpressionInfo.FromString("Solid");
            border3.Width = ExpressionInfo.FromString("1pt");
            tableTextBoxes.Style.Border = border3;
            tableCells.ReportItems.Add(tableTextBoxes);

            tableTextBoxes.SetValue(new TextBox(), 4);
            tableTextBoxes.Name = "textBox4";
            tableTextBoxes.Value = ExpressionInfo.FromString("=Fields!user_password.Value");
            tableTextBoxes.Style.TextAlign = ExpressionInfo.FromString("Right");
            tableTextBoxes.Style.VerticalAlign = ExpressionInfo.FromString("Middle");
            GrapeCity.ActiveReports.PageReportModel.Border border4 = new GrapeCity.ActiveReports.PageReportModel.Border();
            border4.Color = ExpressionInfo.FromString("DarkGray");
            border4.Style = ExpressionInfo.FromString("Solid");
            border4.Width = ExpressionInfo.FromString("1pt");
            tableTextBoxes.Style.Border = border4;
            tableCells.ReportItems.Add(tableTextBoxes);

            tableTextBoxes.SetValue(new TextBox(), 5);
            tableTextBoxes.Name = "textBox1";
            tableTextBoxes.Value = ExpressionInfo.FromString("=Fields!user_age.Value");
            tableTextBoxes.Style.TextAlign = ExpressionInfo.FromString("Right");
            tableTextBoxes.Style.VerticalAlign = ExpressionInfo.FromString("Middle");
            GrapeCity.ActiveReports.PageReportModel.Border border5 = new GrapeCity.ActiveReports.PageReportModel.Border();
            border5.Color = ExpressionInfo.FromString("DarkGray");
            border5.Style = ExpressionInfo.FromString("Solid");
            border5.Width = ExpressionInfo.FromString("1pt");
            tableTextBoxes.Style.Border = border2;
            tableCells.ReportItems.Add(tableTextBoxes);


            //将单元格添加到行中
            tableRows.TableCells.Add(tableCells);
            tableRows.TableCells.Add(tableCells);
            tableRows.TableCells.Add(tableCells);

            tableRows.TableCells.Add(tableCells);
            tableRows.TableCells.Add(tableCells);
            tableRows.TableCells.Add(tableCells);

            //将行添加到table中
            table.Header.TableRows.Add(tableRows);
            table.Details.TableRows.Add(tableRows);

            //将table添加到模板Body中
            report.Report.Body.ReportItems.Add(table);
            return report;
      }
      #endregion


      #region创建数据源,数据集
      /// <summary>
      /// 创建数据源,数据集
      /// </summary>
      /// <param name="report"></param>
      /// <returns></returns>
      public static PageReport AddDataSetDataSource(PageReport report)
      {
            // create DataSource for the report
            DataSource dataSource = new DataSource();
            dataSource.Name = "DataSource1";
            dataSource.ConnectionProperties.DataProvider = "DATASET";
            dataSource.ConnectionProperties.ConnectString = ExpressionInfo.FromString("");
            //Create DataSet with specified query and load database fields to the DataSet
            GrapeCity.ActiveReports.PageReportModel.DataSet dataSet = new GrapeCity.ActiveReports.PageReportModel.DataSet();
            Query query = new Query();
            dataSet.Name = "DataSet1";
            query.DataSourceName = "DataSource1";
            dataSet.Query = query;

            String[] fieldsList = new String[] { "user_name", "user_password", "user_age" };

            foreach (string fieldName in fieldsList)
            {
                Field field = new Field(fieldName, fieldName, null);
                dataSet.Fields.Add(field);
            }
            //create report definition with specified DataSet and DataSource
            report.Report.DataSources.Add(dataSource);
            report.Report.DataSets.Add(dataSet);
            return report;
      }
      #endregion


      #region 生成报表物理文件
      /// <summary>
      /// 生成报表物理文件
      /// </summary>
      /// <param name="rep"></param>
      /// <param name="FilePath"></param>
      public static void creatReportFile(PageReport report, string fileName)
      {
            string rpt = report.ToRdlString();
            byte[] data = Encoding.UTF8.GetBytes(rpt);

            Stream stream = new MemoryStream();
            stream.Read(data, 0, data.Length);
            // 设置当前流的位置为流的开始
            stream.Seek(0, SeekOrigin.Begin);
            // 把 byte[] 写入文件
            FileStream fs = new FileStream(fileName, FileMode.Create);
            BinaryWriter bw = new BinaryWriter(fs);
            bw.Write(data);
            bw.Close();
            bw.Dispose();
            fs.Close();
            fs.Dispose();
            stream.Close();
            stream.Dispose();
      }
      #endregion


      #region 创建动态数据
      /// <summary>
      /// 创建动态数据
      /// </summary>
      /// <returns></returns>
      public DataTable GetData()
      {
            DataTable dt = new DataTable("User");
            dt.Columns.Add("user_name", typeof(string));
            dt.Columns.Add("user_password", typeof(string));
            dt.Columns.Add("user_age", typeof(int));


            System.Data.DataRow dr = dt.NewRow();
            dr = "张三";
            dr = "123";
            dr = 20;
            dt.Rows.Add(dr);

            dr = dt.NewRow();
            dr = "李四";
            dr = "123";
            dr = 23;
            dt.Rows.Add(dr);

            return dt;
      }
      #endregion
    }
}



附截图:


KearneyKang 发表于 2020-4-7 09:51:38

你好,你使用的是V13还是V14。你自己新建一个JSviewer的demo可以正常运行不。建议自己先新建一个新的JSviewer的项目,看看,具体可以参考该博客,进行demo的验证:https://gcdn.grapecity.com.cn/forum.php?mod=viewthread&tid=74434&extra=page%3D1

fistlove159 发表于 2020-4-7 10:03:08

KearneyKang 发表于 2020-4-7 09:51
你好,你使用的是V13还是V14。你自己新建一个JSviewer的demo可以正常运行不。建议自己先新建一个新的JSview ...

已经解决,是我缺少了一个引用

KearneyKang 发表于 2020-4-7 13:59:38

好的,解决了就好
页: [1]
查看完整版本: H5转JSViewer后,提示Report not found: XXX.rdlx