如上图,代码是参考的应收单到收款单单据转换插件,现在想做一个二开单据下推收款单的单据转换插件,因为想做成自动下推,所以要在插件中给一些必录字段赋值,其中就有“收款用途”。
上图代码在OnAfterCreateLink事件中。不知道如何创建实例来接受收付款用途基础资料的信息,请大神指导!
附上源码
[code]using Kingdee.BOS;
using Kingdee.BOS.App.Core.PlugInProxy;
using Kingdee.BOS.Core;
using Kingdee.BOS.Core.Metadata.ConvertElement.PlugIn.Args;
using Kingdee.BOS.Core.Metadata.EntityElement;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.Resource;
using Kingdee.K3.FIN.Core;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using Kingdee.K3.FIN.CN.App.ServicePlugIn.BillConvertPlugIn;
using Kingdee.BOS.Core.Metadata;
using Kingdee.BOS.Core.SqlBuilder;
using Kingdee.BOS.ServiceHelper;
using Kingdee.BOS.App.Data;
namespace Topview.FT.YPS.App.ServicePlugIn
{
[Description("水单拆分单-收款单单据转换插件")]
public class ReceivableToRecConvert : AbstractCNCommonConvert
{
protected const string RECEIVEBILLENTRY = "RECEIVEBILLENTRY";
protected const string RECEIVEBILLSRCENTRY = "RECEIVEBILLSRCENTRY";
public override void OnAfterCreateLink(CreateLinkEventArgs e)
{
base.OnAfterCreateLink(e);
ExtendedDataEntity[] array = e.TargetExtendedDataEntities.FindByEntityKey("FBillHead");
DynamicFormModelProxy modelProxy = base.GetModelProxy(e);
ExtendedDataEntity[] array2 = array;
for (int i = 0; i < array2.Length; i++)
{
ExtendedDataEntity extendedDataEntity = array2[i];
modelProxy.DataObject = extendedDataEntity.DataEntity;
DynamicObjectCollection dynamicObjectCollection = extendedDataEntity.DataEntity["RECEIVEBILLENTRY"] as DynamicObjectCollection;
if (dynamicObjectCollection != null && dynamicObjectCollection.Count > 0)
{
dynamicObjectCollection.Clear();
}
DynamicObjectCollection source = extendedDataEntity.DataEntity["RECEIVEBILLSRCENTRY"] as DynamicObjectCollection;
decimal d = source.Sum((DynamicObject c) => Convert.ToDecimal(c["REALRECAMOUNT"]));
if (d <= 0m)
{
throw new KDException("", ResManager.LoadKDString("非常抱歉,不满足条件:可下推的金额合计需要大于0。。", "003257000004015", SubSystemType.FIN, new object[0]));
}
Dictionary
from x in source
group x by Convert.ToInt64(x["SRCSETTLETYPEID_Id"])).ToDictionary((IGrouping
int num = 0;
decimal num2 = 0m;
foreach (KeyValuePair
{
Entity entity = e.TargetBusinessInfo.Entrys.FirstOrDefault((Entity c) => c.EntryName.Equals("RECEIVEBILLENTRY", StringComparison.OrdinalIgnoreCase));
modelProxy.CreateNewEntryRow(entity, num);
decimal num3 = current.Value.Sum((DynamicObject x) => Convert.ToDecimal(x["REALRECAMOUNT"]));
dynamicObjectCollection[num]["SETTLETYPEID_ID"] = current.Value[0]["SRCSETTLETYPEID_ID"];//结算方式id
dynamicObjectCollection[num]["SETTLETYPEID"] = current.Value[0]["SRCSETTLETYPEID"];//结算方式
//收付款用途
DynamicObject RecPurposeObj = new DynamicObject(((Kingdee.BOS.Core.Metadata.FieldElement.BaseDataField)(recEntity.Fields[26])).RefFormDynamicObjectType);
DynamicObject tempObj = this.GetRecPayPurposemBD(this.Context, "SFKYT01_SYS", "CN_RECPAYPURPOSE");
RecPurposeObj["Id"] = tempObj["FID"];
RecPurposeObj["Name"] = tempObj["FName"];
RecPurposeObj["Number"] = tempObj["FNumber"];
dynamicObjectCollection[num]["PURPOSEID"] = RecPurposeObj;
dynamicObjectCollection[num]["PURPOSEID_Id"] = tempObj["FID"];
dynamicObjectCollection[num]["RECTOTALAMOUNTFOR"] = num3;
dynamicObjectCollection[num]["SETTLERECAMOUNTFOR"] = num3;
dynamicObjectCollection[num]["REALRECAMOUNTFOR"] = num3;
num2 += num3;
num++;
}
modelProxy.DataObject["RECEIVEAMOUNTFOR"] = num2;
modelProxy.DataObject["REALRECAMOUNTFOR"] = num2;
}
}
//获取收付款用途基础资料
public DynamicObject GetRecPayPurposemBD(Context ctx, string fnumber, string formId)
{
var fid_result = DBUtils.ExecuteDynamicObject(ctx, string.Format("SELECT FID FROM T_CN_RECPAYPURPOSE where FNUMBER = '{0}'",fnumber));
if (fid_result.Count == 0) return null;
List
selector.Add(new SelectorItemInfo("FID"));
selector.Add(new SelectorItemInfo("FNAME"));
selector.Add(new SelectorItemInfo("FNUMBER"));
QueryBuilderParemeter para = new QueryBuilderParemeter()
{
FormId = formId,
FilterClauseWihtKey = string.Format("FID={0}", fid_result[0]["FID"]),
SelectItems = selector
};
DynamicObjectCollection unitData = QueryServiceHelper.GetDynamicObjectCollection(ctx, para);
return unitData.FirstOrDefault();
}
}
}[/code]
推荐阅读