常见link实体
using Kingdee.BOS.Core.Bill.PlugIn;using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;using Kingdee.BOS.Core.Metadata;using Kingdee.BOS.Core.Metadata.EntityElement;using Kingdee.BOS.Orm.DataEntity;using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace DynamicFormPlugIn.Test{
[ ]
[ ] public class AdjustTrackResultBillPlugIn : AbstractBillPlugIn
{ public override void BarItemClick(BarItemClickEventArgs e) { if (string.Equals("tb_ShowLinkInfo", e.BarItemKey, StringComparison.OrdinalIgnoreCase))
{ this.View.ShowMessage(LinkHelper.GetSrcLinkInfoByBillObj(this.View.BillBusinessInfo, this.Model.DataObject));
}
}
} public static class LinkHelper
{ /// <summary>
/// 获取link实体
/// </summary>
/// <param name="businessInfo"></param>
/// <returns></returns>
public static LinkEntity GetLinkEntity(BusinessInfo businessInfo) { var billForm = businessInfo.GetForm(); if (billForm.LinkSet == null || billForm.LinkSet.LinkEntitys.Count == 0) return null; return billForm.LinkSet.LinkEntitys[0];
} /// <summary>
/// 获取link实体的关联实体
/// </summary>
/// <param name="businessInfo"></param>
/// <returns></returns>
public static Entity GetLinkParentEntiy(BusinessInfo businessInfo) { var linkEntity = GetLinkEntity(businessInfo); if (linkEntity == null) return null; var linkParentEntity = businessInfo.GetEntity(linkEntity.ParentEntityKey); return linkParentEntity;
} /// <summary>
/// 输出数据包的关联源单关系
/// </summary>
/// <param name="businessInfo">元数据</param>
/// <param name="billDataObj">数据包</param>
/// <returns></returns>
public static string GetSrcLinkInfoByBillObj(BusinessInfo businessInfo, DynamicObject billDataObj) { var linkParentEntity = GetLinkParentEntiy(businessInfo); var linkEntity = GetLinkEntity(businessInfo);
StringBuilder msgBuilder = new StringBuilder(); if (linkParentEntity is HeadEntity)
{ //关联实体在单据头
if (!billDataObj.DynamicObjectType.Properties.ContainsKey(linkEntity.Key)) return string.Empty;
msgBuilder.AppendLine("关联实体在单据头");
DynamicObjectCollection linkObjColl = billDataObj[linkEntity.Key] as DynamicObjectCollection;
ScanLinkDataObj(linkObjColl, (x) => { GetLinkMessage(x, msgBuilder); });
} else if (linkParentEntity is EntryEntity)
{ if (!billDataObj.DynamicObjectType.Properties.Contains(linkParentEntity.DynamicProperty)) return string.Empty;
msgBuilder.AppendLine("关联实体在单据体");
DynamicObjectCollection entityObjColl = billDataObj[linkParentEntity.DynamicProperty] as DynamicObjectCollection; for (int i = 0; i < entityObjColl.Count; ++i)
{ var entityObj = entityObjColl[i]; if (entityObj == null) continue;
msgBuilder.AppendLine(string.Format("分录序号:{0}", i + 1)); if (!entityObj.DynamicObjectType.Properties.ContainsKey(linkEntity.Key)) return string.Empty;
DynamicObjectCollection linkObjColl = entityObj[linkEntity.Key] as DynamicObjectCollection;
ScanLinkDataObj(linkObjColl, (x) => { GetLinkMessage(x, msgBuilder); });
}
} return msgBuilder.ToString();
} /// <summary>
/// link实体遍历
/// </summary>
/// <param name="linkObjColl"></param>
/// <param name="linkObjAct"></param>
private static void ScanLinkDataObj(DynamicObjectCollection linkObjColl, Action<DynamicObject> linkObjAct) { if (linkObjColl == null) return; foreach (var linkRowObj in linkObjColl)
{
linkObjAct(linkRowObj);
}
} /// <summary>
/// 输出单个link数据包的源单信息
/// </summary>
/// <param name="linkObj"></param>
/// <param name="msgBuilder"></param>
private static void GetLinkMessage(DynamicObject linkObj, StringBuilder msgBuilder) { if (linkObj == null) return; const string fstablename = "STABLENAME"; const string fsid = "SID"; const string fsbillid = "SBILLID"; string sTableName = linkObj[fstablename].ToString(); long sid = Convert.ToInt64(linkObj[fsid]); long sbillId = Convert.ToInt64(linkObj[fsbillid]);
msgBuilder.AppendLine(string.Format("源单实体表名:{0},源单实体分录内码:{1},源单单据内码:{2}", sTableName, sid, sbillId));
} /// <summary>
/// 输出单据内码的关联源单关系
/// </summary>
/// <param name="businessInfo"></param>
/// <param name="billId"></param>
/// <returns></returns>
public static string GetSrcLinkInfoByBillId(BusinessInfo businessInfo, object billId) { return string.Empty;
}
}
}
常见link实体
本文2024-09-16 17:43:49发表“云星空知识”栏目。
本文链接:https://wenku.my7c.com/article/kingdee-k3cloud-17583.html