使用水晶报表和实体框架创建自定义报表 4
我想允许 asp.net mvc 2 应用程序的用户动态创建报告。 SQLServer 数据库中有一个表,其中包含用户的所有任务。每个任务都取决于项目和用户。我想要做的是创建一些报告,例如“向我显示项目 X 的所有任务”或“向我显示我的所有任务”,以及“向我显示项目 Y 的状态为 X 的所有任务”。该列表应该可以导出为 PDF 或 CSV。如果可以在 ASP.NET MVC 视图中显示此列表,那就太好了。
我读了很多有关水晶报告的内容,似乎我想要的东西都可以用它实现。我找到了一些教程,解释了如何在报告中显示表格的所有列。但我不明白的是如何“即时”设置一些条件。
如果像下面的伪代码这样的东西能够实现我想要的效果,那就太好了:
// Load the tasks with Entity Framework by reference to some Condition
List<Task> tasks = GetTasks(userId);
// Load the reportfile
var report = GetChristalReport("Name of the .rpt report file");
// Set the loaded entities to the report
report.setData(tasks);
// Export it to pdf or do what you want with the rendered report
var pdf = report.ExportToPdf();
我希望你能帮助我,告诉我这是否可以用 chrystal reports 实现,以及我如何实现它。
I want to allow users of a asp.net mvc 2 application, creating dynamicly reports. In a SQLServer Database is a table with all tasks for a user. Every task depends on a project and a user. What I want to do is to create some reports like "show me all tasks for the project X" or "Show me all my tasks" but also something like "Show me all my tasks with the status X for project Y". This lists should be exportable as PDF or CSV. And it would be also nice if it is possible to show this lists in a asp.net mvc view.
I read a lot about crystal reports and it seems that what I want is possible with it. I found some tutorials which explain how to show all columns of a table in the report. But what I don't understand is how I can set some conditions "on the fly".
It would be very nice if something like the following pseudocode will do what I want:
// Load the tasks with Entity Framework by reference to some Condition
List<Task> tasks = GetTasks(userId);
// Load the reportfile
var report = GetChristalReport("Name of the .rpt report file");
// Set the loaded entities to the report
report.setData(tasks);
// Export it to pdf or do what you want with the rendered report
var pdf = report.ExportToPdf();
I hope you can help me and say if this is possible with chrystal reports and how I can implement this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你提到的一切在 CR 中不仅是可能的,而且相对容易做到。您需要做的大部分工作是创建一个 ReportDocument 对象,调用repDoc.Load("myReport.rpt");然后repDoc.ExportToDisk(fileFormat, fileName);你就完成了。如果你想在asp中以rpt文件的形式查看它,你需要创建一个ReportViewer对象,这有点困难,但ASP本身支持在浏览器中查看pdf。我希望这有帮助
Everything you mention is not only possible but relatively easy to do in CR. Most of what you need to do is to create a ReportDocument object, call repDoc.Load("myReport.rpt"); and then repDoc.ExportToDisk(fileFormat, fileName); and you're done. If you want to view it in the asp as an rpt file you need to create a ReportViewer object which is a little difficult but ASP natively supports viewing pdf in browser. I hope that helps