LightSwitch 没有内置报告功能,但是,可以使用 SQL Server reporting services 来创建报表和查看其从 LightSwitch 应用程序。报表将出现在可以将多个文件格式打印和导出它们的浏览器窗口。
可以创建,部署和管理您的组织的报表使用 SQL Server reporting services,使用各种编程的功能,因此,您可以扩展和自定义您的报告功能。即使您没有 SQL Server 的完整版本,您仍可以创建报表通过 在 SQL Server 的 reporting services express 用于高级服务使用,可以免费下载。
查看报表
在 解决方案资源管理器,从工具栏上的列表中选择 文件视图。
打开 客户端 项目节点的快捷菜单,然后选择 添加引用。
在 添加引用 对话框中,展开 程序集 节点,选择 框架 节点,选择 System.Windows.Browser 复选框,然后选择 确定 按钮。
在 解决方案资源管理器,从工具栏上的列表中选择 逻辑视图。
打开您的屏幕的快捷菜单,然后选择 打开。
在屏幕设计器中,展开 屏幕命令栏 节点,选择 添加 节点,然后选择 新建按钮。
在 添加按钮 对话框中,选择 新建方法 选项按钮,将您创建的按钮,然后选择 确定 按钮。
在屏幕设计器,请打开新按钮的快捷菜单,然后选择 编辑 Execute 代码。
在 代码编辑器,添加以下 导入 或 使用 语句:
Imports Microsoft.LightSwitch.Threading Imports System.Runtime.InteropServices.Automation
using Microsoft.LightSwitch.Threading; using System.Runtime.InteropServices.Automation;
添加下面的代码将打开该报表,替换 Uri 用自己的报表的 URL 和替换 ViewReport 用您的按钮的名称:
Private Sub ViewReport_Execute() Dispatchers.Main.BeginInvoke( Sub() ' Provide the URL for the report that you want to view Dim uri As New Uri("https://www.contoso.com/ReportServer/Pages/ReportViewer.aspx?%2fReportName&rs:Command=Render") If (AutomationFactory.IsAvailable) Then ' This is a desktop app, so shell to the default browser Dim shell = AutomationFactory.CreateObject("Shell.Application") shell.ShellExecute(uri.ToString) ElseIf (Not System.Windows.Application.Current.IsRunningOutOfBrowser) Then ' This is a web app, so navigate to the page System.Windows.Browser.HtmlPage.Window.Navigate(uri, "_blank") End If End Sub) End Sub
private void ViewReport_Execute() { Dispatchers.Main.BeginInvoke(() => { // Provide the URL for the report that you want to view Uri uri = new Uri("https://www.contoso.com/ReportServer/Pages/ReportViewer.aspx?%2fReportName&rs:Command=Render"); if ((AutomationFactory.IsAvailable)) { // This is a desktop app, so shell to the default browser dynamic shell = AutomationFactory.CreateObject("Shell.Application"); shell.ShellExecute(uri.ToString()); } else if ((!System.Windows.Application.Current.IsRunningOutOfBrowser)) { // This is a web app, so navigate to the page System.Windows.Browser.HtmlPage.Window.Navigate(uri, "_blank"); } }); }
该报表将出现在新的浏览器窗口。
提示
您可以构造由报表参数,密码,呈现格式的报表和更多的 URL。有关更多信息,请参见 URL 访问。