<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Viewer="clr-namespace:SAPBusinessObjects.WPF.Viewer;assembly=SAPBusinessObjects.WPF.Viewer" x:Class="TestCrystalReport.MainWindow"
Title="MainWindow" Height="350" Width="525">
<Grid> <Viewer:CrystalReportsViewer x:Name="crystalReportsViewer" Margin="10"/> </Grid>
</Window> using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Data; using CrystalDecisions.CrystalReports.Engine; namespace TestCrystalReport
{ //Crystal Report for Visaul Studio SDK download from http://downloads.businessobjects.com/akdlm/cr4vs2010/CRforVS_13_0_5.exe
//Runtime: CRRuntime_32bit_13_0_5
//http://downloads.businessobjects.com/akdlm/crnetruntime/clickonce/CRRuntime_64bit_13_0_5.msi
//http://downloads.businessobjects.com/akdlm/crnetruntime/clickonce/CRRuntime_32bit_13_0_5.msi
//when vs2010 build setup, this 2 runtime msi file need exists at C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bootstrapper\Packages\Crystal Reports for .NET Framework 4.0
//****importent if the app build with x86 then just need CRRuntime_32bit_13_0_5.msi*******
//and for vs2010 build setup can copy CRRuntime_32bit_13_0_5.msi and rename to CRRuntime_64bit_13_0_5.msi
//****************************************************************************************************************************************************
//can use vs2010 to build the setup package, va2012 just has InstallShield2015LimitedEdition and no microsoft setup.
//build setup with InstallShield refer:https://blog.csdn.net/caiandyong/article/details/50586648
//build setup use vs2010 refer article : https://blog.csdn.net/zhang_yling/article/details/88982585
//note : for this App.config need add below section if app use .NETFramework 4.5:
// <startup useLegacyV2RuntimeActivationPolicy="true">
// <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
// </startup> /// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
Loaded += MainWindow_Loaded;
} string rptDBFile = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Reports\\mm8report.mdb"); void MainWindow_Loaded(object sender, RoutedEventArgs e)
{ string rptTempFile = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Reports\\mm8heatsheet3col.rpt");
showReport(rptTempFile); //crystalReportsViewer.
// CrystalReport
//CrystalDecisions.CrystalReports.ViewerObjectModel. // MyCrystalReport1 rpt = new MyCrystalReport1();
// rpt.SetDataSource(new PersonDAL().ListAll());
// crystalReportsViewer1.ViewerCore.ReportSource = rpt; // CrystalDecisions.CrystalReports.Engine.Database // MessageBox.Show(""+doc.HasSavedData);
/*-------------test set datasource-----------------------------------------------------------------------
DataTable tb=new DataTable() ;
tb.Columns.Add(new DataColumn ("id",DbType.Int32.GetType()));
tb.Columns.Add(new DataColumn("name",DbType.String.GetType() ));
DataRow r = tb.NewRow();
r[0] = 1;
r[0] = "1333333333";
tb.Rows.Add(r);
tb.BeginLoadData();
doc.SetDataSource(tb);
----------------------------------------------------------------------------------------------------------- */ /*-----------------------------test----------------------------------------------------------------------------
for (int i = 0; i < doc.Database.Tables.Count; i++)
{
//doc.Database.Tables[i].Location = aliasName;
//MessageBox.Show(doc.Database.Tables[i].Location);
//doc.Database.Tables[i].SetDataSource(tb);
}
--------------------------------------------------------------------------------------------------------------*/
// MessageBox.Show(doc.DataSourceConnections[0].DatabaseName); /*tes
using (AdventureWorksEntities db = new AdventureWorksEntities())
{
report.SetDataSource(from c in db.Contacts
select new
{
c.FirstName,
c.LastName,
c.EmailAddress,
c.Phone
});
} crystalReportsViewer1.ViewerCore.ReportSource = report;
*
*
' print dailog
PrintPreview pp = new PrintPreview();
pp.ShowDialog(); */ } void showReport(string rptTempFile) {
try
{
ReportDocument doc = new ReportDocument();
doc.Load(rptTempFile);
doc.DataSourceConnections[0].SetConnection(rptDBFile, "", "", "");
crystalReportsViewer.ViewerCore.ReportSource = doc;
crystalReportsViewer.ShowToggleSidePanelButton = false; }
catch(Exception ex) { MessageBox.Show( ex.Message ); } } }
}

  

以上是调用水晶报表的例子

下面是关于打包的问题,在身边注释里有写。

重要的一点是就是下载2个水晶报表的运行时 Runtime: CRRuntime_32bit_13_0_5,这个运行时如同.net framework的性质。

下载地址:http://downloads.businessobjects.com/akdlm/crnetruntime/clickonce/CRRuntime_64bit_13_0_5.msi

http://downloads.businessobjects.com/akdlm/crnetruntime/clickonce/CRRuntime_32bit_13_0_5.msi

版本号要和水晶报表开发包SDK的一致(Crystal Report for Visaul Studio SDK download from http://downloads.businessobjects.com/akdlm/cr4vs2010/CRforVS_13_0_5.exe);

参考: https://blog.csdn.net/zhang_yling/article/details/88982585

VS2017 VS2019 SETUP 参考:https://www.cnblogs.com/lxhbky/p/10695527.html

最新文章

  1. python--基础学习(二)判断 、循环、定义函数、继承、调用
  2. Ajax最详细的参数解析和场景应用
  3. ASP.NET文件上传大小的限制解决方案
  4. zoj3551 Bloodsucker ——概率DP
  5. 用LinqPad查看Nhibernate生成的sql语句
  6. Ubuntu安装Tcpdump
  7. Cisco ASA 5505 Routing Between Two (Internal) VLANS
  8. hdu3829(最大独立集)
  9. Windows命令行命令集锦
  10. iOS 计算两个坐标之间的距离
  11. 数据的增删改查(三层)&lt;!--待补充--&gt;
  12. [物理学与PDEs]第2章第1节 理想流体力学方程组 1.1 预备知识
  13. C# CRC - 16
  14. java杨辉三角和空心菱形(二维数组篇)
  15. swift - 根试图控制器的手势返回冲突 - push 新的tabbar控制器手势冲突
  16. Python os.popen() 方法
  17. 基于PHP采集数据入库程序(一)
  18. PHP老师没教过你的那些知识点
  19. mybatis使用foreach进行批量插入和删除操作
  20. SSH框架学习步骤

热门文章

  1. PHP之常用第三方库
  2. mpvue开发微信小程序之picker
  3. js方法的封装
  4. ip - Linux IPv4 协议实现
  5. 【转】Linux内核中分配4M以上大内存的方法
  6. Linux日常之命令sed
  7. (转) Delete/Truncate删除,释放表空间、降低高水位线、resize释放磁盘空间相关优化
  8. Spring Boot 整合监听器
  9. Spring的新注解
  10. 第二篇:请求库之requests,selenium