简体   繁体   English

如何在不参考数据库的情况下在WPF MVVM应用程序中创建报表

[英]How do I create a report in a WPF MVVM application without refering to a database

I'm trying to create a report in my WPF application. 我正在尝试在我的WPF应用程序中创建一个报告。 I'm using Visual Studio 2010, C# and MVVM 我正在使用Visual Studio 2010,C#和MVVM

I have researched alot and only found articles on the net that deal with Crystal Report by using a database. 我已经研究了很多,并且只在网上找到了使用数据库处理Crystal Report的文章。 In my application, I don't communicate with the database directly. 在我的应用程序中,我不直接与数据库通信。 We use a web service. 我们使用网络服务。 It communicates with the database and writes all the data in xml files. 它与数据库通信并将所有数据写入xml文件。 We get our info via stored procedures. 我们通过存储过程获取信息。 Hopefully that is not a problem. 希望这不是问题。

Anyway, on one of my User Controls, I have a datagrid that is populated with data from the database. 无论如何,在我的一个用户控件上,我有一个数据网格,其中填充了数据库中的数据。 I store this data using a List and Observable Collection. 我使用List和Observable Collection存储这些数据。 So retreiving the data is easy. 因此,检索数据很容易。 But I would now like to export the data into a report for the user to print. 但我现在想将数据导出到报告中供用户打印。

As I said, I've read up on reports, and they all use some form of dataset or datatable. 正如我所说,我已阅读报告,他们都使用某种形式的数据集或数据表。 But as I've stated, we don't use the database directly. 但正如我所说,我们不直接使用数据库。

I have downloaded the SAP Crystal Reports, developer version for Microsoft Visual Studio: Updates & Runtime Downloads just to ensure I can use Crystal Reports. 我已经下载了SAP Crystal Studio,Microsoft Visual Studio的开发人员版本:更新和运行时下载 ,以确保我可以使用Crystal Reports。

I have an idea that I must create a new User Control or Window View and set the datacontext via ViewModel. 我有一个想法,我必须创建一个新的用户控件或窗口视图,并通过ViewModel设置datacontext。 On this form should be a Report Viewer control, that would be populated. 在此表单上应该是一个将填充的报表查看器控件。 But I don't know what to pass through, if I can do something like this. 但我不知道要通过什么,如果我可以做这样的事情。 Can I send over the List/ObservableCollection that has the data I want saved to the form, and bind it to the report control? 我可以将具有我想要保存的数据的List / ObservableCollection发送到表单,并将其绑定到报表控件吗? Using [this] as an example 2 , this is kind of the direction I'm looking for 使用[this]作为示例2 ,这是我正在寻找的方向

Or is there another way of creating a report without using a database? 或者是否有另一种不使用数据库创建报告的方法? I just generally want to create a report in my existing WPF project. 我通常只想在现有的WPF项目中创建一个报告。 A new window or user control is opened and the report viewer is loaded here, with the data I have in a gridview. 打开一个新窗口或用户控件,并在此处加载报表查看器,其中包含我在gridview中的数据。 Using WPF and MVVM, how do I achieve this. 使用WPF和MVVM,我该如何实现。

I also have Component One if anybody knows how to use this. 如果有人知道如何使用它,我也有组件一。 The website itself doesn't offer great tutorials on the subject of thier report views. 该网站本身并未提供有关其报告视图主题的精彩教程。

Please let me know if there is anything else you need from me, and I'll make edits where I can 如果您还需要我的其他信息,请告诉我,我会尽我所能进行编辑

Just started looking at this myself, firstly you can add a DataSource based on either your EF context or your web service. 刚开始看这个,首先你可以根据你的EF上下文或你的web服务添加一个DataSource。 You can then use the built in reporting toolset (which is based on the SQL Server Report Services (though you dont need this to host them)). 然后,您可以使用内置报告工具集(基于SQL Server报告服务(尽管您不需要它来托管它们))。

Though you'll need to use the Windows Forms host control :( MSDN walkthrough about hosting reports in WPF 虽然您需要使用Windows窗体主机控件:( 关于在WPF中托管报告的MSDN演练

I think you're on the right track by creating a user control that uses the data grid. 通过创建使用数据网格的用户控件,我认为您处于正确的轨道上。 I think the next thing you want to look into for printing some kind of reports is DocumentPaginator . 我认为接下来要打印某种报告的是DocumentPaginator Using this approach you can print to .XPS files, print the user control right to paper, or/and use a third-party XPS to PDF converter. 使用此方法,您可以打印到.XPS文件,将用户控件权限打印到纸张,或/和使用第三方XPS到PDF转换器。

Here is an example to get you started! 是一个让你入门的例子!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我有一个 wpf mvvm 应用程序,我应该把数据库或套接字放在哪里? - I have a wpf mvvm application, where do I put Database or Sockets? 如何创建可以在应用程序中的任何位置设置/获取的Application-scope变量? (WPF / MVVM) - How can I create Application-scope variable that can be set/get anywhere in the application? (WPF/MVVM) 如何处理WPF验证和MVVM? - How do I deal with WPF Validation and MVVM? 如何在显示窗口之前使WPF / MVVM应用程序进行后台处理? - How do I make a WPF/MVVM application do background processing before displaying a window? 如何使用C#-WPF-Entity-Framework Code First应用程序创建数据库备份? - How do I create database backups using C#-WPF-Entity-Framework Code First application? 如何在没有数据库的情况下将数据存储在WPF MVVM应用程序中? - How to stored data in WPF MVVM app without database? 使用WPF / MVVM,如何在关闭外部进程后立即将焦点恢复到应用程序? - Using WPF/MVVM, how do I immediately restore focus to my application after closing extnernal process? 如何在不对HTML进行硬编码的情况下创建HTML报告? - How do I create an html report without hardcoding the html? 如何处理 WPF 数据库应用程序中的调度程序问题? - How do I deal with dispatcher issue in WPF database application? 我可以在桌面应用程序中不使用水晶报表创建报表吗? - Can I create Report without using crystal report in Desktop Application?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM