【二开插件】动态创建单据体字段

栏目:云星空知识作者:金蝶来源:金蝶云社区发布:2024-09-16浏览:1

【二开插件】动态创建单据体字段

        /// 元数据
        private BusinessInfo _currInfo = null;
        /// 界面布局
        private LayoutInfo _currLayout = null;
        
        public override void ButtonClick(ButtonClickEventArgs e){
                    base.ButtonClick(e);
                        if (e.Key.EqualsIgnoreCase("F_BDI_Button_83g"))
                        {
                            // 修改元数据
                            this.ReBuildFields();
                            // 根据新的元数据,重构单据体表格列
                            EntryGrid grid = this.View.GetControl<EntryGrid>("FList");//单据体标识FList
                            grid.SetAllowLayoutSetting(false); // 列按照索引显示
                            EntityAppearance listAppearance = _currLayout.GetEntityAppearance("FList");
                            grid.CreateDyanmicList(listAppearance);
            
                            // 填充数据
                            this.SetData();
                            // 下达一个指令
                            this.View.SendDynamicFormAction(this.View);
                        }
        }
         #region 动态创建列
        public override void OnSetBusinessInfo(SetBusinessInfoArgs e)
        {
            // 复制界面元数据到本地变量
            FormMetadata currMeta = (FormMetadata)ObjectUtils.CreateCopy(
            this.View.OpenParameter.FormMetaData);
            _currInfo = currMeta.BusinessInfo;
            _currLayout = currMeta.GetLayoutInfo();
            // 用本地的元数据,替换动态表单引擎持有的元数据
            e.BusinessInfo = _currInfo;
            e.BillBusinessInfo = _currInfo;
        }
        /// 通常在此事件中,修改界面元数据;
        /// 本示例,在此事件中,把界面元数据复制到本地,避免与其他实例公用元数据,造成串账
        public override void OnSetLayoutInfo(SetLayoutInfoArgs e)
        {
            e.LayoutInfo = _currLayout;
            e.BillLayoutInfo = _currLayout;
        }

        private void SetData()
        {
            // 使用最新的元数据,重新界面数据包
            _currInfo.GetDynamicObjectType(true);
           this.Model.CreateNewData();
            this.View.Model.CreateNewEntryRow("FList");
            foreach (Field fld in _currInfo.GetEntity("FList").Fields)
            {
                this.Model.SetValue(fld.Key, 1, 0);
            }
            this.View.Model.CreateNewEntryRow("FList");
            foreach (Field fld in _currInfo.GetEntity("FList").Fields)
            {
                this.Model.SetValue(fld.Key, 1.1, 1);
            }
        }
        private void ReBuildFields()
        {
            // 获取单据体表格的元数据及外观
            Entity entity = _currInfo.GetEntity("FList");
            EntityAppearance entityApp = _currLayout.GetEntityAppearance("FList");
            // 清除全部字段
            int oldCount = entity.Fields.Count;
            for (int i = oldCount - 1; i >= 0; i--)
            {
                Field fld = entity.Fields[i];
                _currInfo.Remove(fld);
                Appearance fldApp = _currLayout.GetAppearance(fld.Key);
                _currLayout.Remove(fldApp);
            }


            // 重新添加字段
            for (int i = 1; i <= 3; i++)
            {
                // 构建文本字段
                //TextField fld = new TextField();
                //fld.Key = string.Format("F{0}", i);
                //fld.Name = new LocaleValue(string.Format("字段{0}", i));
                //fld.PropertyName = fld.Key;
                //fld.EntityKey = "FList";
                //fld.Entity = entity;
                //_currInfo.Add(fld);
                //TextFieldAppearance fldApp = new TextFieldAppearance();
                //fldApp.Key = fld.Key;
                //fldApp.Caption = fld.Name;
                //fldApp.EntityKey = fld.EntityKey;
                //fldApp.Width = new LocaleValue("150");
                //fldApp.LabelWidth = new LocaleValue("80");
                //fldApp.Tabindex = i;
                //fldApp.Field = fld;
                //_currLayout.Add(fldApp); 

                DecimalField fld = new DecimalField();
                fld.Key = string.Format("F{0}", i);
                fld.Name = new LocaleValue(string.Format("字段{0}", i));
                fld.PropertyName = fld.Key;
                fld.EntityKey = "FList";
                fld.FieldScale = 2;//精度
                fld.FieldPrecision = 10;
                fld.Entity = entity;
                _currInfo.Add(fld);
                DecimalFieldAppearance fldApp = new DecimalFieldAppearance();
                fldApp.Key = fld.Key;
                fldApp.Caption = fld.Name;
                fldApp.EntityKey = fld.EntityKey;
                fldApp.Width = new LocaleValue("80");
                fldApp.LabelWidth = new LocaleValue("80");
                fldApp.Tabindex = i;
                fldApp.Field = fld;
                _currLayout.Add(fldApp);

            }
        }

        #endregion


参考链接:

  1. 小技巧 - 如何在运行中,动态创建单据体字段

  2. 插件案例 —— 动态构建控件,让你前端显示异常灵活

【二开插件】动态创建单据体字段

/// 元数据 private BusinessInfo _currInfo = null; /// 界面布局 private LayoutInfo _currLayout = null;...
点击下载文档
确认删除?
回到顶部
客服QQ
  • 客服QQ点击这里给我发消息