?? crystalreport.cs
字號:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
namespace 教務管理系統(tǒng)
{
/// <summary>
/// CrystalReport 的摘要說明。
/// </summary>
public class CrystalReport : System.Windows.Forms.Form
{
public static string studentID;//用于保存報表打印窗體傳遞來的學號
private CrystalDecisions.Windows.Forms.CrystalReportViewer crystalReportViewer1;
/// <summary>
/// 必需的設計器變量。
/// </summary>
private System.ComponentModel.Container components = null;
public CrystalReport()
{
//
// Windows 窗體設計器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 調(diào)用后添加任何構(gòu)造函數(shù)代碼
//
}
/// <summary>
/// 清理所有正在使用的資源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗體設計器生成的代碼
/// <summary>
/// 設計器支持所需的方法 - 不要使用代碼編輯器修改
/// 此方法的內(nèi)容。
/// </summary>
private void InitializeComponent()
{
this.crystalReportViewer1 = new CrystalDecisions.Windows.Forms.CrystalReportViewer();
this.SuspendLayout();
//
// crystalReportViewer1
//
this.crystalReportViewer1.ActiveViewIndex = -1;
this.crystalReportViewer1.DisplayGroupTree = false;
this.crystalReportViewer1.Location = new System.Drawing.Point(0, 0);
this.crystalReportViewer1.Name = "crystalReportViewer1";
this.crystalReportViewer1.ReportSource = null;
this.crystalReportViewer1.Size = new System.Drawing.Size(664, 440);
this.crystalReportViewer1.TabIndex = 0;
//
// CrystalReport
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(664, 437);
this.Controls.Add(this.crystalReportViewer1);
this.Name = "CrystalReport";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "CrystalReport";
this.Load += new System.EventHandler(this.CrystalReport_Load);
this.ResumeLayout(false);
}
#endregion
//----------初始化窗體時,讀入報表數(shù)據(jù),并顯示之-----------
private void CrystalReport_Load(object sender, System.EventArgs e)
{
//讀入數(shù)據(jù)
CrystalReport1 rpt=new CrystalReport1();
string strConn="workstation id=localhost;Integrated Security=SSPI;Database=eisbook;";
SqlConnection cn=new SqlConnection(strConn);
cn.Open();
string sql="SELECT a.學號, c.姓名, b.課程名稱, b.開課系別, b.教師, a.成績"
+" FROM 成績表 a INNER JOIN 課程信息 b ON a.課程編號 = b.課程編號"
+" INNER JOIN 學生信息 c ON a.學號 = c.學號 WHERE (a.學號 = '"+studentID+"')";
SqlDataAdapter da=new SqlDataAdapter(sql,cn);
DataSet ds=new DataSet();
da.Fill(ds);
//連接報表數(shù)據(jù)源
rpt.SetDataSource(ds.Tables[0]);
crystalReportViewer1.ReportSource=rpt;
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -