原創|其它|編輯:郝浩|2011-09-26 11:23:39.000|閱讀 944 次
概述:在本篇文章中,我們將創建一個客戶端報表定義文件(RDCL),并將其與我們的Aspose.BarCode組件整合。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
在本篇文章中,我們將創建一個客戶端報表定義文件(RDCL),并將其與我們的Aspose.BarCode組件整合。
在vs2005中創建一個新項目,選擇“Windows應用程序”作為項目類型。
在解決方案資源管理器中右擊項目并選擇一個新項目,將新的“DataSet”添加到項目中。從模板中選擇“DataSet”。
在數據集的設計視圖中右擊,選擇并添加一個新的“TableAdapter”到數據集中。
創建一個新的數據庫連接,又或者從下了列表中選擇一個已經創建的數據庫連接。果您正創建一個新的連接,請給你的數據庫服務器命名和設置身份驗證信息,并選擇“AdventureWorks”作為你的數據庫。請確保如果你按“測試連接”按鈕,你會得到一個“測試連接成功”的消息。
選擇數據連接后,進行下一步。在“選擇命令類型”屏幕中,選擇“使用SQL語句”,然后點擊“下一步”。在“Enter a SQL Statement”框中輸入下列查詢:SELECT ProductID, Name, ProductNumber FROM Product
按“下一步”,將所有選項為默認選中,按“完成”。
右擊并選擇添加一列到新的數據表中。
將該列命名為“BarCode”,并將此列的數據類型設置為 System.Byte[]. 下列列表中不包含此數據類型,因此,你需要像下圖所示一樣將數據類型輸入進去。
添加引用到項目中的Aspose.BarCode.dll。右鍵單擊解決方案資源管理器中的“References”,選擇“Add Reference”。
接下來,在解決方案資源管理器中右鍵單擊項目,選擇添加一個New Item,便可將一個新的報表添加到項目中。從模板對話框中選擇“Report”。
添加一個新的空白報表。從工具箱中將“Table”拖放到報表中。在表中添加列,如圖所示:
將“Data Source” 窗口中的“ProductNumber” 和“ProductName” 列分別拖到表中。對于“BarCode”一列,從工具箱中拖動“image”到“BarCode”列。
為圖像控件設置屬性,如下圖所示:
然后,打開Windows窗體,將“ReportViewer”控件從工具箱中拖動到Windows窗體。將“Choose Report”添加到剛才創建的rdlc報表。
現在,我們需要編寫一些代碼來顯示條碼列中的條碼圖像。
[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
運行該項目,條碼列會在報表中顯示條碼圖像,如下圖所示:
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自:慧都控件網