二开案例.获取所有单据的表名、字段信息原创
83人赞赏了该文章
576次浏览
编辑于2024年07月15日 17:29:25
using Kingdee.BOS.App.Data; using Kingdee.BOS.Core.DynamicForm.PlugIn; using Kingdee.BOS.Core.DynamicForm.PlugIn.Args; using Kingdee.BOS.Core.Metadata; using Kingdee.BOS.ServiceHelper; using Kingdee.BOS.Util; using System.Linq; namespace Test2024 { [Kingdee.BOS.Util.HotUpdate] public class 获取单据字段信息 : AbstractDynamicFormPlugIn { public override void ButtonClick(ButtonClickEventArgs e) { //导出所有数据速度很慢,这里取前10个单据为例 var formIds = DBUtils.ExecuteDynamicObject(this.Context, "select top 10 fid from T_META_OBJECTTYPE where FMODELTYPEID in (400,100) and FDEVTYPE in (0,1) order by FID desc") .Select(dyo => dyo["fid"].ToString()).ToList(); var data = formIds.Select(formId => { var meta = MetaDataServiceHelper.Load(this.Context, formId, true) as FormMetadata; var fields = meta.BusinessInfo.GetFieldList(); var fieldInfos = fields.Select(f => { var app = meta.GetLayoutInfo().GetFieldAppearance(f.Key); var entity = meta.BusinessInfo.GetEntity(f.EntityKey); var sql = string.Format(@"SELECT DATA_TYPE, CHARACTER_MAXIMUM_LENGTH FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = 'dbo' AND TABLE_NAME = '{0}' and COLUMN_NAME = '{1}'", entity.TableName, f.FieldName); var dyo = DBUtils.ExecuteDynamicObject(this.Context, sql).FirstOrDefault(); return new { 表名 = entity.TableName, 标识 = f.Key, 标题 = app.Caption.ToString(), 字段名称 = f.FieldName, 属性名 = f.PropertyName, 字段类型 = dyo == null ? "" : (dyo["DATA_TYPE"].ToString() + "(" + dyo["CHARACTER_MAXIMUM_LENGTH"] + ")") }; }).ToArray(); return new { formId, fieldInfos }; }); var json = JsonUtil.Serialize(data); this.View.ShowMessage(json); } } }
赞 83
83人点赞
还没有人点赞,快来当第一个点赞的人吧!
打赏
0人打赏
还没有人打赏,快来当第一个打赏的人吧!
推荐阅读