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

📄 form1.cs

📁 是用c#实现的一个有关于报表设计的程序代码
💻 CS
字号:
#region License
/*
This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General
Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option)
any later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
details.

You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to
the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 
*/
#endregion

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing.Printing;
using System.Windows.Forms;


namespace ReportTest
{
	/// <summary>
	/// Summary description for Form1.
	/// </summary>
	public class Form1 : System.Windows.Forms.Form
	{
		#region Declarations

		private System.Windows.Forms.PrintPreviewDialog printPreviewDialog1;
		private System.Windows.Forms.Button btnStaticReport;
		private System.Windows.Forms.Button btnDynamicReport;
		private System.Windows.Forms.Button btnChartReport;
		private System.Windows.Forms.Button btnFormatMask;
		private System.Windows.Forms.Button btnGrouping;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;
		#endregion

		#region Form and Object Event Handlers

		private void btnStaticReport_Click(object sender, System.EventArgs e)
		{
			daReport.DaPrintDocument daPrintDocument = new daReport.DaPrintDocument();

			// set .xml file for printing
			daPrintDocument.setXML("reportStatic.xml");

			// fill in with some parameters
			// (parameter names are case sensitive)
			Hashtable parameters = new Hashtable();
			parameters.Add("author","Predrag Dukanac");
			daPrintDocument.SetParameters(parameters);

			// print preview
			printPreviewDialog1.Document = daPrintDocument;
			printPreviewDialog1.PrintPreviewControl.Zoom = 1.0;
			printPreviewDialog1.WindowState = FormWindowState.Maximized;
			printPreviewDialog1.ShowDialog(this);
		}


		private void btnDynamicReport_Click(object sender, System.EventArgs e)
		{
			daReport.DaPrintDocument daPrintDocument = new daReport.DaPrintDocument();

			// generate some dummy data
			DataTable theData = new DataTable("printTable");

			theData.Columns.Add( new DataColumn("number"));
			theData.Columns.Add( new DataColumn("square"));
			theData.Columns.Add( new DataColumn("cube"));

			for (int i = 0; i<=100;i++)
			{
				theData.Rows.Add(new object[]{i,i*i,i*i*i});
			}

			// add this table to print document
			daPrintDocument.AddData(theData);

			// set .xml file for printing
			daPrintDocument.setXML("reportDynamic.xml");

			// print preview
			printPreviewDialog1.Document = daPrintDocument;
			printPreviewDialog1.PrintPreviewControl.Zoom = 1.0;
			printPreviewDialog1.WindowState = FormWindowState.Maximized;
			printPreviewDialog1.ShowDialog(this);
		}


		private void btnChartReport_Click(object sender, System.EventArgs e)
		{
			daReport.DaPrintDocument daPrintDocument = new daReport.DaPrintDocument();

			// set .xml file for printing
			daPrintDocument.setXML("reportCharts.xml");

			// add X categories to the chart0 
			daPrintDocument.SetChartCategories("chart0",new string[] {"New York","Shangai","Mexico City"});
	
			// add some dummy data to the chart0
			daPrintDocument.AddChartSerie("chart0","Year 1975.",new double[3]{15.9,11.4,11.2},Color.DarkGreen);
			daPrintDocument.AddChartSerie("chart0","Year 2000.",new double[3]{16.6,12.9,18.1},Color.LimeGreen);
			daPrintDocument.AddChartSerie("chart0","Year 2015.",new double[3]{17.4,14.6,19.2},Color.ForestGreen);


			// add X categories to the chart1 
			daPrintDocument.SetChartCategories("chart1",new string[] {"New York","Shangai","Mexico City"});
	
			// add some dummy data to the chart1			
			daPrintDocument.AddChartSerie("chart1","Serie 1",new double[3]{16.6,12.9,18.1},Color.Firebrick);



			// add X categories to the chart2 
			daPrintDocument.SetChartCategories("chart2",new string[] {"a","b","c"});
	
			// add some dummy data to the chart2
			daPrintDocument.AddChartSerie("chart2","Serie 1",new double[3]{57,22,12},Color.LightSalmon);
			daPrintDocument.AddChartSerie("chart2","Serie 2",new double[3]{8,91,67},Color.DarkMagenta);

			
			// add X categories to the chart3 
			daPrintDocument.SetChartCategories("chart3",new string[] {"Category A","Category B","Category C","Category D","Category E"});
	
			// add some dummy data to the chart3			
			daPrintDocument.AddChartSerie("chart3","Serie 1",new double[]{16.6,12.9,18.1,7,11},Color.Indigo);


			// print preview
			printPreviewDialog1.Document = daPrintDocument;
			printPreviewDialog1.PrintPreviewControl.Zoom = 1.0;
			printPreviewDialog1.WindowState = FormWindowState.Maximized;
			printPreviewDialog1.ShowDialog(this);
		}


		private void btnGrouping_Click(object sender, System.EventArgs e)
		{
			daReport.DaPrintDocument daPrintDocument = new daReport.DaPrintDocument();

			DataTable temp = new DataTable("GroupingTest");
			temp.Columns.Add(new DataColumn("SalesPerson", System.Type.GetType("System.String")));
			temp.Columns.Add(new DataColumn("ClientName", System.Type.GetType("System.String")));
			temp.Columns.Add(new DataColumn("Sales", System.Type.GetType("System.Decimal")));

			temp.Rows.Add(new object[] {"Salesperson 1", "Client 1", 25.4D});
			temp.Rows.Add(new object[] {"Salesperson 1", "Client 2", 45.4D});
			temp.Rows.Add(new object[] {"Salesperson 1", "Client 3", 22.4D});
			temp.Rows.Add(new object[] {"Salesperson 1", "Client 4", 15.4D});
			temp.Rows.Add(new object[] {"Salesperson 1", "Client 5", 25.4D});
			temp.Rows.Add(new object[] {"Salesperson 1", "Client 6 Client 6 Client 6 Client 6 Client 6 Client 6 Client 6 Client 6 Client 6 Client 6 Client 6 Client 6 Client 6 Client 6 Client 6 Client 6 Client 6 Client 6 Client 6 Client 6 Client 6 Client 6 ", 25.4D});
			temp.Rows.Add(new object[] {"Salesperson 1", "Client 7", 25.4D});
			temp.Rows.Add(new object[] {"Salesperson 1", "Client 8", 25.4D});
			temp.Rows.Add(new object[] {"Salesperson 1", "Client 9", 25.4D});
			temp.Rows.Add(new object[] {"Salesperson 1", "Client 10", 25.4D});
			temp.Rows.Add(new object[] {"Salesperson 1", "Client 11", 25.4D});
			temp.Rows.Add(new object[] {"Salesperson 2", "Client 1", 25.4D});
			temp.Rows.Add(new object[] {"Salesperson 5", "Client 1 Client 1 Client 1 Client 1 Client 1 Client 1 Client 1 Client 1 Client 1 Client 1 Client 1 Client 1 Client 1 Client 1 Client 1 Client 1 Client 1 Client 1 Client 1 Client 1 Client 1 Client 1 Client 1 Client 1 Client 1 Client 1 Client 1 ", 25.4D});
			temp.Rows.Add(new object[] {"Salesperson 5", "Client 2", 25.4D});
			temp.Rows.Add(new object[] {"Salesperson 1", "Client 12", 25.4D});
			temp.Rows.Add(new object[] {"Salesperson 4", "Client 1", 25.4D});
			temp.Rows.Add(new object[] {"Salesperson 1", "Client 13", 25.4D});
			temp.Rows.Add(new object[] {"Salesperson 5", "Client 3", 25.4D});
			temp.Rows.Add(new object[] {"Salesperson 1", "Client 14", 25.4D});
			temp.Rows.Add(new object[] {"Salesperson 4", "Client 2", 25.4D});
			temp.Rows.Add(new object[] {"Salesperson 1", "Client 15", 25.4D});
			temp.Rows.Add(new object[] {"Salesperson 4", "Client 3", 25.4D});
			temp.Rows.Add(new object[] {"Salesperson 1", "Client 16", 25.4D});
			temp.Rows.Add(new object[] {"Salesperson 4", "Client 4", 25.4D});
			temp.Rows.Add(new object[] {"Salesperson 1", "Client 17", 25.4D});
			temp.Rows.Add(new object[] {"Salesperson 4", "Client 5", 25.4D});
			temp.Rows.Add(new object[] {"Salesperson 1", "Client 18", 25.4D});
			temp.Rows.Add(new object[] {"Salesperson 4", "Client 6", 25.4D});
			temp.Rows.Add(new object[] {"Salesperson 1", "Client 19", 25.4D});

			// add this table to print document
			daPrintDocument.AddData(temp); //, "SalesPerson");

			// set .xml file for printing
			daPrintDocument.setXML("GroupingTest.xml");

			// print preview
			printPreviewDialog1.Document = daPrintDocument;
			printPreviewDialog1.PrintPreviewControl.Zoom = 1.0;
			printPreviewDialog1.WindowState = FormWindowState.Maximized;
			printPreviewDialog1.ShowDialog(this);
		}
		

		private void btnFormatMask_Click(object sender, System.EventArgs e)
		{
			daReport.DaPrintDocument daPrintDocument = new daReport.DaPrintDocument();

			DataTable temp = new DataTable("FormattingTable");
			temp.Columns.Add(new DataColumn("Amount", System.Type.GetType("System.Decimal")));
			temp.Columns.Add(new DataColumn("PurchaseDate", System.Type.GetType("System.DateTime")));

			for (int i=0;i<60; i++)
			{
				DataRow Row1 = temp.NewRow();
				Row1["Amount"] = 24.50;
				Row1["PurchaseDate"] = System.DateTime.Now.AddDays(i);
				temp.Rows.Add(Row1);
			}

			/*
			DataRow Row1 = temp.NewRow();
			Row1["Amount"] = 24.50;
			Row1["PurchaseDate"] = System.DateTime.Now.AddDays(2);
			temp.Rows.Add(Row1);
			DataRow Row2 = temp.NewRow();
			Row2["Amount"] = 1980.65;
			Row2["PurchaseDate"] = System.DateTime.Now.AddDays(-10);
			temp.Rows.Add(Row2);
			DataRow Row3 = temp.NewRow();
			Row3["Amount"] = 0.50;
			Row3["PurchaseDate"] = System.DateTime.Now.AddDays(40);
			temp.Rows.Add(Row3);
			*/

			// add this table to print document
			daPrintDocument.AddData(temp);

			// set .xml file for printing
			daPrintDocument.setXML("FormatMask.xml");

			// print preview
			printPreviewDialog1.Document = daPrintDocument;
			printPreviewDialog1.PrintPreviewControl.Zoom = 1.0;
			printPreviewDialog1.WindowState = FormWindowState.Maximized;
			printPreviewDialog1.ShowDialog(this);
		}
		
		
		#endregion

		#region Creator

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

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
			printPreviewDialog1 = new PrintPreviewDialog();

		}

		/// <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()
		{
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
			this.btnStaticReport = new System.Windows.Forms.Button();
			this.printPreviewDialog1 = new System.Windows.Forms.PrintPreviewDialog();
			this.btnDynamicReport = new System.Windows.Forms.Button();
			this.btnChartReport = new System.Windows.Forms.Button();
			this.btnFormatMask = new System.Windows.Forms.Button();
			this.btnGrouping = new System.Windows.Forms.Button();
			this.SuspendLayout();
			// 
			// btnStaticReport
			// 
			this.btnStaticReport.Location = new System.Drawing.Point(24, 16);
			this.btnStaticReport.Name = "btnStaticReport";
			this.btnStaticReport.Size = new System.Drawing.Size(104, 23);
			this.btnStaticReport.TabIndex = 1;
			this.btnStaticReport.Text = "Static report";
			this.btnStaticReport.Click += new System.EventHandler(this.btnStaticReport_Click);
			// 
			// printPreviewDialog1
			// 
			this.printPreviewDialog1.AutoScrollMargin = new System.Drawing.Size(0, 0);
			this.printPreviewDialog1.AutoScrollMinSize = new System.Drawing.Size(0, 0);
			this.printPreviewDialog1.ClientSize = new System.Drawing.Size(400, 300);
			this.printPreviewDialog1.Enabled = true;
			this.printPreviewDialog1.Icon = ((System.Drawing.Icon)(resources.GetObject("printPreviewDialog1.Icon")));
			this.printPreviewDialog1.Location = new System.Drawing.Point(132, 132);
			this.printPreviewDialog1.MinimumSize = new System.Drawing.Size(375, 250);
			this.printPreviewDialog1.Name = "printPreviewDialog1";
			this.printPreviewDialog1.TransparencyKey = System.Drawing.Color.Empty;
			this.printPreviewDialog1.Visible = false;
			// 
			// btnDynamicReport
			// 
			this.btnDynamicReport.Location = new System.Drawing.Point(24, 48);
			this.btnDynamicReport.Name = "btnDynamicReport";
			this.btnDynamicReport.Size = new System.Drawing.Size(104, 23);
			this.btnDynamicReport.TabIndex = 2;
			this.btnDynamicReport.Text = "Dynamic report";
			this.btnDynamicReport.Click += new System.EventHandler(this.btnDynamicReport_Click);
			// 
			// btnChartReport
			// 
			this.btnChartReport.Location = new System.Drawing.Point(24, 80);
			this.btnChartReport.Name = "btnChartReport";
			this.btnChartReport.Size = new System.Drawing.Size(104, 23);
			this.btnChartReport.TabIndex = 3;
			this.btnChartReport.Text = "Chart report";
			this.btnChartReport.Click += new System.EventHandler(this.btnChartReport_Click);
			// 
			// btnFormatMask
			// 
			this.btnFormatMask.Location = new System.Drawing.Point(144, 16);
			this.btnFormatMask.Name = "btnFormatMask";
			this.btnFormatMask.Size = new System.Drawing.Size(104, 23);
			this.btnFormatMask.TabIndex = 4;
			this.btnFormatMask.Text = "Formatting Test";
			this.btnFormatMask.Click += new System.EventHandler(this.btnFormatMask_Click);
			// 
			// btnGrouping
			// 
			this.btnGrouping.Location = new System.Drawing.Point(144, 48);
			this.btnGrouping.Name = "btnGrouping";
			this.btnGrouping.Size = new System.Drawing.Size(104, 23);
			this.btnGrouping.TabIndex = 0;
			this.btnGrouping.Text = "Grouping Test";
			this.btnGrouping.Click += new System.EventHandler(this.btnGrouping_Click);
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(440, 133);
			this.Controls.Add(this.btnGrouping);
			this.Controls.Add(this.btnFormatMask);
			this.Controls.Add(this.btnChartReport);
			this.Controls.Add(this.btnDynamicReport);
			this.Controls.Add(this.btnStaticReport);
			this.Name = "Form1";
			this.Text = "daReport Test Application";
			this.ResumeLayout(false);

		}
		#endregion

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


		#endregion
	}
}

⌨️ 快捷键说明

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