1、在VS2012中通过新建XAF解决方案Solution2,并在Solution2.Web项目中的配置文件Web.config中配置连接字符串;
<connectionStrings> <add name="EasyTestConnectionString" connectionString="Integrated Security=SSPI;Pooling=false;Data Source=.\SQLEXPRESS;Initial Catalog=Solution2EasyTest" /> <add name="ConnectionString" connectionString="Data Source=GUANBAOPC\SQLEXPRESS;Initial Catalog=Solution2DB;Persist Security Info=true;User ID=sa;Password=123" /> </connectionStrings>
2、双击Solution2.Module项目下的Module.cs打开Module设计器,从工具箱中把ConditionalAppearanceModule、TreeListEditorsAspNetModule拖到Required Modules中。
3、在解决方案Solution2中对应的项目Solution2.Module的文件夹BusinessObjects中新建Xaf Domain Component对象Department。
Department对象(接口)
using System; using System.Linq; using System.Text; using System.ComponentModel; using DevExpress.ExpressApp; using DevExpress.ExpressApp.DC; using DevExpress.Data.Filtering; using DevExpress.Persistent.Base; using System.Collections.Generic; using DevExpress.ExpressApp.Model; using DevExpress.Persistent.Validation; using DevExpress.Persistent.Base.General; using DevExpress.ExpressApp.ConditionalAppearance; using DevExpress.ExpressApp.Editors; namespace Solution2.Module.BusinessObjects { [DomainComponent] [DefaultClassOptions] [XafDisplayName("部门信息")] [Appearance("Single", Enabled = false, TargetItems="Name,Children,Parent", Visibility = ViewItemVisibility.Hide, Criteria = "1=1")] public interface Department : ITreeNode { [XafDisplayName("部门名称")] string DepartmentName { get; set; } [XafDisplayName("部门编号")] string DepartmentCode { get; set; } [XafDisplayName("联系电话")] string ContactNumber { get; set; } [XafDisplayName("子部门")] IList<Department> ChildrenDepartment { get; } [XafDisplayName("父部门")] Department ParentDepartment { get; set; } } [DomainLogic(typeof(Department))] public class Department_Logic { public static string Get_Name(Department instance) { return instance.DepartmentName; } public static Department Get_Parent(Department instance) { return instance.ParentDepartment; } public static IBindingList Get_Children(Department instance) { return new BindingList<Department>(instance.ChildrenDepartment); } } }
4、将Solution2.Web设为启动项目,并使用调试模式运行解决方案。运行结果如下:
提示:
1、部门对象(Deparment)中父部门属性(ParentDepartment)必须设置get与set方法;
2、部门对象(Deparment)中父部门属性(ChildrenDepartment)类型不能以List<Department>代替;
3、Appearance标签目的是隐藏ITreeNode中的属性在任何界面上的显示。