【应用场景】 使用表单插件赋值单据体、子单据体。
【案例演示】使用动态表单,演示插件赋值单据体,子单据体。
BOS中界面如上图所示,子单据体需绑定父级单据体(父分录)。
代码示例:
public override void AfterBindData(EventArgs e)
{
base.AfterBindData(e);
this.BindOrderInfo();
}
private void BindNeedAuditOrderInfo()
{
//从SQL结果中获取单据体,子单据体数据
string sql = "";
DynamicObjectCollection DyObjs = DBServiceHelper.ExecuteDynamicObject(this.Context, sql);
// 获取单据体数据包
DynamicObjectCollection Entrys = this.View.Model.DataObject["Entity"] as DynamicObjectCollection;
if (DyObjs != null && DyObjs.Count > 0)
{
foreach (var dyObj in DyObjs)
{
//创建新的单据体分录行
DynamicObject entry = Entrys.DynamicCollectionItemPropertyType.CreateInstance() as DynamicObject;
entry["SEQ"] = Entrys.Count + 1;
entry["FSaleOrgId_Id"] = dyObj["FSALEORGID"];
entry["FSalerId_Id"] = dyObj["FSALERID"];
entry["FCustomer_Id"] = dyObj["FCUSTOMER"];
entry["FClothingSeries_Id"] = dyObj["FCLOTHINGSERIES"];
#region 子单据体赋值
string sql = string.Format("SELECT * FROM T_SAL_QuotProcess WHERE FENTRYID = {0}", dyObj["FENTRYID"]);
DynamicObjectCollection objs = DBServiceHelper.ExecuteDynamicObject(this.Context, sql);
if (objs.Count > 0)
{
//子单据体数据包
EntryEntity entryRow = this.View.BusinessInfo.GetEntryEntity("FProcessEntry");
DynamicObjectCollection subEntryRows = entryRow.DynamicProperty.GetValue(entry) as DynamicObjectCollection;
foreach (var obj in objs)
{
//创建新的子单据体分录行
DynamicObject subEntry = subEntryRows.DynamicCollectionItemPropertyType.CreateInstance() as DynamicObject;
subEntry["SEQ"] = obj["FSEQ"];
subEntry["FSpecialProcess"] = obj["FSPECIALPROCESS"];
subEntry["FSourceDetailID"] = obj["FDETAILID"];
// 添加到子单据体数据包
subEntryRows.Add(subEntry);
}
}
#endregion
// 添加到单据体数据包
Entrys.Add(entry);
}
// 重新加载数据包
DBServiceHelper.LoadReferenceObject(this.Context, Entrys.ToArray(), Entrys.FirstOrDefault().DynamicObjectType, false);
}
}
代码块解析:
1.新增单据体行数据包
Entrys.DynamicCollectionItemPropertyType.CreateInstance() as DynamicObject;
2.新增子单据体行数据包
subEntryRows.DynamicCollectionItemPropertyType.CreateInstance() as DynamicObject;
3.由于基础资料字段赋值是赋值的_Id,所以需要重新加载基础资料字段数据包
DBServiceHelper.LoadReferenceObject(this.Context, Entrys.ToArray(), Entrys.FirstOrDefault().DynamicObjectType, false);
推荐阅读