Implement Property Value Validation in the Application Model validation attribute values achieved in the application model

In this lesson, you will learn how to check whether or not a property value satisfies a particular rule. For this purpose, the DemoTask.Status property and the MarkCompleted Action will be used. This action should not be executed if the current task status is "NotStarted". Thus, the rule will be checked when executing the MarkCompleted Action.

In this lesson, you will learn how to check the property value meets certain rules. For this purpose, attributes and tags using DemoTask.Status complete the operation. If the current task status is "not started", you should not do this. Thus, when performing "finish flag" rule checks.

Note
Before proceeding, take a moment to review the following lessons.
  • Implement Property Value Validation in Code (XPO/EF)
  • Place an Action in a Different Location

note

Before proceeding, please take a moment to review the following courses.

  • Implement authentication attribute value (XPO / EF) in the code
  • The operation in other locations

The validation functionality is provided by the Validation Module that was added in the Implement Property Value Validation in Code (XPO) lesson. When this module is added to the MySolution.Module project, the Validation node is available in the Application Model. This node defines the validation Contexts and Rules used in your application. You can use the Model Editor to add Rules and specify Contexts.

Verification is provided by the authentication module adds the code (XPO) courses. When this module is added to MySolution. Project module, the authentication node can be used in the application model. Validation rules defined application context and used in this node. You can use the model editor to add rules and specify the context.

 

  • Invoke the Model Editor for the MySolution.Module project. Navigate to the Validation | Rules node. It already contains child nodes that define the rules to be checked. For example, it may contain the "RuleRequiredField for Position.Title" rule that was implemented in the Implement Property Value Validation in Code (XPO) lesson. To add a new rule that checks specific criteria, right-click the Rules node and select Add... | RuleCriteria.

  • Call MySolution. Model Editor module project. Navigate to verify | Rules node. It has a child node contains the rules defined to be checked. For example, it may contain attribute values ​​achieved validation "location .Title.Title" in the code rule (XPO) courses. To add a new rule to check specific conditions, right-click the "rules" node and select "Add ..." | rule criteria.

    Tutorial_UIC_Lesson14_1

    Note Note
    The descriptions of all available rule types are available in the Validation Rules topic.

    All available rules description of the types used in validation rules topic.

 

  • For the newly created node, set the TargetType to "MySolution.Module.BusinessObjects.DemoTask", and set the Criteria property to "Status != 'NotStarted'". Set the ID property to "TaskIsNotStarted", TargetContextIDs to "MarkCompleted" and CustomMessageTemplate to "Cannot set the task as completed because it has not started".
  • For the newly created node, the target type is set to "MySolution.Module. Business object. Demo mission" and "condition" attribute set to "status! =" Not started ". The ID attribute is set to" TaskIsNot started " the target context ID to "mark as done", custom message templates to "not set a task to complete, because it has not been started."

Tutorial_UIC_Lesson14_2

Note Note
The Criteria property value must be specified using the Criteria Language Syntax. To simplify this task, you can invoke the Filter Builder dialog by clicking the ellipsis button (EllipsisButton) to the right of the Criteria value. Within this dialog, you can visually design a criteria expression.

You must use "conditional language syntax" designated "condition" attribute value. To simplify this task, you can call the "Filter Builder" dialog with the ellipsis button (EllipsisButton) Click condition value to the right. In this dialog box, you can visually design a conditional expression.

 

  • The TargetContextIDs property is set to "MarkCompleted". This means that the rule will be checked when executing the Action whose ValidationContexts property is set to "MarkCompleted". So, set the Mark Completed Action's ValidationContexts property (in the ActionDesign | Actions | Task.MarkCompleted node) to "MarkCompleted".

  • "目标上下文"属性设置为"标记已完成"。这意味着在执行其验证上下文属性设置为"标记完成"的操作时,将检查规则。因此,设置"标记已完成操作的验证上下文"属性(在操作设计 |操作 |任务.标记已完成节点)到"标记已完成"。

    Tutorial_UIC_Lesson14_2_1

    Note 注意
    You can also use the Save or Delete contexts, which are available by default. Rules with these contexts are validated when an object is saved or deleted, respectively (see Validation Rules).

    您还可以使用默认可用的"保存或删除"上下文。分别保存或删除对象时,将验证具有这些上下文的规则(请参阅验证规则)。

  • Run the WinForms or ASP.NET application. Assign the "Not Started" value to the Status property of one of the existing DemoTask objects. Click the MarkCompleted button. The following Validation Error dialog will be displayed.

  • 运行 WinForms 或ASP.NET应用程序。将"未启动"值分配给现有演示任务对象之一的状态属性。单击"标记已完成"按钮。将显示以下验证错误对话框。

    Tutorial_UIC_Lesson14_4

Note 注意
Generally, you can add the required rule to a class or property in code (see Implement Property Value Validation in Code (EF \ XPO)). The approach defined above is useful when the class sources are inaccessible.

通常,可以将所需的规则添加到代码中的类或属性(请参阅在代码中实现属性值验证 (EF = XPO)。)。当类源无法访问时,上面定义的方法非常有用。

You can see the changes made in this lesson in the Model Editor invoked for the Model.DesignedDiffs.xafml file located in the Main Demo | MainDemo.Module project. The MainDemo application is installed in %PUBLIC%\Documents\DevExpress Demos 19.2\Components\eXpressApp Framework\MainDemo by default. The ASP.NET version is available online at http://demos.devexpress.com/XAF/MainDemo/

Change the model editor you can model calls you made in this lesson. The main demonstration module project. The demo application is installed in the main % the PUBLIC% \ Documents \ DevExpress the Demos 19.2 \ Components \ eXpressApp Framework \ MainDemo by default. The Available Online at The ASP.NET Version IS AT http://demos.devexpress.com/XAF/MainDemo/

.

Guess you like

Origin www.cnblogs.com/foreachlife/p/Implement-Property-Value-Validation-in-the-Application-Model.html