在操作插件模拟页面操作实现字段值更新服务原创
金蝶云社区-eris
eris
16人赞赏了该文章 2,398次浏览 未经作者许可,禁止转载编辑于2021年04月16日 18:00:00

单据A单价字段值改变会触发金额和总金额字段更新,现在需要再操作插件中改变单价也更实现跟页面想的效果,效果如下图:

image.png

代码:

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Linq;

using System.Text;

using System.Data;


using Kingdee.BOS.Util;

using Kingdee.BOS.Contracts;

using Kingdee.BOS.Core;

using Kingdee.BOS.Core.DynamicForm.PlugIn;

using Kingdee.BOS.Core.DynamicForm;

using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;

using Kingdee.BOS.Orm.DataEntity;

using Kingdee.BOS.Core.Metadata.EntityElement;

using Kingdee.BOS.BusinessEntity.BusinessFlow;

using Kingdee.BOS.Core.Metadata;

using Kingdee.BOS.App.Core;

using Kingdee.BOS.Core.Metadata.FieldElement;

using Kingdee.BOS.ServiceHelper;

using Kingdee.BOS.Core.Bill;

using Kingdee.BOS.Core.Metadata.FormElement;

using Kingdee.BOS.Web.DynamicForm;


namespace Kingdee.BOS.TestPlugIn.FormOperationPlugIn

{

    [HotUpdate]

    [Description("单据A操作插件测试")]

    public class BillAOperationPlugInTest : AbstractOperationServicePlugIn

    {


        /// <summary>

        /// 事务前事件

        /// </summary>

        /// <param name="e"></param>

        public override void BeforeExecuteOperationTransaction(BeforeExecuteOperationTransaction e)

        {

            base.BeforeExecuteOperationTransaction(e);

            var billView = this.CreateView("KKK_BillA") as DynamicWebFormView;

            var priceField=  this.BusinessInfo.GetField("F_KKK_Price");


            foreach (var data in e.SelectedRows)

            {

                billView.Model.DataObject = data.DataEntity;

                var entryObjs = priceField.Entity.DynamicProperty.GetValue( data.DataEntity) as DynamicObjectCollection;

                int index =0;

                foreach (var entryObj in entryObjs)

                {

                    billView.UpdateValue("F_KKK_Price", index, (index+1) * 3);

                    index++;

                }

            }

        }

        /// <summary>

        /// 创建单据视图  

        /// </summary>

        /// <param name="ctx"></param>

        /// <param name="metaData"></param>

        /// <returns></returns>

        private IDynamicFormView CreateView(string formId)

        {

            FormMetadata metadata = FormMetaDataCache.GetCachedFormMetaData(this.Context, formId);

            var OpenParameter = CreateOpenParameter(this.Context, metadata);

            var Provider = metadata.BusinessInfo.GetForm().GetFormServiceProvider(true);

            string importViewClass = "Kingdee.BOS.Web.Import.ImportBillView,Kingdee.BOS.Web";

            Type type = Type.GetType(importViewClass);

            IDynamicFormView view = (IDynamicFormView)Activator.CreateInstance(type);

            ((IDynamicFormViewService)view).Initialize(OpenParameter, Provider);

            return view;

        }

        /// <summary>

        /// 创建输入参数

        /// </summary>

        /// <param name="ctx"></param>

        /// <param name="metaData"></param>

        /// <returns></returns>

        private BillOpenParameter CreateOpenParameter(Context ctx, FormMetadata metaData)

        {

            Form form = metaData.BusinessInfo.GetForm();

            BillOpenParameter openPara = new BillOpenParameter(form.Id, metaData.GetLayoutInfo().Id);


            openPara = new BillOpenParameter(form.Id, string.Empty);

            openPara.Context = ctx;

            openPara.ServiceName = form.FormServiceName;

            openPara.PageId = Guid.NewGuid().ToString();


            // 单据

            openPara.FormMetaData = metaData;

            openPara.LayoutId = metaData.GetLayoutInfo().Id;


            // 操作相关参数

            openPara.Status = OperationStatus.ADDNEW;

            openPara.PkValue = null;

            openPara.CreateFrom = CreateFrom.Default;

            openPara.ParentId = 0;

            openPara.GroupId = "";

            openPara.DefaultBillTypeId = null;

            openPara.DefaultBusinessFlowId = null;

            // 修改主业务组织无须用户确认

            openPara.SetCustomParameter("ShowConfirmDialogWhenChangeOrg", false);


            // 插件

            List<AbstractDynamicFormPlugIn> plugins = form.CreateFormPlugIns();

            openPara.SetCustomParameter(FormConst.PlugIns, plugins);


            return openPara;

        }


    }

}


图标赞 16
16人点赞
还没有人点赞,快来当第一个点赞的人吧!
图标打赏
0人打赏
还没有人打赏,快来当第一个打赏的人吧!