BusinessProcessDeltaOf Method
Returns The delta between the value of
expression before the
EnterRow event, and the current value of
expressionNamespace: Firefly.BoxAssembly: Firefly.Box (in Firefly.Box.dll) Version: debug-master-v:33791
public Number DeltaOf(
Func<Number> expression
)
Public Function DeltaOf (
expression As Func(Of Number)
) As Number
member DeltaOf :
expression : Func<Number> -> Number
- expression FuncNumber
-
NumberThe method returns The delta between the value of
expression before the
EnterRow event, and the current value of
expression Useful for maintaining a grand total in a form
How to use DeltaOf to maintain a grand total
This example is based on test data. The code for the entities included in this test data can be found in the documentation of
EntityThis example uses automatic tools to generate parts of the user interface. Those tools can be found in the example of the documentation of
Formusing Firefly.Box;
using Firefly.Box.Data;
using Firefly.Box.UI;
namespace TestFirefly.Box.Documentation
{
public class JobsTotal
{
public void ShowJobs()
{
var jobs = new Pubs.Jobs();
jobs.InitializeWithTestData();
var totalMinLevel = new NumberColumn();
var countJobs = new NumberColumn();
//Calculate the total before running the task
var bp = new BusinessProcess { From = jobs };
bp.ForEachRow(() =>
{
totalMinLevel.Value += jobs.MinLevel;
countJobs.Value++;
});
//Create the total textbox
var totalTextBox = new TextBox
{
Data = totalMinLevel,
AllowFocus = false
};
//Position the textbox below the grid
totalTextBox.ResizeToFit(10);
//Create a label
var totalLabel = new Label
{
Text = "Total Min Level"
};
totalLabel.ResizeToFitContent();
var countTextBox = new TextBox
{
Data = countJobs,
AllowFocus = false
};
countTextBox.ResizeToFit(6);
var countLabel = new Label { Text = "Number of jobs" };
countLabel.ResizeToFitContent();
//Create the UIController
var uic = new UIController
{
From = jobs,
View = UITools.GenerateFormWithGridFor(
"DeltaOf demo",
"Change the value of Min Level, and leave the row to see the affect on the totals.\n" +
"Try also deleting rows (using F3) and creating new ones."
, jobs.Id
, jobs.Description
, jobs.MinLevel)
};
UITools.AddControlsToForm(uic.View, countLabel, countTextBox, totalLabel, totalTextBox);
var insertB = new Button { Text = "Insert New Row", Width = 150 };
insertB.Click += (sender, e) => e.Raise(Command.InsertRow);
var deleteB = new Button { Text = "Delete Row", Width = 100 };
deleteB.Click += (sender, e) => e.Raise(Command.DeleteRow);
UITools.AddControlsToForm(uic.View, insertB, deleteB);
//Add all the jobs columns to the Columns Collection
uic.AddAllColumns();
//Add the total columns to the columns collection
uic.Columns.Add(totalMinLevel, countJobs);
uic.SavingRow += ( b) => //When the row is left, update the total with the delta in the MinLevel
{
totalMinLevel.AddDeltaOf(() => jobs.MinLevel);
countJobs.AddDeltaOf(() => 1);
};
uic.Run();
}
}
}