上才艺:
/// <summary>
/// 关联关系子表已经创建并填写完毕后触发,
/// 此时,已经在关联子表中,记录了源单与目标单之间的关系
/// </summary>
/// <param name="e"></param>
/// <remarks>
/// 可以在此事件中,对关联关系子表内容进行调整,
/// </remarks>
public override void OnAfterCreateLink(CreateLinkEventArgs e)
{
#region
// 获取源单子单据体元数据
//SubEntryEntity YsubEntity = e.SourceBusinessInfo.GetEntity("FNoticeBOMSubEntry") as SubEntryEntity;
// 获取目标子单据体元数据
SubEntryEntity subEntity = e.TargetBusinessInfo.GetEntity("FSerialSubEntity") as SubEntryEntity;
// 获取子单据体行中的一个文本字段:创建新行时要对此字段赋值
//序列号
Field FSerialNo = e.TargetBusinessInfo.GetField("FSerialNo");
//备注
Field FSerialNote = e.TargetBusinessInfo.GetField("FSerialNote");
//锻批号
Field F_PALE_DPH = e.TargetBusinessInfo.GetField("F_PALE_DPH");
//客户序列号
Field F_PALE_KHXLH = e.TargetBusinessInfo.GetField("F_PALE_KHXLH");
//锭节号
Field F_PALE_DJH = e.TargetBusinessInfo.GetField("F_PALE_DJH");
//BaseDataField FMater = e.TargetBusinessInfo.GetField("FMaterialIdBOM") as BaseDataField;
//BaseDataField FUnit = e.TargetBusinessInfo.GetField("FUnitIDUint") as BaseDataField;
// 获取目标单据体
var entryRows = e.TargetExtendedDataEntities.FindByEntityKey("FEntity");
//var entryRows = e.Result.FindByEntityKey("FEntity");
foreach (var entryRow in entryRows)
{
// 获取当前单据体行的子单据体行集合
DynamicObjectCollection subEntryRows = subEntity.DynamicProperty.GetValue(entryRow.DataEntity) as DynamicObjectCollection;
DynamicObject rowObj = entryRow.DataEntity;
DynamicObjectCollection linkRows = rowObj["FEntity_Link"] as DynamicObjectCollection;
foreach (var linkRow in linkRows)
{
string sql = "/*dialect*/select FSerialNo,FSerialId,FSerialNote,F_PALE_DPH,F_PALE_KHXLH,F_PALE_DJH from PALE_WWYLQD_XLH where FEntryID=" + linkRow["Sid"];
DataSet ds = DBUtils.ExecuteDataSet(this.Context, sql);
DataTable dt = ds.Tables[0];
if (dt.Rows.Count > 0)
{
for (int i = 0; i < dt.Rows.Count; i++)
{
// 创建子单据体行数据包
DynamicObject newRow = new DynamicObject(subEntity.DynamicObjectType);
if (dt.Rows[i]["F_PALE_DPH"] != null)
{
IViewService viewService = ServiceHelper.GetService<IViewService>();
F_PALE_DPH.DynamicProperty.SetValue(newRow, dt.Rows[i]["F_PALE_DPH"].ToString());
FSerialNote.DynamicProperty.SetValue(newRow, dt.Rows[i]["FSerialNote"].ToString());
FSerialNo.DynamicProperty.SetValue(newRow, dt.Rows[i]["FSerialNo"].ToString());
F_PALE_KHXLH.DynamicProperty.SetValue(newRow, dt.Rows[i]["F_PALE_KHXLH"].ToString());
F_PALE_DJH.DynamicProperty.SetValue(newRow, dt.Rows[i]["F_PALE_DJH"].ToString());
// 把创建的新行,添加到子单据体行集合中
subEntryRows.Add(newRow);
}
}
}
}
}
#endregion
}
这种方法是通过关联表查询关联从而进行子单据体的携带,这样携带的子单据体是没得序号的,我们可以在转换完事件内对子单据体的序号进行赋值
/// <summary>
/// 单据从源单到目标单已经转换完毕,输出最后的目标单数据包之前触发,
/// 此时,目标单数据包已经构建完毕,不会再有变动了
/// </summary>
/// <param name="e"></param>
/// <remarks>
/// 可以在此事件中,对目标单数据包进行最后的修订、补充
/// </remarks>
public override void AfterConvert(AfterConvertEventArgs e)
{
#region
//目标单
ExtendedDataEntity[] heads = e.Result.FindByEntityKey("FBillHead");
List<DynamicObject> list = new List<DynamicObject>();
foreach (var head in heads)
{
DynamicObject dataEntity = head.DataEntity;
//目标单单据实体
DynamicObjectCollection FPOOrderEntry = dataEntity["Entity"] as DynamicObjectCollection;
for (int i = 0; i < FPOOrderEntry.Count(); i++)
{
//序列号单据体实体
DynamicObjectCollection PALE_CGDD_XLH = FPOOrderEntry[i]["SUB_FEEDMTRLSERIAL"] as DynamicObjectCollection;
for (int j = 0; j < PALE_CGDD_XLH.Count(); j++)
{
PALE_CGDD_XLH[j]["Seq"] = j + 1;
}
}
}
#endregion
}
分享不易,若有抄袭请及时联系
推荐阅读