如何控制单据头字段只反写一次

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

如何控制单据头字段只反写一次

说明:

   1. 单据反写规则的执行是按单据关联主实体数来执行的,主实体往往是单据体,所以在反写单据头执行了N次

   2. 适应情况,反写规则为累加或累减模式,单据头字段反写单据头字段


反写插件代码:


using System;
using System.Collections.Generic;
using System.Linq;
using System.ComponentModel;

using Kingdee.BOS.Util;
using Kingdee.BOS.Core.BusinessFlow.PlugIn;
using Kingdee.BOS.Core.BusinessFlow.PlugIn.Args;
using Kingdee.BOS.BusinessEntity.BusinessFlow;

namespace Kingdee.BOS.TestPlugIn.Demo
{
    [Description("限制单据头只反写一次")]
    [Kingdee.BOS.Util.HotUpdate]
    public class WriteBackHeadPlugIn : AbstractBusinessFlowServicePlugIn
    {
        //需要干预的反写规则
        private bool _isNeedHandleRule = false;
        private bool _isFirstWriteBack = true;
        /// <summary>
        /// 反写前事件,每个反写规则走一次,得到需要干预反写规则
        /// </summary>
        /// <param name="e"></param>
        public override void BeforeWriteBack(BeforeWriteBackEventArgs e)
        {
            this._isNeedHandleRule = false;
            this._isFirstWriteBack = true;
            var ruleName = e.Rule.Name.ToString();
            if (ruleName.EqualsIgnoreCase("单据B反写单据A——单据头字段"))
            {
                this._isNeedHandleRule = true;
            }
        }
    /// <summary>     
        /// /// 反写条目反写后事件,每一行都会走     
        /// /// </summary>    
        /// /// <param name="e"></param>    
        public override void AfterCommitAmount(AfterCommitAmountEventArgs e)   
        {           
            base.AfterCommitAmount(e);        
            if (this._isNeedHandleRule)      
            {             
                //第一次反写不处理       
                if (this._isFirstWriteBack)    
                {                
                    this._isFirstWriteBack = false;     
                    return;           
                }            
                //第二次操作时,把相应的反写数据扣减或加回去         
                if (this.OperationNumber.EqualsIgnoreCase("Save") ||
                    this.OperationNumber.EqualsIgnoreCase("Delete")||
                    (this.OperationNumber.EqualsIgnoreCase("Audit") ||
                    this.OperationNumber.EqualsIgnoreCase("UnAudit"))     
                {            
                    var sField = e.SourceCommitField;//被反写字段      
                    var currWBValue= (e.WriteBackSourceRow as WSRow<Id>).Val;//当前反写值    
                    //反写后的值
                    var afterWBValue = Convert.ToDecimal(e.SourceDataObject[sField.PropertyName]);   
                    //累加模式,把反写值减掉      
                    e.SourceDataObject[sField.PropertyName] = afterWBValue - currWBValue;      
                    //累减模式,把反写值加回去
                    //e.SourceDataObject[sField.PropertyName] = afterWBValue + currWBValue;      
                }
            } 
    }
}



如何控制单据头字段只反写一次

说明: 1. 单据反写规则的执行是按单据关联主实体数来执行的,主实体往往是单据体,所以在反写单据头执行了N次 2. 适应情况,反写...
点击下载文档
确认删除?
回到顶部
客服QQ
  • 客服QQ点击这里给我发消息