⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.cs

📁 简单CRYSTAL REPORT程序,自己也是刚刚下来看有很多不明白的地方,仅供参考,一起学习
💻 CS
字号:
//********************************************
//Created:       May 17, 2002
//Author ID:     HAN
//Purpose:       This C# .NET sample Windows application demonstrates  
//               accessing subreports in a main report at runtime.
//'*********************************************


using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace csharp_win_subreport_basic
{
	/// <summary>
	/// Summary description for Form1
	/// </summary>
	public class Form1 : System.Windows.Forms.Form
	{

		//CR Variables
		MainReport crReportDocument;
		Sections crSections;
		ReportObjects crReportObjects;
		SubreportObject crSubreportObject;
		ReportDocument crSubreportDocument;
		string SubNames;

		private CrystalDecisions.Windows.Forms.CrystalReportViewer crystalReportViewer1;
		/// <summary>
		/// Required designer variable
		/// </summary>
		private System.ComponentModel.Container components = null;

		public Form1()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			

			//Create an instance of the strongly-typed MAIN report object
			crReportDocument = new MainReport();

			//Get all the sections in the report
			crSections = crReportDocument.ReportDefinition.Sections;

			//Loop through each section of the report
			SubNames = "";
			foreach(Section crSection in crSections)
			{

				//Get all the report objects from each section
				crReportObjects = crSection.ReportObjects;

				//Loop through each report object
				foreach(ReportObject crReportObject in crReportObjects)
				{

					//Check to see if the report object is a subreport
					if (crReportObject.Kind == ReportObjectKind.SubreportObject)
					{
						//Found the subreport  
						//Get the actual subreport object
						crSubreportObject = (SubreportObject)crReportObject;

						//Get the subreport as a regular report object  
						//OpenSubreport returns the subreport object as a report
						crSubreportDocument = crSubreportObject.OpenSubreport(crSubreportObject.SubreportName);

						//Display the name of the subreport
						if (SubNames.Length > 0) SubNames += ", ";
						SubNames = crSubreportDocument.Name;
					}//Go to the next report object
				}
			}//Go to the next section

			MessageBox.Show("Subreport Names: " + SubNames);
			//Set the viewer to the report object to be previewed
			crystalReportViewer1.ReportSource = crReportDocument;

		}

		/// <summary>
		/// Clean up any resources being used
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.crystalReportViewer1 = new CrystalDecisions.Windows.Forms.CrystalReportViewer();
			this.SuspendLayout();
			// 
			// crystalReportViewer1
			// 
			this.crystalReportViewer1.ActiveViewIndex = -1;
			this.crystalReportViewer1.Dock = System.Windows.Forms.DockStyle.Fill;
			this.crystalReportViewer1.Name = "crystalReportViewer1";
			this.crystalReportViewer1.ReportSource = null;
			this.crystalReportViewer1.Size = new System.Drawing.Size(792, 573);
			this.crystalReportViewer1.TabIndex = 0;
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(792, 573);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.crystalReportViewer1});
			this.Name = "Form1";
			this.Text = "Form1";
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// The main entry point for the application
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new Form1());
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -