实现类似于 销售订单新变更单 的功能原创
金蝶云社区-NiceToMeetYou
NiceToMeetYou
3人赞赏了该文章 241次浏览 未经作者许可,禁止转载编辑于2023年10月16日 15:28:06
  1. 问题一:如何实现类似销售订单增添了字段,字段可自动同步到销售订单新变更单,无需同一个字段在两个单据中添加两次?

    答:变更单应使用继承关系继承被变更的单据

  2. 问题二:如何实现销售订单新变更单反写销售订单数据时如何做到插件只编写一次,之后添加了字段无需再次变更插件即可自动将该字段数据反写到销售订单对应字段上?

    答:代码如下

  3. using KH.K3CLOUD.Util;
    using Kingdee.BOS.Core.DynamicForm;
    using Kingdee.BOS.Core.DynamicForm.PlugIn;
    using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
    using Kingdee.BOS.Core.Metadata;
    using Kingdee.BOS.Orm.DataEntity;
    using Kingdee.BOS.Orm.Metadata.DataEntity;
    using Kingdee.BOS.ServiceHelper;
    using Kingdee.BOS.Util;
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace KHSCGL.ServicePlugin
    {
        [HotUpdate]
        [Description("合同条款新变更单反写数据至合同条款")]
        public class HTTKXBGDServicePlugin : AbstractOperationServicePlugIn
        {
    
    
            /// <summary>
            /// 反写变更单
            /// </summary>
            /// <param name="bill"></param>
            public void ReWriteData(DynamicObject bill)
            {
    
            }
            public override void AfterExecuteOperationTransaction(AfterExecuteOperationTransaction e)
            {
                base.AfterExecuteOperationTransaction(e);
                string operation = this.FormOperation.Operation.ToUpper();
                if (OperationResult.IsSuccess && operation == "AUDIT")
                {
                    //ObjectUtil 是自己封装的一个工具类
                    ObjectUtil objutil = new ObjectUtil(this.Context);
                    //获取原始数据单据的businessinfo(请参考者使用金蝶官方的方法获取)
                    BusinessInfo businessInfo = objutil.GetBusinessInfo("k1f3d8767f7ee4da195126aa0856712dc");
                    DynamicObject[] datas = e.DataEntitys;
                    if (datas == null)
                    {
                        return;
                    }
                    //无需进行变更的字段
                    List<string> list = new List<string>();
                    list.Add("DocumentStatus");
                    list.Add("FcjrORGID");
                    list.Add("FcjrORGID_Id");
                    list.Add("FCREATORID");
                    list.Add("FCREATORID_Id");
                    list.Add("FsyrORGID");
                    list.Add("FsyrORGID_Id");
                    list.Add("FCREATEDATE");
                    list.Add("FreviewerID");
                    list.Add("FreviewerID_Id");
                    list.Add("FMODIFIERID");
                    list.Add("FMODIFIERID_Id");
                    list.Add("FauditDATE");
                    list.Add("FMODIFYDATE");
                    list.Add("FdocDATE");
                    list.Add("FHSourceBillType");
                    list.Add("FHSourceBillType_Id");
                    list.Add("FHSourceBillNo");
                    list.Add("Id");
                    list.Add("BillNo");
                    list.Add("FBillTypeID");
                    list.Add("FBillTypeID_Id");
    
                    foreach (var item in datas)
                    {
                        //合同条款新变更单数据
                        DynamicObject newData = objutil.GetObject("k6910f5e8bff24dac9f84975ad9f24c84", Convert.ToString(item["Id"]));
                        //合同条款数据
                        DynamicObject originalData = objutil.GetObject("k1f3d8767f7ee4da195126aa0856712dc", Convert.ToString(newData["FPKID"]));
                        //合同条款新变更单数据属性
                        DynamicPropertyCollection properties = newData.DynamicObjectType.Properties;
                        //合同条款数据属性
                        DynamicPropertyCollection properties2 = originalData.DynamicObjectType.Properties;
    
                        using (IEnumerator<DynamicProperty> enumerator = properties2.GetEnumerator())
                        {
                            while (enumerator.MoveNext())
                            {
                                DynamicProperty pty = enumerator.Current;
    
                                //if (StringUtils.EqualsIgnoreCase(pty.Name, "Id") || StringUtils.EqualsIgnoreCase(pty.Name, "FBillNo"))
                                //    continue;
    
                                if (properties.ContainsKey(pty.Name) && !StringUtils.EqualsIgnoreCase(pty.Name, "FFormId") && !list.Contains(pty.Name))
                                {
                                    if (!pty.IsReadOnly)
                                    {
                                         originalData[pty.Name] = newData[pty.Name];
                                    }
                                }
                                //处理单据体的数据
                                if (StringUtils.EqualsIgnoreCase(pty.PropertyType.Name , "DynamicObjectCollection"))
                                {
                                    //合同条款单据体的数据
                                    DynamicObjectCollection entry = originalData[pty.Name] as DynamicObjectCollection;
                                    int num1 = entry.Count;
                                    //entry.Clear();
                                    //合同条款新变更单的单据体数据
                                    DynamicObjectCollection xentry = newData[pty.Name] as DynamicObjectCollection;
                                    int num2 = xentry.Count;
                                    int num3 = num2 - num1;
                                    //合同条款新变更单的行数与合同条款的行数相等
                                    if (num3 == 0)
                                    {
                                        for (int i = 0; i < num2; i++)
                                        {
                                            //合同条款新变更单单据体i行的属性
                                            DynamicPropertyCollection eproperties = xentry[i].DynamicObjectType.Properties;
                                            //合同条款变更单单据体i行的属性
                                            DynamicPropertyCollection eproperties1 = entry[i].DynamicObjectType.Properties;
                                            foreach (var prop in eproperties)
                                            {
                                                if (eproperties1.Contains(prop.Name) && !StringUtils.EqualsIgnoreCase(prop.Name, "Id"))
                                                {
                                                    entry[i][prop.Name] = xentry[i][prop.Name];
                                                }
                                            }
                                        }
                                        
                                    }
                                    //合同条款新变更单的行数大于合同条款行数
                                    else if (num3 > 0)
                                    {
                                        for (int i = 0; i < num1; i++)
                                        {
                                            //合同条款新变更单单据体i行的属性
                                            DynamicPropertyCollection eproperties = xentry[i].DynamicObjectType.Properties;
                                            //合同条款单据体i行的属性
                                            DynamicPropertyCollection eproperties1 = entry[i].DynamicObjectType.Properties;
                                            foreach (var prop in eproperties)
                                            {
                                                if (eproperties1.Contains(prop.Name) && !StringUtils.EqualsIgnoreCase(prop.Name, "Id"))
                                                {
                                                    entry[i][prop.Name] = xentry[i][prop.Name];
                                                }
                                            }
                                        }
                                        for(int j = 0; j < num3; j++)
                                        {
                                            //新建合同条款新行
                                            DynamicObject newObj = new DynamicObject(entry[0].DynamicObjectType);
                                            //合同条款新变更单单据体i行的属性
                                            DynamicPropertyCollection eproperties = xentry[num1+j].DynamicObjectType.Properties;
                                            //合同条款单据体i行的属性
                                            DynamicPropertyCollection eproperties1 = newObj.DynamicObjectType.Properties;
                                            foreach (var prop in eproperties)
                                            {
                                                if (eproperties1.Contains(prop.Name) && !StringUtils.EqualsIgnoreCase(prop.Name, "Id"))
                                                {
                                                    newObj[prop.Name] = xentry[num1+j][prop.Name];
                                                }
                                            }
                                            entry.Add(newObj);
                                        }
                                    }
                                    //合同条款新变更单行数小于合同小款行数
                                    else if (num3 < 0)
                                    {
                                        for(int i = 0; i < -num3; i++)
                                        {
                                            entry.RemoveAt(-num3+i);
                                        }
                                        for (int j = 0; j < num2; j++)
                                        {
                                            //合同条款新变更单单据体i行的属性
                                            DynamicPropertyCollection eproperties = xentry[j].DynamicObjectType.Properties;
                                            //合同条款单据体i行的属性
                                            DynamicPropertyCollection eproperties1 = entry[j].DynamicObjectType.Properties;
                                            foreach (var prop in eproperties)
                                            {
                                                if (eproperties1.Contains(prop.Name) && !StringUtils.EqualsIgnoreCase(prop.Name, "Id"))
                                                {
                                                    entry[j][prop.Name] = xentry[j][prop.Name];
                                                }
                                            }
                                        }
    
                                    }
                                }
    
                            }
                        }
                        //保存合同条款数据
                        IOperationResult result = BusinessDataServiceHelper.Save(this.Context,businessInfo,originalData);
    
                    }
                }
            }
        }
    }
图标赞 3
3人点赞
还没有人点赞,快来当第一个点赞的人吧!
图标打赏
0人打赏
还没有人打赏,快来当第一个打赏的人吧!