I have a Report with Groups and in some specific Details I want display a Running Sum over all Details.
I place a Label, configure the Running Sum, configure the Visible Property with an Expression.
From the 2nd Group the Label (SumB5
) displays the wrong Value.
Actual Output:
CodeGroup A
1:10 SumA1:10
2:10 SumA2:20 SumB2:20
3:10 SumA3:30
Group B
4:10 SumA4:40
5:10 SumA5:50 SumB5:40
Expected Output:
CodeGroup A
1:10 SumA1:10
2:10 SumA2:20 SumB2:20
3:10 SumA3:30
Group B
4:10 SumA4:40
5:10 SumA5:50 SumB5:50
C#[TestClass]
public class UnitTest1
{
public class Item
{
public int ID { get; set; }
public string Group { get; set; }
public decimal Price { get; set; }
public int ShowRunningSum { get; set; }
}
[TestMethod]
public void TestMethod1()
{
var data = new[] {
new Item {ID = 1, Group="A", Price = 10},
new Item {ID = 2, Group="A", Price = 10, ShowRunningSum=1},
new Item {ID = 3, Group="A", Price = 10},
new Item {ID = 4, Group="B", Price = 10},
new Item {ID = 5, Group="B", Price = 10, ShowRunningSum=1},
};
var rpt = new XtraReport {
Bands = {
new GroupHeaderBand {
GroupFields = {new GroupField { FieldName = "Group" } },
Controls = {
new XRLabel{ExpressionBindings = {new ExpressionBinding(nameof(XRLabel.Text), "'Group ' + [Group]") }}
}
},
new DetailBand {
Controls = {
new XRLabel{ExpressionBindings = {new ExpressionBinding(nameof(XRLabel.Text), "[ID] + ':' + [Price]")}},
// Running Report
new XRLabel{
ExpressionBindings = {
new ExpressionBinding(nameof(XRLabel.Text), "'SumA' + [ID] + ':' + sumRunningSum([Price])")},
Summary = new XRSummary{Running = SummaryRunning.Report},
LeftF = 100},
new XRLabel{
ExpressionBindings = {
new ExpressionBinding(nameof(XRLabel.Text), "'SumB' + [ID] + ':' + sumRunningSum([Price])"),
new ExpressionBinding(nameof(XRLabel.Visible), "[ShowRunningSum] == 1")},
Summary = new XRSummary{Running = SummaryRunning.Report},
LeftF = 200},
}
}
},
DataSource = data
};
string reportText = ReportToText(rpt);
Console.WriteLine(reportText); // <== generates the output above
Assert.IsTrue(reportText.Contains("SumB2:20"));
Assert.IsTrue(reportText.Contains("SumB5:50")); // <== Fails!
}
private static string ReportToText(XtraReport report)
{
using (var ms = new MemoryStream())
{
report.ExportToText(ms);
ms.Position = 0;
using (var sr = new StreamReader(ms))
{
return sr.ReadToEnd();
}
}
}
}