• DevExpress XAF 查找列表视图及联级过滤


      主要通过列表视图,实现联级过滤。只是对官方文件做了简单的代码复制,以后有机会再整理和修改。

    初始化实现

      使用the DataSourcePropertyAttribute 和 DataSourceCriteriaAttribute实现联级过滤。

     1 using System.ComponentModel;
     2 using DevExpress.Data.Filtering;
     3 //... 
     4 [DefaultClassOptions]
     5 public class Order : BaseObject {
     6    public Order(Session session) : base(session) { }
     7    private Product product;
     8    public Product Product {
     9       get {
    10          return product;
    11       }
    12       set {
    13          SetPropertyValue("Product", ref product, value);
    14       }
    15    }
    16    private Accessory accessory;
    17    public Accessory Accessory {
    18       get {
    19          return accessory;
    20       }
    21       set {
    22          SetPropertyValue("Accessory", ref accessory, value);
    23       }
    24    }
    25 }
    26 public class Product : BaseObject {
    27    public Product(Session session) : base(session) { }
    28    private String productName;
    29    public String ProductName {
    30       get { 
    31          return productName;
    32       }
    33       set {
    34          SetPropertyValue("ProductName", ref productName, value);
    35       }
    36    }
    37    [Association("P-To-C")]
    38    public XPCollection<Accessory> Accessories {
    39       get { return GetCollection<Accessory>("Accessories"); }
    40    }
    41 }
    42 public class Accessory : BaseObject {
    43    public Accessory(Session session) : base(session) { }
    44    private String accessoryName;
    45    public String AccessoryName {
    46       get { 
    47          return accessoryName; 
    48       }
    49       set {
    50          SetPropertyValue("AccessoryName", ref accessoryName, value);
    51       }
    52    }
    53    private bool isGlobal;
    54    public bool IsGlobal {
    55       get {
    56          return isGlobal;
    57       }
    58       set {
    59          SetPropertyValue("IsGlobal", ref isGlobal, value);
    60       }
    61    }
    62    private Product product;
    63    [Association("P-To-C")]
    64    public Product Product { 
    65       get {
    66          return product;
    67       } 
    68       set {
    69          SetPropertyValue("Product", ref product, value);
    70       } 
    71    }
    72 }

      效果下图。

    场景1 -使用指定集合属性中的对象填充查找

      关键代码:[DataSourceProperty("Product.Accessories")]
     1 [DefaultClassOptions]
     2 public class Order : BaseObject {
     3    // ... 
     4    [DataSourceProperty("Product.Accessories")]
     5    public Accessory Accessory {
     6       get {
     7          return accessory;
     8       }
     9       set {
    10          SetPropertyValue("Accessory", ref accessory, value);
    11       }
    12    }
    13 }

      效果如下图:

    场景2 -为Lookup属性集合应用标准

     1 [DefaultClassOptions]
     2 public class Order : BaseObject {
     3    // ... 
     4    [DataSourceCriteria("IsGlobal = true")]
     5    public Accessory Accessory {
     6       get {
     7          return accessory;
     8       }
     9       set {
    10          SetPropertyValue("Accessory", ref accessory, value);
    11       }
    12    }
    13 }
    14 public class Accessory : BaseObject {
    15       // ... 
    16    private bool isGlobal;
    17    public bool IsGlobal {
    18       get { return isGlobal; }
    19       set { 
    20          SetPropertyValue("IsGlobal", ref isGlobal, value);      
    21       }
    22    }
    23 }

    场景3 -如果指定的数据源属性为空,则使用备用标准

     1 [DefaultClassOptions]
     2 public class Order : BaseObject {
     3    // ... 
     4    [DataSourceProperty("Product.Accessories", 
     5       DataSourcePropertyIsNullMode.CustomCriteria, "IsGlobal = true")]
     6    public Accessory Accessory {
     7       get {
     8          return accessory;
     9       }
    10       set {
    11          SetPropertyValue("Accessory", ref accessory, value);
    12       }
    13    }
    14 }

    场景4 -手动填充查找

    [DefaultClassOptions]
    public class Order : BaseObject {
       // ... 
       // Set the AvailableAccessories collection as a data source for the Accessory property 
       [DataSourceProperty("AvailableAccessories")] 
       public Accessory Accessory {
          get {return accessory;}
          set {
             SetPropertyValue("Accessory", ref accessory, value);
          }
       }
       private XPCollection<Accessory> availableAccessories;
       [Browsable(false)] // Prohibits showing the AvailableAccessories collection separately 
       public XPCollection<Accessory> AvailableAccessories {
          get {
             if(availableAccessories == null) {
                // Retrieve all Accessory objects 
                availableAccessories = new XPCollection<Accessory>(Session);
                // Filter the retrieved collection according to current conditions 
                RefreshAvailableAccessories();
             }
             // Return the filtered collection of Accessory objects 
             return availableAccessories;
          }
       }
       private void RefreshAvailableAccessories() {
          if(availableAccessories == null)
             return;
          // Process the situation when the Product is not specified (see the Scenario 3 above) 
          if(Product == null) {
             // Show only Global Accessories when the Product is not specified 
             availableAccessories.Criteria = CriteriaOperator.Parse("[IsGlobal] = true");
          }
          else {
             // Leave only the current Product's Accessories in the availableAccessories collection 
             availableAccessories.Criteria = new BinaryOperator("Product", Product);
             if(IncludeGlobalAccessories == true) {
                // Add Global Accessories 
                XPCollection<Accessory> availableGlobalAccessories = 
                   new XPCollection<Accessory>(Session);
                availableGlobalAccessories.Criteria = CriteriaOperator.Parse("[IsGlobal] = true");
                availableAccessories.AddRange(availableGlobalAccessories);
             }
          }
          // Set null for the Accessory property to allow an end-user  
          //to set a new value from the refreshed data source 
          Accessory = null;
       }
       public Product Product {
          get {return product;}
          set {
             SetPropertyValue("Product", ref product, value);
             // Refresh the Accessory Property data source 
             RefreshAvailableAccessories();
          }
       }
       private bool includeGlobalAccessories;
       [ImmediatePostData] //Use this attribute to refresh the Accessory  
       public bool IncludeGlobalAccessories {
          get {return includeGlobalAccessories;}
          set {
             if(includeGlobalAccessories != value) {
                includeGlobalAccessories = value;
                if(!IsLoading) {
                   // Refresh the Accessory Property data source                     
                   RefreshAvailableAccessories();
                   SetPropertyValue("IncludeGlobalAccessories", ref includeGlobalAccessories, value);
                }
             }
          }
       }
    }

     场景5 -根据当前对象的属性筛选Lookup属性集合

     1 using DevExpress.Persistent.Base;
     2 using DevExpress.Persistent.BaseImpl;
     3 // ... 
     4 public class Contact : Person {
     5     // ... 
     6     [DataSourceProperty("Department.Contacts", DataSourcePropertyIsNullMode.SelectAll)]
     7     [DataSourceCriteria("Position.Title = 'Manager' AND Oid != '@This.Oid'")]
     8     public Contact Manager {
     9         get {
    10             return manager;
    11         }
    12         set {
    13             SetPropertyValue("Manager", ref manager, value);
    14         }
    15     }
    16     // ... 
    17 }

      参考网址

      [1] https://documentation.devexpress.com/eXpressAppFramework/112681/Task-Based-Help/Filtering/How-to-Implement-Cascading-Filtering-for-Lookup-List-Views

  • 相关阅读:
    【贪心 堆】luoguP2672 推销员
    【贪心 思维题】[USACO13MAR]扑克牌型Poker Hands
    「整理」[图论]最短路系列
    收集到的小玩意儿
    初遇构造函数
    在2440开发板液晶上显示两行字
    error: converting to execution character set: Invalid or incomplete multibyte or wide character
    宽字节
    宽字符wchar_t和窄字符char区别和相互转换
    linux获取文件大小的函数
  • 原文地址:https://www.cnblogs.com/luyj00436/p/11465627.html
Copyright © 2020-2023  润新知