xtrareport 的使用方法.docx
《xtrareport 的使用方法.docx》由会员分享,可在线阅读,更多相关《xtrareport 的使用方法.docx(23页珍藏版)》请在冰豆网上搜索。
xtrareport的使用方法
Xtrareport
1,此报表在设置时,paperkind中找不到自定义的纸张,所以我就在事件beforeprint中,this.Margins=newSystem.Drawing.Printing.Margins(10,10,10,10);this.PaperKind=System.Drawing.Printing.PaperKind.Custom;this.PageWidth=827;this.PageHeight=584;this.PaperName="21*13"
2.加载已有模板
xrpt1.LoadLayout(@"E:
\EMS.repx");
DeveloperExpress之XtraReport报表预览控件PrintControl设置
using System;
02
using System.Collections.Generic;
03
using System.ComponentModel;
04
using System.Data;
05
using System.Drawing;
06
using System.Text;
07
using System.Windows.Forms;
08
using DevExpress.XtraEditors;
09
using DevExpress.XtraReports.UI;
10
using DevExpress.XtraPrinting.Preview;
11
using DevExpress.XtraPrinting;
12
using DevExpress.XtraPrinting.Control;
13
14
namespace WFAXtraReport
15
{
16
public partial class Form1:
Form
17
{
18
public Form1()
19
{
20
InitializeComponent();
21
}
22
23
private void Form1_Load(object sender,EventArgse)
24
{
25
26
XtraReportfXtraReport= new XtraReport();
27
//fXtraReport.LoadLayout(@"C:
\1.repx");
28
29
PrintControlprintControl1= new PrintControl();
30
printControl1.PrintingSystem=fXtraReport.PrintingSystem;
31
32
33
PrintBarManagerprintBarManager= new PrintBarManager();
34
printBarManager.Form=printControl1;
35
printBarManager.Initialize(printControl1);
36
printBarManager.MainMenu.Visible= false;
37
printBarManager.AllowCustomization= false;
38
39
//操作要显示什么按钮
40
printControl1.PrintingSystem.SetCommandVisibility(new PrintingSystemCommand[]{
41
PrintingSystemCommand.Open,
42
PrintingSystemCommand.Save,
43
PrintingSystemCommand.ClosePreview,
44
PrintingSystemCommand.Customize,
45
PrintingSystemCommand.SendCsv,
46
PrintingSystemCommand.SendFile,
47
PrintingSystemCommand.SendGraphic,
48
PrintingSystemCommand.SendMht,
49
PrintingSystemCommand.SendPdf,
50
PrintingSystemCommand.SendRtf,
51
PrintingSystemCommand.SendTxt,
52
PrintingSystemCommand.SendXls
53
},CommandVisibility.None);
54
55
fXtraReport.CreateDocument();
56
57
Controls.Add(printControl1);
58
printControl1.Dock=DockStyle.Fill;
59
}
60
}
61
}
关于XtraReport的功能还有很多,细节上的处理还有很多,留待以后再整理,先整理这几个常用的。
posted@2010-12-0621:
10CookBlack阅读(423)|评论(0)| 编辑
DeveloperExpress之XtraReport如何显示设计窗体
XtraReport的设计器,其实用XRDesignFormEx就可以。
01
using System;
02
using System.Collections.Generic;
03
using System.ComponentModel;
04
using System.Data;
05
using System.Drawing;
06
using System.Linq;
07
using System.Text;
08
using System.Windows.Forms;
09
using DevExpress.XtraReports.UI;
10
using DevExpress.XtraReports.UserDesigner;
11
using System.Drawing.Design;
12
using System.ComponentModel.Design;
13
14
namespace WFAXtraReport
15
{
16
public partial class Form1:
Form
17
{
18
XtraReportr;//这个可以是加载之前设计好的模板
19
public Form1()
20
{
21
InitializeComponent();
22
}
23
24
private void designForm_FormClosing(object sender,FormClosingEventArgse)
25
{
26
//在此处处理关闭设计器时的操作,主要用来自定义保存数据
27
//r.SaveLayout(@"C:
\1.repx");
28
}
29
30
private void designForm_ReportStateChanged(object sender,ReportStateEventArgse)
31
{
32
//只要报表发生改变就立即将状态设置为保存
33
//避免系统默认保存对话框的出现
34
if (e.ReportState==ReportState.Changed)
35
{
36
((XRDesignFormEx)sender).DesignPanel.ReportState=ReportState.Saved;
37
}
38
}
39
40
private void Form1_Load(object sender,EventArgse)
41
{
42
r= new XtraReport();
43
//r.LoadLayout(@"C:
\1.repx");
44
XRDesignFormExdesignForm= new XRDesignFormEx();
45
46
//隐藏按钮
47
designForm.DesignPanel.SetCommandVisibility(new ReportCommand[]{
48
ReportCommand.NewReport,
49
ReportCommand.SaveFileAs,
50
ReportCommand.NewReportWizard,
51
ReportCommand.OpenFile
52
},CommandVisibility.None);
53
54
55
//更改状态
56
designForm.ReportStateChanged+= new ReportStateEventHandler(designForm_ReportStateChanged);
57
58
designForm.FormClosing+= new FormClosingEventHandler(designForm_FormClosing);
59
60
//加载报表.
61
designForm.OpenReport(r);
62
63
//打开设计器
64
designForm.ShowDialog();
65
66
designForm.Dispose();
67
}
68
}
69
}
70
微软雅黑;">这样我们就能在加载和销毁设计窗体的时候要控制什么,你可以重载里面的数据。
比如设计窗体显示有点慢,我们在开始的时候加载个等待窗体,显示出来后关闭这个
1
微软雅黑;">显示等待的窗体。
还有其他的事件视情况而定。
(参考1
DeveloperExpress之XtraReport如何数据动态绑定。
posted@2010-12-0620:
56CookBlack阅读(296)|评论(0)| 编辑
DeveloperExpress之XtraReport如何动态绑定数据
XtraReport报表编辑器里的保存,是可以保存为一个文件的,所以它应该提供了一个从文件加载的方法,这时我们可以发现XtraReport里有一个LoadLayout的方法,可以加载报表文件,它的重载方法是可以从IO.Stream里加载报表文件,也就是说,我们可以进一步的把这个报表模板以二进制的方式保存在数据库里。
需要的时候,从数据库调用即可。
我们在设计XtraReport的模板的时候,重写它的析构方法,一个有传入数据源的,一个没有。
代码如下:
01
public XtraReport1()
02
{
03
InitializeComponent();
04
05
} //数据预览是有用
06
public XtraReport1(DataSetds)//构造函数重载
07
{
08
InitializeComponent();
09
SetDataBind(ds);
10
}
11
12
private void SetDataBind(DataSetds)//绑定数据源
13
{
14
DataSource=ds;
15
this.xrTableCell4.DataBindings.Add("Text",DataSource, "test1");
16
this.xrTableCell5.DataBindings.Add("Text",DataSource, "test1");
17
}
1
填充数据代码如下:
01
private void simpleButton1_Click(object sender,System.EventArgse)
02
{
03
04
XtraReport1 xrpt1=new XtraReport1(GetTempDataSet());
05
xrpt1.ShowPreviewDialog();
06
}
07
private DataSetGetTempDataSet()
08
{
09
DataSetds=new DataSet();
10
DataTabledt=new DataTable("tempTable");
11
dt.Columns.Add("test1",Type.GetType("System.String"));
12
dt.Columns.Add("test",Type.GetType("System.String"));
13
dt.Columns.Add("test3",Type.GetType("System.String"));
14
dt.Columns.Add("test4",Type.GetType("System.String"));
15
dt.Columns.Add("test5",Type.GetType("System.String"));
16
dt.Columns.Add("test6",Type.GetType("System.String"));
17
dt.Columns.Add("test7",Type.GetType("System.String"));
18
DataRowtempRow;
19
for (int i=0;i<7;i++)//i:
Row
20
{
21
tempRow=dt.NewRow();
22
tempRow[0]=i.ToString();
23
tempRow[1]=i.ToString();
24
tempRow[2]=i.ToString();
25
tempRow[3]=i.ToString();
26
tempRow[4]=i.ToString();
27
tempRow[5]=i.ToString();
28
tempRow[6]=i.ToString();
29
dt.Rows.Add(tempRow);
30
}
31
32
ds.Tables.Add(dt);
33
return ds;
34
}
1
其中关于主从表的话,因为传进去的DaTaSet所以我们可以再外面把相应的关系指定好后加到DaTaSet。
1
下面给出主从表的代码:
1
DataColumnparentColumns;
2
DataColumnchildColumns;
3
parentColumns=ds.Tables["Suppliers"].Columns["SupplierID"];
4
childColumns=ds.Tables["Products"].Columns["SupplierID"];
5
DataRelationdsdr1= new DataRelation("fk_1",parentColumns,childColumns);
6
ds.Relations.Add(dsdr1);
7
8
DataRelationdsdr2= new DataRelation("fk_2",ds.Tables["Products"].Columns["ProductID"],ds.Tables["OrderDetails"].Columns["ProductID"]);
9
ds.Relations.Add(dsdr2);
而模板中绑定数据的话跟上面单表是的大同小异,但是里面的绑定要记得引用的是你绑定关系的外键,也就是,如下代码:
01
public XtraReport1(DataSetds)
02
{
03
InitializeComponent();
04
SetDataBing(ds);
05
}
06
private void SetDataBing(DataSetds)
07
{
08
09
DataMember= "Suppliers";
10
DataSource=ds;
11
12
13
this.cellCompanyName.DataBindings.Add("Text",DataSource, "Suppliers.CompanyName");
14
this.sContadName.DataBindings.Add("Text",DataSource, "Suppliers.ContadName");
15
this.sCountry.DataBindings.Add("Text",DataSource, "Suppliers.Country");
16
this.sContactTitle.DataBindings.Add("Text",DataSource, "Suppliers.ContactTitle");
17
this.sRegion.DataBindings.Add("Text",DataSource, "Suppliers.Region");
18
this.sPhone.DataBindings.Add("Text",DataSource, "Suppliers.Phone");
19
this.sCi