UIControllerSaveRowAndDo Method

Saves the current row to the DB and performs the specified action after the row was saved successfully.

Definition

Namespace: Firefly.Box
Assembly: Firefly.Box (in Firefly.Box.dll) Version: debug-master-v:33791
C#
public void SaveRowAndDo(
	Action<UIOptions> action
)

Parameters

action  ActionUIOptions
The action to be performed after the row is left

Remarks

This method is intended to perform operations like print the current row etc... while making sure that any changes made by the used are saved to DB and are verified.
Also this method is used to reload the data of the UIController or navigate to deferent rows, both are done using the UIOptions interface.

Example

using leave row to access changed data from the current row
This example is based on test data. The code for the entities included in this test data can be found in the documentation of Entity
This example uses automatic tools to generate parts of the user interface. Those tools can be found in the example of the documentation of Form
C#
using System.Drawing;
using System.Windows.Forms;
using Firefly.Box;

namespace TestFirefly.Box.Documentation
{
    public class SaveRowAndDoDemo
    {
        public void UsingSaveRowAndDoToVerifySaveToDB()
        {
            var jobs = new Pubs.Jobs();
            jobs.InitializeWithTestData();

            var uic = new UIController
            {
                From = jobs,
                View = UITools.GenerateFormWithGridFor("Jobs",
                                                       "This demo shows the advantage of using the SaveRowAndDo method.\n" +
                                                       "If you change the value of MinLevel in the current row, and click the \"Show Total\" button.\n" +
                                                       "You will see that the total doesn't reflect the changes in the current row.\n" +
                                                       "But if you click on the \"Save Row And Show Total\" you will see that the total does reflect the \n" +
                                                       "changes to the current row.",
                                                       jobs.Id,
                                                       jobs.Description, 
                                                       jobs.MinLevel)
            };

            var showTotalButton = new Button
            {
                Text = "Show Total"
            };
            showTotalButton.Click += (a, b) => ShowTotalMinLevel();

            var saveRowAndShowTotal = new Button
            {
                Text = "Save Row And Show Total",
                Width = 200
            };
            saveRowAndShowTotal.Click += (a, b) => uic.SaveRowAndDo(o => ShowTotalMinLevel());

            UITools.AddControlsToForm(uic.View, showTotalButton, saveRowAndShowTotal);

            uic.Run();
        }

        void ShowTotalMinLevel()
        {
            var jobs = new Pubs.Jobs();
            int totalMinLevel = 0;

            new BusinessProcess { From = jobs }
                .ForEachRow(() => totalMinLevel += jobs.MinLevel);
            MessageBox.Show("The Total Min Level is " + totalMinLevel);
        }
    }
}

See Also