相忘于江湖

不抛弃,不放弃... 请给我勇敢,改变可以改变的;请给我坚强,接受不可以改变的;请给我智慧,分辨这两者。

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

在报表开发中我们常常要显示合计,比如销售记录,要显示单价,售出件数,合计金额等。

我们可以在从数据库中提取数据的时候就使用SQL来产生一个合计字段,也可以在ActiveReport中进行,有两种方法可以使用。

1.       使用ActiveReport中的LabelTextBox控件的DataField属性。例如,要使一个TextBox显示合计,它的值是由单价和售出件数的乘积。设置TextBoxDataField值为“=单价*售出件数”。然后编写代码,加载数据,设置Field集合,然后在FetchData事件中给Field赋值,就可以完成了,例如:

this.Fields["ProductName"].Value = row.productName;

this.Fields["UnitPrice"].Value = row.unitPrice;

this.Fields["Quantity"].Value = row.quantity;

2.       不对DataField属性使用表达式,而是直接在FetchData中进行计算,例如:

double quantity = Convert.ToDouble(this.Fields["Quantity"].Value);

double unitPrice = Convert.ToDouble(this.Fields["UnitPrice"].Value);

this.Fields["ExtendedPrice"].Value =  quantity * unitPrice;

当然要在报表上显示要设置LabelTextBoxDataField属性为ExtendedPrice

posted on 2007-12-10 14:45  playman0211  阅读(295)  评论(0编辑  收藏  举报