多单据体单据转换插件转换后的数据保存不成功
金蝶云社区-云小爱
云小爱
0人赞赏了该文章 2,084次浏览 未经作者许可,禁止转载编辑于2014年05月16日 08:53:36

一个单据有多个单据体,只好在插件中实现单据体的转换,单据转换成功,生成的单据上显示的数据正确,但保存后有些基础资料数据没保存成功

代码:

[Description("采购合同转采购订单插件")]
public class PurContractToPurOrderConvert : AbstractConvertPlugIn
{
private DynamicObjectCollection sourceDatas;
private DynamicObject sourceBill;
object fid;
public override void OnGetSourceData(Kingdee.BOS.Core.Metadata.ConvertElement.PlugIn.Args.GetSourceDataEventArgs e)
{
base.OnGetSourceData(e);

sourceDatas = e.SourceData;
fid = e.SourceData[0]["FId"];
if (!fid.IsNullOrEmptyOrWhiteSpace())
sourceBill = ServiceHelper.GetDynamicObject(fid.ToString(), "001_PurContract", this.Context);
}

public override void AfterConvert(Kingdee.BOS.Core.Metadata.ConvertElement.PlugIn.Args.AfterConvertEventArgs e)
{
base.AfterConvert(e);

ExtendedDataEntity[] datas = e.Result.FindByEntityKey("FBillHead");
foreach (var data in datas)
{
Entity entity = e.TargetBusinessInfo.GetEntity("FPOOrderClause");

DynamicObjectCollection entryObjCollection = data.DataEntity["POOrderClause"] as DynamicObjectCollection;
if (entryObjCollection == null)
entryObjCollection = new DynamicObjectCollection(entity.DynamicObjectType, data.DataEntity);
else
entryObjCollection.Clear();

if (sourceBill != null)
{
DynamicObjectCollection sourceObjCollection = sourceBill["PurContractClause"] as DynamicObjectCollection;
if (sourceObjCollection != null)
{
foreach (var entry in sourceObjCollection)
{
try
{
DynamicObject newRow = new DynamicObject(entity.DynamicObjectType);

newRow["ClauseId"] = entry["ClauseId"]; //转换成功,但保存不成功
newRow["ID"] = fid;
newRow["ClauseDesc"] = entry["ClauseDesc"];
entryObjCollection.Add(newRow);
}
catch
{
}
}
}
}

// 对每个单据的全部行,进行行序号重排
int seq = 1;
foreach (var entityRow in entryObjCollection)
{
entity.SeqDynamicProperty.SetValue(entityRow, seq);
seq++;
}
}

}

}