To add the capability to analyze data in your application, the eXpressApp Framework supplies the Pivot Chart Module. The Analyze Data topic explains, that to initiate the Analysis functionality in an application, you should add this module and the built-in Analysis business class to the application. In this instance, the navigation control will contain the Analysis item and end-user will be able to create Analysis objects. However, you may need to provide the capability to create an Analysis object from any List View, setting the new Analysis object's DataType property to the object type of the List View. This topic demonstrates how to accomplish this task.
要添加分析应用程序中数据的功能,eXpressApp 框架提供数据透视图模块。"分析数据"主题说明,要在应用程序中启动分析功能,应将此模块和内置分析业务类添加到应用程序中。在这种情况下,导航控件将包含"分析"项,最终用户将能够创建分析对象。但是,您可能需要提供从任何列表视图创建分析对象的功能,将新的分析对象的 DataType 属性设置为列表视图的对象类型。本主题演示如何完成此任务。
Note 注意
Mobile applications do not support the Pivot Chart Module, so the approach described in this topic cannot be implemented in the Mobile platform.
移动应用程序不支持数据透视图模块,因此本主题中描述的方法无法在移动平台中实现。
Tip 提示
A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=E389
完整的示例项目可在 DevExpress 代码示例数据库中找到,http://www.devexpress.com/example=E389
.
-
Create a new ViewController in your application module. Invoke the Designer for it, and set the ViewController.TargetViewType property to ListView. This means that the Controller will be activated for List Views only.
For details on Controller creation, refer to the Extend Functionality section in the Tutorial.
- In the Controller's Designer, add a Simple Action (see Add a Simple Action). Set its ActionBase.Id property to AnalyzeData, the ActionBase.Category property to RecordEdit, the ActionBase.Caption property to Analyze and the ActionBase.ImageName property to BO_Analysis (a built-in image).
-
To deactivate the Action when the VisibleInReportsAttribute is not applied to the business class represented by the current List View, subscribe to the Controller's Controller.Activated event. Handle this event in the following manner:
-
在应用程序模块中创建新的视图控制器。调用设计器,并将视图控制器.TargetViewType 属性设置为 ListView。这意味着控制器将仅针对列表视图激活。
-
有关控制器创建的详细信息,请参阅教程中的扩展功能部分。 在控制器的设计器中,添加简单操作(请参阅添加简单操作)。将其ActionBase.Id属性设置为"分析数据","操作Base.类别"属性设置为"记录编辑","要分析的操作Base.Caption"属性设置为"BO_Analysis"(内置图像)。
-
要在"可见内报属性"未应用于当前列表视图表示的业务部门时停用操作,请订阅控制器控制器。以下列方式处理此事件:
using DevExpress.ExpressApp.Model; // ... public partial class AnalyseDataFromAnyViewController : ViewController { //... private void AnalyseDataFromAnyViewController_Activated(object sender, EventArgs e) { analyseDataAction.Active["VisibleInReports"] = ((IModelClassReportsVisibility)View.Model.Application.BOModel.GetClass( View.ObjectTypeInfo.Type)).IsVisibleInReports; } }
To deactivate the Action, its ActionBase.Active property is used.
要停用操作,将使用其 ActionBase.Active 属性。
-
Subscribe to the Action's SimpleAction.Execute event, to execute the code that will invoke a Detail View with a newly created Analysis object. Handle this event in the following manner:
-
订阅操作的"简单操作.Execute"事件,以执行将使用新创建的分析对象调用详细信息视图的代码。以下列方式处理此事件:
-
using DevExpress.Persistent.BaseImpl; //... public partial class AnalyseDataFromAnyViewController : ViewController { //... private void analyseDataAction_Execute(object sender, SimpleActionExecuteEventArgs e) { IObjectSpace objectSpaceInternal = Application.CreateObjectSpace(typeof(Analysis)); Analysis obj = objectSpaceInternal.CreateObject<Analysis>(); obj.DataType = View.ObjectTypeInfo.Type; obj.Name = "Analysis: " + View.Caption + " " + DateTime.Now.ToString(); e.ShowViewParameters.CreatedView = Application.CreateDetailView(objectSpaceInternal, obj); e.ShowViewParameters.TargetWindow = TargetWindow.Default; e.ShowViewParameters.Context = TemplateContext.View; } }
In the code above, the ShowViewParameters object is used. For details on how to use objects of this type, refer to the Ways to Show a View topic.
- 在上面的代码中,使用 ShowView 参数对象。有关如何使用此类型对象的详细信息,请参阅显示视图的方法主题。
-
Since the Analysis object will be created with the set-up Name and DataType properties, it is appropriate to bind data at once. Otherwise, an end-user will have to perform this additional action himself. To bind data, execute the BindAnalysisData () in code. For this purpose, implement a descendant of the AnalysisDataBindController as it is detailed in the Data Bind Aspects topic.
-
由于分析对象将使用设置的名称和 DataType 属性创建,因此最好一次绑定数据。否则,最终用户必须自己执行此附加操作。要绑定数据,请执行代码中的绑定分析数据(绑定分析数据)。为此,实现分析数据绑定控制器的后代,因为它是在数据绑定方面主题中详细说明的。
using DevExpress.ExpressApp.PivotChart; //... public class AssignAnalysisDataSourceViewController : AnalysisDataBindController { protected override void OnActivated() { base.OnActivated(); Analysis obj = View.CurrentObject as Analysis; //Allow data source loading if the ObjectTypeName property is specified if(obj.ObjectTypeName != null) { analysisEditor.IsDataSourceReady = true; UpdateBindUnbindActionsState(); } } }
Note 注意
Note that you should have the DevExpress.ExpressApp.PivotChart.v19.2 assembly referenced in the module project.
请注意,您应该在模块项目中引用 DevExpress.ExpressApp.PivotChart.v19.2 程序集。
The following image demonstrates the AnalyzeData Action that is available for a Contact List View. When clicking this Action, a newly created Analysis object is displayed in an invoked Detail View. The object's Name and DataType properties are automatically specified.
下图演示了联系人列表视图可用的分析数据操作。单击此操作时,新创建的"分析"对象将显示在调用的详细信息视图中。自动指定对象的名称和数据类型属性。