二开案例.表单插件.设置单据体分组汇总列
【应用场景】
设置单据体分组汇总列。
【案例演示】
新建动态表单,演示给单据体设置分组汇总列。
【实现步骤】
<1>编写表单插件,代码如下。
using Kingdee.BOS.Core.DynamicForm; using Kingdee.BOS.Core.DynamicForm.PlugIn; using Kingdee.BOS.Core.DynamicForm.PlugIn.Args; using Kingdee.BOS.Core.DynamicForm.PlugIn.ControlModel; using Kingdee.BOS.Core.Metadata; using Kingdee.BOS.Core.Metadata.FieldElement; using Kingdee.BOS.Core.Metadata.GroupElement; using Kingdee.BOS.JSON; using Kingdee.BOS.Util; using System; using System.Collections.Generic; using System.ComponentModel; namespace Jac.XkDemo.BOS.Business.PlugIn { /// <summary> /// 【表单插件】设置单据体分组汇总列 /// </summary> [Description("【表单插件】设置单据体分组汇总列"), HotUpdate] public class SetSummaryGroupInfoFormPlugIn : AbstractDynamicFormPlugIn { /// <summary> /// 单据体标识 /// </summary> private const string EntityKey = "F_Jac_Entity"; public override void OnSetBusinessInfo(SetBusinessInfoArgs e) { base.OnSetBusinessInfo(e); InitGroupColumnInfo(this.View.BillBusinessInfo, EntityKey); } public override void BarItemClick(BarItemClickEventArgs e) { base.BarItemClick(e); if (e.BarItemKey.EqualsIgnoreCase("test")) { BindData(); } else if (e.BarItemKey.EqualsIgnoreCase("test1")) { // 只汇总 SetSummaryGroupInfo(this.View, EntityKey, null, new[] { "F_Jac_Integer" }); } else if (e.BarItemKey.EqualsIgnoreCase("test2")) { // 分组+汇总 SetSummaryGroupInfo(this.View, EntityKey, new[] { "F_Jac_Text" }, new[] { "F_Jac_Integer1", "F_Jac_Integer2" }); } else if (e.BarItemKey.EqualsIgnoreCase("test3")) { // 取消分组汇总 SetSummaryGroupInfo(this.View, EntityKey, null, null); } } /// <summary> /// 动态创建单据体数据包 /// </summary> private void BindData() { this.Model.DeleteEntryData(EntityKey); this.Model.BatchCreateNewEntryRow(EntityKey, 10); // 随机生成10行数据 for (var i = 0; i < this.Model.GetEntryRowCount(EntityKey); i++) { this.Model.SetValue("F_Jac_Text", Guid.NewGuid().ToString()[0], i); this.Model.SetValue("F_Jac_Integer", new Random(Guid.NewGuid().GetHashCode()).Next(100, 999), i); this.Model.SetValue("F_Jac_Integer1", new Random(Guid.NewGuid().GetHashCode()).Next(1000, 9999), i); this.Model.SetValue("F_Jac_Integer2", new Random(Guid.NewGuid().GetHashCode()).Next(10000, 99999), i); } this.View.UpdateView(EntityKey); } /// <summary> /// 设置单据分组汇总 /// </summary> /// <param name="view">动态表单的视图</param> /// <param name="entityKey">单据体标识</param> /// <param name="groupFieldKeys">分组字段标识的集合</param> /// <param name="sumFieldKeys">汇总字段标识的集合</param> private void SetSummaryGroupInfo(IDynamicFormView view, string entityKey, string[] groupFieldKeys, string[] sumFieldKeys) { var jsObj = new JSONObject(); #region 设置分组字段 var jsGroupFields = new JSONArray(); //jsObj.Put("groupColums", jsGroupFields); if (groupFieldKeys != null) { foreach (var fieldKey in groupFieldKeys) { var groupField = view.BillBusinessInfo.GetField(fieldKey); if (groupField == null) { continue; } var jsGroupField = new JSONObject(); jsGroupField["fieldKey"] = groupField.Key.ToUpper(); jsGroupFields.Add(jsGroupField); } } jsObj.Put("groupColums", jsGroupFields); if (jsGroupFields.Count == 0) { view.GetControl<EntryGrid>(entityKey).InvokeControlMethod("RebuildGridColumns", null); } #endregion #region 设置汇总字段 var jsSumFields = new JSONArray(); jsObj.Put("groupSumColums", jsSumFields); if (sumFieldKeys != null) { // 修改单据体的汇总元数据 var entity = this.View.BillBusinessInfo.GetEntity(entityKey); InitGroupColumnInfo(this.View.BillBusinessInfo, entityKey); foreach (var fieldKey in sumFieldKeys) { var summaryField = view.BillBusinessInfo.GetField(fieldKey) as DecimalField; if (summaryField == null) { continue; } var jsSumField = new JSONObject(); jsSumField["fieldKey"] = summaryField.Key.ToUpperInvariant(); jsSumField["sumType"] = SummaryType.SUM_VALUE; jsSumFields.Add(jsSumField); // 此处直接改了动态表单的元数据,注意规避元数据缓存问题 entity.GroupColumnInfo.GroupSumColumns.Add(new GroupSumColumn { FieldKey = summaryField.Key, SumType = SummaryType.SUM_VALUE }); } } #endregion #region 表格控件刷新分组汇总配置 var jsArr = new JSONArray(); jsArr.Add(jsObj); view.GetControl<EntryGrid>(entityKey).SetSummaryGroupInfo(jsArr); this.View.UpdateView(entityKey); #endregion } /// <summary> /// 初始化单据体分组汇总元数据(清空已有的设置) /// </summary> /// <param name="businessInfo">单据的元数据</param> /// <param name="entityKey">单据体标识</param> private void InitGroupColumnInfo(BusinessInfo businessInfo, string entityKey) { if (businessInfo == null) { return; } var entity = businessInfo.GetEntity(entityKey); if (entity == null) { return; } if (entity.GroupColumnInfo == null) { entity.GroupColumnInfo = new GroupColumnInfo(); } if (entity.GroupColumnInfo.GroupSumColumns == null) { entity.GroupColumnInfo.GroupSumColumns = new List<GroupSumColumn>(); } entity.GroupColumnInfo.GroupSumColumns.Clear(); } } }
<2>拷贝插件组件到应用站点的WebSite\Bin目录下,重启IIS。
<3>BOSIDE新建动态表单,新增一个单据体,单据体新增几个字段,注册表单插件,保存元数据,发布菜单,开发完毕。
【功能验证】
<1>登录业务站点,打开菜单【动态表单演示】,分组汇总效果如下图。
绑定数据:
汇总:
分组汇总:
---------------------------------------------------------------------------------------------------------
【金蝶云星空BOS二次开发案例演示】https://vip.kingdee.com/article/94751030918525696
二开案例.表单插件.设置单据体分组汇总列
【应用场景】设置单据体分组汇总列。【案例演示】新建动态表单,演示给单据体设置分组汇总列。【实现步骤】<1>编写表单插件,代码如下。usi...
点击下载文档
上一篇:二开案例.元模型.文本下一篇:系统运维.数据库.性能分析常用SQL
本文2024-09-23 03:59:10发表“云星空知识”栏目。
本文链接:https://wenku.my7c.com/article/kingdee-k3cloud-162367.html
您需要登录后才可以发表评论, 登录登录 或者 注册
最新文档
热门文章