二开方案示例:总账凭证分录自定义排序(以摘要排序为例)

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

二开方案示例:总账凭证分录自定义排序(以摘要排序为例)

1.打开BOS IDE扩展凭证,列表添加排序菜单。

上传图片

2.新增列表插件,代码如下。

using Kingdee.BOS.Core;
using Kingdee.BOS.Core.DynamicForm;
using Kingdee.BOS.Core.List.PlugIn;
using Kingdee.BOS.Core.Metadata;
using Kingdee.BOS.Orm;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.ServiceHelper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Kingdee.K3.FIN.GL.Business.PlugIn.Voucher
{
    
    public class VoucherOrder : AbstractListPlugIn
    {
        public override void BarItemClick(BOS.Core.DynamicForm.PlugIn.Args.BarItemClickEventArgs e)
        {
            base.BarItemClick(e);
            
            switch (e.BarItemKey.ToUpperInvariant())
            {
                // 排序
                case "ORDER":
                    OrderByCustomizeField();
                    break;
            }
        }

        /// <summary>
        /// 凭证分录自定义排序
        /// </summary>
        private void OrderByCustomizeField()
        {
            var selectRows = this.ListView.SelectedRowsInfo;
            if (selectRows == null || selectRows.Count == 0)
            {
                return;
            }

            // 获取凭证列表界面勾选的总账凭证id
            string[] vchIds = selectRows.GetPrimaryKeyValues();
            // 加载所勾选总账凭证信息
            FormMetadata metaData = FormMetaDataCache.GetCachedFormMetaData(this.Context, "GL_VOUCHER") as FormMetadata;
            DynamicObject[] lstVoucherInfo = BusinessDataServiceHelper.Load(this.Context, vchIds, metaData.BusinessInfo.GetDynamicObjectType());
            for (int i = 0; i < lstVoucherInfo.Count(); i++)
            {
                // 获取该张总账凭证分录
                DynamicObjectCollection entrys = lstVoucherInfo[i]["GL_VOUCHERENTRY"] as DynamicObjectCollection;
                if (entrys == null || entrys.Count == 0)
                {
                    continue;
                }

                List<DynamicObject> rows = new List<DynamicObject>();
                foreach (var row in entrys)
                {
                    rows.Add(row);
                }
                // 分录按照摘要排序
                rows = rows.OrderBy(o => Convert.ToString(o["FEXPLANATION"])).ToList();
                // 按排序后结果重置行序号
                entrys.Clear();
                for (int k = 0; k < rows.Count;k++ )
                {
                    rows[k]["Seq"] = k+1;
                    entrys.Add(rows[k]);
                }
            }
            var result = BusinessDataServiceHelper.Save(this.Context, metaData.BusinessInfo, lstVoucherInfo, OperateOption.Create(), OperationNumberConst.OperationNumber_Save);
            if (result == null || result.OperateResult == null)
            {
                return;
            }
            StringBuilder sbResult = new StringBuilder();
            if (result.OperateResult.Count > 0)
            {
                foreach (var item in result.OperateResult)
                {
                    sbResult.AppendLine(item.Message);
                }
            }
            if (result.ValidationErrors.Count > 0)
            {
                foreach (var item in result.ValidationErrors)
                {
                    sbResult.AppendLine(item.Message);
                }
            }
            this.View.ShowMessage(sbResult.ToString());
        }
    }
}




二开方案示例:总账凭证分录自定义排序(以摘要排序为例)

1.打开BOS IDE扩展凭证,列表添加排序菜单。2.新增列表插件,代码如下。using Kingdee.BOS.Core;using Kingdee.BOS.Core.DynamicForm;usin...
点击下载文档
确认删除?
回到顶部
客服QQ
  • 客服QQ点击这里给我发消息