[This is preliminary documentation and is subject to change.]

Occurs whenever the user leaves a row, and that row is about to be saved to the Database.

Namespace:  Firefly.Box
Assembly:  Firefly.Box (in Firefly.Box.dll) Version: 3.4.23.6473 (3.4.23.6473)

Syntax

C#
public event CancelEventHandler SavingRow
Visual Basic (Declaration)
Public Event SavingRow As CancelEventHandler
Visual C++
public:
 event CancelEventHandler^ SavingRow {
	void add (CancelEventHandler^ value);
	void remove (CancelEventHandler^ value);
}

Remarks

The SavingRow Process

When the user leaves a row, and that row needs to be saved the UIController will perform the following steps: InputValidation for all the controls on the form according to the tab order, starting from the currently focused control. The row is saved to the database.Notice that The LeaveRow event is being raised as well, just before the SavingRow event occures.
The will happen, when the user leaves a row, in one of the following scenarios: If none of these scenarios occurred the changes to the row will not be saved to the database. Also if the row is a new row, and none of the mentioned scenarios occurred, the row will not be inserted to the database.

Examples

UIController event flow
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
CopyC#
using Firefly.Box;
using System.Windows.Forms;

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

            var uic = new UIController
            {
                From = jobs,
                View = UITools.GenerateFormWithGridFor("UIController events",
                                                       "notice that the SavingRow MessageBox only happens for rows that were changed" +
                                                       "\nAlso pay attention to the fact that the \"After The Run\" message " +
                                                       "will come only after the task ends",
                                                       jobs.Id,
                                                       jobs.Description)
            };
            uic.Load += () => MessageBox.Show("Load");
            uic.Start += () => MessageBox.Show("Start");
            uic.EnterRow += () => MessageBox.Show("EnterRow");
            uic.LeaveRow += () => MessageBox.Show("LeaveRow");
            uic.SavingRow += (b) => MessageBox.Show("SavingRow");

            uic.End += () => MessageBox.Show("End");

            MessageBox.Show("Before The Run");
            uic.Run();
            MessageBox.Show("After The Run");
        }
    }
}

Examples

leave 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
CopyC#
using System.Windows.Forms;
using Firefly.Box;

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

            var uic = new UIController
                          {
                              From = jobs,
                              View = UITools.GenerateFormWithGridFor("SavingRow Demo",
                                                                     "Notice that the SavingRow event only happens for rows\n" +
                                                                     "That were, or if the ForceSaveRow checkbox is set.",
                                                       jobs.Id,
                                                       jobs.Description)
                          };

            var forceLeaveRowCheckBox = new CheckBox
                                            {
                                                Text = "Force Leave Row",
                                                Width = 120,
                                                Checked = uic.ForceSaveRow
                                            };
            forceLeaveRowCheckBox.CheckedChanged += (a, b) => uic.ForceSaveRow = forceLeaveRowCheckBox.Checked;

            UITools.AddControlsToForm(uic.View, forceLeaveRowCheckBox);

            uic.SavingRow += ( b) => MessageBox.Show("Leave Row Happened");

            uic.Run();
        }
    }
}

Examples

and
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
CopyC#
using ENV;
using Firefly.Box;
using Firefly.Box.UI;

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

            var uic = new UIController()
            {
                From = jobs,
                View = UITools.GenerateFormWithGridFor(
                "RowChanged and SavingRow Demo",
                "This example demonstrates the deferent scenarios regarding the RowChanged property.\n" +
                "\nA. Initial State:\n" +
                "        Click the \"Check If Row Was Changed\" button and you'll see that the row was NOT changed.\n" +
                "\nB. User Changed a Value:\n" +
                "   1. Change the job's description.\n" +
                "   2. Click the \"Check If Row Was Changed\" button and you'll see that the row was changed.\n" +
                "   3. Click the \"Undo Changes In Row\" and you'll see that the change was reverted.\n" +
                "   4. Click the \"Check If Row Was Changed\" button and you'll see that the row was NOT changed.\n" +
                "\nC. Value Changes Done In Code:\n" +
                "   1. Click the \"Add 1 to Min Level\" you'll see that the value of Min Level was changed.\n" +
                "   2. Click the \"Check If Row Was Changed\" button and you'll see that the row was changed.\n" +
                "   3. Click the \"Undo Changes In Row\" and you'll see that the change was reverted.\n" +
                "   4. Click the \"Check If Row Was Changed\" button and you'll see that the row was NOT changed.\n" +
                "\nD. Changes to a column set to \"OnChangeMarkRowAsChanged = false\".\n"+
                "        A change to a value of such a column, doesn't set the RowChanged property.\n" +
                "   1. Change the job's Max Level Value.\n" +
                "   2. Click the \"Check If Row Was Changed\" button and you'll see that the row was NOT changed.\n" +
                "   3. Leave the row and reenter it, you'll see that the value of max level, returned to it's original one.\n" +
                "      Because the RowChanged property was not set, the SavingRow event didn't happen, and the\n" +
                "      changes were not saved to the database.\n" +
                "   4. Click the \"Add 1 to Max Level\" you'll see that the value of Max Level was changed.\n" +
                "   5. Click the \"Check If Row Was Changed\" button and you'll see that the row was NOT changed.\n" +
                "\nE. Setting a value using the \"SetValueWithoutMarkingRowAsChanged\" method:\n" +
                "   1. Click the \"Add 1 to Min Level Without Marking Row As Changed\".\n" +
                "   2. Click the \"Check If Row Was Changed\" button and you'll see that the row was NOT changed.\n\n"+
                "Thank you for your patience. ",
                                         jobs.Id,
                                         jobs.Description,
                                         jobs.MinLevel,
                                         jobs.MaxLevel)
            };

            jobs.MaxLevel.OnChangeMarkRowAsChanged = false;


            var btnSetMinLevel = new Button
            {
                Text = "Add 1 to Min Level",
                Width = 150
            };
            btnSetMinLevel.Click += (a, b) => jobs.MinLevel.Value++;

            var btnSetMinLevelWithoutMarkingRowAsChanged = new Button
            {
                Text =
                    "Add 1 to Min Level Without Marking Row As Changed",
                Width = 305
            };
        //    btnSetMinLevelWithoutMarkingRowAsChanged.Click +=
        //        (a, b) => jobs.MinLevel.SetValueWithoutMarkingRowAsChanged(jobs.MinLevel + 1);

            var btnSetMaxLevel = new Button
            {
                Text = "Add 1 To Max Level",
                Width = 150
            };
            btnSetMaxLevel.Click += (a, b) => jobs.MaxLevel.Value++;

            var btnCheckRowChanged = new Button
            {
                Text = "Check If Row Was Changed",
                Width = 150
            };
            btnCheckRowChanged.Click += (a, b) =>
                                        System.Windows.Forms.MessageBox.Show("Row was " +
                                                                             (uic.RowChanged ? "Changed" : "NOT Changed"));

            var btnUndoChangesInRow = new Button
            {
                Text = "Undo Changes In Row",
                Width = 150
            };
            btnUndoChangesInRow.Click += (a, b) => uic.Raise(Command.UndoChangesInRow);

            uic.SavingRow += ( b) => System.Windows.Forms.MessageBox.Show("Changes are being saved to the database");

            UITools.AddControlsToForm(uic.View, btnCheckRowChanged, btnUndoChangesInRow);
            UITools.AddControlsToForm(uic.View, btnSetMinLevel, btnSetMaxLevel);
            UITools.AddControlsToForm(uic.View, btnSetMinLevelWithoutMarkingRowAsChanged);

            uic.Run();
        }
    }
}

See Also