• How to: Extend the Application Model 如何:扩展应用程序模型


    To demonstrate how to extend the Application Model, this topic details how to display a Group Footer for List Views. An IsGroupFooterVisible property will be added to the to the Views | <ListView> node. When set to true for a ListView, a special Controller will enable the group footer. To specify a summary type for different columns, a GroupFooterSummaryType property will be added to the ListView | Columns | Column node. For general information on extending the Application Model, refer to the Extend and Customize the Application Model in Code help topic.

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

    Note 注意
    Mobile applications do not support the Group Footer. However, you can implement the approach described in this topic to extend your Application Model for other purposes.
    移动应用程序不支持组页脚。但是,您可以实现本主题中描述的方法,以扩展应用程序模型以用于其他目的。

    HowToExdendApplicationModel

    Tip 提示
    A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=E213
    完整的示例项目可在 DevExpress 代码示例数据库中找到,http://www.devexpress.com/example=E213

    .

    • Implement the interfaces exposing the IsGroupFooterVisible and GroupFooterSummaryType properties.

    • 实现公开 IsGroupFooter 可见和组FooterSummaryType属性的接口。

      using DevExpress.Data;
      //...
      public interface IModelListViewExtender {
          bool IsGroupFooterVisible { get; set; }
      }
      public interface IModelColumnExtender {
          [DefaultValue(SummaryItemType.None)]
          SummaryItemType GroupFooterSummaryType { get; set; }
      }
    • Override the ModuleBase.ExtendModelInterfaces method of your base Module to extend the Application Model with declared interfaces.

    • 覆盖基本模块的模块Base.ExtendModelInterface方法,以扩展具有声明接口的应用程序模型。

      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>();
          }
      }
    • Create a WinGroupFooterViewControllerViewController in the Windows Forms Module. Inherit it from the ViewController<ListView> type, since this Controller must be activated in List Views only.
    • Override the protected OnViewControlsCreated method to display the group footer, if the IsGroupFooterVisible property is set to true for the current List View. Additionally, when the Controller is activated, handle the View.ModelSaved event to save the group footer summary type for different columns into Application Model, when the current List View is closing.

    • 在 Windows 窗体模块中创建 WinGroupFooterView 控制器视图控制器。从"视图控制器<ListView>类型继承它,因为此控制器必须仅在列表视图中激活。
    • 如果当前列表视图的 IsGroupFooterVisible 属性设置为 true,则覆盖受保护的 OnViewControls创建方法以显示组页脚。此外,当控制器激活时,在当前列表视图关闭时,处理 View.ModelSave 事件,以将不同列的组页脚摘要类型保存到应用程序模型中。

      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();
          }
      }
    • Create a WebGroupFooterViewController ViewController in the ASP.NET Web Module. Inherit it from the ViewController<ListView> type, since this Controller must be activated in List Views only.
    • Override the protected OnViewControlsCreated method to display the group footer, if the IsGroupFooterVisible property is set to true for the current List View. There is no need to handle the ModelSaved event since end-users cannot customize summary types for different columns in the ASP.NET UI.

    • 在ASP.NET Web 模块中创建 Web 组FooterView 控制器视图控制器。从"视图控制器<ListView>类型继承它,因为此控制器必须仅在列表视图中激活。
    • 如果当前列表视图的 IsGroupFooterVisible 属性设置为 true,则覆盖受保护的 OnViewControls创建方法以显示组页脚。无需处理 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);
                              }
                          }
                      }
                  }
              }
          }
      }
    • Rebuild you solution and invoke the Model Editor for the base Module. Set a ListView node's IsGroupPanelVisible property to true to be able to group the List View's columns. Set the newly added IsGroupFooterVisible property to true. Specify summary types for the ListView node's Column nodes.
    • Run the application. Display the List View with a group panel and group the List View by a column. The footer with the specified summary types will be displayed.
    • 重新生成解决方案并调用基本模块的模型编辑器。将 ListView 节点的 IsGroupPanel 可见属性设置为 true,以便能够对列表视图的列进行分组。将新添加的 IsGroupFooter 可见属性设置为 true。为 ListView 节点的列节点指定摘要类型。
    • 运行应用程序。使用组面板显示列表视图,然后按列对列表视图进行分组。将显示具有指定摘要类型的页脚。
  • 相关阅读:
    用GDB调试程序(一)
    Linux编程基础——GDB(设置断点)
    滴滴快车奖励政策,高峰奖励,翻倍奖励,按成交率,指派单数分级(10月12日~10月18日)
    北京Uber优步司机奖励政策(10月19日~10月25日)
    借贷宝人脸识别无需绑卡,需合作者共同冲刺
    王璐首次详解借贷宝诞生历程 直面创业从0到1
    创造信用收入 借贷宝颠覆创新普惠金融
    php中,如何将编译后的代码,反编译回去。
    chrome调试ajax
    提示text还能输入多少字节
  • 原文地址:https://www.cnblogs.com/foreachlife/p/How-to-Extend-the-Application-Model.html
Copyright © 2020-2023  润新知