DevExpress Xaf入门——关于树形结构对象的配置(DC模式)

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中的属性在任何界面上的显示。

转载于:https://www.cnblogs.com/xuguanbao/p/3573195.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值