实现表单动态构造
[i]发现2011-8-8写的文章,放到这里供参考[/i]
通过下面几个步骤,可以实现表单动态构造,数据保存等动作全部由平台自动完成。
1、在App_Data/Common.config中增加元数据提供者
2、客户端插件使用这个提供者构造表单元数据:
const string DynFormId = "HR_PA_PayScale|{0}|{1}@HR|PA";
this._fm = MetaDataServiceHelper.GetFormMetaData(this.View.Context, dfId);
在服务端插件的审核后生成表结构。
string entKey = "FBillHead";
string id = "HR_PA_DynItemClass@HR|PA";
IMetadataProvider mp = MetadataProviderFactory.Instance.GetProviderById(id);
FormMetadata fm = mp.GetFormMetadata(this.Context, id) as FormMetadata;
fm.BusinessInfo.GetEntity(entKey).TableName = "T_PA_PayObject_1";
mp.UpdateFormMetadataTable(this.Context, fm);
3、插件中替代当前View的表单元数据:
this.View.ResetCustomMetadata(this.FormMete);
4、定点刷新单据体的列显示:
EntryGrid grid = this.View.GetControl
var egridAp = this.View.LayoutInfo.GetEntityAppearance(this._entityKey);
grid.CreateDyanmicList(egridAp);
5、提供者实现,继承AbstractMetadataProvider抽象基类:
public class HrPayMetadataProvider : AbstractMetadataProvider
6、Override几个方法:
GetFormMetaDataVerion,GetBaseFormId,DynaAssemblyFormMeta,
7、在DynaAssemblyFormMeta(Context ctx, DomainAsm da, string sourceId)中动态组装元数据。本例中sourceId就是"HR_PA_PayScale|{0}|{1}@HR|PA";
依据自定义组装的sourceId,进行动态load数据,元数据动态组装。
元数据动态组装参考代码如下:
public override void DynaAssemblyFormMeta(Context ctx, DomainAsm da, string sourceId)
{
string key = "FBase";
string entHeadKey = "FBillHead";
string entKey = "FEntity";
da.Fm.BusinessInfo.GetEntity(entHeadKey).TableName = "T_PA_PayPeriodTime";
da.Fm.BusinessInfo.GetEntity(entKey).TableName = "T_PA_PayObject";
da.Fm.BusinessInfo.GetEntity(entKey).SplitTables.Add(new SplitTable() { Suffix = "1" });
ElementType type = da.Dm.GetElementType((int)ENUM_PayItemElementType.NUM);
ElementAsm ea = this.CreateField(da.Fm, key, type, "", entKey, true);
Appearance ap = ea.Ap;
DecimalField el = ea.El as DecimalField;
el.Id = key;
el.Key = key;
el.Name = new LocaleValue("基本工资", ctx.UserLocale.LCID);
el.Suffix = "1";
el.QkQueryTabIndex = 1;
el.FieldScale = 4;
el.FieldPrecision = 10;
ap.Id = key;
ap.Key = key;
ap.Width = new LocaleValue("120",ctx.UserLocale.LCID);
ap.Caption = new LocaleValue("基本工资", ctx.UserLocale.LCID);
key = "FReal";
type = da.Dm.GetElementType((int)ENUM_PayItemElementType.NUM);
ea = this.CreateField(da.Fm, key, type, "", entKey, true);
ap = ea.Ap;
el = ea.El as DecimalField;
el.Id = key;
el.Key = key;
el.Name = new LocaleValue("实发工资", ctx.UserLocale.LCID);
el.Suffix = "1";
el.QkQueryTabIndex = 2;
el.FieldScale = 4;
el.FieldPrecision = 10;
ap.Id = key;
ap.Key = key;
ap.Width = new LocaleValue("120", ctx.UserLocale.LCID);
ap.Caption = new LocaleValue("实发工资", ctx.UserLocale.LCID);
}
切换方案前:
切换方案后:
数据自动存储:
涉及组件:
kingdee.bos.App.core,
kingdee.bos.core,
kingdee.bos.web,
kingdee.bos.web.core,
k3cloudserver/app_data/common.config,
实现表单动态构造
本文2024-09-23 03:47:51发表“云星空知识”栏目。
本文链接:https://wenku.my7c.com/article/kingdee-k3cloud-161165.html