EPR类企业管理系统

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


定制
QQ:460-3528

开发
QQ群:3360-90194

源码
微信:136-3650-3721

如何:扩展应用程序模型

为了演示如何扩展应用程序模型,本主题详细介绍如何显示列表视图的组页脚。一个IsGroupFooterVisible属性将被添加到该视图| <ListView>节点。当ListView设置为true时,特殊的Controller将启用组页脚。要为不同的列指定摘要类型,将GroupFooterSummaryType属性添加到ListView | | 节点。有关扩展应用程序模型的一般信息,请参阅在代码中扩展和自定义应用程序模型 帮助主题。

注意

移动应用程序不支持组页脚。但是,您可以实现本主题中描述的方法,以将应用程序模型扩展用于其他目的。

HowToExdendApplicationModel

提示

可在http://www.devexpress.com/example=E213的DevExpress代码示例数据库中找到完整的示例项目。

  • 实现暴露IsGroupFooterVisibleGroupFooterSummaryType属性的接口。

    using DevExpress.Data;
    //...
    public interface IModelListViewExtender {
        bool IsGroupFooterVisible { get; set; }
    }
    public interface IModelColumnExtender {
        [DefaultValue(SummaryItemType.None)]
        SummaryItemType GroupFooterSummaryType { get; set; }
    }
    
  • 重写基本Module的ModuleBase.ExtendModelInterfaces方法,以使用声明的接口扩展应用程序模型。

    using DevExpress.ExpressApp.Model;
    // ...
    public sealed partial class ExtendModelModule : ModuleBase {
        // ...
        public override void ExtendModelInterfaces(ModelInterfaceExtenders extenders) {
            base.ExtendModelInterfaces(extenders);
            extenders.Add<IModelListView, IModelListViewExtender>();
            extenders.Add<IModelColumn, IModelColumnExtender>();
        }
    }
    
  • 在Windows窗体模块中创建WinGroupFooterViewController ViewController。从ViewController <ListView>类型继承它,因为必须仅在列表视图中激活此Controller。
  • 如果将当前列表视图的IsGroupFooterVisible属性设置为true,则重写受保护的OnViewControlsCreated方法以显示组页脚。此外,激活Controller后,处理View.ModelSaved事件,以在当前列表视图关闭时将不同列的组页脚摘要类型保存到应用程序模型中。

    using System;
    using System.ComponentModel;
    using DevExpress.Data;
    using DevExpress.ExpressApp;
    using DevExpress.ExpressApp.Model;
    using DevExpress.ExpressApp.Win.Editors;
    using DevExpress.XtraGrid.Views.Grid;
    using DevExpress.XtraGrid.Columns;
    //...
    public class WinGroupFooterViewController : ViewController<ListView> {
        private void View_ModelSaved(object sender, EventArgs e) {
            IModelListViewExtender modelListView = View.Model as IModelListViewExtender;
            if(modelListView != null && modelListView.IsGroupFooterVisible) {
                GridListEditor gridListEditor = View.Editor as GridListEditor;
                if(gridListEditor != null) {
                    GridView gridView = gridListEditor.GridView;
                    for(int i = 0; i < gridView.GroupSummary.Count; i  ) {
                        IModelColumnExtender modelColumn = View.Model.Columns[
                            gridView.GroupSummary[i].FieldName] as IModelColumnExtender;
                        if(modelColumn != null) {
                            modelColumn.GroupFooterSummaryType = gridView.GroupSummary[i].SummaryType;
                        }
                    }
                }
            }
        }
        protected override void OnViewControlsCreated() {
            base.OnViewControlsCreated();
            IModelListViewExtender modelListView = View.Model as IModelListViewExtender;
            if(modelListView != null && modelListView.IsGroupFooterVisible) {
                GridListEditor gridListEditor = View.Editor as GridListEditor;
                if(gridListEditor != null) {
                    GridView gridView = gridListEditor.GridView;
                    gridView.GroupFooterShowMode = GroupFooterShowMode.VisibleAlways;
                    foreach(IModelColumn modelColumn in View.Model.Columns) {
                        IModelColumnExtender modelColumnExtender = modelColumn as IModelColumnExtender;
                        if(modelColumnExtender != null && 
                            modelColumnExtender.GroupFooterSummaryType != SummaryItemType.None) {
                            GridColumn gridColumn = gridView.Columns[
                                modelColumn.ModelMember.MemberInfo.BindingName];
                            gridView.GroupSummary.Add(modelColumnExtender.GroupFooterSummaryType, 
                                modelColumn.Id, gridColumn);
                        }
                    }
                }
            }
        }
        protected override void OnActivated() {
            base.OnActivated();
            View.ModelSaved  = View_ModelSaved;
        }
        protected override void OnDeactivated() {
            View.ModelSaved -= View_ModelSaved;
            base.OnDeactivated();
        }
    }
    
  • 在ASP.NET Web模块中创建一个WebGroupFooterViewController ViewController。从ViewController <ListView>类型继承它,因为必须仅在列表视图中激活此Controller。
  • 如果将当前列表视图的IsGroupFooterVisible属性设置为true,则重写受保护的OnViewControlsCreated方法以显示组页脚。无需处理ModelSaved事件,因为最终用户无法为ASP.NET UI中的不同列自定义摘要类型。

    using System;
    using DevExpress.Data;
    using DevExpress.ExpressApp;
    using DevExpress.ExpressApp.Model;
    using DevExpress.ExpressApp.Web.Editors.ASPx;
    using DevExpress.Web.ASPxGridView;
    //...
    public class WebGroupFooterViewController : ViewController<ListView> {
        protected override void OnViewControlsCreated() {
            base.OnViewControlsCreated();
            IModelListViewExtender modelListView = View.Model as IModelListViewExtender;
            if(modelListView != null && modelListView.IsGroupFooterVisible) {
                ASPxGridListEditor gridListEditor = View.Editor as ASPxGridListEditor;
                if(gridListEditor != null) {
                    ASPxGridView gridView = gridListEditor.Grid;
                    gridView.Settings.ShowGroupFooter = GridViewGroupFooterMode.VisibleAlways;
                    foreach(IModelColumn modelColumn in View.Model.Columns) {
                        IModelColumnExtender modelColumnExtender = modelColumn as IModelColumnExtender;
                        if(modelColumnExtender != null && 
                            modelColumnExtender.GroupFooterSummaryType != SummaryItemType.None) {
                            string fieldName = modelColumn.ModelMember.MemberInfo.BindingName;
                            ASPxSummaryItem summaryItem = null;
                            foreach(ASPxSummaryItem currentItem in gridView.GroupSummary) {
                                if(currentItem.FieldName == fieldName) {
                                    currentItem.ShowInGroupFooterColumn = modelColumn.Caption;
                                    summaryItem = currentItem;
                                    break;
                                }
                            }
                            if(summaryItem == null) {
                                summaryItem = new ASPxSummaryItem(
                                    fieldName, modelColumnExtender.GroupFooterSummaryType);
                                summaryItem.ShowInGroupFooterColumn = modelColumn.Caption;
                                gridView.GroupSummary.Add(summaryItem);
                            }
                        }
                    }
                }
            }
        }
    }
    
  • 重建您的解决方案,并为基本模块调用模型编辑器。将ListView节点的IsGroupPanelVisible属性设置为true,以便能够对List View的列进行分组。将新添加的IsGroupFooterVisible属性设置为true。为ListView节点的Column节点指定摘要类型。
  • 运行应用程序。使用组面板显示列表视图,然后按列对列表视图进行分组。将显示具有指定摘要类型的页脚。
相关文章

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