单据转换插件 分组策略无效
1,299次浏览
编辑于2017年03月20日 16:58:37
K3/cloud 6。1
单据转换插件实现后,如果分组策略:多对一生成,是正常的。如果选了一对一生成,在上游多选后,生成的下游单,会变成第一单有多行,第二单没有行,就是明细全跑到第一单里了,请问要插件里还要加什么设置?
插件代码是参考资料里单据转换插件里的AfterConvert事件来做的。
附代码:
public override void AfterConvert(AfterConvertEventArgs e)
{
var eRows = e.Result.FindByEntityKey("FRECEIVEBILLSRCENTRY");
HashSet hs = new HashSet();
foreach(var row in eRows){
DynamicObject rowObj = row.DataEntity;
long srcBillId = Convert.ToInt64(rowObj["SRCBILLID"]);
if(srcBillId ==0){
continue;
}
if(hs.Contains(srcBillId) ==false){
hs.Add(srcBillId);
}
}
Kingdee.BOS.Contracts.IViewService viewService = Kingdee.BOS.App.ServiceHelper.GetService();
object[] pkValues = (from p in hs select (object)p).ToArray();
var srcObjs = viewService.Load(this.Context,pkValues,e.SourceBusinessInfo.GetDynamicObjectType());
Dictionary dctSrcObjs = srcObjs.ToDictionary(t => Convert.ToInt64(t[0]));
var targetBillObj = e.Result.FindByEntityKey("FBillHead");
DynamicObjectCollection packageRows = targetBillObj[0].DataEntity["RECEIVEBILLENTRY"] as DynamicObjectCollection;
packageRows.Clear();
foreach (var item in hs)
{
var srcObj = dctSrcObjs[item];
DynamicObjectCollection srcPackageRows = srcObj["RECCONFIRENTRY"] as DynamicObjectCollection;
foreach (var srcPackageRow in srcPackageRows)
{
DynamicObject packageRow = new DynamicObject(e.TargetBusinessInfo.GetEntity("FRECEIVEBILLENTRY").DynamicObjectType);
packageRow["SETTLENO"] = srcPackageRow["SETTLENO"];
packageRow["ACCOUNTID_Id"] = srcPackageRow["ACCOUNTID_Id"];
var mtrtype = (e.TargetBusinessInfo.GetField("FACCOUNTID") as BaseDataField).RefFormDynamicObjectType;
packageRow["ACCOUNTID"] = BusinessDataServiceHelper.LoadSingle(this.Context, srcPackageRow["ACCOUNTID_Id"], mtrtype);
packageRow["RECTOTALAMOUNTFOR"] = srcPackageRow["REALRECAMOUNTFOR_D"];
packageRow["RECAMOUNTFOR_E"] = srcPackageRow["REALRECAMOUNTFOR_D"];
packageRow["REALRECAMOUNTFOR"] = srcPackageRow["REALRECAMOUNTFOR_D"];
packageRow["OPPOSITEBANKACCOUNT"] = srcPackageRow["OPPOSITEBANKACNTNO"];
packageRow["OPPOSITECCOUNTNAME"] = srcPackageRow["OPPOSITECCOUNTNAME"];
packageRow["OPPOSITEBANKNAME"] = srcPackageRow["OPPOSITEBANKNAME"];
packageRow["RECTOTALAMOUNT"] = srcPackageRow["REALRECAMOUNTFOR_D"];
packageRow["FREALRECAMOUNT"] = srcPackageRow["REALRECAMOUNTFOR_D"];
packageRow["RECAMOUNT_E"] = srcPackageRow["REALRECAMOUNTFOR_D"];
packageRow["COMMENT"] = srcPackageRow["EXPLANATION"];
packageRow["FPOSTDATE"] = System.DateTime.Now;
//packageRow["FEntryID"] =srcPackageRow[""]
packageRows.Add(packageRow);
}
}
base.AfterConvert(e);
}
单据转换插件实现后,如果分组策略:多对一生成,是正常的。如果选了一对一生成,在上游多选后,生成的下游单,会变成第一单有多行,第二单没有行,就是明细全跑到第一单里了,请问要插件里还要加什么设置?
插件代码是参考资料里单据转换插件里的AfterConvert事件来做的。
附代码:
public override void AfterConvert(AfterConvertEventArgs e)
{
var eRows = e.Result.FindByEntityKey("FRECEIVEBILLSRCENTRY");
HashSet
foreach(var row in eRows){
DynamicObject rowObj = row.DataEntity;
long srcBillId = Convert.ToInt64(rowObj["SRCBILLID"]);
if(srcBillId ==0){
continue;
}
if(hs.Contains(srcBillId) ==false){
hs.Add(srcBillId);
}
}
Kingdee.BOS.Contracts.IViewService viewService = Kingdee.BOS.App.ServiceHelper.GetService
object[] pkValues = (from p in hs select (object)p).ToArray();
var srcObjs = viewService.Load(this.Context,pkValues,e.SourceBusinessInfo.GetDynamicObjectType());
Dictionary
var targetBillObj = e.Result.FindByEntityKey("FBillHead");
DynamicObjectCollection packageRows = targetBillObj[0].DataEntity["RECEIVEBILLENTRY"] as DynamicObjectCollection;
packageRows.Clear();
foreach (var item in hs)
{
var srcObj = dctSrcObjs[item];
DynamicObjectCollection srcPackageRows = srcObj["RECCONFIRENTRY"] as DynamicObjectCollection;
foreach (var srcPackageRow in srcPackageRows)
{
DynamicObject packageRow = new DynamicObject(e.TargetBusinessInfo.GetEntity("FRECEIVEBILLENTRY").DynamicObjectType);
packageRow["SETTLENO"] = srcPackageRow["SETTLENO"];
packageRow["ACCOUNTID_Id"] = srcPackageRow["ACCOUNTID_Id"];
var mtrtype = (e.TargetBusinessInfo.GetField("FACCOUNTID") as BaseDataField).RefFormDynamicObjectType;
packageRow["ACCOUNTID"] = BusinessDataServiceHelper.LoadSingle(this.Context, srcPackageRow["ACCOUNTID_Id"], mtrtype);
packageRow["RECTOTALAMOUNTFOR"] = srcPackageRow["REALRECAMOUNTFOR_D"];
packageRow["RECAMOUNTFOR_E"] = srcPackageRow["REALRECAMOUNTFOR_D"];
packageRow["REALRECAMOUNTFOR"] = srcPackageRow["REALRECAMOUNTFOR_D"];
packageRow["OPPOSITEBANKACCOUNT"] = srcPackageRow["OPPOSITEBANKACNTNO"];
packageRow["OPPOSITECCOUNTNAME"] = srcPackageRow["OPPOSITECCOUNTNAME"];
packageRow["OPPOSITEBANKNAME"] = srcPackageRow["OPPOSITEBANKNAME"];
packageRow["RECTOTALAMOUNT"] = srcPackageRow["REALRECAMOUNTFOR_D"];
packageRow["FREALRECAMOUNT"] = srcPackageRow["REALRECAMOUNTFOR_D"];
packageRow["RECAMOUNT_E"] = srcPackageRow["REALRECAMOUNTFOR_D"];
packageRow["COMMENT"] = srcPackageRow["EXPLANATION"];
packageRow["FPOSTDATE"] = System.DateTime.Now;
//packageRow["FEntryID"] =srcPackageRow[""]
packageRows.Add(packageRow);
}
}
base.AfterConvert(e);
}
推荐阅读