• Add a Simple Action添加简单按钮


    In this lesson, you will learn how to create a Simple Action. For this purpose, a new View Controller will be implemented and a new Simple Action will be added to it. This Action will clear all Tracked Tasks of a specific Contact.

    在本课中,您将学习如何创建简单按钮。为此,将实施一个新的视图控制器,并将向其添加新的简单操作。此操作将清除特定联系人的所有跟踪任务。

    Note 注意

    Before proceeding, take a moment to review the following lessons.

    • Inherit from the Business Class Library Class (XPO/EF)
    • Implement Custom Business Classes and Reference Properties (XPO/EF)
    • Set a Many-to-Many Relationship (XPO/EF)

    在继续之前,请花点时间复习以下课程。

    • 从商务舱库类 (XPO/EF) 继承
    • 实现自定义业务类和参考属性 (XPO/EF)
    • 设置多对多关系 (XPO/EF)

     

    The View Controller is a descendant of the ViewController class. To add a View Controller that provides a Simple Action, follow the steps described below.

    视图控制器是视图控制器类的后代。要添加提供简单操作的视图控制器,请按照以下步骤操作。

    • The XAF Controllers | View Controller Visual Studio template makes it easier to add a View Controller to your application. In the Solution Explorer, right-click the Controllers folder in the MySolution.Module project, and choose Add DevExpress Item | New Item... to invoke Template Gallery. Then select View Controller, specify ClearContactTasksController as the new item's name and click Add Item. As a result, you will get an automatically generated ClearContactTasksController.cs (ClearContactTasksController.vb) file with a single View Controller declaration.

               XAF 控制器 |通过视图控制器可视化工作室模板,可以更轻松地向应用程序添加视图控制器。在"解决方案资源管理器"中,右键单击 MySolution.模块项目中的"控制器"文件夹,然后选择"添加开发人员快递项目"新项目...以调用模板库。然后选择"查看控制器",将"清除联系人任务控制器"指定为新项目的名称,然后单击"添加项目"。因此,您将获得一个自动生成的ClearContactTasksController.cs(ClearContact任务控制器.vb)文件,该文件带有单个视图控制器声明。

    Tutorial_EF_Lesson1_1

    • The new Controller will be activated within any type of View by default. Because the task of this lesson is to clear Tracked Tasks in a Detail View, the default behavior should be changed. Right-click the MySolution.Module | Controllers | ClearContactTasksController.cs (ClearContactTasksController.vb) file, and choose View Designer to invoke the Designer.

    • 默认情况下,将在任何类型的视图中激活新控制器。由于本课的任务是清除详细信息视图中的"跟踪任务",因此应更改默认行为。右键单击"我的解决方案"模块 |控制器 |ClearContactTasksController.cs(清除联系人任务控制器.vb)文件,然后选择"视图设计器"以调用设计器。

      Controller_Designer

    • In the Properties window for the controller, set the TargetViewType property to the DetailView. As a result, the controller will only be activated in detail forms.

    • 在控制器的"属性"窗口中,将 TargetViewType 属性设置为"详细信息视图"。因此,控制器将仅在详细窗体中激活。

    1. Tutorial_EF_Lesson1_2

      Note 注意

      The same customization can be done in code, by setting the ViewController.TargetViewType property to ViewType.DetailView in the controller's constructor. If the property value is set after invoking the InitializeComponent method, the Designer setting will be overridden.

      通过在控制器的构造函数中设置 ViewTototoViewType 属性到 ViewType.detailView,可以在代码中执行相同的自定义。如果在调用初始化组件方法后设置了属性值,则将重写设计器设置。

      Alternatively, you can implement the generic ViewController<ViewType> Controller instead of the ViewController and specify the View's type, for which this Controller should be activated, in the ViewType generic parameter.

      或者,您可以在 ViewType 泛型参数中实现泛型视图控制器<ViewType>控制器,而不是视图控制器,并指定应为其激活此控制器的视图类型。

    2. Next, add SimpleAction to the ClearContactTasksController. In the DX.19.2: XAF Actions section in the Toolbox, drag SimpleAction to the Designer.

                接下来,将"简单操作"添加到清除联系人任务控制器。在工具箱中的 DX.19.2:XAF 操作部分中,将"简单操作"拖动到设计器。

    Tutorial_EF_Lesson1_2_1

    • In the Properties window for SimpleAction, set the Name and ID properties to "ClearTasksAction", the Category property to "View", the ImageName property to "Action_Clear" and the Caption property to "Clear Tasks". Set the ConfirmationMessage property to "Are you sure you want to clear the Tasks list?".

    • 在"简单操作的属性"窗口中,将"名称"和"ID"属性设置为"清除任务操作",将"类别"属性设置为"查看",将 ImageName 属性设置为"Action_Clear",将"标题"属性设置为"清除任务"。将"确认消息"属性设置为"是否确实要清除任务列表"。"

      Tutorial_EF_Lesson1_1_0

      Note 注意

      The Category property specifies the Action group to which the current Action belongs. All Actions within one group are displayed sequentially in a UI.

      The ImageName property specifies the icon of the Action's button in the interface. You can use one of the standard images or import your own

      "类别"属性指定当前操作所属的操作组。一个组内的所有操作都按顺序显示在 UI 中。
      ImageName 属性指定界面中操作按钮的图标。您可以使用其中一个标准映像或导入您自己的

    • A SimpleAction is designed to execute specific code when an end-user clicks it. To clear the Tasks collection of the current Person and refresh the view, implement the action's Execute event handler. Switch to the Events view in the Properties window, double-click the Execute event and add the following code to the auto-generated event handler.

    • SimpleAction 旨在在最终用户单击特定代码时执行该代码。要清除当前人员的任务集合并刷新视图,请实现操作的 Execute 事件处理程序。切换到"属性"窗口中的事件视图,双击 Execute 事件并将以下代码添加到自动生成的事件处理程序。

    • Entity Framework

               实体框架

    using MySolution.Module.BusinessObjects;
    //...
    private void ClearTasksAction_Execute(Object sender, SimpleActionExecuteEventArgs e) {
        ((Contact)View.CurrentObject).Tasks.Clear();
        ((DetailView)View).FindItem("Tasks").Refresh();
        ObjectSpace.SetModified(View.CurrentObject);
    }

    eXpress Persistent Objects

    eXpress 持久对象

    using MySolution.Module.BusinessObjects;
    //...
    private void ClearTasksAction_Execute(Object sender, SimpleActionExecuteEventArgs e) {
        while(((Contact)View.CurrentObject).Tasks.Count > 0) {
            ((Contact)View.CurrentObject).Tasks.Remove(((Contact)View.CurrentObject).Tasks[0]);
        }
        ObjectSpace.SetModified(View.CurrentObject);
    }
    • In ASP.NET Web applications, there are two modes for displaying Detail Views - View mode and Edit mode. The ClearTasks Action should only be available when a Detail View is displayed in Edit mode, so check to see if the edit mode for the current Detail View has changed. If it has changed to View mode, the Action should be disabled. To implement this, you should review the following concepts.

    • 在ASP.NET Web 应用程序中,有两种模式可用于显示详细视图 - 视图模式和编辑模式。仅当"详细信息视图"在"编辑"模式下显示时,"清除任务"操作才应可用,因此请检查当前"详细信息视图"的编辑模式是否已更改。如果它已更改为"查看"模式,则应禁用操作。为此,您应该查看以下概念。

      • The Detail View exposes the DetailView.ViewEditModeChanged event, which is fired when the edit mode is changed.
      • The Action exposes the ActionBase.Enabled property, which is not a simple Boolean property, but a key/value pair collection used to determine the Action's enabled state. This kind of collection is used because there can be many factors that influence the Action's state, and an XAF application should take them all into account.
      • "详细视图"公开"详细信息视图.ViewEditModeChanged"事件,该事件在更改编辑模式时触发。
      •  操作公开 ActionBase.Enabled 属性,该属性不是简单的布尔属性,而是用于确定操作的启用状态的键/值对集合。之所以使用此类集合,是因为影响 Action 状态的因素很多,XAF 应用程序应将所有因素都考虑在内。
    • Thus, handle the ViewEditModeChanged event and modify the Action's Enabled collection based on the current edit mode. To do this, return to the Controller's Designer and double-click the Activated event in the Events view of the Properties window. Replace the automatically generated event handler with the following code.

    • 因此,处理 ViewEditModeChanged 事件,并根据当前编辑模式修改操作的"已启用"集合。为此,返回到控制器的设计器,并双击"属性"窗口的"事件"视图中的"已激活"事件。将自动生成的事件处理程序替换为以下代码。

      private void ClearContactTasksController_Activated(object sender, EventArgs e) {
          // Enables the ClearTasks Action if the current Detail View's ViewEditMode property
          // is set to ViewEditMode.Edit.
          ClearTasksAction.Enabled.SetItemValue("EditMode", 
              ((DetailView)View).ViewEditMode == ViewEditMode.Edit);
          ((DetailView)View).ViewEditModeChanged += 
              new EventHandler<EventArgs>(ClearContactTasksController_ViewEditModeChanged);
      }
      // Manages the ClearTasks Action enabled state.
      void ClearContactTasksController_ViewEditModeChanged(object sender, EventArgs e) {
          ClearTasksAction.Enabled.SetItemValue("EditMode", 
              ((DetailView)View).ViewEditMode == ViewEditMode.Edit);
      }

    To see the result, run the WinForms or ASP.NET application and do the following.

    1. Open a detail form for any object.
    2. Click the Clear Tasks button, which represents the Action you have implemented. A confirmation message will appear as shown in the image below.

    要查看结果,请运行 WinForms 或ASP.NET应用程序,然后执行以下操作。

    • 打开任何对象的详细窗体。
    • 单击"清除任务"按钮,该按钮表示已实现的操作。确认消息将显示如下图所示。

    Tutorial_EF_Lesson1_3

    Click Yes (in a WinForms application) or OK (in an ASP.NET application). All Tracked Tasks of the Contact will be emptied.

    单击"是"(在 WinForms 应用程序中)或"确定"(在ASP.NET应用程序中)。联系人的所有跟踪任务都将清空。

    Tutorial_EF_Lesson1_4

    Note  注意

    Although this topic explains how to create a controller using the Designer, a controller is a class that can also be written manually, as shown in the Customize the Application UI and Behavior topic of the Basic Tutorial (SimpleProjectManager Application).

    尽管本主题说明如何使用 Designer 创建控制器,但控制器是一个也可以手动写入的类,如基本教程(简单项目经理应用程序)的"自定义应用程序 UI 和行为"主题所示。

    ­

    If you need to place an action inside the Detail View, refer to the How to: Include an Action to a Detail View Layout topic.

    如果需要在"详细信息视图"中放置操作,请参阅"如何:将操作包括在"详细信息视图布局"主题中。

    You can view the code used in this lesson in the MySolution.Module | Controllers | ClearContactTasksController.cs (ClearContactTasksController.vb) file of the Main Demo installed with XAF. The MainDemo application is installed in %PUBLIC%DocumentsDevExpress Demos 19.2ComponentseXpressApp FrameworkMainDemo by default. The ASP.NET version is available online at http://demos.devexpress.com/XAF/MainDemo/
    您可以在 MySolution.模块中查看本课中使用的代码。控制器 |ClearContactTasksController.cs(清除联系人任务控制器.vb)文件的主要演示安装与XAF。主演示应用程序安装在%PUBLIC%DocumentsDevExpress Demos 19.2ComponentseXpressApp FrameworkMainDemo by default. The ASP.NET version is available online at http://demos.devexpress.com/XAF/MainDemo/

    .

  • 相关阅读:
    使用shell从DB2数据库导出数据
    kettle插入/更新
    kettle删除资源库中的转换或者作业
    DB2中的转义字符
    Kettle行列转换
    Linux查看文件以及文件夹的大小
    Linux下如何查看JDK安装路径
    使用Linux调用资源库中的Job报错-ERROR: No repository provided, can't load job.
    通过shell脚本获取日期,并赋给变量
    批处理判断是否存在文件,存在则运行另外一个bat文件
  • 原文地址:https://www.cnblogs.com/foreachlife/p/Add-a-Simple-Action.html
Copyright © 2020-2023  润新知