运行期动态构造表单模型(一)
2,061次浏览
编辑于2013年06月20日 10:27:45
过下面几个步骤,可以实现表单动态构造,数据保存等动作全部由平台自动完成。
1、在App_Data/Common.config中增加元数据提供者
2、客户端插件使用这个提供者构造表单元数据:
const string DynFormId = "HR_PA_PayScale|{0}|{1}@HR|PA";
this._fm = MetaDataServiceHelper.GetFormMetaData(this.View.Context, dfId);
3、插件中替代当前View的表单元数据:
this.View.ResetCustomMetadata(this.FormMete);
4、定点刷新单据体的列显示:
EntryGrid grid = this.View.GetControl(this._entityKey);
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);
}
1、在App_Data/Common.config中增加元数据提供者
2、客户端插件使用这个提供者构造表单元数据:
const string DynFormId = "HR_PA_PayScale|{0}|{1}@HR|PA";
this._fm = MetaDataServiceHelper.GetFormMetaData(this.View.Context, dfId);
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);
}
推荐阅读