服务插件给单据字段赋值-简单示例

需求场景:委外用料清单保存时,根据子项物料的物料属性,判断勾不勾选MRP计算。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Kingdee.BOS.Core.DynamicForm.PlugIn;
using Kingdee.BOS.Core.Validation;
using Kingdee.BOS.Core;
using Kingdee.BOS;
using Kingdee.BOS.App.Data;
using System.Data;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.Core.Metadata.FieldElement;
using Kingdee.BOS.Orm.Metadata.DataEntity;
using Kingdee.BOS.Util;
using Kingdee.BOS.Contracts;
using Kingdee.BOS.Core.Metadata;
using Kingdee.BOS.Orm;
using System.ComponentModel;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Core.DynamicForm;
using System.Web;
using System.IO;


namespace MRPSelect
{
    [Description("委外用料清单保存判断MRP")]
    public class SUBBOMMRP:AbstractOperationServicePlugIn
    {
        public override void OnPrepareOperationServiceOption(OnPrepareOperationServiceEventArgs e)
        {
            base.OnPrepareOperationServiceOption(e);
        }
        /// <summary>
        /// 数据加载前,确保需要的属性被加载
        /// </summary>
        /// <param name="e"></param>
        /// <remarks>
        /// 在列表上执行操作时,单据的字段并没有被完全加载。
        /// 如果操作插件用到了未被加载的字段,一定会中断;
        /// 本事件允许插件,强制要求加载某些字段,避免中断
        /// </remarks>
        public override void OnPreparePropertys(PreparePropertysEventArgs e)
        {
            // 如下代码行,指定字段xxxxx的Key,强制要求加载字段
            //e.FieldKeys.Add("FJSTORDERNO");
            //e.FieldKeys.Add("FSOURCETYPE");
            //e.FieldKeys.Add("FSetAccountType");
            //e.FieldKeys.Add("FDATE");
        }
        public override void OnAddValidators(AddValidatorsEventArgs e)
        {
            base.OnAddValidators(e);
            this.OperationResult.IsShowMessage = true;
        }
        public override void BeginOperationTransaction(BeginOperationTransactionArgs e)
        {
            base.BeginOperationTransaction(e);
            if (e.DataEntitys.Count() < 1)
            {
                return;
            }
            string MatID = "";
            string Sql = "";
            DataSet ds = new DataSet();
            foreach (var item in e.DataEntitys)
            {
                    
                DynamicObjectCollection PPBomEntry = item["PPBomEntry"] as DynamicObjectCollection;
                if (PPBomEntry.Count > 0)
                {
                    for (int i = 0; i < PPBomEntry.Count; i++)
                    {
                        MatID = PPBomEntry[i]["MaterialID_Id"].ToString();
                        Sql = "select FERPCLSID from t_BD_MaterialBase where FMATERIALID = '" + MatID + "' ";
                        ds = Kingdee.BOS.ServiceHelper.DBServiceHelper.ExecuteDataSet(this.Context, Sql);
                        if (ds.Tables[0].Rows.Count > 0)
                        {
                            if (ds.Tables[0].Rows[0]["FERPCLSID"].ToString() == "2" || ds.Tables[0].Rows[0]["FERPCLSID"].ToString() == "3")
                            {
                                PPBomEntry[i]["IsMrpRun"] = 0;
                            }
                        }
                    }
                }   
            }
        }
    }
}

猜你喜欢

转载自www.cnblogs.com/zfangfang/p/12462819.html