zoukankan      html  css  js  c++  java
  • Add a Parametrized Action 添加带参数的按钮

    In this lesson, you will learn how to add a Parametrized Action. These types of Actions are slightly more complex than the Simple Actions you learned about in the previous lesson. The Parametrized Action provides an editor, so that an end-user can input a value before execution. In this lesson, a new View Controller will be implemented and a new Parametrized Action will be added to it. This Action will search for a DemoTask object by its Subject property value, and display the found object on a detail form.

    在本课中,您将学习如何添加参数化操作。这些类型的操作比您在上一课中学到的简单操作稍微复杂一些。参数化操作提供编辑器,以便最终用户可以在执行之前输入值。在本课中,将实现一个新的视图控制器,并将向其添加新的参数化操作。此操作将按其"主题"属性值搜索 DemoTask 对象,并在详细信息窗体上显示找到的对象。

    Note  注意

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

    • Inherit from the Business Class Library Class (XPO/EF)
    • Initialize a Property After Creating an Object (XPO/EF)
    • Add a Simple Action
    • Add a new View Controller to the MySolution.Module project, as described in the Add a Simple Action lesson. Name it FindBySubjectController.
    • Right-click the newly created MySolution.Module | Controllers | FindBySubjectController.cs (FindBySubjectController.vb) file, and choose View Designer to invoke the Designer. Drag ParametrizedAction from the DX.19.2: XAF Actions Toolbox tab to the Designer. In the ParametrizedAction Properties window, set the Name and ID properties to "FindBySubjectAction", and set the Caption property to "Find Task by Subject".

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

    • 从商务舱库类 (XPO/EF) 继承

    • 创建对象后初始化属性 (XPO/EF)
    • 添加简单操作
    • 向 MySolution.Module 项目添加新的视图控制器,如"添加简单操作"一课中所述。将其命名为"查找主体控制器"。
    • 右键单击新创建的 MySolution.模块 |控制器 |FindBySubjectController.cs (FindBySubjectController.vb) 文件,然后选择"视图设计器"以调用设计器。将参数化操作从 DX.19.2:XAF 操作工具箱选项卡拖动到设计器。在"参数化操作属性"窗口中,将"名称"和"ID"属性设置为"查找按主题操作",并将"标题"属性设置为"按主题查找任务"。

    Tutorial_EF_Lesson3_2

    • To activate the FindBySubjectController with its FindBySubjectAction for DemoTask List Views only, set the ViewController.TargetViewType property to "ListView", and set ViewController.TargetObjectType to MySolution.Module.DemoTask via the Controller's Properties window. To activate the Controller for root Views only, set the ViewController.TargetViewNesting property to Root.

    • 要激活 FindBy 主题控制器,其 FindBySubject 操作仅针对演示任务列表视图,请将"视图控制器.TargetViewType"属性设置为"listView",并将视图控制器.TargetObjectType 设置为 MySolution.module.DemoTask控制器的属性窗口。要仅激活根视图的控制器,请将"视图控制器.TargetViewNesting"属性设置为 root。

      Tutorial_EF_Lesson3_2_1

    • Next, you need to handle the Action's ParametrizedAction.Execute event to implement the search functionality. Focus the FindBySubject Action in the Controller's Designer. Switch to the Events view in the Properties window. Double-click the Execute event, replace the auto-generated event handler code with the following.

    • 接下来,您需要处理操作的参数化操作。在控制器的设计器中集中查找主体操作。切换到"属性"窗口中的"事件"视图。双击 Execute 事件,将自动生成的事件处理程序代码替换为以下内容。

      private void FindBySubjectAction_Execute(object sender, ParametrizedActionExecuteEventArgs e) {
          IObjectSpace objectSpace = Application.CreateObjectSpace(((ListView)View).ObjectTypeInfo.Type);
          string paramValue = e.ParameterCurrentValue as string;
          object obj = objectSpace.FindObject(((ListView)View).ObjectTypeInfo.Type,
              CriteriaOperator.Parse(string.Format("Contains([Subject], '{0}')", paramValue)));
          if(obj != null) {
              DetailView detailView = Application.CreateDetailView(objectSpace, obj);
              detailView.ViewEditMode = DevExpress.ExpressApp.Editors.ViewEditMode.Edit;
              e.ShowViewParameters.CreatedView = detailView;
          }
      }

      The Execute event is raised after a parameter has been typed in the Action's editor. The handler above looks for the DemoTask object, whose subject contains the text specified as a parameter, and invokes the detail form for this object.

              在操作的编辑器中键入参数后,将引发 Execute 事件。上面的处理程序查找 DemoTask 对象,其主题包含指定为参数的文本,并调用此对象的详细信息形式。

    Note 注意
    • To search for an object, you will need an Object Space. The Object Space is always used when manipulating persistent objects. To use the Object Space in this task, create it using the XafApplication.CreateObjectSpace method. Since an application is accessible nearly everywhere in code, its CreateObjectSpace method is always helpful.
    • 要搜索对象,您需要一个对象空间。操作持久对象时始终使用对象空间。要在此任务中使用对象空间,请使用 Xaf 应用程序.CreateObjectSpace 方法创建它。由于应用程序几乎可以在代码的任何地方访问,因此其 CreateObjectSpace 方法始终很有用。

     

    • To use the IObjectSpace.FindObject method, pass the type of the searched object, along with its criteria. To get the type of the objects represented in the current List View, use the View's object type info (see View.ObjectTypeInfo). To generate a criterion, create a BinaryOperator object by passing criteria components as the constructor's parameters. For additional information, refer to the Querying a Data Store section in the XPO documentation.
    • 要使用 IObjectSpace.FindObject 方法,传递搜索对象的类型及其条件。要获取当前列表视图中表示的对象类型,请使用视图的对象类型信息(请参阅 View.ObjectTypeInfo)。要生成条件,请通过将条件组件作为构造函数的参数来创建 BinaryOperator 对象。有关详细信息,请参阅 XPO 文档中的"查询数据存储"部分。

     

    • To get the value entered by an end-user in the editor that represents the FindBySubjectAction, use the event handler's ParametrizedActionExecuteEventArgs.ParameterCurrentValue parameter.
    • 要获取最终用户在编辑器中输入的值,该编辑器表示 FindBySubjectAction 操作,请使用事件处理程序的参数化操作执行事件Args.参数电流值参数。

     

    • To show the found object in a separate Detail View, create the View via the XafApplication.CreateDetailView method and assign it to the ShowViewParameters.CreatedView property of the event handler's ActionBaseEventArgs.ShowViewParameters parameter. Show View Parameters can be initialized in the Execute event handler of an Action of any type, so you can always show a View after Action execution. For additional information on how to show a View in a separate window, refer to the Ways to Show a View topic.
    • 要在单独的详细视图中显示找到的对象,请通过 Xaf 应用程序创建视图.创建详细信息视图方法并将其分配给 ShowView 参数.事件处理程序的 ActionBaseEventAgs.ShowView 参数的 CreateView 属性。可以在任何类型的操作的"执行事件"处理程序中初始化显示视图参数,因此始终可以在操作执行后显示视图。有关如何在单独的窗口中显示视图的其他信息,请参阅显示视图的方法主题。

     

    • As you may have already noticed, the XafApplication object is useful when you need to create a List View, Detail View, Object Space, etc. The XAFApplication object is accessible from many locations in an XAF application. In Controllers, it can be accessed via the Controller.Application property.
    • 您可能已经注意到,当您需要创建列表视图、详细信息视图、对象空间等时,XafApplication 对象非常有用。XAF 应用程序对象可从 XAF 应用程序中的许多位置访问。在控制器中,可以通过控制器.应用程序属性访问它。

     

    • Run the WinForms or ASP.NET application. Select the Task item in the navigation control. Find the Find Task by Subject editor that represents the Action you have implemented. Type a word from an existing DemoTask object's Subject property into this editor. Press the Enter key or click Find Task by Subject. A detail form with this object will be displayed.

    • 运行 WinForms 或ASP.NET应用程序。在导航控件中选择"任务"项。查找"按主题查找任务"编辑器,该编辑器表示已实现的操作。在此编辑器中键入现有 DemoTask 对象的"主题"属性中的单词。按 Enter 键或单击"按主题查找任务"。将显示具有此对象的详细信息窗体。
    • Tutorial_EF_Lesson3_3

    You can see the code demonstrated here in the MySolution.Module | Controllers | FindBySubjectController.cs (FindBySubjectController.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.模块 |控制器 |FindBySubjectController.cs (FindBy主题控制器.vb) 文件与 XAF 安装的主演示。主演示应用程序安装在%PUBLIC%DocumentsDevExpress Demos 19.2ComponentseXpressApp FrameworkMainDemo by default. The ASP.NET version is available online at http://demos.devexpress.com/XAF/MainDemo/

    .

  • 相关阅读:
    个人学习代码保存:例8.在存储过程中使用简单的事务处理
    个人学习代码保存:例6.多文件上传
    泛型 .net学习日记
    .net 点击刷新验证码问题
    个人学习代码保存:例11.读取Excel文件中的数据
    个人学习代码保存:例12.读取GridView文件中的数据到Excel文件
    个人学习代码保存:例5.利用标准FileUpload单文件上传
    Android视频采集
    Android视频采集+H264编码
    实时传输协议(RTP)和实时控制协议(RTCP)
  • 原文地址:https://www.cnblogs.com/foreachlife/p/Add-a-Parametrized-Action.html
Copyright © 2011-2022 走看看