本文参阅官网文档 How to: Use Custom Logon Parameters and Authentication 加以实践并做简单的总结归纳。
修改登录页面文本信息
如果需要修改登录页面文本信息或实现本地化,可以双击解决方案中module工程下的 .xafml
文件,进入模型编辑器,在项目树结构中展开 Views
节点 → 展开 DevExpress.ExpressApp.Security
→ 展开AuthenticationStandardLogonParameters_DetailView
。 然后可以在 Items
文件中选择对应的属性值进行修改, 或者在 Layout
节点中的设计面板中右键点击 costomize layout
按钮中进入设计模式进行编辑。
自定义登录页面
如果需要修改登录页面的登录参数,例如下文所述,是按照公司+工号+密码的方式登录。以下是具体步骤。
创建自定义登录页面
在创建自定义登录页面之前,需要创建登录信息所涉及的 Employee
和 Company
类。 其中 Employee
继承于 PermissionPolicyUser
类,主要的作用是作为 PermissionPolicyUser
类的拓展,提供了工号属性,并与 Company
类关联。
在解决方案中 module
工程下的 BusinessObjects
文件夹中新建 Employee.cs
:
using System.ComponentModel;
using DevExpress.Persistent.Base;
using DevExpress.Persistent.BaseImpl.PermissionPolicy;
using DevExpress.Xpo;
// ...
[DefaultClassOptions, DefaultProperty(nameof(Gonghao))]
public class Employee : PermissionPolicyUser{
public Employee(Session session) : base(session) {
}
private Company company;
string gonghao;
[Size(SizeAttribute.DefaultStringMappingFieldSize)]
[RuleRequiredField("Employee_Gonghao_RuleRequiredField", DefaultContexts.Save)]
[RuleUniqueValue("Employee_Gonghao_RuleUniqueValue", DefaultContexts.Save, "本系统中已经存在该工号!")]
public string Gonghao
{
get => gonghao;
set => SetPropertyValue(nameof(Gonghao), ref gonghao, value);
}
[Association("Company-Employees")]
public Company Company {
get {
return company; }
set {
SetPropertyValue(nameof(Company), ref company, value);}
}
}
在解决方案中 module
工程下的 BusinessObjects
文件夹中新建 Company.cs
:
using DevExpress.Persistent.Base;
using DevExpress.Persistent.BaseImpl;
using DevExpress.Xpo;
// ...
[DefaultClassOptions]
public class Company : BaseObject {
public Company(Session session) : base(session) {
}
private string name;
public string Name {
get {
return name; }
set {
SetPropertyValue(nameof(Name), ref name, value); }
}
[Association("Company-Employees")]
public XPCollection<Employee> Employees {
get {
return GetCollection<Employee>(nameof(Employees)); }
}
}
需要注意的是,需要将公司和工号下拉框设置成不可新增。
在解决方案中 module
工程下创建 CustomLogonParameters
类,作为自定义登录界面。
using System;
using System.ComponentModel;
using System.Runtime.Serialization;
using DevExpress.ExpressApp.DC;
using DevExpress.Persistent.Base;
namespace MySolution.Module.BusinessObjects
{
[DomainComponent, Serializable]
[