EPR类企业管理系统

在我们现有系统基础上或全新开发,提供定制服务
为您的企业高效快速实施ERP,WMS,MES,CRM管理系统
全面管控物料仓库、销售业务、采购业务、仓库业务
生产过程、质量检验、组织架构、业务报表


定制
QQ:460-3528

开发
QQ群:3360-90194

源码
微信:136-3650-3721

如何:访问主详细信息视图和嵌套列表视图环境

本主题说明如何使用控制器访问嵌套列表视图或主详细信息视图的环境(框架,控制器,动作,对象等)。

本文涵盖两种方法:

本主题使用“带有任务嵌套列表视图的联系详细信息视图”方案。您可以在MainDemo应用程序中找到相应的Contact和DemoTask业务类(%PUBLIC%\ Documents \ DevExpress Demos 19.2 \ Components \ eXpressApp Framework \ MainDemo)。

AccessMasterObject2

注意

XAF为集合属性创建嵌套的列表视图。这些属性通常用于持久对象之间的关系中

如何:从嵌套列表视图控制器访问主详细信息视图的环境

选择适合您的方案的最佳方法:

如果需要从DashboardViewItem或DetailPropertyEditor访问主视图,请使用“访问主详细视图的框架及其控制器”方法。有关示例,请参阅E4916文章。

访问主局部视图的框架及其控制器

这种方法需要两个Controller:第一个是嵌套的List View Controller。在下面的代码中,NestedListViewFrameController通过AssignMasterFrame方法接收父Frame。您可以使用此框架来自定义其Controllers和Actions。有关更多信息,请参见自定义控制器和动作。

注意

嵌套列表视图控制器无法访问父级详细视图框架,控制器和操作,除非详细视图的控制器将详细视图框架传递给嵌套的列表视图控制器。

public class NestedListViewFrameController : ViewController {
    private Frame masterFrame;
    public NestedListViewFrameController() {
        TargetViewType = ViewType.ListView;
        TargetViewNesting = Nesting.Nested;
    }
    public void AssignMasterFrame(Frame parentFrame) {
        masterFrame = parentFrame;
        // Use this Frame to get Controllers and Actions. 
    }
}

第二个是主“细节视图控制器”。下面的MasterDetailViewController获取详细视图框架,并将其传递给NestedListViewFrameController。使用ListPropertyEditor.FrameChanged事件订阅可确保存在嵌套的列表视图。

public class MasterDetailViewController : ViewController {
    private void PushFrameToNestedController(Frame frame) {
        foreach (Controller c in frame.Controllers) {
            if (c is NestedListViewFrameController) {
                ((NestedListViewFrameController)c).AssignMasterFrame(Frame);
            }
        }
    }
    private void lpe_FrameChanged(object sender, EventArgs e) {
        PushFrameToNestedController(((ListPropertyEditor)sender).Frame);
    }
    protected override void OnActivated() {
        base.OnActivated();
        foreach (ListPropertyEditor lpe in ((DetailView)View).GetItems<ListPropertyEditor>()) {
            if (lpe.Frame != null) {
                PushFrameToNestedController(lpe.Frame);
            }
            else {
                lpe.FrameChanged  = lpe_FrameChanged;
            }
        }
    }
    protected override void OnDeactivated() {
        foreach (ListPropertyEditor lpe in ((DetailView)View).GetItems<ListPropertyEditor>()) {
            lpe.FrameChanged -= new EventHandler<EventArgs>(lpe_FrameChanged);
        }
        base.OnDeactivated();
    }
    public MasterDetailViewController() {
        TargetViewType = ViewType.DetailView;
    }
}
提示

下载E1012示例,在示例应用程序中查看此方法。

访问主详细视图的当前对象(“视图项”方法)

下面的AccessParentDetailViewController是一个嵌套的列表视图控制器。该控制器采用CurrentObjectChanged事件更新主详细查看标题每次CurrentObject变化。

public class AccessParentDetailViewController : ViewController {
    private void UpdateDetailViewCaption() {
        if (Frame is NestedFrame) {
            if (View.CurrentObject != null) {
                ((NestedFrame)Frame).ViewItem.View.Caption = ((DemoTask)View.CurrentObject).Subject;
            }
        }
    }
    private void View_CurrentObjectChanged(object sender, EventArgs e) {
        UpdateDetailViewCaption();
    }
    protected override void OnActivated() {
        base.OnActivated();
        View.CurrentObjectChanged  = View_CurrentObjectChanged;
        UpdateDetailViewCaption();
    }
    protected override void OnDeactivated() {
        base.OnDeactivated();
        View.CurrentObjectChanged -= new EventHandler(View_CurrentObjectChanged);
    }
    public AccessParentDetailViewController() {
        TargetViewType = ViewType.ListView;
        TargetViewNesting = Nesting.Nested;
        TargetObjectType = typeof(DemoTask);
    }
}
提示

下载E3977示例,在示例应用程序中查看此方法。

访问主详细视图的当前对象(属性集合源方法)

下面的AccessMasterObjectController是一个嵌套的列表视图控制器。嵌套列表视图的CollectionSource类型为PropertyCollectionSource,因为列表视图表示一个collection属性。当主对象更改时,控制器处理MasterObjectChanged事件并处理当前的MasterObject

public class AccessMasterObjectController : ViewController<ListView> {
    private void UpdateMasterObject(object masterObject) {
        Contact MasterObject = (Contact)masterObject;
        // Use the master object as required.            
    }
    private void OnMasterObjectChanged(object sender, System.EventArgs e) {
        UpdateMasterObject(((PropertyCollectionSource)sender).MasterObject);
    }
    protected override void OnActivated() {
        base.OnActivated();
        PropertyCollectionSource collectionSource = View.CollectionSource as PropertyCollectionSource;
        if (collectionSource != null) {
            collectionSource.MasterObjectChanged  = OnMasterObjectChanged;
            if (collectionSource.MasterObject != null){
                UpdateMasterObject(collectionSource.MasterObject);
            }
        }
    }
    protected override void OnDeactivated() {
        PropertyCollectionSource collectionSource = View.CollectionSource as PropertyCollectionSource;
        if (collectionSource != null) {
            collectionSource.MasterObjectChanged -= OnMasterObjectChanged;
        }
        base.OnDeactivated();
    }
    public AccessMasterObjectController() {
        TargetViewNesting = Nesting.Nested;
        TargetObjectType = typeof(DemoTask);
    }
}
提示

下载E950示例,在示例应用程序中查看此方法。

如何:从详细视图控制器访问嵌套列表视图的环境

下面的AccessNestedListViewController详细信息视图控制器。该控制器处理的CurrentObjectChangedControlCreated事件来获得当前嵌套列表视图框架和目标。您可以在PerformLogicWithCurrentListViewObjectPerformLogicInNestedListViewController方法中处理它们,如“自定义控制器和动作”主题所述。

注意

您还可以使用此方法来自定义DashboardViewItemDetailPropertyEditor,因为这些视图项包含带有内部视图的框架。有关示例,请参阅E4916文章。

public class AccessNestedListViewController : ViewController {
    private void PerformLogicWithCurrentListViewObject(Object obj) {
        // Use the object in the nested List View as required.
    }
    private void PerformLogicInNestedListViewController(Frame nestedFrame) {
        // Use the nested Frame as required.
    }
    private void nestedListView_CurrentObjectChanged(object sender, EventArgs e) {
        PerformLogicWithCurrentListViewObject((DemoTask)((ListView)sender).CurrentObject);
    }
    private void listPropertyEditor_ControlCreated(object sender, EventArgs e) {
        ProcessListPropertyEditor((ListPropertyEditor)sender);
    }
    private void ProcessListPropertyEditor(ListPropertyEditor listPropertyEditor) {
        ListView nestedListView = listPropertyEditor.ListView;
        PerformLogicWithCurrentListViewObject(nestedListView.CurrentObject);
        PerformLogicInNestedListViewController(listPropertyEditor.Frame);
        nestedListView.CurrentObjectChanged  = nestedListView_CurrentObjectChanged;
    }
    protected override void OnActivated() {
        base.OnActivated();
        ListPropertyEditor listPropertyEditor = ((DetailView)View).FindItem("Tasks") as ListPropertyEditor;
        if (listPropertyEditor != null) {
            if (listPropertyEditor.Control != null) {
                ProcessListPropertyEditor(listPropertyEditor);
            }
            else {
                listPropertyEditor.ControlCreated  = listPropertyEditor_ControlCreated;
            }
        }
    }
    protected override void OnDeactivated() {
        ListPropertyEditor listPropertyEditor = ((DetailView)View).FindItem("Tasks") as ListPropertyEditor;
        if (listPropertyEditor != null) {
            listPropertyEditor.ControlCreated -= new EventHandler<EventArgs>(listPropertyEditor_ControlCreated);
        }
        base.OnDeactivated();
    }
    public AccessNestedListViewController() {
        TargetViewType = ViewType.DetailView;
        TargetObjectType = typeof(Contact);
    }
}
提示

下载E3977示例,在示例应用程序中查看此方法。

相关文章

转载保留此链接,注明出处