C#水晶报表数据获取方法实例浅析

C#水晶报表数据获取方法有很多,那么这里主要向你介绍一个通过提取模式的方法来实现C#水晶报表数据获取方法,那么具体的实现步骤是什么呢?让我们看看具体的实现代码:

C#水晶报表数据获取方法实例演示:

 
 
 
  1. using System;  
  2. using System.Drawing;  
  3. using System.Collections;  
  4. using System.ComponentModel;  
  5. using System.Windows.Forms;  
  6. using CrystalDecisions.CrystalReports.Engine;  
  7. using CrystalDecisions.Shared;  
  8. namespace DLLCrystal  
  9. {  
  10. /// ﹤summary﹥  
  11. /// frmCrystalView 的摘要说明。  
  12. /// ﹤/summary﹥  
  13. internal class frmCrystalView : System.Windows.Forms.Form  
  14. {  
  15. private CrystalDecisions.Windows.Forms.CrystalReportViewer crView;  
  16. /// ﹤summary﹥  
  17. /// 必需的设计器变量。  
  18. /// ﹤/summary﹥  
  19. private System.ComponentModel.Container components = null;  
  20. private string[] strInfo;  
  21.  
  22. public frmCrystalView(string[] strInfomation)  
  23. {  
  24. //  
  25. // C#水晶报表数据的获取方法之Windows 窗体设计器支持所必需的  
  26. //  
  27. InitializeComponent();  
  28.  
  29. //  
  30. // TODO: 在 InitializeComponent 调用后添加任何构造函数代码  
  31. //  
  32. strInfo=strInfomation;  
  33. }  
  34.  
  35. /// ﹤summary﹥  
  36. /// C#水晶报表数据获取方法之清理所有正在使用的资源。  
  37. /// ﹤/summary﹥  
  38. protected override void Dispose( bool disposing )  
  39. {  
  40. if( disposing )  
  41. {  
  42. if(components != null)  
  43. {  
  44. components.Dispose();  
  45. }  
  46. }  
  47. base.Dispose( disposing );  
  48. }  
  49.  
  50. #region Windows 窗体设计器生成的代码  
  51. /// ﹤summary﹥  
  52. /// C#水晶报表数据获取方法之设计器支持所需的方法 - 不要使用代码编辑器修改  
  53. /// 此方法的内容。  
  54. /// ﹤/summary﹥  
  55. private void InitializeComponent()  
  56. {  
  57. this.crView = new CrystalDecisions.Windows.Forms.CrystalReportViewer();  
  58. this.SuspendLayout();  
  59. //   
  60. // crView  
  61. //   
  62. this.crView.ActiveViewIndex = -1;  
  63. this.crView.Dock = System.Windows.Forms.DockStyle.Fill;  
  64. this.crView.Location = new System.Drawing.Point(0, 0);  
  65. this.crView.Name = "crView";  
  66. this.crView.ReportSource = null;  
  67. this.crView.ShowRefreshButton = false;  
  68. this.crView.Size = new System.Drawing.Size(640, 509);  
  69. this.crView.TabIndex = 0;  
  70. //   
  71. // frmCrystalView  
  72. //   
  73. this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);  
  74. this.ClientSize = new System.Drawing.Size(640, 509);  
  75. this.Controls.Add(this.crView);  
  76. this.Name = "frmCrystalView";  
  77. this.Text = "预览报表";  
  78. this.Load += new System.EventHandler(this.frmCrystalView_Load);  
  79. this.ResumeLayout(false);  
  80.  
  81. }  
  82. #endregion  
  83.  
  84. private void frmCrystalView_Load(object sender, System.EventArgs e)  
  85. {  
  86. ReportDocument rdView=new ReportDocument();  
  87. rdView.Load(@strInfo[0]);  
  88. foreach (Table tbView in rdView.Database.Tables)  
  89. {   
  90. TableLogOnInfo tliView=new TableLogOnInfo();  
  91. tliView=tbView.LogOnInfo;  
  92. tliView.ConnectionInfo.ServerName=strInfo[1];  
  93. tliView.ConnectionInfo.DatabaseName=strInfo[2];  
  94. tliView.ConnectionInfo.UserID=strInfo[3];  
  95. tliView.ConnectionInfo.Password=strInfo[4];  
  96. tbView.ApplyLogOnInfo(tliView);  
  97. }  
  98.  
  99. string [] strParameter=strInfo[5].Split(new char[] {+});  
  100. for (int i=0;i﹤strParameter.Length;i++)  
  101. {  
  102. string [] strSubParam=strParameter[i].Split(new char[] {=});  
  103. ParameterValues pvValue=new ParameterValues();  
  104. ParameterDiscreteValue pdvValue=new ParameterDiscreteValue();  
  105. pdvValue.Value=strSubParam[1];  
  106. pvValue.Add(pdvValue);  
  107. rdView.DataDefinition.  
  108. ParameterFields[strSubParam[0]].ApplyCurrentValues(pvValue);  
  109. }  
  110. crView.ReportSource=rdView;  
  111. this.Location = new Point(0, 0);  
  112. this.Size = new System.Drawing.Size(1024,744);  
  113. }  
  114. }//C#水晶报表数据获取方法  
  115. }  

C#水晶报表数据获取方法的具体事宜就向你介绍到这里,希望那个对你了解和学习C#水晶报表数据获取方法有所帮助。

【编辑推荐】

  1. C#创建一个文件的具体实现浅析
  2. C#打开一个文件的操作详解
  3. C#实现string和byte数组的转换
  4. C# Byte数组转换String详解
  5. 详解C#调用水晶报表的实现
THE END