日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

RDLC报表(六)

發(fā)布時(shí)間:2025/5/22 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 RDLC报表(六) 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.


??????? 你可能已經(jīng)注意到了在調(diào)用LocalReport的Render方法時(shí)用到了一個(gè)XML格式的DeviceInfo結(jié)構(gòu),在SQL Server 2005 Report Services中,DeviceInfo結(jié)構(gòu)是為了給特定的呈現(xiàn)格式傳遞參數(shù)。來(lái)看一個(gè)簡(jiǎn)單的DeviceInfo結(jié)構(gòu):

<DeviceInfo>?
????
<OutputFormat>EMF</OutputFormat>?
????
<PageWidth>21cm</PageWidth>?
????
<PageHeight>29.70cm</PageHeight>?
????
<MarginTop>2cm</MarginTop>?
????
<MarginLeft>2cm</MarginLeft>?
????
<MarginRight>2cm</MarginRight>?
????
<MarginBottom>2cm</MarginBottom>?
</DeviceInfo>

??????? 這個(gè)簡(jiǎn)單的DeviceInfo結(jié)構(gòu)至少為L(zhǎng)ocalReport的Render方法指定了輸出格式、頁(yè)寬、頁(yè)高、左邊距、右邊距、下邊距信息,在我們使用PrintPage的方法將LocalReport呈現(xiàn)為EMF圖片時(shí),EMF圖片在頁(yè)面上顯示的大小、邊距就是由這個(gè)DeviceInfo結(jié)構(gòu)來(lái)決定的,如果為DeviceInfo結(jié)構(gòu)和PrintDocumnt設(shè)置不匹配的頁(yè)面大小或邊距,那么在PrintPage事件中使用DrawImage方法畫(huà)出的圖片將出現(xiàn)放大或縮小的情況,這是我們不愿意看到的結(jié)果。也就是說(shuō),在使用自定義紙張進(jìn)行單據(jù)打印時(shí),我們不僅要為PrintDocument設(shè)置頁(yè)面大小和邊距,還要為L(zhǎng)ocalReport設(shè)置與PrintDocument相同的頁(yè)面大小和邊距。關(guān)于DeviceInfo的結(jié)構(gòu),可以參考http://msdn2.microsoft.com/zh-cn/library/ms155373.aspx

??????? 下面是我封裝的一個(gè)為生成DeviceInfo結(jié)構(gòu)使用的類(lèi):

using?System;
using?System.Collections.Generic;
using?System.Text;

namespace?RDLCReport
{
????
public?class?EMFDeviceInfo
????
{
????????
private?bool?m_Landscape?=?false;

????????
public?bool?Landscape
????????
{
????????????
get
????????????
{
????????????????
return?this.m_Landscape;
????????????}

????????????
set
????????????
{
????????????????
this.m_Landscape?=?value;
????????????}

????????}


????????
/**//*
?????????*?The?pixel?depth?of?the?color?range?supported?by?the?image?output.?
?????????*?Valid?values?are?1,?4,?8,?24,?and?32.?
?????????*?The?default?value?is?24.?
?????????*?ColorDepth?is?only?supported?for?TIFF?rendering?and?is?otherwise?ignored?by?the?report?server?for?other?image?output?formats.?
?????????*?Note:?
?????????*?For?this?release?of?SQL?Server,?the?value?of?this?setting?is?ignored,?and?the?TIFF?image?is?always?rendered?as?24-bit.
?????????*?
?????????*?默認(rèn)值為24,且只有當(dāng)輸出格式為T(mén)IFF時(shí)才該項(xiàng)設(shè)置才起作用
?????????*?
????????
*/

????????
private?int?m_ColorDepth?=?24;

????????
public?int?ColorDepth
????????
{
????????????
get
????????????
{
????????????????
return?this.m_ColorDepth;
????????????}

????????}



????????
/**//*
?????????*?The?number?of?columns?to?set?for?the?report.?This?value?overrides?the?report's?original?settings.
?????????*?
?????????*?未用到此項(xiàng)設(shè)置
?????????*?
????????
*/

????????
private?int?m_Columns?=?0;

????????
public?int?Columns
????????
{
????????????
get
????????????
{
????????????????
return?this.m_Columns;
????????????}

????????????
set
????????????
{
????????????????
this.m_Columns?=?value;
????????????}

????????}



????????
/**//*
?????????*?The?column?spacing?to?set?for?the?report.?This?value?overrides?the?report's?original?settings.
?????????*?
?????????*?未用到此項(xiàng)設(shè)置
?????????*?
????????
*/

????????
private?int?m_ColumnSpacing?=?0;

????????
public?int?ColumnSpacing
????????
{
????????????
get
????????????
{
????????????????
return?this.m_ColumnSpacing;
????????????}

????????????
set
????????????
{
????????????????
this.m_ColumnSpacing?=?value;
????????????}

????????}


????????
/**//*
?????????*?The?resolution?of?the?output?device?in?x-direction.?The?default?value?is?96.
?????????*?
?????????*?解析度,默認(rèn)值為96
?????????*?
????????
*/

????????
private?int?m_DpiX?=?96;

????????
public?int?DpiX
????????
{
????????????
get
????????????
{
????????????????
return?this.m_DpiX;
????????????}

????????????
set
????????????
{
????????????????
this.m_DpiX?=?value;
????????????}

????????}



????????
/**//*
?????????*?The?resolution?of?the?output?device?in?y-direction.?The?default?value?is?96.
?????????*?
?????????*?解析度,默認(rèn)值為96
?????????*?
????????
*/

????????
private?int?m_DpiY?=?96;

????????
public?int?DpiY
????????
{
????????????
get
????????????
{
????????????????
return?this.m_DpiY;
????????????}

????????????
set
????????????
{
????????????????
this.m_DpiY?=?value;
????????????}

????????}



????????
/**//*
?????????*?The?last?page?of?the?report?to?render.?The?default?value?is?the?value?for?StartPage.
?????????*?
?????????*?要輸出的報(bào)表的最后一頁(yè)
?????????*?
?????????
*/

????????
private?int?m_EndPage?=?0;

????????
public?int?EndPage
????????
{
????????????
get
????????????
{
????????????????
return?this.m_EndPage;
????????????}

????????????
set
????????????
{
????????????????
this.m_EndPage?=?value;
????????????}

????????}



????????
/**//*
?????????*?The?first?page?of?the?report?to?render.?A?value?of?0?indicates?that?all?pages?are?rendered.?The?default?value?is?1.
?????????*?
?????????*?起始頁(yè),0代表所有頁(yè)面都將輸出,默認(rèn)值為1。
?????????*?
?????????
*/

????????
private?int?m_StartPage?=?1;

????????
public?int?StartPage
????????
{
????????????
get
????????????
{
????????????????
return?this.m_StartPage;
????????????}

????????????
set
????????????
{
????????????????
this.m_StartPage?=?value;
????????????}

????????}


????????
/**//*
?????????*?The?bottom?margin?value,?in?inches,?to?set?for?the?report.?You?must?include?an?integer?or?decimal?value?followed?by?"in"?(for?example,?1in).?This?value?overrides?the?report's?original?settings.
?????????*?
?????????*?底部邊距,必須加上單位如"in"
?????????*?
?????????
*/

????????
private?decimal?m_MarginBottom?=?0;

????????
public?decimal?MarginBottom
????????
{
????????????
get
????????????
{
????????????????
return?this.m_MarginBottom;
????????????}

????????????
set
????????????
{
????????????????
this.m_MarginBottom?=?value;
????????????}

????????}



????????
/**//*
?????????*?The?top?margin?value,?in?inches,?to?set?for?the?report.?You?must?include?an?integer?or?decimal?value?followed?by?"in"?(for?example,?1in).?This?value?overrides?the?report's?original?settings.
?????????*?
?????????*?頂部邊距,必須加上單位如"in"
?????????*?
?????????
*/

????????
private?decimal?m_MarginTop?=?0;

????????
public?decimal?MarginTop
????????
{
????????????
get
????????????
{
????????????????
return?this.m_MarginTop;
????????????}

????????????
set
????????????
{
????????????????
this.m_MarginTop?=?value;
????????????}

????????}



????????
/**//*
?????????*?The?left?margin?value,?in?inches,?to?set?for?the?report.?You?must?include?an?integer?or?decimal?value?followed?by?"in"?(for?example,?1in).?This?value?overrides?the?report's?original?settings.
?????????*?
?????????*?左邊距,必須加上單位如"in"
?????????*?
?????????
*/

????????
private?decimal?m_MarginLeft?=?0;

????????
public?decimal?MarginLeft
????????
{
????????????
get
????????????
{
????????????????
return?this.m_MarginLeft;
????????????}

????????????
set
????????????
{
????????????????
this.m_MarginLeft?=?value;
????????????}

????????}



????????
/**//*
?????????*?The?right?margin?value,?in?inches,?to?set?for?the?report.?You?must?include?an?integer?or?decimal?value?followed?by?"in"?(for?example,?1in).?This?value?overrides?the?report's?original?settings.
?????????*?
?????????*?右邊距,必須加上單位如"in"
?????????*?
?????????
*/

????????
private?decimal?m_MarginRight?=?0;

????????
public?decimal?MarginRight
????????
{
????????????
get
????????????
{
????????????????
return?this.m_MarginRight;
????????????}

????????????
set
????????????
{
????????????????
this.m_MarginRight?=?value;
????????????}

????????}


????????
/**//*
?????????*?One?of?the?Graphics?Device?Interface?(GDI)?supported?output?formats:?BMP,?EMF,?GIF,?JPEG,?PNG,?or?TIFF.
?????????*?
?????????*?圖形設(shè)備接口(GDI)支持的一種輸出格式,可以是BMP,?EMF,?GIF,?JPEG,?PNG,?或?TIFF.
?????????*?此處使用EMF
?????????
*/

????????
private?string?m_OutputFormat?=?"EMF";

????????
public?string?OutputFormat
????????
{
????????????
get
????????????
{
????????????????
return?this.m_OutputFormat;
????????????}

????????????
set
????????????
{
????????????????
this.m_OutputFormat?=?value;
????????????}

????????}


????????
/**//*
?????????*?The?page?height,?in?inches,?to?set?for?the?report.?You?must?include?an?integer?or?decimal?value?followed?by?"in"?(for?example,?11in).?This?value?overrides?the?report's?original?settings.
?????????*?
?????????*?頁(yè)面高度,必須加上單位如"in"
?????????*?
?????????
*/

????????
private?decimal?m_PageHeight?=?0;

????????
public?decimal?PageHeight
????????
{
????????????
get
????????????
{
????????????????
return?this.m_PageHeight;
????????????}

????????????
set
????????????
{
????????????????
this.m_PageHeight?=?value;
????????????}

????????}



????????
/**//*
?????????*?The?page?width,?in?inches,?to?set?for?the?report.?You?must?include?an?integer?or?decimal?value?followed?by?"in"?(for?example,?8.5in).?This?value?overrides?the?report's?original?settings.
?????????*?
?????????*?頁(yè)面寬度,必須加上單位如"in"
?????????*?
????????
*/

????????
private?decimal?m_PageWidth?=?0;

????????
public?decimal?PageWidth
????????
{
????????????
get
????????????
{
????????????????
return?this.m_PageWidth;
????????????}

????????????
set
????????????
{
????????????????
this.m_PageWidth?=?value;
????????????}

????????}


????????
/**////?<summary>
????????
///?返回包含DeviceInfo的字符串
????????
///?</summary>

????????public?string?DeviceInfoString
????????
{
????????????
get
????????????
{
????????????????
string?strRet?=?string.Empty;

????????????????strRet?
+=?"<DeviceInfo>"?+
????????????????????
"??<OutputFormat>"?+?this.m_OutputFormat?+?"</OutputFormat>";

????????????????
if?(this.m_Landscape)
????????????????????strRet?
+=
????????????????????????
"??<PageWidth>"?+?this.m_PageHeight.ToString()?+?"cm</PageWidth>"?+
????????????????????????
"??<PageHeight>"?+?this.m_PageWidth.ToString()?+?"cm</PageHeight>";
????????????????
else
????????????????????strRet?
+=
????????????????????????
"??<PageWidth>"?+?this.m_PageWidth.ToString()?+?"cm</PageWidth>"?+
????????????????????????
"??<PageHeight>"?+?this.m_PageHeight.ToString()?+?"cm</PageHeight>";

????????????????strRet?
+=
????????????????????????
"??<MarginTop>"?+?this.m_MarginTop.ToString()?+?"cm</MarginTop>"?+
????????????????????????
"??<MarginLeft>"?+?this.m_MarginLeft.ToString()?+?"cm</MarginLeft>"?+
????????????????????????
"??<MarginRight>"?+?this.m_MarginRight.ToString()?+?"cm</MarginRight>"?+
????????????????????????
"??<MarginBottom>"?+?this.m_MarginBottom.ToString()?+?"cm</MarginBottom>";

????????????????strRet?
+=?"</DeviceInfo>";

????????????????
return?strRet;

????????????}


????????}
???
????}

}

??????? 好了,解決了DeviceInfo,現(xiàn)在來(lái)看一下如何在PrintDocument的PrintPage事件中向打印機(jī)輸出由LocalReport呈現(xiàn)的EMF圖片。使用的方法基本上就是在GotReportViewer的例程Print a report from a console app中使用的方法,但是需要指出的一點(diǎn)是例程中使用事件參數(shù)System.Drawing.Printing.PrintPageEventArgs類(lèi)的Graphics屬性的DrawImage方法向打印機(jī)輸出EMF圖片,在實(shí)際的應(yīng)用中,發(fā)現(xiàn)DrawImage方法繪出的圖片會(huì)出現(xiàn)放大或縮小的情況,即使為DrawImage方法指定了看起來(lái)正確的參數(shù)ev.Graphics.DrawImageUnscaledAndClipped(this.m_PageImage, ev.PageBounds);,我使用的方法是DrawImageUnscaledAndClipped,在為DeviceInfo結(jié)構(gòu)和PrintDocument指定好適當(dāng)且匹配的頁(yè)面設(shè)置時(shí),輸出的結(jié)果是比較好的。

??????? 待續(xù)……

??????? 相關(guān)隨筆:
????????????????RDLC報(bào)表(一)
????????????????RDLC報(bào)表(二)
????????????????RDLC報(bào)表(三)
????????????????RDLC報(bào)表(四)
????????????????RDLC報(bào)表(五)

???????


總結(jié)

以上是生活随笔為你收集整理的RDLC报表(六)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。