1.3.3 动态表单 - 创建数据包
金蝶云社区-云小爱
云小爱
4人赞赏了该文章 9,767次浏览 未经作者许可,禁止转载编辑于2014年04月02日 17:09:32

创建数据包 CreateNewData 动态表单数据包创建,只在新增时触发,打开表单不触发。我们在IDE里画好单据和基础资料后,不需要编写任何代码,打开界面,可以看到已经创建好一张新的空单据,这是因为新建时候会调用CreateNewRow创建空数据。很多时候,我们需要创建有缺省值或者新增时候从其他服务获取数据显示过来,我们就可以通过该事件来加载数据。
示例:简单的加载动态表单数据。


[tr][td]C#
[td]


[tr][td=2,1]public override void CreateNewData(BizDataEventArgs e){ if (!billFormId.IsNullOrEmptyOrWhiteSpace()) { DynamicObject obj = BusinessDataServiceHelper.LoadBillTypePara(context, businessInfo, formId, false); e.BizDataObject = obj; } base.CreateNewData(e);}


示例:操作结束后,在动态表单上显示操作结果。
[tr][td]C#
[td]


[tr][td=2,1]///

/// 创建数据包事件处理;由插件处理数据包的创建过程,界面仅展示/// /// public override void CreateNewData(BizDataEventArgs e){ // 创建本界面需要的数据对象 e.BizDataObject = new DynamicObject(this.View.OpenParameter.FormMetaData.BusinessInfo.GetDynamicObjectType());
BusinessInfo info = this.View.OpenParameter.FormMetaData.BusinessInfo;
// 给角色表格赋值 Entity resultEntity = info.GetEntity("FEntity");
Field seqField = info.GetField("FSeq"); Field nameField = info.GetField("FName"); Field statusField = info.GetField("FStatus"); Field messageField = info.GetField("FMessage"); Field typeField = info.GetField("FType");
DynamicObjectCollection resultEntityData = (DynamicObjectCollection)resultEntity.DynamicProperty.GetValue(e.BizDataObject);
int row = 0; foreach (OperateResult rowResult in _results) { // 添加新行 DynamicObject rowData = new DynamicObject(resultEntity.DynamicObjectType);
// 给行中的字段赋值 seqField.DynamicProperty.SetValue(rowData, row + 1); nameField.DynamicProperty.SetValue(rowData, rowResult.Name); statusField.DynamicProperty.SetValue(rowData, (rowResult.SuccessStatus ? "1" : "0")); messageField.DynamicProperty.SetValue(rowData, rowResult.Message); typeField.DynamicProperty.SetValue(rowData, ((int)rowResult.MessageType).ToString()); resultEntityData.Add(rowData); row++; }}


自定义动态表单动态实体创建过程。
[tr][td]C#
[td]


[tr][td=2,1]public override void CreateNewData(BizDataEventArgs e){ QueryBuilderParemeter para=new QueryBuilderParemeter() { FormId= FormIdConst.BOS_ConsoleDetailFunc }; para.SelectItems.Add(new SelectorItemInfo("FName"));
QueryObject o= QueryServiceHelper.GetQueryObject(this.Context, para); //重新构造对象实体类型 HeadEntity headEntity = (HeadEntity)this.View.BusinessInfo.GetEntity(0);
//构造当前表单单据头动态实体类型 DynamicObjectType objType = BusinessInfo.BuilderHeaderDataType(this.View.BusinessInfo.GetForm(), headEntity); headEntity.DynamicObjectType = objType;
Entity gridEntity = this.View.BusinessInfo.Entrys[1];
//构造功能明细单据头动态实体类型的 Entity entity = _funcInfo.GetEntity(0); entity.DynamicObjectType = BusinessInfo.BuilderHeaderDataType(_funcInfo.GetForm(), (HeadEntity)entity);
gridEntity.DynamicProperty = objType.RegisterCollectionProperty(this._entityKey, entity.DynamicObjectType); gridEntity.DynamicObjectType = entity.DynamicObjectType;
entity = this.View.BusinessInfo.GetEntity(2); entity.DynamicObjectType=BusinessInfo.BuilderEntryDataType(entity); entity.DynamicProperty= objType.RegisterCollectionProperty(entity.Key, entity.DynamicObjectType); foreach (Field field in gridEntity.Fields) { Field srcField = _funcInfo.GetField(field.Key); if (srcField != null) { field.DynamicProperty = srcField.DynamicProperty; if (field is BaseDataField) { BaseDataField basedataField = (BaseDataField)field; BaseDataField srcBasedataField = (BaseDataField)srcField; basedataField.RefFormDynamicObjectType = srcBasedataField.RefFormDynamicObjectType; basedataField.RefIDDynamicProperty = srcBasedataField.RefIDDynamicProperty; } } } //读取明细功能对象列表 DynamicObject[] objs = BusinessDataServiceHelper.Load(this.View.Context, FormIdConst.BOS_ConsoleDetailFunc, null, null);
//新建当前实体对象 DynamicObject dataObject = new DynamicObject(objType); //将明细功能对象列表作为单据体数据加入 DynamicObjectCollection entryDataObject = gridEntity.DynamicProperty.GetValue(dataObject); foreach (DynamicObject obj in objs) { entryDataObject.Add(obj); } e.BizDataObject = dataObject;}

AfterCreateNewEntryRow 创建分录行后事件。字段值设置优先考虑使用IDE进行实体服务规则配置。该事件通常用于新增分录后对数据进行判断处理。需要注意,这个事件是在每次新增分录都会触发,对于不需要在界面上显示的可以在新建分录后(如AfterCreateNewData事件)一次性处理。


[tr][td]C#
[td]


[tr][td=2,1]///

/// 创建新的分录行事件/// /// public override void AfterCreateNewEntryRow(CreateNewEntryEventArgs e){ base.AfterCreateNewEntryRow(e);
if (e.Entity.Key.Equals(CONST_ENG_Route.CONST_FSubEntity.ENTITY_FSubEntity)) { IEnumerable subEntryDataCol = this.Model.GetEntityDataObject(e.Entity); if (e.Row == subEntryDataCol.Count() - 1) // 插入行不赋值 { // 设置工序号=上取整((MAX(工序号)+1)/10)*10,且不大于9999 int maxOperNumber = subEntryDataCol.Select(w => w.GetDynamicObjectItemValue(CONST_ENG_Route.CONST_FSubEntity.ORM_OperNumber)).Max(); int newOperNumber = (int)Math.Ceiling(((decimal)maxOperNumber + 1) / 10) * 10; this.Model.SetValue(CONST_ENG_Route.CONST_FSubEntity.KEY_FOperNumber, newOperNumber > 9999 ? 9999 : newOperNumber, e.Row); } }}

AfterCreateNewData 动态表单数据包创建后事件。该方法仅在新增表单后触发。主要用于新建表达根据元数据定义初始化数据包后,根据特殊需求,改变当前数据。通常我们在IDE里通过配置实体服务规则实现表单字段的缺省值赋值:但有时需要根据一些参数动态设置值时,就需要用插件实现。下面举一个例子,新增单据时根据当前组织获取邮件的缺省值,赋值到当前数据包。


[tr][td]C#
[td]


[tr][td=2,1]public override void AfterCreateNewData(EventArgs e){ base.AfterCreateNewData(e); OQLFilter ofilter = new OQLFilter(); ofilter.Add(new OQLFilterHeadEntityItem { FilterString = string.Format(" FORGID ={0} ", this.Model.Context.CurrentOrganizationInfo.ID) });
DynamicObject[] obj = BusinessDataServiceHelper.Load(this.View.Context, "BAS_MAILDEFAULTSET", null, ofilter); if (obj != null && obj.Count() > 0) { DynamicObject defaultSet = obj[0]; this.View.Model.SetValue("FMessageType", defaultSet["FMessageType"]); this.View.Model.SetValue("FServer", defaultSet["FOutgoingMailServer"]); this.View.Model.SetValue("FSMTPPort", defaultSet["FSMTPPort"]); }}

因为该插件属于创建数据包,在该插件里设置的值不会加到状态管理器中,因此该方法设置的值是整个数据包一起发送到客户端的。客户端数据可以通过Http数据监控查询:
AfterCreateModelData
模型层数据包创建完毕。该事件只在新增表单模型后触发,用于对新增后表单模型进行相关操作。此插件的操作不会引起Model.DataChanged值改变。例:订单变更查询中,需要在界面上,根据查询列表中的版本显示订单内容,在打开查询时缺省打开第一行基准版本的订单。插件代码:
[tr][td]C#
[td]


[tr][td=2,1]///

/// 模型数据包创建完毕,显示订单界面/// /// public override void AfterCreateModelData(EventArgs e){ if (listVersions != null && listVersions.Count() > 0) { baseOrderData = SCMCommon.DeserializeJsonStringToDynamicObject(orderBusinessInfo, listVersions[0].JsonData); ShowOrderBillVersion(); }}