报表组件,如何在客户端报表定义文件(RDCL)中使用Aspose.BarCode组件

在本篇文章中,我们将创建一个客户端报表定义文件(RDCL),并将其与我们的Aspose.BarCode组件整合。
在vs2005中创建一个新项目,选择“Windows应用程序”作为项目类型。
在解决方案资源管理器中右击项目并选择一个新项目,将新的“DataSet”添加到项目中。从模板中选择“DataSet”。
在数据集的设计视图中右击,选择并添加一个新的“TableAdapter”到数据集中。
创建一个新的数据库连接,又或者从下了列表中选择一个已经创建的数据库连接。果您正创建一个新的连接,请给你的数据库服务器命名和设置身份验证信息,并选择“AdventureWorks”作为你的数据库。请确保如果你按“测试连接”按钮,你会得到一个“测试连接成功”的消息。
如何在客户端报表定义文件(RDCL)中使用Aspose.BarCode组件报表组件
选择数据连接后,进行下一步。在“选择命令类型”屏幕中,选择“使用SQL语句”,然后点击“下一步”。在“Enter a SQL Statement”框中输入下列查询:SELECT ProductID, Name, ProductNumber FROM Product
如何在客户端报表定义文件(RDCL)中使用Aspose.BarCode组件报表组件
按“下一步”,将所有选项为默认选中,按“完成”。
右击并选择添加一列到新的数据表中。
如何在客户端报表定义文件(RDCL)中使用Aspose.BarCode组件报表组件
将该列命名为“BarCode”,并将此列的数据类型设置为 System.Byte[]. 下列列表中不包含此数据类型,因此,你需要像下图所示一样将数据类型输入进去。
如何在客户端报表定义文件(RDCL)中使用Aspose.BarCode组件报表组件
添加引用到项目中的Aspose.BarCode.dll。右键单击解决方案资源管理器中的“References”,选择“Add Reference”。
接下来,在解决方案资源管理器中右键单击项目,选择添加一个New Item,便可将一个新的报表添加到项目中。从模板对话框中选择“Report”。
如何在客户端报表定义文件(RDCL)中使用Aspose.BarCode组件报表组件
添加一个新的空白报表。从工具箱中将“Table”拖放到报表中。在表中添加列,如图所示:
如何在客户端报表定义文件(RDCL)中使用Aspose.BarCode组件报表组件
将“Data Source” 窗口中的“ProductNumber” 和“ProductName” 列分别拖到表中。对于“BarCode”一列,从工具箱中拖动“image”到“BarCode”列。
如何在客户端报表定义文件(RDCL)中使用Aspose.BarCode组件报表组件
为图像控件设置属性,如下图所示:
如何在客户端报表定义文件(RDCL)中使用Aspose.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
运行该项目,条码列会在报表中显示条码图像,如下图所示:
如何在客户端报表定义文件(RDCL)中使用Aspose.BarCode组件报表组件
Tags:  aspose 通达oa报表组件 报表组件

延伸阅读

最新评论

发表评论