-
//this is the view controller I am using
using System;
using System.Linq;
using System.Collections.Generic;
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Win.SystemModule;
namespace TimeAndBillingXAF.Module.Win.Controllers
{
// For more typical usage scenarios, be sure to check out http://documentation.devexpress.com/#Xaf/clsDevExpressExpressAppViewControllertopic.
public partial class vcSchedule : ViewController
{public vcSchedule()
{
InitializeComponent();
RegisterActions(components);
// Target required Views (via the TargetXXX properties) and create their Actions.
}
private WinModificationsController worker;protected override void OnActivated()
{
base.OnActivated();
ObjectSpace.ObjectChanged += ObjectSpace_ObjectChanged;
//if (ObjectSpace.IsNewObject(View.CurrentObject))
//{
worker = Frame.GetController<WinModificationsController>();worker.ModificationsHandlingMode = DevExpress.ExpressApp.SystemModule.ModificationsHandlingMode.AutoCommit;
//}
}
protected override void OnDeactivated()
{
ObjectSpace.ObjectChanged -= ObjectSpace_ObjectChanged;
worker = null;
base.OnDeactivated();
}
private void ObjectSpace_ObjectChanged(object sender, ObjectChangedEventArgs e)
{
if (worker != null)
{
worker.ModificationsHandlingMode = DevExpress.ExpressApp.SystemModule.ModificationsHandlingMode.AutoCommit;
}
}
protected override void OnViewControlsCreated()
{
base.OnViewControlsCreated();
// Access and customize the target View control.
}}
}
Dennis, You are a genuine hero!
I combined your advice from both of your posts and now have a controller that allows a user to auto save the record before navigating to the detail view.
Much Thanks for the help!
The code is as follows:
using System;using System.Linq;using System.Collections.Generic;using DevExpress.ExpressApp;using DevExpress.ExpressApp.SystemModule;
namespace TBX.Module.Win.Controllers{ public partial class vcSchedule : ViewController {
public vcSchedule() { InitializeComponent(); RegisterActions(components); } private ListViewProcessCurrentObjectController processCurrentObjectController;
protected override void OnActivated() { base.OnActivated(); processCurrentObjectController = Frame.GetController<ListViewProcessCurrentObjectController>(); if (processCurrentObjectController != null) { processCurrentObjectController.CustomProcessSelectedItem += processCurrentObjectController_CustomProcessSelectedItem; }
}
private void processCurrentObjectController_CustomProcessSelectedItem(object sender, CustomProcessListViewSelectedItemEventArgs e) { e.Handled = true; Open.DoExecute(); }
protected override void OnViewControlsCreated() { base.OnViewControlsCreated(); // Access and customize the target View control. }
private void Open_Execute(object sender, DevExpress.ExpressApp.Actions.SimpleActionExecuteEventArgs e) { View.ObjectSpace.CommitChanges(); ListViewProcessCurrentObjectController.ShowObject(e.CurrentObject, e.ShowViewParameters, Application, Frame, View); }
}}
-
using System;
using System.Linq;
using System.Collections.Generic;
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.SystemModule;
namespace TBX.Module.Win.Controllers
{public partial class vcSchedule : ViewController
{
public vcSchedule()
{
InitializeComponent();
RegisterActions(components);
}private ListViewProcessCurrentObjectController processCurrentObjectController;
protected override void OnActivated()
{
base.OnActivated();
processCurrentObjectController =
Frame.GetController<ListViewProcessCurrentObjectController>();
if (processCurrentObjectController != null)
{
processCurrentObjectController.CustomProcessSelectedItem += processCurrentObjectController_CustomProcessSelectedItem;
}
}
private void processCurrentObjectController_CustomProcessSelectedItem(object sender, CustomProcessListViewSelectedItemEventArgs e)
{
e.Handled = true;
Open.DoExecute();}
protected override void OnViewControlsCreated()
{
base.OnViewControlsCreated();
// Access and customize the target View control.
}
private void Open_Execute(object sender, DevExpress.ExpressApp.Actions.SimpleActionExecuteEventArgs e)
{
View.ObjectSpace.CommitChanges();
ListViewProcessCurrentObjectController.ShowObject(e.CurrentObject, e.ShowViewParameters, Application, Frame, View);
}}
}I am glad to hear of your progress, Robert.
Hello Robert,
It is strange that you are trying to change the ModificationsHandlingMode option in the ObjectChanged event handler. It is sufficient to set it only once when еру Controller is activated.
If you need to commit the changes, manually call the View.ObjectSpace.CommitChanges method:
[C#] private void ObjectSpace_ObjectChanged(object sender, ObjectChangedEventArgs e)
{
if (worker != null)
{
View.ObjectSpace.CommitChanges();
//worker.ModificationsHandlingMode = DevExpress.ExpressApp.SystemModule.ModificationsHandlingMode.AutoCommit;
}
}
We will also consider improving the current behavior to avoid execution of the default Action for a new and unsaved object. For instance, here a confirmation message to save the new record can be displayed to the user.
-
Dennis,
Thanks for the response.
I may be a little closer but am still not getting the desired results.
Once I implemented the View.ObjectSpace.CommitChanges(); to the ObjectChanges Event handler it looks like the code is attempting to commit changes however when I add of move something to the schedule control the control is not given the chance to update the end date before the commitchanges method is fired. What is happening now is that a validation error is now popping up anytime changes are made on the schedule control indicating that the start date is less than the end date.
Is there anything else that I can try?
Thanks in advance.Thanks for your update.
Committing data causes data validation as expected. If you do not want automatic data commit, then you can implement different logic as your business requirements dictate. My goal was to just show that it is required to commit data to open a newly created record.
For instance, you can show a confirmation message to a user when a new record is being shown. To do this, handle the CustomProcessSelectedItem event of the ListViewProcessCurrentObjectController.