二开-列表批改功能实现原创
金蝶云社区-墨白64
墨白64
93人赞赏了该文章 1510次浏览 未经作者许可,禁止转载编辑于2023年09月13日 15:57:20
封面

一,需求

    在列表上实现批量修改选定单据的修改人,创建人等数据信息,修改选定数据行单据的所有字段类型为用户的字段。

 

二,实现方式  

      新增一个动态表单,将其作为批改按钮点击事件的弹出框, 同时通过插件获取选定源单的元数据,筛选出所有字段类型为user的字段,作为动态表单上下拉列表的动态数据构建,并且 在动态表单上设置一个基础资料为人员的基础资料。添加返回数据按钮,返回对应修改数据到父表单,更新数据库。对应的添加方式如下附件-111.doc

     也可参照对应官方资料 https://vip.kingdee.com/article/360921550578870784?productLineId=1&isKnowledge=2

三,实现代码

    C#源代码如下

using Kingdee.BOS;
using Kingdee.BOS.App.Data;
using Kingdee.BOS.Core.Bill.PlugIn;
using Kingdee.BOS.Core.DynamicForm;
using Kingdee.BOS.Core.DynamicForm.PlugIn;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Core.DynamicForm.PlugIn.ControlModel;
using Kingdee.BOS.Core.List;
using Kingdee.BOS.Core.List.PlugIn;
using Kingdee.BOS.Core.Metadata;
using Kingdee.BOS.Core.Metadata.FieldElement;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.ServiceHelper;
using Kingdee.BOS.Util;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Linq;

namespace BL.K3.Plugln.APP.List
{
    /// <summary>
    /// 列表测试插件(挂载需要配置的列表插件)
    /// </summary>
    [Description("自定义列表插件-打开动态表单"), HotUpdate]
    public class OpenForm:AbstractListPlugIn
    {
        public override void BarItemClick(BarItemClickEventArgs e)
        {
            base.BarItemClick(e);
            //获取列表的选中行
            if (e.BarItemKey.EqualsIgnoreCase("tbUpdatePerson"))
            {
                var lv = this.View as IListView;
                if (lv == null) { return; }
                var selectedRows = lv.SelectedRowsInfo;
                if (selectedRows == null || selectedRows.Count == 0)
                {
                    this.View.ShowMessage("当前没有行被选中!");
                    return;
                }
                Dictionary<string, string> indexs = new Dictionary<string, string>();  
                string name="";
                string FieldKey = "";
                for (int j = 0; j < selectedRows[0].FieldValues.Keys.Count; j++)
                {                 
                    FieldKey = selectedRows[0].FieldValues.Keys.ElementAt(j).ToString();
                    for (int i = 0; i < selectedRows.Count; i++)
                    {
                        name = name == "" ? " " + selectedRows[i].FieldValues.Where(q => q.Key == FieldKey).First().Value.ToString() : name + "," + selectedRows[i].FieldValues.Where(q => q.Key == FieldKey).First().Value.ToString();                       
                    }
                    indexs.Add(FieldKey, name);
                    name = "";
                }                                            
                DynamicFormShowParameter dynamicFormShowParameter = new DynamicFormShowParameter();
                //要打开的动态表单Id
                dynamicFormShowParameter.FormId = "QPUB_SCDD";
                //弹出动态表单
                this.View.ShowForm(dynamicFormShowParameter, result =>
                {
                    if (result != null && result.ReturnData != null && result.ReturnData is List<Tuple<string, string>>)
                    {
                        //关闭窗体返回值
                        var tuple = result.ReturnData as List<Tuple<string, string>>;
                        //初始化SQL语句
                        string SQL = "";
                            //修改选中单据的数据
                        for (int k = 0; k < indexs.Count; k++)
                        {
                            if (tuple[4].Item2.ToUpper() == indexs.Keys.ElementAt(k).ToUpper())
                            {
                                SQL = string.Format("/*dialect*/UPDATE {0} SET {1} = '{2}'  WHERE {3} in ({4})", tuple[0].Item2, tuple[1].Item2, tuple[2].Item2, tuple[3].Item2,indexs.Values.ElementAt(k));
                                DBUtils.Execute(this.Context, SQL);
                                this.View.Refresh();
                            }
                        }
                    }
                });
            }
        }
}           
    [Description("自定义动态表单插件-返回修改数据"), HotUpdate]
    public class ComboList : AbstractDynamicFormPlugIn
    {
        public override void OnInitialize(InitializeEventArgs e)
        {
            base.OnInitialize(e);
            BindComboField();
        }
        /// <summary>
        /// 设置下拉框数据
        /// </summary>
        public void BindComboField()
        {
            var enumList = GetEnumItems(this.Context);
            //设置下拉框标识
            var comboList = this.View.GetFieldEditor<ComboFieldEditor>("F_BL_UpName", 0); 
            if (comboList != null)
            {
                //添加下拉框内容
                comboList.SetComboItems(enumList);
            }
        }
        private List<EnumItem> GetEnumItems(Context ctx)
        {            
            var enumList = new List<EnumItem>();            
            // 获取对应单据的元数据
            var parentid = this.View.ParentFormView.BillBusinessInfo.GetForm().Id;
            var billMeta = MetaDataServiceHelper.GetFormMetaData(ctx, parentid);
            var obj2 = billMeta.BusinessInfo;           
            //获取基础资料类型为 SEC_User
            var fields = obj2.GetFieldList().FindAll(o => o is BaseDataField && ((BaseDataField)o).LookUpObject != null && ((BaseDataField)o).LookUpObject.FormId == "SEC_User");
            if (fields != null && fields.Count > 0)
            {

                foreach(var obj in fields)
                {
                    var enumItem = new EnumItem();                    
                    //下拉框显示值
                    var EntityName = obj.Entity.Name;                    
                    var RealName = string.Format("{0}-{1}",EntityName,obj.Name);
                    enumItem.Caption = new LocaleValue(RealName); 
                    enumItem.EnumId = obj.Key;
                    enumItem.Invalid = false;
                    //枚举值下拉框选中值
                    enumItem.Value = obj.Key; 
                    enumList.Add(enumItem);                    
                }
            }
            return enumList;            
        }
        /// <summary>
        /// 动态表单返回数据按钮点击事件
        /// </summary>
        public override void BarItemClick(BarItemClickEventArgs e)
        {
            base.BarItemClick(e);
            //动态表单菜单栏配置返回数据按钮,触发点击事件
            if (e.BarItemKey == "tbReturnData")
            {
               
                //动态表单下拉框标识
                var text = this.Model.GetValue("F_BL_UpName") as string;
                //动态表单修改字段内容标识
                var Base = this.GetBaseDataByKey(this.Model.DataObject as DynamicObject, "F_BL_User", "Id");
                //父单据的元数据对应单据名称  
                var parentid = this.View.ParentFormView.BillBusinessInfo.GetForm().Id;               
                var meta = MetaDataServiceHelper.Load(this.Context, parentid, true) as FormMetadata;
                //字段所在表名
                var table = meta.BusinessInfo.GetField(text).TableName;
                //字段所在表名的内码
                var FID = meta.BusinessInfo.GetField(text).Entity.EntryPkFieldName;
                //字段所在对应的实体名
                var FEntity = meta.BusinessInfo.GetField(text).EntityKey;
                List<Tuple<string, string>> items = new List<Tuple<string, string>>();
                items.Add(new Tuple<string, string>("F_BL_Table", table));
                items.Add(new Tuple<string, string>("F_BL_UpName", text));
                items.Add(new Tuple<string, string>("F_BL_User", Base));               
                items.Add(new Tuple<string, string>("FID", FID));
                items.Add(new Tuple<string, string>("FEntity", FEntity));
                this.View.ReturnToParentWindow(items);
                this.View.Close();
                return;
            }
            //关闭动态表单
            else if(e.BarItemKey == "tbClose")
            {
                this.View.Close();
                return;
            }
        }

        //获取基础资料数据
        private string GetBaseDataByKey(DynamicObject doFilter, string sKey, string sItem)
        {
            string sReturnValue = string.Empty;
            if (doFilter != null && doFilter[sKey] != null && !string.IsNullOrWhiteSpace(Convert.ToString(((DynamicObject)doFilter[sKey])[sItem])))
            {
                DynamicObject doTemp = doFilter[sKey] as DynamicObject;
                sReturnValue = Convert.ToString(doTemp[sItem]);
            }
            return sReturnValue;
        }
    }
}

        对应Python代码放到附件了,如果有帮助的话,欢迎动动小手点个赞哦。

赞 93