using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Actions;
using DevExpress.Persistent.Base;
using DevExpress.ExpressApp.Model;
using DevExpress.ExpressApp.Win.SystemModule;
namespace XafExtendTest.Module.SystemModule
{
public interface IModelClassAutoCommitListView : IModelNode
{
[Category("MyCustomProperty")]
[Description("Control if change on editable listview will be autocommited")]
bool AutoCommitListview { get; set; }
}
[ModelInterfaceImplementor(typeof(IModelClassAutoCommitListView),"ModelClass")]
public interface IModelListViewAutoCommitListView : IModelClassAutoCommitListView
{
}
public class AutoCommitListViewController : ViewController<ListView>,IModelExtender
{
protected override void OnViewControllersActivated()
{
base.OnActivated();
var winDetailViewController = Frame.GetController<WinDetailViewController>();
if (winDetailViewController != null && ((IModelListViewAutoCommitListView)View.Model).AutoCommitListview)
{
winDetailViewController.AutoCommitListView = true;
View.QueryCanChangeCurrentObject += View_QueryCanChangeCurrentObject;
}
}
void View_QueryCanChangeCurrentObject(object sender, CancelEventArgs e)
{
if(Frame.GetController<WinDetailViewController>().SuppressConfirmation)
ObjectSpace.CommitChanges();
}
protected override void OnDeactivated()
{
base.OnDeactivated();
var winDetailViewController = Frame.GetController<WinDetailViewController>();
if (winDetailViewController != null && ((IModelListViewAutoCommitListView)View.Model).AutoCommitListview)
{
winDetailViewController.AutoCommitListView = true;
View.QueryCanChangeCurrentObject -= View_QueryCanChangeCurrentObject;
}
}
void IModelExtender.ExtendModelInterfaces(ModelInterfaceExtenders extenders)
{
extenders.Add<IModelClass, IModelClassAutoCommitListView>();
extenders.Add<IModelListView, IModelListViewAutoCommitListView>();
}
}
}
using System.ComponentModel;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Actions;
using DevExpress.Persistent.Base;
using DevExpress.ExpressApp.Model;
using DevExpress.ExpressApp.Win.SystemModule;
namespace XafExtendTest.Module.SystemModule
{
public interface IModelClassAutoCommitListView : IModelNode
{
[Category("MyCustomProperty")]
[Description("Control if change on editable listview will be autocommited")]
bool AutoCommitListview { get; set; }
}
[ModelInterfaceImplementor(typeof(IModelClassAutoCommitListView),"ModelClass")]
public interface IModelListViewAutoCommitListView : IModelClassAutoCommitListView
{
}
public class AutoCommitListViewController : ViewController<ListView>,IModelExtender
{
protected override void OnViewControllersActivated()
{
base.OnActivated();
var winDetailViewController = Frame.GetController<WinDetailViewController>();
if (winDetailViewController != null && ((IModelListViewAutoCommitListView)View.Model).AutoCommitListview)
{
winDetailViewController.AutoCommitListView = true;
View.QueryCanChangeCurrentObject += View_QueryCanChangeCurrentObject;
}
}
void View_QueryCanChangeCurrentObject(object sender, CancelEventArgs e)
{
if(Frame.GetController<WinDetailViewController>().SuppressConfirmation)
ObjectSpace.CommitChanges();
}
protected override void OnDeactivated()
{
base.OnDeactivated();
var winDetailViewController = Frame.GetController<WinDetailViewController>();
if (winDetailViewController != null && ((IModelListViewAutoCommitListView)View.Model).AutoCommitListview)
{
winDetailViewController.AutoCommitListView = true;
View.QueryCanChangeCurrentObject -= View_QueryCanChangeCurrentObject;
}
}
void IModelExtender.ExtendModelInterfaces(ModelInterfaceExtenders extenders)
{
extenders.Add<IModelClass, IModelClassAutoCommitListView>();
extenders.Add<IModelListView, IModelListViewAutoCommitListView>();
}
}
}
欢迎转载,转载请注明出处:http://www.cnblogs.com/Tonyyang/
欢迎转载,转载请注明出处:http://www.cnblogs.com/Tonyyang/