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

📄 frmcustomersreport.cs

📁 Winform_OnlineTraning 我们培训机构的在线培训部分
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;

namespace Example_2
{
	/// <summary>
	/// Summary description for Form1.
	/// </summary>
	public class frmCustomersReport : System.Windows.Forms.Form
	{
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		private CustomersCrystalReport objCustomersCrystalReport;
		private SqlConnection objSqlConnection;
		private SqlDataAdapter objSqlDataAdapter;
		private CrystalDecisions.Windows.Forms.CrystalReportViewer crvCustomersReport;
		private System.Windows.Forms.Button btnExit;
		private DataSet objDataSet;

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

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

		/// <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.crvCustomersReport = new CrystalDecisions.Windows.Forms.CrystalReportViewer();
			this.btnExit = new System.Windows.Forms.Button();
			this.SuspendLayout();
			// 
			// crvCustomersReport
			// 
			this.crvCustomersReport.ActiveViewIndex = -1;
			this.crvCustomersReport.DisplayToolbar = false;
			this.crvCustomersReport.Location = new System.Drawing.Point(0, 0);
			this.crvCustomersReport.Name = "crvCustomersReport";
			this.crvCustomersReport.ReportSource = null;
			this.crvCustomersReport.Size = new System.Drawing.Size(950, 508);
			this.crvCustomersReport.TabIndex = 0;
			// 
			// btnExit
			// 
			this.btnExit.Location = new System.Drawing.Point(864, 517);
			this.btnExit.Name = "btnExit";
			this.btnExit.Size = new System.Drawing.Size(90, 25);
			this.btnExit.TabIndex = 1;
			this.btnExit.Text = "E&xit";
			this.btnExit.Click += new System.EventHandler(this.btnExit_Click);
			// 
			// frmCustomersReport
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(960, 548);
			this.Controls.Add(this.btnExit);
			this.Controls.Add(this.crvCustomersReport);
			this.Name = "frmCustomersReport";
			this.Text = "按国家销售额";
			this.Load += new System.EventHandler(this.Form1_Load);
			this.ResumeLayout(false);

		}
		#endregion

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

		private void Form1_Load(object sender, System.EventArgs e)
		{
			//Creating an object of the report
			objCustomersCrystalReport = new CustomersCrystalReport();

			// Connection information 
			objSqlConnection = new SqlConnection("Server = sam ; database = Inventory; uid = sa; password=;");
			objSqlDataAdapter = new SqlDataAdapter ("SELECT * FROM Customers", objSqlConnection);

			objDataSet = new DataSet ();

			// Connect to, fetch data and disconnect from database 
			objSqlDataAdapter.Fill (objDataSet, "Customers");

			objCustomersCrystalReport.SetDataSource(objDataSet);
			// bind report object with data to the Windows Forms Viewer 
			crvCustomersReport.ReportSource =    objCustomersCrystalReport;
		}

		private void btnExit_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}
	}
}

⌨️ 快捷键说明

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