.NET 學習

.NET 學習生活感想... 万事成蹉跎..... 贵在坚持 及时整理自己做过和学过的东西

博客园 首页 新随笔 联系 订阅 管理

 

 

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 { getset; }
    }
    [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/

posted on 2011-01-03 14:40  Tonyyang  阅读(519)  评论(0编辑  收藏  举报
欢迎转载,转载请注明出处:http://www.cnblogs.com/Tonyyang/