亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

.Net報表開發(fā)控件XtraReport介紹

 更新時間:2022年06月02日 09:30:19   作者:springsnow  
這篇文章介紹了.Net報表開發(fā)控件XtraReport,文中通過示例代碼介紹的非常詳細。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下

?一、概述

在XtraReport中,每一個報表都是XtraReport或者其子類。

XtraReport中的報表類可以與數(shù)據(jù)綁定也可以不綁定。

在創(chuàng)建一個報表時,可以從已有的報表中加載樣式和布局,樣式中包含了報表控件外觀的屬性值,而布局包含了報表的結(jié)構(gòu)信息。另外,還可以從其他報表系統(tǒng)中導(dǎo)入報表,比如:Access,水晶報表等等。

報表類(XtraReport的子類)創(chuàng)建后,就可以生成其實例。需要注意的是,XtraReport對象可以在Windows Forms中使用也可以在Asp.net中使用。在Windows應(yīng)用中使用報表,通常需要維護報表的,這個對象提供了報表的輸出功能。

創(chuàng)建報表有兩種方式,一種是簡單地添加一個"模板"報表,一種是通過報表向?qū)韯?chuàng)建報表。

在報表添加到項目后,報表設(shè)計器提供了大量的設(shè)計時元素來加快簡化報表的創(chuàng)建。XtraReport工具箱包含了所有的控件。

Report Navigator可以瀏覽整個報表,F(xiàn)eild List可以拖放數(shù)據(jù)字段來創(chuàng)建與數(shù)據(jù)綁定的報表控件。

XtraReport的所有報表都是由和組成的。

public class XtraReport1 : DevExpress.XtraReports.UI.XtraReport
{
    private DevExpress.XtraReports.UI.DetailBand Detail;
    private DevExpress.XtraReports.UI.PageHeaderBand PageHeader;
    private DevExpress.XtraReports.UI.PageFooterBand PageFooter;
    private DevExpress.XtraReports.UI.XRLabel xrLabel1;
    private DevExpress.XtraReports.UI.XRLabel xrLabel2;

    private System.ComponentModel.Container components = null;

    public XtraReport1()
    {
        InitializeComponent();
    }

    protected override void Dispose(bool disposing)
    {
        if (disposing)
        {
            if (components != null)
            {
                components.Dispose();
            }
        }
        base.Dispose(disposing);
    }
}

然后開始創(chuàng)建報表的結(jié)構(gòu),首先在XtraReportBase.Bands屬性中添加Bands,然后在相應(yīng)的Bands的XRControl.Controls屬性中添加控件。報表帶和控件的添加方法一般是這樣的。

// Add Detail, PageHeader and PageFooter bands to the report's collection of bands.
this.Bands.AddRange(new DevExpress.XtraReports.UI.Band[] { this.Detail, this.PageHeader, this.PageFooter });

// Add two XRLabel controls to the Detail band.
this.Detail.Controls.AddRange(new DevExpress.XtraReports.UI.XRControl[] { this.xrLabel1, this.xrLabel2 });

可以給報表傳遞參數(shù):

XtraReport1 report = new XtraReport1();  
report.Parameters["yourParameter1"].Value = firstValue;  
report.Parameters["yourParameter2"].Value = secondValue;

報表內(nèi)使用參數(shù):

report.FilterString = "[CategoryID] = [Parameters.yourParameter1]";

最后創(chuàng)建好的報表可以輸出給用戶看了

// Create a report.
XtraReport1 report = new XtraReport1();

// Create the report's document so it can then be previewed, printed or exported.
// NOTE: Usually you don't need to call this method as it's automatically called by all of the following methods.
// See the corresponding member topic to find out when it needs to be called.
report.CreateDocument();

// Show the form with the report's print preview.
report.ShowPreview();

// Print the report in a dialog and "silent" mode.
report.PrintDialog();
report.Print();

// Open the report in the End-User designer
report.RunDesigner();

// Export the report.
report.CreateHtmlDocument("report.html");
report.CreatePdfDocument("report.pdf");
report.CreateImage("report.jpg", System.Drawing.Imaging.ImageFormat.Gif);

二、實例展示

1、報表設(shè)計

在報表屬性中,設(shè)置默認font為微軟雅黑,設(shè)置Language為默認(注意:不能設(shè)置為中文,否則導(dǎo)出PDF中文亂碼)。

2、報表后臺代碼

綁定到List類型的綁定方法,設(shè)置報表上的對象的XRBinging中DataSource參數(shù)為null。

從報表的DataMember 需要設(shè)置,否則從報表只顯示一條記錄。

同時“計算”字段的表達式的使用。

public partial class MyReport : DevExpress.XtraReports.UI.XtraReport
{
    public MyReport()
    {
        InitializeComponent();

        this.xrLabel6.DataBindings.Add("Text", null, "FileNo");
        this.xrLabel7.DataBindings.Add("Text", null, "ApplyTime", "{0:yyyy-MM-dd}");

        CalculatedField calculatedField1 = new CalculatedField
        {
            Expression = "Iif([InspectItms.InspectResult]==1,'合格','不合格' )",
            Name = "calculatedField1"
        };
        CalculatedField calculatedField2 = new CalculatedField
        {
            Expression = "[ReviewResult]=='1'",
            Name = "calculatedField2"
        };

        this.CalculatedFields.AddRange(new DevExpress.XtraReports.UI.CalculatedField[] { calculatedField1, calculatedField2});
        
        DetailReport.DataMember = "InspectItms";
        this.xrTableCell5.DataBindings.Add("Text", null, "InspectItms.InspectItem");
        this.xrTableCell6.DataBindings.Add("Text", null, "calculatedField1");
        this.xrCheckBox1.DataBindings.Add("Checked", null, "calculatedField2");

    }
}

3、調(diào)用報表

List list = new List<MyEntity> { entity };
MyReport myReport = new MyReport(); //報表實例
myReport.DataSource = list;//綁定報表的數(shù)據(jù)源
myReport.ShowPreview();

到此這篇關(guān)于.Net報表開發(fā)控件XtraReport的文章就介紹到這了。希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • WPF框架Prism中View Injection用法介紹

    WPF框架Prism中View Injection用法介紹

    這篇文章介紹了WPF框架Prism中View Injection的用法,文中通過示例代碼介紹的非常詳細。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-02-02
  • ORM框架之Dapper簡介和性能測試

    ORM框架之Dapper簡介和性能測試

    這篇文章介紹了ORM框架之Dapper簡介和性能測試,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2022-01-01
  • asp.net Webconfig中的一些配置

    asp.net Webconfig中的一些配置

    除了手動編輯此文件以外,您還可以使用Web 管理工具來配置應(yīng)用程序的設(shè)置??梢允褂?Visual Studio 中的“網(wǎng)站”->“Asp.Net 配置”選項。
    2010-07-07
  • ASP.NET?Core?Razor頁面用法介紹

    ASP.NET?Core?Razor頁面用法介紹

    這篇文章介紹了ASP.NET?Core?Razor頁面的用法,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2022-02-02
  • asp.net FindControl方法誤區(qū)和解析

    asp.net FindControl方法誤區(qū)和解析

    在ASP.NET中Control都有一個FindControl方法,其作用是根據(jù)ID(注意既不是UniqueID也不是ClientID)在Control所在的命名容器中尋找相應(yīng)控件,但實際使用中存在很多誤區(qū)和陷阱,下面談?wù)剛€人對此的理解
    2012-01-01
  • C#使用正則表達式實例

    C#使用正則表達式實例

    正則表達式(regular expression)是用來快速、高效地處理文本數(shù)據(jù)的工具。被處理的文本可以小到一個電子郵件地址,也可以大到一個多行文本輸入框中的文本數(shù)據(jù)。正則表達式不僅可用來確認一段文本是否與一個預(yù)定義的模式相匹配,還可以用于從文本中抽取符合某一模式的數(shù)據(jù)。
    2008-04-04
  • .Net行為型設(shè)計模式之備忘錄模式(Memento)

    .Net行為型設(shè)計模式之備忘錄模式(Memento)

    這篇文章介紹了.Net行為型設(shè)計模式之備忘錄模式(Memento),文中通過示例代碼介紹的非常詳細。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-05-05
  • ASP.NET 中的Application詳解

    ASP.NET 中的Application詳解

    Application對象是HttpApplicationState類的一個實例,Application狀態(tài)是整個應(yīng)用程序全局的。本文主要詳細介紹Application對象的用法。
    2016-04-04
  • Asp.net請求處理之管道處理介紹

    Asp.net請求處理之管道處理介紹

    在了解Asp.net請求處理流程的過程中,個人認為有必要從源代碼的角度來了解asp.net管道是怎么實現(xiàn)的,需要的朋友可以參考下
    2012-11-11
  • asp.net平臺下C#實現(xiàn)Socket通信

    asp.net平臺下C#實現(xiàn)Socket通信

    這篇文章介紹了asp.net平臺下C#實現(xiàn)Socket通信的方法,文中通過示例代碼介紹的非常詳細。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-01-01

最新評論