【金蝶K3Cloud】 树形控件

  1 树形控件添加到动态表单(或单据等)界面上之后,通过重载界面插件的如下两个事件实现功能:
  2 1. TreeLoadData 事件:在此事件中构建树节点
  3 2. TreeNodeClick 事件:在此事件中响应用户点击树节点动作
  4 
  5 如下代码演示如何在基础资料的列表界面,如何自行构建左边的分组树节点;用户点击分组之后,如何过滤基础资料数据:
  6 
  7 using System;
  8 using System.Collections.Generic;
  9 using System.Linq;
 10 using System.Text;
 11 using System.ComponentModel;
 12 using Kingdee.BOS;
 13 using Kingdee.BOS.Util;
 14 using Kingdee.BOS.Core;
 15 using Kingdee.BOS.Core.DynamicForm.PlugIn;
 16 using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
 17 using Kingdee.BOS.Core.DynamicForm.PlugIn.ControlModel;
 18 using Kingdee.BOS.Core.List;
 19 using Kingdee.BOS.Core.List.PlugIn;
 20 using Kingdee.BOS.Core.List.PlugIn.Args;
 21 using Kingdee.BOS.Core.Metadata;
 22 using Kingdee.BOS.Orm.DataEntity;
 23 namespace JDSample.FormPlugIn.BaseData
 24 {
 25     /// <summary>
 26     /// 多层次基础资料列表插件
 27     /// </summary>
 28     /// <remarks>
 29     /// 演示用基础资料:
 30     /// FormId : 08441f27-444c-43ee-bed9-8498a1ff066c
 31     /// 基类:1.1 不受组织控制基础资料模板(BOS_NoOrgControlBDModel)
 32     /// 名称:资料类别
 33     /// 包含的字段:
 34     /// 1. 上级资料 F_JD_ParentId
 35     /// 2. 编码 FNumber
 36     /// 3. 名称 FName
 37     /// 4. 完整父节点内码 F_JD_FullParentId (由各级父节点内码组成,如(.1001.1002.1003,以便根据当前节点,快速找出所有下级节点)
 38     /// </remarks>
 39     [Description("多层次基础资料列表插件")]
 40     public class MulLevelBaseDataList : AbstractListPlugIn
 41     {
 42         private TreeNode _groupRootNode = null;
 43         /// <summary>
 44         /// 界面请求构建树节点事件;拦截此事件,自行构建树节点
 45         /// </summary>
 46         /// <param name="e"></param>
 47         public override void TreeLoadData(TreeLoadDataArgs e)
 48         {
 49             TreeView tv = this.View.GetControl<TreeView>("FGroupTreeView");
 50             var parentNode = BuildTreeNode(this.Context, this.View.BillBusinessInfo);
 51             tv.SetRootNode(parentNode);
 52             tv.SetExpanded(true);
 53             // 略过系统预置取分组树的功能
 54             e.Cancel  = true;
 55         }
 56         /// <summary>
 57         /// 用户点击树节点事件:
 58         /// 拦截此事件,根据用户所选节点,设置过滤条件,筛选列表数据
 59         /// </summary>
 60         /// <param name="e"></param>
 61         public override void TreeNodeClick(TreeNodeArgs e)
 62         {
 63             TreeViewFilterParameter filterParameter = ((ITreeListModel)this.Model).TreeViewFilterParameter as TreeViewFilterParameter;
 64             filterParameter.FilterString = string.Empty;        // 分组过滤条件
 65             filterParameter.IgnoreSelectedGroupIds = false;     // 是否忽略默认的分组过滤处理
 66             if (e.NodeId == "0")
 67             {
 68                 // 点击根节点,无需设置分组过滤条件
 69                 return;
 70             }
 71             // 拼接分组过滤条件:资料类别 = 本节点,以及本节点的全部下级节点
 72             string filter = string.Format(" (FID = {0} OR F_JD_FullParentId LIKE '%.{0}.%') ", e.NodeId);
 73             // 采用二开设置的分组过滤条件,忽略系统默认的分组过滤
 74             filterParameter.FilterString = filter;
 75             filterParameter.IgnoreSelectedGroupIds = true;
 76         }
 77         public static TreeNode BuildTreeNode(Context ctx, BusinessInfo groupInfo)
 78         {
 79             // 构建根目录
 80             TreeNode rootNode = new TreeNode();
 81             rootNode.id = "0";
 82             rootNode.parentid = "0";
 83             rootNode.text = "全部";
 84             // 读取全部资料分类数据
 85             List<SelectorItemInfo> selectorList = new List<SelectorItemInfo>();
 86             selectorList.Add(new SelectorItemInfo("FID"));
 87             selectorList.Add(new SelectorItemInfo("F_JD_ParentId"));
 88             selectorList.Add(new SelectorItemInfo("FNumber"));
 89             selectorList.Add(new SelectorItemInfo("FName"));
 90             var infoGroups = Kingdee.BOS.ServiceHelper.BusinessDataServiceHelper.Load(
 91                             ctx,
 92                             groupInfo, 
 93                             selectorList,
 94                             OQLFilter.CreateHeadEntityFilter(""));
 95             
 96             if (infoGroups == null || infoGroups.Length == 0) return rootNode;
 97             // 把各资料分类,转换为树节点,并放在字典中
 98             Dictionary<string, TreeNode> dctNodes = new Dictionary<string, TreeNode>();
 99             foreach (var infoGroup in infoGroups)
100             {
101                 long id = Convert.ToInt64(infoGroup["Id"]);
102                 long parentId = Convert.ToInt64(infoGroup["F_JD_ParentId_Id"]);
103                 string number = Convert.ToString(infoGroup["Number"]);
104                 string name = Convert.ToString(infoGroup["Name"]);
105                 TreeNode node = new TreeNode() 
106                 { 
107                     id = id.ToString(), 
108                     text = string.Format("{0}({1})", name, number),
109                     parentid = parentId.ToString(),
110                 };
111                 dctNodes.Add(id.ToString(), node);
112             }
113             // 把各节点,放在其父节点下面
114             foreach (var item in dctNodes)
115             {
116                 TreeNode node = item.Value;
117                 if (node.parentid == "0")
118                 {
119                     rootNode.children.Add(node);
120                 }
121                 else if (dctNodes.Keys.Contains(node.parentid))
122                 {
123                     dctNodes[node.parentid].children.Add(node);
124                 }
125             }
126             return rootNode;
127         }
128     }
129 }

 

posted @ 2018-10-22 14:54  嘿嘿嘿~  阅读(2683)  评论(0编辑  收藏  举报