找回密码
 立即注册

QQ登录

只需一步,快速开始

fistlove159

注册会员

6

主题

21

帖子

79

积分

注册会员

积分
79

微信认证勋章

fistlove159
注册会员   /  发表于:2020-4-4 09:50  /   查看:2917  /  回复:3
环境:vs2019+ar13,mvc5
在项目中使用H5方式完全正常,当使用JSViewer方式后,js和css都能加载,但在展示页总是提示:Report not found: xxx.rdlx。调试了很久都没解决。
项目中的Startup1文件为:
  1. using System;
  2. using System.Data;
  3. using System.IO;
  4. using System.Reflection;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Web.Routing;
  8. using GrapeCity.ActiveReports;
  9. using GrapeCity.ActiveReports.Aspnet.Viewer;
  10. using GrapeCity.ActiveReports.PageReportModel;
  11. using GrapeCity.Enterprise.Data.DataEngine.Expressions;
  12. using Microsoft.Owin;
  13. using Owin;

  14. [assembly: OwinStartup(typeof(Ntnet.Application.Web.Startup1))]

  15. namespace Ntnet.Application.Web
  16. {
  17.     public class Startup1
  18.     {
  19.         public object GetReport(string P)
  20.         {
  21.             PageReport rep = BuildReportLayout();
  22.             rep = AddDataSetDataSource(rep);

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

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

  29.         /// <summary>
  30.         /// UseCustomStore方式
  31.         /// </summary>
  32.         /// <param name="app"></param>
  33.         public void Configuration1(IAppBuilder app)
  34.         {
  35.             app.UseReporting(settings =>
  36.             {
  37.                 settings.UseCompression = true;
  38.                 settings.UseCustomStore(GetReport);
  39.                 settings.LocateDataSource = args =>
  40.                 {
  41.                     if (args.Report.Name.ToString() == "静态报表.rdlx")
  42.                     {
  43.                         if (args.DataSet.Query.DataSourceName == "DataSource1")
  44.                         {
  45.                             if (args.DataSet.Name == "DataSet1")
  46.                             {
  47.                                 return GetData();
  48.                             }
  49.                         }
  50.                         return null;
  51.                     }
  52.                     else if (args.Report.Name.ToString() == "动态报表.rdlx")
  53.                     {
  54.                         if (args.DataSet.Query.DataSourceName == "DataSource1")
  55.                         {
  56.                             if (args.DataSet.Name == "DataSet1")
  57.                             {
  58.                                 return GetData();
  59.                             }
  60.                         }
  61.                         return null;
  62.                     }
  63.                     else
  64.                     {
  65.                         return null;
  66.                     }

  67.                 };


  68.             });
  69.         }

  70.         /// <summary>
  71.         /// UseFileStore模式
  72.         /// </summary>
  73.         /// <param name="app"></param>
  74.         public void Configuration(IAppBuilder app)
  75.         {
  76.             app.UseReporting(settings =>
  77.             {
  78.                 settings.UseCompression = true;
  79.                 string path = System.Web.Hosting.HostingEnvironment.MapPath("~/");
  80.                 settings.UseFileStore(new DirectoryInfo(@"" + path + "Reports"));
  81.                 settings.LocateDataSource = args =>
  82.                 {
  83.                     if (args.Report.Name.ToString() == "静态报表.rdlx")
  84.                     {
  85.                         if (args.DataSet.Query.DataSourceName == "DataSource1")
  86.                         {
  87.                             if (args.DataSet.Name == "DataSet1")
  88.                             {
  89.                                 return GetData();
  90.                             }
  91.                         }
  92.                         return null;
  93.                     }
  94.                     else if (args.Report.Name.ToString() == "动态报表.rdlx")
  95.                     {
  96.                         if (args.DataSet.Query.DataSourceName == "DataSource1")
  97.                         {
  98.                             if (args.DataSet.Name == "DataSet1")
  99.                             {
  100.                                 return GetData();
  101.                             }
  102.                         }
  103.                         return null;
  104.                     }
  105.                     else
  106.                     {
  107.                         return null;
  108.                     }

  109.                 };


  110.             });
  111.         }

  112.         #region  创建UI界面元素
  113.         /// <summary>
  114.         /// 创建UI界面元素
  115.         /// </summary>
  116.         /// <returns></returns>
  117.         public static PageReport BuildReportLayout()
  118.         {
  119.             PageReport report = new PageReport();
  120.             report.Report.Body.Height = "5cm";
  121.             report.Report.Width = "20cm";

  122.             //创建table
  123.             Table table = new Table();
  124.             table.Name = "Table1";
  125.             table.Top = "1cm";
  126.             table.Left = "0.635cm";
  127.             table.Style.BackgroundColor = ExpressionInfo.FromString("Transparent");
  128.             GrapeCity.ActiveReports.PageReportModel.Border border = new GrapeCity.ActiveReports.PageReportModel.Border();
  129.             border.Color = ExpressionInfo.FromString("DarkGray");
  130.             border.Style = ExpressionInfo.FromString("Solid");
  131.             border.Width = ExpressionInfo.FromString("1pt");
  132.             table.Style.Border = border;

  133.             //创建行
  134.             TableRow[] tableRows = new TableRow[2];
  135.             tableRows.SetValue(new TableRow(), 0);
  136.             tableRows[0].Height = "1.25cm";
  137.             table.Height += "1.25cm";
  138.             tableRows.SetValue(new TableRow(), 1);
  139.             tableRows[1].Height = "1.25cm";
  140.             table.Height += "1.25cm";


  141.             //创建列
  142.             TableColumn[] tableColumns = new TableColumn[3];

  143.             tableColumns.SetValue(new TableColumn(), 0);
  144.             tableColumns[0].Width = "3cm";
  145.             table.Width += "3cm";
  146.             table.TableColumns.Add(tableColumns[0]);

  147.             tableColumns.SetValue(new TableColumn(), 1);
  148.             tableColumns[1].Width = "3cm";
  149.             table.Width += "3cm";
  150.             table.TableColumns.Add(tableColumns[1]);

  151.             tableColumns.SetValue(new TableColumn(), 2);
  152.             tableColumns[2].Width = "3cm";
  153.             table.Width += "3cm";
  154.             table.TableColumns.Add(tableColumns[2]);

  155.             //创建单元格
  156.             TableCell[] tableCells = new TableCell[6];
  157.             tableCells.SetValue(new TableCell(), 0);
  158.             tableCells.SetValue(new TableCell(), 1);
  159.             tableCells.SetValue(new TableCell(), 2);
  160.             tableCells.SetValue(new TableCell(), 3);
  161.             tableCells.SetValue(new TableCell(), 4);
  162.             tableCells.SetValue(new TableCell(), 5);

  163.             //创建文本框并将文本框添加到单元格中
  164.             TextBox[] tableTextBoxes = new TextBox[6];
  165.             tableTextBoxes.SetValue(new TextBox(), 0);
  166.             tableTextBoxes[0].Name = "textBox0";
  167.             tableTextBoxes[0].Value = ExpressionInfo.FromString("用户姓名");
  168.             tableTextBoxes[0].Style.TextAlign = ExpressionInfo.FromString("Right");
  169.             tableTextBoxes[0].Style.VerticalAlign = ExpressionInfo.FromString("Middle");
  170.             tableTextBoxes[0].Style.FontWeight = ExpressionInfo.FromString("Bold");
  171.             tableTextBoxes[0].Style.FontSize = ExpressionInfo.FromString("10pt");
  172.             GrapeCity.ActiveReports.PageReportModel.Border border0 = new GrapeCity.ActiveReports.PageReportModel.Border();
  173.             border0.Color = ExpressionInfo.FromString("DarkGray");
  174.             border0.Style = ExpressionInfo.FromString("Solid");
  175.             border0.Width = ExpressionInfo.FromString("1pt");
  176.             tableTextBoxes[0].Style.Border = border0;
  177.             tableCells[0].ReportItems.Add(tableTextBoxes[0]);


  178.             tableTextBoxes.SetValue(new TextBox(), 1);
  179.             tableTextBoxes[1].Name = "textBox1";
  180.             tableTextBoxes[1].Value = ExpressionInfo.FromString("用户密码");
  181.             tableTextBoxes[1].Style.TextAlign = ExpressionInfo.FromString("Right");
  182.             tableTextBoxes[1].Style.VerticalAlign = ExpressionInfo.FromString("Middle");
  183.             tableTextBoxes[1].Style.FontWeight = ExpressionInfo.FromString("Bold");
  184.             tableTextBoxes[1].Style.FontSize = ExpressionInfo.FromString("10pt");
  185.             GrapeCity.ActiveReports.PageReportModel.Border border1 = new GrapeCity.ActiveReports.PageReportModel.Border();
  186.             border1.Color = ExpressionInfo.FromString("DarkGray");
  187.             border1.Style = ExpressionInfo.FromString("Solid");
  188.             border1.Width = ExpressionInfo.FromString("1pt");
  189.             tableTextBoxes[1].Style.Border = border1;
  190.             tableCells[1].ReportItems.Add(tableTextBoxes[1]);

  191.             tableTextBoxes.SetValue(new TextBox(), 2);
  192.             tableTextBoxes[2].Name = "textBox2";
  193.             tableTextBoxes[2].Value = ExpressionInfo.FromString("用户年龄");
  194.             tableTextBoxes[2].Style.TextAlign = ExpressionInfo.FromString("Right");
  195.             tableTextBoxes[2].Style.VerticalAlign = ExpressionInfo.FromString("Middle");
  196.             tableTextBoxes[2].Style.FontWeight = ExpressionInfo.FromString("Bold");
  197.             tableTextBoxes[2].Style.FontSize = ExpressionInfo.FromString("10pt");
  198.             GrapeCity.ActiveReports.PageReportModel.Border border2 = new GrapeCity.ActiveReports.PageReportModel.Border();
  199.             border2.Color = ExpressionInfo.FromString("DarkGray");
  200.             border2.Style = ExpressionInfo.FromString("Solid");
  201.             border2.Width = ExpressionInfo.FromString("1pt");
  202.             tableTextBoxes[2].Style.Border = border2;
  203.             tableCells[2].ReportItems.Add(tableTextBoxes[2]);

  204.             tableTextBoxes.SetValue(new TextBox(), 3);
  205.             tableTextBoxes[3].Name = "textBox3";
  206.             tableTextBoxes[3].Value = ExpressionInfo.FromString("=Fields!user_name.Value");
  207.             tableTextBoxes[3].Style.TextAlign = ExpressionInfo.FromString("Right");
  208.             tableTextBoxes[3].Style.VerticalAlign = ExpressionInfo.FromString("Middle");
  209.             GrapeCity.ActiveReports.PageReportModel.Border border3 = new GrapeCity.ActiveReports.PageReportModel.Border();
  210.             border3.Color = ExpressionInfo.FromString("DarkGray");
  211.             border3.Style = ExpressionInfo.FromString("Solid");
  212.             border3.Width = ExpressionInfo.FromString("1pt");
  213.             tableTextBoxes[3].Style.Border = border3;
  214.             tableCells[3].ReportItems.Add(tableTextBoxes[3]);

  215.             tableTextBoxes.SetValue(new TextBox(), 4);
  216.             tableTextBoxes[4].Name = "textBox4";
  217.             tableTextBoxes[4].Value = ExpressionInfo.FromString("=Fields!user_password.Value");
  218.             tableTextBoxes[4].Style.TextAlign = ExpressionInfo.FromString("Right");
  219.             tableTextBoxes[4].Style.VerticalAlign = ExpressionInfo.FromString("Middle");
  220.             GrapeCity.ActiveReports.PageReportModel.Border border4 = new GrapeCity.ActiveReports.PageReportModel.Border();
  221.             border4.Color = ExpressionInfo.FromString("DarkGray");
  222.             border4.Style = ExpressionInfo.FromString("Solid");
  223.             border4.Width = ExpressionInfo.FromString("1pt");
  224.             tableTextBoxes[4].Style.Border = border4;
  225.             tableCells[4].ReportItems.Add(tableTextBoxes[4]);

  226.             tableTextBoxes.SetValue(new TextBox(), 5);
  227.             tableTextBoxes[5].Name = "textBox1";
  228.             tableTextBoxes[5].Value = ExpressionInfo.FromString("=Fields!user_age.Value");
  229.             tableTextBoxes[5].Style.TextAlign = ExpressionInfo.FromString("Right");
  230.             tableTextBoxes[5].Style.VerticalAlign = ExpressionInfo.FromString("Middle");
  231.             GrapeCity.ActiveReports.PageReportModel.Border border5 = new GrapeCity.ActiveReports.PageReportModel.Border();
  232.             border5.Color = ExpressionInfo.FromString("DarkGray");
  233.             border5.Style = ExpressionInfo.FromString("Solid");
  234.             border5.Width = ExpressionInfo.FromString("1pt");
  235.             tableTextBoxes[5].Style.Border = border2;
  236.             tableCells[5].ReportItems.Add(tableTextBoxes[5]);


  237.             //将单元格添加到行中
  238.             tableRows[0].TableCells.Add(tableCells[0]);
  239.             tableRows[0].TableCells.Add(tableCells[1]);
  240.             tableRows[0].TableCells.Add(tableCells[2]);

  241.             tableRows[1].TableCells.Add(tableCells[3]);
  242.             tableRows[1].TableCells.Add(tableCells[4]);
  243.             tableRows[1].TableCells.Add(tableCells[5]);

  244.             //将行添加到table中
  245.             table.Header.TableRows.Add(tableRows[0]);
  246.             table.Details.TableRows.Add(tableRows[1]);

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


  252.         #region  创建数据源,数据集
  253.         /// <summary>
  254.         /// 创建数据源,数据集
  255.         /// </summary>
  256.         /// <param name="report"></param>
  257.         /// <returns></returns>
  258.         public static PageReport AddDataSetDataSource(PageReport report)
  259.         {
  260.             // create DataSource for the report
  261.             DataSource dataSource = new DataSource();
  262.             dataSource.Name = "DataSource1";
  263.             dataSource.ConnectionProperties.DataProvider = "DATASET";
  264.             dataSource.ConnectionProperties.ConnectString = ExpressionInfo.FromString("");
  265.             //Create DataSet with specified query and load database fields to the DataSet
  266.             GrapeCity.ActiveReports.PageReportModel.DataSet dataSet = new GrapeCity.ActiveReports.PageReportModel.DataSet();
  267.             Query query = new Query();
  268.             dataSet.Name = "DataSet1";
  269.             query.DataSourceName = "DataSource1";
  270.             dataSet.Query = query;

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

  272.             foreach (string fieldName in fieldsList)
  273.             {
  274.                 Field field = new Field(fieldName, fieldName, null);
  275.                 dataSet.Fields.Add(field);
  276.             }
  277.             //create report definition with specified DataSet and DataSource
  278.             report.Report.DataSources.Add(dataSource);
  279.             report.Report.DataSets.Add(dataSet);
  280.             return report;
  281.         }
  282.         #endregion


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

  293.             Stream stream = new MemoryStream();
  294.             stream.Read(data, 0, data.Length);
  295.             // 设置当前流的位置为流的开始
  296.             stream.Seek(0, SeekOrigin.Begin);
  297.             // 把 byte[] 写入文件
  298.             FileStream fs = new FileStream(fileName, FileMode.Create);
  299.             BinaryWriter bw = new BinaryWriter(fs);
  300.             bw.Write(data);
  301.             bw.Close();
  302.             bw.Dispose();
  303.             fs.Close();
  304.             fs.Dispose();
  305.             stream.Close();
  306.             stream.Dispose();
  307.         }
  308.         #endregion


  309.         #region 创建动态数据
  310.         /// <summary>
  311.         /// 创建动态数据
  312.         /// </summary>
  313.         /// <returns></returns>
  314.         public DataTable GetData()
  315.         {
  316.             DataTable dt = new DataTable("User");
  317.             dt.Columns.Add("user_name", typeof(string));
  318.             dt.Columns.Add("user_password", typeof(string));
  319.             dt.Columns.Add("user_age", typeof(int));


  320.             System.Data.DataRow dr = dt.NewRow();
  321.             dr[0] = "张三";
  322.             dr[1] = "123";
  323.             dr[2] = 20;
  324.             dt.Rows.Add(dr);

  325.             dr = dt.NewRow();
  326.             dr[0] = "李四";
  327.             dr[1] = "123";
  328.             dr[2] = 23;
  329.             dt.Rows.Add(dr);

  330.             return dt;
  331.         }
  332.         #endregion
  333.     }
  334. }
复制代码



附截图:


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x

3 个回复

倒序浏览
KearneyKang讲师达人认证 悬赏达人认证
超级版主   /  发表于:2020-4-7 09:51:38
沙发
你好,你使用的是V13还是V14。你自己新建一个JSviewer的demo可以正常运行不。建议自己先新建一个新的JSviewer的项目,看看,具体可以参考该博客,进行demo的验证:https://gcdn.grapecity.com.cn/fo ... &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
地板
好的,解决了就好
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部