原創(chuàng)|其它|編輯:郝浩|2011-09-26 11:23:39.000|閱讀 944 次
概述:在本篇文章中,我們將創(chuàng)建一個客戶端報(bào)表定義文件(RDCL),并將其與我們的Aspose.BarCode組件整合。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
在本篇文章中,我們將創(chuàng)建一個客戶端報(bào)表定義文件(RDCL),并將其與我們的Aspose.BarCode組件整合。
在vs2005中創(chuàng)建一個新項(xiàng)目,選擇“Windows應(yīng)用程序”作為項(xiàng)目類型。
在解決方案資源管理器中右擊項(xiàng)目并選擇一個新項(xiàng)目,將新的“DataSet”添加到項(xiàng)目中。從模板中選擇“DataSet”。
在數(shù)據(jù)集的設(shè)計(jì)視圖中右擊,選擇并添加一個新的“TableAdapter”到數(shù)據(jù)集中。
創(chuàng)建一個新的數(shù)據(jù)庫連接,又或者從下了列表中選擇一個已經(jīng)創(chuàng)建的數(shù)據(jù)庫連接。果您正創(chuàng)建一個新的連接,請給你的數(shù)據(jù)庫服務(wù)器命名和設(shè)置身份驗(yàn)證信息,并選擇“AdventureWorks”作為你的數(shù)據(jù)庫。請確保如果你按“測試連接”按鈕,你會得到一個“測試連接成功”的消息。
選擇數(shù)據(jù)連接后,進(jìn)行下一步。在“選擇命令類型”屏幕中,選擇“使用SQL語句”,然后點(diǎn)擊“下一步”。在“Enter a SQL Statement”框中輸入下列查詢:SELECT ProductID, Name, ProductNumber FROM Product
按“下一步”,將所有選項(xiàng)為默認(rèn)選中,按“完成”。
右擊并選擇添加一列到新的數(shù)據(jù)表中。
將該列命名為“BarCode”,并將此列的數(shù)據(jù)類型設(shè)置為 System.Byte[]. 下列列表中不包含此數(shù)據(jù)類型,因此,你需要像下圖所示一樣將數(shù)據(jù)類型輸入進(jìn)去。
添加引用到項(xiàng)目中的Aspose.BarCode.dll。右鍵單擊解決方案資源管理器中的“References”,選擇“Add Reference”。
接下來,在解決方案資源管理器中右鍵單擊項(xiàng)目,選擇添加一個New Item,便可將一個新的報(bào)表添加到項(xiàng)目中。從模板對話框中選擇“Report”。
添加一個新的空白報(bào)表。從工具箱中將“Table”拖放到報(bào)表中。在表中添加列,如圖所示:
將“Data Source” 窗口中的“ProductNumber” 和“ProductName” 列分別拖到表中。對于“BarCode”一列,從工具箱中拖動“image”到“BarCode”列。
為圖像控件設(shè)置屬性,如下圖所示:
然后,打開Windows窗體,將“ReportViewer”控件從工具箱中拖動到Windows窗體。將“Choose Report”添加到剛才創(chuàng)建的rdlc報(bào)表。
現(xiàn)在,我們需要編寫一些代碼來顯示條碼列中的條碼圖像。
[C#]
private void Form1_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'DataSet1.Product' table. You can move, or remove it, as needed.
this.ProductTableAdapter.Fill(this.DataSet1.Product);
// create an instance of BarCodeBuilder class
BarCodeBuilder builder = new BarCodeBuilder();
// set the symbology type
builder.SymbologyType = Symbology.Code128;
// loop through all the rows in the datatable
foreach (DataSet1.ProductRow row in DataSet1.Product.Rows)
{
// set the codetext as value of "ProductNumber" column
builder.CodeText = row.ProductNumber.ToString();
// generate the barcode and save it in memory stream
MemoryStream ms = new MemoryStream();
builder.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
// set the value of "BarCode" column to the memory stream
// this would show the barcode image
row.BarCode = ms.GetBuffer();
}
this.reportViewer1.RefreshReport();
}
[VB.NET]
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
' TODO: This line of code loads data into the 'DataSet1.Product' table. You can move, or remove it, as needed.
Me.ProductTableAdapter.Fill(Me.DataSet1.Product)
' create an instance of BarCodeBuilder class
Dim builder As BarCodeBuilder = New BarCodeBuilder()
' set the symbology type
builder.SymbologyType = Symbology.Code128
' loop through all the rows in the datatable
For Each row As DataSet1.ProductRow In DataSet1.Product.Rows
' set the codetext as value of "ProductNumber" column
builder.CodeText = row.ProductNumber.ToString()
' generate the barcode and save it in memory stream
Dim ms As MemoryStream = New MemoryStream()
builder.Save(ms, System.Drawing.Imaging.ImageFormat.Png)
' set the value of "BarCode" column to the memory stream
' this would show the barcode image
row.BarCode = ms.GetBuffer()
Next row
Me.reportViewer1.RefreshReport()
End Sub
運(yùn)行該項(xiàng)目,條碼列會在報(bào)表中顯示條碼圖像,如下圖所示:
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉(zhuǎn)載自:慧都控件網(wǎng)