【学习】字段值更新和删除分录行原创
金蝶云社区-___________________
___________________
3人赞赏了该文章 650次浏览 未经作者许可,禁止转载编辑于2023年07月06日 10:15:20

引用

值更新也是表单插件的一种,需要继承AbstractBillPlugIn类来重写DataChanged方法

image.png


注意

获取某个字段是否触发了值更新e.Field.Key.EqualsIgnoreCase("字段标识");

备注:字段触发值更新需要在BOS里面勾选即时触发值更新事件image.png


值更新事件


单据头更新单据体

         if (e.Field.Key.EqualsIgnoreCase("F_VVHD_WL"))
            {
                //获取单据头的物料赋值给单据体
                var F_VVHD_WL = this.Model.GetValue("F_VVHD_WL");
                string Name1 = (F_VVHD_WL as DynamicObject)["id"].ToString();//取值
                int count = this.Model.GetEntryRowCount("FPOOrderEntry");//获取采购订单分录行总数
                for (int i = 0; i < count; i++)
                {
                    this.Model.SetValue("FMaterialId", Name1, i);//赋值
                }
            }


image.png


单据体更新单据头

         if (e.Field.Key.EqualsIgnoreCase("FQty"))
            {
                int count = this.Model.GetEntryRowCount("FPOOrderEntry");//获取采购订单分录行总数
                double Qty = 0;
                for (int i = 0; i < count; i++)
                {
                    string FQty = this.Model.GetValue("FQty", i).ToString();//获取采购订单分录行总数
                    Qty += double.Parse(FQty);
                }
                this.Model.SetValue("F_VVHD_Text", Qty.ToString());//赋值
            }

image.png


值更新需要注意

AfterDeleteRow 分录行删除事件

 public override void AfterDeleteRow(AfterDeleteRowEventArgs e)//分录行被删除时
        {
            //将上面的代码复制一份
            base.AfterDeleteRow(e);
            int count = this.Model.GetEntryRowCount("FPOOrderEntry");
            double Qty = 0;
            for (int i = 0; i < count; i++)
            {
                string FQty = this.Model.GetValue("FQty", i).ToString();
                Qty += double.Parse(FQty);
            }
            this.Model.SetValue("F_VVHD_Text", Qty.ToString());
        }

image.png


代码分享

using Kingdee.BOS.Core.Bill.PlugIn;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.Util;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;

namespace XueXi
{
    [Description("学习值更新事件"), HotUpdate]
    public class Class3 : AbstractBillPlugIn
    {
        public override void DataChanged(DataChangedEventArgs e)
        {
            base.DataChanged(e);
            if (e.Field.Key.EqualsIgnoreCase("F_VVHD_WL"))
            {
                //获取单据头的物料赋值给单据体
                var F_VVHD_WL = this.Model.GetValue("F_VVHD_WL");
                string Name1 = (F_VVHD_WL as DynamicObject)["id"].ToString();//取值
                int count = this.Model.GetEntryRowCount("FPOOrderEntry");//获取采购订单分录行总数
                for (int i = 0; i < count; i++)
                {
                    this.Model.SetValue("FMaterialId", Name1, i);//赋值
                }
            }

            if (e.Field.Key.EqualsIgnoreCase("FQty"))
            {
                int count = this.Model.GetEntryRowCount("FPOOrderEntry");//获取采购订单分录行总数
                double Qty = 0;
                for (int i = 0; i < count; i++)
                {
                    string FQty = this.Model.GetValue("FQty", i).ToString();//获取采购订单分录行总数
                    Qty += double.Parse(FQty);
                }
                this.Model.SetValue("F_VVHD_Text", Qty.ToString());//赋值
            }
        }

        public override void AfterDeleteRow(AfterDeleteRowEventArgs e)//分录行被删除时
        {
            //将上面的代码复制一份
            base.AfterDeleteRow(e);
            int count = this.Model.GetEntryRowCount("FPOOrderEntry");
            double Qty = 0;
            for (int i = 0; i < count; i++)
            {
                string FQty = this.Model.GetValue("FQty", i).ToString();
                Qty += double.Parse(FQty);
            }
            this.Model.SetValue("F_VVHD_Text", Qty.ToString());
        }
    }
}


赞 3